mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
Fix minor warnings in package test.collection:
remove unnecessary generic-type in collections, remove unnecessary exception from signature, replace months numbers on Calendar constants
This commit is contained in:
parent
dc86d5df45
commit
148466ae3e
@ -113,7 +113,7 @@ public class CollectionMappingTest {
|
|||||||
assertThat( source.getOtherStringList() ).containsExactly( "Bob", "Alice" );
|
assertThat( source.getOtherStringList() ).containsExactly( "Bob", "Alice" );
|
||||||
|
|
||||||
// prepare a test list to monitor add all behaviour
|
// prepare a test list to monitor add all behaviour
|
||||||
List<String> testList = new TestList<String>();
|
List<String> testList = new TestList<>();
|
||||||
testList.addAll( target.getOtherStringList() );
|
testList.addAll( target.getOtherStringList() );
|
||||||
TestList.setAddAllCalled( false );
|
TestList.setAddAllCalled( false );
|
||||||
target.setOtherStringList( testList );
|
target.setOtherStringList( testList );
|
||||||
@ -146,7 +146,7 @@ public class CollectionMappingTest {
|
|||||||
@IssueKey("6")
|
@IssueKey("6")
|
||||||
public void shouldMapArrayList() {
|
public void shouldMapArrayList() {
|
||||||
Source source = new Source();
|
Source source = new Source();
|
||||||
source.setStringArrayList( new ArrayList<String>( Arrays.asList( "Bob", "Alice" ) ) );
|
source.setStringArrayList( new ArrayList<>( Arrays.asList( "Bob", "Alice" ) ) );
|
||||||
|
|
||||||
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ public class CollectionMappingTest {
|
|||||||
@IssueKey("6")
|
@IssueKey("6")
|
||||||
public void shouldReverseMapArrayList() {
|
public void shouldReverseMapArrayList() {
|
||||||
Target target = new Target();
|
Target target = new Target();
|
||||||
target.setStringArrayList( new ArrayList<String>( Arrays.asList( "Bob", "Alice" ) ) );
|
target.setStringArrayList( new ArrayList<>( Arrays.asList( "Bob", "Alice" ) ) );
|
||||||
|
|
||||||
Source source = SourceTargetMapper.INSTANCE.targetToSource( target );
|
Source source = SourceTargetMapper.INSTANCE.targetToSource( target );
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ public class CollectionMappingTest {
|
|||||||
@IssueKey("6")
|
@IssueKey("6")
|
||||||
public void shouldMapSet() {
|
public void shouldMapSet() {
|
||||||
Source source = new Source();
|
Source source = new Source();
|
||||||
source.setStringSet( new HashSet<String>( Arrays.asList( "Bob", "Alice" ) ) );
|
source.setStringSet( new HashSet<>( Arrays.asList( "Bob", "Alice" ) ) );
|
||||||
|
|
||||||
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
||||||
|
|
||||||
@ -182,7 +182,7 @@ public class CollectionMappingTest {
|
|||||||
@IssueKey("6")
|
@IssueKey("6")
|
||||||
public void shouldReverseMapSet() {
|
public void shouldReverseMapSet() {
|
||||||
Target target = new Target();
|
Target target = new Target();
|
||||||
target.setStringSet( new HashSet<String>( Arrays.asList( "Bob", "Alice" ) ) );
|
target.setStringSet( new HashSet<>( Arrays.asList( "Bob", "Alice" ) ) );
|
||||||
|
|
||||||
Source source = SourceTargetMapper.INSTANCE.targetToSource( target );
|
Source source = SourceTargetMapper.INSTANCE.targetToSource( target );
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ public class CollectionMappingTest {
|
|||||||
@IssueKey("6")
|
@IssueKey("6")
|
||||||
public void shouldMapSetAsCopy() {
|
public void shouldMapSetAsCopy() {
|
||||||
Source source = new Source();
|
Source source = new Source();
|
||||||
source.setStringSet( new HashSet<String>( Arrays.asList( "Bob", "Alice" ) ) );
|
source.setStringSet( new HashSet<>( Arrays.asList( "Bob", "Alice" ) ) );
|
||||||
|
|
||||||
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
||||||
target.getStringSet().add( "Bill" );
|
target.getStringSet().add( "Bill" );
|
||||||
@ -206,7 +206,7 @@ public class CollectionMappingTest {
|
|||||||
@IssueKey("6")
|
@IssueKey("6")
|
||||||
public void shouldMapHashSetAsCopy() {
|
public void shouldMapHashSetAsCopy() {
|
||||||
Source source = new Source();
|
Source source = new Source();
|
||||||
source.setStringHashSet( new HashSet<String>( Arrays.asList( "Bob", "Alice" ) ) );
|
source.setStringHashSet( new HashSet<>( Arrays.asList( "Bob", "Alice" ) ) );
|
||||||
|
|
||||||
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
||||||
target.getStringHashSet().add( "Bill" );
|
target.getStringHashSet().add( "Bill" );
|
||||||
@ -218,7 +218,7 @@ public class CollectionMappingTest {
|
|||||||
@IssueKey("6")
|
@IssueKey("6")
|
||||||
public void shouldReverseMapSetAsCopy() {
|
public void shouldReverseMapSetAsCopy() {
|
||||||
Target target = new Target();
|
Target target = new Target();
|
||||||
target.setStringSet( new HashSet<String>( Arrays.asList( "Bob", "Alice" ) ) );
|
target.setStringSet( new HashSet<>( Arrays.asList( "Bob", "Alice" ) ) );
|
||||||
|
|
||||||
Source source = SourceTargetMapper.INSTANCE.targetToSource( target );
|
Source source = SourceTargetMapper.INSTANCE.targetToSource( target );
|
||||||
source.getStringSet().add( "Bill" );
|
source.getStringSet().add( "Bill" );
|
||||||
@ -254,7 +254,7 @@ public class CollectionMappingTest {
|
|||||||
@IssueKey("6")
|
@IssueKey("6")
|
||||||
public void shouldMapIntegerSetToRawSet() {
|
public void shouldMapIntegerSetToRawSet() {
|
||||||
Source source = new Source();
|
Source source = new Source();
|
||||||
source.setIntegerSet( new HashSet<Integer>( Arrays.asList( 1, 2 ) ) );
|
source.setIntegerSet( new HashSet<>( Arrays.asList( 1, 2 ) ) );
|
||||||
|
|
||||||
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ public class CollectionMappingTest {
|
|||||||
@IssueKey("6")
|
@IssueKey("6")
|
||||||
public void shouldMapIntegerSetToStringSet() {
|
public void shouldMapIntegerSetToStringSet() {
|
||||||
Source source = new Source();
|
Source source = new Source();
|
||||||
source.setAnotherIntegerSet( new HashSet<Integer>( Arrays.asList( 1, 2 ) ) );
|
source.setAnotherIntegerSet( new HashSet<>( Arrays.asList( 1, 2 ) ) );
|
||||||
|
|
||||||
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
||||||
|
|
||||||
@ -278,7 +278,7 @@ public class CollectionMappingTest {
|
|||||||
@IssueKey("6")
|
@IssueKey("6")
|
||||||
public void shouldReverseMapIntegerSetToStringSet() {
|
public void shouldReverseMapIntegerSetToStringSet() {
|
||||||
Target target = new Target();
|
Target target = new Target();
|
||||||
target.setAnotherStringSet( new HashSet<String>( Arrays.asList( "1", "2" ) ) );
|
target.setAnotherStringSet( new HashSet<>( Arrays.asList( "1", "2" ) ) );
|
||||||
|
|
||||||
Source source = SourceTargetMapper.INSTANCE.targetToSource( target );
|
Source source = SourceTargetMapper.INSTANCE.targetToSource( target );
|
||||||
|
|
||||||
@ -302,7 +302,7 @@ public class CollectionMappingTest {
|
|||||||
@IssueKey("6")
|
@IssueKey("6")
|
||||||
public void shouldReverseMapSetOfEnumToStringSet() {
|
public void shouldReverseMapSetOfEnumToStringSet() {
|
||||||
Target target = new Target();
|
Target target = new Target();
|
||||||
target.setColours( new HashSet<String>( Arrays.asList( "BLUE", "GREEN" ) ) );
|
target.setColours( new HashSet<>( Arrays.asList( "BLUE", "GREEN" ) ) );
|
||||||
|
|
||||||
Source source = SourceTargetMapper.INSTANCE.targetToSource( target );
|
Source source = SourceTargetMapper.INSTANCE.targetToSource( target );
|
||||||
|
|
||||||
@ -314,7 +314,7 @@ public class CollectionMappingTest {
|
|||||||
public void shouldMapMapAsCopy() {
|
public void shouldMapMapAsCopy() {
|
||||||
Source source = new Source();
|
Source source = new Source();
|
||||||
|
|
||||||
Map<String, Long> map = new HashMap<String, Long>();
|
Map<String, Long> map = new HashMap<>();
|
||||||
map.put( "Bob", 123L );
|
map.put( "Bob", 123L );
|
||||||
map.put( "Alice", 456L );
|
map.put( "Alice", 456L );
|
||||||
source.setStringLongMap( map );
|
source.setStringLongMap( map );
|
||||||
@ -331,7 +331,7 @@ public class CollectionMappingTest {
|
|||||||
public void shouldMapMapWithClearAndPutAll() {
|
public void shouldMapMapWithClearAndPutAll() {
|
||||||
Source source = new Source();
|
Source source = new Source();
|
||||||
|
|
||||||
Map<String, Long> map = new HashMap<String, Long>();
|
Map<String, Long> map = new HashMap<>();
|
||||||
map.put( "Bob", 123L );
|
map.put( "Bob", 123L );
|
||||||
map.put( "Alice", 456L );
|
map.put( "Alice", 456L );
|
||||||
source.setOtherStringLongMap( map );
|
source.setOtherStringLongMap( map );
|
||||||
@ -345,7 +345,7 @@ public class CollectionMappingTest {
|
|||||||
source.getOtherStringLongMap().remove( "Alice" );
|
source.getOtherStringLongMap().remove( "Alice" );
|
||||||
|
|
||||||
// prepare a test list to monitor add all behaviour
|
// prepare a test list to monitor add all behaviour
|
||||||
Map<String, Long> originalInstance = new TestMap<String, Long>();
|
Map<String, Long> originalInstance = new TestMap<>();
|
||||||
originalInstance.putAll( target.getOtherStringLongMap() );
|
originalInstance.putAll( target.getOtherStringLongMap() );
|
||||||
TestMap.setPuttAllCalled( false );
|
TestMap.setPuttAllCalled( false );
|
||||||
target.setOtherStringLongMap( originalInstance );
|
target.setOtherStringLongMap( originalInstance );
|
||||||
@ -362,7 +362,7 @@ public class CollectionMappingTest {
|
|||||||
@IssueKey("87")
|
@IssueKey("87")
|
||||||
public void shouldMapIntegerSetToNumberSet() {
|
public void shouldMapIntegerSetToNumberSet() {
|
||||||
Set<Number> numbers = SourceTargetMapper.INSTANCE
|
Set<Number> numbers = SourceTargetMapper.INSTANCE
|
||||||
.integerSetToNumberSet( new HashSet<Integer>( Arrays.asList( 123, 456 ) ) );
|
.integerSetToNumberSet( new HashSet<>( Arrays.asList( 123, 456 ) ) );
|
||||||
|
|
||||||
assertThat( numbers ).isNotNull();
|
assertThat( numbers ).isNotNull();
|
||||||
assertThat( numbers ).containsOnly( 123, 456 );
|
assertThat( numbers ).containsOnly( 123, 456 );
|
||||||
@ -385,7 +385,7 @@ public class CollectionMappingTest {
|
|||||||
@IssueKey("853")
|
@IssueKey("853")
|
||||||
public void shouldMapNonGenericList() {
|
public void shouldMapNonGenericList() {
|
||||||
Source source = new Source();
|
Source source = new Source();
|
||||||
source.setStringList3( new ArrayList<String>( Arrays.asList( "Bob", "Alice" ) ) );
|
source.setStringList3( new ArrayList<>( Arrays.asList( "Bob", "Alice" ) ) );
|
||||||
|
|
||||||
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
||||||
|
|
||||||
@ -406,12 +406,11 @@ public class CollectionMappingTest {
|
|||||||
assertThat( mappedSource.getStringList3() ).containsExactly( "Bill", "Bob" );
|
assertThat( mappedSource.getStringList3() ).containsExactly( "Bill", "Bob" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Test
|
@Test
|
||||||
@IssueKey("853")
|
@IssueKey("853")
|
||||||
public void shouldMapNonGenericMap() {
|
public void shouldMapNonGenericMap() {
|
||||||
Source source = new Source();
|
Source source = new Source();
|
||||||
Map<String, Long> map = new HashMap<String, Long>();
|
Map<String, Long> map = new HashMap<>();
|
||||||
map.put( "Bob", 123L );
|
map.put( "Bob", 123L );
|
||||||
map.put( "Alice", 456L );
|
map.put( "Alice", 456L );
|
||||||
source.setStringLongMapForNonGeneric( map );
|
source.setStringLongMapForNonGeneric( map );
|
||||||
|
@ -41,13 +41,10 @@ public class StringHolder {
|
|||||||
}
|
}
|
||||||
StringHolder other = (StringHolder) obj;
|
StringHolder other = (StringHolder) obj;
|
||||||
if ( string == null ) {
|
if ( string == null ) {
|
||||||
if ( other.string != null ) {
|
return other.string == null;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if ( !string.equals( other.string ) ) {
|
else {
|
||||||
return false;
|
return string.equals( other.string );
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,14 +144,14 @@ public class Target {
|
|||||||
|
|
||||||
public List<String> getStringListNoSetter() {
|
public List<String> getStringListNoSetter() {
|
||||||
if ( stringListNoSetter == null ) {
|
if ( stringListNoSetter == null ) {
|
||||||
stringListNoSetter = new ArrayList<String>();
|
stringListNoSetter = new ArrayList<>();
|
||||||
}
|
}
|
||||||
return stringListNoSetter;
|
return stringListNoSetter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getStringListNoSetter2() {
|
public List<String> getStringListNoSetter2() {
|
||||||
if ( stringListNoSetter2 == null ) {
|
if ( stringListNoSetter2 == null ) {
|
||||||
stringListNoSetter2 = new ArrayList<String>();
|
stringListNoSetter2 = new ArrayList<>();
|
||||||
}
|
}
|
||||||
return stringListNoSetter2;
|
return stringListNoSetter2;
|
||||||
}
|
}
|
||||||
|
@ -117,14 +117,14 @@ public class AdderTest {
|
|||||||
|
|
||||||
@IssueKey("241")
|
@IssueKey("241")
|
||||||
@Test
|
@Test
|
||||||
public void testAddwithExistingTarget() throws DogException {
|
public void testAddWithExistingTarget() {
|
||||||
AdderUsageObserver.setUsed( false );
|
AdderUsageObserver.setUsed( false );
|
||||||
|
|
||||||
Source source = new Source();
|
Source source = new Source();
|
||||||
source.setPets( Arrays.asList( "mouse" ) );
|
source.setPets( Arrays.asList( "mouse" ) );
|
||||||
|
|
||||||
Target target = new Target();
|
Target target = new Target();
|
||||||
target.setPets( new ArrayList<Long>( Arrays.asList( 1L ) ) );
|
target.setPets( new ArrayList<>( Arrays.asList( 1L ) ) );
|
||||||
|
|
||||||
SourceTargetMapper.INSTANCE.toExistingTarget( source, target );
|
SourceTargetMapper.INSTANCE.toExistingTarget( source, target );
|
||||||
assertThat( target ).isNotNull();
|
assertThat( target ).isNotNull();
|
||||||
@ -178,7 +178,7 @@ public class AdderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testshouldFallBackToDaliSingularInAbsenseOfHumanSingular() {
|
public void testShouldFallBackToDaliSingularInAbsenseOfHumanSingular() {
|
||||||
AdderUsageObserver.setUsed( false );
|
AdderUsageObserver.setUsed( false );
|
||||||
|
|
||||||
SourceTeeth source = new SourceTeeth();
|
SourceTeeth source = new SourceTeeth();
|
||||||
@ -192,7 +192,7 @@ public class AdderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddReverse() throws DogException {
|
public void testAddReverse() {
|
||||||
AdderUsageObserver.setUsed( false );
|
AdderUsageObserver.setUsed( false );
|
||||||
|
|
||||||
Target source = new Target();
|
Target source = new Target();
|
||||||
@ -219,7 +219,7 @@ public class AdderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddViaTargetType() throws DogException {
|
public void testAddViaTargetType() {
|
||||||
AdderUsageObserver.setUsed( false );
|
AdderUsageObserver.setUsed( false );
|
||||||
|
|
||||||
Source source = new Source();
|
Source source = new Source();
|
||||||
@ -235,7 +235,7 @@ public class AdderTest {
|
|||||||
|
|
||||||
@IssueKey("242")
|
@IssueKey("242")
|
||||||
@Test
|
@Test
|
||||||
public void testSingleElementSource() throws DogException {
|
public void testSingleElementSource() {
|
||||||
AdderUsageObserver.setUsed( false );
|
AdderUsageObserver.setUsed( false );
|
||||||
|
|
||||||
SingleElementSource source = new SingleElementSource();
|
SingleElementSource source = new SingleElementSource();
|
||||||
@ -250,7 +250,7 @@ public class AdderTest {
|
|||||||
|
|
||||||
@IssueKey( "310" )
|
@IssueKey( "310" )
|
||||||
@Test
|
@Test
|
||||||
public void testMissingImport() throws DogException {
|
public void testMissingImport() {
|
||||||
generatedSource.addComparisonToFixtureFor( Source2Target2Mapper.class );
|
generatedSource.addComparisonToFixtureFor( Source2Target2Mapper.class );
|
||||||
|
|
||||||
Source2 source = new Source2();
|
Source2 source = new Source2();
|
||||||
|
@ -63,7 +63,7 @@ public class PetMapper {
|
|||||||
* @throws DogException
|
* @throws DogException
|
||||||
*/
|
*/
|
||||||
public List<Long> toPets(List<String> pets) throws CatException, DogException {
|
public List<Long> toPets(List<String> pets) throws CatException, DogException {
|
||||||
List<Long> result = new ArrayList<Long>();
|
List<Long> result = new ArrayList<>();
|
||||||
for ( String pet : pets ) {
|
for ( String pet : pets ) {
|
||||||
result.add( toPet( pet ) );
|
result.add( toPet( pet ) );
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ public class PetMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<String> toSourcePets(List<Long> pets) throws CatException, DogException {
|
public List<String> toSourcePets(List<Long> pets) throws CatException, DogException {
|
||||||
List<String> result = new ArrayList<String>();
|
List<String> result = new ArrayList<>();
|
||||||
for ( Long pet : pets ) {
|
for ( Long pet : pets ) {
|
||||||
result.add( PETS_TO_SOURCE.get( pet ) );
|
result.add( PETS_TO_SOURCE.get( pet ) );
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ public class Target {
|
|||||||
public Long addPet(Long pet) {
|
public Long addPet(Long pet) {
|
||||||
AdderUsageObserver.setUsed( true );
|
AdderUsageObserver.setUsed( true );
|
||||||
if ( pets == null ) {
|
if ( pets == null ) {
|
||||||
pets = new ArrayList<Long>();
|
pets = new ArrayList<>();
|
||||||
}
|
}
|
||||||
pets.add( pet );
|
pets.add( pet );
|
||||||
return pet;
|
return pet;
|
||||||
|
@ -26,7 +26,7 @@ public class TargetDali {
|
|||||||
public void addTeeth(Integer tooth) {
|
public void addTeeth(Integer tooth) {
|
||||||
AdderUsageObserver.setUsed( true );
|
AdderUsageObserver.setUsed( true );
|
||||||
if ( teeth == null ) {
|
if ( teeth == null ) {
|
||||||
teeth = new ArrayList<Integer>();
|
teeth = new ArrayList<>();
|
||||||
}
|
}
|
||||||
teeth.add( tooth );
|
teeth.add( tooth );
|
||||||
}
|
}
|
||||||
|
@ -26,14 +26,14 @@ public class TargetHuman {
|
|||||||
public void addTooth(Integer pet) {
|
public void addTooth(Integer pet) {
|
||||||
AdderUsageObserver.setUsed( true );
|
AdderUsageObserver.setUsed( true );
|
||||||
if ( teeth == null ) {
|
if ( teeth == null ) {
|
||||||
teeth = new ArrayList<Integer>();
|
teeth = new ArrayList<>();
|
||||||
}
|
}
|
||||||
teeth.add( pet );
|
teeth.add( pet );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTeeth(Integer tooth) {
|
public void addTeeth(Integer tooth) {
|
||||||
if ( teeth == null ) {
|
if ( teeth == null ) {
|
||||||
teeth = new ArrayList<Integer>();
|
teeth = new ArrayList<>();
|
||||||
}
|
}
|
||||||
teeth.add( tooth );
|
teeth.add( tooth );
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ public class TargetOnlyGetter {
|
|||||||
public void addPet(Long pet) {
|
public void addPet(Long pet) {
|
||||||
AdderUsageObserver.setUsed( true );
|
AdderUsageObserver.setUsed( true );
|
||||||
if ( pets == null ) {
|
if ( pets == null ) {
|
||||||
pets = new ArrayList<Long>();
|
pets = new ArrayList<>();
|
||||||
}
|
}
|
||||||
pets.add( pet );
|
pets.add( pet );
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public class TargetViaTargetType {
|
|||||||
public void addPet(IndoorPet pet) {
|
public void addPet(IndoorPet pet) {
|
||||||
AdderUsageObserver.setUsed( true );
|
AdderUsageObserver.setUsed( true );
|
||||||
if ( pets == null ) {
|
if ( pets == null ) {
|
||||||
pets = new ArrayList<IndoorPet>();
|
pets = new ArrayList<>();
|
||||||
}
|
}
|
||||||
pets.add( pet );
|
pets.add( pet );
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ public class TargetWithoutSetter {
|
|||||||
public void addPet(Long pet) {
|
public void addPet(Long pet) {
|
||||||
AdderUsageObserver.setUsed( true );
|
AdderUsageObserver.setUsed( true );
|
||||||
if ( pets == null ) {
|
if ( pets == null ) {
|
||||||
pets = new ArrayList<Long>();
|
pets = new ArrayList<>();
|
||||||
}
|
}
|
||||||
pets.add( pet );
|
pets.add( pet );
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ public class DefaultCollectionImplementationTest {
|
|||||||
@IssueKey("6")
|
@IssueKey("6")
|
||||||
public void shouldUseDefaultImplementationForSet() {
|
public void shouldUseDefaultImplementationForSet() {
|
||||||
Set<TargetFoo> target =
|
Set<TargetFoo> target =
|
||||||
SourceTargetMapper.INSTANCE.sourceFoosToTargetFoos( new HashSet<SourceFoo>( createSourceFooList() ) );
|
SourceTargetMapper.INSTANCE.sourceFoosToTargetFoos( new HashSet<>( createSourceFooList() ) );
|
||||||
|
|
||||||
assertResultList( target );
|
assertResultList( target );
|
||||||
}
|
}
|
||||||
@ -145,7 +145,7 @@ public class DefaultCollectionImplementationTest {
|
|||||||
@Test
|
@Test
|
||||||
@IssueKey("19")
|
@IssueKey("19")
|
||||||
public void shouldUseTargetParameterForMapping() {
|
public void shouldUseTargetParameterForMapping() {
|
||||||
List<TargetFoo> target = new ArrayList<TargetFoo>();
|
List<TargetFoo> target = new ArrayList<>();
|
||||||
SourceTargetMapper.INSTANCE.sourceFoosToTargetFoosUsingTargetParameter(
|
SourceTargetMapper.INSTANCE.sourceFoosToTargetFoosUsingTargetParameter(
|
||||||
target,
|
target,
|
||||||
createSourceFooList()
|
createSourceFooList()
|
||||||
@ -157,7 +157,7 @@ public class DefaultCollectionImplementationTest {
|
|||||||
@Test
|
@Test
|
||||||
@IssueKey("19")
|
@IssueKey("19")
|
||||||
public void shouldUseAndReturnTargetParameterForMapping() {
|
public void shouldUseAndReturnTargetParameterForMapping() {
|
||||||
List<TargetFoo> target = new ArrayList<TargetFoo>();
|
List<TargetFoo> target = new ArrayList<>();
|
||||||
Iterable<TargetFoo> result =
|
Iterable<TargetFoo> result =
|
||||||
SourceTargetMapper.INSTANCE
|
SourceTargetMapper.INSTANCE
|
||||||
.sourceFoosToTargetFoosUsingTargetParameterAndReturn( createSourceFooList(), target );
|
.sourceFoosToTargetFoosUsingTargetParameterAndReturn( createSourceFooList(), target );
|
||||||
@ -189,7 +189,7 @@ public class DefaultCollectionImplementationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Map<Long, SourceFoo> createSourceFooMap() {
|
private Map<Long, SourceFoo> createSourceFooMap() {
|
||||||
Map<Long, SourceFoo> map = new HashMap<Long, SourceFoo>();
|
Map<Long, SourceFoo> map = new HashMap<>();
|
||||||
map.put( 1L, new SourceFoo( "Bob" ) );
|
map.put( 1L, new SourceFoo( "Bob" ) );
|
||||||
map.put( 2L, new SourceFoo( "Alice" ) );
|
map.put( 2L, new SourceFoo( "Alice" ) );
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ public class NoSetterCollectionMappingTest {
|
|||||||
public void compilesAndMapsCorrectly() {
|
public void compilesAndMapsCorrectly() {
|
||||||
NoSetterSource source = new NoSetterSource();
|
NoSetterSource source = new NoSetterSource();
|
||||||
source.setListValues( Arrays.asList( "foo", "bar" ) );
|
source.setListValues( Arrays.asList( "foo", "bar" ) );
|
||||||
HashMap<String, String> mapValues = new HashMap<String, String>();
|
HashMap<String, String> mapValues = new HashMap<>();
|
||||||
mapValues.put( "fooKey", "fooVal" );
|
mapValues.put( "fooKey", "fooVal" );
|
||||||
mapValues.put( "barKey", "barVal" );
|
mapValues.put( "barKey", "barVal" );
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ public class Target {
|
|||||||
|
|
||||||
public List<TargetFoo> getFooListNoSetter() {
|
public List<TargetFoo> getFooListNoSetter() {
|
||||||
if ( fooListNoSetter == null ) {
|
if ( fooListNoSetter == null ) {
|
||||||
fooListNoSetter = new ArrayList<TargetFoo>();
|
fooListNoSetter = new ArrayList<>();
|
||||||
}
|
}
|
||||||
return fooListNoSetter;
|
return fooListNoSetter;
|
||||||
}
|
}
|
||||||
|
@ -45,14 +45,11 @@ public class TargetFoo implements Comparable<TargetFoo> {
|
|||||||
}
|
}
|
||||||
TargetFoo other = (TargetFoo) obj;
|
TargetFoo other = (TargetFoo) obj;
|
||||||
if ( name == null ) {
|
if ( name == null ) {
|
||||||
if ( other.name != null ) {
|
return other.name == null;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if ( !name.equals( other.name ) ) {
|
else {
|
||||||
return false;
|
return name.equals( other.name );
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,7 +34,7 @@ public class ImmutableProductTest {
|
|||||||
CupboardDto in = new CupboardDto();
|
CupboardDto in = new CupboardDto();
|
||||||
in.setContent( Arrays.asList( "cups", "soucers" ) );
|
in.setContent( Arrays.asList( "cups", "soucers" ) );
|
||||||
CupboardEntity out = new CupboardEntity();
|
CupboardEntity out = new CupboardEntity();
|
||||||
out.setContent( Collections.<String>emptyList() );
|
out.setContent( Collections.emptyList() );
|
||||||
|
|
||||||
CupboardMapper.INSTANCE.map( in, out );
|
CupboardMapper.INSTANCE.map( in, out );
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ package org.mapstruct.ap.test.collection.map;
|
|||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.entry;
|
import static org.assertj.core.api.Assertions.entry;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -32,9 +33,9 @@ public class MapMappingTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateMapMethodImplementation() {
|
public void shouldCreateMapMethodImplementation() {
|
||||||
Map<Long, Date> values = new HashMap<Long, Date>();
|
Map<Long, Date> values = new HashMap<>();
|
||||||
values.put( 42L, new GregorianCalendar( 1980, 0, 1 ).getTime() );
|
values.put( 42L, new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime() );
|
||||||
values.put( 121L, new GregorianCalendar( 2013, 6, 20 ).getTime() );
|
values.put( 121L, new GregorianCalendar( 2013, Calendar.JULY, 20 ).getTime() );
|
||||||
|
|
||||||
Map<String, String> target = SourceTargetMapper.INSTANCE.longDateMapToStringStringMap( values );
|
Map<String, String> target = SourceTargetMapper.INSTANCE.longDateMapToStringStringMap( values );
|
||||||
|
|
||||||
@ -60,8 +61,8 @@ public class MapMappingTest {
|
|||||||
public void shouldCreateMapMethodImplementationWithTargetParameter() {
|
public void shouldCreateMapMethodImplementationWithTargetParameter() {
|
||||||
Map<String, String> values = createStringStringMap();
|
Map<String, String> values = createStringStringMap();
|
||||||
|
|
||||||
Map<Long, Date> target = new HashMap<Long, Date>();
|
Map<Long, Date> target = new HashMap<>();
|
||||||
target.put( 66L, new GregorianCalendar( 2013, 7, 16 ).getTime() );
|
target.put( 66L, new GregorianCalendar( 2013, Calendar.AUGUST, 16 ).getTime() );
|
||||||
|
|
||||||
SourceTargetMapper.INSTANCE.stringStringMapToLongDateMapUsingTargetParameter( target, values );
|
SourceTargetMapper.INSTANCE.stringStringMapToLongDateMapUsingTargetParameter( target, values );
|
||||||
|
|
||||||
@ -73,8 +74,8 @@ public class MapMappingTest {
|
|||||||
public void shouldCreateMapMethodImplementationWithReturnedTargetParameter() {
|
public void shouldCreateMapMethodImplementationWithReturnedTargetParameter() {
|
||||||
Map<String, String> values = createStringStringMap();
|
Map<String, String> values = createStringStringMap();
|
||||||
|
|
||||||
Map<Long, Date> target = new HashMap<Long, Date>();
|
Map<Long, Date> target = new HashMap<>();
|
||||||
target.put( 66L, new GregorianCalendar( 2013, 7, 16 ).getTime() );
|
target.put( 66L, new GregorianCalendar( 2013, Calendar.AUGUST, 16 ).getTime() );
|
||||||
|
|
||||||
Map<Long, Date> returnedTarget = SourceTargetMapper.INSTANCE
|
Map<Long, Date> returnedTarget = SourceTargetMapper.INSTANCE
|
||||||
.stringStringMapToLongDateMapUsingTargetParameterAndReturn( values, target );
|
.stringStringMapToLongDateMapUsingTargetParameterAndReturn( values, target );
|
||||||
@ -88,13 +89,13 @@ public class MapMappingTest {
|
|||||||
assertThat( target ).isNotNull();
|
assertThat( target ).isNotNull();
|
||||||
assertThat( target ).hasSize( 2 );
|
assertThat( target ).hasSize( 2 );
|
||||||
assertThat( target ).contains(
|
assertThat( target ).contains(
|
||||||
entry( 42L, new GregorianCalendar( 1980, 0, 1 ).getTime() ),
|
entry( 42L, new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime() ),
|
||||||
entry( 121L, new GregorianCalendar( 2013, 6, 20 ).getTime() )
|
entry( 121L, new GregorianCalendar( 2013, Calendar.JULY, 20 ).getTime() )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> createStringStringMap() {
|
private Map<String, String> createStringStringMap() {
|
||||||
Map<String, String> values = new HashMap<String, String>();
|
Map<String, String> values = new HashMap<>();
|
||||||
values.put( "42", "01.01.1980" );
|
values.put( "42", "01.01.1980" );
|
||||||
values.put( "121", "20.07.2013" );
|
values.put( "121", "20.07.2013" );
|
||||||
return values;
|
return values;
|
||||||
@ -102,13 +103,13 @@ public class MapMappingTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldInvokeMapMethodImplementationForMapTypedProperty() {
|
public void shouldInvokeMapMethodImplementationForMapTypedProperty() {
|
||||||
Map<Long, Date> values = new HashMap<Long, Date>();
|
Map<Long, Date> values = new HashMap<>();
|
||||||
values.put( 42L, new GregorianCalendar( 1980, 0, 1 ).getTime() );
|
values.put( 42L, new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime() );
|
||||||
values.put( 121L, new GregorianCalendar( 2013, 6, 20 ).getTime() );
|
values.put( 121L, new GregorianCalendar( 2013, Calendar.JULY, 20 ).getTime() );
|
||||||
|
|
||||||
Source source = new Source();
|
Source source = new Source();
|
||||||
source.setValues( values );
|
source.setValues( values );
|
||||||
source.setPublicValues( new HashMap<Long, Date>( values ) );
|
source.setPublicValues( new HashMap<>( values ) );
|
||||||
|
|
||||||
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
Target target = SourceTargetMapper.INSTANCE.sourceToTarget( source );
|
||||||
|
|
||||||
@ -135,7 +136,7 @@ public class MapMappingTest {
|
|||||||
|
|
||||||
Target target = new Target();
|
Target target = new Target();
|
||||||
target.setValues( values );
|
target.setValues( values );
|
||||||
target.publicValues = new HashMap<String, String>( values );
|
target.publicValues = new HashMap<>( values );
|
||||||
|
|
||||||
Source source = SourceTargetMapper.INSTANCE.targetToSource( target );
|
Source source = SourceTargetMapper.INSTANCE.targetToSource( target );
|
||||||
|
|
||||||
@ -143,21 +144,21 @@ public class MapMappingTest {
|
|||||||
assertThat( source.getValues() ).isNotNull();
|
assertThat( source.getValues() ).isNotNull();
|
||||||
assertThat( source.getValues() ).hasSize( 2 );
|
assertThat( source.getValues() ).hasSize( 2 );
|
||||||
assertThat( source.getValues() ).contains(
|
assertThat( source.getValues() ).contains(
|
||||||
entry( 42L, new GregorianCalendar( 1980, 0, 1 ).getTime() ),
|
entry( 42L, new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime() ),
|
||||||
entry( 121L, new GregorianCalendar( 2013, 6, 20 ).getTime() )
|
entry( 121L, new GregorianCalendar( 2013, Calendar.JULY, 20 ).getTime() )
|
||||||
);
|
);
|
||||||
|
|
||||||
assertThat( source.getPublicValues() )
|
assertThat( source.getPublicValues() )
|
||||||
.isNotNull()
|
.isNotNull()
|
||||||
.hasSize( 2 )
|
.hasSize( 2 )
|
||||||
.contains(
|
.contains(
|
||||||
entry( 42L, new GregorianCalendar( 1980, 0, 1 ).getTime() ),
|
entry( 42L, new GregorianCalendar( 1980, Calendar.JANUARY, 1 ).getTime() ),
|
||||||
entry( 121L, new GregorianCalendar( 2013, 6, 20 ).getTime() )
|
entry( 121L, new GregorianCalendar( 2013, Calendar.JULY, 20 ).getTime() )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<Integer, Integer> createIntIntMap() {
|
private Map<Integer, Integer> createIntIntMap() {
|
||||||
Map<Integer, Integer> values = new HashMap<Integer, Integer>();
|
Map<Integer, Integer> values = new HashMap<>();
|
||||||
values.put( 42, 47 );
|
values.put( 42, 47 );
|
||||||
values.put( 121, 123 );
|
values.put( 121, 123 );
|
||||||
return values;
|
return values;
|
||||||
|
@ -29,7 +29,7 @@ public abstract class BeanMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JAXBElement<? super BigDecimal> map(BigDecimal value) {
|
JAXBElement<? super BigDecimal> map(BigDecimal value) {
|
||||||
return new JAXBElement<BigDecimal>( new QName( "test" ), BigDecimal.class, value );
|
return new JAXBElement<>( new QName( "test" ), BigDecimal.class, value );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ public class WildCardTest {
|
|||||||
public void shouldMapBean() {
|
public void shouldMapBean() {
|
||||||
|
|
||||||
GoodIdea aGoodIdea = new GoodIdea();
|
GoodIdea aGoodIdea = new GoodIdea();
|
||||||
aGoodIdea.setContent( new JAXBElement<BigDecimal>( new QName( "test" ), BigDecimal.class, BigDecimal.ONE ) );
|
aGoodIdea.setContent( new JAXBElement<>( new QName( "test" ), BigDecimal.class, BigDecimal.ONE ) );
|
||||||
aGoodIdea.setDescription( BigDecimal.ZERO );
|
aGoodIdea.setDescription( BigDecimal.ZERO );
|
||||||
|
|
||||||
CunningPlan aCunningPlan = BeanMapper.STM.transformA( aGoodIdea );
|
CunningPlan aCunningPlan = BeanMapper.STM.transformA( aGoodIdea );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user