google-code-export / gwt-test-utils

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

doSuccessCallback uses first Mockito stubber rather than last one created #172

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a test that on each run, stubs a success callback that returns a list 
of items.
2. Using junitparams, create a class that calls a test multiple times with 
different parameters.
3. In your test, using the first parameter, have the stubber return one item in 
the list. Then for the second parameter, have the stubber return 2 items in 
it's list.

What is the expected output? What do you see instead?
The first parameter test i would expect the list to return one item. It does.
The second parameter test i would expect the list to return two items. It 
doesn't, it returns the original list from the first time the stubber was 
created.

What version of the product are you using? On what operating system?
0.44, Win 7 64

Please provide any additional information below.

@Test
public void testSaveFooClick()
{
   <Scaffolding to setup the presenter's properties. Sets "foos" to a List of two Foos.>

   ...

   // Get the current List of Foos in the presenter.
   List< Foo > foos = field( "foos" ).ofType( new TypeRef< List< Foo >>(){} ).in( presenter ).get();

   // size will be 2.
   int size = foos.size();

   // Setup the List for the AsyncCallback return.
   // English will return one Foo.
   Collection< Foo > returnFoos = new ArrayList< Foo >( 2 );
   Foo englishFoo = field( "englishFoo" ).ofType( Foo.class ).in( presenter ).get();
   returnFoos.add( englishFoo );

   /*
    * If the presenter is set to dual language, the AsyncCallback needs to return two Foos, the
    * English and Spanish version.
    */
   boolean isDualLanguage = field( "isDualLanguage" ).ofType( boolean.class ).in( presenter ).get();  
   if ( isDualLanguage )
   {
      Foo spanishFoo = field( "spanishFoo" ).ofType( Foo.class ).in( presenter ).get();     
      returnFoos.add( spanishFoo );
   }

   doSuccessCallback( returnFoos ).when( remoteFooServiceMock ).saveFoos( isA( Bar.class ), anyListOf( Foo.class ), any( AsyncCallback.class ) );

   // This method calls the removeFooServiceMock's saveFoos method.
   presenter.saveFoos();

   // Again, English should return a single Foo.
   int increase = 1;
   if ( isDualLanguage )
   {
      // Dual language should return two Foos.
      increase++ ;
   }
   assertThat( foos ).hasSize( size + increase );
}

The test is ran via a parameter class and the first two tests are ran with one 
language. Those tests all validate and foos in presenter correctly has 3 Foos. 
However, the final test is ran with two languages. When it tries to assert the 
size of foos, it fails due to the size of foos being 3 instead of 2. It's 3 
because it's using the FIRST doSuccessCallback stubber that was created. I 
would expect it to be using the stubber that is created during each test run.

Original issue reported on code.google.com by aj.gray...@gmail.com on 6 Apr 2013 at 1:28