Skip to content

Commit 3a2aa1e

Browse files
committed
Added Assertions into ErrorContextTest
1 parent 073a19c commit 3a2aa1e

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

src/test/java/org/apache/ibatis/executor/ErrorContextTest.java

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,49 @@
1717

1818
import static org.junit.jupiter.api.Assertions.assertEquals;
1919

20+
import org.junit.jupiter.api.Assertions;
2021
import org.junit.jupiter.api.Test;
2122

2223
class ErrorContextTest {
2324

25+
private static final String SOME_FILE_XML = "somefile.xml";
26+
private static final String SOME_ACTIVITY = "some activity";
27+
private static final String SOME_OBJECT = "some object";
28+
private static final String MORE_INFO = "Here's more info.";
29+
private static final String EXCEPTION_MESSAGE = "test";
30+
2431
@Test
2532
void shouldShowProgressiveErrorContextBuilding() {
2633
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.");
34+
35+
context.resource(SOME_FILE_XML).activity(SOME_ACTIVITY).object(SOME_OBJECT).message(MORE_INFO);
36+
String contextString = context.toString();
37+
Assertions.assertTrue(contextString.contains("### " + MORE_INFO));
38+
Assertions.assertTrue(contextString.contains("### The error may exist in " + SOME_FILE_XML));
39+
Assertions.assertTrue(contextString.contains("### The error may involve " + SOME_OBJECT));
40+
Assertions.assertTrue(contextString.contains("### The error occurred while " + SOME_ACTIVITY));
2941
context.reset();
3042

31-
context.activity("some activity").object("some object").message("Here's more info.");
32-
context.toString().startsWith("### The error occurred while some activity.");
43+
context.activity(SOME_ACTIVITY).object(SOME_OBJECT).message(MORE_INFO);
44+
contextString = context.toString();
45+
Assertions.assertTrue(contextString.contains("### " + MORE_INFO));
46+
Assertions.assertTrue(contextString.contains("### The error occurred while " + SOME_ACTIVITY));
3347
context.reset();
3448

35-
context.object("some object").message("Here's more info.");
36-
context.toString().startsWith("### Check some object.");
49+
context.object(SOME_OBJECT).message(MORE_INFO);
50+
contextString = context.toString();
51+
Assertions.assertTrue(contextString.contains("### " + MORE_INFO));
52+
Assertions.assertTrue(contextString.contains("### The error may involve " + SOME_OBJECT));
3753
context.reset();
3854

39-
context.message("Here's more info.");
40-
context.toString().startsWith("### Here's more info.");
55+
context.message(MORE_INFO);
56+
contextString = context.toString();
57+
Assertions.assertTrue(contextString.contains("### " + MORE_INFO));
4158
context.reset();
4259

43-
context.cause(new Exception("test"));
44-
context.toString().startsWith("### Cause: java.lang.Exception: test");
60+
context.cause(new Exception(EXCEPTION_MESSAGE));
61+
contextString = context.toString();
62+
Assertions.assertTrue(contextString.contains("### Cause: java.lang.Exception: " + EXCEPTION_MESSAGE));
4563
context.reset();
4664

4765
}

0 commit comments

Comments
 (0)