Skip to content

Commit 483fcc9

Browse files
committed
Remove annotationName fields from AbstractJre[Range]Condition
This commit removes the annotationName fields from AbstractJreCondition and AbstractJreRangeCondition and replaces them with local variables. See #4619
1 parent 7d02a6a commit 483fcc9

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/AbstractJreCondition.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,20 @@ abstract class AbstractJreCondition<A extends Annotation> extends BooleanExecuti
3333
static final String DISABLED_ON_CURRENT_JRE = //
3434
"Disabled on JRE version: " + System.getProperty("java.version");
3535

36-
private final String annotationName;
37-
3836
AbstractJreCondition(Class<A> annotationType, Function<A, String> customDisabledReason) {
3937
super(annotationType, ENABLED_ON_CURRENT_JRE, DISABLED_ON_CURRENT_JRE, customDisabledReason);
40-
this.annotationName = annotationType.getSimpleName();
4138
}
4239

4340
protected final IntStream validatedVersions(JRE[] jres, int[] versions) {
41+
String annotationName = super.annotationType.getSimpleName();
42+
4443
Preconditions.condition(jres.length > 0 || versions.length > 0,
45-
() -> "You must declare at least one JRE or version in @" + this.annotationName);
44+
() -> "You must declare at least one JRE or version in @" + annotationName);
4645

4746
Preconditions.condition(Arrays.stream(jres).noneMatch(isEqual(JRE.UNDEFINED)),
48-
() -> "JRE.UNDEFINED is not supported in @" + this.annotationName);
47+
() -> "JRE.UNDEFINED is not supported in @" + annotationName);
4948
Arrays.stream(versions).min().ifPresent(version -> Preconditions.condition(version >= JRE.MINIMUM_VERSION,
50-
() -> "Version [%d] in @%s must be greater than or equal to %d".formatted(version, this.annotationName,
49+
() -> "Version [%d] in @%s must be greater than or equal to %d".formatted(version, annotationName,
5150
JRE.MINIMUM_VERSION)));
5251

5352
return IntStream.concat(//

junit-jupiter-api/src/main/java/org/junit/jupiter/api/condition/AbstractJreRangeCondition.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ abstract class AbstractJreRangeCondition<A extends Annotation> extends BooleanEx
2929
private static final JRE DEFAULT_MINIMUM_JRE = JRE.JAVA_17;
3030
private static final JRE DEFAULT_MAXIMUM_JRE = JRE.OTHER;
3131

32-
private final String annotationName;
33-
3432
AbstractJreRangeCondition(Class<A> annotationType, Function<A, String> customDisabledReason) {
3533
super(annotationType, ENABLED_ON_CURRENT_JRE, DISABLED_ON_CURRENT_JRE, customDisabledReason);
36-
this.annotationName = annotationType.getSimpleName();
3734
}
3835

3936
protected final boolean isCurrentVersionWithinRange(JRE minJre, JRE maxJre, int minVersion, int maxVersion) {
37+
String annotationName = super.annotationType.getSimpleName();
38+
4039
boolean minJreSet = minJre != JRE.UNDEFINED;
4140
boolean maxJreSet = maxJre != JRE.UNDEFINED;
4241
boolean minVersionSet = minVersion != JRE.UNDEFINED_VERSION;
@@ -45,17 +44,17 @@ protected final boolean isCurrentVersionWithinRange(JRE minJre, JRE maxJre, int
4544
// Users must choose between JRE enum constants and version numbers.
4645
Preconditions.condition(!minJreSet || !minVersionSet,
4746
() -> "@%s's minimum value must be configured with either a JRE enum constant or numeric version, but not both".formatted(
48-
this.annotationName));
47+
annotationName));
4948
Preconditions.condition(!maxJreSet || !maxVersionSet,
5049
() -> "@%s's maximum value must be configured with either a JRE enum constant or numeric version, but not both".formatted(
51-
this.annotationName));
50+
annotationName));
5251

5352
// Users must supply valid values for minVersion and maxVersion.
5453
Preconditions.condition(!minVersionSet || (minVersion >= JRE.MINIMUM_VERSION),
55-
() -> "@%s's minVersion [%d] must be greater than or equal to %d".formatted(this.annotationName, minVersion,
54+
() -> "@%s's minVersion [%d] must be greater than or equal to %d".formatted(annotationName, minVersion,
5655
JRE.MINIMUM_VERSION));
5756
Preconditions.condition(!maxVersionSet || (maxVersion >= JRE.MINIMUM_VERSION),
58-
() -> "@%s's maxVersion [%d] must be greater than or equal to %d".formatted(this.annotationName, maxVersion,
57+
() -> "@%s's maxVersion [%d] must be greater than or equal to %d".formatted(annotationName, maxVersion,
5958
JRE.MINIMUM_VERSION));
6059

6160
// Now that we have checked the basic preconditions, we need to ensure that we are
@@ -72,10 +71,10 @@ protected final boolean isCurrentVersionWithinRange(JRE minJre, JRE maxJre, int
7271

7372
// Finally, we need to validate the effective minimum and maximum values.
7473
Preconditions.condition((min != DEFAULT_MINIMUM_JRE.version() || max != DEFAULT_MAXIMUM_JRE.version()),
75-
() -> "You must declare a non-default value for the minimum or maximum value in @" + this.annotationName);
74+
() -> "You must declare a non-default value for the minimum or maximum value in @" + annotationName);
7675
Preconditions.condition(min <= max,
7776
() -> "@%s's minimum value [%d] must be less than or equal to its maximum value [%d]".formatted(
78-
this.annotationName, min, max));
77+
annotationName, min, max));
7978

8079
return JRE.isCurrentVersionWithinRange(min, max);
8180
}

0 commit comments

Comments
 (0)