Skip to content

Commit 77ecfa9

Browse files
committed
Refactor test provideText.
The last commit added two tests that use a different style. Applied this style to `provideText` for the sake of symmetry.
1 parent f49179e commit 77ecfa9

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

src/test/java/org/junit/contrib/java/lang/system/TextFromStandardInputStreamTest.java

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,22 @@
1515
import org.junit.runners.model.Statement;
1616

1717
public class TextFromStandardInputStreamTest {
18-
private static final String ARBITRARY_TEXT = "arbitrary text";
19-
2018
@Rule
2119
public final Timeout timeout = new Timeout(1000);
2220

2321
private final TextFromStandardInputStream systemInMock = emptyStandardInputStream();
2422

2523
@Test
2624
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+
});
3034
}
3135

3236
@Test
@@ -66,20 +70,4 @@ public void restoreSystemIn() throws Throwable {
6670
private void executeRuleWithStatement(Statement statement) throws Throwable {
6771
systemInMock.apply(statement, null).evaluate();
6872
}
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-
}
8573
}

0 commit comments

Comments
 (0)