Added a test that ensures that invalid class name gets converted
This commit is contained in:
@@ -105,7 +105,7 @@ class TestGenerator {
|
||||
void generateTestClasses(final String basePackageName) {
|
||||
ListMultimap<Path, ContractMetadata> contracts = contractFileScanner.findContracts()
|
||||
contracts.asMap().entrySet().each {
|
||||
Map.Entry<Path, Collection<ContractMetadata>> entry -> processIncludedDirectory(relativizeContractPath(entry), entry.getValue(), basePackageName)
|
||||
Map.Entry<Path, Collection<ContractMetadata>> entry -> processIncludedDirectory(relativizeContractPath(entry), (Collection<ContractMetadata>) entry.getValue(), basePackageName)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ class TestGenerator {
|
||||
Path dir = saver.generateTestBaseDir(basePackageNameForClass, convertIllegalPackageChars(includedDirectoryRelativePath.toString()))
|
||||
Path classPath = saver.pathToClass(dir, convertedClassName)
|
||||
def classBytes = generator.buildClass(configProperties, contracts, includedDirectoryRelativePath,
|
||||
new SingleTestGenerator.GeneratedClassData(className, packageName, classPath)).getBytes(StandardCharsets.UTF_8)
|
||||
new SingleTestGenerator.GeneratedClassData(convertedClassName, packageName, classPath)).getBytes(StandardCharsets.UTF_8)
|
||||
saver.saveClassFile(classPath, classBytes)
|
||||
counter.incrementAndGet()
|
||||
}
|
||||
|
||||
@@ -53,4 +53,15 @@ class GeneratorScannerSpec extends Specification {
|
||||
1 * classGenerator.buildClass(_, _, _, { SingleTestGenerator.GeneratedClassData it -> it.className == 'exceptionsSpec' && it.classPackage == 'org.springframework.cloud.contract.verifier.v2'} ) >> "spec2"
|
||||
}
|
||||
|
||||
def "should create class with name with hyphen"() {
|
||||
given:
|
||||
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(testFramework: SPOCK)
|
||||
properties.contractsDslDir = new File(this.getClass().getResource("/directory/with/name-with-hyphen").toURI())
|
||||
TestGenerator testGenerator = new TestGenerator(properties, classGenerator, Stub(FileSaver))
|
||||
when:
|
||||
testGenerator.generateTestClasses("org.springframework.cloud.contract.verifier")
|
||||
then:
|
||||
1 * classGenerator.buildClass(_, _, _, { SingleTestGenerator.GeneratedClassData it -> it.className == 'car_rentalSpec' && it.classPackage == 'org.springframework.cloud.contract.verifier'} ) >> "spec"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user