我嘗試這樣做,需要做的「嘲諷」的GAE運行中的某些懲戒:在谷歌的AppEngine運行
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中工作的模擬框架?
更新:
我發現了一個類似的問題的方式回到2010:
https://groups.google.com/forum/?fromgroups=#!topic/google-appengine-java/uIWRftGl-fA
但是無人接聽,直到如今。
好的工作回答了這個問題。嘗試通過回答所有問題來完成答案 – Ram