Skip to content

Commit 063109e

Browse files
committed
Assert number of expected @deprecated
1 parent 6902833 commit 063109e

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import java.util.Collections;
2929
import java.util.List;
3030
import java.util.Map;
31+
import java.util.regex.Matcher;
32+
import java.util.regex.Pattern;
3133

3234
import static org.testng.Assert.*;
3335

@@ -177,6 +179,21 @@ public static void assertFileContains(Path path, String... lines) {
177179
}
178180
}
179181

182+
/**
183+
* Count occurrences of the given text
184+
* @param content content of the file
185+
* @param text text to find
186+
* @return
187+
*/
188+
public static int countOccurrences(String content, String text) {
189+
Matcher matcher = Pattern.compile(text).matcher(content);
190+
int count = 0;
191+
while (matcher.find()) {
192+
count++;
193+
}
194+
return count;
195+
}
196+
180197
public static String linearize(String target) {
181198
return target.replaceAll("\r?\n", "").replaceAll("\\s+", "\\s");
182199
}

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515

1616
import java.io.File;
1717
import java.nio.file.Files;
18+
import java.nio.file.Path;
1819
import java.nio.file.Paths;
1920
import java.util.Collections;
2021
import java.util.List;
2122
import java.util.Map;
2223

24+
import static org.junit.jupiter.api.Assertions.assertEquals;
25+
2326
@Test(groups = {TypeScriptGroups.TYPESCRIPT})
2427
public class TypeScriptClientCodegenTest {
2528
@Test
@@ -227,10 +230,15 @@ public void testDeprecatedOperation() throws Exception {
227230
files.forEach(File::deleteOnExit);
228231

229232
// verify operation is deprecated
233+
Path file = Paths.get(output + "/apis/DefaultApi.ts");
230234
TestUtils.assertFileContains(
231-
Paths.get(output + "/apis/DefaultApi.ts"),
235+
file,
232236
"* @deprecated"
233237
);
238+
239+
String content = Files.readString(file);
240+
assertEquals(1, TestUtils.countOccurrences(content, "@deprecated"));
241+
234242
}
235243

236244
@Test
@@ -249,9 +257,14 @@ public void testDeprecatedParameter() throws Exception {
249257
files.forEach(File::deleteOnExit);
250258

251259
// verify parameter is deprecated parameter
260+
Path file = Paths.get(output + "/apis/DefaultApi.ts");
252261
TestUtils.assertFileContains(
253-
Paths.get(output + "/apis/DefaultApi.ts"),
262+
file,
254263
"* @param name name of pet (@deprecated)"
255264
);
265+
266+
String content = Files.readString(file);
267+
assertEquals(1, TestUtils.countOccurrences(content, "@deprecated"));
268+
256269
}
257270
}

0 commit comments

Comments
 (0)