-
Notifications
You must be signed in to change notification settings - Fork 239
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
Injectable and Mock static methods of the same class #1
Comments
You can write the test with @Cascading, which is simpler: public class InetAddressTest {
} That said, not mocking InetAddress would be better, if that's an option. On Fri, Jul 11, 2014 at 8:39 PM, Colin Hebert notifications@github.com
|
I'd love to not mock |
Regarding the solution itself, my bad I should have given a more detailed example of what I need:
In this case, the resolution to reddit.com still works with the default behaviour (using 1.8), which is perfect as it's exactly what I need. The problem with mocking classes such as InetAddress is that some subsystems might depend on it, so the less modifications to the default behaviour, the better. EDIT: changed google.com to reddit.com (google tends to have servers with different hostnames), that doesn't change the point though. |
This is a tough one. If the duplicate mocking of InetAddress is allowed, then what to make of a call to "mockInetAddressRemote.getCanonicalHostName()"? Should it be mocked according to the @Injectable mocking, or according to the partial mocking? In the first case, this method call would simply return null without doing anything; in the second, it would execute the real implementation of "getCanonicalHostName()", since no expectation was recorded for it. Incidentally, I noticed that if that call is made using JMockit 1.8, a JVM crash occurs! I will need to investigate it later. |
I would expect the first behaviour. The |
Yes, it makes more intuitive sense, except that partial mocking is applied later during the execution of the test, so pre-JMockit 1.9 it would always override the @Injectable mocking. I am considering changing the semantics in cases like this, so that instance methods already mocked through an @Injectable are disregarded if the same class is partially mocked later in the test. But it needs more thinking; an idea that occurs is that the use of a "MockUp" may be a better choice here. |
The current semantics will be changed so that @Injectable instances are unaffected by an eventual partial mocking of the same class. |
… unaffected, if there are any of the same class. Fixes issue #1.
This test used to work with JMockit 1.8, stopped working with JMockit 1.9
The problem here is that JMockit complains about the class being already mocked.
This is fair enough, but what is the recommended approach when I need to mock a static method from a class while having an
Injectable
value as well?The text was updated successfully, but these errors were encountered: