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

Replacements for deprecated FullVerificationsInOrder #512

Closed
mgtsai opened this issue Apr 10, 2018 · 0 comments
Closed

Replacements for deprecated FullVerificationsInOrder #512

mgtsai opened this issue Apr 10, 2018 · 0 comments
Assignees
Labels
bug

Comments

@mgtsai
Copy link

@mgtsai mgtsai commented Apr 10, 2018

Please provide the following information:

  • Version of JMockit that was used:
    JMockit 1.39
    with JUnit5 (but using JUnit4 can also reproduce this problem)

  • Description of the problem:
    According to the release notes for version 1.39, FullVerificationsInOrder has been deprecated, and it will be removed from version 1.40. It suggests that FullVerificationsInOrder could be replaced by the VerificationsInOrder block and followed by an empty FullVerifications block.

FullVerificationsInOrder is very useful for verifying whether the methods are invoked with exact expected sequences. In the following example, when a method (in the following example: method2) is invoked multiple times interleaved with other method invocations, the unverified method invocation (the second mocked.method2() invocation) can be captured by the original FullVerificationsInOrder block with throwing an AssertionError.

But when replaced by the VerificationsInOrder block followed by an empty FullVerifications block, this unverified method call is missing and not captured by the FullVerifications block. Thus, the following example unit testing code results as:

  • testFullVerificationsInOrder fails, which is as expected
  • testReplacement succeeds, which is not as expected
import mockit.FullVerifications;
import mockit.FullVerificationsInOrder;
import mockit.Injectable;
import mockit.VerificationsInOrder;
import org.junit.jupiter.api.Test;

public final class FullVerificationsInOrderTest {
    public interface MockedInterface {
        void method1();
        void method2();
        void method3();
    }

    @Test
    public final void testFullVerificationsInOrder(@Injectable MockedInterface mocked) {
        mocked.method1();
        mocked.method2();
        mocked.method3();
        mocked.method1();
        mocked.method2();
        mocked.method3();

        new FullVerificationsInOrder() {{
            mocked.method1(); times = 1;
            mocked.method2(); times = 1;
            mocked.method3(); times = 1;
            mocked.method1(); times = 1;
            //mocked.method2(); times = 1;    // This method invocation is unverified, and captured by FullVerificationsInOrder
            mocked.method3(); times = 1;
        }};
    }

    @Test
    public final void testReplacement(@Injectable MockedInterface mocked) {
        mocked.method1();
        mocked.method2();
        mocked.method3();
        mocked.method1();
        mocked.method2();
        mocked.method3();

        new VerificationsInOrder() {{
            mocked.method1(); times = 1;
            mocked.method2(); times = 1;
            mocked.method3(); times = 1;
            mocked.method1(); times = 1;
            //mocked.method2(); times = 1;    // This method invocation is unverified, and should be captured.  But the following empty FullVerifications block doesn't capture it.
            mocked.method3(); times = 1;
        }};

        new FullVerifications() { };
    }
}
@rliesenfeld rliesenfeld self-assigned this Apr 10, 2018
@rliesenfeld rliesenfeld added the bug label Apr 10, 2018
@jmockit jmockit locked and limited conversation to collaborators Jul 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
2 participants
You can’t perform that action at this time.