Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Professional SQL Server 2000 Database Design

Authors: Louis Davidson

1st Edition

1861004761, 978-1861004765

More Books

Students also viewed these Databases questions