|
17 | 17 |
|
18 | 18 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
19 | 19 |
|
| 20 | +import org.junit.jupiter.api.Assertions; |
20 | 21 | import org.junit.jupiter.api.Test;
|
21 | 22 |
|
22 | 23 | class ErrorContextTest {
|
23 | 24 |
|
| 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 | + |
24 | 31 | @Test
|
25 | 32 | void shouldShowProgressiveErrorContextBuilding() {
|
26 | 33 | 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)); |
29 | 41 | context.reset();
|
30 | 42 |
|
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)); |
33 | 47 | context.reset();
|
34 | 48 |
|
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)); |
37 | 53 | context.reset();
|
38 | 54 |
|
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)); |
41 | 58 | context.reset();
|
42 | 59 |
|
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)); |
45 | 63 | context.reset();
|
46 | 64 |
|
47 | 65 | }
|
|
0 commit comments