-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from rspieldenner/testkit
GradleTestKit Helper
- Loading branch information
Showing
13 changed files
with
259 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
src/main/groovy/com/energizedwork/spock/extensions/TempDirectory.groovy
This file was deleted.
Oops, something went wrong.
122 changes: 0 additions & 122 deletions
122
src/main/groovy/com/energizedwork/spock/extensions/TempDirectoryExtension.groovy
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Copyright 2013-2017 Netflix, Inc. | ||
* | ||
* 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. | ||
*/ | ||
package nebula.test | ||
|
||
import groovy.transform.CompileStatic | ||
import groovy.transform.TypeCheckingMode | ||
import org.junit.Rule | ||
import org.junit.rules.TestName | ||
import spock.lang.Specification | ||
|
||
abstract class BaseIntegrationSpec extends Specification { | ||
@Rule TestName testName = new TestName() | ||
File projectDir | ||
|
||
def setup() { | ||
projectDir = new File("build/nebulatest/${this.class.canonicalName}/${testName.methodName.replaceAll(/\W+/, '-')}") | ||
if (projectDir.exists()) { | ||
projectDir.deleteDir() | ||
} | ||
projectDir.mkdirs() | ||
} | ||
|
||
/* Setup */ | ||
protected File directory(String path, File baseDir = getProjectDir()) { | ||
new File(baseDir, path).with { | ||
mkdirs() | ||
it | ||
} | ||
} | ||
|
||
protected File file(String path, File baseDir = getProjectDir()) { | ||
def splitted = path.split('/') | ||
def directory = splitted.size() > 1 ? directory(splitted[0..-2].join('/'), baseDir) : baseDir | ||
def file = new File(directory, splitted[-1]) | ||
file.createNewFile() | ||
file | ||
} | ||
|
||
@CompileStatic(TypeCheckingMode.SKIP) | ||
protected File createFile(String path, File baseDir = getProjectDir()) { | ||
File file = file(path, baseDir) | ||
if (!file.exists()) { | ||
assert file.parentFile.mkdirs() || file.parentFile.exists() | ||
file.createNewFile() | ||
} | ||
file | ||
} | ||
|
||
protected void writeHelloWorld(String packageDotted, File baseDir = getProjectDir()) { | ||
def path = 'src/main/java/' + packageDotted.replace('.', '/') + '/HelloWorld.java' | ||
def javaFile = createFile(path, baseDir) | ||
javaFile << """\ | ||
package ${packageDotted}; | ||
public class HelloWorld { | ||
public static void main(String[] args) { | ||
System.out.println("Hello Integration Test"); | ||
} | ||
} | ||
""".stripIndent() | ||
} | ||
|
||
/** | ||
* Creates a unit test for testing your plugin. | ||
* @param failTest true if you want the test to fail, false if the test should pass | ||
* @param baseDir the directory to begin creation from, defaults to projectDir | ||
*/ | ||
protected void writeUnitTest(boolean failTest, File baseDir = getProjectDir()) { | ||
writeTest('src/test/java/', 'nebula', failTest, baseDir) | ||
} | ||
|
||
/** | ||
* | ||
* Creates a unit test for testing your plugin. | ||
* @param srcDir the directory in the project where the source file should be created. | ||
* @param packageDotted the package for the unit test class, written in dot notation (ex. - nebula.integration) | ||
* @param failTest true if you want the test to fail, false if the test should pass | ||
* @param baseDir the directory to begin creation from, defaults to projectDir | ||
*/ | ||
protected void writeTest(String srcDir, String packageDotted, boolean failTest, File baseDir = getProjectDir()) { | ||
def path = srcDir + packageDotted.replace('.', '/') + '/HelloWorldTest.java' | ||
def javaFile = createFile(path, baseDir) | ||
javaFile << """\ | ||
package ${packageDotted}; | ||
import org.junit.Test; | ||
import static org.junit.Assert.assertFalse; | ||
public class HelloWorldTest { | ||
@Test public void doesSomething() { | ||
assertFalse( $failTest ); | ||
} | ||
} | ||
""".stripIndent() | ||
} | ||
|
||
/** | ||
* Creates a properties file to included as project resource. | ||
* @param srcDir the directory in the project where the source file should be created. | ||
* @param fileName to be used for the file, sans extension. The .properties extension will be added to the name. | ||
* @param baseDir the directory to begin creation from, defaults to projectDir | ||
*/ | ||
protected void writeResource(String srcDir, String fileName, File baseDir = getProjectDir()) { | ||
def path = "$srcDir/${fileName}.properties" | ||
def resourceFile = createFile(path, baseDir) | ||
resourceFile.text = "firstProperty=foo.bar" | ||
} | ||
|
||
protected void addResource(String srcDir, String filename, String contents, File baseDir = getProjectDir()) { | ||
def resourceFile = createFile("${srcDir}/${filename}", baseDir) | ||
resourceFile.text = contents | ||
} | ||
} |
Oops, something went wrong.