also I found this article interesting: http://blog.danielwellman.com/2009/02/mocking-gwt-widgets-with-gwtmockutilities.html
On Wed, Aug 19, 2009 at 12:28 PM, Alejandro D. Garin <[email protected]>wrote: > David, > > Maybe GWTMockUtilities could help, but didn't tried it. > > On Wed, Aug 19, 2009 at 12:19 PM, davis <[email protected]>wrote: > >> >> Probably stems from the constructor doing this: >> >> /** >> * Creates an empty text box. >> */ >> public TextBox() { >> this(Document.get().createTextInputElement(), "gwt-TextBox"); >> } >> >> >> http://code.google.com/p/google-web-toolkit/source/browse/releases/1.7/user/src/com/google/gwt/user/client/ui/TextBox.java >> >> Anyone have a mock workaround for ui elements they'd like to share? >> Is there a mock framework out there for GWT ui elements? >> >> On Aug 19, 11:14 am, davis <[email protected]> wrote: >> > My fault -- I thought you were talking about something else. It >> > appears you are correct. It looks like even easy mock class extension >> > can't do it. Somewhere in the initialization code of TextBox.class it >> > calls GWT.create()...major bummer. >> > >> > On Aug 19, 10:59 am, "Alejandro D. Garin" <[email protected]> wrote: >> > >> > > Hi David, >> > >> > > I tried your example, but I have this error: >> > >> > > Caused by: java.lang.UnsupportedOperationException: ERROR: >> GWT.create() is >> > > only usable in client code! It cannot be called, for example, from >> server >> > > code. If you are running a unit test, check that your test case >> extends >> > > GWTTestCase and that GWT.create() is not called from within an >> initializer >> > > or constructor. >> > >> > > Stacktrace: >> > >> > > java.lang.ExceptionInInitializerError >> > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> > > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >> > > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) >> > > at java.lang.reflect.Method.invoke(Unknown Source) >> > > at >> net.sf.cglib.proxy.Enhancer.setCallbacksHelper(Enhancer.java:619) >> > > at >> net.sf.cglib.proxy.Enhancer.setThreadCallbacks(Enhancer.java:612) >> > > at >> net.sf.cglib.proxy.Enhancer.registerCallbacks(Enhancer.java:581) >> > > at >> > > >> org.easymock.classextension.internal.ClassProxyFactory.createProxy(ClassProxyFactory.java:108) >> > > at >> org.easymock.internal.MocksControl.createMock(MocksControl.java:51) >> > > at >> org.easymock.classextension.EasyMock.createMock(EasyMock.java:46) >> > > at >> example.publico.client.SimpleTest.testSimple(SimpleTest.java:10) >> > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> > > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >> > > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) >> > > at java.lang.reflect.Method.invoke(Unknown Source) >> > > at junit.framework.TestCase.runTest(TestCase.java:168) >> > > at junit.framework.TestCase.runBare(TestCase.java:134) >> > > at junit.framework.TestResult$1.protect(TestResult.java:110) >> > > at junit.framework.TestResult.runProtected(TestResult.java:128) >> > > at junit.framework.TestResult.run(TestResult.java:113) >> > > at junit.framework.TestCase.run(TestCase.java:124) >> > > at junit.framework.TestSuite.runTest(TestSuite.java:232) >> > > at junit.framework.TestSuite.run(TestSuite.java:227) >> > > at >> > > >> org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:76) >> > > at >> > > >> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45) >> > > at >> > > >> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) >> > > at >> > > >> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) >> > > at >> > > >> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) >> > > at >> > > >> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) >> > > at >> > > >> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) >> > > Caused by: java.lang.UnsupportedOperationException: ERROR: >> GWT.create() is >> > > only usable in client code! It cannot be called, for example, from >> server >> > > code. If you are running a unit test, check that your test case >> extends >> > > GWTTestCase and that GWT.create() is not called from within an >> initializer >> > > or constructor. >> > > at com.google.gwt.core.client.GWT.create(GWT.java:85) >> > > at >> com.google.gwt.user.client.ui.UIObject.<clinit>(UIObject.java:140) >> > > ... 30 more >> > >> > > On Wed, Aug 19, 2009 at 11:09 AM, davis <[email protected] >> >wrote: >> > >> > > > > If your view interface return a TextBox you can't test the >> presenter with >> > > > > JUnit, you will need to use GWTTestCase. >> > >> > > > Sure you can: >> > >> > > > import static org.easymock.classextension.EasyMock.*; >> > > > import com.google.gwt.user.client.ui.TextBox; >> > >> > > > public class SomePresenterTestCase { >> > >> > > > private MyPresenter presenter; >> > > > private MyView view; >> > >> > > > @Test >> > > > public void testSomething() { >> > > > TextBox mockBox = createMock(TextBox.class); >> > > > MyView mockView = createMock(MyView.class); >> > > > presenter = new MyPresenter(mockView); >> > > > expect(mockView.getSomeTextBox()).andReturn(mockBox); >> > > > replay(mockView); >> > > > replay(mockBox); >> > > > TextBox box = presenter.getDisplay().getSomeTextBox(); >> > > > verify(mockView); >> > > > } >> > > > } >> >> >> > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en -~----------~----~----~----~------~----~------~--~---
