-
Notifications
You must be signed in to change notification settings - Fork 24
/
LegacyTest.java
40 lines (31 loc) · 955 Bytes
/
LegacyTest.java
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 org.codefx.demo.junit4;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.lang.StackWalker.StackFrame;
import java.util.List;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
public class LegacyTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void testWithJUnit4_failsIfNotRunWithJUnit5Platform() {
Optional<String> vintageFrame = StackWalker
.getInstance()
.walk(frames -> frames
.peek(System.out::println)
.map(StackFrame::getClassName)
.filter(method -> method.contains("vintage"))
.findAny());
assertThat(vintageFrame).isNotEmpty();
}
@Test
public void useExpectedExceptionRule() {
List<Object> list = List.of();
thrown.expect(IndexOutOfBoundsException.class);
thrown.expectMessage("Index 0 out of bounds for length 0");
// this call fails
list.get(0);
}
}