mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#90 extend DefaultCollectionImplementationTest to cover all collection and map types declared in the test mapper
This commit is contained in:
parent
fc0a4570b7
commit
cd058663f4
@ -19,13 +19,22 @@
|
|||||||
package org.mapstruct.ap.test.collection.defaultimplementation;
|
package org.mapstruct.ap.test.collection.defaultimplementation;
|
||||||
|
|
||||||
import static org.fest.assertions.Assertions.assertThat;
|
import static org.fest.assertions.Assertions.assertThat;
|
||||||
|
import static org.fest.assertions.MapAssert.entry;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.NavigableMap;
|
||||||
|
import java.util.NavigableSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.SortedMap;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
import java.util.concurrent.ConcurrentNavigableMap;
|
||||||
|
|
||||||
import org.mapstruct.ap.testutil.IssueKey;
|
import org.mapstruct.ap.testutil.IssueKey;
|
||||||
import org.mapstruct.ap.testutil.MapperTestBase;
|
import org.mapstruct.ap.testutil.MapperTestBase;
|
||||||
@ -35,27 +44,61 @@ import org.testng.annotations.Test;
|
|||||||
@WithClasses({
|
@WithClasses({
|
||||||
SourceFoo.class,
|
SourceFoo.class,
|
||||||
TargetFoo.class,
|
TargetFoo.class,
|
||||||
SourceTargetMapper.class
|
SourceTargetMapper.class
|
||||||
})
|
})
|
||||||
public class DefaultCollectionImplementationTest extends MapperTestBase {
|
public class DefaultCollectionImplementationTest extends MapperTestBase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@IssueKey("6")
|
@IssueKey( "6" )
|
||||||
public void shouldUseDefaultImplementationForList() {
|
public void shouldUseDefaultImplementationForConcurrentMap() {
|
||||||
List<TargetFoo> target = SourceTargetMapper.INSTANCE.sourceFoosToTargetFoos( createSourceFooList() );
|
ConcurrentMap<String, TargetFoo> target =
|
||||||
|
SourceTargetMapper.INSTANCE.sourceFooMapToTargetFooConcurrentMap( createSourceFooMap() );
|
||||||
|
|
||||||
assertThat( target ).isNotNull();
|
assertResultMap( target );
|
||||||
assertThat( target ).containsExactly( new TargetFoo( "Bob" ), new TargetFoo( "Alice" ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@IssueKey("6")
|
@IssueKey( "6" )
|
||||||
public void shouldUseDefaultImplementationForSet() {
|
public void shouldUseDefaultImplementationForConcurrentNavigableMap() {
|
||||||
Set<TargetFoo> target =
|
ConcurrentNavigableMap<String, TargetFoo> target =
|
||||||
SourceTargetMapper.INSTANCE.sourceFoosToTargetFoos( new HashSet<SourceFoo>( createSourceFooList() ) );
|
SourceTargetMapper.INSTANCE.sourceFooMapToTargetFooConcurrentNavigableMap( createSourceFooMap() );
|
||||||
|
|
||||||
assertThat( target ).isNotNull();
|
assertResultMap( target );
|
||||||
assertThat( target ).containsOnly( new TargetFoo( "Bob" ), new TargetFoo( "Alice" ) );
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@IssueKey( "6" )
|
||||||
|
public void shouldUseDefaultImplementationForMap() {
|
||||||
|
Map<String, TargetFoo> target = SourceTargetMapper.INSTANCE.sourceFooMapToTargetFooMap( createSourceFooMap() );
|
||||||
|
|
||||||
|
assertResultMap( target );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@IssueKey( "6" )
|
||||||
|
public void shouldUseDefaultImplementationForNavigableMap() {
|
||||||
|
NavigableMap<String, TargetFoo> target =
|
||||||
|
SourceTargetMapper.INSTANCE.sourceFooMapToTargetFooNavigableMap( createSourceFooMap() );
|
||||||
|
|
||||||
|
assertResultMap( target );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@IssueKey( "6" )
|
||||||
|
public void shouldUseDefaultImplementationForSortedMap() {
|
||||||
|
SortedMap<String, TargetFoo> target =
|
||||||
|
SourceTargetMapper.INSTANCE.sourceFooMapToTargetFooSortedMap( createSourceFooMap() );
|
||||||
|
|
||||||
|
assertResultMap( target );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@IssueKey( "6" )
|
||||||
|
public void shouldUseDefaultImplementationForNaviableSet() {
|
||||||
|
NavigableSet<TargetFoo> target =
|
||||||
|
SourceTargetMapper.INSTANCE.sourceFoosToTargetFooNavigableSet( createSourceFooList() );
|
||||||
|
|
||||||
|
assertResultList( target );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -64,8 +107,7 @@ public class DefaultCollectionImplementationTest extends MapperTestBase {
|
|||||||
Collection<TargetFoo> target =
|
Collection<TargetFoo> target =
|
||||||
SourceTargetMapper.INSTANCE.sourceFoosToTargetFoos( (Collection<SourceFoo>) createSourceFooList() );
|
SourceTargetMapper.INSTANCE.sourceFoosToTargetFoos( (Collection<SourceFoo>) createSourceFooList() );
|
||||||
|
|
||||||
assertThat( target ).isNotNull();
|
assertResultList( target );
|
||||||
assertThat( target ).containsOnly( new TargetFoo( "Bob" ), new TargetFoo( "Alice" ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -74,17 +116,33 @@ public class DefaultCollectionImplementationTest extends MapperTestBase {
|
|||||||
Iterable<TargetFoo> target =
|
Iterable<TargetFoo> target =
|
||||||
SourceTargetMapper.INSTANCE.sourceFoosToTargetFoos( (Iterable<SourceFoo>) createSourceFooList() );
|
SourceTargetMapper.INSTANCE.sourceFoosToTargetFoos( (Iterable<SourceFoo>) createSourceFooList() );
|
||||||
|
|
||||||
assertThat( target ).isNotNull();
|
|
||||||
assertResultList( target );
|
assertResultList( target );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertResultList(Iterable<TargetFoo> fooIterable) {
|
@Test
|
||||||
assertThat( fooIterable ).isNotNull();
|
@IssueKey("6")
|
||||||
assertThat( fooIterable ).containsOnly( new TargetFoo( "Bob" ), new TargetFoo( "Alice" ) );
|
public void shouldUseDefaultImplementationForList() {
|
||||||
|
List<TargetFoo> target = SourceTargetMapper.INSTANCE.sourceFoosToTargetFoos( createSourceFooList() );
|
||||||
|
|
||||||
|
assertResultList( target );
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<SourceFoo> createSourceFooList() {
|
@Test
|
||||||
return Arrays.asList( new SourceFoo( "Bob" ), new SourceFoo( "Alice" ) );
|
@IssueKey("6")
|
||||||
|
public void shouldUseDefaultImplementationForSet() {
|
||||||
|
Set<TargetFoo> target =
|
||||||
|
SourceTargetMapper.INSTANCE.sourceFoosToTargetFoos( new HashSet<SourceFoo>( createSourceFooList() ) );
|
||||||
|
|
||||||
|
assertResultList( target );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@IssueKey( "6" )
|
||||||
|
public void shouldUseDefaultImplementationForSortedSet() {
|
||||||
|
SortedSet<TargetFoo> target =
|
||||||
|
SourceTargetMapper.INSTANCE.sourceFoosToTargetFooSortedSet( createSourceFooList() );
|
||||||
|
|
||||||
|
assertResultList( target );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -109,4 +167,27 @@ public class DefaultCollectionImplementationTest extends MapperTestBase {
|
|||||||
assertThat( target == result ).isTrue();
|
assertThat( target == result ).isTrue();
|
||||||
assertResultList( target );
|
assertResultList( target );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void assertResultList(Iterable<TargetFoo> fooIterable) {
|
||||||
|
assertThat( fooIterable ).isNotNull();
|
||||||
|
assertThat( fooIterable ).containsOnly( new TargetFoo( "Bob" ), new TargetFoo( "Alice" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertResultMap(Map<String, TargetFoo> result) {
|
||||||
|
assertThat( result ).isNotNull();
|
||||||
|
assertThat( result ).hasSize( 2 );
|
||||||
|
assertThat( result ).includes( entry( "1", new TargetFoo( "Bob" ) ), entry( "2", new TargetFoo( "Alice" ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<Long, SourceFoo> createSourceFooMap() {
|
||||||
|
Map<Long, SourceFoo> map = new HashMap<Long, SourceFoo>();
|
||||||
|
map.put( 1L, new SourceFoo( "Bob" ) );
|
||||||
|
map.put( 2L, new SourceFoo( "Alice" ) );
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<SourceFoo> createSourceFooList() {
|
||||||
|
return Arrays.asList( new SourceFoo( "Bob" ), new SourceFoo( "Alice" ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.test.collection.defaultimplementation;
|
package org.mapstruct.ap.test.collection.defaultimplementation;
|
||||||
|
|
||||||
public class TargetFoo {
|
public class TargetFoo implements Comparable<TargetFoo> {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@ -67,4 +67,9 @@ public class TargetFoo {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(TargetFoo o) {
|
||||||
|
return getName().compareTo( o.getName() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user