I am a big fan of mockito, unfortunately for one of my projects which uses Java 8, it fails on me...
Scenario:
public final class MockTest
{
@Test
public void testDefaultMethodsWithMocks()
{
final Foo foo = mock(Foo.class);
//when(foo.bar()).thenCallRealMethod();
assertThat(foo.bar()).isEqualTo(42);
}
@FunctionalInterface
private interface Foo
{
int foo();
default int bar()
{
return 42;
}
}
}
Unfortunately, the test fails and foo.bar()
returns 0.
When I uncomment the when()
line, I get a stack trace...
java.lang.NoSuchMethodError: java.lang.Object.bar()I
at com.github.fge.lambdas.MockTest.testDefaultMethodsWithMocks(MockTest.java:18)
This is the latest stable version available on maven; googling around didn't tell me much about the status of mockito with regards to this new functionality in Java 8...
Can you make it work in some other way than implementing interfaces and spy()
on them (this works)?