Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Created test files for book, patron, library and an exception #264

Merged
merged 8 commits into from Mar 22, 2024
@@ -0,0 +1,62 @@
package com.codedifferently.lesson9.natayaprice;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

public class BookTest {

@Test
public void testGetTitle() {
Book book = new Book("Children of Blood and Bone", "781250170972", "Tomi Adeyemi", 544);
assertEquals("Children of Blood and Bone", book.getTitle());
}

@Test
public void testGetISBN() {
Book book =
new Book(
"The Sisters Grimm:The Fairy-Tale Detectives", "9780810970571", "Michael Buckley", 176);
assertEquals("9780810970571", book.getISBN());
}

@Test
public void testGetAuthors() {
Book book = new Book("A Light in the Attic", "9780060256739", "Shel Silverstein", 176);
assertEquals("Shel Silverstein", book.getAuthors());
}

@Test
public void testGetTotalPages() {
Book book =
new Book(
"Junie B. Jones and the Mushy Gushy Valentine", "9780375800408", "Barbara Park", 80);
assertEquals(80, book.getTotalPages());
}

@Test
public void testGetCheckedOut() {
Book book =
new Book(
"Thirst: Human Urges, Fatal Consequences", "9780307237060", "Michael Farquhar", 384);
assertFalse(book.getCheckedOut());
}

@Test
public void testIsCheckedOut() {
Book book =
new Book("Women Who Run with the Wolves", "9780345409874", "Clarissa Pinkola Estés", 560);
book.checkOut();
assertTrue(book.getCheckedOut());
}

@Test
public void testGetCheckedIn() {
Book book = new Book("Beloved", "9781400033416", "Toni Morrison", 324);
book.checkIn();
book.checkOut();
assertFalse(book.getCheckedOut());
}
}
@@ -0,0 +1,8 @@
package com.codedifferently.lesson9.natayaprice;

public class BooksCkeckedOutException extends RuntimeException{
anthonydmays marked this conversation as resolved.
Show resolved Hide resolved
public BooksCkeckedOutException(String message){
super (message);
}

}
@@ -0,0 +1,32 @@
package com.codedifferently.lesson9.natayaprice;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

public class LibraryTest {

@Test
void testLibraryConstruction() {
Library library = new Library();
}

@Test
void testAddBook() {
Book book = new Book("781250170972", "Children of Blood and Bone", "Tomi Adeyemi",544);
Library.addBook(book);
assertTrue(yourLibrary.hasBook("781250170972"));
Book retrievedBook = yourLibrary.getBook("781250170972");
assertEquals(book, retrievedBook);
}
@Test
void testRemoveBook() {
Book book = new Book("9780810970571", "The Sisters Grimm:The Fairy-Tale Detectives", "Michael Buckley",176);
yourLibrary.addBook(book);
assertTrue(yourLibrary.hasBook("9780810970571"));
yourLibrary.removeBook("9780810970571");
assertFalse(yourLibrary.hasBook("9780810970571"));
}
}
@@ -0,0 +1,37 @@
package com.codedifferently.lesson9.natayaprice;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;

public class PatronTest {

@Test
void testPatronConstruction() {
Patron patron = new Patron("Jane Smith");
}

@Test
public void testPatronBooksCheckedOutMap() {

Map<String, Integer> patronBooksCheckedOutMap = new HashMap<>();
patronBooksCheckedOutMap.put("John Doe", 5);
patronBooksCheckedOutMap.put("Jane Smith", 3);
patronBooksCheckedOutMap.put("Alice Johnson", 0);

assertEquals(5, patronBooksCheckedOutMap.get("John Doe").intValue());
assertEquals(3, patronBooksCheckedOutMap.get("Jane Smith").intValue());
assertEquals(0, patronBooksCheckedOutMap.get("Alice Johnson").intValue());

assertEquals(3, patronBooksCheckedOutMap.size());

patronBooksCheckedOutMap.put("John Doe", 8);
assertEquals(8, patronBooksCheckedOutMap.get("John Doe").intValue());

assertNull(patronBooksCheckedOutMap.get("Nonexistent Patron"));
}

}