Polish ReflectionTestUtilsTests
This commit is contained in:
@@ -61,50 +61,50 @@ class ReflectionTestUtilsTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setFieldWithNullTargetObject() throws Exception {
|
void setFieldWithNullTargetObject() throws Exception {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException()
|
||||||
setField((Object) null, "id", Long.valueOf(99)))
|
.isThrownBy(() -> setField((Object) null, "id", Long.valueOf(99)))
|
||||||
.withMessageStartingWith("Either targetObject or targetClass");
|
.withMessageStartingWith("Either targetObject or targetClass");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getFieldWithNullTargetObject() throws Exception {
|
void getFieldWithNullTargetObject() throws Exception {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException()
|
||||||
getField((Object) null, "id"))
|
.isThrownBy(() -> getField((Object) null, "id"))
|
||||||
.withMessageStartingWith("Either targetObject or targetClass");
|
.withMessageStartingWith("Either targetObject or targetClass");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setFieldWithNullTargetClass() throws Exception {
|
void setFieldWithNullTargetClass() throws Exception {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException()
|
||||||
setField((Class<?>) null, "id", Long.valueOf(99)))
|
.isThrownBy(() -> setField((Class<?>) null, "id", Long.valueOf(99)))
|
||||||
.withMessageStartingWith("Either targetObject or targetClass");
|
.withMessageStartingWith("Either targetObject or targetClass");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getFieldWithNullTargetClass() throws Exception {
|
void getFieldWithNullTargetClass() throws Exception {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException()
|
||||||
getField((Class<?>) null, "id"))
|
.isThrownBy(() -> getField((Class<?>) null, "id"))
|
||||||
.withMessageStartingWith("Either targetObject or targetClass");
|
.withMessageStartingWith("Either targetObject or targetClass");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setFieldWithNullNameAndNullType() throws Exception {
|
void setFieldWithNullNameAndNullType() throws Exception {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException()
|
||||||
setField(person, null, Long.valueOf(99), null))
|
.isThrownBy(() -> setField(person, null, Long.valueOf(99), null))
|
||||||
.withMessageStartingWith("Either name or type");
|
.withMessageStartingWith("Either name or type");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setFieldWithBogusName() throws Exception {
|
void setFieldWithBogusName() throws Exception {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException()
|
||||||
setField(person, "bogus", Long.valueOf(99), long.class))
|
.isThrownBy(() -> setField(person, "bogus", Long.valueOf(99), long.class))
|
||||||
.withMessageStartingWith("Could not find field 'bogus'");
|
.withMessageStartingWith("Could not find field 'bogus'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void setFieldWithWrongType() throws Exception {
|
void setFieldWithWrongType() throws Exception {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException()
|
||||||
setField(person, "id", Long.valueOf(99), String.class))
|
.isThrownBy(() -> setField(person, "id", Long.valueOf(99), String.class))
|
||||||
.withMessageStartingWith("Could not find field");
|
.withMessageStartingWith("Could not find field");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,8 +316,7 @@ class ReflectionTestUtilsTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void invokeSetterMethodWithNullValueForPrimitiveBoolean() throws Exception {
|
void invokeSetterMethodWithNullValueForPrimitiveBoolean() throws Exception {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
assertThatIllegalArgumentException().isThrownBy(() -> invokeSetterMethod(person, "likesPets", null, boolean.class));
|
||||||
invokeSetterMethod(person, "likesPets", null, boolean.class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -364,29 +363,29 @@ class ReflectionTestUtilsTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void invokeInitMethodBeforeAutowiring() {
|
void invokeInitMethodBeforeAutowiring() {
|
||||||
assertThatIllegalStateException().isThrownBy(() ->
|
assertThatIllegalStateException()
|
||||||
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().isThrownBy(() ->
|
assertThatIllegalStateException()
|
||||||
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().isThrownBy(() ->
|
assertThatIllegalStateException()
|
||||||
invokeMethod(component, "configure", Integer.valueOf(42)))
|
.isThrownBy(() -> invokeMethod(component, "configure", Integer.valueOf(42)))
|
||||||
.withMessageStartingWith("Method not found");
|
.withMessageStartingWith("Method not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void invokeMethodWithTooManyArguments() {
|
void invokeMethodWithTooManyArguments() {
|
||||||
assertThatIllegalStateException().isThrownBy(() ->
|
assertThatIllegalStateException()
|
||||||
invokeMethod(component, "configure", Integer.valueOf(42), "enigma", "baz", "quux"))
|
.isThrownBy(() -> invokeMethod(component, "configure", Integer.valueOf(42), "enigma", "baz", "quux"))
|
||||||
.withMessageStartingWith("Method not found");
|
.withMessageStartingWith("Method not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user