コード例 #1
0
  private void testValidCopy(TestObject src, TestObject dest) {
    src.setName("freddie");
    src.setAge(15);
    src.setSpouse(new TestObject());
    assertFalse(src.getAge() == dest.getAge());

    ReflectionUtils.shallowCopyFieldState(src, dest);
    assertEquals(src.getAge(), dest.getAge());
    assertEquals(src.getSpouse(), dest.getSpouse());
  }
コード例 #2
0
  @Test
  public void invokeMethod() throws Exception {
    String rob = "Rob Harrop";

    TestObject bean = new TestObject();
    bean.setName(rob);

    Method getName = TestObject.class.getMethod("getName", (Class[]) null);
    Method setName = TestObject.class.getMethod("setName", String.class);

    Object name = ReflectionUtils.invokeMethod(getName, bean);
    assertEquals("Incorrect name returned", rob, name);

    String juergen = "Juergen Hoeller";
    ReflectionUtils.invokeMethod(setName, bean, juergen);
    assertEquals("Incorrect name set", juergen, bean.getName());
  }