mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#61 Adding test for map mapping
This commit is contained in:
parent
88011a91a3
commit
e82dd009f0
@ -21,7 +21,9 @@ package org.mapstruct.ap.test.collection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
import org.mapstruct.ap.testutil.IssueKey;
|
||||
import org.mapstruct.ap.testutil.MapperTestBase;
|
||||
@ -258,4 +260,19 @@ public class CollectionMappingTest extends MapperTestBase {
|
||||
assertThat( source ).isNotNull();
|
||||
assertThat( source.getColours() ).containsOnly( Colour.GREEN, Colour.BLUE );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapMapAsCopy() {
|
||||
Source source = new Source();
|
||||
|
||||
Map<String, Long> map = new HashMap<String, Long>();
|
||||
map.put( "Bob", 123L );
|
||||
map.put( "Alice", 456L );
|
||||
source.setStringLongMap( map );
|
||||
|
||||
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
||||
target.getStringLongMap().put( "Bill", 789L );
|
||||
|
||||
assertThat( source.getStringLongMap() ).hasSize( 2 );
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Source {
|
||||
@ -42,6 +43,8 @@ public class Source {
|
||||
|
||||
private Set<Colour> colours;
|
||||
|
||||
private Map<String, Long> stringLongMap;
|
||||
|
||||
public List<String> getStringList() {
|
||||
return stringList;
|
||||
}
|
||||
@ -113,4 +116,12 @@ public class Source {
|
||||
public void setColours(Set<Colour> colours) {
|
||||
this.colours = colours;
|
||||
}
|
||||
|
||||
public Map<String, Long> getStringLongMap() {
|
||||
return stringLongMap;
|
||||
}
|
||||
|
||||
public void setStringLongMap(Map<String, Long> stringLongMap) {
|
||||
this.stringLongMap = stringLongMap;
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Target {
|
||||
@ -40,6 +41,8 @@ public class Target {
|
||||
|
||||
private Set<String> colours;
|
||||
|
||||
private Map<String, Long> stringLongMap;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private Set set;
|
||||
|
||||
@ -116,4 +119,12 @@ public class Target {
|
||||
public Set<String> getColours() {
|
||||
return colours;
|
||||
}
|
||||
|
||||
public Map<String, Long> getStringLongMap() {
|
||||
return stringLongMap;
|
||||
}
|
||||
|
||||
public void setStringLongMap(Map<String, Long> stringLongMap) {
|
||||
this.stringLongMap = stringLongMap;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user