-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Description
Hello,
It seems that spying on interfaces to use real implementations of defender (default) interface methods is not working anymore with Java 17.
Java 17 (Temurin) :
openjdk version "17.0.2" 2022-01-18
OpenJDK Runtime Environment Temurin-17.0.2+8 (build 17.0.2+8)
OpenJDK 64-Bit Server VM Temurin-17.0.2+8 (build 17.0.2+8, mixed mode, sharing)
Tested Mockito versions : 3.3.3 and 4.3.1
Reproducing sample (working with JDK 11) :
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.spy;
import org.junit.jupiter.api.Test;
public class MockitoJava17Issue {
@Test
public void testMockitoIssue() {
MyInterface myInterface = spy(MyInterface.class);
assertEquals("default", myInterface.name());
}
}
interface MyInterface {
default String name() {
return "default";
}
}
->
org.mockito.exceptions.base.MockitoException:
Cannot call abstract real method on java object!
Calling real methods is only possible when mocking non abstract method.
//correct example:
when(mockOfConcreteClass.nonAbstractMethod()).thenCallRealMethod();
Metadata
Metadata
Assignees
Labels
No labels