Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

just fall back to simple class name #397

Merged
merged 1 commit into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ private String humanReadableString(Object o) {
try {
return ((Class) o).newInstance().toString();
} catch (InstantiationException | IllegalAccessException e) {
log.error("Failed to create an instance of {}", ((Class) o).getCanonicalName(), e);
return "Failed to create an instance of " + ((Class) o).getCanonicalName() +
". Does the class have a no args constructor?";
return ((Class) o).getSimpleName();
}
} else {
return o.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void testHumanReadable() {
configuration.put("class", CustomConstraint.class);
configuration.put("groups", new Class<?>[]{Update.class});
configuration.put("payload", new Class<?>[0]);
configuration.put("ref", Entity.class);
Constraint constraint = new Constraint("Custom", configuration);

when(delegate.resolveForProperty("prop", this.getClass()))
Expand All @@ -68,13 +69,13 @@ public void testHumanReadable() {
List<Constraint> constraints = resolver.resolveForProperty("prop", this.getClass());
assertConstraints(constraints);

constraints = resolver.resolveForParameter(Mockito.mock(MethodParameter.class));
constraints = resolver.resolveForParameter(mock(MethodParameter.class));
assertConstraints(constraints);
}

private void assertConstraints(List<Constraint> constraints) {
assertThat(constraints.size(), is(1));
assertThat(constraints.get(0).getConfiguration().size(), is(7));
assertThat(constraints.get(0).getConfiguration().size(), is(8));
assertThat(constraints.get(0).getConfiguration().get("primitive").toString(), is("1"));
assertThat(constraints.get(0).getConfiguration().get("wrapper").toString(), is("1"));
assertThat(constraints.get(0).getConfiguration().get("object").toString(), is("I'm Peter"));
Expand All @@ -85,6 +86,7 @@ private void assertConstraints(List<Constraint> constraints) {
// groups and payload belong to the fields that is not touched
assertThat(constraints.get(0).getConfiguration().get("groups"), instanceOf(Class[].class));
assertThat(constraints.get(0).getConfiguration().get("payload"), instanceOf(Class[].class));
assertThat(constraints.get(0).getConfiguration().get("ref").toString(), is("Entity"));
}

static class CustomObj {
Expand All @@ -106,4 +108,9 @@ public String toString() {
return "I'm custom constraint";
}
}

static class Entity {
Entity(String name) {
}
}
}