Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@SpringSpy doesn't work #971

Open
pchudzik opened this Issue Feb 4, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@pchudzik
Copy link

pchudzik commented Feb 4, 2019

Issue description

@SpringSpy annotations doesn't work when verifying interactions with spies.

Spy is generated and proxied properly: TwoRepository$SpockMock$1035038003$$EnhancerBySpringCGLIB$$11ccc6b0

Looks like a naming problem or something?

Too few invocations for:
1 * twoRepository.getTwo()   (0 invocations)
Unmatched invocations (ordered by similarity):
1 * TwoRepository.getTwo()

How to reproduce

Test case: https://github.com/blog-pchudzik-examples/blog-example-spock-spring/blob/master/src/test/groovy/com/pchudzik/springmock/samples/springboot2/spock/SpockSamplesApplicationTest.groovy

@SpringBootTest(classes = Springboot2Application)
class SpockSamplesApplicationTest extends Specification {
    @SpringBean
    AddOne addOneTranslator = Mock()

    @SpringSpy
    TwoRepository twoRepository

    @Autowired
    MyService myService

    def "should calculate values"() {
        given:
        final inputA = 1
        final translatedA = 10
        final expectedResult = translatedA + TWO
        addOneTranslator.addOne(inputA) >> translatedA

        when:
        final result = myService.calculate(inputA)

        then:
        1 * twoRepository.getTwo()
        result == expectedResult
    }
}

and inside MyService (https://github.com/blog-pchudzik-examples/blog-example-spock-spring/tree/master/src/main/java/com/pchudzik/springmock/samples/springboot2/spock):

public int calculate(int a) {
        return addOne.addOne(a) + twoRepository.getTwo();
    }

Results:

Too few invocations for:

1 * twoRepository.getTwo()   (0 invocations)

Unmatched invocations (ordered by similarity):

1 * TwoRepository.getTwo()

Ignore package names. That's something I hacked quickly just to test @SpringSpy and @SpringBean annotations

Complete project https://github.com/blog-pchudzik-examples/blog-example-spock-spring

Additional Environment information

Complete build log: https://travis-ci.org/blog-pchudzik-examples/blog-example-spock-spring/builds/488647237

Java/JDK

$ java -Xmx32m -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
$ javac -J-Xmx32m -version
javac 1.8.0_151

Groovy version

2.5

testCompile('org.spockframework:spock-core:1.2-groovy-2.5')
testCompile('org.spockframework:spock-spring:1.2-groovy-2.5')

Build tool version

Gradle

gradle -version
4.8.1

@leonard84

This comment has been minimized.

Copy link
Member

leonard84 commented Apr 3, 2019

@pchudzik could you try updating to 1.3 that release has increased debugging output for unmatched invocations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.