Question
Create a Junit Test file for the following class IN JAVA. Use assert methods for Junit. Design your tests so that a complete & correct
Create a Junit Test file for the following class IN JAVA. Use assert methods for Junit. Design your tests so that a complete & correct implementation of Book would pass and skeleton implementation will fail. I have provided the skeleton code of Book.java and Author.java, Create a Junit Test file, TestBook.java.
Book.java
package edu.odu.cs.cs350;
import java.util.Iterator;
/**
* A book object as it might be recorded in a publisher's catalog or a library.
*
*
* This is not a capture of the contents of the book, but of the metadata that
* describes the book: authors, title, etc.
*
* @author zeil
*
*/
public class Book implements Cloneable, Iterable
/**
* Create a "blank" book with empty strings for title, publisher, ISBN
* and an empty (zero-length) list of authors.
*/
public Book() {
// TODO
}
/**
* Create a new book.
* @param title title of the book
* @param publisher publisher of the book.
* @param isbn ISBN identifier for the book.
* @param authors list of authors for this book.
*/
public Book(String title, String publisher, String isbn, Author[] authors) {
// TODO
}
/**
* Get the title of this book.
* @return the title
*/
public String getTitle() {
// TODO
return "";
}
/**
* Set the title of this book.
* @param title the title to set
*/
public void setTitle(String title) {
// TODO
}
/**
* Get the ISBN of this book.
* @return the ISBN
*/
public String getISBN() {
// TODO
return "";
}
/**
* Set the ISBN of this book.
* @param isbn the isbn to set
*/
public void setISBN(String isbn) {
// TODO
}
/**
* Get the publisher of this book.
* @return the publisher
*/
public String getPublisher() {
// TODO
return "";
}
/**
* Set the publisher of this book.
* @param publisher the publisher to set
*/
public void setPublisher(String publisher) {
// TODO
}
/**
* How many authors does this book have?
* @return number of authors
*/
public int numAuthors() {
// TODO
return -1;
}
/**
* Add an author to the end of the books's list (if that author is
* not already in there).
*
* @param au author to be added
*/
public void addAuthor(Author au) {
// TODO
}
/**
* Render the book as a string in a format guaranteed to
* contain all fields.
*/
public String toString() {
// TODO
return "";
}
// Comparison and hashing
/**
* Compares two books for equality. They are considered equal if
* they have the same ISBN.
*
* @param obj object to be compared for equality with this duration
* @return true if the specified object is equal to this one
*/
public boolean equals(Object obj) {
// TODO
return false;
}
/**
* Returns the hash code value for this object.
*
* @return the hash code value for this book
*/
public int hashCode() {
// TODO
return 0;
}
/**
* Return a (deep) copy of this object.
*/
@Override
public Object clone() {
// TODO
return null;
}
/**
* Provide access to the list of authors. e.g.,
* Book book = new Book(...);
* for (Author au: book) {
* doSomethingWithAuthor (au);
* }
*
* @return iterator over the authors.
*/
public Iterator
// TODO
return null;
}
}
Author.java
/**
*
*/
package edu.odu.cs.cs350;
/**
* An author of a book. Currently, this contains only the author's name.
*
* @author zeil
*
*/
public class Author implements Cloneable, Comparable
/**
* The surname ("family name") of this author.
*/
private String surname;
/**
* The given name ("personal name" or "first name") of the author.
*/
private String givenName;
/**
* Create an author.
* @param givenName the personal name of the author
* @param surname the family name of the author
*/
public Author (String givenName, String surname) {
this.givenName = givenName;
this.surname = surname;
}
/**
* Compare two authors for equality.
*
* @param obj another author
* @return true ff they have the same name
*/
public boolean equals(Object obj) {
if (obj instanceof Author) {
Author au = (Author) obj;
return givenName.equals(au.givenName)
&& surname.equals(au.surname);
} else {
return false;
}
}
/**
* Get the name of the author in a form suitable for sorting.
* surname, givenName
* @return sortable name of the author
*/
public String getSortingName() {
return surname + ", " + givenName;
}
/**
* Return the author's name in conventional form.
* givenName surname
*/
public String toString() {
return givenName + " " + surname;
}
/**
* Return the surname of this author
* @return the surname
*/
public String getSurname() {
return surname;
}
/**
* Return the given name of this author
* @return the given name
*/
public String getGivenName() {
return givenName;
}
/**
* Compare this author to another, returning a negative
* value if this author should follow the other in a sorted list,
* zero if they are equal, and a positive value if this author should
* precede the other in a sorted list.
*
* @param au the other author to be compared against.
* @return number whose sign indicates the comparison result
*/
public int compareTo(Author au) {
return getSortingName().compareTo(au.getSortingName());
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started