Skip to content

Commit d3935e8

Browse files
committed
Add test helper method
1 parent 78a0f3b commit d3935e8

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

modules/openapi-generator/src/test/java/org/openapitools/codegen/TestUtils.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,31 @@ public static void assertFileContains(Path path, String... lines) {
177177
}
178178
}
179179

180+
/**
181+
* Verify line is found at given lineNumber
182+
* @param path
183+
* @param lineNumber
184+
* @param line
185+
*/
186+
public static void assertFileContains(Path path, int lineNumber, String line) {
187+
try {
188+
List<String> linesInFile = Files.readAllLines(path);
189+
int index = lineNumber - 1;
190+
191+
assertTrue(index >= 0 && index < linesInFile.size(),
192+
"Invalid line number: " + lineNumber);
193+
194+
String targetLine = linearize(linesInFile.get(index));
195+
String expectedLine = linearize(line);
196+
197+
assertTrue(targetLine.contains(expectedLine),
198+
"Expected line [" + expectedLine + "] not found at line number " + lineNumber);
199+
200+
} catch (IOException e) {
201+
fail("Unable to evaluate file " + path);
202+
}
203+
}
204+
180205
public static String linearize(String target) {
181206
return target.replaceAll("\r?\n", "").replaceAll("\\s+", "\\s");
182207
}

modules/openapi-generator/src/test/java/org/openapitools/codegen/typescript/TypeScriptClientCodegenTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ public void testDeprecatedOperation() throws Exception {
229229
// verify operation is deprecated
230230
TestUtils.assertFileContains(
231231
Paths.get(output + "/apis/DefaultApi.ts"),
232+
18,
232233
"* @deprecated"
233234
);
234235
}
@@ -251,6 +252,7 @@ public void testDeprecatedParameter() throws Exception {
251252
// verify parameter is deprecated parameter
252253
TestUtils.assertFileContains(
253254
Paths.get(output + "/apis/DefaultApi.ts"),
255+
20,
254256
"* @param name name of pet (@deprecated)"
255257
);
256258
}

0 commit comments

Comments
 (0)