-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathRestoreSystemOutChecks.java
More file actions
43 lines (35 loc) · 916 Bytes
/
RestoreSystemOutChecks.java
File metadata and controls
43 lines (35 loc) · 916 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
41
42
43
package com.github.stefanbirkner.systemlambda;
import org.junit.jupiter.api.Test;
import java.io.PrintStream;
import static com.github.stefanbirkner.fishbowl.Fishbowl.ignoreException;
import static org.assertj.core.api.Assertions.assertThat;
abstract class RestoreSystemOutChecks {
private final MethodUnderTest methodUnderTest;
RestoreSystemOutChecks(
MethodUnderTest methodUnderTest
) {
this.methodUnderTest = methodUnderTest;
}
@Test
void after_statement_is_executed(
) throws Exception {
PrintStream originalOut = System.out;
methodUnderTest.accept(
() -> {
}
);
assertThat(System.out).isSameAs(originalOut);
}
@Test
void after_statement_throws_exception() {
PrintStream originalOut = System.out;
ignoreException(
() -> methodUnderTest.accept(
() -> {
throw new Exception("some exception");
}
)
);
assertThat(System.out).isSameAs(originalOut);
}
}