mobi_reader/MobiReader/test/tests/SqlConnectionJUnitTest.java

80 lines
2.0 KiB
Java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package tests;
import java.util.ArrayList;
import java.util.List;
import mobireader.Author;
import mobireader.Book;
import mobireader.SqliteDatabaseHandler;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
/**
*
* @author att
*/
public class SqlConnectionJUnitTest {
public SqlConnectionJUnitTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
// TODO add test methods here.
// The methods must be annotated with annotation @Test. For example:
//
@Test
public void testIfConnectionWorks() throws Exception
{
SqliteDatabaseHandler.main();
}
@Test
public void testAddingBookToDb() throws Exception
{
SqliteDatabaseHandler handler = new SqliteDatabaseHandler();
String title = "Title";
String authorName = "Gepetto";
Author gepetto = new Author(authorName, title);
String path = "/somepath/book.txt";
Book bookToBeAdded = new Book(title, gepetto, path);
handler.addBook(bookToBeAdded);
Book bookFromDB = handler.findBook(title);
assertEquals(title, bookFromDB.getTitle());
assertEquals(authorName, bookFromDB.getAuthor().getName());
assertEquals(path, bookFromDB.getPathToContent());
}
public void testAddingFewBooksToDB() throws Exception
{
SqliteDatabaseHandler handler = new SqliteDatabaseHandler();
ArrayList<Book> books = Book.createSomeExamples();
handler.addBooks(books);
for(Book book : books)
{
Book bookFromDB = handler.findBook(book.getTitle());
assertTrue(bookFromDB != null);
}
}
}