|
1 | 1 | package com.graphql.spring.boot.test; |
2 | 2 |
|
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | + |
3 | 5 | import graphql.ErrorType; |
4 | 6 | import graphql.GraphQLError; |
5 | 7 | import graphql.language.SourceLocation; |
| 8 | +import java.util.Arrays; |
| 9 | +import java.util.Collections; |
| 10 | +import java.util.stream.Stream; |
6 | 11 | import org.junit.jupiter.api.DisplayName; |
7 | 12 | import org.junit.jupiter.params.ParameterizedTest; |
8 | 13 | import org.junit.jupiter.params.provider.Arguments; |
9 | 14 | import org.junit.jupiter.params.provider.MethodSource; |
10 | 15 |
|
11 | | -import java.util.Arrays; |
12 | | -import java.util.Collections; |
13 | | -import java.util.stream.Stream; |
14 | | - |
15 | | -import static org.assertj.core.api.Assertions.assertThat; |
16 | | - |
17 | | -public class GraphQLTestErrorToStringTest { |
| 16 | +class GraphQLTestErrorToStringTest { |
18 | 17 |
|
19 | | - private static final String TEST_MESSAGE = "Test message"; |
| 18 | + private static final String TEST_MESSAGE = "Test message"; |
20 | 19 |
|
21 | | - private static Stream<Arguments> toStringTestArguments() { |
22 | | - return Stream.of( |
23 | | - Arguments.of( |
24 | | - new GraphQLTestError(null, null, null, null, null), |
25 | | - "<Unspecified error>: <error message not provided>" |
26 | | - ), |
27 | | - Arguments.of( |
28 | | - new GraphQLTestError(TEST_MESSAGE, null, null, null, null), |
29 | | - "<Unspecified error>: Test message" |
30 | | - ), |
31 | | - Arguments.of( |
32 | | - new GraphQLTestError(TEST_MESSAGE, null, ErrorType.DataFetchingException, null, null), |
33 | | - "DataFetchingException: Test message" |
34 | | - ), |
35 | | - Arguments.of( |
36 | | - new GraphQLTestError(TEST_MESSAGE, Collections.emptyList(), ErrorType.DataFetchingException, null, null), |
37 | | - "DataFetchingException: Test message" |
38 | | - ), |
39 | | - Arguments.of( |
40 | | - new GraphQLTestError(TEST_MESSAGE, Collections.singletonList(new SourceLocation(1, 2)), |
41 | | - ErrorType.DataFetchingException, null, null), |
42 | | - "DataFetchingException: Test message at line 1, column 2 in unnamed/unspecified source" |
43 | | - ), |
44 | | - Arguments.of( |
45 | | - new GraphQLTestError(TEST_MESSAGE, Collections.singletonList(new SourceLocation(1, 2)), |
46 | | - ErrorType.DataFetchingException, Collections.emptyList(), null), |
47 | | - "DataFetchingException: Test message at line 1, column 2 in unnamed/unspecified source" |
48 | | - ), |
49 | | - Arguments.of( |
50 | | - new GraphQLTestError(TEST_MESSAGE, Collections.singletonList(new SourceLocation(1, 2)), |
51 | | - ErrorType.DataFetchingException, Arrays.asList("path", "to", "error"), null), |
52 | | - "DataFetchingException: Test message at line 1, column 2 in unnamed/unspecified source. Selection path: path/to/error" |
53 | | - ), |
54 | | - Arguments.of( |
55 | | - new GraphQLTestError(TEST_MESSAGE, Collections.singletonList(new SourceLocation(1, 2, "test.graphql")), |
56 | | - ErrorType.DataFetchingException, Arrays.asList("path", "to", "error"), null), |
57 | | - "DataFetchingException: Test message at line 1, column 2 in test.graphql. Selection path: path/to/error" |
58 | | - ), |
59 | | - Arguments.of( |
60 | | - new GraphQLTestError(TEST_MESSAGE, Collections.singletonList(new SourceLocation(1, 2)), |
61 | | - ErrorType.DataFetchingException, Arrays.asList("path", 123, "error"), null), |
62 | | - "DataFetchingException: Test message at line 1, column 2 in unnamed/unspecified source. Selection path: path[123]/error" |
63 | | - ), |
64 | | - Arguments.of( |
65 | | - new GraphQLTestError(TEST_MESSAGE, Collections.singletonList(new SourceLocation(1, 2)), |
66 | | - ErrorType.DataFetchingException, Arrays.asList("path", 123, "error"), Collections.singletonMap("please ignore", "this")), |
67 | | - "DataFetchingException: Test message at line 1, column 2 in unnamed/unspecified source. Selection path: path[123]/error" |
68 | | - ) |
69 | | - ); |
70 | | - } |
| 20 | + private static Stream<Arguments> toStringTestArguments() { |
| 21 | + return Stream.of( |
| 22 | + Arguments.of( |
| 23 | + new GraphQLTestError(null, null, null, null, null), |
| 24 | + "<Unspecified error>: <error message not provided>" |
| 25 | + ), |
| 26 | + Arguments.of( |
| 27 | + new GraphQLTestError(TEST_MESSAGE, null, null, null, null), |
| 28 | + "<Unspecified error>: Test message" |
| 29 | + ), |
| 30 | + Arguments.of( |
| 31 | + new GraphQLTestError(TEST_MESSAGE, null, ErrorType.DataFetchingException, null, null), |
| 32 | + "DataFetchingException: Test message" |
| 33 | + ), |
| 34 | + Arguments.of( |
| 35 | + new GraphQLTestError(TEST_MESSAGE, Collections.emptyList(), |
| 36 | + ErrorType.DataFetchingException, null, null), |
| 37 | + "DataFetchingException: Test message" |
| 38 | + ), |
| 39 | + Arguments.of( |
| 40 | + new GraphQLTestError(TEST_MESSAGE, Collections.singletonList(new SourceLocation(1, 2)), |
| 41 | + ErrorType.DataFetchingException, null, null), |
| 42 | + "DataFetchingException: Test message at line 1, column 2 in unnamed/unspecified source" |
| 43 | + ), |
| 44 | + Arguments.of( |
| 45 | + new GraphQLTestError(TEST_MESSAGE, Collections.singletonList(new SourceLocation(1, 2)), |
| 46 | + ErrorType.DataFetchingException, Collections.emptyList(), null), |
| 47 | + "DataFetchingException: Test message at line 1, column 2 in unnamed/unspecified source" |
| 48 | + ), |
| 49 | + Arguments.of( |
| 50 | + new GraphQLTestError(TEST_MESSAGE, Collections.singletonList(new SourceLocation(1, 2)), |
| 51 | + ErrorType.DataFetchingException, Arrays.asList("path", "to", "error"), null), |
| 52 | + "DataFetchingException: Test message at line 1, column 2 in unnamed/unspecified source. Selection path: path/to/error" |
| 53 | + ), |
| 54 | + Arguments.of( |
| 55 | + new GraphQLTestError(TEST_MESSAGE, |
| 56 | + Collections.singletonList(new SourceLocation(1, 2, "test.graphql")), |
| 57 | + ErrorType.DataFetchingException, Arrays.asList("path", "to", "error"), null), |
| 58 | + "DataFetchingException: Test message at line 1, column 2 in test.graphql. Selection path: path/to/error" |
| 59 | + ), |
| 60 | + Arguments.of( |
| 61 | + new GraphQLTestError(TEST_MESSAGE, Collections.singletonList(new SourceLocation(1, 2)), |
| 62 | + ErrorType.DataFetchingException, Arrays.asList("path", 123, "error"), null), |
| 63 | + "DataFetchingException: Test message at line 1, column 2 in unnamed/unspecified source. Selection path: path[123]/error" |
| 64 | + ), |
| 65 | + Arguments.of( |
| 66 | + new GraphQLTestError(TEST_MESSAGE, Collections.singletonList(new SourceLocation(1, 2)), |
| 67 | + ErrorType.DataFetchingException, Arrays.asList("path", 123, "error"), |
| 68 | + Collections.singletonMap("please ignore", "this")), |
| 69 | + "DataFetchingException: Test message at line 1, column 2 in unnamed/unspecified source. Selection path: path[123]/error" |
| 70 | + ) |
| 71 | + ); |
| 72 | + } |
71 | 73 |
|
72 | | - @DisplayName("toString should work properly") |
73 | | - @ParameterizedTest(name = "{1}") |
74 | | - @MethodSource("toStringTestArguments") |
75 | | - void testGraphQLTestErrorToString(final GraphQLError error, final String expectedToString) { |
76 | | - assertThat(error.toString()).isEqualTo(expectedToString); |
77 | | - } |
| 74 | + @DisplayName("toString should work properly") |
| 75 | + @ParameterizedTest(name = "{1}") |
| 76 | + @MethodSource("toStringTestArguments") |
| 77 | + void testGraphQLTestErrorToString(final GraphQLError error, final String expectedToString) { |
| 78 | + assertThat(error).hasToString(expectedToString); |
| 79 | + } |
78 | 80 | } |
0 commit comments