Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.junit.*;
- import static org.junit.Assert.*;
- import java.io.*;
- public class Tests {
- BasicInput student = new BasicInput();
- private ByteArrayOutputStream TOut;
- private ByteArrayInputStream TIn;
- private final PrintStream SOut = System.out;
- private final InputStream SIn = System.in;
- String[] args = {};
- @Test
- public void testFixMe1(){
- setInput("10 2.2 a this ");
- student.main(args);
- String correct = "Enter integer:\nEnter double:\nEnter character:\nEnter string:\n10 2.2 a this\n";
- String result = getOutput().substring(0,correct.length());
- assertEquals(correct, result);
- }
- @Test
- public void testFixMe2(){
- setInput("104 0.235 S stringy");
- student.main(args);
- String correct = "Enter integer:\nEnter double:\nEnter character:\nEnter string:\n104 0.235 S stringy\n";
- correct += "stringy S 0.235 104\n";
- String result = getOutput().substring(0,correct.length());
- assertEquals(correct, result);
- }
- @Test
- public void testFixMe3(){
- setInput("14 13.235 J cheese");
- student.main(args);
- String correct = "Enter integer:\nEnter double:\nEnter character:\nEnter string:\n14 13.235 J cheese\n";
- correct += "cheese J 13.235 14\n";
- correct += "13.235 cast to an integer is 13\n";
- String result = getOutput();
- assertEquals(correct, result);
- }
- //Set up methods
- @Before
- public void setOutput(){
- TOut = new ByteArrayOutputStream();
- System.setOut(new PrintStream(TOut));
- }
- private void setInput(String data){
- TIn = new ByteArrayInputStream(data.getBytes());
- System.setIn(TIn);
- }
- private String getOutput(){
- return TOut.toString();
- }
- @After
- public void restoreSystem(){
- System.setOut(SOut);
- System.setIn(SIn);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement