1919 * under the License.
2020 */
2121
22+ import java .io .File ;
2223import java .util .Set ;
2324
2425import org .apache .maven .artifact .Artifact ;
2526import org .apache .maven .enforcer .rule .api .EnforcerLogger ;
26- import org .junit .Before ;
27- import org .junit .Rule ;
28- import org .junit .Test ;
29- import org . junit . rules . TemporaryFolder ;
30-
31- import static org .junit .Assert . assertEquals ;
32- import static org .junit .Assert . assertFalse ;
33- import static org .junit .Assert .assertTrue ;
27+ import org .junit .jupiter . api . BeforeEach ;
28+ import org .junit .jupiter . api . Test ;
29+ import org .junit .jupiter . api . io . TempDir ;
30+
31+ import static org . junit . jupiter . api . Assertions . assertEquals ;
32+ import static org .junit .jupiter . api . Assertions . assertFalse ;
33+ import static org .junit .jupiter . api . Assertions . assertThrows ;
34+ import static org .junit .jupiter . api . Assertions .assertTrue ;
3435import static org .mockito .Mockito .mock ;
3536
3637public class ClassesWithSameNameTest {
@@ -48,13 +49,13 @@ public class ClassesWithSameNameTest {
4849
4950 private static final EnforcerLogger LOG = mock (EnforcerLogger .class );
5051
51- @ Rule
52- public TemporaryFolder temporaryFolder = new TemporaryFolder () ;
52+ @ TempDir
53+ private File temporaryFolder ;
5354
5455 private ClassFileHelper classFileHelper ;
5556
56- @ Before
57- public void beforeEachTest () {
57+ @ BeforeEach
58+ void beforeEachTest () {
5859 classFileHelper = new ClassFileHelper (temporaryFolder );
5960 }
6061
@@ -64,7 +65,7 @@ public void beforeEachTest() {
6465 * files are exactly the same.
6566 */
6667 @ Test
67- public void hasDuplicatesShouldReturnTrueWhenClassNameIsDuplicate () throws Exception {
68+ void hasDuplicatesShouldReturnTrueWhenClassNameIsDuplicate () throws Exception {
6869 ClassFile classFile1 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "" );
6970 ClassFile classFile2 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "" );
7071 ClassesWithSameName classesWithSameName = new ClassesWithSameName (LOG , classFile1 , classFile2 );
@@ -75,7 +76,7 @@ public void hasDuplicatesShouldReturnTrueWhenClassNameIsDuplicate() throws Excep
7576 }
7677
7778 @ Test
78- public void hasDuplicatesShouldReturnFalseWhenClassNameIsDuplicateButBytecodeIsIdentical () throws Exception {
79+ void hasDuplicatesShouldReturnFalseWhenClassNameIsDuplicateButBytecodeIsIdentical () throws Exception {
7980 ClassFile classFile1 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "content matches in both" );
8081 ClassFile classFile2 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "content matches in both" );
8182 ClassesWithSameName classesWithSameName = new ClassesWithSameName (LOG , classFile1 , classFile2 );
@@ -86,7 +87,7 @@ public void hasDuplicatesShouldReturnFalseWhenClassNameIsDuplicateButBytecodeIsI
8687 }
8788
8889 @ Test
89- public void hasDuplicatesShouldReturnFalseWhenClassHasNoDuplicates () throws Exception {
90+ void hasDuplicatesShouldReturnFalseWhenClassHasNoDuplicates () throws Exception {
9091 ClassFile classFile = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "" );
9192 ClassesWithSameName classesWithSameName = new ClassesWithSameName (LOG , classFile );
9293
@@ -104,7 +105,7 @@ public void hasDuplicatesShouldReturnFalseWhenClassHasNoDuplicates() throws Exce
104105 * bytecode).
105106 */
106107 @ Test
107- public void hasDuplicatesShouldReturnTrueWhenClassNameIsDuplicateButBytecodeDiffers () throws Exception {
108+ void hasDuplicatesShouldReturnTrueWhenClassNameIsDuplicateButBytecodeDiffers () throws Exception {
108109 ClassFile classFile1 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "1" );
109110 ClassFile classFile2 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "2" );
110111 ClassesWithSameName classesWithSameName = new ClassesWithSameName (LOG , classFile1 , classFile2 );
@@ -122,7 +123,7 @@ public void hasDuplicatesShouldReturnTrueWhenClassNameIsDuplicateButBytecodeDiff
122123 * We set the test up so it finds duplicates only if the bytecode differs.
123124 */
124125 @ Test
125- public void hasDuplicatesShouldReturnFalseWhenClassNameIsDuplicateAndBytecodeDiffers () throws Exception {
126+ void hasDuplicatesShouldReturnFalseWhenClassNameIsDuplicateAndBytecodeDiffers () throws Exception {
126127 ClassFile classFile1 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "1" );
127128 ClassFile classFile2 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "2" );
128129 ClassesWithSameName classesWithSameName = new ClassesWithSameName (LOG , classFile1 , classFile2 );
@@ -136,7 +137,7 @@ public void hasDuplicatesShouldReturnFalseWhenClassNameIsDuplicateAndBytecodeDif
136137 * This tests the normal condition where we just output the class file path.
137138 */
138139 @ Test
139- public void toOutputStringOutputsPlainArtifactWhenJustNamesAreDuplicate () throws Exception {
140+ void toOutputStringOutputsPlainArtifactWhenJustNamesAreDuplicate () throws Exception {
140141 ClassFile classFile1 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "" );
141142 ClassFile classFile2 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "" );
142143 ClassesWithSameName classesWithSameName = new ClassesWithSameName (LOG , classFile1 , classFile2 );
@@ -152,7 +153,7 @@ public void toOutputStringOutputsPlainArtifactWhenJustNamesAreDuplicate() throws
152153 * determine which artifacts they can ignore when fix the BanDuplicateClasses error.
153154 */
154155 @ Test
155- public void toOutputStringOutputsTwoArtifactsWhereBytecodeIsExactMatch () throws Exception {
156+ void toOutputStringOutputsTwoArtifactsWhereBytecodeIsExactMatch () throws Exception {
156157 ClassFile classFile1 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "content matches in both" );
157158 ClassFile classFile2 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "content matches in both" );
158159 ClassesWithSameName classesWithSameName = new ClassesWithSameName (LOG , classFile1 , classFile2 );
@@ -171,8 +172,7 @@ public void toOutputStringOutputsTwoArtifactsWhereBytecodeIsExactMatch() throws
171172 * 1 and 2 don't match 3 and 4.
172173 */
173174 @ Test
174- public void toOutputStringOutputsFourArtifactsWhereBytecodeIsExactMatchInTwoAndExactMatchInOtherTwo ()
175- throws Exception {
175+ void toOutputStringOutputsFourArtifactsWhereBytecodeIsExactMatchInTwoAndExactMatchInOtherTwo () throws Exception {
176176 ClassFile classFile1 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "file content of 1 and 2" );
177177 ClassFile classFile2 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "file content of 1 and 2" );
178178 ClassFile classFile3 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "file content of 3 and 4" );
@@ -194,16 +194,15 @@ public void toOutputStringOutputsFourArtifactsWhereBytecodeIsExactMatchInTwoAndE
194194 * The method should return the 2nd-to-last element in the last, but if there's only 1 element
195195 * there's no 2nd-to-last element to return.
196196 */
197- @ Test ( expected = IllegalArgumentException . class )
198- public void previousShouldThrowIfOnlyOneArtifact () throws Exception {
197+ @ Test
198+ void previousShouldThrowIfOnlyOneArtifact () throws Exception {
199199 ClassFile classFile = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "file content of 1 and 2" );
200200 ClassesWithSameName classesWithSameName = new ClassesWithSameName (LOG , classFile );
201-
202- classesWithSameName .previous ();
201+ assertThrows (IllegalArgumentException .class , () -> classesWithSameName .previous ());
203202 }
204203
205204 @ Test
206- public void previousShouldReturn2ndToLastElement () throws Exception {
205+ void previousShouldReturn2ndToLastElement () throws Exception {
207206 ClassFile classFile1 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "file content of 1 and 2" );
208207 ClassFile classFile2 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "file content of 1 and 2" );
209208 ClassesWithSameName classesWithSameName = new ClassesWithSameName (LOG , classFile1 , classFile2 );
@@ -214,7 +213,7 @@ public void previousShouldReturn2ndToLastElement() throws Exception {
214213 }
215214
216215 @ Test
217- public void addShouldAddArtifact () throws Exception {
216+ void addShouldAddArtifact () throws Exception {
218217 ClassFile classFile1 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "" );
219218 ClassFile classFile2 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "" );
220219 ClassesWithSameName classesWithSameName = new ClassesWithSameName (LOG , classFile1 );
@@ -224,25 +223,25 @@ public void addShouldAddArtifact() throws Exception {
224223 assertEquals (2 , classesWithSameName .getAllArtifactsThisClassWasFoundIn ().size ());
225224 }
226225
227- @ Test ( expected = IllegalArgumentException . class )
228- public void addShouldThrowWhenClassNameDoesNotMatch () throws Exception {
226+ @ Test
227+ void addShouldThrowWhenClassNameDoesNotMatch () throws Exception {
229228 ClassFile classFile1 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "" );
230229 ClassFile classFile2 = classFileHelper .createWithContent ("some/other/path.class" , "" );
231230 ClassesWithSameName classesWithSameName = new ClassesWithSameName (LOG , classFile1 );
232-
233- classesWithSameName .add (classFile2 );
231+ assertThrows (IllegalArgumentException .class , () -> classesWithSameName .add (classFile2 ));
234232 }
235233
236- @ Test ( expected = IllegalArgumentException . class )
237- public void constructorShouldThrowWhenClassNameDoesNotMatch () throws Exception {
234+ @ Test
235+ void constructorShouldThrowWhenClassNameDoesNotMatch () throws Exception {
238236 ClassFile classFile1 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "" );
239237 ClassFile classFile2 = classFileHelper .createWithContent ("some/other/path.class" , "" );
240-
241- new ClassesWithSameName (LOG , classFile1 , classFile2 );
238+ assertThrows (IllegalArgumentException .class , () -> {
239+ new ClassesWithSameName (LOG , classFile1 , classFile2 );
240+ });
242241 }
243242
244243 @ Test
245- public void getAllArtifactsThisClassWasFoundInShouldReturnAllArtifacts () throws Exception {
244+ void getAllArtifactsThisClassWasFoundInShouldReturnAllArtifacts () throws Exception {
246245 ClassFile classFile1 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "" );
247246 ClassFile classFile2 = classFileHelper .createWithContent (PATH_TO_CLASS_FILE , "" );
248247 ClassesWithSameName classesWithSameName = new ClassesWithSameName (LOG , classFile1 , classFile2 );
0 commit comments