Skip to content

Commit 2c242ec

Browse files
committed
remove test framework dependency
1 parent 1bd1b54 commit 2c242ec

2 files changed

Lines changed: 40 additions & 58 deletions

File tree

build.gradle.kts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ dependencies {
5656
implementation("com.google.jimfs:jimfs:1.1") {
5757
exclude("com.google.guava")
5858
}
59-
60-
compileOnly("junit:junit:4.13.1")
61-
implementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
62-
runtimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.0")
63-
runtimeOnly("org.junit.vintage:junit-vintage-engine:5.7.0")
6459
}
6560

6661
val sourcesJar by tasks.registering(Jar::class) {

src/main/groovy/com/github/hauner/openapi/test/ProcessorTestBase.groovy renamed to src/main/groovy/io/openapiprocessor/test/TestSetRunner.groovy

Lines changed: 40 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,42 @@
11
/*
2-
* Copyright 2019-2020 the original authors
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
2+
* Copyright © 2020 https://github.com/openapi-processor/openapi-processor-test
3+
* PDX-License-Identifier: Apache-2.0
154
*/
165

17-
package com.github.hauner.openapi.test
6+
package io.openapiprocessor.test
187

198
import com.fasterxml.jackson.databind.DeserializationFeature
209
import com.fasterxml.jackson.databind.ObjectMapper
2110
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
2211
import com.github.difflib.DiffUtils
2312
import com.github.difflib.UnifiedDiffUtils
24-
import org.junit.Rule
25-
import org.junit.rules.TemporaryFolder
13+
import com.github.hauner.openapi.test.TestItems
14+
import com.github.hauner.openapi.test.TestSet
2615

2716
import java.nio.file.FileSystem
2817
import java.nio.file.Files
2918
import java.nio.file.Path
3019
import java.util.stream.Stream
3120

32-
import static org.junit.Assert.assertEquals
33-
34-
abstract class ProcessorTestBase {
35-
36-
@Rule
37-
public TemporaryFolder folder = new TemporaryFolder()
21+
/**
22+
* used to execute test sets.
23+
*/
24+
class TestSetRunner {
3825

3926
TestSet testSet
4027

41-
ProcessorTestBase (TestSet testSet) {
28+
TestSetRunner(TestSet testSet) {
4229
this.testSet = testSet
4330
}
4431

45-
protected runOnNativeFileSystem () {
32+
boolean runOnNativeFileSystem (File folder) {
4633
def source = testSet.name
4734

4835
def processor = testSet.processor
4936
def options = [
5037
parser: testSet.parser,
5138
apiPath: "resource:/tests/${source}/inputs/openapi.yaml",
52-
targetDir: folder.root
39+
targetDir: folder.absolutePath
5340
]
5441

5542
def mappingYaml = getResource ("/tests/${source}/inputs/mapping.yaml")
@@ -66,7 +53,7 @@ abstract class ProcessorTestBase {
6653
def packageName = testSet.packageName
6754
def sourcePath = "/tests/${source}"
6855
def expectedPath = "${sourcePath}/${packageName}"
69-
def generatedPath = Path.of (folder.root.toString()).resolve (packageName)
56+
def generatedPath = Path.of (folder.absolutePath).resolve (packageName)
7057

7158
def expectedFiles = collectRelativeOutputPaths (sourcePath, packageName)
7259
.sort ()
@@ -75,20 +62,18 @@ abstract class ProcessorTestBase {
7562

7663
assert expectedFiles == generatedFiles
7764

65+
def success = true
7866
expectedFiles.each {
7967
def expected = "${expectedPath}/$it"
8068
def generated = generatedPath.resolve (it)
8169

82-
printUnifiedDiff (expected, generated)
83-
assertEquals(
84-
// ignore cr (ie. crlf vs lf)
85-
getResource (expected).text.replace('\r',''),
86-
generated.text.replace('\r','')
87-
)
70+
success &= printUnifiedDiff (expected, generated)
8871
}
72+
73+
success
8974
}
9075

91-
protected void runOnCustomFileSystem (FileSystem fs) {
76+
boolean runOnCustomFileSystem (FileSystem fs) {
9277
def source = testSet.name
9378

9479
Path root = Files.createDirectory (fs.getPath ("source"))
@@ -126,23 +111,21 @@ abstract class ProcessorTestBase {
126111
def generatedFiles = collectPaths (generatedPath)
127112
assert expectedFiles == generatedFiles
128113

114+
def success = true
129115
expectedFiles.each {
130-
def expected = expectedPath.resolve (it)
116+
def expected = "${expectedPath}/$it"
131117
def generated = generatedPath.resolve (it)
132118

133-
printUnifiedDiff (expected, generated)
134-
assertEquals(
135-
// ignore cr (ie. crlf vs lf)
136-
expected.text.replace('\r',''),
137-
generated.text.replace('\r','')
138-
)
119+
success &= printUnifiedDiff (expected, generated)
139120
}
121+
122+
success
140123
}
141124

142125
/**
143126
* copy paths file system <=> file system
144127
*/
145-
protected static void copy (Path source, Path target) {
128+
private static void copy (Path source, Path target) {
146129
Stream<Path> paths = Files.walk (source)
147130
.filter ({f -> !Files.isDirectory (f)})
148131

@@ -162,7 +145,7 @@ abstract class ProcessorTestBase {
162145
/**
163146
* copy paths resources <=> file system
164147
*/
165-
protected void copy (String source, List<String> sources, Path target) {
148+
private void copy (String source, List<String> sources, Path target) {
166149
for (String p : sources) {
167150
String relativePath = p.substring (source.size () + 1)
168151

@@ -180,7 +163,7 @@ abstract class ProcessorTestBase {
180163
*
181164
* will convert all paths to use "/" as path separator
182165
*/
183-
protected static List<String> collectPaths(Path source) {
166+
private static List<String> collectPaths(Path source) {
184167
List<String> files = []
185168

186169
def found = Files.walk (source)
@@ -201,21 +184,21 @@ abstract class ProcessorTestBase {
201184
/**
202185
* collect input paths
203186
*/
204-
protected List<String> collectAbsoluteInputPaths (String path) {
187+
private List<String> collectAbsoluteInputPaths (String path) {
205188
collectAbsoluteResourcePaths (path, "inputs.yaml")
206189
}
207190

208191
/**
209192
* collect output paths
210193
*/
211-
protected List<String> collectAbsoluteOutputPaths (String path) {
194+
private List<String> collectAbsoluteOutputPaths (String path) {
212195
collectAbsoluteResourcePaths (path, "generated.yaml")
213196
}
214197

215198
/**
216199
* collect output paths, relative to packageName
217200
*/
218-
protected List<String> collectRelativeOutputPaths (String path, String packageName) {
201+
private List<String> collectRelativeOutputPaths (String path, String packageName) {
219202
collectRelativeResourcePaths (path, "generated.yaml").collect {
220203
it.substring (packageName.size () + 1)
221204
}
@@ -224,7 +207,7 @@ abstract class ProcessorTestBase {
224207
/**
225208
* collect absolute paths from output.yaml in resources
226209
*/
227-
protected List<String> collectAbsoluteResourcePaths (String path, String itemsYaml) {
210+
private List<String> collectAbsoluteResourcePaths (String path, String itemsYaml) {
228211
collectRelativeResourcePaths (path, itemsYaml).collect {
229212
"${path}/${it}".toString ()
230213
}
@@ -233,7 +216,7 @@ abstract class ProcessorTestBase {
233216
/**
234217
* collect paths from output.yaml in resources
235218
*/
236-
protected List<String> collectRelativeResourcePaths (String path, String itemsYaml) {
219+
private List<String> collectRelativeResourcePaths (String path, String itemsYaml) {
237220
def source = getResource ("${path}/${itemsYaml}")
238221
if (!source) {
239222
println "ERROR: missing '${path}/${itemsYaml}' configuration file!"
@@ -246,8 +229,10 @@ abstract class ProcessorTestBase {
246229

247230
/**
248231
* unified diff resources <=> file system
232+
*
233+
* @return true if delta
249234
*/
250-
protected void printUnifiedDiff (String expected, Path generated) {
235+
private boolean printUnifiedDiff (String expected, Path generated) {
251236
def expectedLines = getResource (expected).readLines ()
252237

253238
def patch = DiffUtils.diff (
@@ -259,18 +244,20 @@ abstract class ProcessorTestBase {
259244
generated.toString (),
260245
expectedLines,
261246
patch,
262-
2
247+
4
263248
)
264249

265250
diff.each {
266251
println it
267252
}
253+
254+
return !patch.deltas.isEmpty ()
268255
}
269256

270257
/**
271258
* unified diff file system <=> file system
272259
*/
273-
protected static void printUnifiedDiff (Path expected, Path generated) {
260+
private static void printUnifiedDiff (Path expected, Path generated) {
274261
def patch = DiffUtils.diff (
275262
expected.readLines (),
276263
generated.readLines ())
@@ -288,11 +275,11 @@ abstract class ProcessorTestBase {
288275
}
289276
}
290277

291-
protected InputStream getResource (String path) {
278+
private InputStream getResource (String path) {
292279
this.class.getResourceAsStream (path)
293280
}
294281

295-
protected static ObjectMapper createYamlParser () {
282+
private static ObjectMapper createYamlParser () {
296283
new ObjectMapper (new YAMLFactory ())
297284
.configure (DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
298285
}

0 commit comments

Comments
 (0)