How does JMockIt work under the hood with multiple expectations?

14 views Asked by At

For example:

class JMockItTest {
    @Injectable Foo foo;
    @Test void test() {
        new Expectations() {{
            foo.nonVoidMethod();
            result = "a";
            result = "b";
            result = "c";
        }};
        assertEquals("a", foo.nonVoidMethod());
        assertEquals("b", foo.nonVoidMethod());
        assertEquals("c", foo.nonVoidMethod());
    }
}

This example will tell JMockIt to return "a" then "b" then "c" for each of the 3 invocations of nonVoidMethod()... but how does this work? It's not possible to override operators like = in Java, so how does simply assigning result = x multiple times tell JMockIt what to return?

0

There are 0 answers