2121 */
2222package com .github .packageurl ;
2323
24- import org .hamcrest .CoreMatchers ;
25- import org .hamcrest .MatcherAssert ;
26- import org .junit .Assert ;
27- import org .junit .Rule ;
28- import org .junit .Test ;
29- import org .junit .rules .ExpectedException ;
24+ import static org .junit .jupiter .api .Assertions .assertEquals ;
25+ import static org .junit .jupiter .api .Assertions .assertThrows ;
26+ import static org .junit .jupiter .api .Assertions .fail ;
3027
3128import java .util .Collections ;
3229import java .util .HashMap ;
3330import java .util .Map ;
31+ import org .junit .jupiter .api .Test ;
3432
35- import static org .hamcrest .CoreMatchers .allOf ;
36- import static org .hamcrest .CoreMatchers .containsString ;
37- import static org .junit .Assert .*;
38-
39- public class PackageURLBuilderTest {
40-
41- @ Rule
42- public ExpectedException exception = ExpectedException .none ();
33+ class PackageURLBuilderTest {
4334
4435 @ Test
45- public void testPackageURLBuilder () throws MalformedPackageURLException {
46- exception = ExpectedException .none ();
47-
36+ void packageURLBuilder () throws MalformedPackageURLException {
4837 PackageURL purl = PackageURLBuilder .aPackageURL ()
4938 .withType ("my.type-9+" )
5039 .withName ("name" )
@@ -100,81 +89,86 @@ public void testPackageURLBuilder() throws MalformedPackageURLException {
10089 }
10190
10291 @ Test
103- public void testPackageURLBuilderException1 () throws MalformedPackageURLException {
92+ void packageURLBuilderException1 () throws MalformedPackageURLException {
10493 PackageURL purl = PackageURLBuilder .aPackageURL ()
10594 .withType ("type" )
10695 .withName ("name" )
10796 .withQualifier ("key" ,"" )
10897 .build ();
109- assertEquals ("qualifier count" , 0 , purl .getQualifiers ().size ());
98+ assertEquals (0 , purl .getQualifiers ().size (), "qualifier count" );
11099 }
111100
112101 @ Test
113- public void testPackageURLBuilderException1Null () throws MalformedPackageURLException {
102+ void packageURLBuilderException1Null () throws MalformedPackageURLException {
114103 PackageURL purl = PackageURLBuilder .aPackageURL ()
115104 .withType ("type" )
116105 .withName ("name" )
117106 .withQualifier ("key" ,null )
118107 .build ();
119- assertEquals ("qualifier count" , 0 , purl .getQualifiers ().size ());
108+ assertEquals (0 , purl .getQualifiers ().size (), "qualifier count" );
120109 }
121110
122111 @ Test
123- public void testPackageURLBuilderException2 () throws MalformedPackageURLException {
124- exception .expect (MalformedPackageURLException .class );
125- PackageURLBuilder .aPackageURL ()
126- .withType ("type" )
127- .withNamespace ("invalid//namespace" )
128- .withName ("name" )
129- .build ();
130- Assert .fail ("Build should fail due to invalid namespace" );
112+ void packageURLBuilderException2 () {
113+ assertThrows (MalformedPackageURLException .class , () -> {
114+ PackageURLBuilder .aPackageURL ()
115+ .withType ("type" )
116+ .withNamespace ("invalid//namespace" )
117+ .withName ("name" )
118+ .build ();
119+ fail ("Build should fail due to invalid namespace" );
120+ });
131121 }
132122
133123 @ Test
134- public void testPackageURLBuilderException3 () throws MalformedPackageURLException {
135- exception .expect (MalformedPackageURLException .class );
136- PackageURLBuilder .aPackageURL ()
137- .withType ("typ^e" )
138- .withSubpath ("invalid/name%2Fspace" )
139- .withName ("name" )
140- .build ();
141- Assert .fail ("Build should fail due to invalid subpath" );
124+ void packageURLBuilderException3 () {
125+ assertThrows (MalformedPackageURLException .class , () -> {
126+ PackageURLBuilder .aPackageURL ()
127+ .withType ("typ^e" )
128+ .withSubpath ("invalid/name%2Fspace" )
129+ .withName ("name" )
130+ .build ();
131+ fail ("Build should fail due to invalid subpath" );
132+ });
142133 }
143134
144135 @ Test
145- public void testPackageURLBuilderException4 () throws MalformedPackageURLException {
146- exception .expect (MalformedPackageURLException .class );
147- PackageURLBuilder .aPackageURL ()
148- .withType ("0_type" )
149- .withName ("name" )
150- .build ();
151- Assert .fail ("Build should fail due to invalid type" );
136+ void packageURLBuilderException4 () {
137+ assertThrows (MalformedPackageURLException .class , () -> {
138+ PackageURLBuilder .aPackageURL ()
139+ .withType ("0_type" )
140+ .withName ("name" )
141+ .build ();
142+ fail ("Build should fail due to invalid type" );
143+ });
152144 }
153145
154146 @ Test
155- public void testPackageURLBuilderException5 () throws MalformedPackageURLException {
156- exception .expect (MalformedPackageURLException .class );
157- PackageURLBuilder .aPackageURL ()
158- .withType ("ype" )
159- .withName ("name" )
160- .withQualifier ("0_key" ,"value" )
161- .build ();
162- Assert .fail ("Build should fail due to invalid qualifier key" );
147+ void packageURLBuilderException5 () {
148+ assertThrows (MalformedPackageURLException .class , () -> {
149+ PackageURLBuilder .aPackageURL ()
150+ .withType ("ype" )
151+ .withName ("name" )
152+ .withQualifier ("0_key" , "value" )
153+ .build ();
154+ fail ("Build should fail due to invalid qualifier key" );
155+ });
163156 }
164157
165158 @ Test
166- public void testPackageURLBuilderException6 () throws MalformedPackageURLException {
167- exception .expect (MalformedPackageURLException .class );
168- PackageURLBuilder .aPackageURL ()
169- .withType ("ype" )
170- .withName ("name" )
171- .withQualifier ("" ,"value" )
172- .build ();
173- Assert .fail ("Build should fail due to invalid qualifier key" );
159+ void packageURLBuilderException6 () {
160+ assertThrows (MalformedPackageURLException .class , () -> {
161+ PackageURLBuilder .aPackageURL ()
162+ .withType ("ype" )
163+ .withName ("name" )
164+ .withQualifier ("" , "value" )
165+ .build ();
166+ fail ("Build should fail due to invalid qualifier key" );
167+ });
174168 }
175169
176170 @ Test
177- public void testEditBuilder1 () throws MalformedPackageURLException {
171+ void editBuilder1 () throws MalformedPackageURLException {
178172
179173 PackageURL p =
new PackageURL (
"pkg:generic/namespace/[email protected] ?k=v#s" );
180174 PackageURLBuilder b = p .toBuilder ();
@@ -196,7 +190,7 @@ public void testEditBuilder1() throws MalformedPackageURLException {
196190 }
197191
198192 @ Test
199- public void testQualifiers () throws MalformedPackageURLException {
193+ void qualifiers () throws MalformedPackageURLException {
200194 Map <String , String > qualifiers = new HashMap <>();
201195 qualifiers .put ("key2" , "value2" );
202196 Map <String , String > qualifiers2 = new HashMap <>();
@@ -219,7 +213,7 @@ public void testQualifiers() throws MalformedPackageURLException {
219213 }
220214
221215 @ Test
222- public void testFromExistingPurl () throws MalformedPackageURLException {
216+ void fromExistingPurl () throws MalformedPackageURLException {
223217 String purl =
"pkg:generic/namespace/[email protected] ?k=v#s" ;
224218 PackageURL p = new PackageURL (purl );
225219 PackageURL purl2 = PackageURLBuilder .aPackageURL (p ).build ();
@@ -230,22 +224,21 @@ public void testFromExistingPurl() throws MalformedPackageURLException {
230224
231225 private void assertBuilderMatch (PackageURL expected , PackageURLBuilder actual ) throws MalformedPackageURLException {
232226
233- Assert . assertEquals (expected .toString (), actual .build ().toString ());
234- Assert . assertEquals (expected .getType (), actual .getType ());
235- Assert . assertEquals (expected .getNamespace (), actual .getNamespace ());
236- Assert . assertEquals (expected .getName (), actual .getName ());
237- Assert . assertEquals (expected .getVersion (), actual .getVersion ());
238- Assert . assertEquals (expected .getSubpath (), actual .getSubpath ());
227+ assertEquals (expected .toString (), actual .build ().toString ());
228+ assertEquals (expected .getType (), actual .getType ());
229+ assertEquals (expected .getNamespace (), actual .getNamespace ());
230+ assertEquals (expected .getName (), actual .getName ());
231+ assertEquals (expected .getVersion (), actual .getVersion ());
232+ assertEquals (expected .getSubpath (), actual .getSubpath ());
239233
240234 Map <String , String > eQualifiers = expected .getQualifiers ();
241235 Map <String , String > aQualifiers = actual .getQualifiers ();
242236
243237 assertEquals (eQualifiers , aQualifiers );
244238
245239 if (eQualifiers != null && aQualifiers != null ) {
246- eQualifiers .forEach ((k ,v ) -> {
247- Assert .assertEquals (v , actual .getQualifier (k ));
248- });
240+ eQualifiers .forEach ((k ,v ) ->
241+ assertEquals (v , actual .getQualifier (k )));
249242 }
250243 }
251244
0 commit comments