Jmockit + Robolectric

29 views
Skip to first unread message

Fabriceli Fabrice

unread,
Jul 28, 2020, 3:28:35 AM7/28/20
to Robolectric
Hi, Could you give me some tips about how to use Jmockit and Robolectric? I made some test demo, but i got the error:
java.lang.RuntimeException: java.lang.NoSuchMethodException: com.xxxx.xxxx.app.ReceivedMsgNotificationHelperTestJmockit.testIsBaseBusinessMessage_hiddenChat()

at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:236)
at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:89)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoSuchMethodException: com.xxxx.xxxx.app.ReceivedMsgNotificationHelperTestJmockit.testIsBaseBusinessMessage_hiddenChat()
at java.lang.Class.getMethod(Class.java:1786)
at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:234)
... 5 more

Infos:
OS: Mac OS
JAVA: JDK 1.8.261 
JMockit: 1.49
Robolectric: 4.3.1
Junit: 4.13 


@RunWith(RobolectricTestRunner.class) 
public class ReceivedMsgNotificationHelperTestJmockit {

@Mocked
MessageMocker messageMocker;

public static class AppInterfaceMockUp extends MockUp<AppInterface> {
@Mock
public void $init(BaseApplicationImpl baseApplication, String processname) {}
@Mock
public void $clinit() {}
}

@Test
public void testIsBaseBusinessMessage_hiddenChat(@Injectable BaseApplicationImpl baseApplication) throws Exception {
final Message message = messageMocker.simpleMessage();
new AppInterfaceMockUp();
final AppInterface app = new AppInterface(baseApplication, "processname");

new Expectations(){
{
HiddenChatHelper.isHiddenChat(message.frienduin, message.istroop, app);
result = true;
}
};
boolean res = HiddenChatHelper.isHiddenChat(message.frienduin, message.istroop, app);
Assert.assertTrue(res);
}

}

 
Reply all
Reply to author
Forward
0 new messages