Java Reference
In-Depth Information
cases. It will be important to check not only ratings in the middle of this range, but also the
maximum and minimum possible rating.
In order to conduct tests along these lines, create a SalesItem object on the object bench and
try the following as initial tests of the comment functionality. If you do these tests carefully,
they should uncover two errors in our code.
Exercise 7.1 Add several comments to the sales item while keeping an eye on the inspector
for the comments list. Make sure the list behaves as expected (that is, its size should increase).
You may also like to inspect the elementData field of the ArrayList object.
Exercise 7.2 Check that the showInfo method correctly prints the item information,
including the comments. Try this both for items with and without comments.
Exercise 7.3 Check that the getNumberOfComments method works as expected.
Exercise 7.4 Now check that duplicate authors are correctly handled—i.e., that further
comments by the same author are rejected. When trying to add a comment with an author
name for whom a comment already exists, the addComment method should return false .
Check also that the comment was not added to the list.
Exercise 7.5 Perform boundary checking on the rating value. That is, create comments not
only with medium ratings, but also with top and bottom ratings. Does this work correctly?
Exercise 7.6 Good boundary testing also involves testing values that lie just beyond the valid
range of data. Test 0 and 6 as rating values. In both cases, the comment should be rejected
( addComment should return false , and the comment should not be added to the comment list).
Exercise 7.7 Test the upvoteComment and downvoteComment methods. Make sure
that the vote balance is correctly counted.
Exercise 7.8 Use the upvoteComment and downvoteComment methods to mark some
comments as more or less helpful. Then test the findMostHelpfulComment method.
This method should return the comment that was voted most helpful. You will notice that the
method returns an object reference. You can use the Inspect function in the method result
dialog to check whether the correct comment was returned. Of course, you will need to know
which is the correct comment in order to check whether you get the right result!
Exercise 7.9 Do boundary testing of the findMostHelpfulComment method. That is,
call this method when the comments list is empty (no comments have been added). Does this
work as expected?
Exercise 7.10 The tests in the exercises above should have uncovered two bugs in our
code. Fix them. After fixing these errors, is it safe to assume that all previous tests will still work
as before? Section 7.4 will discuss some of the testing issues that arise when software is cor-
rected or enhanced.
Search WWH ::

Custom Search