Skip to content

Commit e015542

Browse files
committed
Use expression lambdas
1 parent c4fec82 commit e015542

File tree

4 files changed

+15
-29
lines changed

4 files changed

+15
-29
lines changed

platform-tests/src/test/java/org/junit/platform/commons/util/CollectionUtilsTests.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,14 @@ class CollectionUtilsTests {
4747

4848
@Test
4949
void getOnlyElementWithNullCollection() {
50-
PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, () -> {
51-
CollectionUtils.getOnlyElement(null);
52-
});
50+
var exception = assertThrows(PreconditionViolationException.class, () -> CollectionUtils.getOnlyElement(null));
5351
assertEquals("collection must not be null", exception.getMessage());
5452
}
5553

5654
@Test
5755
void getOnlyElementWithEmptyCollection() {
58-
PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, () -> {
59-
CollectionUtils.getOnlyElement(emptySet());
60-
});
56+
var exception = assertThrows(PreconditionViolationException.class,
57+
() -> CollectionUtils.getOnlyElement(emptySet()));
6158
assertEquals("collection must contain exactly one element: []", exception.getMessage());
6259
}
6360

@@ -70,9 +67,8 @@ void getOnlyElementWithSingleElementCollection() {
7067

7168
@Test
7269
void getOnlyElementWithMultiElementCollection() {
73-
PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, () -> {
74-
CollectionUtils.getOnlyElement(asList("foo", "bar"));
75-
});
70+
var exception = assertThrows(PreconditionViolationException.class,
71+
() -> CollectionUtils.getOnlyElement(asList("foo", "bar")));
7672
assertEquals("collection must contain exactly one element: [foo, bar]", exception.getMessage());
7773
}
7874

platform-tests/src/test/java/org/junit/platform/commons/util/FunctionUtilsTests.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,13 @@ class FunctionUtilsTests {
3030

3131
@Test
3232
void whereWithNullFunction() {
33-
PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, () -> {
34-
FunctionUtils.where(null, o -> true);
35-
});
33+
var exception = assertThrows(PreconditionViolationException.class, () -> FunctionUtils.where(null, o -> true));
3634
assertEquals("function must not be null", exception.getMessage());
3735
}
3836

3937
@Test
4038
void whereWithNullPredicate() {
41-
PreconditionViolationException exception = assertThrows(PreconditionViolationException.class, () -> {
42-
FunctionUtils.where(o -> o, null);
43-
});
39+
var exception = assertThrows(PreconditionViolationException.class, () -> FunctionUtils.where(o -> o, null));
4440
assertEquals("predicate must not be null", exception.getMessage());
4541
}
4642

platform-tests/src/test/java/org/junit/platform/commons/util/ToStringBuilderTests.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,12 @@ class ToStringBuilderTests {
2828

2929
@Test
3030
void withNullObject() {
31-
assertThrows(PreconditionViolationException.class, () -> {
32-
new ToStringBuilder((Object) null);
33-
});
31+
assertThrows(PreconditionViolationException.class, () -> new ToStringBuilder((Object) null));
3432
}
3533

3634
@Test
3735
void withNullClass() {
38-
assertThrows(PreconditionViolationException.class, () -> {
39-
new ToStringBuilder((Class<?>) null);
40-
});
36+
assertThrows(PreconditionViolationException.class, () -> new ToStringBuilder((Class<?>) null));
4137
}
4238

4339
@Test

platform-tests/src/test/java/org/junit/platform/launcher/listeners/discovery/AbstractLauncherDiscoveryListenerTests.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ protected TestEngineStub createEngineThatCannotResolveAnything(String engineId)
2424
return new TestEngineStub(engineId) {
2525
@Override
2626
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
27-
discoveryRequest.getSelectorsByType(DiscoverySelector.class).forEach(selector -> {
28-
discoveryRequest.getDiscoveryListener().selectorProcessed(uniqueId, selector,
29-
SelectorResolutionResult.unresolved());
30-
});
27+
discoveryRequest.getSelectorsByType(DiscoverySelector.class) //
28+
.forEach(selector -> discoveryRequest.getDiscoveryListener().selectorProcessed(uniqueId,
29+
selector, SelectorResolutionResult.unresolved()));
3130
return new EngineDescriptor(uniqueId, "Some Engine");
3231
}
3332
};
@@ -37,10 +36,9 @@ protected TestEngineStub createEngineThatFailsToResolveAnything(String engineId,
3736
return new TestEngineStub(engineId) {
3837
@Override
3938
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
40-
discoveryRequest.getSelectorsByType(DiscoverySelector.class).forEach(selector -> {
41-
discoveryRequest.getDiscoveryListener().selectorProcessed(uniqueId, selector,
42-
SelectorResolutionResult.failed(rootCause));
43-
});
39+
discoveryRequest.getSelectorsByType(DiscoverySelector.class) //
40+
.forEach(selector -> discoveryRequest.getDiscoveryListener().selectorProcessed(uniqueId,
41+
selector, SelectorResolutionResult.failed(rootCause)));
4442
return new EngineDescriptor(uniqueId, "Some Engine");
4543
}
4644
};

0 commit comments

Comments
 (0)