google / gwtmockito

Better GWT unit testing
https://google.github.io/gwtmockito
Apache License 2.0
157 stars 51 forks source link

LayoutComposite requires that its wrapped widget implement RequiresResize #15

Closed nikp closed 11 years ago

nikp commented 11 years ago

I have a widget which extends ResizeComposite, and I'm using the GwtMockitoTestRunner

The call inside the constructor initWidget(uiBinder.createAndBindUi(this)); fails with this exception because initWidget inside ResizeComposite has the following assert:

    assert widget instanceof RequiresResize :
      "LayoutComposite requires that its wrapped widget implement RequiresResize";

I have a feeling this is related to https://github.com/google/gwtmockito/issues/4, but perhaps not.

I realize uiBinder is a FakeUiBinder, but I think it should ensure that the mocks it returns do more than just initialize the UiFields, it should also ensure to implement all the original interfaces of the owner widget.

ekuefler commented 11 years ago

Could you show how you're setting up your UiBinder? This seems to work for me:

interface MyUiBinder extends UiBinder<DataGrid, MyClass> {}
private final MyUiBinder uiBinder = GWT.create(MyUiBinder.class);
MyClass() {
  initWidget(uiBinder.createAndBindUi(this));
}

However, it only works if I declare the UiBinder to extend UiBinder<DataGrid, MyClass>, not UiBinder<Widget, MyClass>. This makes sense, since if you declare it to return a widget there's no way for GwtMockito to know you need to implement RequiresResize. Any chance this is the problem, or am I misunderstanding?

While debugging this I did find an unrelated bug that GwtMockito wasn't handling UiBinders that return a generic type properly - I fixed that in 8706592b3be57d06a1e9f724f836f8bc98a39dc4 in case you run into it.

nikp commented 11 years ago

You are absolutely right, that is the difference!

Though your bug fix seems like it could be related too, because my UI binder was defined like:

interface MyViewImplUiBinder extends UiBinder<Widget, MyViewImpl<T>> {}