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

Mocking call chain does not work for public interface hierarchy in multiple tests #420

Closed
Milbor-zz opened this issue May 29, 2017 · 0 comments
Assignees
Labels

Comments

@Milbor-zz
Copy link

1.32
testng 6.9.10

when whole test class run - test1 passes, test2 fails with NPE when mocking call chain.
Passes in 1.31.
Is this bug? I don't see anything relevant in release notes.
Please see comments in code. Interface and class public visibility affects test result.

public class SpikeTest {
    @Injectable
    private SubInterface subInterface;

    @Test
    public void test1() {
        test();
    }

    @Test
    public void test2() {
        test();
    }

    private void test() {
        final String expected = "mocked";
        new Expectations() {{
            subInterface.getData().get();
            result = expected;
        }};
        final String actual = subInterface.getData().get();
        assertSame(actual, expected);
    }

    interface ParentInterface {
        Data getData();
    }

    // both tests pass with default visibility
    public interface SubInterface extends ParentInterface {
    }

    // first test fails with default visibility
    // java.lang.IllegalAccessError: tried to access class SpikeTest$Data from class $Impl_SubInterface
    public static class Data {
        String get() {
            throw new UnsupportedOperationException();
        }
    }
}
@rliesenfeld rliesenfeld self-assigned this May 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants