Skip to content

Commit

Permalink
Copy constructor checker didn't know about Double[]
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyestein committed Jul 3, 2024
1 parent 7b9b01a commit 182d2c2
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 182d2c2

Please sign in to comment.