Search in sources :

Example 1 with MockRuntimeException

use of com.helger.commons.exception.mock.MockRuntimeException in project ph-commons by phax.

the class SingleErrorTest method testLinkedException.

@Test
public void testLinkedException() {
    final Locale aDisplayLocale = Locale.US;
    final MockRuntimeException ex = new MockRuntimeException("msg");
    final SingleError aErr = SingleError.builder().linkedException(ex).build();
    assertEquals(EErrorLevel.ERROR, aErr.getErrorLevel());
    assertNull(aErr.getErrorID());
    assertNull(aErr.getErrorFieldName());
    assertNotNull(aErr.getErrorLocation());
    assertFalse(aErr.getErrorLocation().isAnyInformationPresent());
    assertNull(aErr.getErrorTexts());
    assertNull(aErr.getErrorText(aDisplayLocale));
    assertSame(ex, aErr.getLinkedException());
    assertNull(aErr.getLinkedExceptionCause());
    assertEquals("msg", aErr.getLinkedExceptionMessage());
    assertNotNull(aErr.getLinkedExceptionStackTrace());
    assertEquals("[error] (" + ex.getClass().getName() + ": msg)", aErr.getAsString(aDisplayLocale));
    assertEquals(aErr, SingleError.builder(aErr).build());
}
Also used : Locale(java.util.Locale) MockRuntimeException(com.helger.commons.exception.mock.MockRuntimeException) Test(org.junit.Test)

Example 2 with MockRuntimeException

use of com.helger.commons.exception.mock.MockRuntimeException in project ph-commons by phax.

the class SingleErrorTest method testAll.

@Test
public void testAll() {
    final Locale aDisplayLocale = Locale.US;
    final MockRuntimeException ex = new MockRuntimeException("exception msg");
    final SingleError aErr = SingleError.builder().errorID("id1").errorFieldName("field").errorLocation(new SimpleLocation("file.xml", 4, 13)).errorText("abc").linkedException(ex).build();
    assertEquals(EErrorLevel.ERROR, aErr.getErrorLevel());
    assertEquals("id1", aErr.getErrorID());
    assertEquals("field", aErr.getErrorFieldName());
    assertNotNull(aErr.getErrorLocation());
    assertTrue(aErr.getErrorLocation().isAnyInformationPresent());
    assertNotNull(aErr.getErrorTexts());
    assertEquals("abc", aErr.getErrorText(aDisplayLocale));
    assertSame(ex, aErr.getLinkedException());
    assertNull(aErr.getLinkedExceptionCause());
    assertEquals("exception msg", aErr.getLinkedExceptionMessage());
    assertNotNull(aErr.getLinkedExceptionStackTrace());
    assertEquals("[error] [id1] in field @ file.xml(4:13) abc (" + ex.getClass().getName() + ": exception msg)", aErr.getAsString(aDisplayLocale));
    assertEquals(aErr, SingleError.builder(aErr).build());
}
Also used : Locale(java.util.Locale) SimpleLocation(com.helger.commons.location.SimpleLocation) MockRuntimeException(com.helger.commons.exception.mock.MockRuntimeException) Test(org.junit.Test)

Aggregations

MockRuntimeException (com.helger.commons.exception.mock.MockRuntimeException)2 Locale (java.util.Locale)2 Test (org.junit.Test)2 SimpleLocation (com.helger.commons.location.SimpleLocation)1