Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me fill in these jUnit Test cases and explain them too please? Unit being tested Rule / requirement being tested Setup work

Can someone help me fill in these jUnit Test cases and explain them too please?

image text in transcribedimage text in transcribed

Unit being tested

Rule / requirement being tested

Setup work required

Test value

Expected result(s) (all must be verified via appropriate JUnit assert() invocations

getCapacity()

returns storage capacity

getSpacesRemaining()

returns number of available storage spaces

reset()

sets collection to an empty state

isFull()

determines if there is any remaining storage capacity

isEmpty()

determines if the collection is empty

getStudentCount()

returns number of elements in collection

retrieveStudentBySID()

retrieves a student from collection based on supplied SID value

removeStudentBySID()

removes a student from collection based on supplied SID value

toString()

"stringifies" each collection element and concatenates the results into a single string

create a collection of size 4

n/a

returned string == "empty collection"

"

create a collection of size 4, create two student objects S1 and S2, adding each to the collection

n/a

returned string == S1 + "&" + S2

writeCollectionToDisk()

write contents of collection to a specified file such that the contents can be read back at a later date

NOTE: it is not possible to verify writeCollectionToDisk() without invoking readCollectionFromDisk(), because without reading back what was written, there is no empirical evidence that what was written was written correctly. Similarly, readCollectionFromDisk() cannot be verified without first invoking writeCollectionToDisk(), because one must first write something to disk before it can be read.

filename cannot be null

none

null

throws IllegalArgumentException

filename cannot be an empty string

none

(empty string)

throws IllegalArgumentException

write contents of collection to a specified file such that the contents can be read back at a later date

create two students with different SIDs; create a reference collection (size 5) and a checklist collection (size 5); store the both students into both collections;

invoke writeCollectionToDisk via the REFERENCE collection

valid filename

no exception thrown;

fileExists(filename) == TRUE;

create a retrieved collection (size 10);

invoke retrieveCollectionFromDisk() via the

RETRIEVED collection, no thrown exception;

create an iterator via the RETRIEVED collection;

loop through the iterator object:

student = handle.next();

remove student from the checklist collection

(if student is removed, increment count)

end loop;

referenceCollection.getStudentCount() ==

retrievedCollection.getStudentCount();

checkListCollection.getStudentCount() == 0;

count = retrievedCollection.getStudentCount();

readCollectionFromDisk()

read contents of a collection that was previously written to disk

NOTE: it is not possible to verify readCollectionFromDis() without invoking writeCollectionToDisk(), because one must first write something to disk before it can be read. Similarly, readCollectionFromDisk() cannot be verified without first invoking writeCollectionToDisk(), because without reading back what was written there is no empirical evidence that what was written was written correctly and retrieved correctly.

filename cannot be null

none

null

throws IllegalArgumentException

filename cannot be an empty string

none

(empty string)

throws IllegalArgumentException

filename must exist

none

valid filename that does not exist

throws StudentCollectionException

filename exists but does not contain serialized content

create a file with non-serialized content (e.g. .docx, .pdf, .jpg)

valid filename

throws StudentCollectionException

filename exists but contains serialized content of a different class

Create a file with serialized content from any class other than StudentCollection

valid filename

throws StudentCollectionException

filename exists, contains serialized content of this class, but SVUID is different

Create a file with serialized content from a StudentCollection class version with a SVUID that differs from the current SVUID

valid filename

throws StudentCollectionException

write contents of collection to a specified file such that the contents can be read back at a later date

create two students with different SIDs; create a reference collection (size 5) and a checklist collection (size 5); store the both students into both collections;

invoke writeCollectionToDisk via the REFERENCE collection

valid filename

no exception thrown;

fileExists(filename) == TRUE;

create a retrieved collection (size 10);

invoke retrieveCollectionFromDisk() via the

RETRIEVED collection, no thrown exception;

create an iterator via the RETRIEVED collection;

loop through the iterator object:

student = handle.next();

remove student from the checklist collection

(if student is removed, increment count)

end loop;

referenceCollection.getStudentCount() ==

retrievedCollection.getStudentCount();

checkListCollection.getStudentCount() == 0;

count = retrievedCollection.getStudentCount();

void reset ) empty the collection ("throw away" the current contents) void retrieveCollectionFromDisk(java.lang.String sourcerileName) reads the contents of the supplied file into a StudentCollectionSpec-type object; the file must have been previously written via Serializable method(s). retrieveStudentBySID(java.lang.String searchKey) find a student object with an SID that matches the supplied SID; the Student is NOT removed from the collection StudentSpec java.lang.String toString () return the contents of the collection, represented as a single String void writecollectionToDisk (java.lang.String targetFileName) writes the contents of this StudentCollectionSpec object to the supplied file. Methods inherited from class java.lang.Object clone, equals, finalize, getclass, hashCode, notify, notifyAll, wait, wait, wait Methods inherited from interface studentcollection.StudentCollectionSpec fileExists Static Methods Instance Methods Concrete Methods All Methods Modifier and Type void Method and Description addStudent (StudentSpec anElement) add a student to the collection java.util.Iterator

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

Step: 3

blur-text-image

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

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions