diff --git a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java index 63bb6f92e..30920b9ae 100644 --- a/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java +++ b/processor/src/test/java/org/mapstruct/ap/test/nullvaluepropertymapping/NullValuePropertyMappingTest.java @@ -8,7 +8,6 @@ package org.mapstruct.ap.test.nullvaluepropertymapping; import java.util.Arrays; import java.util.function.BiConsumer; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mapstruct.ap.testutil.IssueKey; @@ -104,7 +103,6 @@ public class NullValuePropertyMappingTest { } @Test - @Ignore // test gives different results for JDK and JDT @WithClasses(ErroneousCustomerMapper1.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -112,6 +110,7 @@ public class NullValuePropertyMappingTest { @Diagnostic(type = ErroneousCustomerMapper1.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, + alternativeLine = 22, // Javac wrong error reporting on repeatable annotations JDK-8042710 messageRegExp = "Default value and nullValuePropertyMappingStrategy are both defined in @Mapping, " + "either define a defaultValue or an nullValuePropertyMappingStrategy.") } @@ -120,7 +119,6 @@ public class NullValuePropertyMappingTest { } @Test - @Ignore // test gives different results for JDK and JDT @WithClasses(ErroneousCustomerMapper2.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -128,6 +126,7 @@ public class NullValuePropertyMappingTest { @Diagnostic(type = ErroneousCustomerMapper2.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, + alternativeLine = 22, // Javac wrong error reporting on repeatable annotations JDK-8042710 messageRegExp = "Expression and nullValuePropertyMappingStrategy are both defined in @Mapping, " + "either define an expression or an nullValuePropertyMappingStrategy.") } @@ -136,7 +135,6 @@ public class NullValuePropertyMappingTest { } @Test - @Ignore // test gives different results for JDK and JDT @WithClasses(ErroneousCustomerMapper3.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -144,6 +142,7 @@ public class NullValuePropertyMappingTest { @Diagnostic(type = ErroneousCustomerMapper3.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, + alternativeLine = 22, // Javac wrong error reporting on repeatable annotations JDK-8042710 messageRegExp = "DefaultExpression and nullValuePropertyMappingStrategy are both defined in " + "@Mapping, either define a defaultExpression or an nullValuePropertyMappingStrategy.") } @@ -152,7 +151,6 @@ public class NullValuePropertyMappingTest { } @Test - @Ignore // test gives different results for JDK and JDT @WithClasses(ErroneousCustomerMapper4.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -160,6 +158,7 @@ public class NullValuePropertyMappingTest { @Diagnostic(type = ErroneousCustomerMapper4.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, + alternativeLine = 22, // Javac wrong error reporting on repeatable annotations JDK-8042710 messageRegExp = "Constant and nullValuePropertyMappingStrategy are both defined in @Mapping, " + "either define a constant or an nullValuePropertyMappingStrategy.") } @@ -168,7 +167,6 @@ public class NullValuePropertyMappingTest { } @Test - @Ignore // test gives different results for JDK and JDT @WithClasses(ErroneousCustomerMapper5.class) @ExpectedCompilationOutcome( value = CompilationResult.FAILED, @@ -176,6 +174,7 @@ public class NullValuePropertyMappingTest { @Diagnostic(type = ErroneousCustomerMapper5.class, kind = javax.tools.Diagnostic.Kind.ERROR, line = 20, + alternativeLine = 22, // Javac wrong error reporting on repeatable annotations JDK-8042710 messageRegExp = "Ignore and nullValuePropertyMappingStrategy are both defined in @Mapping, " + "either define ignore or an nullValuePropertyMappingStrategy.") } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/Diagnostic.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/Diagnostic.java index c12930251..b2016f1c2 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/Diagnostic.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/annotation/Diagnostic.java @@ -35,6 +35,16 @@ public @interface Diagnostic { */ long line() default -1; + /** + * In case compilers report diagnostics on different lines this can be used as the alternative expected line number + * of the diagnostic. + *
+ * This should be used as a last resort when the compilers report the diagnostic on a wrong line. + * + * @return The alternative line number of the diagnostic. + */ + long alternativeLine() default -1; + /** * A regular expression matching the expected message of the diagnostic. * Wild-cards matching any character (".*") will be added to the beginning diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java index b406ae7ea..f02361064 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/compilation/model/DiagnosticDescriptor.java @@ -26,12 +26,18 @@ public class DiagnosticDescriptor { private final String sourceFileName; private final Kind kind; private final Long line; + private final Long alternativeLine; private final String message; private DiagnosticDescriptor(String sourceFileName, Kind kind, Long line, String message) { + this( sourceFileName, kind, line, null, message ); + } + + private DiagnosticDescriptor(String sourceFileName, Kind kind, Long line, Long alternativeLine, String message) { this.sourceFileName = sourceFileName; this.kind = kind; this.line = line; + this.alternativeLine = alternativeLine; this.message = message; } @@ -43,6 +49,7 @@ public class DiagnosticDescriptor { soureFileName, diagnostic.kind(), diagnostic.line() != -1 ? diagnostic.line() : null, + diagnostic.alternativeLine() != -1 ? diagnostic.alternativeLine() : null, diagnostic.messageRegExp() ); } @@ -135,6 +142,10 @@ public class DiagnosticDescriptor { return line; } + public Long getAlternativeLine() { + return alternativeLine; + } + public String getMessage() { return message; } diff --git a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java index 215ab1c70..73693e4cb 100644 --- a/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java +++ b/processor/src/test/java/org/mapstruct/ap/testutil/runner/CompilingStatement.java @@ -269,7 +269,10 @@ abstract class CompilingStatement extends Statement { if ( expected.getSourceFileName() != null ) { assertThat( actual.getSourceFileName() ).isEqualTo( expected.getSourceFileName() ); } - if ( expected.getLine() != null ) { + if ( expected.getLine() != null && expected.getAlternativeLine() != null ) { + assertThat( actual.getLine() ).isIn( expected.getLine(), expected.getAlternativeLine() ); + } + else if ( expected.getLine() != null ) { assertThat( actual.getLine() ).isEqualTo( expected.getLine() ); } assertThat( actual.getKind() ).isEqualTo( expected.getKind() );