Question: I am trying to implement some assert methods into a test method but I am not sure on how to do that. We are currently

I am trying to implement some assert methods into a test method but I am not sure on how to do that. We are currently in the subject of Junit testing. This method has to pass the test with no failures or errors. Thank you!

here is my current code.

public void testCreateIterator() { System.out.println("createIterator"); StudentCollectionSpec instance = StudentCollection.createStudentCollection(); Iterator expResult = null; StudentSpec student1 = Student.create("1234567","FirstName","M","LastName","CSC"); StudentSpec student2 = Student.create("2345678","FirstName","M","LastName","CSC"); StudentSpec student3 = Student.create("3456789","FirstName","M","LastName","CSC"); StudentSpec student4 = Student.create("4567892","FirstName","M","LastName","CSC"); instance.addStudent(student1); instance.addStudent(student2); instance.addStudent(student3); instance.addStudent(student4); Iterator result = instance.createIterator(); assertNotEquals(expResult, result);

---------------------------------------

Here is what it needs

Rule / requirement being tested Set up work required test value | Expected result(must be verified via appropriate Junit assert..() invocations)

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!