Code example for ByteArrayOutputStream

Methods: toString

0
 
    private final String NL = System.getProperty("line.separator");
 
    @Test 
    public void shouldOnlyReportOverriddenMethods() { 
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        final PrintStream printStream = new PrintStream(out);
        StoryReporter reporter = new NullStoryReporter(){
 
            @Override 
            public void beforeStory(Story story, boolean givenStory) {
                printStream.println("beforeStory");
            } 
 
            @Override 
            public void afterStory(boolean givenStory) {
                printStream.println("afterStory");
            } 
 
        }; 
        StoryNarrator.narrateAnInterestingStory(reporter, false);
        assertThat(out.toString(), Matchers.equalTo("beforeStory" + NL + "afterStory" + NL));
    } 
 
}