在.java文件中运行的测试在放入.groovy文件时会引发异常。那是为什么?
代码:
@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)