|
18 | 18 |
|
19 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
20 | 20 |
|
21 |
| -import java.util.HashMap; |
| 21 | +import java.util.Collections; |
| 22 | +import java.util.Map; |
| 23 | +import java.util.stream.Stream; |
22 | 24 | import org.junit.jupiter.api.Test;
|
| 25 | +import org.junit.jupiter.params.ParameterizedTest; |
| 26 | +import org.junit.jupiter.params.provider.Arguments; |
| 27 | +import org.junit.jupiter.params.provider.MethodSource; |
23 | 28 | import org.neo4j.driver.Value;
|
24 | 29 |
|
25 | 30 | class Neo4jExceptionTest {
|
26 | 31 |
|
27 |
| - @Test |
28 |
| - void shouldInit() { |
29 |
| - var gqlStatus = "status"; |
30 |
| - var description = "description"; |
31 |
| - var code = "code"; |
32 |
| - var message = "message"; |
33 |
| - var map = new HashMap<String, Value>(); |
34 |
| - var throwable = new Neo4jException(gqlStatus, description, code, message, map, null); |
| 32 | + @ParameterizedTest |
| 33 | + @MethodSource("shouldInitArgs") |
| 34 | + void shouldInit( |
| 35 | + String gqlStatus, |
| 36 | + String description, |
| 37 | + String code, |
| 38 | + String message, |
| 39 | + Map<String, Value> diagnosticRecord, |
| 40 | + Throwable cause) { |
35 | 41 |
|
36 |
| - var exception = new Neo4jException(gqlStatus, description, code, message, map, throwable); |
| 42 | + var exception = new Neo4jException(gqlStatus, description, code, message, diagnosticRecord, cause); |
37 | 43 |
|
38 | 44 | assertEquals(gqlStatus, exception.gqlStatus());
|
39 | 45 | assertEquals(description, exception.statusDescription());
|
40 | 46 | assertEquals(code, exception.code());
|
41 | 47 | assertEquals(message, exception.getMessage());
|
42 |
| - assertEquals(map, exception.diagnosticRecord()); |
43 |
| - assertEquals(throwable, exception.gqlCause().orElse(null)); |
| 48 | + assertEquals(diagnosticRecord, exception.diagnosticRecord()); |
| 49 | + assertEquals(cause, exception.getCause()); |
| 50 | + assertEquals(cause, exception.gqlCause().orElse(null)); |
| 51 | + } |
| 52 | + |
| 53 | + private static Stream<Arguments> shouldInitArgs() { |
| 54 | + return Stream.of( |
| 55 | + Arguments.of( |
| 56 | + "status", |
| 57 | + "description", |
| 58 | + "code", |
| 59 | + "message", |
| 60 | + Collections.emptyMap(), |
| 61 | + new Neo4jException("status", "description", "code", "message", Collections.emptyMap(), null)), |
| 62 | + Arguments.of( |
| 63 | + "status", |
| 64 | + "description", |
| 65 | + "code", |
| 66 | + "message", |
| 67 | + Collections.emptyMap(), |
| 68 | + new ServiceUnavailableException("message"))); |
| 69 | + } |
| 70 | + |
| 71 | + @Test |
| 72 | + void shouldFindGqlCauseOnNonInterruptedChainOnly() { |
| 73 | + var exception4 = new ServiceUnavailableException("message", null); |
| 74 | + var exception3 = new IllegalStateException("message", exception4); |
| 75 | + var exception2 = |
| 76 | + new Neo4jException("status", "description", "code", "message", Collections.emptyMap(), exception3); |
| 77 | + var exception1 = |
| 78 | + new Neo4jException("status", "description", "code", "message", Collections.emptyMap(), exception2); |
| 79 | + var exception = |
| 80 | + new ClientException("status", "description", "code", "message", Collections.emptyMap(), exception1); |
| 81 | + |
| 82 | + assertError(exception, exception1, exception1); |
| 83 | + assertError(exception1, exception2, exception2); |
| 84 | + assertError(exception2, exception3, null); |
| 85 | + } |
| 86 | + |
| 87 | + private void assertError(Neo4jException exception, Throwable expectedCause, Neo4jException expectedGqlCause) { |
| 88 | + assertEquals(expectedCause, exception.getCause()); |
| 89 | + assertEquals(expectedGqlCause, exception.gqlCause().orElse(null)); |
44 | 90 | }
|
45 | 91 | }
|
0 commit comments