school-library/src/main/java/com/redhat/training/BookStats.java | ●●●●● patch | view | raw | blame | history | |
school-library/src/main/java/com/redhat/training/books/Book.java | ●●●●● patch | view | raw | blame | history | |
school-library/src/test/java/com/redhat/training/BookStatsTest.java | ●●●●● patch | view | raw | blame | history | |
school-library/src/test/java/com/redhat/training/LibraryWithMockedInventoryTest.java | ●●●●● 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;