Skip to content

Commit

Permalink
Add book details feature
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermedias committed Jul 31, 2015
1 parent 9f6bce9 commit c638a5f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/com/twu/biblioteca/Biblioteca.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public List<Book> listBooks() {
}

private void initialiazeBookList() {
Book book = new Book("Harry Potter");
Book book = new Book("Harry Potter", "J. K. Rowling", 1997);
books.add(book);
}
}
2 changes: 1 addition & 1 deletion src/com/twu/biblioteca/BibliotecaApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
11 changes: 10 additions & 1 deletion src/com/twu/biblioteca/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
7 changes: 4 additions & 3 deletions test/com/twu/biblioteca/BibliotecaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Book> expected = new ArrayList<Book>();
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());
}
}
16 changes: 16 additions & 0 deletions test/com/twu/biblioteca/BookTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit c638a5f

Please sign in to comment.