Search in sources :

Example 1 with ExpectedCompilationOutcome

use of org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome in project mapstruct by mapstruct.

the class UnmappedSourceTest method shouldLeaveUnmappedSourcePropertyUnset.

@ProcessorTest
@WithClasses({ Source.class, Target.class, SourceTargetMapper.class })
@ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, diagnostics = { @Diagnostic(type = SourceTargetMapper.class, kind = Kind.WARNING, line = 20, message = "Unmapped source property: \"qux\"."), @Diagnostic(type = SourceTargetMapper.class, kind = Kind.WARNING, line = 22, message = "Unmapped source property: \"bar\".") })
public void shouldLeaveUnmappedSourcePropertyUnset() {
    Source source = new Source();
    source.setFoo(42L);
    Target target = SourceTargetMapper.INSTANCE.sourceToTarget(source);
    assertThat(target).isNotNull();
    assertThat(target.getFoo()).isEqualTo(42L);
    assertThat(target.getBar()).isEqualTo(0);
}
Also used : Target(org.mapstruct.ap.test.unmappedtarget.Target) Source(org.mapstruct.ap.test.unmappedtarget.Source) ExpectedCompilationOutcome(org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Example 2 with ExpectedCompilationOutcome

use of org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome in project mapstruct by mapstruct.

the class MultipleBuilderMapperTest method tooManyBuilderCreationMethods.

@WithClasses({ TooManyBuilderCreationMethodsMapper.class })
@ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, diagnostics = { @Diagnostic(type = Case.class, kind = javax.tools.Diagnostic.Kind.WARNING, line = 11, message = "More than one builder creation method for \"org.mapstruct.ap.test.builder.multiple.builder" + ".Case\". Found methods: \"wrongBuilder(), builder()\". Builder will not be used. Consider " + "implementing a custom BuilderProvider SPI.") })
@ProcessorTest
public void tooManyBuilderCreationMethods() {
    Case caseTarget = TooManyBuilderCreationMethodsMapper.INSTANCE.map(new Source("test"));
    assertThat(caseTarget).isNotNull();
    assertThat(caseTarget.getName()).isEqualTo("test");
    assertThat(caseTarget.getBuilderCreationMethod()).isNull();
    assertThat(caseTarget.getBuildMethod()).isEqualTo("constructor");
}
Also used : Case(org.mapstruct.ap.test.builder.multiple.builder.Case) ExpectedCompilationOutcome(org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome) ProcessorTest(org.mapstruct.ap.testutil.ProcessorTest) WithClasses(org.mapstruct.ap.testutil.WithClasses)

Aggregations

ProcessorTest (org.mapstruct.ap.testutil.ProcessorTest)2 WithClasses (org.mapstruct.ap.testutil.WithClasses)2 ExpectedCompilationOutcome (org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome)2 Case (org.mapstruct.ap.test.builder.multiple.builder.Case)1 Source (org.mapstruct.ap.test.unmappedtarget.Source)1 Target (org.mapstruct.ap.test.unmappedtarget.Target)1