Skip to content

Commit

Permalink
Merge pull request mybatis#3204 from dk2k/dk2k_implement_assertions
Browse files Browse the repository at this point in the history
Added Assertions into ErrorContextTest
  • Loading branch information
hazendaz authored Jul 22, 2024
2 parents 073a19c + 3a2aa1e commit 22f2034
Showing 1 changed file with 28 additions and 10 deletions.
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

0 comments on commit 22f2034

Please sign in to comment.