diff --git a/examples/kotlin/build.gradle b/examples/kotlin/build.gradle index c5029c9..2536081 100644 --- a/examples/kotlin/build.gradle +++ b/examples/kotlin/build.gradle @@ -13,5 +13,6 @@ dependencies { } test { + forkEvery 1 useJUnitPlatform() } diff --git a/examples/spock13/build.gradle b/examples/spock13/build.gradle index 61b45cd..4b2fd43 100644 --- a/examples/spock13/build.gradle +++ b/examples/spock13/build.gradle @@ -11,3 +11,7 @@ dependencies { testImplementation 'org.spockframework:spock-core' testImplementation 'org.objenesis:objenesis:3.1' } + +test { + forkEvery 1 +} \ No newline at end of file diff --git a/examples/spock13/src/test/groovy/io/github/joke/spockmockable/PersonTestWithInheritance.groovy b/examples/spock13/src/test/groovy/io/github/joke/spockmockable/PersonTestWithInheritance.groovy new file mode 100644 index 0000000..6475079 --- /dev/null +++ b/examples/spock13/src/test/groovy/io/github/joke/spockmockable/PersonTestWithInheritance.groovy @@ -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' + } + +} diff --git a/examples/spock13/src/test/groovy/io/github/joke/spockmockable/TestBase.groovy b/examples/spock13/src/test/groovy/io/github/joke/spockmockable/TestBase.groovy new file mode 100644 index 0000000..38d371b --- /dev/null +++ b/examples/spock13/src/test/groovy/io/github/joke/spockmockable/TestBase.groovy @@ -0,0 +1,7 @@ +package io.github.joke.spockmockable; + +import spock.lang.Specification; + +@Mockable([Person, Person.Address]) +abstract class TestBase extends Specification { +} diff --git a/examples/spock20/build.gradle b/examples/spock20/build.gradle index 473c241..90ece96 100644 --- a/examples/spock20/build.gradle +++ b/examples/spock20/build.gradle @@ -12,5 +12,6 @@ dependencies { } test { + forkEvery 1 useJUnitPlatform() } diff --git a/examples/spring/build.gradle b/examples/spring/build.gradle index afb0836..e3dbf55 100644 --- a/examples/spring/build.gradle +++ b/examples/spring/build.gradle @@ -18,5 +18,6 @@ dependencies { } test { + forkEvery 1 useJUnitPlatform() } diff --git a/examples/spring/src/test/groovy/io/github/joke/spockmockable/ControllerTestBase.groovy b/examples/spring/src/test/groovy/io/github/joke/spockmockable/ControllerTestBase.groovy new file mode 100644 index 0000000..a6908f4 --- /dev/null +++ b/examples/spring/src/test/groovy/io/github/joke/spockmockable/ControllerTestBase.groovy @@ -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 { +} diff --git a/examples/spring/src/test/groovy/io/github/joke/spockmockable/ControllerTestFromBase.groovy b/examples/spring/src/test/groovy/io/github/joke/spockmockable/ControllerTestFromBase.groovy new file mode 100644 index 0000000..49d0fa7 --- /dev/null +++ b/examples/spring/src/test/groovy/io/github/joke/spockmockable/ControllerTestFromBase.groovy @@ -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' + } + +}