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

How to mock System with 1.16 #155

Closed
ascassel opened this Issue Mar 17, 2015 · 4 comments

Comments

3 participants
@ascassel

ascassel commented Mar 17, 2015

I used to mock java.System to ensure that the tested code uses System.exit() with the expected return code - but so far I only get java.lang.IllegalArgumentException: Matching real methods not found for the following mocks:
test.Test$4#exit(int)
at test.Test$4.(Test.java:178)
......
new MockUp<System>()
{
@mock
public void exit( int code )
{
//verification code here
}
};
....

Is this no longer possible? Note that I use a IBM JAVA 7

@marcdonovan

This comment has been minimized.

Show comment
Hide comment
@marcdonovan

marcdonovan Mar 17, 2015

Don't mock java internals. It only leads to misery. Ditto for using IBM java. If you are not on a mainframe, there is no excuse.

  From: ascassel <notifications@github.com>

To: jmockit/jmockit1 jmockit1@noreply.github.com
Sent: Monday, March 16, 2015 7:31 PM
Subject: [jmockit1] How to mock System with 1.16 (#155)

I used to mock java.System to ensure that the tested code uses System.exit() with the expected return code - but so far I only get java.lang.IllegalArgumentException: Matching real methods not found for the following mocks:
test.Test$4#exit(int)
at test.Test$4.(Test.java:178)
......
new MockUp()
{
@mock
public void exit( int code )
{
//verification code here
}
};

....Is this no longer possible? Note that I use a IBM JAVA 7 —
Reply to this email directly or view it on GitHub.

marcdonovan commented Mar 17, 2015

Don't mock java internals. It only leads to misery. Ditto for using IBM java. If you are not on a mainframe, there is no excuse.

  From: ascassel <notifications@github.com>

To: jmockit/jmockit1 jmockit1@noreply.github.com
Sent: Monday, March 16, 2015 7:31 PM
Subject: [jmockit1] How to mock System with 1.16 (#155)

I used to mock java.System to ensure that the tested code uses System.exit() with the expected return code - but so far I only get java.lang.IllegalArgumentException: Matching real methods not found for the following mocks:
test.Test$4#exit(int)
at test.Test$4.(Test.java:178)
......
new MockUp()
{
@mock
public void exit( int code )
{
//verification code here
}
};

....Is this no longer possible? Note that I use a IBM JAVA 7 —
Reply to this email directly or view it on GitHub.

@rliesenfeld

This comment has been minimized.

Show comment
Hide comment
@rliesenfeld

rliesenfeld Mar 17, 2015

Member

I am unable to see any problem. The following test works as expected:

    @Test
    public void mockSystemExit() {
        new MockUp<System>() {
            @Mock
            void exit(int i) {}
        };

        System.exit(1);
    }
Member

rliesenfeld commented Mar 17, 2015

I am unable to see any problem. The following test works as expected:

    @Test
    public void mockSystemExit() {
        new MockUp<System>() {
            @Mock
            void exit(int i) {}
        };

        System.exit(1);
    }
@ascassel

This comment has been minimized.

Show comment
Hide comment
@ascassel

ascassel Mar 18, 2015

Rogiero, thx for your answer.
You are right, it works in an Oracle JVM - but fails using the IBM one.
And yes, I need to be running on ZOS (thx Marc for the helpful comment... 8-) )
What frustrates more is that it worked in the 1.9 version..
Regards,
Achim

ascassel commented Mar 18, 2015

Rogiero, thx for your answer.
You are right, it works in an Oracle JVM - but fails using the IBM one.
And yes, I need to be running on ZOS (thx Marc for the helpful comment... 8-) )
What frustrates more is that it worked in the 1.9 version..
Regards,
Achim

@ascassel ascassel closed this Mar 18, 2015

@rliesenfeld rliesenfeld self-assigned this Mar 18, 2015

@rliesenfeld

This comment has been minimized.

Show comment
Hide comment
@rliesenfeld

rliesenfeld Mar 18, 2015

Member

I discovered why this isn't working anymore. It is described in the release notes for version 1.11: http://jmockit.org/changes.html#1.11

On the IBM JRE, java.lang.System gets explicitly excluded from mocking with a MockUp. This was done after seeing the test execution thread hanging up, when said class was mocked. It appears to be a bug in the IBM JVM; so, for safety, I decided to exclude java.lang.System entirely.

This isn't the only problem with the IBM JRE. On a developer machine which likely can use an Oracle JDK, I would recommed to use that for test execution. But if you have a ZOS build machine which can only use the IBM JRE, then there is no choice but to avoid mocking the System class.

Member

rliesenfeld commented Mar 18, 2015

I discovered why this isn't working anymore. It is described in the release notes for version 1.11: http://jmockit.org/changes.html#1.11

On the IBM JRE, java.lang.System gets explicitly excluded from mocking with a MockUp. This was done after seeing the test execution thread hanging up, when said class was mocked. It appears to be a bug in the IBM JVM; so, for safety, I decided to exclude java.lang.System entirely.

This isn't the only problem with the IBM JRE. On a developer machine which likely can use an Oracle JDK, I would recommed to use that for test execution. But if you have a ZOS build machine which can only use the IBM JRE, then there is no choice but to avoid mocking the System class.

@rliesenfeld rliesenfeld reopened this Mar 18, 2015

@rliesenfeld rliesenfeld added the other label Mar 18, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment