Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
6th Edition
ISBN: 9780134477367
Author: David J. Barnes, Michael Kolling
Publisher: PEARSON
Question
Book Icon
Chapter 9, Problem 20E
Program Plan Intro

Program plan:

The variables used in the program are given below:

  1. item: SalesItem - an instance of the SalesItem class, which represents a sales item being sold on a website or in a store.
  2. comment1: Comment - an instance of the Comment class, which represents a comment left by a user about the sales item.
  3. comment2: Comment - another instance of the Comment class, representing a second comment about the sales item.
  4. comment3: Comment - a third instance of the Comment class, representing a third comment about the sales item.

The methods used in the program are as follows:

  1. addComment(comment: Comment): void - a method of the SalesItem class that adds a new Comment object to the item's list of comments.
  2. getComments(): List - a method of the SalesItem class that returns a list of all Comment objects that have been added to the item.
  3. assertEquals(expected: int, actual: int): void - a method of the org.junit.Assert class that checks if two integer values are equal, and throws an assertion error if they are not.
  4. assertTrue(condition: boolean): void - a method of the org.junit.Assert class that checks if a given boolean condition is true, and throws an assertion error if it is not.
  5. testAddNullComment(): a unit test method that tests the behavior of the SalesItem class when attempting to add a null comment to an item. Expects an IllegalArgumentException to be thrown.

Program Description:

The given code is a unit test written in JUnit framework for the addComment() method of the SalesItem class. It creates a new SalesItem object with a name and description and then adds three comments to it using addComment() method. The test then checks that the comments were added successfully by verifying that the size of the SalesItem's comments list is 3 and that each of the three comments is contained in the list. This is an important test to ensure that comments can be successfully added to a SalesItem object, which is a critical feature of the class for user interaction and feedback.

Blurred answer
Students have asked these similar questions
It implies testing in a "BLACK Box." What different variants exist on this theme?
Write out what you think the outer wrappers of the Student and LabClass classes might look like; do not worry about the inner part.
Risking telling the obvious, you will need to make all necessary modifications to the files, including adapting the documentation and removing any parts that are irrelevant. I suggest that you pattern after the way the suggested book authors document a template class (such as for bag4) when adapting the documentation.
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education