Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit 973cf83

Browse files
committed
Fix unit tests
1 parent dd6ce66 commit 973cf83

File tree

2 files changed

+67
-65
lines changed

2 files changed

+67
-65
lines changed

graphql-spring-boot-test/src/main/java/com/graphql/spring/boot/test/GraphQLTestError.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public String toString() {
5959
.map(Object::toString)
6060
.map(this::toNumericIndexIfPossible)
6161
.collect(Collectors.joining("/"))
62-
.replace("/\\[", "[")
62+
.replace("/[", "[")
6363
);
6464
}
6565
return sb.toString();
Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,80 @@
11
package com.graphql.spring.boot.test;
22

3+
import static org.assertj.core.api.Assertions.assertThat;
4+
35
import graphql.ErrorType;
46
import graphql.GraphQLError;
57
import graphql.language.SourceLocation;
8+
import java.util.Arrays;
9+
import java.util.Collections;
10+
import java.util.stream.Stream;
611
import org.junit.jupiter.api.DisplayName;
712
import org.junit.jupiter.params.ParameterizedTest;
813
import org.junit.jupiter.params.provider.Arguments;
914
import org.junit.jupiter.params.provider.MethodSource;
1015

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 {
1817

19-
private static final String TEST_MESSAGE = "Test message";
18+
private static final String TEST_MESSAGE = "Test message";
2019

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+
}
7173

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+
}
7880
}

0 commit comments

Comments
 (0)