@Test public void testGetNumFields() throws DatabaseException { Project census = new Project("census", 2, 3, 4, 5); dbProjects.add(census); assertEquals(dbProjects.getNumFields(census.getId()), 5); }
@Test public void testAdd() throws DatabaseException { Project census = new Project("census", 2, 3, 4, 5); Project births = new Project("births", 6, 7, 8, 9); dbProjects.add(census); dbProjects.add(births); List<Project> all = dbProjects.getAll(); assertEquals(2, all.size()); boolean foundAge = false; boolean foundPlace = false; for (Project p : all) { assertFalse(p.getId() == -1); if (!foundAge) { foundAge = areEqual(p, census, false); } if (!foundPlace) { foundPlace = areEqual(p, births, false); } } assertTrue(foundAge && foundPlace); }
@Test public void testGetRecsPerImage() throws DatabaseException { Project census = new Project("census", 2, 3, 4, 5); dbProjects.add(census); assertEquals(dbProjects.getRecsPerImage(census.getId()), 2); }
@Test public void testDelete() throws DatabaseException { Project census = new Project("census", 2, 3, 4, 5); Project births = new Project("births", 6, 7, 8, 9); dbProjects.add(census); dbProjects.add(births); List<Project> all = dbProjects.getAll(); assertEquals(2, all.size()); dbProjects.delete(census); dbProjects.delete(births); all = dbProjects.getAll(); assertEquals(0, all.size()); }
@Test public void testUpdate() throws DatabaseException { Project census = new Project("census", 2, 3, 4, 5); Project births = new Project("births", 6, 7, 8, 9); dbProjects.add(census); dbProjects.add(births); census.setTitle("CENSUS"); census.setRecordsperimage(3); census.setFirstycoord(4); census.setRecordheight(5); census.setNumfields(6); births.setTitle("BIRTHS"); births.setRecordsperimage(7); births.setFirstycoord(8); births.setRecordheight(9); births.setNumfields(10); dbProjects.update(census); dbProjects.update(births); List<Project> all = dbProjects.getAll(); assertEquals(2, all.size()); boolean foundAge = false; boolean foundPlace = false; for (Project p : all) { if (!foundAge) { foundAge = areEqual(p, census, false); } if (!foundPlace) { foundPlace = areEqual(p, births, false); } } assertTrue(foundAge && foundPlace); }
@Test public void testGetAll() throws DatabaseException { List<Project> all = dbProjects.getAll(); assertEquals(0, all.size()); }
@Test(expected = DatabaseException.class) public void testInvalidDelete() throws DatabaseException { Project invalidProject = new Project(null, -1, -1, -1, -1); dbProjects.delete(invalidProject); }