Skip to content

Commit

Permalink
refactor: Cleanup test and make test run on Windows OS
Browse files Browse the repository at this point in the history
t2gran committed Jan 2, 2025
1 parent 0bf3c72 commit f2406e7
Showing 4 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -37,12 +37,13 @@ void testEndOfText() {
org.opentest4j.AssertionFailedError.class,
() -> assertLinesEquals("A\n", "A\nExtra Line")
);
Assertions.assertEquals(
"""
Expected(@end-of-text): <>
Actual (@line 1): <Extra Line>
""",
ex.getMessage()
Assertions.assertTrue(
ex.getMessage().contains("Expected(@end-of-text)"),
"<" + ex.getMessage() + "> does not contain expected line."
);
Assertions.assertTrue(
ex.getMessage().contains("Actual (@line 1): <Extra Line>"),
"<" + ex.getMessage() + "> does not contain actual line."
);
}
}
Original file line number Diff line number Diff line change
@@ -34,12 +34,11 @@
class InjectCustomDocumentationTest {

private GraphQLSchema schema;
private String sdl;
private String sdlExpected;

@BeforeEach
void setUp() throws IOException {
sdl = loadSchemaResource(".graphql");
var sdl = loadSchemaResource(".graphql");
sdlExpected = loadSchemaResource(".graphql.expected");

var parser = new SchemaParser();
@@ -88,10 +87,12 @@ static Map<String, String> text() {
"AEnum.description",
"AEnum.E1.description",
"AEnum.E2.deprecated",
"AEnum.E3.deprecated",
"Duration.description",
"InputType.description",
"InputType.a.description",
"InputType.b.deprecated"
"InputType.b.deprecated",
"InputType.c.deprecated"
)
.collect(Collectors.toMap(e -> e, e -> e));
}
@@ -103,11 +104,7 @@ void test() {
var visitor = new InjectCustomDocumentation(customDocumentation);
var newSchema = SchemaTransformer.transformSchema(schema, visitor);
var p = new SchemaPrinter();
var result = p
.print(newSchema)
// Some editors like IntelliJ remove space characters at the end of a
// line, so we do the same here to avoid false positive results.
.replaceAll(" +\\n", "\n");
var result = p.print(newSchema);

var missingValues = texts
.values()
@@ -118,13 +115,19 @@ void test() {

// There is a bug in the Java GraphQL API, existing deprecated
// doc is not updated or replaced.
var expected = List.of("BType.a.deprecated", "CType.b.deprecated.append");
var expected = List.of(
"AEnum.E3.deprecated",
"BType.a.deprecated",
"CType.b.deprecated.append",
"InputType.c.deprecated"
);

assertEquals(expected, missingValues);

TextAssertions.assertLinesEquals(sdlExpected, result);
}

@SuppressWarnings("DataFlowIssue")
String loadSchemaResource(String suffix) throws IOException {
var cl = getClass();
var name = cl.getName().replace('.', '/') + suffix;
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ type QueryType {
enum AEnum {
E1
E2
E3 @deprecated(reason: "REPLACE")
}

# Add doc to scalar
@@ -49,4 +50,5 @@ scalar Duration
input InputType {
a: String
b: String
c: String @deprecated(reason: "REPLACE")
}
Original file line number Diff line number Diff line change
@@ -80,6 +80,7 @@ enum AEnum {
"AEnum.E1.description"
E1
E2 @deprecated(reason : "AEnum.E2.deprecated")
E3 @deprecated(reason : "REPLACE")
}

"Duration.description"
@@ -90,4 +91,5 @@ input InputType {
"InputType.a.description"
a: String
b: String @deprecated(reason : "InputType.b.deprecated")
c: String @deprecated(reason : "REPLACE")
}

0 comments on commit f2406e7

Please sign in to comment.