Example #1
0
  @Test(expected = RuntimeException.class)
  public void testAddWithExceptionNotInThrowsClause() throws DogException {
    AdderUsageObserver.setUsed(false);

    Source source = new Source();
    source.setPets(Arrays.asList("cat"));

    SourceTargetMapper.INSTANCE.toTarget(source);
  }
Example #2
0
  @Test
  public void testAddReverse() throws DogException {
    AdderUsageObserver.setUsed(false);

    Target source = new Target();
    source.setPets(Arrays.asList(3L));

    Source target = SourceTargetMapper.INSTANCE.toSource(source);
    assertThat(target).isNotNull();
    assertThat(target.getPets().size()).isEqualTo(1);
    assertThat(target.getPets().get(0)).isEqualTo("cat");
  }
Example #3
0
  @Test
  public void testAddOnlyGetter() throws DogException {
    AdderUsageObserver.setUsed(false);

    Source source = new Source();
    source.setPets(Arrays.asList("mouse"));

    TargetOnlyGetter target = SourceTargetMapper.INSTANCE.toTargetOnlyGetter(source);
    assertThat(target).isNotNull();
    assertThat(target.getPets().size()).isEqualTo(1);
    assertThat(target.getPets().get(0)).isEqualTo(2L);
    assertTrue(AdderUsageObserver.isUsed());
  }
Example #4
0
  @Test
  public void testShouldUseDefaultStrategy() throws DogException {
    AdderUsageObserver.setUsed(false);

    Source source = new Source();
    source.setPets(Arrays.asList("mouse"));

    Target target = SourceTargetMapperStrategyDefault.INSTANCE.shouldFallBackToAdder(source);
    assertThat(target).isNotNull();
    assertThat(target.getPets().size()).isEqualTo(1);
    assertThat(target.getPets().get(0)).isEqualTo(2L);
    assertFalse(AdderUsageObserver.isUsed());
  }
Example #5
0
  @Test
  public void testShouldPreferSetterStrategyButThereIsNone() throws DogException {
    AdderUsageObserver.setUsed(false);

    Source source = new Source();
    source.setPets(Arrays.asList("mouse"));

    TargetWithoutSetter target =
        SourceTargetMapperStrategySetterPreferred.INSTANCE.toTargetDontUseAdder(source);
    assertThat(target).isNotNull();
    assertThat(target.getPets().size()).isEqualTo(1);
    assertThat(target.getPets().get(0)).isEqualTo(2L);
    assertTrue(AdderUsageObserver.isUsed());
  }
Example #6
0
  @IssueKey("241")
  @Test
  public void testAddwithExistingTarget() throws DogException {
    AdderUsageObserver.setUsed(false);

    Source source = new Source();
    source.setPets(Arrays.asList("mouse"));

    Target target = new Target();
    target.setPets(new ArrayList<Long>(Arrays.asList(1L)));

    SourceTargetMapper.INSTANCE.toExistingTarget(source, target);
    assertThat(target).isNotNull();
    assertThat(target.getPets().size()).isEqualTo(2);
    assertThat(target.getPets().get(0)).isEqualTo(1L);
    assertThat(target.getPets().get(1)).isEqualTo(2L);
    assertTrue(AdderUsageObserver.isUsed());
  }