-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnnamedVariablesTest.java
More file actions
40 lines (29 loc) · 926 Bytes
/
UnnamedVariablesTest.java
File metadata and controls
40 lines (29 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package jep456;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;
import org.junit.jupiter.api.Test;
public class UnnamedVariablesTest {
@Test
void unnamedVariable() {
AtomicInteger counter = new AtomicInteger(0);
IntStream.range(1, 15)
.forEach(_ -> counter.addAndGet(1));
assertThat(counter.get()).isEqualTo(14);
}
@Test
void unnamedPatternVariable() {
Shape shape = null;
String status = switch (shape) {
// multiple patterns in case label are now possible
case Rectangle _, Square _ -> "right angles";
case Circle _ -> "round";
case null -> "N/A";
};
assertThat(status).isEqualTo("N/A");
}
sealed interface Shape {}
final class Rectangle implements Shape {}
final class Square implements Shape {}
final class Circle implements Shape {}
}