Skip to content

Commit

Permalink
Merge branch 'master' into fix-e2e-co-merge-test
Browse files Browse the repository at this point in the history
  • Loading branch information
david-mackessy committed Jan 16, 2025
2 parents dfd990d + 3a5ec37 commit 9f84cde
Show file tree
Hide file tree
Showing 3 changed files with 257 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import org.hisp.dhis.jsontree.JsonArray;
import org.hisp.dhis.jsontree.JsonList;
import org.hisp.dhis.jsontree.JsonObject;
Expand Down Expand Up @@ -171,6 +173,24 @@ public static void assertHasMember(JsonObject json, String name) {
assertTrue(json.has(name), String.format("member \"%s\" should be in %s", name, json));
}

/**
* Asserts that the actual list contains an element matching the predicate. If the element is
* found, it is returned.
*
* @param actual the list to search
* @param predicate the predicate to match the element
* @param messageSubject the subject of the message in case the element is not found
* @return the element that matches the predicate
* @param <T> the type of the elements in the list
*/
public static <T extends JsonValue> T assertContains(
JsonList<T> actual, Predicate<? super T> predicate, String messageSubject) {
Optional<T> element = actual.stream().filter(predicate).findFirst();
assertTrue(
element.isPresent(), () -> String.format("%s not found in %s", messageSubject, actual));
return element.get();
}

public static <E extends JsonValue, T> void assertContainsAll(
Collection<T> expected, JsonList<E> actual, Function<E, T> toValue) {
assertFalse(
Expand Down
Loading

0 comments on commit 9f84cde

Please sign in to comment.