-
Notifications
You must be signed in to change notification settings - Fork 240
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
Comments
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.
To: jmockit/jmockit1 jmockit1@noreply.github.com 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: ....Is this no longer possible? Note that I use a IBM JAVA 7 — |
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);
} |
Rogiero, thx for your answer. |
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. |
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
The text was updated successfully, but these errors were encountered: