package com.twu.biblioteca;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

@RunWith(MockitoJUnitRunner.class)
public class BooksViewTest {
    private ByteArrayOutputStream byteArrayOutputStream;

    @Before
    public void setUp() throws Exception {
        byteArrayOutputStream = new ByteArrayOutputStream();
        System.setOut(new PrintStream(byteArrayOutputStream));
    }

    @Test
    public void shouldBeAbleToPrintWelcomeMessage() throws Exception {
        BooksView booksView = new BooksView(new Books());
        booksView.display();

        String actualBookList = byteArrayOutputStream.toString();

        assertThat(actualBookList, is(equalTo("| Harry Potter and The Sorcer's Stone | JK Rowling | 1999 |\n" +
                "| Harry Potter and The Chamber of Secrets | JK Rowling | 2000 |\n")));
    }
}
@@ -103,16 +103,41 @@
 unWith;%0A
+import org.mockito.Mock;%0A
 import o
@@ -175,16 +175,16 @@
 Runner;%0A
-
 %0Aimport 
@@ -378,16 +378,56 @@
 ertThat;
+%0Aimport static org.mockito.Mockito.when;
 %0A%0A@RunWi
@@ -484,16 +484,56 @@
 wTest %7B%0A
+    @Mock%0A    private Books mockBooks;%0A%0A
     priv
@@ -897,19 +897,238 @@
 iew(
-new Books()
+mockBooks);%0A        when(mockBooks.toString())%0A                .thenReturn(%22%7C Harry Potter and The Sorcer's Stone %7C JK Rowling %7C 1999 %7C%5Cn%22 +%0A                        %22%7C Harry Potter and The Chamber of Secrets %7C JK Rowling %7C 2000 %7C%22
 );%0A 

Replace creation of new Book object with mock in BooksViewTest