Powermock spöttische Void-Methode wirft Fehler

Ich benutze Powermockito, mockito mit TestNG. Meine Testklasse erweitert PowerMockTestCase. Ich möchte eine leere Methode verspotten. Dafür habe ich folgende Beispielsyntax verwendet:

@PrepareForTest(TestClass.class)
class Sample extends PowerMockTestCase{

@BeforeClass
public void beforeClass(){
TestClass obj = PowerMockito.spy(TestClass.getInstance());
PowerMockito.doNothing().when(obj).voidMethodName(Matchers.any(Type1.class), Matchers.anyString(), Matchers.any(Type2.class));
}

Wenn ich das gebe, bekomme ich:

FAILED CONFIGURATION: @BeforeClass beforeClass
org.mockito.exceptions.misusing.UnfinishedStubbingException: 
Unfinished stubbing detected here:
-> at org.powermock.api.mockito.internal.PowerMockitoCore.doAnswer(PowerMockitoCore.java:36)

E.g. thenReturn() may be missing.
Examples of correct stubbing:
    when(mock.isOk()).thenReturn(true);
    when(mock.isOk()).thenThrow(exception);
    doThrow(exception).when(mock).someVoidMethod();
Hints:
 1. missing thenReturn()
 2. you are trying to stub a final method, you naughty developer!

önnen Sie mir bitte mitteilen, was ich hier vermiss

Vielen Dan

Antworten auf die Frage(2)

Ihre Antwort auf die Frage