Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JUNIT TESTING You will find the code for this project, including the Java source file for the class Magazine here or, if you are logged

JUNIT TESTING

You will find the code for this project, including the Java source file for the class Magazine here or, if you are logged in to one of the CS Linux machines, at ~zeil/Assignments/cs350/unittest-magazine/. Note that what you are being provided is a skeleton for the Magazine class that defines the interface for that ADT, but does not implement it. This is consistent with the practice of Test Driven Development (TDD) in which you would develop your tests before writing the code to be tested. Because none of the member functions of Magazine have been implemented yet, your tests should probably all fail when run against this skeleton. Your challenge, as in any TDD project, is to design your tests so that a complete & correct implementation of Magazine will pass.

Prepare your JUnit4 test as a class edu.odu.cs.cs350.TestMagazine.

MAGAZINE.JAVA  package edu.odu.cs.cs350; import java.time.LocalDate; import java.util.Set; /** * A magazine containing a collection of articles, organized by (starting) page number. * * * @author zeil * */ public class Magazine implements Cloneable { /** * Create a "blank" magazine with empty strings for title, the current * date for the publication date, * and an empty (zero-length) list of articles. */ public Magazine() { } /** * Create a new magazine. * @param title title of the magazine * @param publDate publication date of the magazine. */ public Magazine(String title, LocalDate pubDate) { } /** * Get the title of this magazine. * @return the title */ public String getTitle() { return ""; } /** * Set the title of this magazine. * @param title the title to set */ public void setTitle(String title) { } /** * Get the publication date of this magazine. * @return the date */ public LocalDate getPublicationDate() { return null; } /** * Set the publication date of this magazine. * @param pubDate the publication date to set */ public void setPublicationDate(LocalDate pubDate) { } /** * How many articles does this magazine have? * @return number of articles */ public int numArticles() { return 0; } /** * Add an article to the magazine at an indicated starting page. * * If an article is already at that page, replaces the existing one. * * @param startingPage first page of the article * @param article author to be added */ public void addArticle(int startingPage, Article article) { } /** * Get the article previously placed at a given starting page. * * @param startingAtPage a page number in the magazine * @return the article starting at that page, or null if no article * has been put there. */ public Article getArticle (int startingAtPage) { return null; } /** * Render the magazine as a string in a format guaranteed to * contain all fields. */ public String toString() { return ""; } // Comparison and hashing /** * Compares two magazines for equality. They are considered equal if * all functions on them return equal results.. * * @param obj object to be compared for equality with this magazine * @return true if the specified object is equal to this one */ public boolean equals(Object obj) { return true; } /** * Returns the hash code value for this object. * * @return the hash code value for this magazine */ public int hashCode() { return 0; } /** * Return a (deep) copy of this object. */ @Override public Object clone() { return this; } /** * Provide access to the table of contents of * this magazine. e.g., * Magazine magazine = new Magazine(...); * ... * for (Integer page: magazine,startingPages()) { * Article art = magazine.getArticle(page); * doSomethingWith (page, art); * } * * @return iterator over the starting page numbers. Numbers * are returned in ascending order. */ public Set startingPages() { return null; } } 
 ARTICLE.JAVA /** */ package edu.odu.cs.cs350; /** * An article within a magazine. An article has a title and an author name. * * @author zeil * */ public class Article implements Cloneable { /** * The title of this article. */ private String title; /** * The author of this article. */ private String author; /** * Create an article. * @param title the title of the article * @param author the name of the author */ public Article (String title, String author) { this.title = title; this.author = author; } /** * Compare two articles for equality. * * @param obj another author * @return true ff they have the same name */ public boolean equals(Object obj) { if (obj instanceof Article) { Article au = (Article) obj; return author.equals(au.author) && title.equals(au.title); } else { return false; } } /** * Return a description of the article. * givenName surname */ public String toString() { return '"' + title + '"' + " by " + author; } /** * Hash function for articles. */ public int hashCode() { return title.hashCode() * 13 + author.hashCode(); } /** * Return the surname of this author * @return the surname */ public String getTitle() { return title; } /** * Return the given name of this author * @return the given name */ public String getGivenName() { return author; } public Object clone() { return new Article(title, author); } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions