|
15 | 15 | import org.junit.runners.model.Statement;
|
16 | 16 |
|
17 | 17 | public class TextFromStandardInputStreamTest {
|
18 |
| - private static final String ARBITRARY_TEXT = "arbitrary text"; |
19 |
| - |
20 | 18 | @Rule
|
21 | 19 | public final Timeout timeout = new Timeout(1000);
|
22 | 20 |
|
23 | 21 | private final TextFromStandardInputStream systemInMock = emptyStandardInputStream();
|
24 | 22 |
|
25 | 23 | @Test
|
26 | 24 | public void provideText() throws Throwable {
|
27 |
| - ReadTextFromSystemIn statement = new ReadTextFromSystemIn(ARBITRARY_TEXT); |
28 |
| - executeRuleWithStatement(statement); |
29 |
| - assertThat(statement.textFromSystemIn, is(equalTo(ARBITRARY_TEXT))); |
| 25 | + executeRuleWithStatement(new Statement() { |
| 26 | + @Override |
| 27 | + public void evaluate() throws Throwable { |
| 28 | + systemInMock.provideText("arbitrary text"); |
| 29 | + Scanner scanner = new Scanner(System.in); |
| 30 | + String textFromSystemIn = scanner.nextLine(); |
| 31 | + assertThat(textFromSystemIn, is(equalTo("arbitrary text"))); |
| 32 | + } |
| 33 | + }); |
30 | 34 | }
|
31 | 35 |
|
32 | 36 | @Test
|
@@ -66,20 +70,4 @@ public void restoreSystemIn() throws Throwable {
|
66 | 70 | private void executeRuleWithStatement(Statement statement) throws Throwable {
|
67 | 71 | systemInMock.apply(statement, null).evaluate();
|
68 | 72 | }
|
69 |
| - |
70 |
| - private class ReadTextFromSystemIn extends Statement { |
71 |
| - private final String textProvidedBySystemIn; |
72 |
| - private String textFromSystemIn; |
73 |
| - |
74 |
| - public ReadTextFromSystemIn(String textProvidedBySystemIn) { |
75 |
| - this.textProvidedBySystemIn = textProvidedBySystemIn; |
76 |
| - } |
77 |
| - |
78 |
| - @Override |
79 |
| - public void evaluate() throws Throwable { |
80 |
| - systemInMock.provideText(textProvidedBySystemIn); |
81 |
| - Scanner scanner = new Scanner(System.in); |
82 |
| - textFromSystemIn = scanner.nextLine(); |
83 |
| - } |
84 |
| - } |
85 | 73 | }
|
0 commit comments