From a62040d5f7aa104e6c919e26e9080ab27fa9ba5a Mon Sep 17 00:00:00 2001 From: meliurwen Date: Sun, 12 Jan 2020 23:23:45 +0100 Subject: [PATCH] Aggiornamento test Book e Author --- mivan/src/main/java/mivan/model/Book.java | 2 +- mivan/src/test/java/mivan/AuthorTest.java | 7 ++-- mivan/src/test/java/mivan/BookTest.java | 49 ++++++++++++++++++++++- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/mivan/src/main/java/mivan/model/Book.java b/mivan/src/main/java/mivan/model/Book.java index 96e14b7..0c00668 100644 --- a/mivan/src/main/java/mivan/model/Book.java +++ b/mivan/src/main/java/mivan/model/Book.java @@ -50,7 +50,7 @@ public class Book implements Serializable { return isbn; } - public String getTitolo() { + public String getTitle() { return title; } diff --git a/mivan/src/test/java/mivan/AuthorTest.java b/mivan/src/test/java/mivan/AuthorTest.java index 197309a..59002f2 100644 --- a/mivan/src/test/java/mivan/AuthorTest.java +++ b/mivan/src/test/java/mivan/AuthorTest.java @@ -57,7 +57,8 @@ public class AuthorTest { @Test @Order(3) void testDeleteUser() { - String name = "ivan"; + int size = authorRepository.getSize(); + String name = "gollum"; Author author = new Author(name); @@ -69,8 +70,8 @@ public class AuthorTest { authorRepository.deleteAuthorById(ID); - int size = authorRepository.getSize(); - assertEquals(size, 0); + int end_size = authorRepository.getSize(); + assertEquals(end_size, size); } diff --git a/mivan/src/test/java/mivan/BookTest.java b/mivan/src/test/java/mivan/BookTest.java index c127605..9ff3abe 100644 --- a/mivan/src/test/java/mivan/BookTest.java +++ b/mivan/src/test/java/mivan/BookTest.java @@ -1,6 +1,11 @@ package mivan; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Optional; + +import javax.validation.constraints.AssertTrue; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; @@ -21,7 +26,7 @@ public class BookTest { @Order(1) void testAddBook() { - int isbn = 1234; + long isbn = 1234; String title = "illiade"; Book prequel = null; @@ -36,6 +41,48 @@ public class BookTest { } + @Test + @Order(2) + void testUpdateBook(){ + long isbn = 12348; + String title = "odissea"; + Book prequel = null; + + Book book = new Book(isbn, title, prequel); + + bookRepository.addBook(book); + String update_title = "eneide"; + bookRepository.updateBook(isbn, update_title, prequel); + + Optional opt_book2 = bookRepository.findById(isbn); + + Book book2 = opt_book2.get(); + assertTrue(update_title.equals(book2.getTitle())); + + } + + @Test + @Order(3) + void testDeleteBook() { + int start_size = bookRepository.getSize(); + long isbn = 12345; + String title = "illiade"; + Book prequel = null; + + Book book = new Book(isbn, title, prequel); + + bookRepository.addBook(book); + + Optional opt_book2 = bookRepository.findById(isbn); + + Book book2 = opt_book2.get(); + long ID = book2.getIsbn(); + + bookRepository.deleteBookById(ID); + + int size = bookRepository.getSize(); + assertEquals(start_size,size); + } }