fork download
  1. import static org.junit.Assert.*;
  2.  
  3. import java.io.BufferedOutputStream;
  4. import java.io.BufferedReader;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.io.InputStreamReader;
  8. import java.io.OutputStream;
  9. import java.io.PipedInputStream;
  10. import java.io.PipedOutputStream;
  11. import java.io.PrintStream;
  12.  
  13. import org.junit.After;
  14. import org.junit.Before;
  15. import org.junit.Test;
  16. import org.jmock.Mockery;
  17. import org.jmock.Expectations;
  18. import org.jmock.lib.legacy.ClassImposteriser;
  19. import ProcessingLogic.Counter;
  20. import ProcessingLogic.Word;
  21. import StorageLogic.WordFrequency;
  22.  
  23.  
  24.  
  25. public class UnitTests {
  26. private Mockery context = new Mockery() {{
  27. setImposteriser(ClassImposteriser.INSTANCE);
  28. }};
  29. private main mn;
  30. private Counter counter;
  31.  
  32. private InputStream oldIn;
  33. private PrintStream oldOut;
  34. private InputStream mockIn;
  35. private PrintStream mockOut;
  36. private BufferedReader reader;
  37. private InputStream input;
  38. @Before
  39. public void setMinimalMockingExpectations() throws IOException {
  40. mn = context.mock(main.class);
  41. counter = context.mock(Counter.class);
  42. reader = context.mock(BufferedReader.class);
  43. oldIn = System.in;
  44. oldOut = System.out;
  45. mockIn = context.mock(InputStream.class);
  46. mockOut = context.mock(PrintStream.class);
  47. System.setOut(mockOut);
  48. System.setIn(mockIn);
  49. }
  50.  
  51. @After
  52. public void reset() {
  53. System.setOut(oldOut);
  54. System.setIn(oldIn);
  55. }
  56.  
  57. //File associated errors
  58. @Test
  59. public void EnsureFileCheckExists() throws IOException {
  60. final String DNE = "Does not exist";
  61.  
  62. Expectations exp;
  63. exp = new Expectations() {{
  64. //one(mn).main(null);
  65. //one(mn).promptStringOrFile(); will(returnValue(true)); //use parameter here
  66. one(mockOut).println("Do you want to process standard (I)nput, or a (F)ile? I/F");
  67. one(input).read(with(any( Object.class )), any(Integer.class), any(Integer.class));
  68. one(reader).read(new char[2], 0,1);
  69. //one(mn).grabConfig(); will(returnValue(new String[] {"-1", "1"}));
  70. one(mockOut).println("How many results would you like to see? (-1 for all)");
  71. //one(mn).readInput(); will(returnValue("-1"));
  72. //one(mn).readInput(); will(returnValue(DNE));
  73. //one(mn).ensureFileExists(DNE); will(returnValue(false));
  74. }};
  75. context.checking(exp);
  76. main.main(null);
  77. }
  78. }
  79.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout

Standard output is empty