Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: dccb8d00d4
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 70 lines (50 sloc) 2.439 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
class CreateUnitTestTestCase extends AbstractCliTestCase {

    protected void setUp() {
        workDir = new File(baseWorkDir, 'app1')
    }
    
    void testCreateUnitTest() {
        execute([ "create-unit-test" ])
        enterInput "com.demo.unit.HelloWorld"
        
        assertEquals 0, waitForProcess()
        
        def appDir = new File(baseWorkDir, 'app1')
        
        assertTrue 'unit test case was not created', new File(appDir, 'test/unit/com/demo/unit/HelloWorldTests.groovy').exists()
    }
    
    void testCreateUnitTestWithSpock() {
        // Prepare the test application that has Spock installed.
        def appSource = new File(cliTestsDir, "spock-app")
        def app = new File(baseWorkDir, "createunittest-spock-app")

        copyDir appSource, app
        workDir = app

        upgrade()

        // Make sure the plugin is installed and compiled.
        execute([ "compile" ])
        assertEquals "Failed to compile the app", 0, waitForProcess()

        execute([ "create-unit-test" ])
        enterInput "com.demo.unit.HelloWorld"
        
        assertEquals 0, waitForProcess()
        
        def appDir = new File(baseWorkDir, 'app1')
        def expectedTestFile = new File(app, 'test/unit/com/demo/unit/HelloWorldSpec.groovy')
        
        assertTrue 'Spock unit test case was not created', expectedTestFile.exists()

        def fileContent = expectedTestFile.text
        assertTrue 'Unit test case is not a Spock test', fileContent.contains(" extends Specification")
    }
    
    void testSuffixStripping() {
        execute([ "create-unit-test" ])
        enterInput "com.demo.unit.DemoTests"
        
        assertEquals 0, waitForProcess()
        
        def appDir = new File(baseWorkDir, 'app1')
        
        assertTrue 'unit test case was not created', new File(appDir, 'test/unit/com/demo/unit/DemoTests.groovy').exists()
        assertFalse 'test with wrong name was created', new File(appDir, 'test/unit/com/demo/unit/DemoTestsTests.groovy').exists()
    }

    private copyDir(source, destination) {
        if (source.directory) {
            if (!destination.exists()) {
                assert destination.mkdir() : "making $destination"
            }
            source.eachFile { copyDir(it, new File(destination, it.name)) }
        } else {
            destination.createNewFile()
            destination << source.newInputStream()
        }
    }
}
Something went wrong with that request. Please try again.