Search in sources :

Example 21 with IssueKey

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

the class SourcePropertyMapSeveralTimesTest method shouldMapSameSourcePropertyToSeveralTargetPropertiesInvokingOtherMapper.

@Test
@IssueKey("94")
public void shouldMapSameSourcePropertyToSeveralTargetPropertiesInvokingOtherMapper() throws ParseException {
    Source source = new Source();
    String sourceFormat = "dd-MM-yyyy";
    SimpleDateFormat dateFormat = new SimpleDateFormat(sourceFormat);
    Date sourceTime = dateFormat.parse("09-01-2014");
    TimeAndFormat sourceTimeAndFormat = new TimeAndFormat();
    sourceTimeAndFormat.setTfFormat(sourceFormat);
    sourceTimeAndFormat.setTfTime(sourceTime);
    source.setTimeAndFormat(sourceTimeAndFormat);
    Target target = SourceTargetMapper.INSTANCE.sourceToTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getFormat()).isEqualTo(sourceFormat);
    assertThat(target.getTime()).isEqualTo(sourceTime);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test) IssueKey(org.mapstruct.ap.testutil.IssueKey)

Example 22 with IssueKey

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

the class BigNumbersConversionTest method shouldApplyReverseBigDecimalConversions.

@ProcessorTest
@IssueKey("21")
@WithClasses({ BigDecimalSource.class, BigDecimalTarget.class, BigDecimalMapper.class })
public void shouldApplyReverseBigDecimalConversions() {
    BigDecimalTarget target = new BigDecimalTarget();
    target.setB((byte) 1);
    target.setBb((byte) 2);
    target.setS((short) 3);
    target.setSs((short) 4);
    target.setI(5);
    target.setIi(6);
    target.setL(7);
    target.setLl(8L);
    target.setF(9.0f);
    target.setFf(10.0f);
    target.setD(11.0d);
    target.setDd(12.0d);
    target.setString("13.45");
    target.setBigInteger(new BigInteger("14"));
    BigDecimalSource source = BigDecimalMapper.INSTANCE.targetToSource(target);
    assertThat(source).isNotNull();
    assertThat(source.getB()).isEqualTo(new BigDecimal("1"));
    assertThat(source.getBb()).isEqualTo(new BigDecimal("2"));
    assertThat(source.getS()).isEqualTo(new BigDecimal("3"));
    assertThat(source.getSs()).isEqualTo(new BigDecimal("4"));
    assertThat(source.getI()).isEqualTo(new BigDecimal("5"));
    assertThat(source.getIi()).isEqualTo(new BigDecimal("6"));
    assertThat(source.getL()).isEqualTo(new BigDecimal("7"));
    assertThat(source.getLl()).isEqualTo(new BigDecimal("8"));
    assertThat(source.getF()).isEqualTo(new BigDecimal("9.0"));
    assertThat(source.getFf()).isEqualTo(new BigDecimal("10.0"));
    assertThat(source.getD()).isEqualTo(new BigDecimal("11.0"));
    assertThat(source.getDd()).isEqualTo(new BigDecimal("12.0"));
    assertThat(source.getString()).isEqualTo(new BigDecimal("13.45"));
    assertThat(source.getBigInteger()).isEqualTo(new BigDecimal("14"));
}
Also used : BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 23 with IssueKey

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

the class BigNumbersConversionTest method shouldApplyBigIntegerConversions.

@ProcessorTest
@IssueKey("21")
@WithClasses({ BigIntegerSource.class, BigIntegerTarget.class, BigIntegerMapper.class })
public void shouldApplyBigIntegerConversions() {
    BigIntegerSource source = new BigIntegerSource();
    source.setB(new BigInteger("1"));
    source.setBb(new BigInteger("2"));
    source.setS(new BigInteger("3"));
    source.setSs(new BigInteger("4"));
    source.setI(new BigInteger("5"));
    source.setIi(new BigInteger("6"));
    source.setL(new BigInteger("7"));
    source.setLl(new BigInteger("8"));
    source.setF(new BigInteger("9"));
    source.setFf(new BigInteger("10"));
    source.setD(new BigInteger("11"));
    source.setDd(new BigInteger("12"));
    source.setString(new BigInteger("13"));
    BigIntegerTarget target = BigIntegerMapper.INSTANCE.sourceToTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getB()).isEqualTo((byte) 1);
    assertThat(target.getBb()).isEqualTo((byte) 2);
    assertThat(target.getS()).isEqualTo((short) 3);
    assertThat(target.getSs()).isEqualTo((short) 4);
    assertThat(target.getI()).isEqualTo(5);
    assertThat(target.getIi()).isEqualTo(6);
    assertThat(target.getL()).isEqualTo(7);
    assertThat(target.getLl()).isEqualTo(8);
    assertThat(target.getF()).isEqualTo(9.0f);
    assertThat(target.getFf()).isEqualTo(10.0f);
    assertThat(target.getD()).isEqualTo(11.0d);
    assertThat(target.getDd()).isEqualTo(12.0d);
    assertThat(target.getString()).isEqualTo("13");
}
Also used : BigInteger(java.math.BigInteger) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 24 with IssueKey

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

the class IgnorePropertyTest method shouldOnlyIgnoreBase.

@ProcessorTest
@IssueKey("1933")
public void shouldOnlyIgnoreBase() {
    WorkBenchDto workBenchDto = new WorkBenchDto();
    workBenchDto.setArticleName("MyBench");
    workBenchDto.setArticleDescription("Beautiful");
    workBenchDto.setCreationDate(new Date());
    workBenchDto.setModificationDate(new Date());
    WorkBenchEntity benchTarget = ToolMapper.INSTANCE.mapBenchWithImplicit(workBenchDto);
    assertThat(benchTarget).isNotNull();
    assertThat(benchTarget.getArticleName()).isEqualTo("MyBench");
    assertThat(benchTarget.getDescription()).isEqualTo("Beautiful");
    assertThat(benchTarget.getKey()).isNull();
    assertThat(benchTarget.getModificationDate()).isNull();
    assertThat(benchTarget.getCreationDate()).isNull();
}
Also used : Date(java.util.Date) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 25 with IssueKey

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

the class ConflictingTypesNamesTest method mapperHasNoUnnecessaryImports.

@ProcessorTest
@IssueKey("178")
public void mapperHasNoUnnecessaryImports() {
    Source source = new Source();
    source.setNotImported(new NotImportedDatatype(42));
    Target target = SourceTargetMapper.INSTANCE.sourceToTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getNotImported()).isSameAs(source.getNotImported());
    target = SecondSourceTargetMapper.INSTANCE.sourceToTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getNotImported()).isSameAs(source.getNotImported());
    generatedSource.forMapper(SourceTargetMapper.class).containsNoImportFor(NotImportedDatatype.class);
    generatedSource.forMapper(SecondSourceTargetMapper.class).containsNoImportFor(NotImportedDatatype.class);
}
Also used : Target(org.mapstruct.ap.test.imports.referenced.Target) NotImportedDatatype(org.mapstruct.ap.test.imports.referenced.NotImportedDatatype) GeneratedSource(org.mapstruct.ap.testutil.runner.GeneratedSource) Source(org.mapstruct.ap.test.imports.referenced.Source) 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