@Test public void convertListShouldReturnConvertedListWhenProperParametersWereGiven() { List<TestClass1> sourceList = Arrays.asList( new TestClass1(TEST_CLASS_FIRST_ID), new TestClass1(TEST_CLASS_SECOND_ID) ); List<TestClass2> expected = Arrays.asList( new TestClass2(TEST_CLASS_FIRST_ID), new TestClass2(TEST_CLASS_SECOND_ID) ); for (int i = 0; i < 2; i++) { given(modelMapper.map(sourceList.get(i), TestClass2.class)) .willReturn(expected.get(i)); } List<TestClass2> result = modelMapperConverterService.convert(sourceList, TestClass2.class); assertThat(result, notNullValue()); assertThat(result, not(empty())); assertThat(result, is(expected)); for (int i = 0; i < 2; i++) { then(modelMapper).should().map(sourceList.get(i), TestClass2.class); } }
@Override public <S, T> T convert(S source, Class<T> targetType) { Assert.notNull(source); Assert.notNull(targetType); return modelMapper.map(source, targetType); }
ModelMapperConverterServiceImpl implements ConverterService { @Override public <S, T> T convert(S source, Class<T> targetType) { Assert.notNull(source); Assert.notNull(targetType); return modelMapper.map(source, targetType); } }
ModelMapperConverterServiceImpl implements ConverterService { @Override public <S, T> T convert(S source, Class<T> targetType) { Assert.notNull(source); Assert.notNull(targetType); return modelMapper.map(source, targetType); } ModelMapperConverterServiceImpl(ModelMapper modelMapper); }
ModelMapperConverterServiceImpl implements ConverterService { @Override public <S, T> T convert(S source, Class<T> targetType) { Assert.notNull(source); Assert.notNull(targetType); return modelMapper.map(source, targetType); } ModelMapperConverterServiceImpl(ModelMapper modelMapper); void setupCustomConverters(List<ConverterAdapter> converterAdapters); @Override T convert(S source, Class<T> targetType); @Override List<T> convert(List<S> sourceList, Class<T> targetType); }
ModelMapperConverterServiceImpl implements ConverterService { @Override public <S, T> T convert(S source, Class<T> targetType) { Assert.notNull(source); Assert.notNull(targetType); return modelMapper.map(source, targetType); } ModelMapperConverterServiceImpl(ModelMapper modelMapper); void setupCustomConverters(List<ConverterAdapter> converterAdapters); @Override T convert(S source, Class<T> targetType); @Override List<T> convert(List<S> sourceList, Class<T> targetType);  }