fork download
  1. import static java.lang.System.in;
  2. import static java.lang.System.setIn;
  3. import static org.junit.Assert.fail;
  4.  
  5. import java.io.BufferedOutputStream;
  6. import java.io.BufferedReader;
  7. import java.io.ByteArrayInputStream;
  8. import java.io.IOException;
  9. import java.io.InputStream;
  10. import java.io.InputStreamReader;
  11. import java.io.PipedInputStream;
  12. import java.io.PipedOutputStream;
  13. import java.io.PrintStream;
  14. import java.nio.channels.Pipe;
  15.  
  16. import org.jmock.Expectations;
  17. import org.jmock.Mockery;
  18. import org.jmock.lib.legacy.ClassImposteriser;
  19. import org.junit.After;
  20. import org.junit.Before;
  21. import org.junit.Rule;
  22. import org.junit.Test;
  23. import org.junit.contrib.java.lang.system.TextFromStandardInputStream;
  24.  
  25. public class UnitTests {
  26. private Mockery context = new Mockery() {{
  27. setImposteriser(ClassImposteriser.INSTANCE);
  28. }};
  29. private main mn;
  30. private InputStream oldIn;
  31. private PrintStream oldOut;
  32. private InputStream mockIn;
  33. private InputStreamReader mockinputStream;
  34. private PrintStream mockOut;
  35. private BufferedReader reader;
  36.  
  37.  
  38. @Before
  39. public void setMinimalMockingExpectations() throws IOException {
  40. mn = context.mock(main.class);
  41. mockinputStream = context.mock(InputStreamReader.class);
  42. oldIn = System.in;
  43. oldOut = System.out;
  44. mockIn = context.mock(InputStream.class);
  45. mockOut = context.mock(PrintStream.class);
  46. System.setOut(mockOut);
  47. //System.setIn(mockIn);
  48. }
  49.  
  50. @After
  51. public void reset() {
  52. //System.setOut(oldOut);
  53. //System.setIn(oldIn);
  54. }
  55.  
  56. // @Rule
  57. // public final TextFromStandardInputStream selectF = new TextFromStandardInputStream("F\nDNE\n");
  58. @Test
  59. public void EnsureFileCheckExists() throws IOException {
  60. InputStream originalIn = System.in;
  61. BufferedReader reader = new BufferedReader(new InputStreamReader(pipeInput));
  62. final PipedOutputStream out = new PipedOutputStream(pipeInput);
  63. System.setIn(pipeInput);
  64. out.write("F\n".getBytes());
  65. out.write("DNE\n".getBytes());
  66.  
  67. Expectations exp;
  68. exp = new Expectations() {{
  69. one(mockOut).println("Do you want to process standard (I)nput, or a (F)ile? I/F");
  70. one(mockOut).println("Enter filename: ");
  71.  
  72. //System.setIn(new ByteArrayInputStream("DNE".getBytes()));
  73. //one(mn).readInput(); will(returnValue("-1"));
  74. //one(mn).readInput(); will(returnValue(DNE));
  75. //one(mn).ensureFileExists(DNE); will(returnValue(false));
  76. }};
  77. context.checking(exp);
  78. main.main(null);
  79. System.setIn(originalIn);
  80. }
  81. }
  82.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:25: class UnitTests is public, should be declared in a file named UnitTests.java
public class UnitTests {
       ^
Main.java:3: package org.junit does not exist
import static org.junit.Assert.fail;
                       ^
Main.java:3: static import only from classes and interfaces
import static org.junit.Assert.fail;
^
Main.java:16: package org.jmock does not exist
import org.jmock.Expectations;
                ^
Main.java:17: package org.jmock does not exist
import org.jmock.Mockery;
                ^
Main.java:18: package org.jmock.lib.legacy does not exist
import org.jmock.lib.legacy.ClassImposteriser;
                           ^
Main.java:19: package org.junit does not exist
import org.junit.After;
                ^
Main.java:20: package org.junit does not exist
import org.junit.Before;
                ^
Main.java:21: package org.junit does not exist
import org.junit.Rule;
                ^
Main.java:22: package org.junit does not exist
import org.junit.Test;
                ^
Main.java:23: package org.junit.contrib.java.lang.system does not exist
import org.junit.contrib.java.lang.system.TextFromStandardInputStream;
                                         ^
Main.java:26: cannot find symbol
symbol  : class Mockery
location: class UnitTests
	private Mockery context = new Mockery() {{
	        ^
Main.java:29: cannot find symbol
symbol  : class main
location: class UnitTests
	private main mn;
	        ^
Main.java:38: cannot find symbol
symbol  : class Before
location: class UnitTests
	@Before
	 ^
Main.java:50: cannot find symbol
symbol  : class After
location: class UnitTests
	@After
	 ^
Main.java:58: cannot find symbol
symbol  : class Test
location: class UnitTests
	@Test
	 ^
Main.java:26: cannot find symbol
symbol  : class Mockery
location: class UnitTests
	private Mockery context = new Mockery() {{
	                              ^
Main.java:40: cannot find symbol
symbol  : class main
location: class UnitTests
		mn = context.mock(main.class);
		                  ^
Main.java:68: cannot find symbol
symbol  : class Expectations
location: class UnitTests
		Expectations exp;
		^
Main.java:69: cannot find symbol
symbol  : class Expectations
location: class UnitTests
		exp = new Expectations() {{
		          ^
Main.java:79: cannot find symbol
symbol  : variable main
location: class UnitTests
		main.main(null);
		^
21 errors
stdout
Standard output is empty