@Test
  public void testRootObjectBinding() {
    WrapperDTO<SimpleAssociation> source = new WrapperDTO<SimpleAssociation>();
    SimpleAssociation entity = new SimpleAssociation();
    source.setWrapped(entity);

    // the wrapped instance should just be ignored.
    SimpleAssociation result = binder.extractFromDto(SimpleAssociation.class, source);

    assertNotNull("Should have returned a result", result);
  }
  @Test
  public void testAssociationReverseBinding() {
    SimpleAssociationDTO dto = new SimpleAssociationDTO();
    dto.setFirstString("myFirstString");
    dto.setSecondString("theAssociatedString");

    SimpleAssociation entity = binder.extractFromDto(SimpleAssociation.class, dto);

    assertEquals(dto.getFirstString(), entity.getMyString());
    assertNotNull("related entity should not be null", entity.getRelated());
    assertEquals(dto.getSecondString(), entity.getRelated().getaString());
  }
  @Test
  public void testMappedReverseBinding() {

    // create a basic entity
    AnnotatedEntity entity = new AnnotatedEntity("Jones", "Tom", "NOOOOO");

    // try and build a DTO out of the same entity.
    AnnotatedEntity dto = binder.bindFromBusinessObject(AnnotatedEntity.class, entity);

    // change things on the dto
    dto.setFirstString("Myers");
    dto.setSecondString("Mike");

    entity = binder.extractFromDto(AnnotatedEntity.class, dto);

    assertNull(entity.getThirdString());
    assertEquals("Mike", entity.getFirstString());
    assertEquals("Myers", entity.getSecondString());
  }
  /**
   * One simple way to check if everything is working fine is binding an entity against itself,
   * first we'll start with simple attributes, no nested relationships and see how the framework
   * behaves.
   */
  @Test
  public void testSimpleReverseBinding() {

    // create a basic entity
    SimpleEntity entity = new SimpleEntity("test", 123, 345.35, true);

    // try and build a DTO out of the same entity.
    SimpleEntity dto = binder.bindFromBusinessObject(SimpleEntity.class, entity);

    // change things on the dto
    dto.setAnInt(10);
    dto.setaBoolean(false);
    dto.setaDouble(20.20);
    dto.setaString("Changed!");

    entity = binder.extractFromDto(SimpleEntity.class, dto);

    assertEquals(10, entity.getAnInt());
    assertEquals(false, entity.isaBoolean());
    assertEquals(20.20, entity.getaDouble(), 0.0001);
    assertEquals("Changed!", entity.getaString());
  }
  @Test
  public void testValueRestoringReverseBinding() {
    MergerDTO dto = new MergerDTO();
    dto.setBigNumber("10.5");
    dto.setFormattedDate("1983-02-10 07:00");

    GeneralPurposeEntity entity = binder.extractFromDto(GeneralPurposeEntity.class, dto);
    assertNotNull(entity);
    assertNotNull(entity.getTheBigDecimal());
    assertNotNull(entity.getTheDate());

    assertEquals("The value should be 10.5", 10.5, entity.getTheBigDecimal().doubleValue(), 0.0001);

    Calendar cal = Calendar.getInstance();
    cal.setTime(entity.getTheDate());

    assertEquals("The year should be the same.", 1983, cal.get(Calendar.YEAR));
    assertEquals("The month should be the same.", 01, cal.get(Calendar.MONTH));
    assertEquals("The day should be the same.", 10, cal.get(Calendar.DAY_OF_MONTH));
    assertEquals("The hour should be the same.", 7, cal.get(Calendar.HOUR));
    assertEquals("The minute should be the same.", 0, cal.get(Calendar.MINUTE));
  }
 @Test
 public void testNullBinding() {
   SimpleEntity source = null;
   SimpleEntity result = binder.extractFromDto(SimpleEntity.class, source);
   assertNull(result);
 }