Skip to content

Commit 8a0be13

Browse files
committed
Improve message of discovery issues for ineffective @Order annotations (#4718)
Resolves #4713. (cherry picked from commit 9549b59)
1 parent 59d562e commit 8a0be13

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

documentation/src/docs/asciidoc/release-notes/release-notes-5.13.3.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ repository on GitHub.
5959
that both `null` and _blank_ values are supported for reason strings and that such
6060
values will result in an _empty_ `Optional` returned from
6161
`ConditionEvaluationResult.getReason()`.
62+
* Improve message of discovery issues reported for ineffective `@Order` annotations.
6263

6364

6465
[[release-notes-5.13.3-junit-vintage]]

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/discovery/ClassOrderingVisitor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.junit.platform.engine.DiscoveryIssue;
2929
import org.junit.platform.engine.DiscoveryIssue.Severity;
3030
import org.junit.platform.engine.TestDescriptor;
31-
import org.junit.platform.engine.support.descriptor.ClassSource;
3231
import org.junit.platform.engine.support.discovery.DiscoveryIssueReporter;
3332
import org.junit.platform.engine.support.discovery.DiscoveryIssueReporter.Condition;
3433

@@ -49,11 +48,12 @@ class ClassOrderingVisitor extends AbstractOrderingVisitor {
4948
this.globalOrderer = createGlobalOrderer(configuration);
5049
this.noOrderAnnotation = issueReporter.createReportingCondition(
5150
testDescriptor -> !isAnnotated(testDescriptor.getTestClass(), Order.class), testDescriptor -> {
52-
String message = String.format(
53-
"Ineffective @Order annotation on class '%s'. It will not be applied because ClassOrderer.OrderAnnotation is not in use.",
54-
testDescriptor.getTestClass().getName());
51+
String message = String.format("Ineffective @Order annotation on class '%s'. ",
52+
testDescriptor.getTestClass().getName())
53+
+ "It will not be applied because ClassOrderer.OrderAnnotation is not in use. "
54+
+ "Note that the annotation may be either directly present or meta-present on the class.";
5555
return DiscoveryIssue.builder(Severity.INFO, message) //
56-
.source(ClassSource.from(testDescriptor.getTestClass())) //
56+
.source(testDescriptor.getSource()) //
5757
.build();
5858
});
5959
}

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/discovery/MethodOrderingVisitor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.junit.platform.engine.DiscoveryIssue;
3232
import org.junit.platform.engine.DiscoveryIssue.Severity;
3333
import org.junit.platform.engine.TestDescriptor;
34-
import org.junit.platform.engine.support.descriptor.MethodSource;
3534
import org.junit.platform.engine.support.discovery.DiscoveryIssueReporter;
3635
import org.junit.platform.engine.support.discovery.DiscoveryIssueReporter.Condition;
3736

@@ -51,11 +50,12 @@ class MethodOrderingVisitor extends AbstractOrderingVisitor {
5150
this.configuration = configuration;
5251
this.noOrderAnnotation = issueReporter.createReportingCondition(
5352
testDescriptor -> !isAnnotated(testDescriptor.getTestMethod(), Order.class), testDescriptor -> {
54-
String message = String.format(
55-
"Ineffective @Order annotation on method '%s'. It will not be applied because MethodOrderer.OrderAnnotation is not in use.",
56-
testDescriptor.getTestMethod().toGenericString());
53+
String message = String.format("Ineffective @Order annotation on method '%s'. ",
54+
testDescriptor.getTestMethod().toGenericString())
55+
+ "It will not be applied because MethodOrderer.OrderAnnotation is not in use. "
56+
+ "Note that the annotation may be either directly present or meta-present on the method.";
5757
return DiscoveryIssue.builder(Severity.INFO, message) //
58-
.source(MethodSource.from(testDescriptor.getTestMethod())) //
58+
.source(testDescriptor.getSource()) //
5959
.build();
6060
});
6161
this.methodsBeforeNestedClassesOrderer = createMethodsBeforeNestedClassesOrderer();

jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/OrderedClassTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ private static void assertIneffectiveOrderAnnotationIssues(List<DiscoveryIssue>
204204
assertThat(discoveryIssues).extracting(DiscoveryIssue::severity).containsOnly(Severity.INFO);
205205
assertThat(discoveryIssues).extracting(DiscoveryIssue::message) //
206206
.allMatch(it -> it.startsWith("Ineffective @Order annotation on class")
207-
&& it.endsWith("It will not be applied because ClassOrderer.OrderAnnotation is not in use."));
207+
&& it.contains("It will not be applied because ClassOrderer.OrderAnnotation is not in use.")
208+
&& it.endsWith(
209+
"Note that the annotation may be either directly present or meta-present on the class."));
208210
assertThat(discoveryIssues).extracting(DiscoveryIssue::source).extracting(Optional::orElseThrow) //
209211
.containsExactlyInAnyOrder(ClassSource.from(A_TestCase.class), ClassSource.from(C_TestCase.class));
210212
}

jupiter-tests/src/test/java/org/junit/jupiter/engine/extension/OrderedMethodTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,9 @@ private static void assertIneffectiveOrderAnnotationIssues(List<DiscoveryIssue>
394394
assertThat(discoveryIssues).extracting(DiscoveryIssue::severity).containsOnly(Severity.INFO);
395395
assertThat(discoveryIssues).extracting(DiscoveryIssue::message) //
396396
.allMatch(it -> it.startsWith("Ineffective @Order annotation on method")
397-
&& it.endsWith("It will not be applied because MethodOrderer.OrderAnnotation is not in use."));
397+
&& it.contains("It will not be applied because MethodOrderer.OrderAnnotation is not in use.")
398+
&& it.endsWith(
399+
"Note that the annotation may be either directly present or meta-present on the method."));
398400
var testClass = WithoutTestMethodOrderTestCase.class;
399401
assertThat(discoveryIssues).extracting(DiscoveryIssue::source).extracting(Optional::orElseThrow) //
400402
.containsExactlyInAnyOrder(MethodSource.from(testClass.getDeclaredMethod("test1")),

0 commit comments

Comments
 (0)