google / gwtmockito

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

Problem mocking SimplePager #42

Closed lofidewanto closed 9 years ago

lofidewanto commented 10 years ago

GWT: 2.6.1 GWTMockito: 1.1.4

I try to test my UI class which uses following SimplePager class:

....
    @UiField(provided = true)
    DataGrid<LaboruserValue> dataGrid = new DataGrid<LaboruserValue>(33);

    private final SimplePager dataGridPager = new SimplePager();

....
    // Somewhere in the method I call following: 
    dataGridPager.setDisplay(dataGrid);

In this setDisplay(dataGrid) method I always get following exception:

java.lang.StringIndexOutOfBoundsException: String index out of range: 0 at java.lang.String.charAt(String.java:658) at com.google.gwt.i18n.client.NumberFormat.format(NumberFormat.java:1146) at com.google.gwt.i18n.client.NumberFormat.format(NumberFormat.java:927) at com.google.gwt.user.cellview.client.SimplePager.createText(SimplePager.java:566) at com.google.gwt.user.cellview.client.SimplePager.onRangeOrRowCountChanged(SimplePager.java:573) at com.google.gwt.user.cellview.client.AbstractPager.setDisplay(AbstractPager.java:137) at com.google.gwt.user.cellview.client.SimplePager.setDisplay(SimplePager.java:522) at de.generatio.client.laboruser.Laboruser.initTable(Laboruser.java:268) at de.generatio.client.laboruser.Laboruser.(Laboruser.java:125) at de.generatio.client.laboruser.LaboruserTest.setUp(LaboruserTest.java:26) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) 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.RunBefores.evaluate(RunBefores.java:27) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 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) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 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)

Any ideas?

Thanks, Lofi

ekuefler commented 9 years ago

Thanks for the report - looks like GwtMockito didn't have any locale data available, which was causing issue inside the number formatter. I've set it up in 76935fef45b10de7982469fbe6427ec59533210c to hardcode some English locale data by default. The latest snapshot should work now, or if you want to work around the issue in the current version of GwtMockito you can use GwtMockito.useProviderForType to provide a fake NumberConstantsImpl in the same way I did in 76935fef45b10de7982469fbe6427ec59533210c.

lofidewanto commented 9 years ago

Thanks, it works now.