DefaultExceptionLevelResolver implements ExceptionLevelResolver { @Override public ExceptionLevel resolveExceptionLevel(Exception ex) { String exceptionCode = resolveExceptionCode(ex); if (exceptionCode == null || exceptionCode.isEmpty()) { return ExceptionLevel.ERROR; } String exceptionCodePrefix = exceptionCode.substring(0, 1); if ("e".equalsIgnoreCase(exceptionCodePrefix)) { return ExceptionLevel.ERROR; } if ("w".equalsIgnoreCase(exceptionCodePrefix)) { return ExceptionLevel.WARN; } if ("i".equalsIgnoreCase(exceptionCodePrefix)) { return ExceptionLevel.INFO; } return ExceptionLevel.ERROR; } DefaultExceptionLevelResolver();  DefaultExceptionLevelResolver(
            ExceptionCodeResolver exceptionCodeResolver); void setExceptionCodeResolver(
            ExceptionCodeResolver exceptionCodeResolver); @Override ExceptionLevel resolveExceptionLevel(Exception ex);  }
@Test public void testResolveExceptionLevel_info() { Exception exception = new SystemException("i", "info."); ExceptionLevel actualExceptionLevel = testTarget.resolveExceptionLevel( exception); ExceptionLevel expectedExceptionLevel = ExceptionLevel.INFO; assertThat(actualExceptionLevel, is(expectedExceptionLevel)); }
@Test public void testResolveExceptionLevel_warn() { Exception exception = new SystemException("W.i", "warn."); ExceptionLevel actualExceptionLevel = testTarget.resolveExceptionLevel( exception); ExceptionLevel expectedExceptionLevel = ExceptionLevel.WARN; assertThat(actualExceptionLevel, is(expectedExceptionLevel)); }
@Test public void testResolveExceptionLevel_error() { Exception exception = new SystemException("Error.i.e", "error"); ExceptionLevel actualExceptionLevel = testTarget.resolveExceptionLevel( exception); ExceptionLevel expectedExceptionLevel = ExceptionLevel.ERROR; assertThat(actualExceptionLevel, is(expectedExceptionLevel)); }
@Test public void testResolveExceptionLevel_undefine() { Exception exception = new SystemException("F.i.e", "undefine"); ExceptionLevel actualExceptionLevel = testTarget.resolveExceptionLevel( exception); ExceptionLevel expectedExceptionLevel = ExceptionLevel.ERROR; assertThat(actualExceptionLevel, is(expectedExceptionLevel)); }
@Test public void testResolveExceptionLevel_exceptionCode_is_unresolve() { Exception exception = new Exception("error."); ExceptionLevel actualExceptionLevel = testTarget.resolveExceptionLevel( exception); ExceptionLevel expectedExceptionLevel = ExceptionLevel.ERROR; assertThat(actualExceptionLevel, is(expectedExceptionLevel)); }
@Test public void testResolveExceptionLevel_exceptionCode_is_empty() { Exception exception = new SystemException("", "error."); ExceptionLevel actualExceptionLevel = testTarget.resolveExceptionLevel( exception); ExceptionLevel expectedExceptionLevel = ExceptionLevel.ERROR; assertThat(actualExceptionLevel, is(expectedExceptionLevel)); }
@Test public void testResolveExceptionCode_resolver_is_undefine() { testTarget = new DefaultExceptionLevelResolver(); Exception exception = new SystemException("i.w.e", "error."); ExceptionLevel actualExceptionLevel = testTarget.resolveExceptionLevel( exception); ExceptionLevel expectedExceptionLevel = ExceptionLevel.ERROR; assertThat(actualExceptionLevel, is(expectedExceptionLevel)); }