diff --git a/src/com/twu/biblioteca/Biblioteca.java b/src/com/twu/biblioteca/Biblioteca.java index 521c3f3..48b575c 100644 --- a/src/com/twu/biblioteca/Biblioteca.java +++ b/src/com/twu/biblioteca/Biblioteca.java @@ -28,7 +28,7 @@ public List listBooks() { } private void initialiazeBookList() { - Book book = new Book("Harry Potter"); + Book book = new Book("Harry Potter", "J. K. Rowling", 1997); books.add(book); } } diff --git a/src/com/twu/biblioteca/BibliotecaApp.java b/src/com/twu/biblioteca/BibliotecaApp.java index a87fe87..0ee082b 100755 --- a/src/com/twu/biblioteca/BibliotecaApp.java +++ b/src/com/twu/biblioteca/BibliotecaApp.java @@ -7,7 +7,7 @@ public static void main(String[] args) { System.out.println(biblioteca.welcomeUser()); for(Book book : biblioteca.listBooks()) { - System.out.println(book.name + "\n"); + System.out.println(book.showDetails() + "\n"); } } } diff --git a/src/com/twu/biblioteca/Book.java b/src/com/twu/biblioteca/Book.java index 700ad99..00e5bd9 100644 --- a/src/com/twu/biblioteca/Book.java +++ b/src/com/twu/biblioteca/Book.java @@ -5,8 +5,17 @@ */ public class Book { public String name; + public String author; + public int year; - public Book(String name) { + public Book(String name, String author, int year) { this.name = name; + this.author = author; + this.year = year; + } + + public String showDetails() { + String separator = " - "; + return name + separator + author + separator + Integer.toString(year); } } diff --git a/test/com/twu/biblioteca/BibliotecaTest.java b/test/com/twu/biblioteca/BibliotecaTest.java index 1db8cbf..be7025c 100755 --- a/test/com/twu/biblioteca/BibliotecaTest.java +++ b/test/com/twu/biblioteca/BibliotecaTest.java @@ -25,12 +25,13 @@ public void welcomeUser_ShouldReturnGivenMessage() throws Exception { @Test public void listBooks_ShouldListAllBooks() throws Exception { biblioteca = new Biblioteca(); - Book book = new Book("Harry Potter"); + String separator = " - "; + Book book = new Book("Harry Potter", "J. K. Rowling", 1997); List expected = new ArrayList(); expected.add(book); + Book expectedBook = expected.get(0); assertEquals(expected.size(), biblioteca.listBooks().size()); - - assertEquals(expected.get(0).name, biblioteca.listBooks().get(0).name); + assertEquals(expectedBook.name + separator + expectedBook.author + separator + expectedBook.year , biblioteca.listBooks().get(0).showDetails()); } } diff --git a/test/com/twu/biblioteca/BookTest.java b/test/com/twu/biblioteca/BookTest.java new file mode 100644 index 0000000..89bcb19 --- /dev/null +++ b/test/com/twu/biblioteca/BookTest.java @@ -0,0 +1,16 @@ +package com.twu.biblioteca; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Created by gdias on 7/31/15. + */ +public class BookTest { + @Test + public void showDetails_ShouldReturnBookNameAuthorAndYear() throws Exception { + String expected = "Harry Potter - J. K. Rowling - 1997"; + assertEquals(expected, new Book("Harry Potter", "J. K. Rowling", 1997).showDetails()); + } +}