--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/ed2c783e-563b-4061-b0a3-77a2fc99b63bn%40googlegroups.com.
If you want to invoke the real method when invoking `MyStaticClass.speak()`, you can add the following stub:
MyStaticClassMock.when(MyStaticClass::speak).thenCallRealMethod();Op zo 17 jan. 2021 om 20:01 schreef Anesti Andrioti <anestia...@gmail.com>:
Hello,I've read that I can mock static methods since 3.4.0I am trying to mock a static method that is used in another static method, but I am having issues with this.What I am looking for, is something like the bellow
public class MyStaticClass {public static String speak() {
return saySpeech();
}public static String saySpeech() {return "Speech"}}@Testvoid myTest() {try (MockedStatic<MyStaticClass> MyStaticClassMock = Mockito.mockStatic(MyStaticClass.class)) {MyStaticClassMock.when(MyStaticClass::saySpeach).thenReturn("MockedSpeech");assertEquals("MockedSpeech", MyStaticClass.speak());}assertEquals("Speech", MyStaticClass.speak());}
I would appreciate any help!
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/49acf7fe-1cd1-4ab5-ba9d-9ec011cae979n%40googlegroups.com.