diff --git a/core/src/test/java/io/parsingdata/metal/AutoEqualityTest.java b/core/src/test/java/io/parsingdata/metal/AutoEqualityTest.java index f2ebc5f6..3b48da82 100644 --- a/core/src/test/java/io/parsingdata/metal/AutoEqualityTest.java +++ b/core/src/test/java/io/parsingdata/metal/AutoEqualityTest.java @@ -52,8 +52,9 @@ import java.lang.reflect.Modifier; import java.math.BigInteger; import java.net.URL; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; @@ -202,7 +203,7 @@ public class AutoEqualityTest { private static final List> STRINGS = List.of(() -> "a", () -> "b"); private static final List> STRING_ARRAYS = List.of(() -> new String[] {"a"}, () -> new String[] {"b"}, () -> new String[] {"a", "b"}, () -> new String[] {"b", "c"}, () -> new String[] {"a", "b", "c"}); - private static final List> ENCODINGS = List.of(EncodingFactory::enc, EncodingFactory::signed, EncodingFactory::le, () -> new Encoding(Charset.forName("UTF-8"))); + private static final List> ENCODINGS = List.of(EncodingFactory::enc, EncodingFactory::signed, EncodingFactory::le, () -> new Encoding(StandardCharsets.UTF_8)); private static final List> TOKENS = List.of(() -> any("a"), () -> any("b")); private static final List> TOKEN_ARRAYS = List.of(() -> new Token[] { any("a"), any("b")}, () -> new Token[] { any("b"), any("c") }, () -> new Token[] { any("a"), any("b"), any("c") }); private static final List> SINGLE_VALUE_EXPRESSIONS = List.of(() -> con(1), () -> con(2)); @@ -221,10 +222,11 @@ public class AutoEqualityTest { private static final List> BYTE_STREAMS = List.of(() -> new InMemoryByteStream(new byte[] { 1, 2 }), () -> DUMMY_STREAM); private static final List> BIG_INTEGERS = List.of(() -> ONE, () -> BigInteger.valueOf(3)); private static final List> PARSE_STATES = List.of(() -> createFromByteStream(DUMMY_STREAM), () -> createFromByteStream(DUMMY_STREAM, ONE), () -> new ParseState(GRAPH_WITH_REFERENCE, NO_CACHE, DUMMY_BYTE_STREAM_SOURCE, TEN, new ImmutableList<>(), new ImmutableList<>())); - private static final List> PARSE_VALUE_CACHES = List.of(() -> NO_CACHE, () -> new ParseValueCache(), () -> new ParseValueCache().add(PARSE_VALUE), () -> new ParseValueCache().add(PARSE_VALUE).add(PARSE_VALUE)); + private static final List> PARSE_VALUE_CACHES = List.of(() -> NO_CACHE, ParseValueCache::new, () -> new ParseValueCache().add(PARSE_VALUE), () -> new ParseValueCache().add(PARSE_VALUE).add(PARSE_VALUE)); private static final List> IMMUTABLE_LISTS = List.of(ImmutableList::new, () -> ImmutableList.create("TEST"), () -> ImmutableList.create(1), () -> ImmutableList.create(1).add(2)); private static final List> BOOLEANS = List.of(() -> true, () -> false); private static final List> BIPREDICATES = List.of(() -> (BiPredicate) (o, o2) -> false); + private static final List> MAPS = List.of(Map::of, () -> Map.of("1", 1, "2", 2)); private static final Map, List>> mapping = buildMap(); private static Map, List>> buildMap() { @@ -254,6 +256,7 @@ private static Map, List>> buildMap() { result.put(ImmutableList.class, IMMUTABLE_LISTS); result.put(boolean.class, BOOLEANS); result.put(BiPredicate.class, BIPREDICATES); + result.put(Map.class, MAPS); return result; } @@ -313,31 +316,38 @@ private static Class getClass(final String className) { private static Collection generateObjectArrays(final Set> classes) throws IllegalAccessException, InstantiationException, InvocationTargetException { Collection results = new ArrayList<>(); for (Class c : classes) { - results.add(generateObjectArrays(c)); + results.addAll(generateObjectArrays(c)); } return results; } - private static Arguments generateObjectArrays(final Class c) throws IllegalAccessException, InvocationTargetException, InstantiationException { - Constructor cons = c.getDeclaredConstructors()[0]; - cons.setAccessible(true); - List>> args = new ArrayList<>(); - for (Class cl : cons.getParameterTypes()) { - if (!mapping.containsKey(cl)) { - throw new AssertionError("Please add a mapping for type " + cl.getSimpleName()); + private static List generateObjectArrays(final Class c) throws IllegalAccessException, InvocationTargetException, InstantiationException { + final List arguments = new ArrayList<>(); + for (Constructor cons : c.getDeclaredConstructors()) { + final boolean containsGenericArgument = Arrays.stream(cons.getParameterTypes()).anyMatch(p -> p == Object.class); + if (containsGenericArgument) { + break; } - args.add(mapping.get(cl)); - } - List>> argLists = generateCombinations(0, args); - List otherInstances = new ArrayList<>(); - for (List> argList : argLists.subList(1, argLists.size())) { - otherInstances.add(cons.newInstance(instantiate(argList).toArray())); + cons.setAccessible(true); + List>> args = new ArrayList<>(); + for (Class cl : cons.getParameterTypes()) { + if (!mapping.containsKey(cl)) { + throw new AssertionError("Please add a mapping for type " + cl.getSimpleName()); + } + args.add(mapping.get(cl)); + } + List>> argLists = generateCombinations(0, args); + List otherInstances = new ArrayList<>(); + for (List> argList : argLists.subList(1, argLists.size())) { + otherInstances.add(cons.newInstance(instantiate(argList).toArray())); + } + arguments.add(Arguments.arguments( + cons.newInstance(instantiate(argLists.get(0)).toArray()), + cons.newInstance(instantiate(argLists.get(0)).toArray()), + otherInstances.toArray() + )); } - return Arguments.arguments( - cons.newInstance(instantiate(argLists.get(0)).toArray()), - cons.newInstance(instantiate(argLists.get(0)).toArray()), - otherInstances.toArray() - ); + return arguments; } private static List>> generateCombinations(final int index, final List>> args) {