Skip to content

Commit

Permalink
mapstruct#1001 Change meaningless names in MultipleForgedMethodTest t…
Browse files Browse the repository at this point in the history
…o Dictionaries and Words to make test data easier to understand
  • Loading branch information
navpil committed Jan 25, 2017
1 parent 5088aa0 commit ef1c95a
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mapstruct.ap.test.nestedbeans.maps.AntonymsDictionary;
import org.mapstruct.ap.test.nestedbeans.maps.AntonymsDictionaryDto;
import org.mapstruct.ap.test.nestedbeans.maps.AutoMapMapper;
import org.mapstruct.ap.test.nestedbeans.maps.Bar;
import org.mapstruct.ap.test.nestedbeans.maps.BarDto;
import org.mapstruct.ap.test.nestedbeans.maps.Dto;
import org.mapstruct.ap.test.nestedbeans.maps.Entity;
import org.mapstruct.ap.test.nestedbeans.maps.Word;
import org.mapstruct.ap.test.nestedbeans.maps.WordDto;
import org.mapstruct.ap.test.nestedbeans.multiplecollections.Garage;
import org.mapstruct.ap.test.nestedbeans.multiplecollections.GarageDto;
import org.mapstruct.ap.test.nestedbeans.multiplecollections.MultipleListMapper;
Expand All @@ -42,23 +42,32 @@
public class MultipleForgedMethodsTest {

@WithClasses({
Bar.class, BarDto.class, Dto.class, Entity.class, AutoMapMapper.class
Word.class, WordDto.class, AntonymsDictionaryDto.class, AntonymsDictionary.class, AutoMapMapper.class
})
@Test
public void testNestedMapsAutoMap() {

HashMap<BarDto, BarDto> dtoMap = new HashMap<BarDto, BarDto>();
HashMap<Bar, Bar> entityMap = new HashMap<Bar, Bar>();
for ( int i = 0; i < 10; i++ ) {
String key = "key-" + i;
String value = "value-" + i;
dtoMap.put( new BarDto( key ), new BarDto( value ) );
entityMap.put( new Bar( key ), new Bar( value ) );
HashMap<WordDto, WordDto> dtoAntonyms = new HashMap<WordDto, WordDto>();
HashMap<Word, Word> entityAntonyms = new HashMap<Word, Word>();

String[] words = { "black", "good", "up", "left", "fast" };
String[] antonyms = { "white", "bad", "down", "right", "slow" };

assert words.length == antonyms.length : "Words length and antonyms length differ, please fix test data";

for ( int i = 0; i < words.length; i++ ) {
String word = words[i];
String antonym = antonyms[i];
dtoAntonyms.put( new WordDto( word ), new WordDto( antonym ) );
entityAntonyms.put( new Word( word ), new Word( antonym ) );
}

Entity mappedEntity = AutoMapMapper.INSTANCE.entityToDto( new Dto( dtoMap ) );
AntonymsDictionary mappedAntonymsDictionary = AutoMapMapper.INSTANCE.entityToDto(
new AntonymsDictionaryDto( dtoAntonyms ) );

Assert.assertEquals( "Mapper did not map dto to entity correctly", new Entity( entityMap ), mappedEntity );
Assert.assertEquals( "Mapper did not map dto to entity correctly", new AntonymsDictionary( entityAntonyms ),
mappedAntonymsDictionary
);
}

@WithClasses({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@

import java.util.Map;

public class Dto {
private Map<BarDto, BarDto> map;
public class AntonymsDictionary {
private Map<Word, Word> antonyms;

public Dto() {
public AntonymsDictionary() {
}

public Dto(Map<BarDto, BarDto> map) {
this.map = map;
public AntonymsDictionary(Map<Word, Word> antonyms) {
this.antonyms = antonyms;
}

public Map<BarDto, BarDto> getMap() {
return map;
public Map<Word, Word> getAntonyms() {
return antonyms;
}

public void setMap(Map<BarDto, BarDto> map) {
this.map = map;
public void setAntonyms(Map<Word, Word> antonyms) {
this.antonyms = antonyms;
}

@Override
Expand All @@ -47,14 +47,14 @@ public boolean equals(Object o) {
return false;
}

Dto dto = (Dto) o;
AntonymsDictionary antonymsDictionary = (AntonymsDictionary) o;

return map != null ? map.equals( dto.map ) : dto.map == null;
return antonyms != null ? antonyms.equals( antonymsDictionary.antonyms ) : antonymsDictionary.antonyms == null;

}

@Override
public int hashCode() {
return map != null ? map.hashCode() : 0;
return antonyms != null ? antonyms.hashCode() : 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@

import java.util.Map;

public class Entity {
private Map<Bar, Bar> map;
public class AntonymsDictionaryDto {
private Map<WordDto, WordDto> antonyms;

public Entity() {
public AntonymsDictionaryDto() {
}

public Entity(Map<Bar, Bar> map) {
this.map = map;
public AntonymsDictionaryDto(Map<WordDto, WordDto> antonyms) {
this.antonyms = antonyms;
}

public Map<Bar, Bar> getMap() {
return map;
public Map<WordDto, WordDto> getAntonyms() {
return antonyms;
}

public void setMap(Map<Bar, Bar> map) {
this.map = map;
public void setAntonyms(Map<WordDto, WordDto> antonyms) {
this.antonyms = antonyms;
}

@Override
Expand All @@ -47,14 +47,15 @@ public boolean equals(Object o) {
return false;
}

Entity entity = (Entity) o;
AntonymsDictionaryDto antonymsDictionaryDto = (AntonymsDictionaryDto) o;

return map != null ? map.equals( entity.map ) : entity.map == null;
return antonyms != null ? antonyms.equals( antonymsDictionaryDto.antonyms ) :
antonymsDictionaryDto.antonyms == null;

}

@Override
public int hashCode() {
return map != null ? map.hashCode() : 0;
return antonyms != null ? antonyms.hashCode() : 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ public interface AutoMapMapper {

AutoMapMapper INSTANCE = Mappers.getMapper( AutoMapMapper.class );

Entity entityToDto(Dto dto);
AntonymsDictionary entityToDto(AntonymsDictionaryDto antonymsDictionaryDto);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@
*/
package org.mapstruct.ap.test.nestedbeans.maps;

public class Bar {
private String name;
public class Word {
private String textValue;

public Bar() {
public Word() {
}

public Bar(String name) {
this.name = name;
public Word(String textValue) {
this.textValue = textValue;
}

public String getName() {
return name;
public String getTextValue() {
return textValue;
}

public void setName(String name) {
this.name = name;
public void setTextValue(String textValue) {
this.textValue = textValue;
}

@Override
Expand All @@ -45,14 +45,14 @@ public boolean equals(Object o) {
return false;
}

Bar bar = (Bar) o;
Word word = (Word) o;

return name != null ? name.equals( bar.name ) : bar.name == null;
return textValue != null ? textValue.equals( word.textValue ) : word.textValue == null;

}

@Override
public int hashCode() {
return name != null ? name.hashCode() : 0;
return textValue != null ? textValue.hashCode() : 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@
*/
package org.mapstruct.ap.test.nestedbeans.maps;

public class BarDto {
private String name;
public class WordDto {
private String textValue;

public BarDto() {
public WordDto() {
}

public BarDto(String name) {
this.name = name;
public WordDto(String textValue) {
this.textValue = textValue;
}

public String getName() {
return name;
public String getTextValue() {
return textValue;
}

public void setName(String name) {
this.name = name;
public void setTextValue(String textValue) {
this.textValue = textValue;
}

@Override
Expand All @@ -45,14 +45,14 @@ public boolean equals(Object o) {
return false;
}

BarDto barDto = (BarDto) o;
WordDto wordDto = (WordDto) o;

return name != null ? name.equals( barDto.name ) : barDto.name == null;
return textValue != null ? textValue.equals( wordDto.textValue ) : wordDto.textValue == null;

}

@Override
public int hashCode() {
return name != null ? name.hashCode() : 0;
return textValue != null ? textValue.hashCode() : 0;
}
}

0 comments on commit ef1c95a

Please sign in to comment.