-
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.
- Loading branch information
Showing
8 changed files
with
121 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,6 @@ dependencies { | |
} | ||
|
||
test { | ||
forkEvery 1 | ||
useJUnitPlatform() | ||
} |
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
67 changes: 67 additions & 0 deletions
67
...les/spock13/src/test/groovy/io/github/joke/spockmockable/PersonTestWithInheritance.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,67 @@ | ||
package io.github.joke.spockmockable | ||
|
||
import org.spockframework.mock.MockUtil | ||
|
||
class PersonTestWithInheritance extends TestBase { | ||
|
||
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 'privat 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 privat 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' | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
examples/spock13/src/test/groovy/io/github/joke/spockmockable/TestBase.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,7 @@ | ||
package io.github.joke.spockmockable; | ||
|
||
import spock.lang.Specification; | ||
|
||
@Mockable([Person, Person.Address]) | ||
abstract class TestBase extends Specification { | ||
} |
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 |
---|---|---|
|
@@ -12,5 +12,6 @@ dependencies { | |
} | ||
|
||
test { | ||
forkEvery 1 | ||
useJUnitPlatform() | ||
} |
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 |
---|---|---|
|
@@ -18,5 +18,6 @@ dependencies { | |
} | ||
|
||
test { | ||
forkEvery 1 | ||
useJUnitPlatform() | ||
} |
10 changes: 10 additions & 0 deletions
10
examples/spring/src/test/groovy/io/github/joke/spockmockable/ControllerTestBase.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,10 @@ | ||
package io.github.joke.spockmockable | ||
|
||
|
||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest | ||
import spock.lang.Specification | ||
|
||
@Mockable(SimpleService) | ||
@WebMvcTest(controllers = SimpleController) | ||
abstract class ControllerTestBase extends Specification { | ||
} |
30 changes: 30 additions & 0 deletions
30
examples/spring/src/test/groovy/io/github/joke/spockmockable/ControllerTestFromBase.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,30 @@ | ||
package io.github.joke.spockmockable | ||
|
||
import org.spockframework.spring.SpringBean | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.test.web.servlet.MockMvc | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get | ||
|
||
@Mockable(SimpleService) | ||
|
||
class ControllerTestFromBase extends ControllerTestBase { | ||
|
||
@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' | ||
} | ||
|
||
} |