88import java .net .URI ;
99import java .util .stream .Stream ;
1010
11- import static org .junit . jupiter .api .Assertions . assertDoesNotThrow ;
12- import static org .junit . jupiter .api .Assertions . assertThrows ;
11+ import static org .assertj . core .api .AssertionsForClassTypes . assertThatCode ;
12+ import static org .assertj . core .api .AssertionsForClassTypes . assertThatThrownBy ;
1313
1414class PackageValidatorTest {
1515
@@ -28,7 +28,7 @@ void validate_severityBelowThreshold_allowed() {
2828 new Ignores ()
2929 );
3030
31- assertDoesNotThrow (() -> validator .validate (artifact ));
31+ assertThatCode (() -> validator .validate (artifact )). doesNotThrowAnyException ( );
3232 }
3333
3434 @ Test
@@ -46,7 +46,7 @@ void validate_vulnIssueAboveThreshold_forbidden() {
4646 new Ignores ()
4747 );
4848
49- assertThrows ( CancelException . class , () -> validator .validate (artifact ));
49+ assertThatThrownBy ( () -> validator .validate (artifact )). isExactlyInstanceOf ( CancelException . class );
5050 }
5151
5252 @ Test
@@ -64,7 +64,7 @@ void validate_vulnIssuesIgnored_allowed() {
6464 new Ignores ().withIgnoreVulnIssues (true )
6565 );
6666
67- assertDoesNotThrow (() -> validator .validate (artifact ));
67+ assertThatCode (() -> validator .validate (artifact )). doesNotThrowAnyException ( );
6868 }
6969
7070 @ Test
@@ -82,7 +82,7 @@ void validate_licenseIssueAboveThreshold_forbidden() {
8282 new Ignores ()
8383 );
8484
85- assertThrows ( CancelException . class , () -> validator .validate (artifact ));
85+ assertThatThrownBy ( () -> validator .validate (artifact )). isExactlyInstanceOf ( CancelException . class );
8686 }
8787
8888 @ Test
@@ -100,6 +100,25 @@ void validate_licenseIssuesIgnored_allowed() {
100100 new Ignores ().withIgnoreLicenseIssues (true )
101101 );
102102
103- assertDoesNotThrow (() -> validator .validate (artifact ));
103+ assertThatCode (() -> validator .validate (artifact )).doesNotThrowAnyException ();
104+ }
105+
106+ @ Test
107+ void validate_includesSnykDetailsUrlInCancelException () {
108+ ValidationSettings settings = new ValidationSettings ()
109+ .withVulnSeverityThreshold (Severity .LOW );
110+ PackageValidator validator = new PackageValidator (settings );
111+ MonitoredArtifact artifact = new MonitoredArtifact ("" ,
112+ new TestResult (
113+ IssueSummary .from (Stream .of (Severity .LOW )),
114+ IssueSummary .from (Stream .empty ()),
115+ URI .create ("https://snyk.io/package/details" )
116+ ),
117+ new Ignores ()
118+ );
119+
120+ assertThatThrownBy (() -> validator .validate (artifact ))
121+ .isExactlyInstanceOf (CancelException .class )
122+ .hasMessageContaining ("https://snyk.io/package/details" );
104123 }
105124}
0 commit comments