Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 0 additions & 51 deletions src/main/java/object/example/Person.java

This file was deleted.

49 changes: 49 additions & 0 deletions src/main/java/object/example/derwinbell/Library.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package object.example.derwinbell;

public class Library {
private String title;
private String author;
private int pages;
private boolean checkedOut;
private int dueDays;

public Library(String title, String author, int pages, boolean checkedOut, int dueDays) {
if (pages <= 0) {
throw new IllegalArgumentException("Pages must be greater than 0");
}
this.title = title;
this.author = author;
this.pages = pages;
this.checkedOut = checkedOut;
this.dueDays = dueDays;
}

public String getTitle() {
return title;
}

public String getAuthor() {
return author;
}

public int getPages() {
return pages;
}

public boolean isCheckedOut() {
return checkedOut;
}

public int getDueDays() {
return dueDays;
}
public void checkOut(){
checkedOut = true;
}

public void returnBook(){
checkedOut = false;
}


}
99 changes: 0 additions & 99 deletions src/test/java/object/example/PersonTest.java

This file was deleted.

42 changes: 42 additions & 0 deletions src/test/java/object/example/derwinbell/LibraryTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package object.example.derwinbell;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

class LibraryTest {
@Test
void constructorWorks(){
Library book = new Library("Java", "Smith", 300, false, 14);

assertEquals("Java", book.getTitle());
assertEquals("Smith", book.getAuthor());
}


@Test
void checkOutWorks(){

Library book = new Library("Java", "Smith", 300, false, 14);

book.checkOut();

assertTrue(book.isCheckedOut());
}

@Test
void invalidPagesThrows(){

assertThrows(IllegalArgumentException.class, () -> {
new Library("Java", "Smith", -1, false, 14);
});
}

@Test
void findPagesAndDueDates(){
Library book = new Library("Java", "Smith", 300, false, 14);

assertEquals(14, book.getDueDays());
assertEquals(300, book.getPages());
}

}