1
我有一些JSNI代碼,我想單元測試,所以我決定使用GWT測試-utils的修補程式,但由於某種原因它不工作...gwt-test-utils:JSO Patcher不工作?
我按照和雙重檢查我的代碼和我無法讓它工作..我有一種感覺,這是非常愚蠢的,我忘記了,任何人都可以發現問題?
測試:
@GwtModule("com.my.app.gwt.client.view.MyView")
public class MyViewTest extends GwtTest {
private MyView mView;
@Before
public void setUp() {
mView = new MyView(Mockito.mock(MyView.Binder.class));
}
@Test
public void shouldGetMyConfigAndParse() {
MyConfig oMyConfig = mView.getMyConfig();
System.out.println("########## oMyConfig=" + oMyConfig);
assertTrue(true);
}
}
查看:
public class MyView extends ViewImpl implements MyPresenter.MyView {
interface Binder extends UiBinder<Widget, MyView> {
}
@UiField SimplePanel mMainPanel;
@Inject
public MyView(Binder pBinder) {
initWidget(pBinder.createAndBindUi(this));
}
@Override
public void setInSlot(Object pSlot, IsWidget pContent) {
if (pSlot == MyPresenter.SLOT_MAIN) mMainPanel.setWidget(pContent);
else super.setInSlot(pSlot, pContent);
}
@Override
public MyConfig getMyConfig() {
JSOMyConfig oJSOConfig = getJSOMyConfig();
MyConfig oConfig = new MyConfig();
oConfig.setAutoPlay(oJSOConfig.isAutoPlay());
oConfig.setWidth(oJSOConfig.getWidth());
oConfig.setHeight(oJSOConfig.getHeight());
return oConfig;
}
private native JSOMyConfig getJSOMyConfig()/*-{
return $wnd.myConfig;
}-*/;
}
JSO
public class JSOMyConfig extends JavaScriptObject {
protected JSOMyConfig() { }
public native boolean isAutoPlay() /*-{
return this.autoPlay;
}-*/;
public native String getWidth() /*-{
return this.width;
}-*/;
public native String getHeight() /*-{
return this.height;
}-*/;
}
JSOPatcher
@PatchClass(JSOMyConfig.class)
public class JSOMyConfigPatcher {
@PatchMethod
public static boolean isAutoPlay(JSOMyConfig JSOMyConfig) {
return false;
}
@PatchMethod
public static String getWidth(JSOMyConfig JSOMyConfig) {
return "500";
}
@PatchMethod
public static String getHeight(JSOMyConfig JSOMyConfig) {
return "400";
}
}
META-INF/gwt-test-utils.properties:
com.my.app.gwt.client.config.model.jso = scan-package
com.my.app.gwt.client.view.MyView = gwt-module
我錯過了什麼?
感謝您的時間:)
真棒,似乎已經奏效!但現在我得到了:「GwtTestPatchException:覆蓋類型'com.my.app.gwt.client.config.model.jso.JSOMyConfig'還沒有找到,你忘了繼承一些GWT模塊。」任何想法?我確實有: 。但似乎沒有工作.. –