Polishing

This commit is contained in:
Sam Brannen
2024-08-28 14:46:12 +02:00
parent 38a56b3fda
commit 5bcfcdd0be

View File

@@ -65,50 +65,50 @@ class ReflectionTestUtilsTests {
@Test @Test
void setFieldWithNullTargetObject() { void setFieldWithNullTargetObject() {
assertThatIllegalArgumentException() assertThatIllegalArgumentException()
.isThrownBy(() -> setField((Object) null, "id", 99L)) .isThrownBy(() -> setField((Object) null, "id", 99L))
.withMessageStartingWith("Either targetObject or targetClass"); .withMessageStartingWith("Either targetObject or targetClass");
} }
@Test @Test
void getFieldWithNullTargetObject() { void getFieldWithNullTargetObject() {
assertThatIllegalArgumentException() assertThatIllegalArgumentException()
.isThrownBy(() -> getField((Object) null, "id")) .isThrownBy(() -> getField((Object) null, "id"))
.withMessageStartingWith("Either targetObject or targetClass"); .withMessageStartingWith("Either targetObject or targetClass");
} }
@Test @Test
void setFieldWithNullTargetClass() { void setFieldWithNullTargetClass() {
assertThatIllegalArgumentException() assertThatIllegalArgumentException()
.isThrownBy(() -> setField(null, "id", 99L)) .isThrownBy(() -> setField(null, "id", 99L))
.withMessageStartingWith("Either targetObject or targetClass"); .withMessageStartingWith("Either targetObject or targetClass");
} }
@Test @Test
void getFieldWithNullTargetClass() { void getFieldWithNullTargetClass() {
assertThatIllegalArgumentException() assertThatIllegalArgumentException()
.isThrownBy(() -> getField(null, "id")) .isThrownBy(() -> getField(null, "id"))
.withMessageStartingWith("Either targetObject or targetClass"); .withMessageStartingWith("Either targetObject or targetClass");
} }
@Test @Test
void setFieldWithNullNameAndNullType() { void setFieldWithNullNameAndNullType() {
assertThatIllegalArgumentException() assertThatIllegalArgumentException()
.isThrownBy(() -> setField(person, null, 99L, null)) .isThrownBy(() -> setField(person, null, 99L, null))
.withMessageStartingWith("Either name or type"); .withMessageStartingWith("Either name or type");
} }
@Test @Test
void setFieldWithBogusName() { void setFieldWithBogusName() {
assertThatIllegalArgumentException() assertThatIllegalArgumentException()
.isThrownBy(() -> setField(person, "bogus", 99L, long.class)) .isThrownBy(() -> setField(person, "bogus", 99L, long.class))
.withMessageStartingWith("Could not find field 'bogus'"); .withMessageStartingWith("Could not find field 'bogus'");
} }
@Test @Test
void setFieldWithWrongType() { void setFieldWithWrongType() {
assertThatIllegalArgumentException() assertThatIllegalArgumentException()
.isThrownBy(() -> setField(person, "id", 99L, String.class)) .isThrownBy(() -> setField(person, "id", 99L, String.class))
.withMessageStartingWith("Could not find field"); .withMessageStartingWith("Could not find field");
} }
@Test @Test
@@ -434,29 +434,29 @@ class ReflectionTestUtilsTests {
@Test @Test
void invokeInitMethodBeforeAutowiring() { void invokeInitMethodBeforeAutowiring() {
assertThatIllegalStateException() assertThatIllegalStateException()
.isThrownBy(() -> invokeMethod(component, "init")) .isThrownBy(() -> invokeMethod(component, "init"))
.withMessageStartingWith("number must not be null"); .withMessageStartingWith("number must not be null");
} }
@Test @Test
void invokeMethodWithIncompatibleArgumentTypes() { void invokeMethodWithIncompatibleArgumentTypes() {
assertThatIllegalStateException() assertThatIllegalStateException()
.isThrownBy(() -> invokeMethod(component, "subtract", "foo", 2.0)) .isThrownBy(() -> invokeMethod(component, "subtract", "foo", 2.0))
.withMessageStartingWith("Method not found"); .withMessageStartingWith("Method not found");
} }
@Test @Test
void invokeMethodWithTooFewArguments() { void invokeMethodWithTooFewArguments() {
assertThatIllegalStateException() assertThatIllegalStateException()
.isThrownBy(() -> invokeMethod(component, "configure", 42)) .isThrownBy(() -> invokeMethod(component, "configure", 42))
.withMessageStartingWith("Method not found"); .withMessageStartingWith("Method not found");
} }
@Test @Test
void invokeMethodWithTooManyArguments() { void invokeMethodWithTooManyArguments() {
assertThatIllegalStateException() assertThatIllegalStateException()
.isThrownBy(() -> invokeMethod(component, "configure", 42, "enigma", "baz", "quux")) .isThrownBy(() -> invokeMethod(component, "configure", 42, "enigma", "baz", "quux"))
.withMessageStartingWith("Method not found"); .withMessageStartingWith("Method not found");
} }
@Test // SPR-14363 @Test // SPR-14363
@@ -469,7 +469,7 @@ class ReflectionTestUtilsTests {
void setFieldOnLegacyEntityWithSideEffectsInToString() { void setFieldOnLegacyEntityWithSideEffectsInToString() {
String testCollaborator = "test collaborator"; String testCollaborator = "test collaborator";
setField(entity, "collaborator", testCollaborator, Object.class); setField(entity, "collaborator", testCollaborator, Object.class);
assertThat(entity.toString()).contains(testCollaborator); assertThat(entity).asString().contains(testCollaborator);
} }
@Test // SPR-14363 @Test // SPR-14363
@@ -489,28 +489,28 @@ class ReflectionTestUtilsTests {
void invokeSetterMethodOnLegacyEntityWithSideEffectsInToString() { void invokeSetterMethodOnLegacyEntityWithSideEffectsInToString() {
String testCollaborator = "test collaborator"; String testCollaborator = "test collaborator";
invokeSetterMethod(entity, "collaborator", testCollaborator); invokeSetterMethod(entity, "collaborator", testCollaborator);
assertThat(entity.toString()).contains(testCollaborator); assertThat(entity).asString().contains(testCollaborator);
} }
@Test @Test
void invokeStaticMethodWithNullTargetClass() { void invokeStaticMethodWithNullTargetClass() {
assertThatIllegalArgumentException() assertThatIllegalArgumentException()
.isThrownBy(() -> invokeMethod(null, null)) .isThrownBy(() -> invokeMethod(null, null))
.withMessage("Target class must not be null"); .withMessage("Target class must not be null");
} }
@Test @Test
void invokeStaticMethodWithNullMethodName() { void invokeStaticMethodWithNullMethodName() {
assertThatIllegalArgumentException() assertThatIllegalArgumentException()
.isThrownBy(() -> invokeMethod(getClass(), null)) .isThrownBy(() -> invokeMethod(getClass(), null))
.withMessage("Method name must not be empty"); .withMessage("Method name must not be empty");
} }
@Test @Test
void invokeStaticMethodWithEmptyMethodName() { void invokeStaticMethodWithEmptyMethodName() {
assertThatIllegalArgumentException() assertThatIllegalArgumentException()
.isThrownBy(() -> invokeMethod(getClass(), " ")) .isThrownBy(() -> invokeMethod(getClass(), " "))
.withMessage("Method name must not be empty"); .withMessage("Method name must not be empty");
} }
@Test @Test
@@ -550,8 +550,8 @@ class ReflectionTestUtilsTests {
@Test @Test
void invokeStaticMethodWithNullTargetObjectAndNullTargetClass() { void invokeStaticMethodWithNullTargetObjectAndNullTargetClass() {
assertThatIllegalArgumentException() assertThatIllegalArgumentException()
.isThrownBy(() -> invokeMethod(null, (Class<?>) null, "id")) .isThrownBy(() -> invokeMethod(null, (Class<?>) null, "id"))
.withMessage("Either 'targetObject' or 'targetClass' for the method must be specified"); .withMessage("Either 'targetObject' or 'targetClass' for the method must be specified");
} }
} }