You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(13) |
Aug
(151) |
Sep
(21) |
Oct
(6) |
Nov
(70) |
Dec
(8) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(47) |
Feb
(66) |
Mar
(23) |
Apr
(115) |
May
(24) |
Jun
(53) |
Jul
(10) |
Aug
(279) |
Sep
(84) |
Oct
(149) |
Nov
(138) |
Dec
(52) |
2003 |
Jan
(22) |
Feb
(20) |
Mar
(29) |
Apr
(106) |
May
(170) |
Jun
(122) |
Jul
(70) |
Aug
(64) |
Sep
(27) |
Oct
(71) |
Nov
(49) |
Dec
(9) |
2004 |
Jan
(7) |
Feb
(38) |
Mar
(3) |
Apr
(9) |
May
(22) |
Jun
(4) |
Jul
(1) |
Aug
(2) |
Sep
(2) |
Oct
|
Nov
(15) |
Dec
(2) |
2005 |
Jan
(1) |
Feb
(1) |
Mar
|
Apr
(1) |
May
(28) |
Jun
(3) |
Jul
(11) |
Aug
(5) |
Sep
(1) |
Oct
(5) |
Nov
(2) |
Dec
(3) |
2006 |
Jan
(8) |
Feb
(3) |
Mar
(8) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Nat P. <np...@us...> - 2002-11-11 16:20:42
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv15732/src/core/com/mockobjects/dynamic Modified Files: Mock.java Log Message: Neatened up some formatting, no change in functionality Index: Mock.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Mock.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- Mock.java 7 Nov 2002 17:45:05 -0000 1.13 +++ Mock.java 11 Nov 2002 16:20:34 -0000 1.14 @@ -406,8 +406,7 @@ if( expectation.canBeCalled() ) { return expectation.callAndCheckResult( method, args ); } else { - assertTrue( "unexpected call to " + method.getName(), - !_strict ); + assertTrue( "unexpected call to "+method.getName(), !_strict ); return defaultResult( method.getReturnType() ); } } |
From: Joe W. <joe...@us...> - 2002-11-10 16:34:39
|
Update of /cvsroot/mockobjects/nmock/test/NMock In directory usw-pr-cvs1:/tmp/cvs-serv31632/test/NMock Removed Files: DynamicMockTest.cs MockTest.cs PredicatesTest.cs Log Message: Moved NMock stuff out of MockObject project and into NMock project. http://sf.net/projects/nmock/ --- DynamicMockTest.cs DELETED --- --- MockTest.cs DELETED --- --- PredicatesTest.cs DELETED --- |
From: Joe W. <joe...@us...> - 2002-11-10 16:34:39
|
Update of /cvsroot/mockobjects/nmock/test/NMock/Dynamic In directory usw-pr-cvs1:/tmp/cvs-serv31632/test/NMock/Dynamic Removed Files: ClassGeneratorTest.cs Log Message: Moved NMock stuff out of MockObject project and into NMock project. http://sf.net/projects/nmock/ --- ClassGeneratorTest.cs DELETED --- |
From: Joe W. <joe...@us...> - 2002-11-10 16:34:38
|
Update of /cvsroot/mockobjects/nmock/src/NMock/Dynamic In directory usw-pr-cvs1:/tmp/cvs-serv31632/src/NMock/Dynamic Removed Files: ClassGenerator.cs Log Message: Moved NMock stuff out of MockObject project and into NMock project. http://sf.net/projects/nmock/ --- ClassGenerator.cs DELETED --- |
From: Joe W. <joe...@us...> - 2002-11-10 16:34:38
|
Update of /cvsroot/mockobjects/nmock/sample/random In directory usw-pr-cvs1:/tmp/cvs-serv31632/sample/random Removed Files: Weather.cs WeatherTest.cs Log Message: Moved NMock stuff out of MockObject project and into NMock project. http://sf.net/projects/nmock/ --- Weather.cs DELETED --- --- WeatherTest.cs DELETED --- |
From: Joe W. <joe...@us...> - 2002-11-10 16:34:38
|
Update of /cvsroot/mockobjects/nmock/src/NMock In directory usw-pr-cvs1:/tmp/cvs-serv31632/src/NMock Removed Files: DynamicMock.cs IMock.cs IPredicate.cs Mock.cs Predicates.cs VerifyException.cs Log Message: Moved NMock stuff out of MockObject project and into NMock project. http://sf.net/projects/nmock/ --- DynamicMock.cs DELETED --- --- IMock.cs DELETED --- --- IPredicate.cs DELETED --- --- Mock.cs DELETED --- --- Predicates.cs DELETED --- --- VerifyException.cs DELETED --- |
From: Joe W. <joe...@us...> - 2002-11-10 16:34:38
|
Update of /cvsroot/mockobjects/nmock/sample/order In directory usw-pr-cvs1:/tmp/cvs-serv31632/sample/order Removed Files: Notifier.cs Order.cs OrderProcessor.cs OrderProcessorTest.cs Log Message: Moved NMock stuff out of MockObject project and into NMock project. http://sf.net/projects/nmock/ --- Notifier.cs DELETED --- --- Order.cs DELETED --- --- OrderProcessor.cs DELETED --- --- OrderProcessorTest.cs DELETED --- |
From: Joe W. <joe...@us...> - 2002-11-10 16:34:38
|
Update of /cvsroot/mockobjects/nmock In directory usw-pr-cvs1:/tmp/cvs-serv31632 Removed Files: README.txt Log Message: Moved NMock stuff out of MockObject project and into NMock project. http://sf.net/projects/nmock/ --- README.txt DELETED --- |
From: Steve F. <sm...@us...> - 2002-11-10 11:28:49
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv10108/src/core/com/mockobjects/dynamic Modified Files: Or.java And.java Log Message: Removed unnecessary if/else statements. Unlike C and C++, Java preserves ordering in conditional and/or expressions. Index: Or.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/Or.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Or.java 22 Oct 2002 13:00:58 -0000 1.2 +++ Or.java 10 Nov 2002 11:28:46 -0000 1.3 @@ -19,11 +19,7 @@ } public boolean eval( Object o ) { - if( _p1.eval(o) ) { - return true; - } else { - return _p2.eval(o); - } + return _p1.eval(o) || _p2.eval(o); } public String toString() { Index: And.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/And.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- And.java 22 Oct 2002 13:00:58 -0000 1.2 +++ And.java 10 Nov 2002 11:28:46 -0000 1.3 @@ -19,11 +19,7 @@ } public boolean eval( Object o ) { - if( !_p1.eval(o) ) { - return false; - } else { - return _p2.eval(o); - } + return _p1.eval(o) && _p2.eval(o); } public String toString() { |
From: Steve F. <ste...@m3...> - 2002-11-10 11:18:24
|
I've checked in implementations of this for the j2ee 1.3.1 version. I've also realised that we need to do something to get the same effect into the j2ee 1.2.1 version as well, preferably be pulling out the common code. Any suggestions for an easier way gratefully received. Steve Stefan Gruendel wrote: > Hi, > > implemented some methods I was missing. > > Best regards, Stefan > > > --- MockHttpServletRequest.java.original Tue Sep 10 10:40:32 2002 > +++ MockHttpServletRequest.java Fri Nov 8 13:05:37 2002 > @@ -23,8 +23,11 @@ > private String myContentTypeToReturn; > private String myContextPath; > private String myPathInfo; > + private String myQueryString; > private String myRemoteAddress; > private String myRequestURI; > + private String myScheme; > + private String myServerName; > private String myMethod; > private ServletInputStream myInputStream; > private Principal myUserPrincipal; > @@ -183,9 +186,12 @@ > return null; > } > > + public void setupGetQueryString(String aQueryString) { > + this.myQueryString = aQueryString; > + } > + > public String getQueryString() { > - notImplemented(); > - return null; > + return myQueryString; > } > > public BufferedReader getReader() throws IOException { > @@ -235,14 +241,20 @@ > return myRequestURI; > } > > + public void setupGetScheme(String aScheme) { > + myScheme = aScheme; > + } > + > public String getScheme() { > - notImplemented(); > - return null; > + return myScheme; > + } > + > + public void setupGetServerName(String aServerName) { > + myServerName = aServerName; > } > > public String getServerName() { > - notImplemented(); > - return null; > + return myServerName; > } > > public int getServerPort() { > > > ------------------------------------------------------- > This sf.net email is sponsored by: See the NEW Palm > Tungsten T handheld. Power & Color in a compact size! > http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev |
From: Steve F. <sm...@us...> - 2002-11-10 11:15:58
|
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/servlet In directory usw-pr-cvs1:/tmp/cvs-serv1639/src/j2ee/1.3/com/mockobjects/servlet Modified Files: MockHttpServletRequest.java Log Message: Added stub support for queryString, scheme, and serverName Index: MockHttpServletRequest.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/1.3/com/mockobjects/servlet/MockHttpServletRequest.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- MockHttpServletRequest.java 10 Sep 2002 10:40:32 -0000 1.9 +++ MockHttpServletRequest.java 10 Nov 2002 11:15:55 -0000 1.10 @@ -16,6 +16,7 @@ * @version $Revision$ */ public class MockHttpServletRequest extends MockObject + implements HttpServletRequest { private Dictionary myParameters = new Hashtable(); private Dictionary myHeaders = new Hashtable(); @@ -28,17 +29,17 @@ private String myMethod; private ServletInputStream myInputStream; private Principal myUserPrincipal; - private final ExpectationSet mySetAttributes = - new ExpectationSet(MockHttpServletRequest.class.getName() + - ".setAttribute"); - private final ExpectationSet myRemoveAttributes = new ExpectationSet( - MockHttpServletRequest.class.getName() + ".removeAttribute"); - private final ReturnObjectList myAttributesToReturn - = new ReturnObjectList("attributes"); - private final ExpectationValue myContentType = new ExpectationValue("content type"); - private final ExpectationList myGetAttributeNames = new ExpectationList("get attribute names"); - private Vector myAttributesNames; + private String queryString; + private String scheme; + private String serverName; + + private ExpectationSet mySetAttributes = new ExpectationSet("HttpServletRequest.setAttribute"); + private ExpectationSet myRemoveAttributes = new ExpectationSet("HttpServletRequest.removeAttribute"); + private ReturnObjectList myAttributesToReturn = new ReturnObjectList("attributes"); + private ExpectationValue myContentType = new ExpectationValue("content type"); + private ExpectationList myGetAttributeNames = new ExpectationList("get attribute names"); + public void setupGetAttribute(Object anAttributeToReturn) { myAttributesToReturn.addObjectToReturn(anAttributeToReturn); @@ -184,8 +185,7 @@ } public String getQueryString() { - notImplemented(); - return null; + return queryString; } public BufferedReader getReader() throws IOException { @@ -236,13 +236,11 @@ } public String getScheme() { - notImplemented(); - return null; + return scheme; } public String getServerName() { - notImplemented(); - return null; + return serverName; } public int getServerPort() { @@ -344,6 +342,18 @@ public void setupPathInfo(String pathInfo) { myPathInfo = pathInfo; + } + + public void setupQueryString(String aQueryString) { + queryString = aQueryString; + } + + public void setupScheme(String aScheme) { + scheme = aScheme; + } + + public void setupServerName(String aServerName) { + serverName = aServerName; } public StringBuffer getRequestURL() { |
From: Steve F. <ste...@m3...> - 2002-11-10 10:59:14
|
I've checked in a version that allows you to setup an autoCommit value. I've also changed the autoCommit expectation from a value to a list, otherwise your example code would barf where autoCommit is true. S. Piran Montford wrote: > I'm trying to test some code that make sure something is done on a > non-auto-committing connection. I.e., the code does this: > > if ( myConnection.getAutoCommit() == true ) { > try { > myConnection.setAutoCommit(false); > doCode(); > } finally { > myConnection.setAutoCommit(true); > } > } else { > doCode(); > } > > But you've not implemented getAutoCommit. Below is a diff -u for the > addition. > > BCNU, > > Piran Montford. |
From: Steve F. <sm...@us...> - 2002-11-10 10:57:00
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/sql In directory usw-pr-cvs1:/tmp/cvs-serv21036/src/jdk/common/com/mockobjects/sql Modified Files: CommonMockConnection.java Log Message: Added support for returning an autoCommit value Added sequence for expected autoCommit values Index: CommonMockConnection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/sql/CommonMockConnection.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- CommonMockConnection.java 7 Sep 2002 18:52:31 -0000 1.3 +++ CommonMockConnection.java 10 Nov 2002 10:56:57 -0000 1.4 @@ -81,7 +81,6 @@ import com.mockobjects.ExpectationCollection; import com.mockobjects.ExpectationCounter; import com.mockobjects.ExpectationList; -import com.mockobjects.ExpectationValue; import com.mockobjects.MockObject; import com.mockobjects.ReturnObjectList; import java.sql.CallableStatement; @@ -97,8 +96,10 @@ // -------------------------------------------------------------------- fields - private ExpectationValue myAutoCommit = - new ExpectationValue("CommonMockConnection.setAutoCommit"); + private boolean autoCommit = false; + + private ExpectationList myAutoCommit = + new ExpectationList("CommonMockConnection.setAutoCommit"); private ExpectationCounter myCloseCalls = new ExpectationCounter("CommonMockConnection.close"); @@ -151,8 +152,8 @@ /** * Register the anticipated value for autoCommit during testing. */ - public void setExpectedAutoCommit(boolean autoCommit) { - myAutoCommit.setExpected(autoCommit); + public void addExpectedAutoCommit(boolean autoCommit) { + myAutoCommit.addExpected(new Boolean(autoCommit)); } @@ -254,6 +255,10 @@ myStatementException = exception; } + public void setupAutoCommit(boolean autoCommitToReturn) { + autoCommit = autoCommitToReturn; + } + // --------------------------------------------------------------------- throw /** @@ -342,7 +347,7 @@ * The validate method will report any discrepency. */ public void setAutoCommit(boolean autoCommit) throws SQLException { - myAutoCommit.setActual(autoCommit); + myAutoCommit.addActual(new Boolean(autoCommit)); } // ------------------------------------------------------------ notImplemented @@ -365,12 +370,8 @@ return null; } - /** - * Calls notImplemented. Returns false. - */ public boolean getAutoCommit() throws SQLException { - notImplemented(); - return false; + return autoCommit; } /** |
From: Steve F. <sm...@us...> - 2002-11-10 10:55:14
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic In directory usw-pr-cvs1:/tmp/cvs-serv19778/src/core/com/mockobjects/dynamic Modified Files: AbstractMockCall.java Log Message: Removed unused describeArgument() Index: AbstractMockCall.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/dynamic/AbstractMockCall.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- AbstractMockCall.java 7 Nov 2002 17:45:05 -0000 1.2 +++ AbstractMockCall.java 10 Nov 2002 10:55:08 -0000 1.3 @@ -72,12 +72,4 @@ " was " + arg + "", expectedArg.eval(arg) ); } - - private String describeArgument( int n ) { - if( _expected_args == null ) { - return "anything"; - } else { - return _expected_args[n].toString(); - } - } } |
From: Steve F. <ste...@m3...> - 2002-11-10 10:42:55
|
Thanks for your example. I'm assuming that you're doing the getString() so that you can check for null values, which getInt() won't tell you. It's true that our current implementation cannot handle different returns for the same index, we haven't had to so far. Looking at the JDBC spec, there's a wasNull() call on a result set which tells you if the last retrieved value was null. Would that be a better solution? You could then override wasNull() on the MockResultSet you're using and return a boolean as appropriate. Alternatively, if you feel like changing the code in MockResultSet, go ahead. We don't believe we can cover all the bases in something as large as the JDBC library and that's what CVS merge is for. Steve Mark Harper wrote: >Hi there, > >Sanjay Chakravarty told me that that you might be interested in a problem >I've run into using com.mockobjects.sql.MockSingleRowResultSet. >See the attached test class for a full description... > >I realize that the code in countSomething() is redundant, and probably >should be simplified. But the question is, should this be considered a >bug in the MockResultSet implementation? >If I am constrained not to change this code, how might I work around this? > >Many Thanks, >_Mark Harper > > > > >------------------------------------------------------------------------ > >package mockobjectstest; > >import com.mockobjects.sql.MockConnection; >import com.mockobjects.sql.MockPreparedStatement; >import com.mockobjects.sql.MockSingleRowResultSet; >import com.mockobjects.sql.MockStatement; >import java.lang.Exception; >import java.sql.Connection; >import java.sql.ResultSet; >import java.sql.PreparedStatement; > >public class ResultSetBugTest >{ > /* > * The following code works on a java.sql.ResultSet. > * With a MockResultSet, however, I can't get it to work. > */ > public static int countSomething(Connection conn) > { > PreparedStatement pstmt = null; > int resultCount = 0; > > try { > pstmt = conn.prepareStatement("SELECT COUNT(*) FROM A_TABLE"); > > ResultSet rs = pstmt.executeQuery(); > > if (rs.next()) > { > if (rs.getString(1) != null) //line 1 > { > resultCount = rs.getInt(1); //line 2 > } > } > } > catch (java.sql.SQLException e) > { > e.printStackTrace(); > } > return resultCount; > } > > /* > * If I set up a Mock Result set with an Integer value for the count... > */ > public static void testSetupOne() > { > MockConnection mockConnection = new MockConnection(); > MockPreparedStatement mockPreparedStatement = new MockPreparedStatement(); > mockConnection.setupStatement( mockPreparedStatement ); > mockConnection.addExpectedPreparedStatement( mockPreparedStatement ); > MockSingleRowResultSet mockResultSet = new MockSingleRowResultSet(); > > Integer countValue = new Integer(1); > Integer[] resultValues = new Integer[] {countValue}; > mockResultSet.addExpectedIndexedValues( resultValues ); > mockPreparedStatement.addResultSet( mockResultSet ); > countSomething( mockConnection ); > /* > * I get a... > * java.lang.ClassCastException: java.lang.Integer > * at com.mockobjects.sql.MockResultSet.getString(MockResultSet.java:306) > * at //line 1 above. > */ > } > > > /* > * If I set up the Mock Result set with a String value... > */ > public static void testSetupTwo() > { > MockConnection mockConnection = new MockConnection(); > MockPreparedStatement mockPreparedStatement = new MockPreparedStatement(); > mockConnection.setupStatement( mockPreparedStatement ); > mockConnection.addExpectedPreparedStatement( mockPreparedStatement ); > MockSingleRowResultSet mockResultSet = new MockSingleRowResultSet(); > > String countValue = "1"; > String[] resultValues = new String[] {countValue}; > mockResultSet.addExpectedIndexedValues( resultValues ); > mockPreparedStatement.addResultSet( mockResultSet ); > countSomething( mockConnection ); > /* > * I get a... > * java.lang.ClassCastException: java.lang.String > * at com.mockobjects.sql.MockResultSet.getInt(MockResultSet.java:266) > * at //line 2 above. > */ > } > > public static void main (String args[]) > { > System.out.println("Trying Test One"); > try > { > testSetupOne(); > } > catch (Exception e) > { > e.printStackTrace(); > } > > System.out.println("Trying Test Two"); > try > { > testSetupTwo(); > } > catch (Exception e) > { > e.printStackTrace(); > } > > > } >} > > > |
From: Steve F. <ste...@m3...> - 2002-11-08 22:32:35
|
We're happy to help. Keep pushing us. Steve Immanuel, Gidado-Yisa wrote: >Jeff, Steve, et. Al, > >Thanks for all the help. I understood the idea of >Mock objects, but because it was late, I just targeted >the code that would get me started, basically skimming >through the Endo-Testing. So I really didn't pick up >on the ordering requirement. A tutorial would be nice >(sometime down the road). If I find time, I will >contribute to that. > >After reading Mock Objects, I found that "I Have This >Pattern" ( http://c2.com/cgi/wiki?HaveThisPattern ). >Thanks for the work, the Verifier and EasyMock are >going to simplify my life. For right now, I'm a lurker, >but I'll try to contribute when I can. > > > |
From: Immanuel, Gidado-Y. <av...@cd...> - 2002-11-08 15:16:44
|
Jeff, Steve, et. Al, Thanks for all the help. I understood the idea of Mock objects, but because it was late, I just targeted the code that would get me started, basically skimming through the Endo-Testing. So I really didn't pick up on the ordering requirement. A tutorial would be nice (sometime down the road). If I find time, I will contribute to that. After reading Mock Objects, I found that "I Have This Pattern" ( http://c2.com/cgi/wiki?HaveThisPattern ). Thanks for the work, the Verifier and EasyMock are going to simplify my life. For right now, I'm a lurker, but I'll try to contribute when I can. Regards, Gidado -----Original Message----- From: Jeff Martin [mailto:je...@mk...] Sent: Friday, November 08, 2002 4:49 AM To: "'''moc...@li...' "' ' Subject: Re: [MO-java-dev] ordering of setActual/Expected Probably should spell this out somewhere. It's one of those things that you learn when you start using mocks and then just do without thinking about. It then becomes just to obvious to mention ;) I'm sure there will be a mention of it within the FAQ soonish. |
From: Stefan G. <ste...@ii...> - 2002-11-08 13:20:30
|
Hi, implemented some methods I was missing. Best regards, Stefan --- MockHttpServletRequest.java.original Tue Sep 10 10:40:32 2002 +++ MockHttpServletRequest.java Fri Nov 8 13:05:37 2002 @@ -23,8 +23,11 @@ private String myContentTypeToReturn; private String myContextPath; private String myPathInfo; + private String myQueryString; private String myRemoteAddress; private String myRequestURI; + private String myScheme; + private String myServerName; private String myMethod; private ServletInputStream myInputStream; private Principal myUserPrincipal; @@ -183,9 +186,12 @@ return null; } =20 + public void setupGetQueryString(String aQueryString) { + this.myQueryString =3D aQueryString; + } + public String getQueryString() { - notImplemented(); - return null; + return myQueryString; } =20 public BufferedReader getReader() throws IOException { @@ -235,14 +241,20 @@ return myRequestURI; } =20 + public void setupGetScheme(String aScheme) { + myScheme =3D aScheme; + } + public String getScheme() { - notImplemented(); - return null; + return myScheme; + } + + public void setupGetServerName(String aServerName) { + myServerName =3D aServerName; } =20 public String getServerName() { - notImplemented(); - return null; + return myServerName; } =20 public int getServerPort() { |
From: Jeff M. <cus...@us...> - 2002-11-08 10:26:18
|
Update of /cvsroot/mockobjects/mockobjects-java/doc/html In directory usw-pr-cvs1:/tmp/cvs-serv18150 Modified Files: faq.html Log Message: Added question about mocking classes Index: faq.html =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/doc/html/faq.html,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- faq.html 9 Sep 2002 09:31:39 -0000 1.4 +++ faq.html 8 Nov 2002 10:26:15 -0000 1.5 @@ -140,6 +140,34 @@ <code>Expectation</code> </p> + <h3>How do I create a mock of a class not an interface?</h3> + <p> +Actually the MockObject class is a just a convenience, it handles the +reflection stuff that verifies the expectations. The important point is +that objects should be verifiable (i.e. implement the Verifiable +interface). + +The other useful class is the Verifier class which will use reflection +to verify each expectation. + +So you get this. + +<pre> +public class MockMyClass extends MyClass implements Verifiable { + private final ExpectationValue logMsg = new ExpectationValue("log"); + + public void log(String message, Throwable t) { + super.log(message, t); // want to include behavior of super + mock.logMsg.setActual(message); + } + + // Verifiable implemention + public void verify(){ + Verifier.verify(this); + } +} +</pre> + </p> <h3>What are the alt.* packages for?</h3> <p> |
From: Jeff M. <je...@mk...> - 2002-11-08 09:55:21
|
Probably should spell this out somewhere. It's one of those things that you learn when you start using mocks and then just do without thinking about. It then becomes just to obvious to mention ;) I'm sure there will be a mention of it within the FAQ soonish. On Fri, 2002-11-08 at 08:36, Immanuel, Gidado-Yisa wrote: > Uhhh....just making the title more appropriate... > > -----Original Message----- > From: Immanuel, Gidado-Yisa > To: ''moc...@li...' ' > Sent: 11/8/2002 3:25 AM > Subject: RE: [MO-java-dev] Release 0.07? > > (Appologies if this should go to the user list, but > that list has been dormant for a little while, so > I'm headed straight to the source) > > This has taken me about an 1 1/2 to figure out (thank > goodness for the code). In my test case I have: > > 1. handler.log(val); > 2. mock.setExpectedLogMessage(val); > 3. mock.verify(); > > where the handler knows about the mock. What happens is > that line 1 eventually calls mock.log() which then calls > mock.logMessage.setActual(). setActual looks to see if > it should verify...finds no expectations...so skips it. > > Line 2 sets the expected value which eventually calls > ExpectationValue.setExpected() which calls > AbstractExpectation.setHasExpectations() which does the > not so obvious: > > AbstractExpectation.clearActual() > > So Line 2 ends up clearing whatever is set in Line 1. The > only usage pattern that works is to setExpected() before setActual(): > > 1. mock.setExpectedLogMessage(val); > 2. handler.log(val); > 3. mock.verify(); > > This was not clear anywhere in the articles or javadoc. Perhaps > you could add this to the FAQ page. I assume there is a very > good reason why clearActual() is necessary in > setHasExpectations()...I'm very new to all this, so if you don't > mind educating me a little, I would love to know. > > Thanks, > Gidado > > > ------------------------------------------------------- > This sf.net email is sponsored by: See the NEW Palm > Tungsten T handheld. Power & Color in a compact size! > http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev -- Jeff Martin <je...@mk...> mkodo |
From: Steve F. <ste...@m3...> - 2002-11-08 09:50:11
|
Happy to have you on board. Pattern 2 is the correct one. The idea of setting expectations is so that the test can fail at the right time, when the actual event occurs. We can't do that if you don't specify your requirements before you start. We know that the javadoc is a mess, but we talk about this pattern at least in the Endo-testing paper. Is it not clear? S Immanuel, Gidado-Yisa wrote: >(Appologies if this should go to the user list, but >that list has been dormant for a little while, so >I'm headed straight to the source) > >This has taken me about an 1 1/2 to figure out (thank >goodness for the code). In my test case I have: > > 1. handler.log(val); > 2. mock.setExpectedLogMessage(val); > 3. mock.verify(); > >where the handler knows about the mock. What happens is >that line 1 eventually calls mock.log() which then calls >mock.logMessage.setActual(). setActual looks to see if >it should verify...finds no expectations...so skips it. > >Line 2 sets the expected value which eventually calls >ExpectationValue.setExpected() which calls >AbstractExpectation.setHasExpectations() which does the >not so obvious: > > AbstractExpectation.clearActual() > >So Line 2 ends up clearing whatever is set in Line 1. The >only usage pattern that works is to setExpected() before setActual(): > > 1. mock.setExpectedLogMessage(val); > 2. handler.log(val); > 3. mock.verify(); > >This was not clear anywhere in the articles or javadoc. Perhaps >you could add this to the FAQ page. I assume there is a very >good reason why clearActual() is necessary in >setHasExpectations()...I'm very new to all this, so if you don't >mind educating me a little, I would love to know. > >Thanks, >Gidado > > > |
From: Jeff M. <je...@mk...> - 2002-11-08 09:49:14
|
Actually the MockObject class is a just a convenience, it handles the reflection stuff that verifies the expectations. The important point is that objects should be verifiable (i.e. implement the Verifiable interface). The other useful class is the Verifier class which will use reflection to verify each expectation. So you get this. public class MockHandlerContext extends HandlerContext implements Verifiable { ExpectationValue logMsg = new ExpectationValue("log"); public void log(String message, Throwable t) { super.log(message, t); // want to include behavior of super mock.logMsg.setActual(message); } // Verifiable implemention public void verify(){ Verifier.verify(this); } } On Fri, 2002-11-08 at 08:34, Immanuel, Gidado-Yisa wrote: > Hope I have not worn out my welcome :) > > I saw how to create a Mock object for an interface: > > public class MockMyInterface extends MockObject implements MyInterface > > But I did not see anything about how to do it for classes > (including abstract classes). Below is my attempt to do > so. My qustions is: is my example a typical mock pattern, > or are there other/better patterns that I should be aware of? > > Thanks, > Gidado > > MOCK ___________________________ > > public class MockHandlerContext extends HandlerContext { > public innerMock mock = new innerMock();// make it visible > > public void log(String message, Throwable t) { > super.log(message, t); // want to include behavior of super > mock.logMsg.setActual(message); > } > > class innerMock extends MockObject { > ExpectationValue logMsg = new ExpectationValue("log"); > public void setExpectedLogMessage(String msg) { > logMsg.setExpected(msg); > } > } > > } > > TEST ____________________________________ > > // fixutre stuff.... > > public void testLog() { > String val = "hello"; > > context.mock.setExpectedLogMessage(val); > handler.log(val); > context.mock.verify(); > } > > > ------------------------------------------------------- > This sf.net email is sponsored by: See the NEW Palm > Tungsten T handheld. Power & Color in a compact size! > http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev -- Jeff Martin <je...@mk...> mkodo |
From: Steve F. <ste...@m3...> - 2002-11-08 09:24:59
|
I was only trying to make the numbers line up as we go to more digits. Should really revisit the whole thing. I like the idea of a James Bond release. S. Immanuel, Gidado-Yisa wrote: >I take it that 0.07 (the James Bond release :) >is the successor to 0.6, despite the fact that >0.6 > 0.007 ? > >Regards, >Gidado > > >------------------------------------------------------- >This sf.net email is sponsored by: See the NEW Palm >Tungsten T handheld. Power & Color in a compact size! >http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en >_______________________________________________ >Mockobjects-java-dev mailing list >Moc...@li... >https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev > > |
From: Immanuel, Gidado-Y. <av...@cd...> - 2002-11-08 08:36:32
|
Uhhh....just making the title more appropriate... -----Original Message----- From: Immanuel, Gidado-Yisa To: ''moc...@li...' ' Sent: 11/8/2002 3:25 AM Subject: RE: [MO-java-dev] Release 0.07? (Appologies if this should go to the user list, but that list has been dormant for a little while, so I'm headed straight to the source) This has taken me about an 1 1/2 to figure out (thank goodness for the code). In my test case I have: 1. handler.log(val); 2. mock.setExpectedLogMessage(val); 3. mock.verify(); where the handler knows about the mock. What happens is that line 1 eventually calls mock.log() which then calls mock.logMessage.setActual(). setActual looks to see if it should verify...finds no expectations...so skips it. Line 2 sets the expected value which eventually calls ExpectationValue.setExpected() which calls AbstractExpectation.setHasExpectations() which does the not so obvious: AbstractExpectation.clearActual() So Line 2 ends up clearing whatever is set in Line 1. The only usage pattern that works is to setExpected() before setActual(): 1. mock.setExpectedLogMessage(val); 2. handler.log(val); 3. mock.verify(); This was not clear anywhere in the articles or javadoc. Perhaps you could add this to the FAQ page. I assume there is a very good reason why clearActual() is necessary in setHasExpectations()...I'm very new to all this, so if you don't mind educating me a little, I would love to know. Thanks, Gidado |
From: Immanuel, Gidado-Y. <av...@cd...> - 2002-11-08 08:35:09
|
Hope I have not worn out my welcome :) I saw how to create a Mock object for an interface: public class MockMyInterface extends MockObject implements MyInterface But I did not see anything about how to do it for classes (including abstract classes). Below is my attempt to do so. My qustions is: is my example a typical mock pattern, or are there other/better patterns that I should be aware of? Thanks, Gidado MOCK ___________________________ public class MockHandlerContext extends HandlerContext { public innerMock mock = new innerMock();// make it visible public void log(String message, Throwable t) { super.log(message, t); // want to include behavior of super mock.logMsg.setActual(message); } class innerMock extends MockObject { ExpectationValue logMsg = new ExpectationValue("log"); public void setExpectedLogMessage(String msg) { logMsg.setExpected(msg); } } } TEST ____________________________________ // fixutre stuff.... public void testLog() { String val = "hello"; context.mock.setExpectedLogMessage(val); handler.log(val); context.mock.verify(); } |