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"));
}
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);
}
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");
}
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");
}
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);
}
Aggregations