From 182d2c299a387cab82e3f1a4f9f65b571be172d2 Mon Sep 17 00:00:00 2001 From: Jeremy Stein Date: Wed, 3 Jul 2024 17:27:50 +0100 Subject: [PATCH] Copy constructor checker didn't know about Double[] --- .../ucl/rits/inform/informdb/TestCopyConstructor.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/emap-star/emap-star/src/test/java/uk/ac/ucl/rits/inform/informdb/TestCopyConstructor.java b/emap-star/emap-star/src/test/java/uk/ac/ucl/rits/inform/informdb/TestCopyConstructor.java index dce1879f3..20b8ad1fe 100644 --- a/emap-star/emap-star/src/test/java/uk/ac/ucl/rits/inform/informdb/TestCopyConstructor.java +++ b/emap-star/emap-star/src/test/java/uk/ac/ucl/rits/inform/informdb/TestCopyConstructor.java @@ -32,6 +32,7 @@ public class TestCopyConstructor { "boolean", "java.lang.Boolean", "java.lang.Double", + "java.lang.Double[]", "java.lang.Long", "java.lang.String", "java.time.Instant", @@ -134,7 +135,7 @@ Class classFromName(String className) { } catch (ClassNotFoundException e) { e.printStackTrace(); - throw new RuntimeException("Failed to generate an instance of " + className); + throw new RuntimeException("Failed to generate an instance of " + className, e); } } @@ -149,7 +150,7 @@ Object defaultConstructedInstance(Class entity) { } catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) { e.printStackTrace(); - throw new RuntimeException("Failed to generate an instance of " + entity.getName()); + throw new RuntimeException("Failed to generate an instance of " + entity.getName(), e); } } @@ -176,6 +177,8 @@ Object newBaseInstance(String className) { return Instant.now(); case "java.lang.Double": return (double) INTEGERS.get(index); + case "java.lang.Double[]": + return new Double[]{(double) INTEGERS.get(index)}; case "long": case "java.lang.Long": return (long) INTEGERS.get(index); @@ -189,7 +192,7 @@ Object newBaseInstance(String className) { return List.of(); } - throw new StringIndexOutOfBoundsException("Did not find " + className + " in base types"); + throw new IllegalArgumentException("Need to add an implementation for initialising object of type: " + className); } /** @@ -224,7 +227,7 @@ void setAllFieldsOf(Class entity, Object instance) { for (Method method : setterMethodsOf(entity)) { Object[] params = Arrays.stream(method.getParameterTypes()) - .map(p -> newInstance(p.getName())) + .map(p -> newInstance(p.getTypeName())) .toArray(); try {