Created
March 17, 2016 19:43
-
-
Save AlexGabor/90f23c032fcde6b4ad1c to your computer and use it in GitHub Desktop.
tests for Book
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ro.oneandonly.bookstore.service; | |
import org.junit.After; | |
import org.junit.Before; | |
import org.junit.Ignore; | |
import org.junit.Test; | |
import ro.oneandonly.bookstore.domain.Book; | |
import ro.oneandonly.bookstore.domain.validators.ValidatorException; | |
import ro.oneandonly.bookstore.repository.Repository; | |
import java.util.*; | |
import java.util.concurrent.RunnableFuture; | |
import static org.junit.Assert.fail; | |
/** | |
* Created by alex on 3/17/16. | |
*/ | |
public class BookServiceTest { | |
private static final Book BOOK1 = new Book("isbn3", "title1", "First Last"); | |
private static final Book BOOK2 = new Book("isbn2", "title3", "First Smith"); | |
private static final Book BOOK3 = new Book("isbn1", "title2", "Foo Bar"); | |
private static final List<Book> BOOKS = Arrays.asList(BOOK1, BOOK2, BOOK3); | |
private static final List<Book> BOOKS_SORTED_BY_TITLE_REVERSED = Arrays.asList(BOOK2, BOOK3, BOOK1); | |
private static final Set<Book> SET_ISBN1 = new HashSet<>(Collections.singletonList(BOOK3)); | |
private static final Set<Book> BOOK_SET = new HashSet<>(BOOKS); | |
private static final Set<Book> SET_AUTHORS = new HashSet<>(Arrays.asList(BOOK1, BOOK2)); | |
private BookService service; | |
@Before | |
public void setUp() throws Exception { | |
BOOK2.setPrice(12); | |
BOOK3.setPrice(50); | |
service = new BookService(new Repository<Long, Book>() { | |
@Override | |
public Optional<Book> findOne(Long aLong) { | |
return null; | |
} | |
@Override | |
public Iterable<Book> findAll() { | |
return BOOKS; | |
} | |
@Override | |
public Optional<Book> save(Book entity) throws ValidatorException { | |
return null; | |
} | |
@Override | |
public Optional<Book> delete(Long aLong) { | |
return null; | |
} | |
@Override | |
public Optional<Book> update(Book entity) throws ValidatorException { | |
return null; | |
} | |
}); | |
} | |
@After | |
public void tearDown() throws Exception { | |
service = null; | |
} | |
@Ignore | |
@Test | |
public void testAddBook() throws Exception { | |
fail("Not tested"); | |
} | |
@Test | |
public void testGetAllBooks() throws Exception { | |
assert service.getAllBooks().equals(BOOK_SET); | |
} | |
@Ignore | |
@Test | |
public void testUpdateBook() throws Exception { | |
fail("Not tested"); | |
} | |
@Ignore | |
@Test | |
public void testDeleteBook() throws Exception { | |
fail("Not tested"); | |
} | |
@Test | |
public void testFilterByAuthor() throws Exception { | |
assert service.filterByAuthor("FIRST").equals(SET_AUTHORS) : "Incorrectly filtered"; | |
} | |
@Test | |
public void testFilterByTitle() throws Exception { | |
assert service.filterByTitle("title").equals(BOOK_SET) : "Incorrectly filtered"; | |
} | |
@Test | |
public void testFilterByIsbn() throws Exception { | |
assert service.filterByIsbn("isbn1").equals(SET_ISBN1) : "Incorrectly filtered"; | |
} | |
@Test | |
public void testSortByTitle() throws Exception { | |
assert service.sortByTitle(true).equals(BOOKS_SORTED_BY_TITLE_REVERSED) : "Incorrectly sorted"; | |
} | |
@Test | |
public void testSortByAuthor() throws Exception { | |
assert service.sortByAuthor(false).equals(BOOKS) : "Incorrectly sorted"; | |
} | |
@Test | |
public void testSortByPrice() throws Exception { | |
assert service.sortByPrice(false).equals(BOOKS_SORTED_BY_TITLE_REVERSED) : "Incorrectly sorted"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment