google / gwtmockito

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

java.lang.ClassCastException: com.google.gwt.user.client.Element$$EnhancerByMockitoWithCGLIB$$492e40ea cannot be cast to com.google.gwt.dom.client.InputElement #40

Closed supertoy closed 9 years ago

supertoy commented 9 years ago

When i test a wiget which include some textbox got the error.

Java.lang.ClassCastException: com.google.gwt.user.client.Element$$EnhancerByMockitoWithCGLIB$$492e40ea cannot be cast to com.google.gwt.dom.client.InputElement
    at com.google.gwt.user.client.ui.TextBox.getInputElement(TextBox.java:137)
    at com.google.gwt.user.client.ui.TextBox.setMaxLength(TextBox.java:124)
    at xxxx.EndPointWidget.initForm(EndPointWidget.java:62)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at com.google.gwtmockito.GwtMockitoTestRunner.run(GwtMockitoTestRunner.java:301)

Target class is here:

 private final TextBox serveripValueWidget = new TextBox();
 public EndPointWidget() {
        initForm();
  }

 private void initForm() {
        serveripValueWidget.setMaxLength(50);
}

Test case is here:

    @Test
    public void setData() {
        EndPointWidget epw = new EndPointWidget(); //error happen.
    }
ekuefler commented 9 years ago

Thanks for the clear report / repro case. Looks like the same sort of issue as #33. Should be fixed in the latest snapshot now if you'd like to try it out.