1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.executor;
17
18 import static org.junit.jupiter.api.Assertions.assertEquals;
19
20 import org.junit.jupiter.api.Test;
21
22 class ErrorContextTest {
23
24 @Test
25 void shouldShowProgressiveErrorContextBuilding() {
26 ErrorContext context = ErrorContext.instance();
27 context.resource("somefile.xml").activity("some activity").object("some object").message("Here's more info.");
28 context.toString().startsWith("### The error occurred in somefile.xml.");
29 context.reset();
30
31 context.activity("some activity").object("some object").message("Here's more info.");
32 context.toString().startsWith("### The error occurred while some activity.");
33 context.reset();
34
35 context.object("some object").message("Here's more info.");
36 context.toString().startsWith("### Check some object.");
37 context.reset();
38
39 context.message("Here's more info.");
40 context.toString().startsWith("### Here's more info.");
41 context.reset();
42
43 context.cause(new Exception("test"));
44 context.toString().startsWith("### Cause: java.lang.Exception: test");
45 context.reset();
46
47 }
48
49 @Test
50 void verifyStoreRecall() throws Exception {
51 ErrorContext outer = ErrorContext.instance();
52 ErrorContext inner = ErrorContext.instance().store();
53 assertEquals(inner, ErrorContext.instance());
54 ErrorContext recalled = ErrorContext.instance().recall();
55 assertEquals(outer, recalled);
56 assertEquals(outer, ErrorContext.instance());
57 }
58 }