12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import static org.junit.Assert.*;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. import java.io.ByteArrayInputStream;
  6. /**
  7. * The test class ConsoleTest.
  8. *
  9. * @author (your name)
  10. * @version (a version number or a date)
  11. */
  12. public class ConsoleTest
  13. {
  14. @Test
  15. public void testInputDouble(){
  16. ByteArrayInputStream in = new ByteArrayInputStream ("7".getBytes());
  17. System.setIn(in);
  18. assertEquals(Double.valueOf("7"),Console.inputDouble(),.000000001);
  19. }
  20. @Test
  21. public void testInputInt(){
  22. ByteArrayInputStream in = new ByteArrayInputStream ("7".getBytes());
  23. System.setIn(in);
  24. assertEquals(7,Console.inputInt());
  25. }
  26. @Test
  27. public void testInputString(){
  28. ByteArrayInputStream in = new ByteArrayInputStream ("7".getBytes());
  29. System.setIn(in);
  30. assertEquals("7",Console.inputString());
  31. }
  32. @Test
  33. public void testGetOperator(){
  34. ByteArrayInputStream in = new ByteArrayInputStream ("a".getBytes());
  35. System.setIn(in);
  36. assertEquals('a',Console.getOperator());
  37. }
  38. @Test
  39. public void TestInputAddMethod()
  40. {
  41. assertEquals(5, Console.inputString());
  42. }
  43. }