Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions src/test/java/org/apache/ibatis/executor/ErrorContextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,49 @@

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

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class ErrorContextTest {

private static final String SOME_FILE_XML = "somefile.xml";
private static final String SOME_ACTIVITY = "some activity";
private static final String SOME_OBJECT = "some object";
private static final String MORE_INFO = "Here's more info.";
private static final String EXCEPTION_MESSAGE = "test";

@Test
void shouldShowProgressiveErrorContextBuilding() {
ErrorContext context = ErrorContext.instance();
context.resource("somefile.xml").activity("some activity").object("some object").message("Here's more info.");
context.toString().startsWith("### The error occurred in somefile.xml.");

context.resource(SOME_FILE_XML).activity(SOME_ACTIVITY).object(SOME_OBJECT).message(MORE_INFO);
String contextString = context.toString();
Assertions.assertTrue(contextString.contains("### " + MORE_INFO));
Assertions.assertTrue(contextString.contains("### The error may exist in " + SOME_FILE_XML));
Assertions.assertTrue(contextString.contains("### The error may involve " + SOME_OBJECT));
Assertions.assertTrue(contextString.contains("### The error occurred while " + SOME_ACTIVITY));
context.reset();

context.activity("some activity").object("some object").message("Here's more info.");
context.toString().startsWith("### The error occurred while some activity.");
context.activity(SOME_ACTIVITY).object(SOME_OBJECT).message(MORE_INFO);
contextString = context.toString();
Assertions.assertTrue(contextString.contains("### " + MORE_INFO));
Assertions.assertTrue(contextString.contains("### The error occurred while " + SOME_ACTIVITY));
context.reset();

context.object("some object").message("Here's more info.");
context.toString().startsWith("### Check some object.");
context.object(SOME_OBJECT).message(MORE_INFO);
contextString = context.toString();
Assertions.assertTrue(contextString.contains("### " + MORE_INFO));
Assertions.assertTrue(contextString.contains("### The error may involve " + SOME_OBJECT));
context.reset();

context.message("Here's more info.");
context.toString().startsWith("### Here's more info.");
context.message(MORE_INFO);
contextString = context.toString();
Assertions.assertTrue(contextString.contains("### " + MORE_INFO));
context.reset();

context.cause(new Exception("test"));
context.toString().startsWith("### Cause: java.lang.Exception: test");
context.cause(new Exception(EXCEPTION_MESSAGE));
contextString = context.toString();
Assertions.assertTrue(contextString.contains("### Cause: java.lang.Exception: " + EXCEPTION_MESSAGE));
context.reset();

}
Expand Down
Loading