1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.lang3.exception;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertTrue;
21
22 import org.apache.commons.lang3.ObjectToStringRuntimeException;
23 import org.junit.jupiter.api.BeforeEach;
24 import org.junit.jupiter.api.Test;
25
26
27
28
29 public class DefaultExceptionContextTest extends AbstractExceptionContextTest<DefaultExceptionContext> {
30
31 @Override
32 @BeforeEach
33 public void setUp() throws Exception {
34 exceptionContext = new DefaultExceptionContext();
35 super.setUp();
36 }
37
38 @Test
39 public void testFormattedExceptionMessageExceptionHandling() {
40 exceptionContext = new DefaultExceptionContext();
41 final String label1 = "throws 1";
42 final String label2 = "throws 2";
43 exceptionContext.addContextValue(label1, new ObjectToStringRuntimeException(label1));
44 exceptionContext.addContextValue(label2, new ObjectToStringRuntimeException(label2));
45 final String message = exceptionContext.getFormattedExceptionMessage(TEST_MESSAGE);
46 assertTrue(message.startsWith(TEST_MESSAGE));
47 assertTrue(message.contains(label1));
48 assertTrue(message.contains(label2));
49 }
50
51 @Test
52 public void testFormattedExceptionMessageNull() {
53 exceptionContext = new DefaultExceptionContext();
54 assertEquals("", exceptionContext.getFormattedExceptionMessage(null));
55 }
56
57 @Test
58 public void testFormattedExceptionMessageNullValue() {
59 exceptionContext = new DefaultExceptionContext();
60 final String label1 = "throws 1";
61 final String label2 = "throws 2";
62 exceptionContext.addContextValue(label1, null);
63 exceptionContext.addContextValue(label2, null);
64 final String message = exceptionContext.getFormattedExceptionMessage(TEST_MESSAGE);
65 assertTrue(message.startsWith(TEST_MESSAGE));
66 assertTrue(message.contains(label1));
67 assertTrue(message.contains(label2));
68 }
69
70 }