mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#34 Asserting line and source type of diagnostics only when specified via @Diagnostic
This commit is contained in:
parent
cd14bd368f
commit
785ccece90
@ -168,8 +168,12 @@ public abstract class MapperTestBase {
|
|||||||
DiagnosticDescriptor actual = actualIterator.next();
|
DiagnosticDescriptor actual = actualIterator.next();
|
||||||
DiagnosticDescriptor expected = expectedIterator.next();
|
DiagnosticDescriptor expected = expectedIterator.next();
|
||||||
|
|
||||||
assertThat( actual.getSourceFileName() ).isEqualTo( expected.getSourceFileName() );
|
if ( expected.getSourceFileName() != null ) {
|
||||||
assertThat( actual.getLine() ).isEqualTo( expected.getLine() );
|
assertThat( actual.getSourceFileName() ).isEqualTo( expected.getSourceFileName() );
|
||||||
|
}
|
||||||
|
if ( expected.getLine() != null ) {
|
||||||
|
assertThat( actual.getLine() ).isEqualTo( expected.getLine() );
|
||||||
|
}
|
||||||
assertThat( actual.getKind() ).isEqualTo( expected.getKind() );
|
assertThat( actual.getKind() ).isEqualTo( expected.getKind() );
|
||||||
assertThat( actual.getMessage() ).describedAs(
|
assertThat( actual.getMessage() ).describedAs(
|
||||||
String.format(
|
String.format(
|
||||||
|
@ -32,7 +32,7 @@ public @interface Diagnostic {
|
|||||||
*
|
*
|
||||||
* @return The type for which the diagnostic was created.
|
* @return The type for which the diagnostic was created.
|
||||||
*/
|
*/
|
||||||
Class<?> type() default Diagnostic.class;
|
Class<?> type() default void.class;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The expected kind of diagnostic.
|
* The expected kind of diagnostic.
|
||||||
@ -46,7 +46,7 @@ public @interface Diagnostic {
|
|||||||
*
|
*
|
||||||
* @return The expected line number of the diagnostic.
|
* @return The expected line number of the diagnostic.
|
||||||
*/
|
*/
|
||||||
int line() default -1;
|
long line() default -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A regular expression matching the expected message of the diagnostic.
|
* A regular expression matching the expected message of the diagnostic.
|
||||||
|
@ -37,10 +37,10 @@ public class DiagnosticDescriptor {
|
|||||||
|
|
||||||
private final String sourceFileName;
|
private final String sourceFileName;
|
||||||
private final Kind kind;
|
private final Kind kind;
|
||||||
private final long line;
|
private final Long line;
|
||||||
private final String message;
|
private final String message;
|
||||||
|
|
||||||
private DiagnosticDescriptor(String sourceFileName, Kind kind, long line, String message) {
|
private DiagnosticDescriptor(String sourceFileName, Kind kind, Long line, String message) {
|
||||||
this.sourceFileName = sourceFileName;
|
this.sourceFileName = sourceFileName;
|
||||||
this.kind = kind;
|
this.kind = kind;
|
||||||
this.line = line;
|
this.line = line;
|
||||||
@ -48,13 +48,13 @@ public class DiagnosticDescriptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static DiagnosticDescriptor forDiagnostic(Diagnostic diagnostic) {
|
public static DiagnosticDescriptor forDiagnostic(Diagnostic diagnostic) {
|
||||||
String soureFileName = diagnostic.type() != Diagnostic.class
|
String soureFileName = diagnostic.type() != void.class
|
||||||
? diagnostic.type().getName().replace( ".", File.separator ) + ".java"
|
? diagnostic.type().getName().replace( ".", File.separator ) + ".java"
|
||||||
: null;
|
: null;
|
||||||
return new DiagnosticDescriptor(
|
return new DiagnosticDescriptor(
|
||||||
soureFileName,
|
soureFileName,
|
||||||
diagnostic.kind(),
|
diagnostic.kind(),
|
||||||
diagnostic.line(),
|
diagnostic.line() != -1 ? diagnostic.line() : null,
|
||||||
diagnostic.messageRegExp()
|
diagnostic.messageRegExp()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ public class DiagnosticDescriptor {
|
|||||||
return kind;
|
return kind;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLine() {
|
public Long getLine() {
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user