Search in sources :

Example 11 with IssueKey

use of org.mapstruct.ap.testutil.IssueKey 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 12 with IssueKey

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

the class InnerClassesImportsTest method mapperRequiresInnerClassImports.

@ProcessorTest
@IssueKey("412")
public void mapperRequiresInnerClassImports() {
    SourceWithInnerClass source = new SourceWithInnerClass();
    source.setInnerClassMember(new SourceInnerClass(412));
    TargetWithInnerClass target = InnerClassMapper.INSTANCE.sourceToTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getInnerClassMember().getValue()).isEqualTo(412);
    generatedSource.addComparisonToFixtureFor(InnerClassMapper.class);
}
Also used : SourceWithInnerClass(org.mapstruct.ap.test.imports.innerclasses.SourceWithInnerClass) SourceInnerClass(org.mapstruct.ap.test.imports.innerclasses.SourceWithInnerClass.SourceInnerClass) TargetWithInnerClass(org.mapstruct.ap.test.imports.innerclasses.TargetWithInnerClass) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 13 with IssueKey

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

the class InnerClassesImportsTest method mapperRequiresInnerInnerClassImports.

@ProcessorTest
@IssueKey("412")
public void mapperRequiresInnerInnerClassImports() {
    SourceInnerClass source = new SourceInnerClass();
    source.setValue(412);
    TargetInnerInnerClass target = InnerClassMapper.INSTANCE.innerSourceToInnerInnerTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getValue()).isEqualTo(412);
    generatedSource.addComparisonToFixtureFor(InnerClassMapper.class);
}
Also used : SourceInnerClass(org.mapstruct.ap.test.imports.innerclasses.SourceWithInnerClass.SourceInnerClass) TargetInnerInnerClass(org.mapstruct.ap.test.imports.innerclasses.TargetWithInnerClass.TargetInnerClass.TargetInnerInnerClass) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 14 with IssueKey

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

the class InnerClassesImportsTest method mapperRequiresInnerEnumImports.

@ProcessorTest
@IssueKey("209")
public void mapperRequiresInnerEnumImports() {
    BeanWithInnerEnum source = new BeanWithInnerEnum();
    source.setTest("whatever");
    source.setInnerEnum(InnerEnum.A);
    BeanFacade target = BeanWithInnerEnumMapper.INSTANCE.toFacade(source);
    assertThat(target).isNotNull();
    assertThat(target.getInnerEnum()).isEqualTo("A");
    BeanWithInnerEnum sourceAgain = BeanWithInnerEnumMapper.INSTANCE.fromFacade(target);
    assertThat(sourceAgain).isNotNull();
    assertThat(sourceAgain.getInnerEnum()).isEqualTo(InnerEnum.A);
    generatedSource.addComparisonToFixtureFor(BeanWithInnerEnumMapper.class);
}
Also used : BeanWithInnerEnum(org.mapstruct.ap.test.imports.innerclasses.BeanWithInnerEnum) BeanFacade(org.mapstruct.ap.test.imports.innerclasses.BeanFacade) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 15 with IssueKey

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

the class SourceTypeContainsCollectionWithExtendsBoundTest method generatesImportsForCollectionWithExtendsBoundInSourceType.

@ProcessorTest
@IssueKey("768")
public void generatesImportsForCollectionWithExtendsBoundInSourceType() {
    Astronaut astronaut = new Astronaut();
    astronaut.setName("Bob");
    Spaceship spaceship = new Spaceship();
    spaceship.setAstronauts(Collections.singleton(astronaut));
    SpaceshipDto spaceshipDto = SpaceshipMapper.INSTANCE.spaceshipToDto(spaceship);
    assertThat(spaceshipDto).isNotNull();
    assertThat(spaceshipDto.getAstronauts()).extracting("name").containsOnly("Bob");
    generatedSource.forMapper(SpaceshipMapper.class).containsImportFor(Astronaut.class);
    generatedSource.forMapper(SpaceshipMapper.class).containsImportFor(Spaceship.class);
    generatedSource.forMapper(SpaceshipMapper.class).containsImportFor(AstronautDto.class);
    generatedSource.forMapper(SpaceshipMapper.class).containsImportFor(SpaceshipDto.class);
}
Also used : Astronaut(org.mapstruct.ap.test.imports.sourcewithextendsbound.entity.Astronaut) SpaceshipDto(org.mapstruct.ap.test.imports.sourcewithextendsbound.dto.SpaceshipDto) Spaceship(org.mapstruct.ap.test.imports.sourcewithextendsbound.entity.Spaceship) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Aggregations

IssueKey (org.mapstruct.ap.testutil.IssueKey)38 ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)36 WithClasses (org.mapstruct.ap.testutil.WithClasses)14 Date (java.util.Date)6 GeneratedSource (org.mapstruct.ap.testutil.runner.GeneratedSource)6 BigInteger (java.math.BigInteger)4 Target (org.mapstruct.ap.test.collection.adder._target.Target)4 SingleElementSource (org.mapstruct.ap.test.collection.adder.source.SingleElementSource)4 BigDecimal (java.math.BigDecimal)3 HashMap (java.util.HashMap)3 Source (org.mapstruct.ap.test.collection.adder.source.Source)3 OriginalRelease (org.mapstruct.ap.test.selection.qualifier.bean.OriginalRelease)3 Time (java.sql.Time)2 Timestamp (java.sql.Timestamp)2 SimpleDateFormat (java.text.SimpleDateFormat)2 GregorianCalendar (java.util.GregorianCalendar)2 List (java.util.List)2 ListAssert (org.assertj.core.api.ListAssert)2 Test (org.junit.Test)2 Target (org.mapstruct.ap.test.bugs._1170._target.Target)2