Skip to content

Super Constructor Gets Called Wrongly #492

@mina-asham

Description

@mina-asham

Please provide the following information:

  • Version of JMockit that was used: 1.36.3

  • Description of the problem: Super constructor always gets called when trying to use mocking API to override constructor

Example test:

import mockit.Expectations;
import org.junit.Test;

public class FailedTest {

    @Test
    public void foo() {
        new Expectations(B.class) {{
            new B(anyString);
            times = 1;
        }};

        new B(""); // Always throws a null pointer exception due to `System.out.println(x.length());` below
    }

    class A {

        A(String x) {
            System.out.println(x.length());
        }
    }

    class B extends A {

        B(String x) {
            super(x);
        }
    }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions