fork download
import static org.junit.Assert.*;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.jmock.Mockery;
import org.jmock.Expectations;
import org.jmock.lib.legacy.ClassImposteriser;
import ProcessingLogic.Counter;
import ProcessingLogic.Word;
import StorageLogic.WordFrequency;



public class UnitTests {
	private Mockery context = new Mockery() {{
		setImposteriser(ClassImposteriser.INSTANCE);
	}};
	private main mn;
	private Counter counter;

	private InputStream oldIn;
	private PrintStream oldOut;
	private InputStream mockIn;
	private PrintStream mockOut;
	private BufferedReader reader;
	private InputStream input;
	@Before
	public void setMinimalMockingExpectations() throws IOException {
		mn = context.mock(main.class);
		counter = context.mock(Counter.class);
		reader = context.mock(BufferedReader.class);
		oldIn = System.in;
		oldOut = System.out;
		mockIn = context.mock(InputStream.class);
		mockOut = context.mock(PrintStream.class);
		System.setOut(mockOut);
		System.setIn(mockIn);
	}
	
	@After
	public void reset() {
		System.setOut(oldOut);
		System.setIn(oldIn);
	}
	
	//File associated errors
	@Test
	public void EnsureFileCheckExists() throws IOException {
		final String DNE = "Does not exist";

		Expectations exp;
		exp = new Expectations() {{
			//one(mn).main(null);
			//one(mn).promptStringOrFile(); will(returnValue(true)); //use parameter here
			one(mockOut).println("Do you want to process standard (I)nput, or a (F)ile? I/F");
			one(input).read(with(any( Object.class )), any(Integer.class), any(Integer.class));
			one(reader).read(new char[2], 0,1);
			//one(mn).grabConfig(); will(returnValue(new String[] {"-1", "1"}));
			one(mockOut).println("How many results would you like to see? (-1 for all)");
			//one(mn).readInput(); will(returnValue("-1"));
			//one(mn).readInput(); will(returnValue(DNE));
			//one(mn).ensureFileExists(DNE); will(returnValue(false));
		}};
		context.checking(exp);
		main.main(null);
	}
}
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout

Standard output is empty