<commit_before>package next_book_web_scrapper.database;

import next_book_web_scrapper.entity.Book;
import org.junit.Test;
import org.junit.Before;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.*;

public class BookDAOTest {

    private BookDAO bookDao;
    @Before
    public void setup() {
        bookDao = new BookDAO();
    }

    @Test
    public void addBookStaticBookTest() throws Exception {
        List<String> genreList = new ArrayList<String>();
        genreList.add("Classical");
        genreList.add("Rock");
        Book book = new Book();
        book.setAuthorName("Meseeks");
        book.setTitle("A different book");
        book.setGenre(genreList);
        book.setIsbn("1234567890");
        book.setRating(5);
        book.setFk_id_author(3);
        bookDao.deleteBook(book);
        int book_id = bookDao.addBook(book);
        assertTrue("Validation failure", book_id >= 0);
        assertTrue("Book was not added to the database", book_id != 0);
    }



    @Test
    public void getBookInDatabase() throws Exception {
        List<String> genreList = new ArrayList<String>();
        genreList.add("Classical");
        genreList.add("Rock");
        Book book = new Book();
        book.setAuthorName("Meseeks");
        book.setTitle("Differet student book");
        book.setGenre(genreList);
        book.setIsbn("1234567890");
        book.setRating(5);
        book.setFk_id_author(3);
        int book_id = bookDao.addBook(book);
        Book inDatabase = bookDao.getBook(book_id);

        bookDao.deleteBook(book);
        assertTrue("Get book failure", inDatabase != null);
        //assertTrue(book.getAuthorName().equals("Kansas"));
    }

    /*
    @Test
    public void updateBookAlreadyInDatabase() {
        Book book = bookDao.getBook(1);

        assertTrue("Get fail for book update", book != null);

        book.setRating(3);
        book.setTitle("Rick and morty");

        boolean passed = bookDao.updateBook(book);
        assertTrue(passed);
    }
    */

    @Test
    public void deleteBookTest() {
        ArrayList<String> genres = new ArrayList<String>();
        genres.add("Contemporary");
        genres.add("Hello");
        Book book = new Book();
        book.setAuthorName("<NAME>");
        book.setTitle("To be nuked");
        book.setRating(5);
        book.setIsbn("1234567890");
        book.setGenre(genres);
        book.setFk_id_author(3);
        int book_id = bookDao.addBook(book);
        assertTrue("Fail to add in delete Test", book_id > 0);


        int other_id = bookDao.deleteBook(book);

        assertTrue("Ids do not match in delete",other_id == book_id);
    }

    /*
    @Test
    public void deleteBookById() {
        ArrayList<String> genres = new ArrayList<String>();
        genres.add("comedy");
        genres.add("relationships");
        Book book = new Book();
        book.setAuthorName("<NAME>");
        book.setTitle("Deleted 2");
        book.setRating(5);
        book.setIsbn(1234567890);
        book.setGenre(genres);
        book.setFk_id_author(3);
        int book_id = bookDao.addBook(book);
        assertTrue("Fail to add in delete Test", book_id > 0);

        int delete_id = bookDao.deleteBook(book_id);
        assertTrue( delete_id > 0);
        assertTrue(delete_id == book_id);
    }
    */
    @Test
    public void safeAddBookTest() {
        ArrayList<String> genres = new ArrayList<String>();
        genres.add("Dark");
        genres.add("Action");
        Book book = new Book();
        book.setAuthorName("Morty");
        book.setTitle("Adventures of Rick and morty season 99");
        book.setRating(5);
        book.setIsbn("1234567891");
        book.setGenre(genres);
        book.setFk_id_author(3);

        int book_id = bookDao.safeAddBook(book);
        assertTrue("Error occurred\n", book_id >= 0);
        assertTrue("Addition failure\n", book_id > 0);

        Book inDatabase = bookDao.getBook(book_id);

        assertTrue("Id was never set", inDatabase.getId() != 0);

        int another_id = bookDao.safeAddBook(inDatabase);
        assertTrue("Add went through\n", another_id == 0);

        bookDao.safeDeleteBook(book);
    }

    @Test
    public void safeDeleteBookTest() {
        ArrayList<String> genres = new ArrayList<String>();
        genres.add("Dark");
        genres.add("Action");
        Book book = new Book();
        book.setAuthorName("Morty");
        book.setTitle("Guiness book of world records");
        book.setRating(5);
        book.setIsbn("1234567891");
        book.setGenre(genres);
        book.setFk_id_author(3);

        int book_id = bookDao.safeAddBook(book);
        assertTrue("Error occurred\n", book_id >= 0);
        assertTrue("Addition failure\n", book_id > 0);

        int delete_id = bookDao.safeDeleteBook(book);
        assertTrue("Delete failed\n", delete_id > 0);
        assertTrue("Ids are not the same", delete_id == book_id);
    }

    @Test
    public void safeUpdateBookTest() {
        ArrayList<String> genres = new ArrayList<String>();
        genres.add("Dark");
        genres.add("Comedy");
        Book book = new Book();
        book.setAuthorName("Morty");
        book.setTitle("Adventures of Rick and Morty");
        book.setRating(5);
        book.setIsbn("1234567891");
        book.setGenre(genres);
        book.setFk_id_author(3);

        int book_id = bookDao.safeAddBook(book);

        book.setIsbn("1111111111");

        boolean passed = bookDao.safeUpdateBook(book);
        assertTrue("Update Failed", passed);

        bookDao.safeDeleteBook(book);
    }
}<commit_msg>Adding authors to pass tests, then extraction!<commit_after>package next_book_web_scrapper.database;

import next_book_web_scrapper.entity.Book;
import next_book_web_scrapper.entity.Author;
import org.junit.Test;
import org.junit.Before;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.*;

public class BookDAOTest {

    private BookDAO bookDao;
    @Before
    public void setup() {
        bookDao = new BookDAO();
    }

    @Test
    public void addBookStaticBookTest() throws Exception {
        List<String> genreList = new ArrayList<String>();
        genreList.add("Classical");
        genreList.add("Rock");
        Book book = new Book();
        book.setAuthorName("Meseeks");
        book.setTitle("A different book");
        book.setGenre(genreList);
        book.setIsbn("1234567890");
        book.setRating(5);
        book.setFk_id_author(3);
        //
        Author author = new Author("Ben", "Jamin", 4);
        book.setBookAuthor(author);
        //
        bookDao.deleteBook(book);
        int book_id = bookDao.addBook(book);
        assertTrue("Validation failure", book_id >= 0);
        assertTrue("Book was not added to the database", book_id != 0);
    }



    @Test
    public void getBookInDatabase() throws Exception {
        List<String> genreList = new ArrayList<String>();
        genreList.add("Classical");
        genreList.add("Rock");
        Book book = new Book();
        book.setAuthorName("Meseeks");
        book.setTitle("Differet student book");
        book.setGenre(genreList);
        book.setIsbn("1234567890");
        book.setRating(5);
        book.setFk_id_author(3);

        //
        Author author = new Author("Ben", "Jamin", 4);
        book.setBookAuthor(author);
        //
        int book_id = bookDao.addBook(book);
        Book inDatabase = bookDao.getBook(book_id);



        bookDao.deleteBook(book);
        assertTrue("Get book failure", inDatabase != null);
        //assertTrue(book.getAuthorName().equals("Kansas"));
    }

    /*
    @Test
    public void updateBookAlreadyInDatabase() {
        Book book = bookDao.getBook(1);

        assertTrue("Get fail for book update", book != null);

        book.setRating(3);
        book.setTitle("Rick and morty");

        boolean passed = bookDao.updateBook(book);
        assertTrue(passed);
    }
    */

    @Test
    public void deleteBookTest() {
        ArrayList<String> genres = new ArrayList<String>();
        genres.add("Contemporary");
        genres.add("Hello");
        Book book = new Book();
        book.setAuthorName("<NAME>");
        book.setTitle("To be nuked");
        book.setRating(5);
        book.setIsbn("1234567890");
        book.setGenre(genres);
        book.setFk_id_author(3);
        //
        Author author = new Author("Ben", "Jamin", 4);
        book.setBookAuthor(author);
        //
        int book_id = bookDao.addBook(book);
        assertTrue("Fail to add in delete Test", book_id > 0);


        int other_id = bookDao.deleteBook(book);

        assertTrue("Ids do not match in delete",other_id == book_id);
    }

    /*
    @Test
    public void deleteBookById() {
        ArrayList<String> genres = new ArrayList<String>();
        genres.add("comedy");
        genres.add("relationships");
        Book book = new Book();
        book.setAuthorName("<NAME>");
        book.setTitle("Deleted 2");
        book.setRating(5);
        book.setIsbn(1234567890);
        book.setGenre(genres);
        book.setFk_id_author(3);
        int book_id = bookDao.addBook(book);
        assertTrue("Fail to add in delete Test", book_id > 0);

        int delete_id = bookDao.deleteBook(book_id);
        assertTrue( delete_id > 0);
        assertTrue(delete_id == book_id);
    }
    */
    @Test
    public void safeAddBookTest() {
        ArrayList<String> genres = new ArrayList<String>();
        genres.add("Dark");
        genres.add("Action");
        Book book = new Book();
        book.setAuthorName("Morty");
        book.setTitle("Adventures of Rick and morty season 99");
        book.setRating(5);
        book.setIsbn("1234567891");
        book.setGenre(genres);
        book.setFk_id_author(3);
        //
        Author author = new Author("Ben", "Jamin", 4);
        book.setBookAuthor(author);
        //
        int book_id = bookDao.safeAddBook(book);
        assertTrue("Error occurred\n", book_id >= 0);
        assertTrue("Addition failure\n", book_id > 0);

        Book inDatabase = bookDao.getBook(book_id);

        assertTrue("Id was never set", inDatabase.getId() != 0);

        int another_id = bookDao.safeAddBook(inDatabase);
        assertTrue("Add went through\n", another_id == 0);

        bookDao.safeDeleteBook(book);
    }

    @Test
    public void safeDeleteBookTest() {
        ArrayList<String> genres = new ArrayList<String>();
        genres.add("Dark");
        genres.add("Action");
        Book book = new Book();
        book.setAuthorName("Morty");
        book.setTitle("Guiness book of world records");
        book.setRating(5);
        book.setIsbn("1234567891");
        book.setGenre(genres);
        book.setFk_id_author(3);

        //
        Author author = new Author("Ben", "Jamin", 4);
        book.setBookAuthor(author);
        //
        int book_id = bookDao.safeAddBook(book);
        assertTrue("Error occurred\n", book_id >= 0);
        assertTrue("Addition failure\n", book_id > 0);

        int delete_id = bookDao.safeDeleteBook(book);
        assertTrue("Delete failed\n", delete_id > 0);
        assertTrue("Ids are not the same", delete_id == book_id);
    }

    @Test
    public void safeUpdateBookTest() {
        ArrayList<String> genres = new ArrayList<String>();
        genres.add("Dark");
        genres.add("Comedy");
        Book book = new Book();
        book.setAuthorName("Morty");
        book.setTitle("Adventures of Rick and Morty");
        book.setRating(5);
        book.setIsbn("1234567891");
        book.setGenre(genres);
        book.setFk_id_author(3);

        //
        Author author = new Author("Ben", "Jamin", 4);
        book.setBookAuthor(author);
        //

        int book_id = bookDao.safeAddBook(book);

        book.setIsbn("1111111111");

        boolean passed = bookDao.safeUpdateBook(book);
        assertTrue("Update Failed", passed);

        bookDao.safeDeleteBook(book);
    }
}
{'fraction_non_alphanumeric': 0.13075201061271868, 'fraction_numerical': 0.018903905148826797, 'mean_word_length': 2.446285714285714, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3113953', 'n_tokens_mistral': 3805, 'n_tokens_neox': 3646, 'n_words': 750}