City Service Exception Tests
Classified in Design and Engineering
Written at on English with a size of 4.39 KB.
TESTCANCEL
EXCEPTION expected
- Service already cancelled, we capture and check text before throwing the exception
- @throws CityServiceException
@Test(expected = CityServiceException.class)
public void testAssignExceptionText () throws CityServiceException {
Activity a = moderator.cancel(service, "already exists");
assertNotNull(a);
try {
moderator.cancel(service, "reported by another user");
}
catch (CityServiceException e) {
assertEquals("Service was already cancelled", e.getMessage());
throw e;
}
//fail
fail();
}
TESTCOMMENT
EXCEPTION expected
- User not found. The user is not found, we capture and check text before throwing the exception
- @throws CityServiceException
@Test(expected = CityServiceException.class)
public void testUserNotFoundCheckText () throws CityServiceException {
try {
city.addComment(-73, serviceId, "citizen comment");
}
catch (CityServiceException e) {
assertEquals("User -73 not found", e.getMessage());
throw e;
}
//fail
fail();
}
EXCEPTION expected
- User not found. The user is not found, we capture and check text before throwing the exception
- @throws CityServiceException
@Test(expected = CityServiceException.class)
public void testServiceNotFoundCheckText () throws CityServiceException {
Id anyId = IdGenerator.getInstance().next();
try {
city.addComment(citizenId, anyId, "citizen comment");
}
catch (CityServiceException e) {
System.out.println(e.getMessage());
assertEquals("Service " + anyId + " not found", e.getMessage());
throw e;
}
//fail
fail();
}
TESTMODERATOR
EXCEPTION expected
- Service already assigned, we capture and check text before throwing the exception
- @throws CityServiceException
@Test(expected = CityServiceException.class)
public void testAssignExceptionText () throws CityServiceException {
Activity a = moderator.assign(service, streetDep);
assertNotNull(a);
try {
moderator.assign(service, streetDep);
}
catch (CityServiceException e) {
assertEquals("Service already has department", e.getMessage());
throw e;
}
//fail
fail();
}
TESTOBSERVER
Add a subscriber as listener
@throws CityServiceException
@Test
public void testAddListener () throws CityServiceException {
Subscriber subs = new Subscriber("[email protected]");
service.addListener(subs);
}
Check my own notifications
@throws CityServiceException
@Test
public void testListenerOwnClass () throws CityServiceException {
final List got = new ArrayList<>();
Service Listener myListener = new ServiceListener() {
@Override
public void newActivity(Activity a) {
got.add(a);
}
};
TESTSERVICEREQUEST
EXCEPTION expected
- User not found. The user is not found, we capture and check text before throwing the exception
- @throws CityServiceException
@Test(expected = CityServiceException.class)
public void testUserNotFoundCheckText () throws CityServiceException {
try {
city.newIncidence(-73, typeLightOut, "Bulb seems to be damaged", "7447 W Talcott Ave Norwood Park");
}
catch (CityServiceException e) {
assertEquals("User -73 not found", e.getMessage());
throw e;
}
//fail
fail();
}