Ejemplo n.º 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);
  }
Ejemplo n.º 2
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());
  }
Ejemplo n.º 3
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());
  }
Ejemplo n.º 4
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());
  }
Ejemplo n.º 5
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());
  }