Skip to content

Commit 0681c6f

Browse files
committed
Use records
1 parent 3d1b7aa commit 0681c6f

File tree

42 files changed

+121
-528
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+121
-528
lines changed

junit-jupiter-api/src/main/java/org/junit/jupiter/api/AssertIterableEquals.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -198,30 +198,7 @@ private static void failIterablesNotEqual(Object expected, Object actual, Deque<
198198
.buildAndThrow();
199199
}
200200

201-
private final static class Pair {
202-
private final Object left;
203-
private final Object right;
204-
205-
public Pair(Object left, Object right) {
206-
this.left = left;
207-
this.right = right;
208-
}
209-
210-
@Override
211-
public boolean equals(Object o) {
212-
if (this == o)
213-
return true;
214-
if (o == null || getClass() != o.getClass())
215-
return false;
216-
Pair that = (Pair) o;
217-
return Objects.equals(this.left, that.left) //
218-
&& Objects.equals(this.right, that.right);
219-
}
220-
221-
@Override
222-
public int hashCode() {
223-
return Objects.hash(left, right);
224-
}
201+
private record Pair(Object left, Object right) {
225202
}
226203

227204
private enum Status {

junit-jupiter-api/src/main/java/org/junit/jupiter/api/AssertLinesMatch.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,8 @@ static void assertLinesMatch(List<String> expectedLines, List<String> actualLine
8383
new LinesMatcher(expectedLines, actualLines, messageOrSupplier).assertLinesMatch();
8484
}
8585

86-
private static class LinesMatcher {
87-
88-
private final List<String> expectedLines;
89-
private final List<String> actualLines;
90-
91-
@Nullable
92-
private final Object messageOrSupplier;
93-
94-
LinesMatcher(List<String> expectedLines, List<String> actualLines, @Nullable Object messageOrSupplier) {
95-
this.expectedLines = expectedLines;
96-
this.actualLines = actualLines;
97-
this.messageOrSupplier = messageOrSupplier;
98-
}
86+
private record LinesMatcher(List<String> expectedLines, List<String> actualLines,
87+
@Nullable Object messageOrSupplier) {
9988

10089
void assertLinesMatch() {
10190
int expectedSize = expectedLines.size();

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/DefaultDynamicTestInvocationContext.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@
1818
*
1919
* @since 5.8
2020
*/
21-
class DefaultDynamicTestInvocationContext implements DynamicTestInvocationContext {
22-
23-
private final Executable executable;
24-
25-
DefaultDynamicTestInvocationContext(Executable executable) {
26-
this.executable = executable;
27-
}
21+
record DefaultDynamicTestInvocationContext(Executable executable) implements DynamicTestInvocationContext {
2822

2923
@Override
3024
public Executable getExecutable() {

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/DefaultTestInstanceFactoryContext.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,8 @@
2020
*
2121
* @since 5.3
2222
*/
23-
class DefaultTestInstanceFactoryContext implements TestInstanceFactoryContext {
24-
25-
private final Class<?> testClass;
26-
private final Optional<Object> outerInstance;
27-
28-
DefaultTestInstanceFactoryContext(Class<?> testClass, Optional<Object> outerInstance) {
29-
this.testClass = testClass;
30-
this.outerInstance = outerInstance;
31-
}
23+
record DefaultTestInstanceFactoryContext(Class<?> testClass, Optional<Object> outerInstance)
24+
implements TestInstanceFactoryContext {
3225

3326
@Override
3427
public Class<?> getTestClass() {

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/execution/DefaultParameterContext.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,12 @@
2323
/**
2424
* @since 5.0
2525
*/
26-
class DefaultParameterContext implements ParameterContext {
26+
record DefaultParameterContext(Parameter parameter, int index, Optional<Object> target) implements ParameterContext {
2727

28-
private final Parameter parameter;
29-
private final int index;
30-
private final Optional<Object> target;
31-
32-
DefaultParameterContext(Parameter parameter, int index, Optional<Object> target) {
28+
DefaultParameterContext {
3329
Preconditions.condition(index >= 0, "index must be greater than or equal to zero");
34-
this.parameter = Preconditions.notNull(parameter, "parameter must not be null");
35-
this.index = index;
36-
this.target = Preconditions.notNull(target, "target must not be null");
30+
Preconditions.notNull(parameter, "parameter must not be null");
31+
Preconditions.notNull(target, "target must not be null");
3732
}
3833

3934
@Override

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/execution/InvocationInterceptorChain.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,8 @@ public interface VoidInterceptorCall {
9191

9292
}
9393

94-
private static class InterceptedInvocation<T> implements Invocation<T> {
95-
96-
private final Invocation<T> invocation;
97-
private final InterceptorCall<T> call;
98-
private final InvocationInterceptor interceptor;
99-
100-
InterceptedInvocation(Invocation<T> invocation, InterceptorCall<T> call, InvocationInterceptor interceptor) {
101-
this.invocation = invocation;
102-
this.call = call;
103-
this.interceptor = interceptor;
104-
}
94+
private record InterceptedInvocation<T>(Invocation<T> invocation, InterceptorCall<T> call,
95+
InvocationInterceptor interceptor) implements Invocation<T> {
10596

10697
@Override
10798
public T proceed() throws Throwable {

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/DefaultPreInterruptContext.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
/**
1818
* @since 5.12
1919
*/
20-
class DefaultPreInterruptContext implements PreInterruptContext {
21-
private final Thread threadToInterrupt;
20+
record DefaultPreInterruptContext(Thread threadToInterrupt) implements PreInterruptContext {
2221

23-
DefaultPreInterruptContext(Thread threadToInterrupt) {
22+
DefaultPreInterruptContext {
2423
Preconditions.notNull(threadToInterrupt, "threadToInterrupt must not be null");
25-
this.threadToInterrupt = threadToInterrupt;
2624
}
2725

2826
@Override

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/DefaultRepetitionInfo.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,8 @@
1818
/**
1919
* Default implementation of {@link RepetitionInfo}.
2020
*/
21-
class DefaultRepetitionInfo implements RepetitionInfo {
22-
23-
final int currentRepetition;
24-
final int totalRepetitions;
25-
final AtomicInteger failureCount;
26-
final int failureThreshold;
27-
28-
DefaultRepetitionInfo(int currentRepetition, int totalRepetitions, AtomicInteger failureCount,
29-
int failureThreshold) {
30-
this.currentRepetition = currentRepetition;
31-
this.totalRepetitions = totalRepetitions;
32-
this.failureCount = failureCount;
33-
this.failureThreshold = failureThreshold;
34-
}
21+
record DefaultRepetitionInfo(int currentRepetition, int totalRepetitions, AtomicInteger failureCount,
22+
int failureThreshold) implements RepetitionInfo {
3523

3624
@Override
3725
public int getCurrentRepetition() {

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/RepeatedTestInvocationContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public RepeatedTestInvocationContext(DefaultRepetitionInfo repetitionInfo,
3636

3737
@Override
3838
public String getDisplayName(int invocationIndex) {
39-
return this.formatter.format(this.repetitionInfo.currentRepetition, this.repetitionInfo.totalRepetitions);
39+
return this.formatter.format(this.repetitionInfo.currentRepetition(), this.repetitionInfo.totalRepetitions());
4040
}
4141

4242
@Override

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/RepetitionExtension.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ public RepetitionInfo resolveParameter(ParameterContext parameterContext, Extens
6363

6464
@Override
6565
public void testFailed(ExtensionContext context, @Nullable Throwable cause) {
66-
this.repetitionInfo.failureCount.incrementAndGet();
66+
this.repetitionInfo.failureCount().incrementAndGet();
6767
}
6868

6969
@Override
7070
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
71-
int failureThreshold = this.repetitionInfo.failureThreshold;
72-
if (this.repetitionInfo.failureCount.get() >= failureThreshold) {
71+
int failureThreshold = this.repetitionInfo.getFailureThreshold();
72+
if (this.repetitionInfo.getFailureCount() >= failureThreshold) {
7373
return disabled("Failure threshold [" + failureThreshold + "] exceeded");
7474
}
7575
return enabled("Failure threshold not exceeded");

0 commit comments

Comments
 (0)