Question
i need help to create java and junit code with the code at the bottom. I was unaware you couldn't see the previous post. thankz
i need help to create java and junit code with the code at the bottom. I was unaware you couldn't see the previous post. thankz
Unit being tested | Rule / requirement being tested | Setup work required | Test value | Expected result(s) (all must be verified via appropriate JUnit assert() invocations |
---|---|---|---|---|
createStudentCollection() | none default-sized collection | none | n/a | returned handle non-null; getCapacity() == DEFAULT COLLECTION_CAPACITY; isEmpty() == TRUE; isFull() == FALSE; getStudentCount() == 0; getRemainingSpaces() == DEFAULT COLLECTION_CAPACITY |
createStudentCollection(int) | collection size > 0 | none | -1 | StudentCollectionException thrown |
" | " | 0 | StudentCollectionException thrown | |
" | " | 1 | non-null handle returned; getCapacity() == 1; isEmpty() == TRUE; isFull() == FALSE; getStudentCount() == 0; getRemainingSpaces() ==1 | |
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 | |||
addStudent() | inserts a student object into the collection | create collection of size 4; create student1 with a known SID value (SID1) (note replace "SID1" with a valid value during actual testing) | student1 instance | no exception thrown; getStudentCount() == 1; isEmpty() == false; isFull== false; getSpacesRemaining() == 3; retrieveStudentBySID(student1.getSID()) retrieves non-null handle and handle.getSID() == student1.getSID() |
" | using same collection, create student2 with SID2 (different from SID1) | student2 instance | no exception thrown; getStudentCount() == 2; isEmpty() == false; isFull() == false; getSpacesRemaining() == 2; retrieveStudentBySID(student2.getSID()) retrieves non-null handle and handle.getSID() == student2.getSID(); retrieveStudentBySID(student2.getSID()) retrieves non-null handle and handle.getSID() == student1.getSID() ("paranoia check") | |
" | using same collection, create student3 with SID3 (different from SID1 and SID2) | student SID3 instance | no exception thrown; getStudentCount() == 3; isEmpty() == false; isFull() == true; getSpacesRemaining() == 1; retrieveStudentBySID(student3.getSID()) retrieves non-null handle and handle.getSID() == student3.getSID() | |
" | using same collection, create student4 with SID4 (different from SID1, SID2, SID3) | student SID4 instance | no exception thrown; getStudentCount() == 4; isEmpty() == false; isFull() == true; getSpacesRemaining() == 0; retrieveStudentBySID(student4.getSID()) retrieves non-null handle and handle.getSID() == student4.getSID() | |
" | using same collection, create student5 with SID5 (different from SID1, SID2, SID3, SID4) | student SID5 instance | exception is thrown; getStudentCount() == 4; isEmpty() == false; isFull() == true; getSpacesRemaining() == 0; retrieveStudentBySID(student5.getSID()) retrieves null handle | |
" | create collection of size 3, create student1 with a known SID value (SID1), add student1 to collection | null | exception is thrown; getStudentCount() == 1; isEmpty() == false; isFull== false; getSpacesRemaining() == 2; retrieveStudentBySID(student1.getSID()) retrieves non-null handle and handle.getSID() == student1.getSID() | |
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 | |
createIterator() | creates an Iterator object that allows the entire contents of the collection to be retrieved, one element at a time; Iterator.remove() is not supported | create four student objects, SIDs in the sequence first, smallest, largest, last; create a reference collection of size 4 and insert all four students; create a checklist collection (array,ArrayList,List,whatever) of size 4 and insert all four students; invoke createIterator via the REFERENCE collection | n/a | returned handle non-null; loop through the iterator object: student = handle.next(); increment counter; remove student from the checklist collection (if student not removed, test fails) end loop; referenceCollection.getStudentCount() == counter; checklistCollection.isEmpty() == TRUE; handle.hasNext() == false; handle.next() throws NoSuchElementException |
" | create collection of size four | n/a | returned handle non-null; handle.hasNext() == false handle.next() throws NoSuchElementException | |
" | create collection of size 5; create three student objects S1, S2, S3, with unique SIDs in ascending non-consecutive sequence, adding each to the collection | n/a | returned handle non-null; handle.remove() throws UnsupportedOperationException | |
" | create collection of size 5 | n/a | returned handle non-null; handle.remove() throws UnsupportedOperationException | |
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(); | |
fileExists() | determine if a file name exists as a physical file | none | null | throws IllegalArgumentException |
(empty string) | throws IllegalArgumentException | |||
Create a collection of size 2; create two students and add to collection; write collection to disk with a known name | known name | returns TRUE | ||
none | filename known to NOT exist | Return FALSE | ||
Here are the test classes in which need to be created
package studentcollection; import java.util.Iterator; import java.util.NoSuchElementException; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import static org.junit.Assert.*; import student.Student; import studentspec.StudentSpec; import studentcollection.StudentCollectionSpec.StudentCollectionException; public class StudentCollectionTest { public StudentCollectionTest() { } @BeforeClass public static void setUpClass() { } @AfterClass public static void tearDownClass() { } @Before public void setUp() { } @After public void tearDown() { } /** * Test of getCapacity method, of class StudentCollection. */ @Test public void testGetCapacity() { System.out.println("getCapacity"); } /** * Test of reset method, of class StudentCollection. */ @Test public void testReset() { } /** * Test of isFull method, of class StudentCollection. */ @Test public void testIsFull() { System.out.println("isFull"); } /** * Test of isEmpty method, of class StudentCollection. */ @Test public void testIsEmpty() { System.out.println("isEmpty"); } /** * Test of getStudentCount method, of class StudentCollection. */ @Test public void testGetStudentCount() { System.out.println("getStudentCount"); } /** * Test of addStudent method, of class StudentCollection. */ @Test public void testAddStudent() { System.out.println("addStudent"); } /** * Test of retrieveStudentBySID method, of class StudentCollection. */ @Test public void testRetrieveStudentBySID() { System.out.println("retrieveStudentBySID"); } /** * Test of removeStudentBySID method, of class StudentCollection. */ @Test public void testRemoveStudentBySID() { System.out.println("removeStudentBySID"); } /** * Test of toString method, of class StudentCollection. */ @Test public void testToString() { System.out.println("toString"); } /** * Test of createIterator method, of class StudentCollection. */ @Test public void testCreateIterator() { System.out.println("createIterator"); } /** * Test of getSpacesRemaining method, of class StudentCollection. */ @Test public void testGetSpacesRemaining() { System.out.println("getSpacesRemaining"); } /** * Test of writeCollectionToDisk method, of class StudentCollection. */ @Test public void testWriteCollectionToDisk() { System.out.println("writeCollectionToDisk"); } /** * Test of fileExists method, of class StudentCollection. */ @Test public void testFileExists() { System.out.println("fileExists"); } /** * Test of retrieveCollectionFromDisk method, of class StudentCollection. */ @Test public void testRetrieveCollectionFromDisk() { System.out.println("retrieveCollectionFromDisk"); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started