2323import static org .eclipse .core .tests .resources .ResourceTestUtil .createTestMonitor ;
2424import static org .eclipse .core .tests .resources .ResourceTestUtil .createUniqueString ;
2525import static org .eclipse .core .tests .resources .ResourceTestUtil .waitForEncodingRelatedJobs ;
26- import static org .junit .Assert .assertFalse ;
27- import static org .junit .Assert .assertThrows ;
28- import static org .junit .Assert .assertTrue ;
26+ import static org .junit .jupiter . api . Assertions .assertFalse ;
27+ import static org .junit .jupiter . api . Assertions .assertThrows ;
28+ import static org .junit .jupiter . api . Assertions .assertTrue ;
2929
3030import java .io .DataInputStream ;
3131import java .io .DataOutputStream ;
6565import org .eclipse .core .runtime .jobs .Job ;
6666import org .eclipse .core .runtime .preferences .IEclipsePreferences ;
6767import org .eclipse .core .runtime .preferences .InstanceScope ;
68- import org .junit .After ;
69- import org .junit .Before ;
70- import org .junit .Rule ;
71- import org .junit .Test ;
72- import org .junit .rules .TestName ;
73-
68+ import org .eclipse .core .tests .resources .util .WorkspaceResetExtension ;
69+ import org .junit .jupiter .api .AfterEach ;
70+ import org .junit .jupiter .api .BeforeEach ;
71+ import org .junit .jupiter .api .Test ;
72+ import org .junit .jupiter .api .TestInfo ;
73+ import org .junit .jupiter .api .extension .ExtendWith ;
74+
75+ @ ExtendWith (WorkspaceResetExtension .class )
7476public class MarkerTest {
7577
76- @ Rule
77- public TestName testName = new TestName ();
78-
79- @ Rule
80- public WorkspaceTestRule workspaceRule = new WorkspaceTestRule ();
81-
8278 public static final String TRANSIENT_MARKER = "org.eclipse.core.tests.resources.transientmarker" ;
8379 public static final String TEST_PROBLEM_MARKER = "org.eclipse.core.tests.resources.testproblem" ;
8480
@@ -128,8 +124,8 @@ protected void assertMarkersDoNotExist(IMarker[] markers) {
128124 }
129125
130126 protected void assertMarkerDoesNotExist (IMarker marker ) {
131- assertFalse (String . format ( " marker '%s' exists unexpectedly for resource '%s'" , marker , marker . getResource () ),
132- marker . exists ( ));
127+ assertFalse (marker . exists ( ),
128+ String . format ( "marker '%s' exists unexpectedly for resource '%s'" , marker , marker . getResource () ));
133129 }
134130
135131 protected void assertMarkersExist (IMarker [] markers ) {
@@ -139,8 +135,8 @@ protected void assertMarkersExist(IMarker[] markers) {
139135 }
140136
141137 protected void assertMarkerExists (IMarker marker ) {
142- assertTrue (String . format ( " marker '%s' does not exist for resource '%s'" , marker , marker . getResource () ),
143- marker . exists ( ));
138+ assertTrue (marker . exists ( ),
139+ String . format ( " marker '%s' does not exist for resource '%s'" , marker , marker . getResource () ));
144140 }
145141
146142 private void assertMarkerHasAttributeValue (IMarker marker , String attributeName , Object expectedValue )
@@ -161,11 +157,11 @@ private void assertSingleMarkerWithId(IMarker[] markers, long id) {
161157 }
162158
163159 private void assertMarkerIsSubtype (IMarker marker , String superType ) throws CoreException {
164- assertTrue (String .format ("Marker '%s' is no subtype of %s" , marker , superType ), marker . isSubtypeOf ( superType ));
160+ assertTrue (marker . isSubtypeOf ( superType ), String .format ("Marker '%s' is no subtype of %s" , marker , superType ));
165161 }
166162
167163 private void assertMarkerIsNoSubtype (IMarker marker , String superType ) throws CoreException {
168- assertFalse (String .format ("Marker '%s' is subtype of %s" , marker , superType ), marker . isSubtypeOf ( superType ));
164+ assertFalse (marker . isSubtypeOf ( superType ), String .format ("Marker '%s' is subtype of %s" , marker , superType ));
169165 }
170166
171167 public IResource [] createLargeHierarchy () throws CoreException {
@@ -193,7 +189,7 @@ public void createProblem(IResource host, int severity) throws CoreException {
193189 marker .setAttribute (IMarker .SEVERITY , severity );
194190 }
195191
196- @ Before
192+ @ BeforeEach
197193 public void setUp () throws Exception {
198194 resources = buildResources (getWorkspace ().getRoot (),
199195 new String [] { "/" , "1/" , "1/1" , "1/2/" , "1/2/1" , "1/2/2/" , "2/" , "2/1" , "2/2/" , "2/2/1" , "2/2/2/" });
@@ -208,7 +204,7 @@ public void setUp() throws Exception {
208204 }
209205
210206
211- @ After
207+ @ AfterEach
212208 public void tearDown () throws Exception {
213209 if (registeredResourceChangeLister != null ) {
214210 setResourceChangeListener (null );
@@ -283,14 +279,14 @@ public void testCreateMarker() throws CoreException {
283279 assertMarkersExist (markers );
284280 listener .assertNumberOfAffectedResources (1 );
285281 listener .assertChanges (resource , markers , null , null );
286- assertThrows (resource . getFullPath (). toString (), RuntimeException .class , () -> resource .createMarker (null ));
282+ assertThrows (RuntimeException .class , () -> resource .createMarker (null ), resource . getFullPath (). toString ( ));
287283 }
288284
289285 // try creating a marker on a resource which does't exist
290286 IResource testResource = getWorkspace ().getRoot ().getFile (IPath .fromOSString ("non/existant/resource" ));
291- assertFalse ("resource should not exist: " + testResource , testResource . exists () );
292- assertThrows (testResource . getFullPath (). toString (), CoreException . class ,
293- () -> testResource .createMarker ( IMarker . PROBLEM ));
287+ assertFalse (testResource . exists (), "resource should not exist: " + testResource );
288+ assertThrows (CoreException . class , () -> testResource . createMarker ( IMarker . PROBLEM ) ,
289+ testResource .getFullPath (). toString ( ));
294290 }
295291
296292 @ Test
@@ -325,9 +321,10 @@ public void testCreateNullMarkerWithAttributesShouldFail() {
325321 public void testCreateMarkerWithAttributesOnAResourceWhichDoesNotExistShouldFail () {
326322 // try creating a marker on a resource which does't exist
327323 IResource testResource = getWorkspace ().getRoot ().getFile (IPath .fromOSString ("non/existant/resource" ));
328- assertFalse ("resource should not exist: " + testResource , testResource .exists ());
329- assertThrows (testResource .getFullPath ().toString (), CoreException .class ,
330- () -> testResource .createMarker (IMarker .PROBLEM , Map .of (IMarker .MESSAGE , "My text" )));
324+ assertFalse (testResource .exists (), "resource should not exist: " + testResource );
325+ assertThrows (CoreException .class ,
326+ () -> testResource .createMarker (IMarker .PROBLEM , Map .of (IMarker .MESSAGE , "My text" )),
327+ testResource .getFullPath ().toString ());
331328 }
332329
333330 // testing that markers creation and calling setAttribute trigger multiple
@@ -907,14 +904,14 @@ public void testMarkerDeltasMerge() throws CoreException {
907904 * Tests the appearance of marker changes in the resource delta.
908905 */
909906 @ Test
910- public void testMarkerDeltasMoveFolder () throws CoreException {
907+ public void testMarkerDeltasMoveFolder (TestInfo testInfo ) throws CoreException {
911908 IWorkspaceRoot root = getWorkspace ().getRoot ();
912909 final IProject project = root .getProject ("MyProject" );
913910 IFolder folder = project .getFolder ("folder" );
914911 IFile file = project .getFile ("file.txt" );
915912 IFile subFile = folder .getFile ("subFile.txt" );
916913 createInWorkspace (new IResource [] { project , folder , file , subFile });
917- waitForEncodingRelatedJobs (testName . getMethodName ());
914+ waitForEncodingRelatedJobs (testInfo . getDisplayName ());
918915 IFolder destFolder = project .getFolder ("myOtherFolder" );
919916 IFile destSubFile = destFolder .getFile (subFile .getName ());
920917
@@ -947,14 +944,14 @@ public void testMarkerDeltasMoveFolder() throws CoreException {
947944 * Tests the appearance of marker changes in the resource delta.
948945 */
949946 @ Test
950- public void testMarkerDeltasMoveFile () throws CoreException {
947+ public void testMarkerDeltasMoveFile (TestInfo testInfo ) throws CoreException {
951948 IWorkspaceRoot root = getWorkspace ().getRoot ();
952949 final IProject project = root .getProject ("MyProject" );
953950 IFolder folder = project .getFolder ("folder" );
954951 IFile file = project .getFile ("file.txt" );
955952 IFile subFile = folder .getFile ("subFile.txt" );
956953 createInWorkspace (new IResource [] { project , folder , file , subFile });
957- waitForEncodingRelatedJobs (testName . getMethodName ());
954+ waitForEncodingRelatedJobs (testInfo . getDisplayName ());
958955 IFile destFile = folder .getFile (file .getName ());
959956 IFile destSubFile = project .getFile (subFile .getName ());
960957
@@ -1109,7 +1106,7 @@ public String requestName() {
11091106 assertThat (actual ).containsExactlyInAnyOrder (expected );
11101107
11111108 // cleanup
1112- assertTrue ("deleting file failed" , file .delete ());
1109+ assertTrue (file .delete ());
11131110 }
11141111
11151112 @ Test
@@ -1198,7 +1195,7 @@ public String requestName() {
11981195 assertThat (actual ).containsExactlyInAnyOrder (expected );
11991196
12001197 // cleanup
1201- assertTrue ("deleting file failed" , file .delete ());
1198+ assertTrue (file .delete ());
12021199 }
12031200
12041201 /**
@@ -1260,22 +1257,23 @@ public void testSetGetAttribute() throws CoreException {
12601257 assertThat (marker .getAttributes ()).as (resourcePath ).isEqualTo (originalMap );
12611258
12621259 // try sending null as args
1263- assertThrows (resourcePath , RuntimeException .class , () -> marker .getAttribute (null ));
1264- assertThrows (resourcePath , RuntimeException .class , () -> marker .getAttributes (null ));
1265- assertThrows (resourcePath , RuntimeException .class , () -> marker .setAttribute (null , createRandomString ()));
1266- assertThrows (resourcePath , RuntimeException .class ,
1267- () -> marker .setAttributes (null , new String [] { createRandomString () }));
1268- assertThrows (resourcePath , RuntimeException .class ,
1269- () -> marker . setAttributes ( new String [] { IMarker . MESSAGE }, null ) );
1260+ assertThrows (RuntimeException .class , () -> marker .getAttribute (null ), resourcePath );
1261+ assertThrows (RuntimeException .class , () -> marker .getAttributes (null ), resourcePath );
1262+ assertThrows (RuntimeException .class , () -> marker .setAttribute (null , createRandomString ()), resourcePath );
1263+ assertThrows (RuntimeException .class ,
1264+ () -> marker .setAttributes (null , new String [] { createRandomString () }), resourcePath );
1265+ assertThrows (RuntimeException .class , () -> marker . setAttributes ( new String [] { IMarker . MESSAGE }, null ) ,
1266+ resourcePath );
12701267 //set attributes on deleted marker
12711268 marker .delete ();
1272- assertThrows (resourcePath , CoreException .class , () -> marker .setAttribute (IMarker .MESSAGE , "Hello" ));
1273- assertThrows (resourcePath , CoreException .class ,
1269+ assertThrows (CoreException .class , () -> marker .setAttribute (IMarker .MESSAGE , "Hello" ), resourcePath );
1270+ assertThrows (CoreException .class ,
12741271 () -> marker .setAttributes (new String [] { IMarker .LINE_NUMBER },
1275- new Object [] { Integer .valueOf (4 ) }));
1272+ new Object [] { Integer .valueOf (4 ) }),
1273+ resourcePath );
12761274 HashMap <String , String > attributes = new HashMap <>();
12771275 attributes .put (IMarker .MESSAGE , "Hello" );
1278- assertThrows (resourcePath , CoreException .class , () -> marker .setAttributes (attributes ));
1276+ assertThrows (CoreException .class , () -> marker .setAttributes (attributes ), resourcePath );
12791277 }
12801278 }
12811279
@@ -1341,16 +1339,16 @@ public void testSetGetAttribute2() throws CoreException {
13411339 assertThat (marker .getAttributes ()).as (resourcePath ).isEqualTo (originalMap );
13421340
13431341 // try sending null as args
1344- assertThrows (resourcePath , RuntimeException .class , () -> marker .getAttribute (null ));
1345- assertThrows (resourcePath , RuntimeException .class , () -> marker .getAttribute (null , "default" ));
1346- assertThrows (resourcePath , RuntimeException .class , () -> marker .getAttribute (null , true ));
1347- assertThrows (resourcePath , RuntimeException .class , () -> marker .getAttribute (null , 5 ));
1348- assertThrows (resourcePath , RuntimeException .class , () -> marker .getAttributes (null ));
1349- assertThrows (resourcePath , RuntimeException .class , () -> marker .setAttribute (null , createRandomString ()));
1350- assertThrows (resourcePath , RuntimeException .class ,
1351- () -> marker .setAttributes (null , new String [] { createRandomString () }));
1352- assertThrows (resourcePath , RuntimeException .class ,
1353- () -> marker . setAttributes ( new String [] { IMarker . MESSAGE }, null ) );
1342+ assertThrows (RuntimeException .class , () -> marker .getAttribute (null ), resourcePath );
1343+ assertThrows (RuntimeException .class , () -> marker .getAttribute (null , "default" ), resourcePath );
1344+ assertThrows (RuntimeException .class , () -> marker .getAttribute (null , true ), resourcePath );
1345+ assertThrows (RuntimeException .class , () -> marker .getAttribute (null , 5 ), resourcePath );
1346+ assertThrows (RuntimeException .class , () -> marker .getAttributes (null ), resourcePath );
1347+ assertThrows (RuntimeException .class , () -> marker .setAttribute (null , createRandomString ()), resourcePath );
1348+ assertThrows (RuntimeException .class ,
1349+ () -> marker .setAttributes (null , new String [] { createRandomString () }), resourcePath );
1350+ assertThrows (RuntimeException .class , () -> marker . setAttributes ( new String [] { IMarker . MESSAGE }, null ) ,
1351+ resourcePath );
13541352
13551353 Map <String , Object > retrievedAttributes = marker .getAttributes ();
13561354 retrievedAttributes .put ("1" , null ); // allowed for clients using IMarker.getAttributes()
@@ -1363,7 +1361,7 @@ public void testSetGetAttribute2() throws CoreException {
13631361 Map <String , Object > reretrievedAttributes = marker .getAttributes ();
13641362 reretrievedAttributes .put (null , 1 ); // allowed for clients using IMarker.getAttributes()
13651363 // not allowed for clients to put null key
1366- assertThrows (resourcePath , RuntimeException .class , () -> marker .setAttributes (reretrievedAttributes ));
1364+ assertThrows (RuntimeException .class , () -> marker .setAttributes (reretrievedAttributes ), resourcePath );
13671365 assertThat (marker .getAttribute ("2" )).as (resourcePath ).isNotNull ();
13681366 assertThat (marker .getAttributes ()).as (resourcePath ).isNotNull ();
13691367 marker .setAttributes (null );
0 commit comments