Skip to content

Commit

Permalink
test annotation inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
joke committed Jan 23, 2021
1 parent a05277b commit 1d881a2
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ dependencies {
}

test {
forkEvery 1
useJUnitPlatform()
}
4 changes: 4 additions & 0 deletions examples/spock13/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ dependencies {
testImplementation 'org.spockframework:spock-core'
testImplementation 'org.objenesis:objenesis:3.1'
}

test {
forkEvery 1
}
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'
}

}
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 {
}
1 change: 1 addition & 0 deletions examples/spock20/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ dependencies {
}

test {
forkEvery 1
useJUnitPlatform()
}
1 change: 1 addition & 0 deletions examples/spring/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ dependencies {
}

test {
forkEvery 1
useJUnitPlatform()
}
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 {
}
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'
}

}

0 comments on commit 1d881a2

Please sign in to comment.