Search in sources :

Example 6 with TestObject

use of org.springframework.tests.sample.objects.TestObject in project spring-framework by spring-projects.

the class ReflectionUtilsTests method rejectsNullDest.

@Test
void rejectsNullDest() {
    TestObject src = new TestObject();
    String dest = null;
    assertThatIllegalArgumentException().isThrownBy(() -> ReflectionUtils.shallowCopyFieldState(src, dest));
}
Also used : TestObject(org.springframework.tests.sample.objects.TestObject) Test(org.junit.jupiter.api.Test)

Example 7 with TestObject

use of org.springframework.tests.sample.objects.TestObject in project spring-framework by spring-projects.

the class ReflectionUtilsTests method invokeMethod.

@Test
void invokeMethod() throws Exception {
    String rob = "Rob Harrop";
    TestObject bean = new TestObject();
    bean.setName(rob);
    Method getName = TestObject.class.getMethod("getName");
    Method setName = TestObject.class.getMethod("setName", String.class);
    Object name = ReflectionUtils.invokeMethod(getName, bean);
    assertThat(name).as("Incorrect name returned").isEqualTo(rob);
    String juergen = "Juergen Hoeller";
    ReflectionUtils.invokeMethod(setName, bean, juergen);
    assertThat(bean.getName()).as("Incorrect name set").isEqualTo(juergen);
}
Also used : TestObject(org.springframework.tests.sample.objects.TestObject) TestObject(org.springframework.tests.sample.objects.TestObject) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 8 with TestObject

use of org.springframework.tests.sample.objects.TestObject in project spring-framework by spring-projects.

the class ReflectionUtilsTests method testValidCopy.

private void testValidCopy(TestObject src, TestObject dest) {
    src.setName("freddie");
    src.setAge(15);
    src.setSpouse(new TestObject());
    assertThat(src.getAge() == dest.getAge()).isFalse();
    ReflectionUtils.shallowCopyFieldState(src, dest);
    assertThat(dest.getAge()).isEqualTo(src.getAge());
    assertThat(dest.getSpouse()).isEqualTo(src.getSpouse());
}
Also used : TestObject(org.springframework.tests.sample.objects.TestObject)

Example 9 with TestObject

use of org.springframework.tests.sample.objects.TestObject in project spring-framework by spring-projects.

the class ReflectionUtilsTests method validCopy.

@Test
void validCopy() {
    TestObject src = new TestObject();
    TestObject dest = new TestObject();
    testValidCopy(src, dest);
}
Also used : TestObject(org.springframework.tests.sample.objects.TestObject) Test(org.junit.jupiter.api.Test)

Example 10 with TestObject

use of org.springframework.tests.sample.objects.TestObject in project spring-framework by spring-projects.

the class ReflectionUtilsTests method rejectsNullSrc.

@Test
void rejectsNullSrc() {
    TestObject src = null;
    String dest = new String();
    assertThatIllegalArgumentException().isThrownBy(() -> ReflectionUtils.shallowCopyFieldState(src, dest));
}
Also used : TestObject(org.springframework.tests.sample.objects.TestObject) Test(org.junit.jupiter.api.Test)

Aggregations

TestObject (org.springframework.tests.sample.objects.TestObject)11 Test (org.junit.jupiter.api.Test)9 Method (java.lang.reflect.Method)1