Skip to content

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

@mina-asham

Description

@mina-asham
  • 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 {}
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions