コード例 #1
0
 public void testCreateInstanceWithReflection() throws Exception {
   Class klass = Class.forName("org.openehr.schemas.v1.DVTEXT");
   Class factoryClass = klass.getClasses()[0];
   Method factoryMethod = factoryClass.getMethod("newInstance", null);
   Object obj = factoryMethod.invoke(null, null);
   assertTrue(obj instanceof DVTEXT);
 }
コード例 #2
0
  public void testCallSetterWithReflection() throws Exception {
    Class klass = Class.forName("org.openehr.schemas.v1.DVTEXT");
    Class factoryClass = klass.getClasses()[0];
    Method factoryMethod = factoryClass.getMethod("newInstance", null);
    Object obj = factoryMethod.invoke(null, null);
    Method setterMethod = klass.getMethod("setValue", String.class);
    setterMethod.invoke(obj, "new value");

    assertEquals("new value", ((DVTEXT) obj).getValue());
  }