google / gwtmockito

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

AssertionError in LabelBase #21

Closed mwohlf closed 10 years ago

mwohlf commented 10 years ago

Hi guys, I am using gwtmockit 1.1.2 with gwt 2.5.0 to write tests for a MVP Application. One of my Tests creates an AssertionError, a simple Testcase that reproduces the Problem looks like this:

@Test
public void featureTest() {
    InlineHTML inline = new InlineHTML("hello world");
    assertNotNull(inline);
}

this creates the following stacktrace:

java.lang.AssertionError at com.google.gwt.user.client.ui.LabelBase.(LabelBase.java:61) at com.google.gwt.user.client.ui.LabelBase.(LabelBase.java:57) at com.google.gwt.user.client.ui.Label.(Label.java:199) at com.google.gwt.user.client.ui.HTML.(HTML.java:168) at com.google.gwt.user.client.ui.InlineHTML.(InlineHTML.java:79) at com.google.gwt.user.client.ui.InlineHTML.(InlineHTML.java:125)

I am using @RunWith(GwtMockitoTestRunner.class) am i doing something wrong or is this a know limitation? thanks for your help!

ekuefler commented 10 years ago

Thanks for reporting this. Looks like the issue is that the LabelBase makes an assertion that doesn't play nicely with the GwtMockito-generated stubs. This should be fixable by adding LabelBase to the set of base classes to stub, and ensuring that we're stubbing constructors in addition to methods. I've done this in 754ec50c90e99bec373647cee3a2485f5146dce6 and pushed a new snapshot. Can you check if this resolves your problem?

mwohlf commented 10 years ago

Hi Erik, thanks for your help, I am getting a NPE now:

java.lang.NullPointerException at com.google.gwt.user.client.ui.HTML.setHTML(HTML.java:183) at com.google.gwt.user.client.ui.InlineHTML.<init>(InlineHTML.java:126)

In general I can work around this kind of problem by mocking the whole view component that contains the "new InlineHTML()" or similar calls.

However in order to run tests I also need to reproduce the view's behaviour with mockito's "when(viewComponent.methodCall()).thenReturn(viewResult)" setups.

My impression was that with gwtmockito I can just instantiate the view and get some kind of java version of the view that behaves almost like the original gwt/JS view. This way I need to do less of mockito's when().thenReturn() magic. Is this something gwtmockito intends to do?

Thanks again for your help! Michael

paulharrington1000 commented 10 years ago

I am also encountering this problem using 1.1.2. I was wondering wil thi sbe fixed in the next release of GWTMockito. If so when will this be available as a jar?

Thank you

Paul

ekuefler commented 10 years ago

Okay, got the chance to take another look into this. It looks like instantiating the HTML object was fixed, but actually calling setHTML wasn't. I think I've found a better solution to the problem by telling GwtMockito to actually try and return realistic tag names for the elements it generates, which avoids the assertion issue in the first place. I've committed this as 815bffe90f89f60e594c909a474bb150b941ed19 and published a snapshot, could you let me know if it fixes your issue?

paulharrington1000 commented 10 years ago

Sorry I took a while to get round to this. I downloaded the latest code from source, built it and it does fix the issue.

Thank you very much

Paul