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

Commit af9c66e

Browse files
authored
just fall back to simple class name (#397)
1 parent b39239a commit af9c66e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

spring-auto-restdocs-core/src/main/java/capital/scalable/restdocs/constraints/HumanReadableConstraintResolver.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ private String humanReadableString(Object o) {
8888
try {
8989
return ((Class) o).newInstance().toString();
9090
} catch (InstantiationException | IllegalAccessException e) {
91-
log.error("Failed to create an instance of {}", ((Class) o).getCanonicalName(), e);
92-
return "Failed to create an instance of " + ((Class) o).getCanonicalName() +
93-
". Does the class have a no args constructor?";
91+
return ((Class) o).getSimpleName();
9492
}
9593
} else {
9694
return o.toString();

spring-auto-restdocs-core/src/test/java/capital/scalable/restdocs/constraints/HumanReadableConstraintResolverTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public void testHumanReadable() {
5858
configuration.put("class", CustomConstraint.class);
5959
configuration.put("groups", new Class<?>[]{Update.class});
6060
configuration.put("payload", new Class<?>[0]);
61+
configuration.put("ref", Entity.class);
6162
Constraint constraint = new Constraint("Custom", configuration);
6263

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

71-
constraints = resolver.resolveForParameter(Mockito.mock(MethodParameter.class));
72+
constraints = resolver.resolveForParameter(mock(MethodParameter.class));
7273
assertConstraints(constraints);
7374
}
7475

7576
private void assertConstraints(List<Constraint> constraints) {
7677
assertThat(constraints.size(), is(1));
77-
assertThat(constraints.get(0).getConfiguration().size(), is(7));
78+
assertThat(constraints.get(0).getConfiguration().size(), is(8));
7879
assertThat(constraints.get(0).getConfiguration().get("primitive").toString(), is("1"));
7980
assertThat(constraints.get(0).getConfiguration().get("wrapper").toString(), is("1"));
8081
assertThat(constraints.get(0).getConfiguration().get("object").toString(), is("I'm Peter"));
@@ -85,6 +86,7 @@ private void assertConstraints(List<Constraint> constraints) {
8586
// groups and payload belong to the fields that is not touched
8687
assertThat(constraints.get(0).getConfiguration().get("groups"), instanceOf(Class[].class));
8788
assertThat(constraints.get(0).getConfiguration().get("payload"), instanceOf(Class[].class));
89+
assertThat(constraints.get(0).getConfiguration().get("ref").toString(), is("Entity"));
8890
}
8991

9092
static class CustomObj {
@@ -106,4 +108,9 @@ public String toString() {
106108
return "I'm custom constraint";
107109
}
108110
}
111+
112+
static class Entity {
113+
Entity(String name) {
114+
}
115+
}
109116
}

0 commit comments

Comments
 (0)