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

@Tested contains a hidden implicit ordering (unlike @Injectable) #504

Closed
mina-asham opened this issue Jan 22, 2018 · 0 comments
Closed

@Tested contains a hidden implicit ordering (unlike @Injectable) #504

mina-asham opened this issue Jan 22, 2018 · 0 comments
Assignees
Labels

Comments

@mina-asham
Copy link

@mina-asham mina-asham commented Jan 22, 2018

  • Version of JMockit that was used: 1.38

  • Description of the problem:
    @tested behaves differently from @Injectable requiring a hidden implicit order of parameters. Also there is nothing specifically mentioned about the order in the documentation.

Super simple example to reproduce:

import mockit.Tested;
import org.junit.Test;

public class TestedOrderBug {

    @Test
    // The following two alternatives of the method definition work
    // 1) public void testedOrderBug(@Tested Outer outer, @Injectable Inner inner) { // Replacing second Tested with Injectable
    // 2) public void testedOrderBug(@Tested Inner inner, @Tested Outer outer) { // Putting the second Tested first instead
    public void testedOrderBug(@Tested Outer outer, @Tested Inner inner) {
        System.out.println(outer.toString());
    }

    private static class Outer {

        private final Inner inner;

        private Outer(Inner inner) {
            this.inner = inner;
        }
    }

    private static class Inner {}
}

This also hold to test class initialization:

import mockit.Tested;
import org.junit.Test;

public class TestedOrderBug {

    @Tested Outer outer;
    
    // The following two alternatives work:
    // 1) Replacing Tested with Injectable
    // 2) Putting this line above the one above
    @Tested Inner inner;

    @Test
    public void testedOrderBug() {
        System.out.println(outer.toString());
    }

    private static class Outer {

        private final Inner inner;

        private Outer(Inner inner) {
            this.inner = inner;
        }
    }

    private static class Inner {}
}
@rliesenfeld rliesenfeld self-assigned this Jan 24, 2018
@jmockit jmockit locked and limited conversation to collaborators Jul 21, 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.