-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionExampleTest.java
More file actions
49 lines (43 loc) · 1.45 KB
/
ExceptionExampleTest.java
File metadata and controls
49 lines (43 loc) · 1.45 KB
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
41
42
43
44
45
46
47
48
49
package example;
import app.zoftwhere.bolt.Runner;
import org.junit.jupiter.api.Test;
/**
* This class is the test class for {@link example.ExceptionExample}.
*
* @author Osmund
* @version 11.2.0
* @since 1.0.0
*/
class ExceptionExampleTest {
// An immutable runner that can be reused.
private final Runner runner = new Runner();
@Test
@SuppressWarnings("SimplifyOptionalCallChains")
void testCase() {
// Run with programs that should throw exceptions.
runner
.runConsole((inputStream, outputStream) -> ExceptionExample.programWithError())
.input()
.expected()
.assertError();
// Run with a custom assertion check.
runner
.runConsole((inputStream, outputStream) -> ExceptionExample.programWithError())
.input()
.expected()
.assertCheck(
(result) -> {
if (result.isSuccess()) {
throw new Exception("The program should have thrown an exception!");
}
if (!result.error().isPresent()) {
throw new NullPointerException("Handle null pointers.");
}
if (!(result.error().get() instanceof IllegalStateException)) {
String format = "Error: Expected IllegalStateException (found: %s)";
String message = String.format(format, result.error().getClass());
throw new IllegalStateException(message);
}
});
}
}