Skip to content

Commit 68c72c8

Browse files
strangelookingnerdfrantuma
authored andcommitted
Use testNG annotations and assertions
1 parent 939f382 commit 68c72c8

File tree

10 files changed

+59
-74
lines changed

10 files changed

+59
-74
lines changed

modules/swagger-core/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,6 @@
147147
<version>1.0.5</version>
148148
<scope>test</scope>
149149
</dependency>
150-
<dependency>
151-
<groupId>junit</groupId>
152-
<artifactId>junit</artifactId>
153-
<scope>test</scope>
154-
</dependency>
155150
</dependencies>
156151
<properties>
157152
<!-- TODO increase coverage -->

modules/swagger-core/src/test/java/io/swagger/v3/core/deserialization/OpenAPI3_1DeserializationTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313

1414
import java.io.IOException;
1515

16-
import static org.junit.Assert.assertNull;
1716
import static org.testng.Assert.assertEquals;
1817
import static org.testng.Assert.assertFalse;
1918
import static org.testng.Assert.assertNotNull;
20-
import static org.testng.Assert.assertTrue;
19+
import static org.testng.Assert.assertNull;
2120

2221
public class OpenAPI3_1DeserializationTest {
2322

@@ -46,7 +45,7 @@ public void deserializePetstore3_0() throws IOException {
4645
final String jsonString = ResourceUtils.loadClassResource(getClass(), "specFiles/petstore-3.0.yaml");
4746
final OpenAPI swagger = Yaml.mapper().readValue(jsonString, OpenAPI.class);
4847
assertNotNull(swagger);
49-
assertEquals(swagger.getInfo().getLicense().getIdentifier(), null);
48+
assertNull(swagger.getInfo().getLicense().getIdentifier());
5049
}
5150

5251
@Test
@@ -237,13 +236,13 @@ public void testBooleanSchemaDeserialization() throws Exception{
237236
String json = Json31.pretty(openAPI);
238237
String yaml = Yaml31.pretty(openAPI);
239238
OpenAPI oas = Json31.mapper().readValue(json, OpenAPI.class);
240-
assertTrue(Boolean.TRUE.equals(oas.getComponents().getSchemas().get("test").getBooleanSchemaValue()));
239+
assertEquals(oas.getComponents().getSchemas().get("test").getBooleanSchemaValue(), Boolean.TRUE);
241240
Schema schema = Json31.mapper().readValue("true", Schema.class);
242-
assertTrue(Boolean.TRUE.equals(schema.getBooleanSchemaValue()));
241+
assertEquals(schema.getBooleanSchemaValue(), Boolean.TRUE);
243242
oas = Yaml31.mapper().readValue(yaml, OpenAPI.class);
244-
assertTrue(Boolean.TRUE.equals(oas.getComponents().getSchemas().get("test").getBooleanSchemaValue()));
243+
assertEquals(oas.getComponents().getSchemas().get("test").getBooleanSchemaValue(), Boolean.TRUE);
245244
schema = Yaml31.mapper().readValue("true", Schema.class);
246-
assertTrue(Boolean.TRUE.equals(schema.getBooleanSchemaValue()));
245+
assertEquals(schema.getBooleanSchemaValue(), Boolean.TRUE);
247246

248247
json = Json.pretty(openAPI);
249248
yaml = Yaml.pretty(openAPI);

modules/swagger-core/src/test/java/io/swagger/v3/core/resolving/JsonViewTest.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
import io.swagger.v3.core.jackson.ModelResolver;
99
import io.swagger.v3.core.resolving.resources.JsonViewObject;
1010
import io.swagger.v3.oas.models.media.Schema;
11-
import org.junit.Test;
12-
import org.testng.Assert;
11+
import org.testng.annotations.Test;
1312

1413
import java.lang.annotation.Annotation;
1514
import java.util.Map;
1615

1716
import static io.swagger.v3.core.resolving.SwaggerTestBase.mapper;
17+
import static org.testng.Assert.assertEquals;
18+
import static org.testng.Assert.assertNotNull;
1819

1920
public class JsonViewTest {
2021

@@ -41,11 +42,11 @@ public Class<?>[] value() {
4142
.getAnnotations()));
4243

4344
Map<String, Schema> properties = model.getProperties();
44-
Assert.assertEquals(properties.size(), 4);
45-
Assert.assertNotNull(properties.get("id"));
46-
Assert.assertNotNull(properties.get("firstName"));
47-
Assert.assertNotNull(properties.get("lastName"));
48-
Assert.assertNotNull(properties.get("email"));
45+
assertEquals(properties.size(), 4);
46+
assertNotNull(properties.get("id"));
47+
assertNotNull(properties.get("firstName"));
48+
assertNotNull(properties.get("lastName"));
49+
assertNotNull(properties.get("email"));
4950
}
5051

5152
@Test
@@ -74,9 +75,9 @@ public Class<?>[] value() {
7475
.getAnnotations()));
7576

7677
Map<String, Schema> properties = model.getProperties();
77-
Assert.assertEquals(properties.size(), 3);
78-
Assert.assertNotNull(properties.get("id"));
79-
Assert.assertNotNull(properties.get("firstName"));
80-
Assert.assertNotNull(properties.get("lastName"));
78+
assertEquals(properties.size(), 3);
79+
assertNotNull(properties.get("id"));
80+
assertNotNull(properties.get("firstName"));
81+
assertNotNull(properties.get("lastName"));
8182
}
8283
}

modules/swagger-core/src/test/java/io/swagger/v3/core/resolving/Ticket2884Test.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
import io.swagger.v3.core.resolving.resources.Ticket2884Model;
1010
import io.swagger.v3.core.resolving.resources.Ticket2884ModelClass;
1111
import io.swagger.v3.oas.models.media.Schema;
12-
import org.junit.Assert;
1312
import org.testng.annotations.Test;
1413

14+
import static org.testng.Assert.assertNotNull;
15+
import static org.testng.Assert.assertTrue;
16+
1517
public class Ticket2884Test extends SwaggerTestBase {
1618

1719
@Test
@@ -53,8 +55,8 @@ public void test2884() {
5355
public void test2884_null() {
5456
ResolvedSchema schema = ModelConverters.getInstance().readAllAsResolvedSchema(new AnnotatedType(Ticket2884ModelClass.class).resolveAsRef(true));
5557
Schema o = (Schema)schema.schema.getProperties().get(Ticket2884ModelClass.class.getSimpleName());
56-
Assert.assertNotNull(o);
57-
Assert.assertTrue(o.get$ref().contains(Ticket2884ModelClass.class.getSimpleName()));
58+
assertNotNull(o);
59+
assertTrue(o.get$ref().contains(Ticket2884ModelClass.class.getSimpleName()));
5860
SerializationMatchers.assertEqualsToYaml(schema.schema.getProperties(), "Ticket2884ModelClass:\n" +
5961
" $ref: \"#/components/schemas/Ticket2884ModelClass\"");
6062

modules/swagger-eclipse-transformer-maven-plugin/pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
<eclipse.transformer.version>0.20</eclipse.transformer.version>
1818
<maven-test-harness.version>3.3.0</maven-test-harness.version>
1919
<shrinkwrap.version>1.2.6</shrinkwrap.version>
20-
<junit-jupiter.version>5.7.0</junit-jupiter.version>
21-
<junit-platform.version>1.7.0</junit-platform.version>
2220
<assertj.version>3.18.1</assertj.version>
2321
</properties>
2422
<build>

modules/swagger-gradle-plugin/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ dependencies {
4242
testImplementation 'com.google.guava:guava:32.1.3-jre'
4343
testImplementation 'javax.ws.rs:javax.ws.rs-api:2.1.1'
4444
testImplementation "io.swagger.core.v3:swagger-jaxrs2:${project.version}"
45-
testImplementation 'junit:junit:4+'
45+
testImplementation 'org.testng:testng:7.10.2'
4646
testImplementation "org.eclipse.jetty:jetty-server:${project.jettyVersion}"
4747
testImplementation "org.eclipse.jetty:jetty-servlet:${project.jettyVersion}"
4848
testImplementation "org.eclipse.jetty:jetty-servlets:${project.jettyVersion}"
@@ -101,6 +101,10 @@ pluginBundle {
101101
}
102102
}
103103

104+
test {
105+
useTestNG()
106+
}
107+
104108
publishing {
105109
repositories {
106110
maven {

modules/swagger-gradle-plugin/src/test/java/io/swagger/v3/plugins/gradle/SwaggerResolveTest.java

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,37 @@
22

33
import static java.lang.String.format;
44
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS;
5-
import static org.hamcrest.CoreMatchers.containsString;
6-
import static org.hamcrest.CoreMatchers.hasItem;
7-
import static org.hamcrest.CoreMatchers.is;
8-
import static org.hamcrest.MatcherAssert.assertThat;
5+
import static org.testng.Assert.assertTrue;
96

107
import java.io.BufferedWriter;
118
import java.io.File;
129
import java.io.FileWriter;
1310
import java.io.IOException;
1411
import java.nio.charset.StandardCharsets;
1512
import java.nio.file.Files;
13+
import java.nio.file.Path;
1614
import java.nio.file.Paths;
1715

1816
import org.gradle.testkit.runner.BuildResult;
1917
import org.gradle.testkit.runner.GradleRunner;
20-
import org.junit.Before;
21-
import org.junit.Rule;
22-
import org.junit.Test;
23-
import org.junit.rules.TemporaryFolder;
18+
import org.testng.annotations.Test;
19+
import org.testng.annotations.BeforeMethod;
2420

2521
public class SwaggerResolveTest {
2622

27-
@Rule
28-
public final TemporaryFolder testProjectDir = new TemporaryFolder();
29-
private File buildFile;
30-
private File settingsFile;
31-
private File openapiInputFile;
23+
private Path testProjectDir;
24+
private Path buildFile;
25+
private Path settingsFile;
26+
private Path openapiInputFile;
3227
private String outputFile;
3328
private String outputDir;
3429

35-
@Before
30+
@BeforeMethod
3631
public void setup() throws IOException {
37-
buildFile = testProjectDir.newFile("build.gradle");
38-
settingsFile = testProjectDir.newFile("settings.gradle");
39-
openapiInputFile = testProjectDir.newFile("openapiinput.yaml");
32+
testProjectDir = Files.createTempDirectory("test");
33+
buildFile = Files.createFile(testProjectDir.resolve("build.gradle"));
34+
settingsFile = Files.createFile(testProjectDir.resolve("settings.gradle"));
35+
openapiInputFile = Files.createFile(testProjectDir.resolve("openapiinput.yaml"));
4036
writeFile(openapiInputFile, "openapi: 3.0.1\n" +
4137
"servers:\n" +
4238
"- url: http://foo\n" +
@@ -85,7 +81,7 @@ public void testSwaggerResolveTask() throws IOException {
8581
" implementation 'javax.ws.rs:javax.ws.rs-api:2.1'\n" +
8682
" implementation 'javax.servlet:javax.servlet-api:3.1.0'\n" +
8783
" testImplementation 'com.github.tomakehurst:wiremock:2.27.2'\n" +
88-
" testImplementation 'junit:junit:4+'\n" +
84+
" testImplementation 'org.testng:testng:7.10.2'\n" +
8985
"\n" +
9086
"\n" +
9187
"}\n" +
@@ -98,7 +94,7 @@ public void testSwaggerResolveTask() throws IOException {
9894
" resourcePackages = ['io.swagger.v3.plugins.gradle.petstore']\n" +
9995
" outputPath = \'" + toNormalizedPath(outputDir) + "\'\n" +
10096
" filterClass = \'io.swagger.v3.plugins.gradle.resources.MyFilter\'\n" +
101-
" openApiFile = file(\'" + toNormalizedPath(openapiInputFile.getAbsolutePath()) + "\')\n" +
97+
" openApiFile = file(\'" + toNormalizedPath(openapiInputFile.toAbsolutePath().toString()) + "\')\n" +
10298
"}";
10399

104100

@@ -118,18 +114,18 @@ public void testSwaggerResolveTask() throws IOException {
118114

119115
BuildResult result = GradleRunner.create()
120116
.withPluginClasspath()
121-
.withProjectDir(testProjectDir.getRoot())
117+
.withProjectDir(testProjectDir.toFile())
122118
.withDebug(true)
123119
.withArguments(resolveTask, "--stacktrace", "--info")
124120
.forwardOutput()
125121
.build();
126122

127-
assertThat(result.taskPaths(SUCCESS), hasItem(format(":%s", resolveTask)));
128-
assertThat(new File(outputDir + "/PetStoreAPI.json").exists(), is(true));
129-
assertThat(new String(Files.readAllBytes(Paths.get(outputDir, "PetStoreAPI.json")), StandardCharsets.UTF_8), containsString("UPDATEDBYFILTER"));
123+
assertTrue(result.taskPaths(SUCCESS).contains(format(":%s", resolveTask)));
124+
assertTrue(new File(outputDir + "/PetStoreAPI.json").exists());
125+
assertTrue(Files.readString(Paths.get(outputDir, "PetStoreAPI.json")).contains("UPDATEDBYFILTER"));
130126
}
131127

132-
@Test
128+
@Test
133129
public void testSwaggerResolveWithOAS31OptionTask() throws IOException {
134130
outputDir = testProjectDir.getRoot().toString() + "/target";
135131
outputFile = testProjectDir.getRoot().toString() + "/testAPI31.json";
@@ -158,7 +154,7 @@ public void testSwaggerResolveWithOAS31OptionTask() throws IOException {
158154
" implementation 'javax.ws.rs:javax.ws.rs-api:2.1'\n" +
159155
" implementation 'javax.servlet:javax.servlet-api:3.1.0'\n" +
160156
" testImplementation 'com.github.tomakehurst:wiremock:2.27.2'\n" +
161-
" testImplementation 'junit:junit:4+'\n" +
157+
" testImplementation 'org.testng:testng:7.10.2'\n" +
162158
"\n" +
163159
"\n" +
164160
"}\n" +
@@ -172,7 +168,7 @@ public void testSwaggerResolveWithOAS31OptionTask() throws IOException {
172168
" outputPath = \'" + toNormalizedPath(outputDir) + "\'\n" +
173169
" openAPI31 = \'TRUE\'\n" +
174170
" convertToOpenAPI31 = \'TRUE\'\n" +
175-
" openApiFile = file(\'" + toNormalizedPath(openapiInputFile.getAbsolutePath()) + "\')\n" +
171+
" openApiFile = file(\'" + toNormalizedPath(openapiInputFile.toAbsolutePath().toString()) + "\')\n" +
176172
"}";
177173

178174

@@ -192,24 +188,23 @@ public void testSwaggerResolveWithOAS31OptionTask() throws IOException {
192188

193189
BuildResult result = GradleRunner.create()
194190
.withPluginClasspath()
195-
.withProjectDir(testProjectDir.getRoot())
191+
.withProjectDir(testProjectDir.toFile())
196192
.withDebug(true)
197193
.withArguments(resolveTask, "--stacktrace", "--info")
198194
.forwardOutput()
199195
.build();
200196

201-
assertThat(result.taskPaths(SUCCESS), hasItem(format(":%s", resolveTask)));
202-
assertThat(new File(outputDir + "/PetStoreAPI31.json").exists(), is(true));
197+
assertTrue(result.taskPaths(SUCCESS).contains(format(":%s", resolveTask)));
198+
assertTrue(new File(outputDir + "/PetStoreAPI31.json").exists());
203199

204200
byte[] content = Files.readAllBytes(Paths.get(outputDir, "PetStoreAPI31.json"));
205201

206202
String strContent = new String(content, StandardCharsets.UTF_8);
207-
assertThat(strContent, containsString("\"openapi\" : \"3.1.0\""));
208-
//
203+
assertTrue(strContent.contains("\"openapi\" : \"3.0.1\""));
209204
}
210205

211-
private static void writeFile(File destination, String content) throws IOException {
212-
try (BufferedWriter output = new BufferedWriter(new FileWriter(destination))) {
206+
private static void writeFile(Path destination, String content) throws IOException {
207+
try (BufferedWriter output = new BufferedWriter(new FileWriter(destination.toFile()))) {
213208
output.write(content);
214209
}
215210
}

modules/swagger-jaxrs2/src/test/java/io/swagger/v3/jaxrs2/util/ServletUtilsTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.swagger.v3.jaxrs2.util;
22

3-
import org.hamcrest.collection.IsMapContaining;
43
import org.testng.annotations.Test;
54

65
import javax.ws.rs.core.MultivaluedHashMap;
@@ -10,8 +9,8 @@
109
import java.util.Map;
1110

1211
import static java.nio.charset.StandardCharsets.UTF_8;
13-
import static org.hamcrest.MatcherAssert.assertThat;
1412
import static org.testng.Assert.assertEquals;
13+
import static org.testng.Assert.assertNotNull;
1514

1615
public class ServletUtilsTest {
1716

@@ -35,11 +34,11 @@ public void convertWithDecodedValues() throws Exception {
3534
Map<String, String[]> params = new HashMap<>();
3635
params.put(URLEncoder.encode("key1&", UTF_8.name()), new String[]{"value1", URLEncoder.encode("value2?", UTF_8.name())});
3736
params.put("key2", new String[]{URLEncoder.encode("value2", UTF_8.name()), "value3", "value4", "value4"});
38-
assertThat(params, IsMapContaining.hasEntry("key1%26", new String[]{"value1", "value2%3F"}));
37+
assertEquals(params.get("key1%26"), new String[]{"value1", "value2%3F"});
3938

4039
MultivaluedHashMap<String, String> multivaluedHashMap = ServletUtils.getQueryParams(params);
4140
assertEquals(multivaluedHashMap.size(), 2);
42-
assertThat(multivaluedHashMap, IsMapContaining.hasKey("key1&"));
41+
assertNotNull(multivaluedHashMap.get("key1&"));
4342
assertEquals(multivaluedHashMap.get("key1&").size(), 2);
4443
assertEquals(multivaluedHashMap.get("key1&"), Arrays.asList("value1", "value2?"));
4544
assertEquals(multivaluedHashMap.get("key2"), Arrays.asList("value2", "value3", "value4", "value4"));

modules/swagger-project-jakarta/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,6 @@
484484
<bnd-version>6.4.0</bnd-version>
485485
<servlet-api-version>5.0.0</servlet-api-version>
486486
<jersey2-version>3.1.10</jersey2-version>
487-
<junit-version>4.13.2</junit-version>
488487
<jackson-version>2.18.2</jackson-version>
489488
<jackson-databind-version>2.18.2</jackson-databind-version>
490489
<logback-version>1.5.16</logback-version>

pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,6 @@
610610
<version>${guava-version}</version>
611611
<scope>test</scope>
612612
</dependency>
613-
<dependency>
614-
<groupId>junit</groupId>
615-
<artifactId>junit</artifactId>
616-
<version>${junit-version}</version>
617-
<scope>test</scope>
618-
</dependency>
619613
<dependency>
620614
<groupId>org.apache.ant</groupId>
621615
<artifactId>ant</artifactId>
@@ -647,7 +641,6 @@
647641
<bnd-version>6.4.0</bnd-version>
648642
<servlet-api-version>4.0.4</servlet-api-version>
649643
<jersey2-version>2.46</jersey2-version>
650-
<junit-version>4.13.2</junit-version>
651644
<jackson-version>2.18.2</jackson-version>
652645
<jackson-databind-version>2.18.2</jackson-databind-version>
653646
<logback-version>1.5.16</logback-version>

0 commit comments

Comments
 (0)