1717import static org .assertj .core .api .Assertions .assertThat ;
1818
1919import java .util .ArrayList ;
20+ import java .util .Arrays ;
2021import java .util .Collections ;
2122import java .util .List ;
2223import java .util .Map ;
2930import org .eclipse .core .resources .IResourceChangeListener ;
3031import org .eclipse .core .resources .IResourceDelta ;
3132import org .eclipse .core .runtime .IPath ;
33+ import org .junit .jupiter .api .Assertions ;
3234
3335/**
3436 * A support class for the marker tests.
@@ -41,31 +43,44 @@ public MarkersChangeListener() {
4143 }
4244
4345 /**
44- * Asserts whether the changes for the given resource (or null for the workspace)
45- * are exactly the added, removed and changed markers given. The arrays may be null.
46+ * Asserts whether the changes for the given resource (or null for the
47+ * workspace) are exactly the added, removed and changed markers given. The
48+ * arrays may be null.
4649 */
4750 public void assertChanges (IResource resource , IMarker [] added , IMarker [] removed , IMarker [] changed ) {
4851 IPath path = resource == null ? IPath .ROOT : resource .getFullPath ();
4952 Supplier <List <IMarkerDelta >> changesRetriever = () -> changes .getOrDefault (path , Collections .emptyList ());
50- int numChanges = (added == null ? 0 : added .length ) + (removed == null ? 0 : removed .length ) + (changed == null ? 0 : changed .length );
51- TestUtil .waitForCondition (() -> changesRetriever .get ().size () == numChanges , 5000 );
52- assertThat (numChanges ).as ("number of markers for resource %s" , path ).isEqualTo (changesRetriever .get ().size ());
53-
54- for (IMarkerDelta delta : changesRetriever .get ()) {
55- switch (delta .getKind ()) {
56- case IResourceDelta .ADDED :
57- assertThat (added ).as ("check added markers contain resource %s" , path ).contains (delta .getMarker ());
58- break ;
59- case IResourceDelta .REMOVED :
60- assertThat (removed ).as ("check removed markers contain resource %s" , path ).contains (delta .getMarker ());
61- break ;
62- case IResourceDelta .CHANGED :
63- assertThat (changed ).as ("check changed markers contain resource %s" , path ).contains (delta .getMarker ());
64- break ;
65- default :
66- throw new IllegalArgumentException ("delta with unsupported kind: " + delta );
67- }
68- }
53+
54+ int expectedTotal = (added == null ? 0 : added .length ) + (removed == null ? 0 : removed .length )
55+ + (changed == null ? 0 : changed .length );
56+
57+ TestUtil .waitForCondition (() -> changesRetriever .get ().size () == expectedTotal , 5000 );
58+
59+ List <IMarkerDelta > deltas = new ArrayList <>(changesRetriever .get ());
60+
61+ List <IMarker > actualAdded = deltas .stream ().filter (d -> d .getKind () == IResourceDelta .ADDED )
62+ .map (IMarkerDelta ::getMarker ).toList ();
63+ List <IMarker > actualRemoved = deltas .stream ().filter (d -> d .getKind () == IResourceDelta .REMOVED )
64+ .map (IMarkerDelta ::getMarker ).toList ();
65+ List <IMarker > actualChanged = deltas .stream ().filter (d -> d .getKind () == IResourceDelta .CHANGED )
66+ .map (IMarkerDelta ::getMarker ).toList ();
67+
68+ List <IMarker > expectedAdded = added == null ? Collections .emptyList () : Arrays .asList (added );
69+ List <IMarker > expectedRemoved = removed == null ? Collections .emptyList () : Arrays .asList (removed );
70+ List <IMarker > expectedChanged = changed == null ? Collections .emptyList () : Arrays .asList (changed );
71+
72+ List <IMarkerDelta > unsupported = deltas .stream ().filter (d -> d .getKind () != IResourceDelta .ADDED
73+ && d .getKind () != IResourceDelta .REMOVED && d .getKind () != IResourceDelta .CHANGED ).toList ();
74+
75+ Assertions .assertAll (String .format ("marker delta assertions for resource %s" , path ),
76+ () -> assertThat (deltas ).as ("number of marker deltas for resource %s" , path ).hasSize (expectedTotal ),
77+ () -> assertThat (actualAdded ).as ("added markers for resource %s" , path )
78+ .containsExactlyInAnyOrderElementsOf (expectedAdded ),
79+ () -> assertThat (actualRemoved ).as ("removed markers for resource %s" , path )
80+ .containsExactlyInAnyOrderElementsOf (expectedRemoved ),
81+ () -> assertThat (actualChanged ).as ("changed markers for resource %s" , path )
82+ .containsExactlyInAnyOrderElementsOf (expectedChanged ),
83+ () -> assertThat (unsupported ).as ("unsupported delta kinds for resource %s" , path ).isEmpty ());
6984 }
7085
7186 /**
0 commit comments