public class TextFromStandardInputStream
extends org.junit.rules.ExternalResource
TextFromStandardInputStream rule replaces System.in with
another InputStream, which provides an arbitrary text. The original
System.in is restored after the test.
public void MyTest {
@Rule
public final TextFromStandardInputStream systemInMock
= emptyStandardInputStream();
@Test
public void readTextFromStandardInputStream() {
systemInMock.provide("foo");
Scanner scanner = new Scanner(System.in);
assertEquals("foo", scanner.nextLine());
}
}
| Constructor and Description |
|---|
TextFromStandardInputStream(java.lang.String text)
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
after() |
protected void |
before() |
static TextFromStandardInputStream |
emptyStandardInputStream() |
void |
provideText(java.lang.String text) |
@Deprecated public TextFromStandardInputStream(java.lang.String text)
provideText(String)TextFromStandardInputStream, which provides the
specified text.text - this text is return by System.in.public static TextFromStandardInputStream emptyStandardInputStream()
public void provideText(java.lang.String text)
protected void before()
throws java.lang.Throwable
before in class org.junit.rules.ExternalResourcejava.lang.Throwableprotected void after()
after in class org.junit.rules.ExternalResourceCopyright © 2011-2015. All Rights Reserved.