package com.twu.biblioteca;


import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.lang.StringBuilder;
import java.util.List;
import java.util.ArrayList;

public class BibliotecaAppTest {

    @Test
    public void testBibliotecaStartup() {
        List<String> bookList = new ArrayList<String>();
        bookList.add("Test-Driven Development By Example");
        bookList.add("The Agile Samurai");
        bookList.add("Head First Java");
        bookList.add("Don't Make Me Think, Revisited: A Common Sense Approach to Web Usability");

        StringBuilder startupOutput = new StringBuilder();
        startupOutput.append("Welcome to Biblioteca!\n");
        startupOutput.append("Book list:\n");
        for (String book : bookList) {
            startupOutput.append(book + "\n");
        }

        ByteArrayOutputStream outContent = new ByteArrayOutputStream();
        System.setOut(new PrintStream(outContent));
        BibliotecaApp.main(new String[] {});

        assertEquals(startupOutput.toString(), outContent.toString());
    }
}

@@ -239,16 +239,44 @@
 rayList;
+%0Aimport java.util.Formatter;
 %0A%0Apublic
@@ -367,65 +367,69 @@
     
-List%3C
 String
-%3E bookList = new ArrayList%3CString%3E
+Builder expectedOutput = new StringBuilder
 ();%0A
+%0A
         
 book
@@ -428,152 +428,286 @@
     
-bookList.add(%22Test-Driven Development By Example%22);%0A        bookList.add(%22The Agile Samurai%22);%0A        bookList.add(%22Head First Java%22
+expectedOutput.append(%22Welcome to Biblioteca!%5Cn%22);%0A        expectedOutput.append(printBookList());%0A%0A        ByteArrayOutputStream outContent = new ByteArrayOutputStream();%0A        System.setOut(new PrintStream(outContent));%0A        BibliotecaApp.main(new String%5B%5D %7B%7D
 );%0A
+%0A
         
 book
@@ -706,99 +706,166 @@
     
-bookList.add(%22Don't Make Me Think, Revisited: A Common Sense Approach to Web Usability%22
+assertEquals(expectedOutput.toString(), outContent.toString());%0A    %7D%0A%0A    private String printBookList() %7B%0A        List%3CBook%3E bookList = generateBookList(
 );%0A
-%0A
     
@@ -882,24 +882,17 @@
 Builder 
-startupO
+o
 utput = 
@@ -916,32 +916,25 @@
 ();%0A        
-startupO
+o
 utput.append
@@ -939,34 +939,80 @@
 nd(%22
-Welcome to Biblioteca!
+Book List:%22);%0A%0A        String leftAlignFormat = %22%25-32s %7C %25-32s %7C %25-4d
 %5Cn%22
-)
 ;%0A  
@@ -1013,32 +1013,25 @@
 n%22;%0A        
-startupO
+o
 utput.append
@@ -1035,22 +1035,75 @@
 end(
-%22Book list:%5Cn%22
+String.format(leftAlignFormat, %22Title%22, %22Author%22, %22Year Published%22)
 );%0A 
@@ -1114,22 +1114,26 @@
    for (
-String
+List%3CBook%3E
  book : 
@@ -1156,24 +1156,17 @@
         
-startupO
+o
 utput.ap
@@ -1174,19 +1174,98 @@
 end(
-book + %22%5Cn%22
+String.format(leftAlignFormat, book.getTitle(), book.getAuthor(), book.getYearPublished())
 );%0A 
@@ -1273,25 +1273,24 @@
       %7D%0A
-%0A
         
 ByteArra
@@ -1285,47 +1285,119 @@
     
-ByteArrayOutputStream outConten
+return output.toString();%0A    %7D%0A%0A    private List%3CBook%3E generateBookList() %7B%0A        List%3CBook%3E bookLis
 t = new 
 Byte
@@ -1396,139 +1396,205 @@
 new 
-Byte
 Array
-OutputStream();%0A        System.setOut(new PrintStream(outContent));%0A        BibliotecaApp.main(new String%5B%5D %7B%7D
+List%3CBook%3E();%0A        bookList.add(new Book(%22Test-Driven Development By Example%22, %22Kent Beck%22, 2003));%0A        bookList.add(new Book(%22The Agile Samurai%22, %22Jonathan Rasmusson%22, 2010)
 );%0A
-%0A
         
 asse
@@ -1593,69 +1593,237 @@
     
-assertEquals(startupOutput.toString(), outContent.toString())
+bookList.add(new Book(%22Head First Java%22, %22Kathy Sierra & Bert Bates%22, 2005));%0A        bookList.add(new Book(%22Don't Make Me Think, Revisited: A Common Sense Approach to Web Usability%22, %22Steve Krug%22, 2014));%0A        return bookList
 ;%0A  

Test printing book list with author and publish year