@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); }
@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()); }
@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()); }
@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()); }
@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()); }