Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. import org.junit.*;
  2. import static org.junit.Assert.*;
  3. import java.io.*;
  4.  
  5. public class Tests {
  6. BasicInput student = new BasicInput();
  7. private ByteArrayOutputStream TOut;
  8. private ByteArrayInputStream TIn;
  9. private final PrintStream SOut = System.out;
  10. private final InputStream SIn = System.in;
  11. String[] args = {};
  12.  
  13. @Test
  14. public void testFixMe1(){
  15. setInput("10 2.2 a this ");
  16. student.main(args);
  17. String correct = "Enter integer:\nEnter double:\nEnter character:\nEnter string:\n10 2.2 a this\n";
  18. String result = getOutput().substring(0,correct.length());
  19. assertEquals(correct, result);
  20. }
  21. @Test
  22. public void testFixMe2(){
  23. setInput("104 0.235 S stringy");
  24. student.main(args);
  25. String correct = "Enter integer:\nEnter double:\nEnter character:\nEnter string:\n104 0.235 S stringy\n";
  26. correct += "stringy S 0.235 104\n";
  27. String result = getOutput().substring(0,correct.length());
  28. assertEquals(correct, result);
  29. }
  30. @Test
  31. public void testFixMe3(){
  32. setInput("14 13.235 J cheese");
  33. student.main(args);
  34. String correct = "Enter integer:\nEnter double:\nEnter character:\nEnter string:\n14 13.235 J cheese\n";
  35. correct += "cheese J 13.235 14\n";
  36. correct += "13.235 cast to an integer is 13\n";
  37. String result = getOutput();
  38. assertEquals(correct, result);
  39. }
  40.  
  41. //Set up methods
  42. @Before
  43. public void setOutput(){
  44. TOut = new ByteArrayOutputStream();
  45. System.setOut(new PrintStream(TOut));
  46. }
  47. private void setInput(String data){
  48. TIn = new ByteArrayInputStream(data.getBytes());
  49. System.setIn(TIn);
  50. }
  51. private String getOutput(){
  52. return TOut.toString();
  53. }
  54. @After
  55. public void restoreSystem(){
  56. System.setOut(SOut);
  57. System.setIn(SIn);
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement