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
True or False: Given the sets F and G with F being an element of G, is it always ture that P(F) is an element of P(G)? (P(F) and P(G) mean power sets). Why?
Can you please simplify (the domain is not empty) ∃xF (x) → ¬∃x(F (x) ∨ ¬G(x)). Fo
HistogramUse par(mfrow=c(2,2)) and output 4 plots with different argument settings.
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
CMPTR
Computer Science
ISBN:9781337681872
Author:PINARD
Publisher:Cengage
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning