-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Make complete packages mockable
- Loading branch information
Showing
9 changed files
with
352 additions
and
8 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
61 changes: 61 additions & 0 deletions
61
.../kotlin/src/test/groovy/io/github/joke/spockmockable/PersonTestWithMockablePackage.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,61 @@ | ||
package io.github.joke.spockmockable | ||
|
||
import org.spockframework.mock.MockUtil | ||
import spock.lang.Specification | ||
|
||
@Mockable(packages = "io.github.joke.spockmockable") | ||
class PersonTestWithMockablePackage extends Specification { | ||
|
||
def mockUtil = new MockUtil() | ||
|
||
def 'final from class is removed'() { | ||
setup: | ||
Person person = Mock() | ||
|
||
expect: | ||
mockUtil.isMock person | ||
} | ||
|
||
def 'final from method is removed'() { | ||
setup: | ||
Person person = Mock() | ||
|
||
when: | ||
def res = person.firstName | ||
|
||
then: | ||
1 * person.firstName >> 'Dorothy' | ||
|
||
expect: | ||
res == 'Dorothy' | ||
} | ||
|
||
def 'private on method is now protected'() { | ||
setup: | ||
Person person = Mock() | ||
|
||
when: | ||
def res = person.lastName | ||
|
||
then: | ||
1 * person.lastName >> 'Gale' | ||
|
||
expect: | ||
res == 'Gale' | ||
} | ||
|
||
def 'final is removed and private on method is now protected'() { | ||
setup: | ||
Person person = Mock() | ||
|
||
when: | ||
def res = person.address.street | ||
|
||
then: | ||
1 * person.address >> new Address('Yellow Brick Road', 'Blue City') | ||
|
||
expect: | ||
res == 'Yellow Brick Road' | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
...roovy24/src/test/groovy/io/github/joke/spockmockable/PersonTestWithMockablePackage.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,69 @@ | ||
package io.github.joke.spockmockable | ||
|
||
import org.spockframework.mock.MockUtil | ||
import spock.lang.Specification | ||
|
||
@Mockable(packages = "io.github.joke.spockmockable") | ||
class PersonTestWithMockablePackage extends Specification { | ||
|
||
def mockUtil = new MockUtil() | ||
|
||
def 'final from class is removed'() { | ||
setup: | ||
Person person = Mock() | ||
|
||
expect: | ||
mockUtil.isMock person | ||
} | ||
|
||
def 'final from subclass is removed'() { | ||
setup: | ||
Person.Address address = Mock() | ||
|
||
expect: | ||
mockUtil.isMock address | ||
} | ||
|
||
def 'final from method is removed'() { | ||
setup: | ||
Person person = Mock() | ||
|
||
when: | ||
def res = person.firstName | ||
|
||
then: | ||
1 * person.firstName >> 'Dorothy' | ||
|
||
expect: | ||
res == 'Dorothy' | ||
} | ||
|
||
def 'private on method is now protected'() { | ||
setup: | ||
Person person = Mock() | ||
|
||
when: | ||
def res = person.lastName | ||
|
||
then: | ||
1 * person.lastName >> 'Gale' | ||
|
||
expect: | ||
res == 'Gale' | ||
} | ||
|
||
def 'final is removed and private on method is now protected'() { | ||
setup: | ||
Person person = Mock() | ||
|
||
when: | ||
def res = person.address.street | ||
|
||
then: | ||
1 * person.address >> new Person.Address('Yellow Brick Road') | ||
|
||
expect: | ||
res == 'Yellow Brick Road' | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
...roovy25/src/test/groovy/io/github/joke/spockmockable/PersonTestWithMockablePackage.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,69 @@ | ||
package io.github.joke.spockmockable | ||
|
||
import org.spockframework.mock.MockUtil | ||
import spock.lang.Specification | ||
|
||
@Mockable(packages = "io.github.joke.spockmockable") | ||
class PersonTestWithMockablePackage extends Specification { | ||
|
||
def mockUtil = new MockUtil() | ||
|
||
def 'final from class is removed'() { | ||
setup: | ||
Person person = Mock() | ||
|
||
expect: | ||
mockUtil.isMock person | ||
} | ||
|
||
def 'final from subclass is removed'() { | ||
setup: | ||
Person.Address address = Mock() | ||
|
||
expect: | ||
mockUtil.isMock address | ||
} | ||
|
||
def 'final from method is removed'() { | ||
setup: | ||
Person person = Mock() | ||
|
||
when: | ||
def res = person.firstName | ||
|
||
then: | ||
1 * person.firstName >> 'Dorothy' | ||
|
||
expect: | ||
res == 'Dorothy' | ||
} | ||
|
||
def 'private on method is now protected'() { | ||
setup: | ||
Person person = Mock() | ||
|
||
when: | ||
def res = person.lastName | ||
|
||
then: | ||
1 * person.lastName >> 'Gale' | ||
|
||
expect: | ||
res == 'Gale' | ||
} | ||
|
||
def 'final is removed and private on method is now protected'() { | ||
setup: | ||
Person person = Mock() | ||
|
||
when: | ||
def res = person.address.street | ||
|
||
then: | ||
1 * person.address >> new Person.Address('Yellow Brick Road') | ||
|
||
expect: | ||
res == 'Yellow Brick Road' | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
...spock20/src/test/groovy/io/github/joke/spockmockable/PersonTestWithMockablePackage.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,69 @@ | ||
package io.github.joke.spockmockable | ||
|
||
import org.spockframework.mock.MockUtil | ||
import spock.lang.Specification | ||
|
||
@Mockable(packages = "io.github.joke.spockmockable") | ||
class PersonTestWithMockablePackage extends Specification { | ||
|
||
def mockUtil = new MockUtil() | ||
|
||
def 'final from class is removed'() { | ||
setup: | ||
Person person = Mock() | ||
|
||
expect: | ||
mockUtil.isMock person | ||
} | ||
|
||
def 'final from subclass is removed'() { | ||
setup: | ||
Person.Address address = Mock() | ||
|
||
expect: | ||
mockUtil.isMock address | ||
} | ||
|
||
def 'final from method is removed'() { | ||
setup: | ||
Person person = Mock() | ||
|
||
when: | ||
def res = person.firstName | ||
|
||
then: | ||
1 * person.firstName >> 'Dorothy' | ||
|
||
expect: | ||
res == 'Dorothy' | ||
} | ||
|
||
def 'private on method is now protected'() { | ||
setup: | ||
Person person = Mock() | ||
|
||
when: | ||
def res = person.lastName | ||
|
||
then: | ||
1 * person.lastName >> 'Gale' | ||
|
||
expect: | ||
res == 'Gale' | ||
} | ||
|
||
def 'final is removed and private on method is now protected'() { | ||
setup: | ||
Person person = Mock() | ||
|
||
when: | ||
def res = person.address.street | ||
|
||
then: | ||
1 * person.address >> new Person.Address('Yellow Brick Road') | ||
|
||
expect: | ||
res == 'Yellow Brick Road' | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
...ing/src/test/groovy/io/github/joke/spockmockable/ControllerTestWithMockablePackage.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,32 @@ | ||
package io.github.joke.spockmockable | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
|
||
import org.spockframework.spring.SpringBean | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest | ||
import org.springframework.test.web.servlet.MockMvc | ||
import spock.lang.Specification | ||
|
||
@Mockable(packages = "io.github.joke.spockmockable") | ||
@WebMvcTest(controllers = SimpleController) | ||
class ControllerTestWithMockablePackage extends Specification { | ||
|
||
@SpringBean | ||
SimpleService simpleService = Mock() | ||
|
||
@Autowired | ||
MockMvc mockMvc | ||
|
||
def 'final from class is removed'() { | ||
when: | ||
def response = mockMvc.perform(get('/name')).andReturn().response | ||
|
||
then: | ||
1 * simpleService.name >> 'This is a mock' | ||
|
||
expect: | ||
response.contentAsString == 'This is a mock' | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -21,4 +21,5 @@ | |
*/ | ||
Class<?>[] value() default {}; | ||
|
||
String[] packages() default {}; | ||
} |
Oops, something went wrong.