Search in sources :

Example 56 with ProcessorTest

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

the class Issue892Test method compiles.

@ProcessorTest
public void compiles() {
    Source src = new Source();
    src.setType(42);
    Target target = Mappers.getMapper(Issue892Mapper.class).toTarget(src);
    assertThat(target.getType()).isEqualTo(42);
}
Also used : Target(org.mapstruct.ap.test.bugs._892.Issue892Mapper.Target) Source(org.mapstruct.ap.test.bugs._892.Issue892Mapper.Source) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 57 with ProcessorTest

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

the class Issue895Test method properlyMapsMultiDimensionalArrays.

@ProcessorTest
public void properlyMapsMultiDimensionalArrays() {
    WithArrayOfByteArray arrayOfByteArray = new WithArrayOfByteArray();
    arrayOfByteArray.setBytes(new byte[][] { new byte[] { 0, 1 }, new byte[] { 1, 2 } });
    WithListOfByteArray listOfByteArray = Mappers.getMapper(MultiArrayMapper.class).convert(arrayOfByteArray);
    assertThat(listOfByteArray.getBytes()).containsExactly(new byte[] { 0, 1 }, new byte[] { 1, 2 });
    arrayOfByteArray = Mappers.getMapper(MultiArrayMapper.class).convert(listOfByteArray);
    assertThat(arrayOfByteArray.getBytes()).isDeepEqualTo(new byte[][] { { 0, 1 }, { 1, 2 } });
}
Also used : WithListOfByteArray(org.mapstruct.ap.test.bugs._895.MultiArrayMapper.WithListOfByteArray) WithArrayOfByteArray(org.mapstruct.ap.test.bugs._895.MultiArrayMapper.WithArrayOfByteArray) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 58 with ProcessorTest

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

the class NamedTest 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 59 with ProcessorTest

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

the class UnderscoreSelectionTest method selectingUnderscorePropertiesWorks.

@ProcessorTest
public void selectingUnderscorePropertiesWorks() {
    SubType target = UnderscoreMapper.INSTANCE.map(createSource());
    assertThat(target.getInheritedUnderscore().getValue()).isEqualTo("hi");
    assertThat(target.getDeclaredUnderscore().getValue()).isEqualTo("there");
}
Also used : SubType(org.mapstruct.ap.test.selection.jaxb.underscores.SubType) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 60 with ProcessorTest

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

the class JavaDefaultExpressionTest method testJavaDefaultExpressionWithValues.

@ProcessorTest
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class })
public void testJavaDefaultExpressionWithValues() {
    Source source = new Source();
    source.setId(123);
    source.setDate(new Date(0L));
    Target target = SourceTargetMapper.INSTANCE.sourceToTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getSourceId()).isEqualTo("123");
    assertThat(target.getSourceDate()).isEqualTo(source.getDate());
}
Also used : Date(java.util.Date) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Aggregations

ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)314 WithClasses (org.mapstruct.ap.testutil.WithClasses)118 GeneratedSource (org.mapstruct.ap.testutil.runner.GeneratedSource)51 IssueKey (org.mapstruct.ap.testutil.IssueKey)39 XmlGregorianCalendarBean (org.mapstruct.ap.test.builtin.jodatime.bean.XmlGregorianCalendarBean)24 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)22 Date (java.util.Date)16 LocalDateTimeBean (org.mapstruct.ap.test.builtin.jodatime.bean.LocalDateTimeBean)16 Calendar (java.util.Calendar)13 LocalDateTime (org.joda.time.LocalDateTime)13 CarDto (org.mapstruct.ap.test.complex._target.CarDto)13 Car (org.mapstruct.ap.test.complex.source.Car)13 PersonDto (org.mapstruct.ap.test.constructor.PersonDto)13 GregorianCalendar (java.util.GregorianCalendar)12 XmlGregorianCalendarProperty (org.mapstruct.ap.test.builtin.bean.XmlGregorianCalendarProperty)12 Song (org.mapstruct.ap.test.nestedsourceproperties.source.Song)12 BigDecimal (java.math.BigDecimal)11 ChartEntry (org.mapstruct.ap.test.nestedsourceproperties._target.ChartEntry)11 DriverAndCarDto (org.mapstruct.ap.test.nullvaluemapping._target.DriverAndCarDto)11 DateTime (org.joda.time.DateTime)10