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

Unable to use JMock 2.6.0 with Java 8 #60

Closed
muminc opened this issue Apr 7, 2014 · 7 comments
Closed

Unable to use JMock 2.6.0 with Java 8 #60

muminc opened this issue Apr 7, 2014 · 7 comments
Assignees
Milestone

Comments

@muminc
Copy link

muminc commented Apr 7, 2014

Out of curiosity, tried to build an existing project (which uses 7) with Java 8 (source = 1.8, target=1.8) but I see many of these errors emitted by the Java 8 Compiler.

error: reference to with is ambiguous  both method with(Matcher<Float>) in Expectations and method with(Matcher<Double>) in Expectations match
@muminc
Copy link
Author

muminc commented Apr 7, 2014

I can confirm, if I build jmock (2.7.0-SNAPSHOT) and use this instead, Java 8 build works fine.

When will 2.7.0 be released?

@jh1234
Copy link

jh1234 commented May 22, 2014

we have same problems. any changes?

@mread
Copy link

mread commented Oct 17, 2014

Also interested. What is the upgrade path for Java 8? We have 3000+ tests and I'm trying to find the least invasive way to get to a version of JMock that will support Java 8. The latest master gives me this error for tests are using @RunWith(JMock.class) - more than just deprecated perhaps?

java.lang.IllegalStateException: Mockery named 'mockery' is null
    at org.jmock.integration.junit4.JMock.mockeryOf(JMock.java:67)
    at org.jmock.integration.junit4.JMock.createTest(JMock.java:35)
    at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:244)
...

@mikerimov
Copy link

I too had this problem but after looking at the code I suspect that it is an issue with the JDK 1.8 compiler. In my case the code that wouldn't compile was:

oneOf(something).method(with(anything()));

By adding a cast like so:

oneOf(something).method(with( (Matcher<Object>)anything() ) ) )

(Change the cast to whatever your argument type is)
And it then compiled for me. Also note that the eclipse compiler for me (Luna) compiles it correctly.

@mread
Copy link

mread commented Oct 20, 2014

... or use the new with primitive methods, e.g. with.floatIs(any(Float.class))

@bsiver
Copy link

bsiver commented Jan 29, 2015

Thanks @mread, I had some issues using parameterized types in expectations after upgrading to JDK 8:

oneOf(something).method(with(any(X.class)))

Started to generate a compiler error:
The method something(X<Y>) in the type Something is not applicable for the arguments (X).

Changing the expectation to

oneOf(something).method(with.is(any(X.class)))

fixed the compiler error.

@olibye olibye self-assigned this Mar 21, 2015
@olibye olibye added this to the 2.8 milestone Mar 21, 2015
@olibye olibye modified the milestones: 2.7, 2.8 Apr 15, 2015
@olibye
Copy link
Member

olibye commented Apr 17, 2015

Solved in 2.8.0, in maven central now.

@olibye olibye closed this as completed Apr 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants