Merge branch 'release/#166'
This commit is contained in:
@@ -7,6 +7,9 @@ import org.codehaus.plexus.util.DirectoryScanner
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
import static io.codearte.accurest.util.NamesUtil.afterLast
|
||||
import static io.codearte.accurest.util.NamesUtil.beforeLast
|
||||
import static io.codearte.accurest.util.NamesUtil.directoryToPackage
|
||||
|
||||
/**
|
||||
* @author Jakub Kubrynski
|
||||
*/
|
||||
@@ -62,14 +65,20 @@ class TestGenerator {
|
||||
}
|
||||
if (filesToClass.size()) {
|
||||
def className = afterLast(includedDirectoryRelativePath, File.separator) + configProperties.targetFramework.classNameSuffix
|
||||
def classBytes = generator.buildClass(filesToClass, className, packageNameForClass).bytes
|
||||
saver.saveClassFile(className, packageNameForClass, classBytes)
|
||||
def packageName = buildPackage(packageNameForClass, includedDirectoryRelativePath)
|
||||
def classBytes = generator.buildClass(filesToClass, className, packageName).bytes
|
||||
saver.saveClassFile(className, packageName, classBytes)
|
||||
counter.incrementAndGet()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String normalizePath(String path) {
|
||||
|
||||
private static String buildPackage(final String packageNameForClass, final String includedDirectoryRelativePath) {
|
||||
String directory = beforeLast(includedDirectoryRelativePath, File.separator)
|
||||
return "$packageNameForClass.${directoryToPackage(directory)}"
|
||||
}
|
||||
|
||||
private static String normalizePath(String path) {
|
||||
return FilenameUtils.separatorsToUnix(path)
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,13 @@ package io.codearte.accurest.util
|
||||
*/
|
||||
class NamesUtil {
|
||||
|
||||
static String beforeLast(String string, String separator) {
|
||||
if (string?.indexOf(separator) > -1) {
|
||||
return string.substring(0, string.lastIndexOf(separator))
|
||||
}
|
||||
return string
|
||||
}
|
||||
|
||||
static String afterLast(String string, String separator) {
|
||||
if (string?.indexOf(separator) > -1) {
|
||||
return string.substring(string.lastIndexOf(separator) + 1)
|
||||
@@ -42,4 +49,8 @@ class NamesUtil {
|
||||
static String packageToDirectory(String packageName) {
|
||||
return packageName.replaceAll('\\.', File.separator)
|
||||
}
|
||||
|
||||
static String directoryToPackage(String directory) {
|
||||
return directory.replace(File.separator, '.')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class GeneratorScannerSpec extends Specification {
|
||||
when:
|
||||
testGenerator.generateTestClasses("com.ofg")
|
||||
then:
|
||||
3 * classGenerator.buildClass(_, _, _) >> "qwerty"
|
||||
5 * classGenerator.buildClass(_, _, _) >> "qwerty"
|
||||
}
|
||||
|
||||
def "should filter other directory"() {
|
||||
@@ -30,6 +30,7 @@ class GeneratorScannerSpec extends Specification {
|
||||
testGenerator.generateTestClasses("com.ofg")
|
||||
then:
|
||||
1 * classGenerator.buildClass(_, 'differentSpec', _) >> "qwerty"
|
||||
2 * classGenerator.buildClass(_, 'exceptionsSpec', _) >> "qwerty"
|
||||
}
|
||||
|
||||
def "should ignore file"() {
|
||||
@@ -45,4 +46,17 @@ class GeneratorScannerSpec extends Specification {
|
||||
then:
|
||||
1 * classGenerator.buildClass({ it.size() == 1 }, 'otherSpec', _) >> "sample.groovy"
|
||||
}
|
||||
|
||||
def "should create class with full package"() {
|
||||
given:
|
||||
AccurestConfigProperties properties = new AccurestConfigProperties()
|
||||
properties.contractsDslDir = new File(this.getClass().getResource("/directory/with/stubs/package").toURI())
|
||||
TestGenerator testGenerator = new TestGenerator(properties, classGenerator, Stub(FileSaver))
|
||||
when:
|
||||
testGenerator.generateTestClasses("com.ofg")
|
||||
then:
|
||||
1 * classGenerator.buildClass(_, 'exceptionsSpec', 'com.ofg.v1') >> "spec1"
|
||||
1 * classGenerator.buildClass(_, 'exceptionsSpec', 'com.ofg.v2') >> "spec2"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user