66import org .junit .jupiter .api .Test ;
77
88import java .net .URI ;
9+ import java .util .Optional ;
910import java .util .stream .Stream ;
1011
1112import static org .assertj .core .api .AssertionsForClassTypes .assertThatCode ;
@@ -16,8 +17,8 @@ class PackageValidatorTest {
1617 @ Test
1718 void validate_severityBelowThreshold_allowed () {
1819 ValidationSettings settings = new ValidationSettings ()
19- .withVulnSeverityThreshold (Severity .MEDIUM )
20- .withLicenseSeverityThreshold (Severity .CRITICAL );
20+ .withVulnSeverityThreshold (Optional . of ( Severity .MEDIUM ) )
21+ .withLicenseSeverityThreshold (Optional . of ( Severity .CRITICAL ) );
2122 PackageValidator validator = new PackageValidator (settings );
2223 MonitoredArtifact artifact = new MonitoredArtifact ("" ,
2324 new TestResult (
@@ -34,8 +35,8 @@ void validate_severityBelowThreshold_allowed() {
3435 @ Test
3536 void validate_vulnIssueAboveThreshold_forbidden () {
3637 ValidationSettings settings = new ValidationSettings ()
37- .withVulnSeverityThreshold (Severity .HIGH )
38- .withLicenseSeverityThreshold (Severity .LOW );
38+ .withVulnSeverityThreshold (Optional . of ( Severity .HIGH ) )
39+ .withLicenseSeverityThreshold (Optional . of ( Severity .LOW ) );
3940 PackageValidator validator = new PackageValidator (settings );
4041 MonitoredArtifact artifact = new MonitoredArtifact ("" ,
4142 new TestResult (
@@ -52,8 +53,8 @@ void validate_vulnIssueAboveThreshold_forbidden() {
5253 @ Test
5354 void validate_vulnIssuesIgnored_allowed () {
5455 ValidationSettings settings = new ValidationSettings ()
55- .withVulnSeverityThreshold (Severity .HIGH )
56- .withLicenseSeverityThreshold (Severity .LOW );
56+ .withVulnSeverityThreshold (Optional . of ( Severity .HIGH ) )
57+ .withLicenseSeverityThreshold (Optional . of ( Severity .LOW ) );
5758 PackageValidator validator = new PackageValidator (settings );
5859 MonitoredArtifact artifact = new MonitoredArtifact ("" ,
5960 new TestResult (
@@ -70,8 +71,8 @@ void validate_vulnIssuesIgnored_allowed() {
7071 @ Test
7172 void validate_licenseIssueAboveThreshold_forbidden () {
7273 ValidationSettings settings = new ValidationSettings ()
73- .withVulnSeverityThreshold (Severity .LOW )
74- .withLicenseSeverityThreshold (Severity .MEDIUM );
74+ .withVulnSeverityThreshold (Optional . of ( Severity .LOW ) )
75+ .withLicenseSeverityThreshold (Optional . of ( Severity .MEDIUM ) );
7576 PackageValidator validator = new PackageValidator (settings );
7677 MonitoredArtifact artifact = new MonitoredArtifact ("" ,
7778 new TestResult (
@@ -85,11 +86,30 @@ void validate_licenseIssueAboveThreshold_forbidden() {
8586 assertThatThrownBy (() -> validator .validate (artifact )).isExactlyInstanceOf (CancelException .class );
8687 }
8788
89+
90+ @ Test
91+ void validate_thresholdNone_allowed () {
92+ ValidationSettings settings = new ValidationSettings ()
93+ .withVulnSeverityThreshold (Optional .empty ())
94+ .withLicenseSeverityThreshold (Optional .empty ());
95+ PackageValidator validator = new PackageValidator (settings );
96+ MonitoredArtifact artifact = new MonitoredArtifact ("" ,
97+ new TestResult (
98+ IssueSummary .from (Stream .of (Severity .CRITICAL )),
99+ IssueSummary .from (Stream .of (Severity .CRITICAL )),
100+ URI .create ("https://snyk.io/package/version" )
101+ ),
102+ new Ignores ()
103+ );
104+
105+ assertThatCode (() -> validator .validate (artifact )).doesNotThrowAnyException ();
106+ }
107+
88108 @ Test
89109 void validate_licenseIssuesIgnored_allowed () {
90110 ValidationSettings settings = new ValidationSettings ()
91- .withVulnSeverityThreshold (Severity .LOW )
92- .withLicenseSeverityThreshold (Severity .MEDIUM );
111+ .withVulnSeverityThreshold (Optional . of ( Severity .LOW ) )
112+ .withLicenseSeverityThreshold (Optional . of ( Severity .MEDIUM ) );
93113 PackageValidator validator = new PackageValidator (settings );
94114 MonitoredArtifact artifact = new MonitoredArtifact ("" ,
95115 new TestResult (
@@ -106,7 +126,7 @@ void validate_licenseIssuesIgnored_allowed() {
106126 @ Test
107127 void validate_includesSnykDetailsUrlInCancelException () {
108128 ValidationSettings settings = new ValidationSettings ()
109- .withVulnSeverityThreshold (Severity .LOW );
129+ .withVulnSeverityThreshold (Optional . of ( Severity .LOW ) );
110130 PackageValidator validator = new PackageValidator (settings );
111131 MonitoredArtifact artifact = new MonitoredArtifact ("" ,
112132 new TestResult (
0 commit comments