コード例 #1
0
  @Test
  public void shouldAcceptOnlyWhenCreateMethodDefined() {
    directive.setCreateMethod("a");
    assertTrue(byCreateMethod.isApplicable(directive));

    directive.setCreateMethod("");
    assertFalse(byCreateMethod.isApplicable(directive));

    directive.setCreateMethod(null);
    assertFalse(byCreateMethod.isApplicable(directive));
  }
コード例 #2
0
 @Test(expected = MappingException.class)
 public void shouldFailWithNoSuchMethod() {
   directive.setTargetClass(SelfFactory.class);
   directive.setCreateMethod("wrong");
   byCreateMethod.create(directive);
   fail();
 }
コード例 #3
0
 @Test
 public void shouldUseFullyQualifiedStaticCreateMethod() {
   directive.setTargetClass(String.class);
   directive.setCreateMethod(
       "org.dozer.factory.ConstructionStrategiesTest$ExternalFactory.create");
   String result = (String) byCreateMethod.create(directive);
   assertEquals("hello", result);
 }
コード例 #4
0
  @Test
  public void shouldUseStaticCreateMethod() {
    directive.setTargetClass(SelfFactory.class);
    directive.setCreateMethod("create");
    SelfFactory result = (SelfFactory) byCreateMethod.create(directive);

    assertNotNull(result);
    assertEquals("a", result.getName());
  }