|
From: <Ext...@no...> - 2003-07-02 15:08:15
|
Nathaniel, thanks very much - I can almost cut'n'paste the code :-)
> -----Original Message-----
> From: ext Nat Pryce [mailto:nat...@b1...]
> Sent: 02 July, 2003 18:02
> To: Hogan Mike (EXT-IBM/Espoo);
> moc...@li...
> Subject: Re: [MO-java-users] Modifying method parameters with DynaMock
>=20
>=20
> The Callable interface and the decorator/stub structure is designed to
> achieve exactly what you need. If you want to mock a=20
> side-effect, create a
> decorator chain with a domain-specific stub that implements=20
> the side effect.
> It is easy to write the stub as an anonymous inner class in=20
> the body of the
> test, and then later extract it into a reusable class if you=20
> need it in more
> than one test.
>=20
> For example, in long-hand using the version 0.09 API:
>=20
> // Note: resultSetHandler and resultSet are final so they can=20
> be used by
> // the anonymous inner class
> final ResultSetHandler resultSetHandler =3D ....
> final Mock mockResultSet =3D new Mock(ResultSet.class);
>=20
> Mock mockSQLExecuter =3D new Mock(SQLExecuter.class);
>=20
> mockSQLExecuter.add(
> new CallOnceExpectation(
> new CallSignature( "execute", C.eq( expectedSQL,=20
> expectedBindVariables,
> resultSetHandler ) ),
> new VoidStub() {
> public void getDescription() { " [calls back to
> resultSetHandler]"; }
> public Object call( String methodName, Object[] args ) {
> resultSetHandler.handle(=20
> (ResultSet)mockResultSet.proxy() );
> return super.call( methodName, args ); // stubs=20
> the void result
> }
> } ) ) );
>=20
> In my experimental branch I have added an expect method to my=20
> branch that
> takes three parameters: a method name, argument constraints=20
> and a Callable
> stub. This creates the CallOnceExpectation, NameMatcher,=20
> ArgumentMatcher
> around the stub, and so makes it more convenient to use=20
> domain-specific
> stubs in tests.
>=20
> I have also put some documentation about these=20
> interfaces/classes on the
> Mock Objects wiki, so check that out for more info.
>=20
> Regards,
> Nat.
> _______________________
> Dr. Nathaniel Pryce
> B13media Ltd.
> http://www.b13media.com
> +44 (0)7712 526 661
>=20
> ----- Original Message -----
> From: <Ext...@no...>
> To: <moc...@li...>
> Sent: Wednesday, July 02, 2003 3:25 PM
> Subject: [MO-java-users] Modifying method parameters with DynaMock
>=20
>=20
> Hi,
>=20
> I want to "do something" with a parameter that is passed into=20
> a method that
> I am DynaMock'ing. The interface is:
>=20
> public interface SqlExecutor {
> public void execute(String sql, Iterator bindVariables,=20
> ResultSetHandler
> handler) throws SQLException;
> }
>=20
> and
>=20
> public interface ResultSetHandler {
> public void handle(ResultSet resultSet) throws SQLException;
> }
>=20
> So, I create a DynaMock of SqlExecutor, my code under test=20
> passes in some
> implementation of ResultSetHandler, and I need the DynaMock to push a
> ResultSet into this ResultSetHandler implementation.
>=20
> Can DynaMock do this, or should I fall back on plain old=20
> expectation classes
> etc?
>=20
> Thanks,
> Mike.
>=20
>=20
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
> http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_06
1203_01/01
_______________________________________________
Mockobjects-java-users mailing list
Moc...@li...
https://lists.sourceforge.net/lists/listinfo/mockobjects-java-users
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100006ave/direct;at.asp_061203_01/01
_______________________________________________
Mockobjects-java-users mailing list
Moc...@li...
https://lists.sourceforge.net/lists/listinfo/mockobjects-java-users
|