From: Vincent M. <vm...@pi...> - 2003-05-18 06:59:11
|
Hi, It is currently very difficult to write common setUp using the new Dyna Mock API (it was easy with the previous DynaMock API). The main reason is that you cannot write something like that: public void setUp() { mock.matchAndReturn("create", C.ANY_ARGS, whatever); } public void test1() { [...] } public void test2() { [...] } public void testException() { mock.expectAndThrow("create", C.ANY_ARGS, new CreateException("error")); [...] } The testException() test will fail with: junit.framework.AssertionFailedError: mockOrderLocalHome: create(<ANY>) was expected but not called I think that it would be a normal behavior that expectations override matches. What do you think? Thanks -Vincent |
From: Vincent M. <vm...@pi...> - 2003-05-18 08:21:06
|
After looking at the source code, it seems the behavior is correctly implemented. There must be some other error in my test... debugging now... Thanks and sorry for the false alarm :-) -Vincent > -----Original Message----- > From: moc...@li... > [mailto:moc...@li...] On Behalf Of > Vincent Massol > Sent: 18 May 2003 08:59 > To: 'Mockobjects-Java-Dev' > Subject: [MO-java-dev] [DynaMock] Very difficult to factorize matches... > > Hi, > > It is currently very difficult to write common setUp using the new Dyna > Mock API (it was easy with the previous DynaMock API). The main reason > is that you cannot write something like that: > > public void setUp() > { > mock.matchAndReturn("create", C.ANY_ARGS, whatever); > } > > public void test1() > { > [...] > } > > public void test2() > { > [...] > } > > public void testException() > { > mock.expectAndThrow("create", C.ANY_ARGS, > new CreateException("error")); > [...] > } > > The testException() test will fail with: > > junit.framework.AssertionFailedError: mockOrderLocalHome: create(<ANY>) > was expected but not called > > I think that it would be a normal behavior that expectations override > matches. > > What do you think? > > Thanks > -Vincent > > > > ------------------------------------------------------- > This SF.net email is sponsored by: If flattening out C++ or Java > code to make your application fit in a relational database is painful, > don't do it! Check out ObjectStore. Now part of Progress Software. > http://www.objectstore.net/sourceforge > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |
From: Vincent M. <vm...@pi...> - 2003-05-18 10:18:04
|
Ok, I've found the error. For those interested it has to do with unit testing EJB code. Very often the EJB Homes are cached in static variables. As I was mocking the EJB Home using the DynaMock this dyna mock instance was saved as a static variable and thus the same expectations were carried across different tests making the test fail for some tests.... Statics are evil! :-) -Vincent > -----Original Message----- > From: moc...@li... > [mailto:moc...@li...] On Behalf Of > Vincent Massol > Sent: 18 May 2003 09:37 > To: 'Mockobjects-Java-Dev' > Subject: RE: [MO-java-dev] [DynaMock] Very difficult to factorize > matches... > > After looking at the source code, it seems the behavior is correctly > implemented. There must be some other error in my test... debugging > now... > > Thanks and sorry for the false alarm :-) > -Vincent > > > -----Original Message----- > > From: moc...@li... > > [mailto:moc...@li...] On Behalf Of > > Vincent Massol > > Sent: 18 May 2003 08:59 > > To: 'Mockobjects-Java-Dev' > > Subject: [MO-java-dev] [DynaMock] Very difficult to factorize > matches... > > > > Hi, > > > > It is currently very difficult to write common setUp using the new > Dyna > > Mock API (it was easy with the previous DynaMock API). The main reason > > is that you cannot write something like that: > > > > public void setUp() > > { > > mock.matchAndReturn("create", C.ANY_ARGS, whatever); > > } > > > > public void test1() > > { > > [...] > > } > > > > public void test2() > > { > > [...] > > } > > > > public void testException() > > { > > mock.expectAndThrow("create", C.ANY_ARGS, > > new CreateException("error")); > > [...] > > } > > > > The testException() test will fail with: > > > > junit.framework.AssertionFailedError: mockOrderLocalHome: > create(<ANY>) > > was expected but not called > > > > I think that it would be a normal behavior that expectations override > > matches. > > > > What do you think? > > > > Thanks > > -Vincent > > > > > > > > ------------------------------------------------------- > > This SF.net email is sponsored by: If flattening out C++ or Java > > code to make your application fit in a relational database is painful, > > don't do it! Check out ObjectStore. Now part of Progress Software. > > http://www.objectstore.net/sourceforge > > _______________________________________________ > > Mockobjects-java-dev mailing list > > Moc...@li... > > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev > > > > ------------------------------------------------------- > This SF.net email is sponsored by: If flattening out C++ or Java > code to make your application fit in a relational database is painful, > don't do it! Check out ObjectStore. Now part of Progress Software. > http://www.objectstore.net/sourceforge > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |