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

Method chaining with lists #748

Closed
gajarajkalburgi opened this Issue Jun 27, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@gajarajkalburgi

gajarajkalburgi commented Jun 27, 2017

Chaining Method Responses with lists

Chaining result gets scrambled while using lists.

Issue description

Mock any class returning list of objects.
Mocking and stubbing and result chaining given in example.

Expected

First call should return [1,2,3]
Second call should return [4,5,6]

Result

First call resturns [4,5,6]
Second call returns [1,2,3]

How to reproduce

def mockobj = Mock(Class)
given:
     mockobj.func(_) >>> [[1,2,3],[4,5,6]]

Java/JDK

Java version: 1.8.0_101, vendor: Oracle Corporation

Groovy version

Groovy 2.4

Build tool version

Apache Maven

Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T01:41:47+09:00)

Operating System

Windows

IDE

IntelliJ

Build-tool dependencies used

Apache Maven

<dependency>
       <groupId>org.spockframework</groupId>
       <artifactId>spock-core</artifactId>
   <version>1.1-groovy-2.4</version>
</dependency>
@leonard84

This comment has been minimized.

Show comment
Hide comment
@leonard84

leonard84 Jun 27, 2017

Member

I cannot reproduce your issue. This works fine for me:

class TestMock extends Specification {

    def "mock list return"() {
        def mock = Mock(Foo)
        mock.func(_) >>> [[1,2,3],[4,5,6]]

        when:
        def r1 = mock.func(1)
        def r2 = mock.func(2)

        then:
        r1 == [1,2,3]
        r2 == [4,5,6]

    }


    def "stub list return"() {
        def mock = Stub(Foo)
        mock.func(_) >>> [[1,2,3],[4,5,6]]

        when:
        def r1 = mock.func(1)
        def r2 = mock.func(2)

        then:
        r1 == [1,2,3]
        r2 == [4,5,6]

    }

}

interface Foo {
    List func(param)
}

Please provide a SSCCE

Member

leonard84 commented Jun 27, 2017

I cannot reproduce your issue. This works fine for me:

class TestMock extends Specification {

    def "mock list return"() {
        def mock = Mock(Foo)
        mock.func(_) >>> [[1,2,3],[4,5,6]]

        when:
        def r1 = mock.func(1)
        def r2 = mock.func(2)

        then:
        r1 == [1,2,3]
        r2 == [4,5,6]

    }


    def "stub list return"() {
        def mock = Stub(Foo)
        mock.func(_) >>> [[1,2,3],[4,5,6]]

        when:
        def r1 = mock.func(1)
        def r2 = mock.func(2)

        then:
        r1 == [1,2,3]
        r2 == [4,5,6]

    }

}

interface Foo {
    List func(param)
}

Please provide a SSCCE

@leonard84 leonard84 closed this Jun 30, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment