/** Test generateExceptionContext(). */
@Test public void testGenerateExceptionContext() {
// This test is very sensitive to line numbers, so if you edit stuff above (even organize imports), this will fail
ExceptionContext context;
String expected;
context = ExceptionUtils.generateExceptionContext(null, 0);
assertNull(context);
Exception exception = new Exception("Hello", null);
context = ExceptionUtils.generateExceptionContext(exception, 0);
expected = "com.cedarsolutions.util.ExceptionUtilsTest.testGenerateExceptionContext(ExceptionUtilsTest.java:85)";
assertEquals(expected, context.getLocation());
assertNotNull(context.getStackTrace());
assertNull(context.getRootCause());
Exception cause = new Exception("I am a cause");
exception = new Exception("Hello", cause);
context = ExceptionUtils.generateExceptionContext(exception, 0);
expected = "com.cedarsolutions.util.ExceptionUtilsTest.testGenerateExceptionContext(ExceptionUtilsTest.java:93)";
assertEquals(expected, context.getLocation());
assertNotNull(context.getStackTrace());
assertEquals(ExceptionUtils.generateRootCause(cause), context.getRootCause());
// note: line number should be marked as if it came from the line below, not the method call
exception = createException();
context = ExceptionUtils.generateExceptionContext(exception, 1);
expected = "com.cedarsolutions.util.ExceptionUtilsTest.testGenerateExceptionContext(ExceptionUtilsTest.java:101)";
assertEquals(expected, context.getLocation());
assertNotNull(context.getStackTrace());
assertNull(context.getRootCause());
}