Skip to content

Instantly share code, notes, and snippets.

@born2snipe
Created October 12, 2018 13:23
Show Gist options
  • Save born2snipe/a22772c60da2bec54f929085279ae4cc to your computer and use it in GitHub Desktop.
Save born2snipe/a22772c60da2bec54f929085279ae4cc to your computer and use it in GitHub Desktop.
Closed System.in
import org.junit.Assert;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class SystemInTest {
@Test
public void closed_system_in() throws IOException {
ByteArrayInputStream input = new ByteArrayInputStream(new byte[0]);
System.setIn(input);
InputStreamReader reader = new InputStreamReader(System.in);
Assert.assertEquals(-1, reader.read());
}
}
@jbrains
Copy link

jbrains commented Oct 12, 2018

Yep. I ended up here, too. It turned out not to be what I wanted to check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment