use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.
the class JavaDefaultExpressionTest method testJavaDefaultExpressionWithNoValues.
@ProcessorTest
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class })
public void testJavaDefaultExpressionWithNoValues() {
Source source = new Source();
Target target = SourceTargetMapper.INSTANCE.sourceToTarget(source);
assertThat(target).isNotNull();
assertThat(target.getSourceId()).isEqualTo("test");
assertThat(target.getSourceDate()).isEqualTo(new Date(30L));
}
use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.
the class JavaExpressionTest method testJavaExpressionInsertionWithExistingTarget.
@ProcessorTest
@WithClasses({ Source.class, Target.class, TimeAndFormat.class, SourceTargetMapper.class })
public void testJavaExpressionInsertionWithExistingTarget() throws ParseException {
Source source = new Source();
String format = "dd-MM-yyyy,hh:mm:ss";
Date time = getTime(format, "09-01-2014,01:35:03");
source.setFormat(format);
source.setTime(time);
Target target = new Target();
Target target2 = SourceTargetMapper.INSTANCE.sourceToTargetWithMappingTarget(source, target);
assertThat(target).isNotNull();
assertThat(target.getTimeAndFormat().getTime()).isEqualTo(time);
assertThat(target.getTimeAndFormat().getFormat()).isEqualTo(format);
assertThat(target.getAnotherProp()).isNull();
assertThat(target).isEqualTo(target2);
}
use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.
the class SeveralReferencedMappersWithSameSimpleNameTest method severalMappersWithSameSimpleNameCanBeReferenced.
@ProcessorTest
public void severalMappersWithSameSimpleNameCanBeReferenced() {
Source source = new Source();
source.setFoo(123);
source.setBar(456L);
Target target = SourceTargetMapper.INSTANCE.sourceToTarget(source);
assertThat(target).isNotNull();
assertThat(target.getFoo()).isEqualTo("246");
assertThat(target.getBar()).isEqualTo("912");
}
use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.
the class SeveralReferencedMappersWithSameSimpleNameTest method mapperInSamePackageAndAnotherMapperWithSameNameInAnotherPackageCanBeReferenced.
@ProcessorTest
public void mapperInSamePackageAndAnotherMapperWithSameNameInAnotherPackageCanBeReferenced() {
Source source = new Source();
source.setFoo(123);
source.setBar(456L);
Target target = AnotherSourceTargetMapper.INSTANCE.sourceToTarget(source);
assertThat(target).isNotNull();
assertThat(target.getFoo()).isEqualTo("246");
assertThat(target.getBar()).isEqualTo("912");
}
use of org.mapstruct.ap.testutil.ProcessorTest in project mapstruct by mapstruct.
the class NullValueMappingTest method shouldMapExpressionAndConstantRegardlessNullArg.
@ProcessorTest
public void shouldMapExpressionAndConstantRegardlessNullArg() {
// given
Car car = new Car("Morris", 2);
// when
CarDto carDto1 = CarMapper.INSTANCE.carToCarDto(car);
// then
assertThat(carDto1).isNotNull();
assertThat(carDto1.getMake()).isEqualTo(car.getMake());
assertThat(carDto1.getSeatCount()).isEqualTo(car.getNumberOfSeats());
assertThat(carDto1.getModel()).isEqualTo("ModelT");
assertThat(carDto1.getCatalogId()).isNotEmpty();
// when
CarDto carDto2 = CarMapper.INSTANCE.carToCarDto(null);
// then
assertThat(carDto2).isNotNull();
assertThat(carDto2.getMake()).isNull();
assertThat(carDto2.getSeatCount()).isEqualTo(0);
assertThat(carDto2.getModel()).isEqualTo("ModelT");
assertThat(carDto2.getCatalogId()).isNotEmpty();
}
Aggregations