diff --git a/approvaltests-util-tests/src/test/java/org/lambda/query/QueryableTest.java b/approvaltests-util-tests/src/test/java/org/lambda/query/QueryableTest.java index 460f500b..c068f151 100644 --- a/approvaltests-util-tests/src/test/java/org/lambda/query/QueryableTest.java +++ b/approvaltests-util-tests/src/test/java/org/lambda/query/QueryableTest.java @@ -9,6 +9,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map.Entry; +import java.util.Set; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -212,4 +213,18 @@ void testRecursive() Queryable integers = Queryable.as(48, 8); Approvals.verifyAll("", integers.selectRecursivelyUntil(i -> i / 2, i -> i <= 1)); } + @Test + void testOf() + { + Approvals.settings().allowMultipleVerifyCallsForThisMethod(); + verifyQueryable(Queryable.of(1, 2, 3)); + verifyQueryable(Queryable.of(Set.of(1, 2, 3))); + verifyQueryable(Queryable.as(Set.of(1, 2, 3))); + verifyQueryable(Queryable.of(Set.of(1, 2, 3), Integer.class)); + verifyQueryable(Queryable.as(Set.of(1, 2, 3), Integer.class)); + } + private static void verifyQueryable(Queryable queryable) + { + Approvals.verifyAll("", queryable.orderBy(i -> i)); + } } diff --git a/approvaltests-util-tests/src/test/java/org/lambda/query/QueryableTest.testOf.approved.txt b/approvaltests-util-tests/src/test/java/org/lambda/query/QueryableTest.testOf.approved.txt new file mode 100644 index 00000000..eab3a13d --- /dev/null +++ b/approvaltests-util-tests/src/test/java/org/lambda/query/QueryableTest.testOf.approved.txt @@ -0,0 +1,3 @@ +[0] = 1 +[1] = 2 +[2] = 3 diff --git a/approvaltests-util/src/main/java/org/lambda/query/Queryable.java b/approvaltests-util/src/main/java/org/lambda/query/Queryable.java index 66340990..eaa66763 100644 --- a/approvaltests-util/src/main/java/org/lambda/query/Queryable.java +++ b/approvaltests-util/src/main/java/org/lambda/query/Queryable.java @@ -12,6 +12,7 @@ import java.util.Collection; import java.util.List; import java.util.Map.Entry; +import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -130,6 +131,14 @@ public static Queryable of(List list, Class type) { return as(list, type); } + public static Queryable of(Set set) + { + return as(set); + } + public static Queryable of(Set set, Class type) + { + return as(set, type); + } public static Queryable of(T... array) { return as(array); @@ -151,6 +160,14 @@ public static Queryable as(List list, Class type) q.addAll(list); return q; } + public static Queryable as(Set set) + { + return as(new ArrayList<>(set)); + } + public static Queryable as(Set set, Class type) + { + return as(new ArrayList<>(set), type); + } public static Queryable as(T... array) { return as(Arrays.asList(array), (Class) array.getClass().getComponentType());