package com.github.liucijus.jinsist;

import com.github.liucijus.jinsist.mock.UnexpectedInvocation;
import com.github.liucijus.jinsist.testtypes.Collaborator;
import org.junit.Assert;
import org.junit.Test;

import static com.googlecode.catchexception.CatchException.verifyException;

public class ExpectationsTest {
    private Mockery mockery = new Mockery();
    private Collaborator collaborator = mockery.mock(Collaborator.class);

    @Test
    public void stubsMethod() {
        mockery.expect(collaborator).stub(mock -> mock.firstMethod("input")).returns("output");

        Assert.assertEquals("output", collaborator.firstMethod("input"));
    }

    @Test
    public void failsUnexpectedInvocation() {
        mockery.expect(collaborator).stub(mock -> mock.firstMethod("input")).returns("output");

        verifyException(collaborator, UnexpectedInvocation.class).firstMethod("unexpected input");

        verifyException(mockery, UnmetExpectations.class).verify();
    }

    @Test()
    public void stubsMultipleMethods() {
        mockery.expect(collaborator)
                .stub(mock -> mock.firstMethod("first input"))
                .returns("first output");

        mockery.expect(collaborator)
                .stub(mock -> mock.secondMethod("first input", "second input"))
                .returns("second output");

        Assert.assertEquals("first output", collaborator.firstMethod("first input"));
        Assert.assertEquals("second output", collaborator.secondMethod("first input", "second input"));

        mockery.verify();
    }

    @Test
    public void failsForOutOfOrderInvocations() {
        mockery.expect(collaborator)
                .stub(mock -> mock.firstMethod("first input"))
                .returns("first output");

        mockery.expect(collaborator)
                .stub(mock -> mock.secondMethod("first input", "second input"))
                .returns("second output");

        verifyException(collaborator, UnexpectedInvocation.class).secondMethod("first input", "second input");

        verifyException(mockery, UnmetExpectations.class).verify();
    }
}

@@ -2108,11 +2108,590 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void stubsMultipleMocks() %7B%0A        Collaborator collaborator1 = mockery.mock(Collaborator.class);%0A        Collaborator collaborator2 = mockery.mock(Collaborator.class);%0A%0A        mockery.expect(collaborator1).stub(mock -%3E mock.firstMethod(%22input1%22)).returns(%22output1%22);%0A        mockery.expect(collaborator2).stub(mock -%3E mock.firstMethod(%22input2%22)).returns(%22output2%22);%0A%0A        Assert.assertEquals(%22output1%22, collaborator1.firstMethod(%22input1%22));%0A        Assert.assertEquals(%22output2%22, collaborator2.firstMethod(%22input2%22));%0A%0A        mockery.verify();%0A    %7D
 %0A%7D%0A

Add test for multiple collaborators