Frage

I have some JSNI code that I would like to Unit test, so I decided to use gwt-test-utils' Patcher but for some reason it's not working...

I have followed and double checked my code and I can't get it to work.. I have a feeling that it's something very silly I'm forgetting, can anyone spot the problem?

Test:

@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);
}

}

View:

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

Did I miss anything?

Thanks for your time :)

War es hilfreich?

Lösung

You patched JSOMyConfig JSNI methods, but apparently not the MyView.getJSOMyConfig() one. Am I right ?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top