Merge branch '1.2.x'
This commit is contained in:
@@ -95,10 +95,12 @@ class RecursiveFilesConverter {
|
||||
convertedContent.entrySet().eachWithIndex { Map.Entry<Contract, String> content, int index ->
|
||||
Contract dsl = content.key
|
||||
String converted = content.value
|
||||
Path absoluteTargetPath = createAndReturnTargetDirectory(sourceFile)
|
||||
File newJsonFile = createTargetFileWithProperName(stubGenerator, absoluteTargetPath,
|
||||
sourceFile, contractsSize, index, dsl)
|
||||
newJsonFile.setText(converted, StandardCharsets.UTF_8.toString())
|
||||
if (converted) {
|
||||
Path absoluteTargetPath = createAndReturnTargetDirectory(sourceFile)
|
||||
File newJsonFile = createTargetFileWithProperName(stubGenerator, absoluteTargetPath,
|
||||
sourceFile, contractsSize, index, dsl)
|
||||
newJsonFile.setText(converted, StandardCharsets.UTF_8.toString())
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -130,6 +130,34 @@ class RecursiveFilesConverterSpec extends Specification {
|
||||
tmpFolder.root.list().toList().containsAll("foo", "bar")
|
||||
}
|
||||
|
||||
def "should not create stub file when generated stub is empty"() {
|
||||
given:
|
||||
def sourceFile = tmpFolder.newFile("test.groovy")
|
||||
sourceFile.text = """
|
||||
org.springframework.cloud.contract.spec.Contract.make {
|
||||
request {
|
||||
url "/baz"
|
||||
method "GET"
|
||||
}
|
||||
response {
|
||||
status 200
|
||||
}
|
||||
}
|
||||
"""
|
||||
and:
|
||||
StubGenerator stubGenerator = stubGenerator("")
|
||||
and:
|
||||
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties()
|
||||
properties.contractsDslDir = tmpFolder.root
|
||||
properties.stubsOutputDir = tmpFolder.newFolder("target")
|
||||
and:
|
||||
RecursiveFilesConverter recursiveFilesConverter = new RecursiveFilesConverter(properties, new StubGeneratorProvider([stubGenerator]))
|
||||
when:
|
||||
recursiveFilesConverter.processFiles()
|
||||
then:
|
||||
properties.stubsOutputDir.list().toList().isEmpty()
|
||||
}
|
||||
|
||||
private static Set<Path> getRelativePathsForFilesInDirectory(Collection<File> createdFiles, File targetRootDirectory) {
|
||||
Path rootSourcePath = Paths.get(targetRootDirectory.toURI())
|
||||
Set<Path> relativizedCreatedFiles = createdFiles.collect { File file ->
|
||||
|
||||
Reference in New Issue
Block a user