Search in sources :

Example 11 with ProcessorTest

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

the class NumberFormatConversionTest method shouldApplyReverseStringConversions.

@ProcessorTest
public void shouldApplyReverseStringConversions() {
    Target target = new Target();
    target.setI("1.00");
    target.setIi("2.00");
    target.setD("3.00");
    target.setDd("4.00");
    target.setF("3.00");
    target.setFf("4.00");
    target.setL("5.00");
    target.setLl("6.00");
    target.setB("7.00");
    target.setBb("8.00");
    target.setComplex1("345.35E3");
    target.setComplex2("$5007034.30");
    target.setBigDecimal1("9.87E-18");
    target.setBigInteger1("1.23456789E12");
    Source source = SourceTargetMapper.INSTANCE.targetToSource(target);
    assertThat(source).isNotNull();
    assertThat(source.getI()).isEqualTo(1);
    assertThat(source.getIi()).isEqualTo(Integer.valueOf(2));
    assertThat(source.getD()).isEqualTo(3.0);
    assertThat(source.getDd()).isEqualTo(Double.valueOf(4.0));
    assertThat(source.getF()).isEqualTo(3.0f);
    assertThat(source.getFf()).isEqualTo(Float.valueOf(4.0f));
    assertThat(source.getL()).isEqualTo(5L);
    assertThat(source.getLl()).isEqualTo(Long.valueOf(6L));
    assertThat(source.getB()).isEqualTo((byte) 7);
    assertThat(source.getBb()).isEqualTo((byte) 8);
    assertThat(source.getComplex1()).isEqualTo(345350.0);
    assertThat(source.getComplex2()).isEqualTo(5007034.3);
    assertThat(source.getBigDecimal1()).isEqualTo(new BigDecimal("987E-20"));
    assertThat(source.getBigInteger1()).isEqualTo(new BigInteger("1234567890000"));
}
Also used : BigInteger(java.math.BigInteger) BigDecimal(java.math.BigDecimal) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 12 with ProcessorTest

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

the class StringConversionTest method stringShouldBeMappedToObjectByReference.

@ProcessorTest
@IssueKey("328")
public void stringShouldBeMappedToObjectByReference() {
    Target target = new Target();
    target.setObject(STRING_CONSTANT);
    Source source = SourceTargetMapper.INSTANCE.targetToSource(target);
    // no conversion, no built-in method
    assertThat(source.getObject()).isSameAs(STRING_CONSTANT);
}
Also used : GeneratedSource(org.mapstruct.ap.testutil.runner.GeneratedSource) IssueKey(org.mapstruct.ap.testutil.IssueKey) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 13 with ProcessorTest

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

the class SpringDecoratorTest method shouldDelegateNonDecoratedMethodsToDefaultImplementation.

@ProcessorTest
public void shouldDelegateNonDecoratedMethodsToDefaultImplementation() {
    // given
    Address address = new Address("42 Ocean View Drive");
    // when
    AddressDto addressDto = personMapper.addressToAddressDto(address);
    // then
    assertThat(addressDto).isNotNull();
    assertThat(addressDto.getAddressLine()).isEqualTo("42 Ocean View Drive");
}
Also used : Address(org.mapstruct.ap.test.decorator.Address) AddressDto(org.mapstruct.ap.test.decorator.AddressDto) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 14 with ProcessorTest

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

the class SpringDecoratorTest method shouldInvokeDecoratorMethods.

@ProcessorTest
public void shouldInvokeDecoratorMethods() {
    // given
    Calendar birthday = Calendar.getInstance();
    birthday.set(1928, Calendar.MAY, 23);
    Person person = new Person("Gary", "Crant", birthday.getTime(), new Address("42 Ocean View Drive"));
    // when
    PersonDto personDto = personMapper.personToPersonDto(person);
    // then
    assertThat(personDto).isNotNull();
    assertThat(personDto.getName()).isEqualTo("Gary Crant");
    assertThat(personDto.getAddress()).isNotNull();
    assertThat(personDto.getAddress().getAddressLine()).isEqualTo("42 Ocean View Drive");
}
Also used : Address(org.mapstruct.ap.test.decorator.Address) PersonDto(org.mapstruct.ap.test.decorator.PersonDto) Calendar(java.util.Calendar) Person(org.mapstruct.ap.test.decorator.Person) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

Example 15 with ProcessorTest

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

the class ProcessorTestExtension method provideTestTemplateInvocationContexts.

@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
    Method testMethod = context.getRequiredTestMethod();
    ProcessorTest processorTest = AnnotationSupport.findAnnotation(testMethod, ProcessorTest.class).orElseThrow(() -> new RuntimeException("Failed to get CompilerTest on " + testMethod));
    return Stream.of(processorTest.value()).map(ProcessorTestInvocationContext::new);
}
Also used : Method(java.lang.reflect.Method) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest)

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