Question: Hello I need help with this assignment. I need to come up with four black box test methods for describeBooksBy() method of the Library.java class

Hello I need help with this assignment. I need to come up with four black box test methods for describeBooksBy() method of the Library.java class

Thank you!!

The requirements of this assignment are as follows:

  • The given NetBeans Java project contains two classes (Book.java and Library.java).
  • The Library.java class contains a method (describeBooksBy()). It is the method that you will black-box test.

You will use the NetBeans JUnit framework to develop four black-box test methods for the describeBooksBy() method of the Library.java class.

package bookstore;

import javax.annotation.CheckForNull;

import javax.annotation.Nonnull;

public class Book {

private @Nonnull String author;

private @Nonnull String title;

private @CheckForNull String subtitle;

public @Nonnull String getAuthor() {

return author;

}

public @Nonnull String getSubtitle() {

return subtitle;

}

public @Nonnull String getTitle() {

return title;

}

}

package bookstore;

import java.io.Serializable;

import java.util.ArrayList;

import java.util.Comparator;

import java.util.List;

import java.util.Set;

import java.util.TreeSet;

import javax.annotation.Nonnull;

public class Library {

private final Set books = new TreeSet(new ComparatorImpl());

public void addBook(@Nonnull Book newBook) {

if (newBook == null) {

//@Nonnull was not present in the first version, protect against old

//clients which may not know about the constraint

return;

}

books.add(newBook);

}

public @Nonnull Iterable describeBooksBy(@Nonnull String author) {

List result = new ArrayList();

for (Book b : books) {

if (!author.equals(b.getAuthor())) continue;

result.add(String.format("%s: %d", b.getAuthor(), b.getTitle()));

}

return result;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!