google-code-export / gwt-test-utils

Automatically exported from code.google.com/p/gwt-test-utils
1 stars 0 forks source link

Add getElementById in DOMPAtcher #148

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.
test a method that does
Element id = DOM.getElementById("ID");
if(loading != null) {
     DOM.removeChild(RootPanel.getBodyElement(), id); 
     RootPanel.get("APP").add(appPanel);
}

 - ID is a DIV in the HTML host page that has to be removed once some data has been loaded
 - APP is the DIV in the HTML host page where to inject the application
 - appPanel is a IsWidget that is the root node of the application

What is the expected output? What do you see instead?
I expect to have, at least, a NO-OP behavior but no error.
I got a 
java.lang.NoSuchMethodError: 
com.google.gwt.user.client.DOM.getElementById(Ljava/lang/String;)Lcom/google/gwt
/user/client/Element;

What version of the product are you using? On what operating system?
0.38 with Mockito
Windows XP

Please provide any additional information below.

I tried to create my own DOMPatcher but I didn't succeed. Maybe my patcher is 
not taken into account but my other patchers (in the same package) are so I 
guess my patcher is ok.

@PatchClass(DOM.class)
public class DOMPatcherOverride {

    @PatchMethod
    public static Element getElementById(String eltId) {
        return null;
    }

}

I also tried with @PatchMethod(override=true)
and with 
@PatchClass(target="com.googlecode.gwt.test.internal.patchers.dom.DOMPatcher")

If my patcher worked it would be enough for me, but I think this is a quite 
common behavior to have in GWT apps so maybe it could be integrated in 
gwt-test-utils ?

Regards

Original issue reported on code.google.com by david.le...@gmail.com on 9 Jul 2012 at 11:26

GoogleCodeExporter commented 9 years ago
There is something wrong with your "NoSuchMethodError" : DOM.getElementById() 
is not patched by the DOMPatcher. Its implementation relies on 
"Document.get().getElementById(id).cast();", patched in  DocumentPatcher.

Could you please copy/paste the entire stacktrace ?

Original comment by gael.laz...@gmail.com on 9 Jul 2012 at 1:08

GoogleCodeExporter commented 9 years ago
BTW, 
@PatchClass(target="com.googlecode.gwt.test.internal.patchers.dom.DOMPatcher") 
is a very bad practice ;)

Original comment by gael.laz...@gmail.com on 9 Jul 2012 at 1:10

GoogleCodeExporter commented 9 years ago
Hello,

my complete stack trace (I skipped some lines related to my own class hierarchy)

java.lang.NoSuchMethodError: 
com.google.gwt.user.client.DOM.getElementById(Ljava/lang/String;)Lcom/google/gwt
/user/client/Element;
    at ...
com.googlecode.gwt.test.GwtTestWithMockito$FailureAnswer.answer(GwtTestWithMocki
to.java:46)
    at org.mockito.internal.stubbing.StubbedInvocationMatcher.answer(StubbedInvocationMatcher.java:34)
    at org.mockito.internal.MockHandler.handle(MockHandler.java:99)
    at org.mockito.internal.InvocationNotifierHandler.handle(InvocationNotifierHandler.java:36)
    at org.mockito.internal.creation.MethodInterceptorFilter.intercept(MethodInterceptorFilter.java:48)
    at com.thales.primavera.extensions.pmdesk.gwt.common.server.PortalServiceAsync$$EnhancerByMockitoWithCGLIB$$fc2360c0.getSession(<generated>)
    at com.thales.primavera.extensions.pmdesk.gwt.common.client.event.PMDeskUserConnectedEventHandler.onUserConnected(PMDeskUserConnectedEventHandler.java:76)
    at com.thales.primavera.extensions.pmdesk.gwt.common.client.event.PMDeskUserConnectedEventHandlerTest.testOnUserConnectedFailure(PMDeskUserConnectedEventHandlerTest.java:54)
    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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at com.googlecode.gwt.test.internal.runner.AbstractGwtRunner.run(AbstractGwtRunner.java:40)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Patching Document.class was my first attempt but I had the same error.

Regards

Original comment by david.le...@gmail.com on 10 Jul 2012 at 10:12

GoogleCodeExporter commented 9 years ago
I suspect some error with mockito and classloaders. Could you please update to 
the lastest 0.40-SNAPSHOT, where I made some change on mock supports ? 
Before upgrading, you should carefully read this : 
http://code.google.com/p/gwt-test-utils/wiki/MigrationTo040

Original comment by gael.laz...@gmail.com on 20 Jul 2012 at 5:35