-
-
Notifications
You must be signed in to change notification settings - Fork 314
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
New <T, R> R createMock(Class<T> toMock) signature fails when used for vararg calls #259
Comments
Interesting. I need to put some more thought into this new typing. The real mitigation is |
Interesting, too. I have not used type witnesses in years. I guess the change to the signature was made to improve things, and that this example is very specific. It seems very counter intuitive that I have to do anything when mocking arguments to a method call on the fly, just because the method takes a vararg. |
Yes. The change made is possible to mock generics (e. g. So I might rollback the change and add some |
I have to admit: our team is mostly into Mockito these days. Having said that: the problem with "yet another" mockXXX() method that I see: having createMock, createNiceMock, createStrictMock ... is confusing enough already. Unfortunately more degrees of freedom ... mean more things one has to know about. It really depends on what you think the underlying "theme" of EasyMock is, and how that comes into play here. |
Mockito has the same problem. It is super annoying to use because of that. I mock generics a lot. There are 3 solutions I'm aware of:
|
I guess the real answer is somehow different ... for us. We simply changed the way we write our unit tests. The test I had in my production code that failed was like: @Test(expected=NullPointerException.class)
public void testCtorWithNullWhatever() {
new Foo(null, createMock(Bar.class));
} Where the Bar parameter is actually a vararg. Nowadays, I write the same test in a way that doesn't care about the signature of "create" methods: @Mock
private Bar someBar;
@Test(expected=NullPointerException.class)
public void testCtorWithNullWhatever() {
new Foo(null, someBar);
} My "main" point of this issue is the fact that our existing tests stopped working, and required a strange change to be working again ... |
Yes. I broke compatibility in some inference cases like this one. My hope was that they were pretty rare but that you can now remove a lot of |
See this code:
When I compile and run this with EasyMock 3.4, the output I get is:
But when I run it with EasyMock 4, the output is:
In other words: the old
<T> T createMock(Class<T> toMock)
ensures that the compiler sees B required, and thus ensures that the argument is pushed into the required array. With the new signature, things go haywire.Sure, it can be mitigated by adding that cast, but that feels really wrong.
The text was updated successfully, but these errors were encountered: