コード例 #1
0
 @Test
 public void validCopyToSubType() {
   TestObject src = new TestObject();
   TestObjectSubclassWithNewField dest = new TestObjectSubclassWithNewField();
   dest.magic = 11;
   testValidCopy(src, dest);
   // Should have left this one alone
   assertEquals(11, dest.magic);
 }
コード例 #2
0
  @Test
  public void validCopyOnSubTypeWithNewField() {
    TestObjectSubclassWithNewField src = new TestObjectSubclassWithNewField();
    TestObjectSubclassWithNewField dest = new TestObjectSubclassWithNewField();
    src.magic = 11;

    // Will check inherited fields are copied
    testValidCopy(src, dest);

    // Check subclass fields were copied
    assertEquals(src.magic, dest.magic);
    assertEquals(src.prot, dest.prot);
  }
コード例 #3
0
  @Test
  public void setField() {
    TestObjectSubclassWithNewField testBean = new TestObjectSubclassWithNewField();
    Field field =
        ReflectionUtils.findField(TestObjectSubclassWithNewField.class, "name", String.class);

    ReflectionUtils.makeAccessible(field);

    ReflectionUtils.setField(field, testBean, "FooBar");
    assertNotNull(testBean.getName());
    assertEquals("FooBar", testBean.getName());

    ReflectionUtils.setField(field, testBean, null);
    assertNull(testBean.getName());
  }