Jaime Ramirez
2020-10-13 15d46e685bfff29245e45cbe299988cc8b5bce41
Added Book counter test
2 files added
1 files modified
1 files renamed
57 ■■■■■ changed files
school-library/src/main/java/com/redhat/training/BookStats.java 14 ●●●●● patch | view | raw | blame | history
school-library/src/main/java/com/redhat/training/books/Book.java 7 ●●●●● patch | view | raw | blame | history
school-library/src/test/java/com/redhat/training/BookStatsTest.java 34 ●●●●● patch | view | raw | blame | history
school-library/src/test/java/com/redhat/training/LibraryWithMockedInventoryTest.java 2 ●●● patch | view | raw | blame | history
school-library/src/main/java/com/redhat/training/BookStats.java
New file
@@ -0,0 +1,14 @@
package com.redhat.training;
import com.redhat.training.books.Book;
public class BookStats {
    public static int countWords(Book book) {
        if (book.text.isEmpty()) {
            return 0;
        }
        return book.text.split("\\s+").length;
    }
}
school-library/src/main/java/com/redhat/training/books/Book.java
@@ -3,9 +3,16 @@
public class Book {
    public String isbn;
    public String text;
    public Book(String isbn) {
        this.isbn = isbn;
        text = "";
    }
    public Book(String isbn, String text) {
        this.isbn = isbn;
        this.text = text;
    }
}
school-library/src/test/java/com/redhat/training/BookStatsTest.java
New file
@@ -0,0 +1,34 @@
package com.redhat.training;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.redhat.training.books.Book;
import org.junit.jupiter.api.Test;
public class BookStatsTest {
    @Test
    public void test_countWords_Returns0_WhenBookEmpty() {
        // Given
        Book book = new Book("someISBN");
        // When
        double wordCount = BookStats.countWords(book);
        // Then
        assertEquals(0, wordCount);
    }
    @Test
    public void test_countWords_returnsNumberOfWords() {
        // Given
        Book book = new Book("someISBN", "this is the content");
        // When
        double wordCount = BookStats.countWords(book);
        // Then
        assertEquals(4, wordCount);
    }
}
school-library/src/test/java/com/redhat/training/LibraryWithMockedInventoryTest.java
File was renamed from school-library/src/test/java/com/redhat/training/TestLibraryWithMockedInventory.java
@@ -12,7 +12,7 @@
import org.junit.jupiter.api.Test;
public class TestLibraryWithMockedInventory {
public class LibraryWithMockedInventoryTest {
    Inventory inventory;
    Library library;