Search in sources :

Example 81 with WithClasses

use of org.mapstruct.ap.testutil.WithClasses in project mapstruct by mapstruct.

the class QualifierTest method shouldNotUseQualifierAnnotatedMethod.

@ProcessorTest
@WithClasses({ MapperWithoutQualifiedBy.class, Facts.class, EnglishToGerman.class, Reverse.class })
@IssueKey("341")
public void shouldNotUseQualifierAnnotatedMethod() {
    OriginalRelease foreignMovies = new OriginalRelease();
    foreignMovies.setTitle("Sixth Sense, The");
    GermanRelease result = MapperWithoutQualifiedBy.INSTANCE.map(foreignMovies);
    assertThat(result).isNotNull();
    assertThat(result.getTitle()).isEqualTo("ehT ,esneS htxiS");
}
Also used : GermanRelease(org.mapstruct.ap.test.selection.qualifier.bean.GermanRelease) CreateGermanRelease(org.mapstruct.ap.test.selection.qualifier.annotation.CreateGermanRelease) OriginalRelease(org.mapstruct.ap.test.selection.qualifier.bean.OriginalRelease) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 82 with WithClasses

use of org.mapstruct.ap.testutil.WithClasses in project mapstruct by mapstruct.

the class QualifierTest method shouldMatchClassAndMethod.

@ProcessorTest
@WithClasses({ Titles.class, Facts.class, PlotWords.class, OriginalRelease.class, EnglishToGerman.class, TitleTranslator.class, MovieMapper.class, KeyWordMapper.class, FactMapper.class })
public void shouldMatchClassAndMethod() {
    OriginalRelease foreignMovies = new OriginalRelease();
    foreignMovies.setTitle("Sixth Sense, The");
    foreignMovies.setKeyWords(Arrays.asList("evergreen", "magnificent"));
    Map<String, List<String>> facts = new HashMap<>();
    facts.put("director", Arrays.asList("M. Night Shyamalan"));
    facts.put("cast", Arrays.asList("Bruce Willis", "Haley Joel Osment", "Toni Collette"));
    facts.put("plot keywords", Arrays.asList("boy", "child psychologist", "I see dead people"));
    foreignMovies.setFacts(facts);
    GermanRelease germanMovies = MovieMapper.INSTANCE.toGerman(foreignMovies);
    assertThat(germanMovies).isNotNull();
    assertThat(germanMovies.getTitle()).isEqualTo("Der sechste Sinn");
    assertThat(germanMovies.getKeyWords()).isNotNull();
    assertThat(germanMovies.getKeyWords().size()).isEqualTo(2);
    assertThat(germanMovies.getKeyWords()).containsSequence("Evergreen", "Großartig");
    assertThat(germanMovies.getFacts()).isNotNull();
    assertThat(germanMovies.getFacts()).hasSize(3);
    assertThat(germanMovies.getFacts()).contains(entry("Regisseur", Arrays.asList("M. Night Shyamalan")), entry("Besetzung", Arrays.asList("Bruce Willis", "Haley Joel Osment", "Toni Collette")), entry("Handlungstichwörter", Arrays.asList("Jungen", "Kinderpsychologe", "Ich sehe tote Menschen")));
}
Also used : GermanRelease(org.mapstruct.ap.test.selection.qualifier.bean.GermanRelease) CreateGermanRelease(org.mapstruct.ap.test.selection.qualifier.annotation.CreateGermanRelease) OriginalRelease(org.mapstruct.ap.test.selection.qualifier.bean.OriginalRelease) HashMap(java.util.HashMap) List(java.util.List) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 83 with WithClasses

use of org.mapstruct.ap.testutil.WithClasses in project mapstruct by mapstruct.

the class QualifierTest method testFactorySelectionWithQualifier.

@ProcessorTest
@WithClasses({ MovieFactoryMapper.class, ReleaseFactory.class, CreateGermanRelease.class })
@IssueKey("342")
public void testFactorySelectionWithQualifier() {
    OriginalRelease foreignMovies = new OriginalRelease();
    foreignMovies.setTitle("Sixth Sense, The");
    foreignMovies.setKeyWords(Arrays.asList("evergreen", "magnificent"));
    Map<String, List<String>> facts = new HashMap<>();
    facts.put("director", Arrays.asList("M. Night Shyamalan"));
    facts.put("cast", Arrays.asList("Bruce Willis", "Haley Joel Osment", "Toni Collette"));
    facts.put("plot keywords", Arrays.asList("boy", "child psychologist", "I see dead people"));
    foreignMovies.setFacts(facts);
    AbstractEntry abstractEntry = MovieFactoryMapper.INSTANCE.toGerman(foreignMovies);
    assertThat(abstractEntry).isNotNull();
    assertThat(abstractEntry).isInstanceOf(GermanRelease.class);
    assertThat(abstractEntry.getTitle()).isEqualTo("Sixth Sense, The");
    assertThat(abstractEntry.getKeyWords()).isNotNull();
    assertThat(abstractEntry.getKeyWords().size()).isEqualTo(2);
    assertThat(abstractEntry.getKeyWords()).containsSequence("evergreen", "magnificent");
    assertThat(abstractEntry.getFacts()).isNotNull();
    assertThat(abstractEntry.getFacts()).hasSize(3);
    assertThat(abstractEntry.getFacts()).contains(entry("director", Arrays.asList("M. Night Shyamalan")), entry("cast", Arrays.asList("Bruce Willis", "Haley Joel Osment", "Toni Collette")), entry("plot keywords", Arrays.asList("boy", "child psychologist", "I see dead people")));
}
Also used : AbstractEntry(org.mapstruct.ap.test.selection.qualifier.bean.AbstractEntry) OriginalRelease(org.mapstruct.ap.test.selection.qualifier.bean.OriginalRelease) HashMap(java.util.HashMap) List(java.util.List) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 84 with WithClasses

use of org.mapstruct.ap.testutil.WithClasses in project mapstruct by mapstruct.

the class JavaExpressionTest method testJavaExpressionInsertionWithSeveralSources.

@IssueKey("255")
@ProcessorTest
@WithClasses({ Source.class, Source2.class, Target.class, TimeAndFormat.class, SourceTargetMapperSeveralSources.class })
public void testJavaExpressionInsertionWithSeveralSources() throws ParseException {
    Source source1 = new Source();
    String format = "dd-MM-yyyy,hh:mm:ss";
    Date time = getTime(format, "09-01-2014,01:35:03");
    source1.setFormat(format);
    source1.setTime(time);
    Source2 source2 = new Source2();
    source2.setAnotherProp("test");
    Target target = SourceTargetMapperSeveralSources.INSTANCE.sourceToTarget(source1, source2);
    assertThat(target).isNotNull();
    assertThat(target.getTimeAndFormat().getTime()).isEqualTo(time);
    assertThat(target.getTimeAndFormat().getFormat()).isEqualTo(format);
    assertThat(target.getAnotherProp()).isEqualTo("test");
}
Also used : Date(java.util.Date) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 85 with WithClasses

use of org.mapstruct.ap.testutil.WithClasses in project mapstruct by mapstruct.

the class JavaExpressionTest method testJavaExpressionInsertion.

@ProcessorTest
@WithClasses({ Source.class, Target.class, TimeAndFormat.class, SourceTargetMapper.class })
public void testJavaExpressionInsertion() throws ParseException {
    Source source = new Source();
    String format = "dd-MM-yyyy,hh:mm:ss";
    Date time = getTime(format, "09-01-2014,01:35:03");
    source.setFormat(format);
    source.setTime(time);
    Target target = SourceTargetMapper.INSTANCE.sourceToTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getTimeAndFormat().getTime()).isEqualTo(time);
    assertThat(target.getTimeAndFormat().getFormat()).isEqualTo(format);
    assertThat(target.getAnotherProp()).isNull();
}
Also used : Date(java.util.Date) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Aggregations

WithClasses (org.mapstruct.ap.testutil.WithClasses)119 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)118 XmlGregorianCalendarBean (org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean)24 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)17 IssueKey (org.mapstruct.ap.testutil.IssueKey)17 LocalDateTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean)16 XmlGregorianCalendarProperty (org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty)12 Song (org.mapstruct.ap.test.nestedsourceproperties.source.Song)11 DateTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.DateTimeBean)10 CalendarProperty (org.mapstruct.ap.test.builtin.bean.CalendarProperty)8 Song (org.mapstruct.ap.test.constructor.nestedsource.source.Song)8 ChartEntry (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry)7 BigDecimal (java.math.BigDecimal)6 BigInteger (java.math.BigInteger)6 ChartEntry (org.mapstruct.ap.test.constructor.nestedsource._target.ChartEntry)6 Date (java.util.Date)5 LocalDateTime (org.joda.time.LocalDateTime)5 StringProperty (org.mapstruct.ap.test.builtin.bean.StringProperty)5 XmlGregorianCalendarToLocalDateTime (org.mapstruct.ap.test.builtin.jodatime.mapper.XmlGregorianCalendarToLocalDateTime)5 VehicleCollection (org.mapstruct.ap.test.subclassmapping.mappables.VehicleCollection)5