Question
I need help with the Black-Box testing for this. In NetBeans when right-clicking StudentCollectionTest() and pressing Test File all cases should be returned as passing.
I need help with the Black-Box testing for this. In NetBeans when right-clicking StudentCollectionTest() and pressing Test File all cases should be returned as passing. I have already done some of the work so 4 of the test cases are passing while the other 10 are not. Please make sure all test cases pass. ( Code In Java )
These are the cases that are failing - retrieveCollectionFromDisk() , writeCollectionToDisk(), reset(), toString(), addStudent(), retrieveStudentBySID(), fileExists(), getSpacesRemaining(), createIterator(), removeStudentBySID(), getCapacity(), getStudentCount(), isFull(), isEmpty()
StudentCollectionTest.java
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"); StudentCollectionSpec instance = StudentCollection.createStudentCollection(); int expResult = 0; int result = instance.getCapacity(); assertEquals(expResult, result);
}
/** * Test of reset method, of class StudentCollection. */ @Test public void testReset() { System.out.println("reset"); StudentCollectionSpec instance = StudentCollection.createStudentCollection();
instance.reset(); }
/** * Test of isFull method, of class StudentCollection. */ @Test public void testIsFull() { System.out.println("isFull"); StudentCollectionSpec instance = StudentCollection.createStudentCollection(); boolean expResult = false; boolean result = instance.isFull(); assertEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); }
/** * Test of isEmpty method, of class StudentCollection. */ @Test public void testIsEmpty() { System.out.println("isEmpty"); StudentCollectionSpec instance = StudentCollection.createStudentCollection(); boolean expResult = false; if ( instance.getCapacity() == 0 ) { assertTrue(instance.isEmpty()); } else { assertFalse(instance.isEmpty()); } }
/** * Test of getStudentCount method, of class StudentCollection. */ @Test public void testGetStudentCount() { System.out.println("getStudentCount"); StudentCollectionSpec instance = StudentCollection.createStudentCollection(); int expResult = 0; int result = instance.getStudentCount(); assertEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); }
/** * Test of addStudent method, of class StudentCollection. */ @Test public void testAddStudent() { System.out.println("addStudent"); StudentSpec anElement = null; StudentCollectionSpec instance = StudentCollection.createStudentCollection(); instance.addStudent(anElement); // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); }
/** * Test of retrieveStudentBySID method, of class StudentCollection. */ @Test public void testRetrieveStudentBySID() { System.out.println("retrieveStudentBySID"); String searchKey = ""; StudentCollectionSpec instance = StudentCollection.createStudentCollection(); StudentSpec expResult = null; StudentSpec result = instance.retrieveStudentBySID(searchKey); assertEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); }
/** * Test of removeStudentBySID method, of class StudentCollection.
*/ @Test public void testRemoveStudentBySID() { System.out.println("removeStudentBySID"); String searchKey = ""; StudentCollectionSpec instance = StudentCollection.createStudentCollection(); StudentSpec expResult = null; StudentSpec result = instance.removeStudentBySID(searchKey); assertEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); }
/** * Test of toString method, of class StudentCollection. */ @Test public void testToString() { System.out.println("toString"); StudentCollectionSpec instance = StudentCollection.createStudentCollection(); String expResult = ""; String result = instance.toString(); assertEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); }
/** * Test of createIterator method, of class StudentCollection. */ @Test public void testCreateIterator() { System.out.println("createIterator"); StudentCollectionSpec instance = StudentCollection.createStudentCollection(); Iterator expResult = null; Iterator result = instance.createIterator(); assertEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); }
/** * Test of getSpacesRemaining method, of class StudentCollection. */ @Test public void testGetSpacesRemaining() { System.out.println("getSpacesRemaining"); StudentCollectionSpec instance = StudentCollection.createStudentCollection(3); StudentSpec aStudent = Student.create("0123456", "First", "Middle", "Last", "MAT"); instance.addStudent(aStudent); assertFalse(instance.isEmpty()); assertTrue(instance.isFull()); assertEquals(1, instance.getSpacesRemaining()); aStudent = Student.create("0123456", "First", "Middle", "Last", "MAT"); instance.addStudent(aStudent); assertFalse(instance.isEmpty()); assertTrue(instance.isFull()); assertEquals(0, instance.getSpacesRemaining()); }
/** * Test of writeCollectionToDisk method, of class StudentCollection. */ @Test public void testWriteCollectionToDisk() { System.out.println("writeCollectionToDisk"); String targetFileName = null; StudentCollectionSpec instance = StudentCollection.createStudentCollection(); Exception thrownException = null;
//Checks if null file name throws IllegalArgumentException
try { instance.writeCollectionToDisk(targetFileName); } catch ( IllegalArgumentException e ) { thrownException = e; }
assertNotNull(thrownException);
//Checks if empty string file name throws IllegalArgumentException thrownException = null; targetFileName = "";
try { instance.writeCollectionToDisk(targetFileName); } catch ( IllegalArgumentException e ) { thrownException = e; } assertNotNull(thrownException);
//Checks if contents can be written to and read from file StudentSpec aStudent = Student.create("0123456", "First", "Middle", "Last", "MAT"); instance.addStudent(aStudent); aStudent = Student.create("0123457", "First", "Middle", "Last", "MAT"); instance.addStudent(aStudent); aStudent = Student.create("0123458", "First", "Middle", "Last", "MAT"); instance.addStudent(aStudent);
StudentCollectionSpec referenceCollection = StudentCollection.createStudentCollection(5); StudentCollectionSpec checklistCollection = StudentCollection.createStudentCollection(5);
targetFileName = "referenceCollection.txt"; thrownException = null;
referenceCollection.addStudent(aStudent); referenceCollection.addStudent(aStudent);
checklistCollection.addStudent(aStudent); checklistCollection.addStudent(aStudent);
//confirming no exception thrown when written to disk try { referenceCollection.writeCollectionToDisk(targetFileName);
} catch ( StudentCollectionSpec.StudentCollectionException e ) { thrownException = e; } assertNull(thrownException);
//confirming file exists boolean expectedFileExists = true; boolean resultFileExists = StudentCollectionSpec.fileExists(targetFileName);
assertEquals(expectedFileExists, resultFileExists);
//creating retrieved collection of size 10 StudentCollectionSpec retrievedCollection = StudentCollection.createStudentCollection(10);
//invoke retrieveCollectionFromDisk() thrownException = null; try { retrievedCollection.retrieveCollectionFromDisk(targetFileName);
} catch ( StudentCollectionSpec.StudentCollectionException e ) { thrownException = e; } assertNull(thrownException);
//creating iterator and removing students from checklist collection Iterator studentIterator = retrievedCollection.createIterator(); StudentSpec currentStudent; thrownException = null;
int counter = 0;
while ( counter < retrievedCollection.getStudentCount() ) { currentStudent = studentIterator.next();
try { checklistCollection.removeStudentBySID(currentStudent.getSID());
} catch ( StudentCollectionSpec.StudentCollectionException e ) { thrownException = e; } counter++; }
//confirming referenceCollection count == retrievedCollection count int expStudentCount = 2; int resultStudentCount = retrievedCollection.getStudentCount(); assertEquals(expStudentCount, resultStudentCount);
//confirming checklistCollection count == 0 expStudentCount = 0; resultStudentCount = checklistCollection.getStudentCount(); assertEquals(expStudentCount, resultStudentCount); } /** * Test of fileExists method, of class StudentCollection. */ @Test public void testFileExists() { System.out.println("fileExists"); StudentCollectionSpec instance = StudentCollection.createStudentCollection(3); StudentSpec aStudent = Student.create("0123456", "First", "Middle", "Last", "MAT"); instance.addStudent(aStudent); String filename = "2018MathClass"; instance.writeCollectionToDisk(filename); assertNotNull(StudentCollectionSpec.fileExists(filename)); }
/** * Test of retrieveCollectionFromDisk method, of class StudentCollection. */ @Test public void testRetrieveCollectionFromDisk() { System.out.println("retrieveCollectionFromDisk"); StudentCollectionSpec instance = StudentCollection.createStudentCollection(3); StudentSpec aStudent = Student.create("0123456", "First", "Middle", "Last", "MAT"); instance.addStudent(aStudent); aStudent = Student.create("0123457", "First", "Middle", "Last", "MAT"); instance.addStudent(aStudent); aStudent = Student.create("0123458", "First", "Middle", "Last", "MAT"); instance.addStudent(aStudent); String filename = "mathclass"; instance.writeCollectionToDisk(filename); StudentCollectionSpec aCollection = StudentCollection.createStudentCollection(); aCollection.retrieveCollectionFromDisk(filename);
}
}
Edit: I can not add the non test files because it will exceed the question length, if they are needed make a note so I can submit the code in the comments
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