Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. public abstract class StdOutTest {
  2.  
  3. private final PrintStream stdOutMock = mock(PrintStream.class);
  4. private final PrintStream stdOutOrig = System.out;
  5.  
  6. @Before
  7. public void setUp() {
  8. System.setOut(this.stdOutMock);
  9. }
  10.  
  11. @After
  12. public void tearDown() {
  13. System.setOut(this.stdOutOrig);
  14. }
  15.  
  16. protected final PrintStream getStdOutMock() {
  17. return this.stdOutMock;
  18. }
  19. }
  20.  
  21. public class test extends StdOutTest{
  22.  
  23. @Before
  24. public void setUp(){
  25. //empty
  26. }
  27.  
  28. @Test
  29. public void example(){
  30. System.out.println("hello");
  31. verify(getStdOutMock()).println("hello");
  32. }
  33. }
  34.  
  35. hello
  36.  
  37.  
  38. Wanted but not invoked:
  39. printStream.println("hello");
  40. -> at observer_test.test.example(test.java:18)
  41. Actually, there were zero interactions with this mock.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement