forked from spockframework/spock
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add :spock-specs:mock-integration subproject (spockframework#902)
The new project contains integration tests for using Spock to mock Java interfaces/classes with cglib/byte-buddy and objenesis, and without any of them. The old testCglib task that reran all tests with byte-buddy deactivated was removed except for spock-spring which contains a few tests that only run when cglib is being used.
- Loading branch information
1 parent
a463f1b
commit ab43f8c
Showing
6 changed files
with
111 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
ext.displayName = "Spock Framework - Integration Specs for Mocking" | ||
|
||
description = "Integration Specs for Mocking" | ||
|
||
configurations { | ||
cglib | ||
bytebuddy | ||
objenesis | ||
} | ||
|
||
dependencies { | ||
testCompile(project(":spock-core")) { | ||
exclude group: "cglib" | ||
exclude group: "net.bytebuddy" | ||
exclude group: "org.objenesis" | ||
} | ||
cglib libs.cglib | ||
bytebuddy libs.bytebuddy | ||
objenesis libs.objenesis | ||
} | ||
|
||
def codeGenerationLibraries = [ | ||
cglib: configurations.cglib, | ||
ByteBuddy: configurations.bytebuddy | ||
] | ||
|
||
codeGenerationLibraries.each { key, config -> | ||
tasks.create("test${key.capitalize()}WithoutObjenesis", Test) { | ||
systemProperty("org.spockframework.mock.testType", "${key.toLowerCase()} - objenesis") | ||
classpath += config | ||
} | ||
tasks.create("test${key.capitalize()}WithObjenesis", Test) { | ||
systemProperty("org.spockframework.mock.testType", "${key.toLowerCase()} + objenesis") | ||
classpath += config | ||
classpath += configurations.objenesis | ||
} | ||
} | ||
|
||
check.dependsOn(tasks.withType(Test)) |
64 changes: 64 additions & 0 deletions
64
spock-specs/mock-integration/src/test/groovy/MockingIntegrationSpec.groovy
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,64 @@ | ||
import org.spockframework.mock.CannotCreateMockException | ||
import spock.lang.IgnoreIf | ||
import spock.lang.Requires | ||
import spock.lang.Specification | ||
|
||
class MockingIntegrationSpec extends Specification { | ||
|
||
static final String TEST_TYPE = System.getProperty("org.spockframework.mock.testType", "plain"); | ||
|
||
def "can mock interface"() { | ||
given: | ||
def list = Mock(List) | ||
|
||
when: | ||
list.add(1) | ||
|
||
then: | ||
1 * list.add(1) | ||
} | ||
|
||
@IgnoreIf({ TEST_TYPE == "plain" }) | ||
def "can mock class when cglib or byte-buddy are present"() { | ||
given: | ||
def list = Mock(ArrayList) | ||
|
||
when: | ||
list.add(1) | ||
|
||
then: | ||
1 * list.add(1) | ||
} | ||
|
||
@Requires({ TEST_TYPE == "plain" }) | ||
def "cannot mock class without cglib and byte-buddy"() { | ||
when: | ||
Mock(ArrayList) | ||
|
||
then: | ||
thrown(CannotCreateMockException) | ||
} | ||
|
||
@IgnoreIf({ TEST_TYPE == "plain" }) | ||
def "can spy on class when cglib or byte-buddy are present"() { | ||
given: | ||
def list = Spy(ArrayList) | ||
|
||
when: | ||
list.add(1) | ||
|
||
then: | ||
1 * list.add(1) | ||
list.get(0) == 1 | ||
} | ||
|
||
@Requires({ TEST_TYPE == "plain" }) | ||
def "cannot spy on class without cglib and byte-buddy"() { | ||
when: | ||
Spy(ArrayList) | ||
|
||
then: | ||
thrown(CannotCreateMockException) | ||
} | ||
|
||
} |
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