我正在尝试在 GAE 运行时中做一些需要“模拟”的事情:
private Mongo createMongo() {
Mongo mongo = Mockito.mock(Mongo.class);
...
}
但是,这显然会导致错误,因为“反射”是一个受限类:
java.lang.NoClassDefFoundError: sun.reflect.ReflectionFactory is a restricted class. Please see the Google App Engine developer's guide for more details.
at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.<init>(SunReflectionFactoryInstantiator.java:24)
at org.objenesis.strategy.StdInstantiatorStrategy.newInstantiatorOf(StdInstantiatorStrategy.java:65)
at org.objenesis.ObjenesisBase.getInstantiatorOf(ObjenesisBase.java:76)
at org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:59)
at org.mockito.internal.creation.jmock.ClassImposterizer.createProxy(ClassImposterizer.java:111)
at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:51)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:52)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:41)
at org.mockito.Mockito.mock(Mockito.java:1014)
at org.mockito.Mockito.mock(Mockito.java:909)
- 有什么解决方法吗?有没有办法让“反射”与 GAE 运行时一起工作?
- 是否有任何“仿真”库
sun.reflect
可以进行反射? - 也许,定义哪些类可以被反映?喜欢
@Reflectable
什么的 - 或者已经存在在 AppEngine 中工作的 Mock 框架?
更新:
我在 2010 年发现了一个类似的问题:
https://groups.google.com/forum/?fromgroups=#!topic/google-appengine-java/uIWRftGl-fA
然而直到现在都没有答案。