/** Test createServiceException. */
@Test public void testCreateServiceException() {
Throwable nested = new IllegalAccessException("nested");
Throwable cause1 = new Exception("cause1");
Throwable cause2 = new Exception("cause2", nested);
LocalizableMessage message = new LocalizableMessage("whatever");
try {
throw ServiceExceptionUtils.createServiceException();
} catch (ServiceException e) {
assertTrue(e instanceof CedarRuntimeException);
assertEquals(null, e.getMessage());
assertMessageValues(e.getLocalizableMessage(), (String) null);
assertNull(e.getCause());
assertNotNull(e.getContext());
assertNull(e.getContext().getRootCause());
}
try {
throw ServiceExceptionUtils.createServiceException("error");
} catch (ServiceException e) {
assertTrue(e instanceof CedarRuntimeException);
assertEquals("error", e.getMessage());
assertMessageValues(e.getLocalizableMessage(), "error");
assertNull(e.getCause());
assertNotNull(e.getContext());
assertNull(e.getContext().getRootCause());
}
try {
throw ServiceExceptionUtils.createServiceException(message);
} catch (ServiceException e) {
assertTrue(e instanceof CedarRuntimeException);
assertEquals(message.getText(), e.getMessage());
assertMessageValues(e.getLocalizableMessage(), message);
assertNull(e.getCause());
assertNotNull(e.getContext());
assertNull(e.getContext().getRootCause());
}
try {
throw ServiceExceptionUtils.createServiceException("error", cause1);
} catch (ServiceException e) {
assertTrue(e instanceof CedarRuntimeException);
assertEquals("error", e.getMessage());
assertMessageValues(e.getLocalizableMessage(), "error");
assertSame(cause1, e.getCause());
assertNotNull(e.getContext());
assertNotNull(e.getContext().getRootCause());
}
try {
throw ServiceExceptionUtils.createServiceException(message, cause1);
} catch (ServiceException e) {
assertTrue(e instanceof CedarRuntimeException);
assertEquals(message.getText(), e.getMessage());
assertMessageValues(e.getLocalizableMessage(), message);
assertSame(cause1, e.getCause());
assertNotNull(e.getContext());
assertNotNull(e.getContext().getRootCause());
}
try {
throw ServiceExceptionUtils.createServiceException("error", cause2);
} catch (ServiceException e) {
assertTrue(e instanceof CedarRuntimeException);
assertEquals("error", e.getMessage());
assertMessageValues(e.getLocalizableMessage(), "error");
assertSame(cause2, e.getCause());
assertNotNull(e.getContext());
assertNotNull(e.getContext().getRootCause());
}
try {
throw ServiceExceptionUtils.createServiceException(message, cause2);
} catch (ServiceException e) {
assertTrue(e instanceof CedarRuntimeException);
assertEquals(message.getText(), e.getMessage());
assertMessageValues(e.getLocalizableMessage(), message);
assertSame(cause2, e.getCause());
assertNotNull(e.getContext());
assertNotNull(e.getContext().getRootCause());
}