JMockit抛出"没有名为java_lang_System $ currentTimeMillis"的类。从Groovy使用时

时间:2015-12-15 01:59:25

标签: java groovy jmockit

在.java文件中运行的测试在放入.groovy文件时会引发异常。那是为什么?

  • Groovy:2.3.9
  • JMockit:1.20
  • Java:1.8.0_60

代码:

@Test
public void testSystemCurrentTimeMillis(@Mocked final System unused) {
    new NonStrictExpectations() {{
        System.currentTimeMillis(); result = 1438357206679L;
    }};
    long currentTime = System.currentTimeMillis();
    Assert.assertEquals(1438357206679L, currentTime);
}

例外:

java.lang.IllegalArgumentException: No class with name "java_lang_System$currentTimeMillis" found

    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
    at x.GroovyTest$1.<init>(GroovyTest.groovy:12)
    at x.GroovyTest.testSystemCurrentTimeMillis(GroovyTest.groovy:11)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

0 个答案:

没有答案