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: Steve F. <sm...@us...> - 2002-09-09 21:24:46
|
Update of /cvsroot/mockobjects/mockobjects-java/doc In directory usw-pr-cvs1:/tmp/cvs-serv10231/doc Removed Files: SiteHack.java Log Message: Removed unused class --- SiteHack.java DELETED --- |
From: Ted H. <th...@us...> - 2002-09-09 12:13:57
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/sql In directory usw-pr-cvs1:/tmp/cvs-serv12404 Modified Files: MockResultSet.java CommonMockSingleRowResultSet.java CommonMockPreparedStatement.java Log Message: License, JavaDoc, et al. Index: MockResultSet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/sql/MockResultSet.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- MockResultSet.java 19 Jun 2002 15:26:26 -0000 1.2 +++ MockResultSet.java 9 Sep 2002 12:13:53 -0000 1.3 @@ -1,3 +1,63 @@ +/* + * + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact ap...@ap.... + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +// ------------------------------------------------------------------------ 78 + package com.mockobjects.sql; import com.mockobjects.ExpectationCounter; @@ -18,15 +78,46 @@ * For basic java types (e.g. int, boolean), insert an instance of * the appropriate object (e.g. Integer, Boolean) * It also counts close() and next() calls - * To force throwing a SQLException on a getter, set the corresponding value to be of type SQLException. + * To force throwing a SQLException on a getter, + * set the corresponding value to be of type SQLException. */ abstract public class MockResultSet extends MockObject implements ResultSet { - private ExpectationCounter myCloseCalls = new ExpectationCounter("MockResultSet.close"); - protected ExpectationCounter myNextCalls = new ExpectationCounter("MockResultSet.next"); + + +// -------------------------------------------------------------------- fields + + private ExpectationCounter myCloseCalls = + new ExpectationCounter("MockResultSet.close"); + + protected ExpectationCounter myNextCalls = + new ExpectationCounter("MockResultSet.next"); private ResultSetMetaData myMetaData; + private Statement myStatement; +// -------------------------------------------------------------- setExpected* + + public void setExpectedCloseCalls(int calls) { + myCloseCalls.setExpected(calls); + } + + public void setExpectedNextCalls(int calls) { + myNextCalls.setExpected(calls); + } + +// --------------------------------------------------------------------- setup + + public void setupMetaData(ResultSetMetaData metaData) { + myMetaData = metaData; + } + + public void setupStatement(Statement statement) { + myStatement = statement; + } + +// ------------------------------------------------------------------ abstract + /** * Used as the base implementation for getting all types of object, * based on 1-based column index @@ -45,21 +136,7 @@ abstract public int getRow() throws SQLException; - public void setExpectedCloseCalls(int calls) { - myCloseCalls.setExpected(calls); - } - - public void setExpectedNextCalls(int calls) { - myNextCalls.setExpected(calls); - } - - public void setupMetaData(ResultSetMetaData metaData) { - myMetaData = metaData; - } - - public void setupStatement(Statement statement) { - myStatement = statement; - } +// --------------------------------------------------------------- implemented public void close() throws SQLException { myCloseCalls.inc(); @@ -153,16 +230,6 @@ return (Clob) getObject(colName); } - public String getCursorName() throws SQLException { - notImplemented(); - return null; - } - - public int getConcurrency() throws SQLException { - notImplemented(); - return 0; - } - public Date getDate(int columnIndex) throws SQLException { return (Date) getObject(columnIndex); } @@ -187,16 +254,6 @@ return ((Double) getObject(columnName)).doubleValue(); } - public int getFetchDirection() throws SQLException { - notImplemented(); - return 0; - } - - public int getFetchSize() throws SQLException { - notImplemented(); - return 0; - } - public float getFloat(int columnIndex) throws SQLException { return ((Float) getObject(columnIndex)).floatValue(); } @@ -225,16 +282,6 @@ return myMetaData; } - public Object getObject(int i, Map map) throws SQLException { - notImplemented(); - return null; - } - - public Object getObject(String colName, Map map) throws SQLException { - notImplemented(); - return null; - } - public Ref getRef(int i) throws SQLException { return (Ref) getObject(i); } @@ -287,316 +334,567 @@ return (Timestamp) getObject(columnName); } - public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { + public Timestamp getTimestamp(int columnIndex, Calendar cal) + throws SQLException { return getTimestamp(columnIndex); } - public Timestamp getTimestamp(String columnName, Calendar cal) throws SQLException { + public Timestamp getTimestamp(String columnName, Calendar cal) + throws SQLException { return getTimestamp(columnName); } - public int getType() throws SQLException { + public InputStream getUnicodeStream(int columnIndex) + throws SQLException { + return (InputStream) getObject(columnIndex); + } + + public InputStream getUnicodeStream(String columnName) + throws SQLException { + return (InputStream) getObject(columnName); + } + +// ------------------------------------------------------------ notImplemented + + public String getCursorName() throws SQLException { + notImplemented(); + return null; + } + + public int getConcurrency() throws SQLException { notImplemented(); return 0; } - public InputStream getUnicodeStream(int columnIndex) throws SQLException { - return (InputStream) getObject(columnIndex); + /** + * Calls notImplemented. Returns 0. + */ + public int getFetchDirection() throws SQLException { + notImplemented(); + return 0; } - public InputStream getUnicodeStream(String columnName) throws SQLException { - return (InputStream) getObject(columnName); + /** + * Calls notImplemented. Returns 0. + */ + public int getFetchSize() throws SQLException { + notImplemented(); + return 0; + } + + /** + * Calls notImplemented. Returns null. + */ + public Object getObject(int i, Map map) throws SQLException { + notImplemented(); + return null; + } + + /** + * Calls notImplemented. Returns null. + */ + public Object getObject(String colName, Map map) throws SQLException { + notImplemented(); + return null; + } + + /** + * Calls notImplemented. Returns 0. + */ + public int getType() throws SQLException { + notImplemented(); + return 0; } + /** + * Calls notImplemented. Returns null. + */ public SQLWarning getWarnings() throws SQLException { notImplemented(); return null; } + /** + * Calls notImplemented. + */ public void clearWarnings() throws SQLException { notImplemented(); } + /** + * Calls notImplemented. Returns 0. + */ public int findColumn(String columnName) throws SQLException { notImplemented(); return 0; } + /** + * Calls notImplemented. Returns false. + */ public boolean isBeforeFirst() throws SQLException { notImplemented(); return false; } + /** + * Calls notImplemented. Returns false. + */ public boolean isAfterLast() throws SQLException { notImplemented(); return false; } + /** + * Calls notImplemented. Returns false. + */ public boolean isFirst() throws SQLException { notImplemented(); return false; } + /** + * Calls notImplemented. Returns false. + */ public boolean isLast() throws SQLException { notImplemented(); return false; } + /** + * Calls notImplemented. + */ public void beforeFirst() throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void afterLast() throws SQLException { notImplemented(); } + /** + * Calls notImplemented. Returns false. + */ public boolean first() throws SQLException { notImplemented(); return false; } - public boolean last() throws SQLException { + /** + * Calls notImplemented. Returns false. + */ + public boolean last() throws SQLException { notImplemented(); return false; } + /** + * Calls notImplemented. Returns false. + */ public boolean absolute(int row) throws SQLException { notImplemented(); return false; } + /** + * Calls notImplemented. Returns false. + */ public boolean relative(int rows) throws SQLException { notImplemented(); return false; } + /** + * Calls notImplemented. Returns false. + */ public boolean previous() throws SQLException { notImplemented(); return false; } + /** + * Calls notImplemented. + */ public void setFetchDirection(int direction) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void setFetchSize(int rows) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. Returns false. + */ public boolean rowUpdated() throws SQLException { notImplemented(); return false; } + /** + * Calls notImplemented. Returns false. + */ public boolean rowInserted() throws SQLException { notImplemented(); return false; } + /** + * Calls notImplemented. Returns false. + */ public boolean rowDeleted() throws SQLException { notImplemented(); return false; } + /** + * Calls notImplemented. + */ public void updateNull(int columnIndex) throws SQLException { notImplemented(); } - public void updateBoolean(int columnIndex, boolean x) throws SQLException { + /** + * Calls notImplemented. + */ + public void updateBoolean(int columnIndex, boolean x) + throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateByte(int columnIndex, byte x) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateShort(int columnIndex, short x) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateInt(int columnIndex, int x) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateLong(int columnIndex, long x) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateFloat(int columnIndex, float x) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateDouble(int columnIndex, double x) throws SQLException { notImplemented(); } - public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { + /** + * Calls notImplemented. + */ + public void updateBigDecimal(int columnIndex, BigDecimal x) + throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateString(int columnIndex, String x) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateBytes(int columnIndex, byte x[]) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateDate(int columnIndex, Date x) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateTime(int columnIndex, Time x) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateObject(int columnIndex, Object x, int scale) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateObject(int columnIndex, Object x) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateNull(String columnName) throws SQLException { notImplemented(); } - public void updateBoolean(String columnName, boolean x) throws SQLException { + /** + * Calls notImplemented. + */ + public void updateBoolean(String columnName, boolean x) + throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateByte(String columnName, byte x) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateShort(String columnName, short x) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateInt(String columnName, int x) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateLong(String columnName, long x) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateFloat(String columnName, float x) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateDouble(String columnName, double x) throws SQLException { notImplemented(); } - public void updateBigDecimal(String columnName, BigDecimal x) throws SQLException { + /** + * Calls notImplemented. + */ + public void updateBigDecimal(String columnName, BigDecimal x) + throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateString(String columnName, String x) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateBytes(String columnName, byte x[]) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateDate(String columnName, Date x) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateTime(String columnName, Time x) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateTimestamp(String columnName, Timestamp x) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateAsciiStream(String columnName, InputStream x, int length) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateBinaryStream(String columnName, InputStream x, int length) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateCharacterStream(String columnName, Reader reader, int length) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateObject(String columnName, Object x, int scale) throws SQLException { notImplemented(); } - public void updateObject(String columnName, Object x) throws SQLException { + /** + * Calls notImplemented. + */ + public void updateObject(String columnName, Object x) + throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void insertRow() throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void updateRow() throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void deleteRow() throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void refreshRow() throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void cancelRowUpdates() throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void moveToInsertRow() throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void moveToCurrentRow() throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public boolean wasNull() throws SQLException { notImplemented(); return false; } -} +} // end MockResultSet Index: CommonMockSingleRowResultSet.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/sql/CommonMockSingleRowResultSet.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CommonMockSingleRowResultSet.java 28 Jun 2002 17:35:39 -0000 1.1 +++ CommonMockSingleRowResultSet.java 9 Sep 2002 12:13:53 -0000 1.2 @@ -1,64 +1,187 @@ +/* + * + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact ap...@ap.... + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +// ------------------------------------------------------------------------ 78 + package com.mockobjects.sql; import java.sql.SQLException; -import java.util.*; - +import java.util.Map; /** - * This is a simple implementation of a MockResultSet. - * It verifies that the values fed to it have been retrieved. - * These can be found by either column index or column name. + * Implementation of a MockResultSet that uses the ExpectationRow + * object to simulate a ResultSet that returns a single row. + * It verifies that the values fed to it have been retrieved + * throw a call to next and getRow. + * Column values can be retrieved using any of the getters + * declared in MockResultSet. + * Depending on which constructor is used, + * these can be found by either column index or column name. * For basic java types (e.g. int, boolean), insert an instance of - * the appropriate object (e.g. Integer, Boolean) - * To force throwing a SQLException on a getter, set the corresponding value to be of type SQLException. + * the appropriate object (e.g. Integer, Boolean). + * To force throwing a SQLException on a getter, + * set the corresponding value to be of type SQLException. + * @author Jeff Martin + * @author Ted Husted */ public abstract class CommonMockSingleRowResultSet extends MockResultSet { - private ExpectationSqlRow myRow = new ExpectationSqlRow("single row"); + +// -------------------------------------------------------------------- fields + + private ExpectationSqlRow myRow = + new ExpectationSqlRow("CommonMockSingleRowResultSet.SqlRow"); + private int myNextCallCount = 0; - public CommonMockSingleRowResultSet(Object[] values) { - addExpectedIndexedValues(values); +// -------------------------------------------------------------- addExpected* + + + /** + * Add expected values from an array to be retrieved by index. + */ + public void addExpectedIndexedValues(Object[] values) { + myRow.addExpectedIndexedValues(values); + } + + /** + * Add expected values from an array to be retrieved by name or + * index. + */ + public void addExpectedNamedValues(String[] names, Object[] values) { + myRow.addExpectedNamedValues(names, values); + } + + /** + * Add expected values from a Map to be retrieved by name or + * index. + */ + public void addExpectedNamedValues(Map map) { + myRow.addExpectedNamedValues(map); } +// -------------------------------------------------------------- constructors + + /** + * Default constructor. + * Call one of the AddExpected* methods before use, + * or use one of the alternate constructors instead. + */ public CommonMockSingleRowResultSet(){ super(); } + /** + * Constructor to create a single row ResultSet + * that can retrieve passed values by index. + */ + public CommonMockSingleRowResultSet(Object[] values) { + addExpectedIndexedValues(values); + } + + /** + * Constructor to create a single row ResultSet + * that can retrieve passed values by name. + */ public CommonMockSingleRowResultSet(String[] names, Object[] values) { addExpectedNamedValues(names, values); } + /** + * Constructor to create a single row ResultSet + * from a Map. + */ public CommonMockSingleRowResultSet(Map map) { addExpectedNamedValues(map); } - public void addExpectedIndexedValues(Object[] values) { - myRow.addExpectedIndexedValues(values); - } - - public void addExpectedNamedValues(String[] names, Object[] values) { - myRow.addExpectedNamedValues(names, values); - } +// --------------------------------------------------------------- implemented - public void addExpectedNamedValues(Map map) { - myRow.addExpectedNamedValues(map); - } + /** + * Return true if this is the first time next is called. + */ public boolean next() throws SQLException { myNextCalls.inc(); myNextCallCount++; return myNextCallCount == 1; } + /** + * Return 1 if next has been called exactly once. + */ public int getRow() throws SQLException { return myNextCallCount; } + /** + * Return value set for given index by an addExpected* method. + * Called by superclass to cast values to appropriate type. + */ public Object getObject(int columnIndex) throws SQLException { return myRow.get(columnIndex); } + /** + * Return value set for given name by an addExpectedNamedValue + * method. + * Called by superclass to cast values to appropriate type. + */ public Object getObject(String columnName) throws SQLException { return myRow.get(columnName); } -} +} // end CommonMockSingleRowResultSet Index: CommonMockPreparedStatement.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/sql/CommonMockPreparedStatement.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CommonMockPreparedStatement.java 28 Jun 2002 17:35:39 -0000 1.1 +++ CommonMockPreparedStatement.java 9 Sep 2002 12:13:53 -0000 1.2 @@ -1,3 +1,63 @@ +/* + * + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact ap...@ap.... + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +// ------------------------------------------------------------------------ 78 + package com.mockobjects.sql; import java.sql.*; @@ -6,26 +66,40 @@ import java.math.BigDecimal; import com.mockobjects.*; -public abstract class CommonMockPreparedStatement extends CommonMockStatement implements -PreparedStatement { +/** + * Abstract PreparedStatement for use with mock testing. + * If a notImplemented method is are needed for your project, + * please submit a patch. + * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/sql/PreparedStatement.html">java.sql.PreparedStatement</a> + * @author Jeff Martin + * @author Ted Husted + * @version $Revision$ $Date$ + */ +public abstract class CommonMockPreparedStatement + extends CommonMockStatement implements PreparedStatement { + +// -------------------------------------------------------------------- fields + private ExpectationSet mySetParameters = new ExpectationSet("CommonMockPreparedStatement.setParameters"); + private ExpectationCounter myClearParametersCalls = - new ExpectationCounter("CommonMockPreparedStatement.clearParameters() calls"); + new ExpectationCounter + ("CommonMockPreparedStatement.clearParameters() calls"); + private ExpectationSet myTargetSQLTypes = - new ExpectationSet("target sql types"); + new ExpectationSet("CommonMockPreparedStatement.targetSQLTypes"); +// -------------------------------------------------------------- addExpected* public void addExpectedSetParameter(int parameterIndex, int intValue) { addExpectedSetParameter(parameterIndex, new Integer(intValue)); } - public void addExpectedTargetSQLType(int aTargetSQLType){ - myTargetSQLTypes.addExpected(new Integer(aTargetSQLType)); - } - - public void addExpectedSetParameter(int parameterIndex, Object parameterValue) { - mySetParameters.addExpected(new MapEntry(new Integer(parameterIndex), parameterValue)); + public void addExpectedSetParameter(int parameterIndex, + Object parameterValue) { + mySetParameters.addExpected(new MapEntry(new Integer(parameterIndex), + parameterValue)); } public void addExpectedSetParameters(Object[] parameters) { @@ -34,14 +108,11 @@ } } - public void clearParameters() throws SQLException { - myClearParametersCalls.inc(); + public void addExpectedTargetSQLType(int aTargetSQLType){ + myTargetSQLTypes.addExpected(new Integer(aTargetSQLType)); } - public boolean execute() throws SQLException { - innerExecute(); - return false; - } +// -------------------------------------------------------------- setExpected* public void setExpectedClearParametersCalls(int callCount) { myClearParametersCalls.setExpected(callCount); @@ -51,10 +122,30 @@ mySetParameters.setExpectNothing(); } +// --------------------------------------------------------------- implemented + + public void clearParameters() throws SQLException { + myClearParametersCalls.inc(); + } + + /** + * Calls innerExecute() (see CommonMockStatement). Returns false. + */ + public boolean execute() throws SQLException { + innerExecute(); + return false; + } + + /** + * Returns executeQuery(String) with an empty String. + */ public ResultSet executeQuery() throws SQLException { return executeQuery(""); } + /** + * Returns executeUpdate(String) with an empty String. + */ public int executeUpdate() throws SQLException { return executeUpdate(""); } @@ -67,7 +158,8 @@ setObject(parameterIndex, x); } - public void setTimestamp(int param, Timestamp timestamp) throws SQLException { + public void setTimestamp(int param, Timestamp timestamp) throws + SQLException { setObject(param, timestamp); } @@ -79,10 +171,6 @@ setObject(param, new Long(aLong)); } - public void addBatch() throws SQLException { - notImplemented(); - } - public void setNull(int param, int param1) throws SQLException { setObject(param, null); } @@ -95,14 +183,11 @@ setObject(param, new Short(aShort)); } - public void setTime(int param, Time time, Calendar calendar) throws SQLException { + public void setTime(int param, Time time, Calendar calendar) throws + SQLException { setObject(param, time); } - public void setObject(int param, Object anObject, int targetSqlType, int scale) throws SQLException { - notImplemented(); - } - public void setObject(int param, Object anObject, int aTargetSQLType) throws SQLException { setObject(param, anObject); @@ -125,26 +210,11 @@ setObject(param, blob); } - public void setCharacterStream(int param, Reader reader, int length) throws SQLException { - notImplemented(); - } - - public void setAsciiStream(int param, java.io.InputStream inputStream, int length) throws SQLException { - notImplemented(); - } - - public void setDate(int param, Date date, Calendar calendar) throws SQLException { + public void setDate(int param, Date date, Calendar calendar) throws + SQLException { setDate(param, date); } - public void setBinaryStream(int param, java.io.InputStream inputStream, int length) throws SQLException { - notImplemented(); - } - - public void setUnicodeStream(int param, java.io.InputStream inputStream, int length) throws SQLException { - notImplemented(); - } - public void setBytes(int param, byte[] values) throws SQLException { setObject(param, values); } @@ -161,29 +231,90 @@ setObject(param, new Double(aDouble)); } - public ResultSetMetaData getMetaData() throws SQLException { + public void setTime(int param, Time time) throws SQLException { + setObject(param, time); + } + + public void setBoolean(int param, boolean aBoolean) throws SQLException { + setObject(param, new Boolean(aBoolean)); + } + + public void setBigDecimal(int param, BigDecimal bigDecimal) throws + SQLException { + setObject(param, bigDecimal); + } + +// ------------------------------------------------------------ notImplemented + + /** + * Calls notImplemented. + */ + public void addBatch() throws SQLException { notImplemented(); - return null; } - public void setTimestamp(int param, Timestamp timestamp, Calendar calendar) throws SQLException { + /** + * Calls notImplemented. + */ + public void setObject(int param, Object anObject, int targetSqlType, + int scale) throws SQLException { notImplemented(); } - public void setTime(int param, Time time) throws SQLException { - setObject(param, time); + /** + * Calls notImplemented. + */ + public void setCharacterStream(int param, Reader reader, int length) + throws SQLException { + notImplemented(); } - public void setBoolean(int param, boolean aBoolean) throws SQLException { - setObject(param, new Boolean(aBoolean)); + /** + * Calls notImplemented. + */ + public void setAsciiStream(int param, java.io.InputStream inputStream, + int length) throws SQLException { + notImplemented(); } - public void setNull(int param, int param1, String typeName) throws SQLException { + /** + * Calls notImplemented. + */ + public void setBinaryStream(int param, java.io.InputStream inputStream, + int length) throws SQLException { notImplemented(); } - public void setBigDecimal(int param, BigDecimal bigDecimal) throws SQLException { - setObject(param, bigDecimal); + /** + * Calls notImplemented. + */ + public void setNull(int param, int param1, String typeName) throws + SQLException { + notImplemented(); + } + + /** + * Calls notImplemented. + */ + public void setUnicodeStream(int param, java.io.InputStream inputStream, + int length) throws SQLException { + notImplemented(); + } + + /** + * Calls notImplemented. Returns null. + */ + public ResultSetMetaData getMetaData() throws SQLException { + notImplemented(); + return null; + } + + /** + * Calls notImplemented. + */ + public void setTimestamp(int param, Timestamp timestamp, Calendar + calendar) throws SQLException { + notImplemented(); } -} +} // end CommonMockPreparedStatement |
From: Jeff M. <cus...@us...> - 2002-09-09 09:43:31
|
Update of /cvsroot/mockobjects/mockobjects-java/doc/html In directory usw-pr-cvs1:/tmp/cvs-serv19123/html Modified Files: template.txt Log Message: Added a break after mockdoclet Index: template.txt =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/doc/html/template.txt,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- template.txt 9 Sep 2002 09:31:10 -0000 1.6 +++ template.txt 9 Sep 2002 09:43:29 -0000 1.7 @@ -65,7 +65,8 @@ <a target="_blank" href="http://www.easymock.org/">Easy Mock</a><br> <a target="_blank" href="http://www.junit.org/">JUnit</a><br> <a target="_blank" href="http://www.abstrakt.de/mockcreator.html">Mock Creator</a><br> - <a target="_blank" href="http://www.mockmaker.org/">Mock Maker</a> + <a target="_blank" href="http://www.mockmaker.org/">Mock +Maker</a><br> <a target="_blank" href="http://joe.truemesh.com/mockdoclet/">Mock Doclet</a> </td> |
From: Jeff M. <cus...@us...> - 2002-09-09 09:33:15
|
Update of /cvsroot/mockobjects/mockobjects-java/doc/com/mockobjects/doc In directory usw-pr-cvs1:/tmp/cvs-serv14305/com/mockobjects/doc Modified Files: SiteTemplate.java Log Message: Change indentaion to four spaces Index: SiteTemplate.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/doc/com/mockobjects/doc/SiteTemplate.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SiteTemplate.java 9 Sep 2002 00:44:50 -0000 1.1 +++ SiteTemplate.java 9 Sep 2002 09:33:12 -0000 1.2 @@ -9,102 +9,102 @@ import java.text.MessageFormat; public class SiteTemplate extends MatchingTask { - private File dir; - private File todir; - private File templatefile; - - public void setTemplatefile(File aTemplatefile) { - templatefile = aTemplatefile; - } - - public void setTodir(File aTodir) { - todir = aTodir; - } - - public void setDir(File aDir) { - dir = aDir; - } - - /** - * @see org.apache.tools.ant.Task#execute() - */ - public void execute() throws BuildException { - validateAttributes(); - - log("Template file: " + templatefile.getPath(), Project.MSG_INFO); - - createOutputDirectory(); - try { - MessageFormat template = new MessageFormat(readFileContent(templatefile)); - - DirectoryScanner scanner = getDirectoryScanner(dir); - String[] filenames = scanner.getIncludedFiles(); - for (int i = 0; i < filenames.length; ++i) { - String filename = filenames[i]; - writeToFile(filename, formattedContents(template, filename)); - } - } catch (IOException e) { - log("IO Failure " + e.getMessage(), Project.MSG_ERR); - } - } - - private String formattedContents(MessageFormat template, String filename) throws IOException { - return template.format( - new Object[] { - readFileContent(new File(dir, filename))}); - } - - private void createOutputDirectory() { - if (!todir.exists()) { - todir.mkdirs(); - } - } - - private void validateFile(File file, String propertyName) { - if (file == null) { - throw new BuildException("Missing " + propertyName, location); - } - if (!file.exists()) { - throw new BuildException("Cannot find " + file.getPath(), location); - } - - } - - private void validateAttributes() throws BuildException { - validateFile(templatefile, "templatefile"); - validateFile(dir, "dir"); - validateFile(todir, "todir"); - } - - private final String readFileContent(File inputFile) throws IOException { - FileReader rd = new FileReader(inputFile); - try { - BufferedReader reader = new BufferedReader(rd); - StringBuffer fileContents = new StringBuffer(); - - String line = reader.readLine(); - while (line != null) { - fileContents.append(line); - fileContents.append("\r\n"); - line = reader.readLine(); - } - - return fileContents.toString(); - } finally { - rd.close(); - } - } - - private final void writeToFile(String fileName, String content) throws IOException { - File outputFile = new File(todir, fileName); - log("Writing to " + outputFile.getPath(), Project.MSG_INFO); - - FileWriter writer = new FileWriter(outputFile); - try { - writer.write(content); - writer.flush(); - } finally { - writer.close(); + private File dir; + private File todir; + private File templatefile; + + public void setTemplatefile(File aTemplatefile) { + templatefile = aTemplatefile; + } + + public void setTodir(File aTodir) { + todir = aTodir; + } + + public void setDir(File aDir) { + dir = aDir; + } + + /** + * @see org.apache.tools.ant.Task#execute() + */ + public void execute() throws BuildException { + validateAttributes(); + + log("Template file: " + templatefile.getPath(), Project.MSG_INFO); + + createOutputDirectory(); + try { + MessageFormat template = new MessageFormat(readFileContent(templatefile)); + + DirectoryScanner scanner = getDirectoryScanner(dir); + String[] filenames = scanner.getIncludedFiles(); + for (int i = 0; i < filenames.length; ++i) { + String filename = filenames[i]; + writeToFile(filename, formattedContents(template, filename)); + } + } catch (IOException e) { + log("IO Failure " + e.getMessage(), Project.MSG_ERR); + } + } + + private String formattedContents(MessageFormat template, String filename) throws IOException { + return template.format( + new Object[] { + readFileContent(new File(dir, filename))}); + } + + private void createOutputDirectory() { + if (!todir.exists()) { + todir.mkdirs(); + } + } + + private void validateFile(File file, String propertyName) { + if (file == null) { + throw new BuildException("Missing " + propertyName, location); + } + if (!file.exists()) { + throw new BuildException("Cannot find " + file.getPath(), location); + } + + } + + private void validateAttributes() throws BuildException { + validateFile(templatefile, "templatefile"); + validateFile(dir, "dir"); + validateFile(todir, "todir"); + } + + private final String readFileContent(File inputFile) throws IOException { + FileReader rd = new FileReader(inputFile); + try { + BufferedReader reader = new BufferedReader(rd); + StringBuffer fileContents = new StringBuffer(); + + String line = reader.readLine(); + while (line != null) { + fileContents.append(line); + fileContents.append("\r\n"); + line = reader.readLine(); + } + + return fileContents.toString(); + } finally { + rd.close(); + } + } + + private final void writeToFile(String fileName, String content) throws IOException { + File outputFile = new File(todir, fileName); + log("Writing to " + outputFile.getPath(), Project.MSG_INFO); + + FileWriter writer = new FileWriter(outputFile); + try { + writer.write(content); + writer.flush(); + } finally { + writer.close(); + } } - } } |
From: Jeff M. <cus...@us...> - 2002-09-09 09:31:42
|
Update of /cvsroot/mockobjects/mockobjects-java/doc/html In directory usw-pr-cvs1:/tmp/cvs-serv13765/html Modified Files: faq.html Log Message: More answers Index: faq.html =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/doc/html/faq.html,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- faq.html 6 Sep 2002 12:53:04 -0000 1.3 +++ faq.html 9 Sep 2002 09:31:39 -0000 1.4 @@ -81,13 +81,11 @@ </p> <h2>About the Mock Object Implementation</h2> - <h3>Why do I have to call setup???? to instead of set??? to add something to a map?</h3> <p> </p> - <h3>How do I contribute changes back to the mock objects project?</h3> <p> If you've made changes to any of the mock objects we'd love to see them an @@ -102,7 +100,7 @@ used we don't write any mock code in them until someone has a need for it. In order to make it easier to tell with methods have been implemented and which haven't any method which has not been implemented will throw a -NotImplementedException when it is called. If this happens during a test you can +<code>NotImplementedException</code> when it is called. If this happens during a test you can either write an implementation for the method and send us a patch for it, or mail us with details of how you'd like to use the method and we'll try(spare time permitting) to implement it. @@ -111,30 +109,77 @@ <h3>How do I write a mock?</h3> <p> + Simple put you just need to extends <code>com.mockobjects.MockObjects</code> implement +your chosen interface and sprinkle some expectations about and your done. +e.g.</p> +<pre> +pubic class MockMyInterface extends MockObject implements MyInterface{ + + private final ExpectationValue something = + new ExpectationValue("something"); + + public void setSomething(SomeClass something){ + this.something.setActual(something); + } + + public void setExpectedSomething(SomeClass something){ + this.something.setExpected(something); + } +} +</pre> + <p> + easy really. </p> <h3>Why don't mocks verify their expectations?</h3> <p> + As you can see in the above example we don't have to explicitly call + <code>verify();</code> on each expectation. This is because the super class MockObject + will auto-magically call verify on an member variables which implement + <code>Expectation</code> </p> <h3>What are the alt.* packages for?</h3> <p> + The <code>alt.*</code> packages are to help get around some of the limitations of other peoples class libraries.</p> + <p>Generally these classes are very simple wrappers around classes which are +constructed in such a way that they cannot be mocked. An example of this is +<code>java.io.File</code> which is concrete class marked as final this provides +us with no way to mock it other than to wrap it in a mockable wrapper. + </p> + <p>Each alt implementation consists of an interface, +an wrapper class and a mock. In some cases there will also be a factory +interface with mock and real implementations. </p> - <h3>What do I do if I can't find a mock for a class?</h3> <p> + Easy one this, write one! Write as little of it as you possibly can, use +<code>notImplemented();</code> for any methods you don't use and send it to us +when your done.</p> + <p>You can try pursuading someone on the developer mailing list to do it for +your but it's probably quicker doing it yourself. </p> <h3>Are there any tools to help create mocks?</h3> <p> + Yes there are, currently we know of three. <a +href="http://www.mockmaker.org/"/>MockMaker</a>, <a +href="http://www.easymock.org/">EasyMock</a>, <a +href="http://www.abstrakt.de/mockcreator.html">MockCreator</a> and <a +href="http://joe.sitemesh.com/mockdoclet.html">MockDoclet</a> </p> <h3>Why are the internals of mock private when there just test class?</h3> + <p> + Because they can be. When your writing a test you shouldn't need to access +any of the internals of a mock objects. If you need to extends one of our mocks +you can just change the source code and send us the patch ;-) + </p> <h3>What is the best practise for integrating mocks into a project?</h3> <h2>Other Questions</h2> |
From: Jeff M. <cus...@us...> - 2002-09-09 09:31:13
|
Update of /cvsroot/mockobjects/mockobjects-java/doc/html In directory usw-pr-cvs1:/tmp/cvs-serv13562/html Modified Files: template.txt Log Message: Changed copyright notice Index: template.txt =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/doc/html/template.txt,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- template.txt 3 Sep 2002 10:02:19 -0000 1.5 +++ template.txt 9 Sep 2002 09:31:10 -0000 1.6 @@ -1,9 +1,10 @@ <html> <head> - <meta name="generator" content="HTML Tidy, see www.w3.org"> + <meta name="generator" content="Jeff"> <title>Mock Objects</title> <link rel="stylesheet" href="stylesheet.css" type="text/css"> + <meta name="keywords" content="unit test, test first, mock object, junit"> </head> <body marginheight="4" marginwidth="4" leftmargin="4" topmargin= @@ -15,7 +16,7 @@ border="0" vspace="0" hspace="0" src= "./images/mockturtle.jpg"></a></td> - <td bgcolor="#ffffff" align="center" valign="middle" width= + <td align="center" valign="middle" width= "100%"><img align="center" alt= "Mock Objects" border="0" vspace="0" hspace="0" src=".//images/mockobjects.gif"></td> @@ -61,10 +62,11 @@ <a href="./coding_conventions.html" class="menu">Coding conventions</a><br> <a href="./release_process.html" class="menu">Release process</a><br> <h4>Links</h4> - <a href="http://www.easymock.org/">Easy Mock</a><br> - <a href="http://www.junit.org/">JUnit</a><br> - <a href="http://www.abstrakt.de/mockcreator.html">Mock Creator</a><br> - <a href="http://www.mockmaker.org/">Mock Maker</a> + <a target="_blank" href="http://www.easymock.org/">Easy Mock</a><br> + <a target="_blank" href="http://www.junit.org/">JUnit</a><br> + <a target="_blank" href="http://www.abstrakt.de/mockcreator.html">Mock Creator</a><br> + <a target="_blank" href="http://www.mockmaker.org/">Mock Maker</a> + <a target="_blank" href="http://joe.truemesh.com/mockdoclet/">Mock Doclet</a> </td> @@ -90,10 +92,9 @@ <hr size="1" noshade=""> </td> </tr> - <tr> <td align="center"><span><i>Copyright © - 2001 Mock Objects. All Rights Reserved.</i></span> </td> + 2001-2002 Mock Objects. All Rights Reserved.</i></span> </td> </tr> </table> </body> |
From: Jeff M. <cus...@us...> - 2002-09-09 09:30:45
|
Update of /cvsroot/mockobjects/mockobjects-java/doc/html In directory usw-pr-cvs1:/tmp/cvs-serv13332/html Modified Files: stylesheet.css Log Message: Chnage order of entries to make it easier to follow Index: stylesheet.css =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/doc/html/stylesheet.css,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- stylesheet.css 2 Sep 2002 11:35:07 -0000 1.2 +++ stylesheet.css 9 Sep 2002 09:30:42 -0000 1.3 @@ -1,10 +1,24 @@ body { - background-color: white; + background-color: #eee; color: black; font-size:12px; font-family: Verdana, Arial, Helvetica, sans-serif; } +p{ + margin-left: 30; + margin-right: 30; + font-size:12px; +} + +pre{ + font-size:12px; + background: #fff; + padding: 10; + margin-left: 30; + margin-right: 30; +} + h1{ color: white; background-color: #023264; @@ -21,26 +35,14 @@ } h3{ - color: white; - background-color: #023264; + color: #023264; + background-color: #fff; padding: 3; margin-left: 20; font-size:100%; } -p{ - margin-left: 30; - margin-right: 30; - font-size:12px; -} - :link { color: #525D76 } :visited { color: #023264 } :active { color: #023264 } -pre{ - background: #eee; - padding: 10; - margin-left: 30; - margin-right: 30; -} |
From: Jeff M. <je...@mk...> - 2002-09-09 09:27:40
|
It's still very much a work in progress. But it still follows my general design principle of "Not prefect, just better" On Sun, 2002-09-08 at 16:43, Vincent Massol wrote: > Hi, > > I just discovered that the web site had a new look. I kinda like it! > Here are a few comments (sorry not to correct them right away, but my > environment is not set up right now and I'm a bit in a rush): > > 1/ Copyright at the bottom of the page should say 2001-2002 Sorted. > > 2/ The font for normal text is very very small. The first paragraph of > the main page that starts with ""The Mock Objects project is a generic > ..." is way too small compared to the bullet list. > Can someone who runs windows look at this one, as fonts on Linux seem to be totally different. Should just be a case of editing doc/html/stylesheet.css > 3/ The todo page is oooooolddddddd. Version there is 0.02 ... > Yup, this need to be talked about. > 4/ Links: I think we should add MockDoclet > (http://joe.truemesh.com/mockdoclet/) Yeah was going to do that. There's also RubyMock (www.b13media.com/dev/ruby/mock.html), but I figured Nat could handle that one. > > But congratulations to you guys. It definitely is better than before! > Again, sorry not to help more. I still hope that I will find some time > for that not too far in the distant future ... > Just getting feed back is a big help. > Thanks > -Vincent > > > > ------------------------------------------------------- > This sf.net email is sponsored by: OSDN - Tired of that same old > cell phone? Get a new here for FREE! > https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev -- jeff martin information technologist mkodo limited mobile: 44 (0) 78 5547 8331 phone: 44 (0) 20 2226 4545 email: je...@mk... www.mkodo.com |
From: Jeff M. <je...@mk...> - 2002-09-09 09:14:04
|
Cool, that was just bubbling under my threshold of things I might do when I'm supposed to be working. On Mon, 2002-09-09 at 01:47, Steve Freeman wrote: > having nothing better to do ;-) I added an Ant task version of SiteHack. > > People happy for me to release it? > > S. > - - - - - - - - - - - - - - - > Steve Freeman st...@m3... > Programme chair OT2003. http://www.ot2003.org > > "Nonsense is just nonsense, but the study of nonsense is science." > > > > > ------------------------------------------------------- > This sf.net email is sponsored by: OSDN - Tired of that same old > cell phone? Get a new here for FREE! > https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev -- jeff martin information technologist mkodo limited mobile: 44 (0) 78 5547 8331 phone: 44 (0) 20 2226 4545 email: je...@mk... www.mkodo.com |
From: Steve F. <st...@m3...> - 2002-09-09 00:49:37
|
having nothing better to do ;-) I added an Ant task version of SiteHack. People happy for me to release it? S. - - - - - - - - - - - - - - - Steve Freeman st...@m3... Programme chair OT2003. http://www.ot2003.org "Nonsense is just nonsense, but the study of nonsense is science." |
From: Steve F. <sm...@us...> - 2002-09-09 00:44:53
|
Update of /cvsroot/mockobjects/mockobjects-java/doc/com/mockobjects/doc In directory usw-pr-cvs1:/tmp/cvs-serv9735/doc/com/mockobjects/doc Added Files: SiteTemplate.java Log Message: Added SiteTemplate ant task as alternative to SiteHack --- NEW FILE: SiteTemplate.java --- package com.mockobjects.doc; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.MatchingTask; import java.io.*; import java.text.MessageFormat; public class SiteTemplate extends MatchingTask { private File dir; private File todir; private File templatefile; public void setTemplatefile(File aTemplatefile) { templatefile = aTemplatefile; } public void setTodir(File aTodir) { todir = aTodir; } public void setDir(File aDir) { dir = aDir; } /** * @see org.apache.tools.ant.Task#execute() */ public void execute() throws BuildException { validateAttributes(); log("Template file: " + templatefile.getPath(), Project.MSG_INFO); createOutputDirectory(); try { MessageFormat template = new MessageFormat(readFileContent(templatefile)); DirectoryScanner scanner = getDirectoryScanner(dir); String[] filenames = scanner.getIncludedFiles(); for (int i = 0; i < filenames.length; ++i) { String filename = filenames[i]; writeToFile(filename, formattedContents(template, filename)); } } catch (IOException e) { log("IO Failure " + e.getMessage(), Project.MSG_ERR); } } private String formattedContents(MessageFormat template, String filename) throws IOException { return template.format( new Object[] { readFileContent(new File(dir, filename))}); } private void createOutputDirectory() { if (!todir.exists()) { todir.mkdirs(); } } private void validateFile(File file, String propertyName) { if (file == null) { throw new BuildException("Missing " + propertyName, location); } if (!file.exists()) { throw new BuildException("Cannot find " + file.getPath(), location); } } private void validateAttributes() throws BuildException { validateFile(templatefile, "templatefile"); validateFile(dir, "dir"); validateFile(todir, "todir"); } private final String readFileContent(File inputFile) throws IOException { FileReader rd = new FileReader(inputFile); try { BufferedReader reader = new BufferedReader(rd); StringBuffer fileContents = new StringBuffer(); String line = reader.readLine(); while (line != null) { fileContents.append(line); fileContents.append("\r\n"); line = reader.readLine(); } return fileContents.toString(); } finally { rd.close(); } } private final void writeToFile(String fileName, String content) throws IOException { File outputFile = new File(todir, fileName); log("Writing to " + outputFile.getPath(), Project.MSG_INFO); FileWriter writer = new FileWriter(outputFile); try { writer.write(content); writer.flush(); } finally { writer.close(); } } } |
From: Steve F. <sm...@us...> - 2002-09-09 00:44:53
|
Update of /cvsroot/mockobjects/mockobjects-java/doc In directory usw-pr-cvs1:/tmp/cvs-serv9735/doc Modified Files: site.xml Log Message: Added SiteTemplate ant task as alternative to SiteHack Index: site.xml =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/doc/site.xml,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- site.xml 2 Sep 2002 10:26:25 -0000 1.3 +++ site.xml 9 Sep 2002 00:44:50 -0000 1.4 @@ -28,4 +28,33 @@ </java> </target> + + <target name="clean"> + <delete quiet="true"> + <fileset dir="out" /> + <fileset includes="**/*.class" /> + </delete> + </target> + + <target name="add-task"> + <javac srcdir="." /> + <taskdef name="template" + classname="com.mockobjects.doc.SiteTemplate" + classpath="."/> + </target> + + <target name="create-out-dir"> + <mkdir dir="out" /> + </target> + + <target name="format" + depends="add-task, create-out-dir, copy-stylesheet" + description="Create the output directory and copy templated files over."> + <template + templatefile="html/template.txt" + todir="out" + dir="html" + includes="*.html"/> + </target> + </project> |
From: Steve F. <sm...@us...> - 2002-09-09 00:44:19
|
Update of /cvsroot/mockobjects/mockobjects-java/doc/com/mockobjects/doc In directory usw-pr-cvs1:/tmp/cvs-serv9399/doc/com/mockobjects/doc Log Message: Directory /cvsroot/mockobjects/mockobjects-java/doc/com/mockobjects/doc added to the repository |
From: Steve F. <sm...@us...> - 2002-09-09 00:44:19
|
Update of /cvsroot/mockobjects/mockobjects-java/doc/com In directory usw-pr-cvs1:/tmp/cvs-serv9399/doc/com Log Message: Directory /cvsroot/mockobjects/mockobjects-java/doc/com added to the repository |
From: Steve F. <sm...@us...> - 2002-09-09 00:44:19
|
Update of /cvsroot/mockobjects/mockobjects-java/doc/com/mockobjects In directory usw-pr-cvs1:/tmp/cvs-serv9399/doc/com/mockobjects Log Message: Directory /cvsroot/mockobjects/mockobjects-java/doc/com/mockobjects added to the repository |
From: Steve F. <st...@m3...> - 2002-09-08 20:05:33
|
Kudos to Jeff (custommonkey). S. - - - - - - - - - - - - - - - Steve Freeman st...@m3... Programme chair OT2003. http://www.ot2003.org "Nonsense is just nonsense, but the study of nonsense is science." ----- Original Message ----- From: "Vincent Massol" <vm...@oc...> To: "'MockObjects'" <moc...@li...> Sent: Sunday, September 08, 2002 4:43 PM Subject: [MO-java-dev] Comments on the web site > Hi, > > I just discovered that the web site had a new look. I kinda like it! > Here are a few comments (sorry not to correct them right away, but my > environment is not set up right now and I'm a bit in a rush): > > 1/ Copyright at the bottom of the page should say 2001-2002 > > 2/ The font for normal text is very very small. The first paragraph of > the main page that starts with ""The Mock Objects project is a generic > ..." is way too small compared to the bullet list. > > 3/ The todo page is oooooolddddddd. Version there is 0.02 ... > > 4/ Links: I think we should add MockDoclet > (http://joe.truemesh.com/mockdoclet/) > > But congratulations to you guys. It definitely is better than before! > Again, sorry not to help more. I still hope that I will find some time > for that not too far in the distant future ... |
From: Vincent M. <vm...@oc...> - 2002-09-08 15:49:00
|
Hi, I just discovered that the web site had a new look. I kinda like it! Here are a few comments (sorry not to correct them right away, but my environment is not set up right now and I'm a bit in a rush): 1/ Copyright at the bottom of the page should say 2001-2002 2/ The font for normal text is very very small. The first paragraph of the main page that starts with ""The Mock Objects project is a generic ..." is way too small compared to the bullet list. 3/ The todo page is oooooolddddddd. Version there is 0.02 ... 4/ Links: I think we should add MockDoclet (http://joe.truemesh.com/mockdoclet/) But congratulations to you guys. It definitely is better than before! Again, sorry not to help more. I still hope that I will find some time for that not too far in the distant future ... Thanks -Vincent |
From: Steve F. <sm...@us...> - 2002-09-08 15:19:01
|
Update of /cvsroot/mockobjects/no-stone-unturned/src/java/nostone/addressbook In directory usw-pr-cvs1:/tmp/cvs-serv18399/src/java/nostone/addressbook Modified Files: AddressBookServletTest.java AddressBookServlet.java Log Message: Reworked servlet tests. Realised that testNoEntries is testMissingRequest Added ExpectationValue for parameterName Extracted some instance variables in the test case Index: AddressBookServletTest.java =================================================================== RCS file: /cvsroot/mockobjects/no-stone-unturned/src/java/nostone/addressbook/AddressBookServletTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- AddressBookServletTest.java 2 Sep 2002 22:40:11 -0000 1.2 +++ AddressBookServletTest.java 8 Sep 2002 15:18:57 -0000 1.3 @@ -6,38 +6,64 @@ import javax.servlet.ServletException; import java.io.*; +import com.mockobjects.ExpectationValue; + public class AddressBookServletTest extends TestCase { + private final StringWriter page = new StringWriter(); + private final ExpectationValue requestParameterName = new ExpectationValue("Request parameter name"); + private HttpServletResponse mockResponse = new NullHttpServletResponse() { + private String contentType; + public void setContentType(String aContentType) { + assertEquals("Content type", "text/plain", aContentType); + contentType = aContentType; + } + + public PrintWriter getWriter() throws IOException { + assertNotNull("Should have content type", contentType); + return new PrintWriter(page); + } + }; + private AddressBookServlet servlet = new AddressBookServlet(); + public AddressBookServletTest(String name) { super(name); } public void testNoEntries() throws ServletException, IOException { - final StringWriter page = new StringWriter(); + requestParameterName.setExpected("name"); + HttpServletRequest mockRequest = new NullHttpServletRequest() { + public String getMethod() { + return "GET"; + } + public String getProtocol() { + return "HTTP/1.1"; + } + }; + servlet.service(mockRequest, mockResponse); + requestParameterName.verify(); + assertEquals("Should be empty response", "No address found", page.toString().trim()); + } + + public void testFindOneAddress() throws ServletException, IOException { + requestParameterName.setExpected("name"); HttpServletRequest mockRequest = new NullHttpServletRequest() { - public String getMethod() { - return "GET"; - } - public String getProtocol() { - return "HTTP/1.1"; - } - }; - HttpServletResponse mockResponse = new NullHttpServletResponse() { - private String contentType; - public void setContentType(String aContentType) { - assertEquals("Content type", "text/plain", aContentType); - contentType = aContentType; - } - - public PrintWriter getWriter() throws IOException { - assertNotNull("Should have content type", contentType); - return new PrintWriter(page); - } - }; + public String getMethod() { + return "GET"; + } + public String getProtocol() { + return "HTTP/1.1"; + } - AddressBookServlet servlet = new AddressBookServlet(); + public String getParameter(String parameterName) { + requestParameterName.setActual(parameterName); + return "surname"; + } + }; servlet.service(mockRequest, mockResponse); - assertEquals("Should be empty response", "No address found", page.toString().trim()); + requestParameterName.verify(); + assertEquals("Should be empty response", "surname@domain", page.toString().trim()); } + } Index: AddressBookServlet.java =================================================================== RCS file: /cvsroot/mockobjects/no-stone-unturned/src/java/nostone/addressbook/AddressBookServlet.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- AddressBookServlet.java 2 Sep 2002 22:40:11 -0000 1.2 +++ AddressBookServlet.java 8 Sep 2002 15:18:57 -0000 1.3 @@ -11,9 +11,11 @@ } protected void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException - { + throws ServletException, IOException { + String name = request.getParameter("name"); + response.setContentType("text/plain"); - response.getWriter().println( "No address found" ); + response.getWriter().println( + name == null ? "No address found" : "surname@domain"); } } |
From: Steve F. <sm...@us...> - 2002-09-08 15:19:01
|
Update of /cvsroot/mockobjects/no-stone-unturned/doc/xdocs In directory usw-pr-cvs1:/tmp/cvs-serv18399/doc/xdocs Modified Files: a_longer_example.xml Log Message: Reworked servlet tests. Realised that testNoEntries is testMissingRequest Added ExpectationValue for parameterName Extracted some instance variables in the test case Index: a_longer_example.xml =================================================================== RCS file: /cvsroot/mockobjects/no-stone-unturned/doc/xdocs/a_longer_example.xml,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- a_longer_example.xml 2 Sep 2002 22:40:11 -0000 1.4 +++ a_longer_example.xml 8 Sep 2002 15:18:57 -0000 1.5 @@ -86,6 +86,13 @@ } }</programlisting> + <tip><title>Just do it</title> + <para> + We've just done something here that's worth noticing. We've just created an instance of + a servlet by calling <function>new</function>, rather than using a servlet container. + If we can do that, we can write stand-alone unit tests. + </para> + </tip> <para> Let's see if this test passes. It doesn't test much, not even what it says in its name, but we just want to see if the basic infrastructure works — and we haven't seen a green @@ -320,16 +327,197 @@ &greenbar; <para> - Now we're ready for our first acceptance test. + <comment status="todo">Now we're ready for our first acceptance test.</comment> </para> </section> <!-- We write our first implementation of the servlet --> - <!-- TODO --> - <section> - <title>accept a name and return a result from a hard-coded collection.</title> + <title>We accept a name and return a result from a hard-coded collection.</title> + + <para> + Decided to return a single value for a known name. + First thing to test is that we get the name parameter from the request. + We can check that the <emphasis>right</emphasis> parameter is requested, but also need to test that + any is requested at all. + Copy and rename the test, we'll fix it soon. + But, need to override getParameter(), how can tell it's been called? Use an ExpectationValue. + </para> + +<programlisting> +public void testFindOneAddress() throws ServletException, IOException { + final StringWriter page = new StringWriter(); + final ExpectationValue requestParameterName = new ExpectationValue("Request parameter name"); + + HttpServletRequest mockRequest = new NullHttpServletRequest() { + public String getMethod() { + return "GET"; + } + public String getProtocol() { + return "HTTP/1.1"; + } + + public String getParameter(String parameterName) { + requestParameterName.setActual(parameterName); + return "surname"; + } + }; + + HttpServletResponse mockResponse = new NullHttpServletResponse() { + private String contentType; + public void setContentType(String aContentType) { + assertEquals("Content type", "text/plain", aContentType); + contentType = aContentType; + } + + public PrintWriter getWriter() throws IOException { + assertNotNull("Should have content type", contentType); + return new PrintWriter(page); + } + }; + + requestParameterName.setExpected("name"); + AddressBookServlet servlet = new AddressBookServlet(); + servlet.service(mockRequest, mockResponse); + + requestParameterName.verify(); + assertEquals("Should be empty response", "surname@domain", page.toString().trim()); +} +</programlisting> + +<screen> +There was 1 failure: +1) testFindOneAddress(nostone.addressbook.AddressBookServletTest) +AssertionFailedError: Request parameter name did not receive the expected Value. +Expected: name +Received: Nothing + at com.mockobjects.AbstractExpectation.assertEquals(AbstractExpectation.java:39) + at com.mockobjects.ExpectationValue.verify(ExpectationValue.java:69) + at nostone.addressbook.AddressBookServletTest.testFindOneAddress(AddressBookServletTest.java:81) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at com.intellij.execution.e.bp.main(bp.java:0) + +FAILURES!!! +Tests run: 2, Failures: 1, Errors: 0</screen> + + &redbar; + + <para> + Fix this somehow. + </para> + + <programlisting> +public class AddressBookServlet extends HttpServlet { + public AddressBookServlet() { + } + + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException + { + String name = request.getParameter("name"); + + response.setContentType("text/plain"); + if( name == null ) { + response.getWriter().println( "No address found" ); + } else { + response.getWriter().println("surname@domain"); + } + } +}</programlisting> + &greenbar; + + <para> + The response.getWriter is duplicated, let's refactor. + </para> + + <programlisting> +protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + String name = request.getParameter("name"); + + response.setContentType("text/plain"); + response.getWriter().println( + name == null ? "No address found" : "surname@domain"); +}</programlisting> + &greenbar; + + <para> + Time to fix the tests. Pull lots of stuff into instance fields. + </para> + + <programlisting> +public class AddressBookServletTest extends TestCase { + private final StringWriter page = new StringWriter(); + private final ExpectationValue requestParameterName = new ExpectationValue("Request parameter name"); + private HttpServletResponse mockResponse = new NullHttpServletResponse() { + private String contentType; + public void setContentType(String aContentType) { + assertEquals("Content type", "text/plain", aContentType); + contentType = aContentType; + } + + public PrintWriter getWriter() throws IOException { + assertNotNull("Should have content type", contentType); + return new PrintWriter(page); + } + }; + private AddressBookServlet servlet = new AddressBookServlet(); + + public AddressBookServletTest(String name) { + super(name); + } + + public void testNoEntries() throws ServletException, IOException { + HttpServletRequest mockRequest = new NullHttpServletRequest() { + public String getMethod() { + return "GET"; + } + public String getProtocol() { + return "HTTP/1.1"; + } + }; + servlet.service(mockRequest, mockResponse); + + assertEquals("Should be empty response", "No address found", page.toString().trim()); + } + + public void testFindOneAddress() throws ServletException, IOException { + requestParameterName.setExpected("name"); + HttpServletRequest mockRequest = new NullHttpServletRequest() { + public String getMethod() { + return "GET"; + } + public String getProtocol() { + return "HTTP/1.1"; + } + + public String getParameter(String parameterName) { + requestParameterName.setActual(parameterName); + return "surname"; + } + }; + servlet.service(mockRequest, mockResponse); + + requestParameterName.verify(); + assertEquals("Should be empty response", "surname@domain", page.toString().trim()); + } +}</programlisting> + + <para> + We couldn't reuse mockrequest as it stands because the getParameter() method is different. + Note in this task, testNoEntries is now the wrong thing to test, because we are going to search for names + in a hard-coded address book, and so we will never have no entries. Instead, we want to test searching for + a name that is not in the address book. So testNoEntries should really be testNoAddressFound. + However, at it stands, testNoEntries is actually testing how the servlet handles a request with no name + parameter. This is a useful -- we can reuse the test as it stands to test our servlet's error handing. + A useful clue is that we're not using "surname", the value of the name parameter. + So, the test is driving us to add the book logic to the servlet. + </para> </section> <!-- accept a name and return a result from a hard-coded collection --> + <!-- TODO --> + <section> <title> Retrieve the entries from a file, specified as a servlet property. @@ -356,7 +544,7 @@ Sort the results alphabetically </para></listitem> </itemizedlist> - </chapter> + </chapter> <!-- List all the entries in the book --> <chapter> <title>Add a name and address</title> @@ -372,10 +560,11 @@ lock the file while it's being written. </para></listitem> </itemizedlist> - </chapter> + </chapter> <!-- Add a name and address --> </part> +<!-- <part status="todo"> <title>Iteration 2</title> @@ -427,4 +616,5 @@ Click on name to see its entries. </para> </chapter> -</part> \ No newline at end of file +</part> +--> \ No newline at end of file |
From: Ted H. <th...@us...> - 2002-09-07 18:52:35
|
Update of /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/sql In directory usw-pr-cvs1:/tmp/cvs-serv23360 Modified Files: CommonMockConnection.java Log Message: For consistency, add addExpectedPreparedStatement and deprecate setupAddPreparedStatement. For consistency, add setupIsClosed and depcrecate setupIsClose. Add license, JavaDocs. Add code-dividers for addExpected, setExpected, implemented, notImplemented, et cetera. Sort members alphabetically by property or member name within each division. Wrap lines at 78 characters. Index: CommonMockConnection.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/jdk/common/com/mockobjects/sql/CommonMockConnection.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CommonMockConnection.java 8 Jul 2002 18:33:58 -0000 1.2 +++ CommonMockConnection.java 7 Sep 2002 18:52:31 -0000 1.3 @@ -1,72 +1,277 @@ +/* + * + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2002 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact ap...@ap.... + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * <http://www.apache.org/>. + * + */ + +// ------------------------------------------------------------------------ 78 + +/** + * Abstract Connection for use with mock testing. + * Can verify the expected SQL strings with PreparedStatement or Statement + * instances (mock versions can be used). + * Can verify the state of closed and autoCommit. + * Can verify the number of calls to close, commit, createStatement, and + * rollBack. + * Exceptions to throw can be registered for calling createStatement, + * preparedStatement, or close. + * Several less-often-used methods are not implemented. + * If a notImplemented method is are needed for your project, please submit + * a patch. + * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/sql/Connection.html">javax.sql.Connection</a> + * @author + * @author Jeff Martin + * @author Ted Husted + * @version $Revision$ $Date$ + */ package com.mockobjects.sql; -import com.mockobjects.*; - -import java.sql.*; +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; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.PreparedStatement; +import java.sql.Statement; +import java.sql.SQLException; +import java.sql.SQLWarning; import java.util.Map; public abstract class CommonMockConnection extends MockObject implements Connection { - private ExpectationCounter myCommitCalls = new ExpectationCounter("CommonMockConnection.commit"); - private ExpectationCounter myRollbackCalls = new ExpectationCounter("CommonMockConnection.rollback"); - private ExpectationCounter myCloseCalls = new ExpectationCounter("CommonMockConnection.close"); - private ExpectationCollection myPreparedStatementStrings = new ExpectationList("CommonMockConnection.preparedStatementString"); - private ReturnObjectList myPreparedStatements = new ReturnObjectList("statements"); - private SQLException myStatementException = null; +// -------------------------------------------------------------------- fields - private ExpectationCounter myCreateStatementCalls = new ExpectationCounter("CommonMockConnection.createStatement"); - private ExpectationValue myAutoCommit = new ExpectationValue("CommonMockConnection.setAutoCommit"); - private Statement myStatement; - private DatabaseMetaData myMetaData; + private ExpectationValue myAutoCommit = + new ExpectationValue("CommonMockConnection.setAutoCommit"); + + private ExpectationCounter myCloseCalls = + new ExpectationCounter("CommonMockConnection.close"); + + private ExpectationCounter myCommitCalls = + new ExpectationCounter("CommonMockConnection.commit"); + + private ExpectationCounter myCreateStatementCalls = + new ExpectationCounter("CommonMockConnection.createStatement"); private boolean myIsClosed; - private SQLException myIsClosedException; + private SQLException myCloseException; + private SQLException myIsClosedException; + + private DatabaseMetaData myMetaData; + + private ReturnObjectList myPreparedStatements = + new ReturnObjectList("CommonMockConnection.PreparedStatements"); + + private ExpectationCollection myPreparedStatementStrings = + new ExpectationList("CommonMockConnection.preparedStatementString"); + + private ExpectationCounter myRollbackCalls = + new ExpectationCounter("CommonMockConnection.rollback"); + + private Statement myStatement; + + private SQLException myStatementException = null; + +// --------------------------------------------------------------- addExpected + + /** + * Add an SQL string to use with a prepared staement. + */ + public void addExpectedPreparedStatementString(String sql) { + myPreparedStatementStrings.addExpected(sql); + } + + /** + * Add a PreparedStatement instance for use with tests. + */ + public void addExpectedPreparedStatement(PreparedStatement prepared) { + myPreparedStatements.addObjectToReturn(prepared); + } + +// --------------------------------------------------------------- setExpected + + /** + * Register the anticipated value for autoCommit during testing. + */ + public void setExpectedAutoCommit(boolean autoCommit) { + myAutoCommit.setExpected(autoCommit); + } + + + /** + * Register the number of close calls the test should make. + * The valid method will report any discrepancy with the + * actual count. + */ public void setExpectedCloseCalls(int callCount) { myCloseCalls.setExpected(callCount); } + /** + * Register the number of commit calls the test should make. + * The valid method will report any discrepancy with the + * actual count. + */ public void setExpectedCommitCalls(int callCount) { myCommitCalls.setExpected(callCount); } + /** + * Register the number of create statement calls the test should make. + * The valid method will report any discrepancy with the + * actual count. + */ public void setExpectedCreateStatementCalls(int calls) { myCreateStatementCalls.setExpected(calls); } - public void addExpectedPreparedStatementString(String sql) { - myPreparedStatementStrings.addExpected(sql); - } - + /** + * Register the number of roll back calls the test should make. + * The valid method will report any discrepancy with the + * actual count. + */ public void setExpectedRollbackCalls(int callCount) { myRollbackCalls.setExpected(callCount); } +// --------------------------------------------------------------------- setup + + /** + * @deprecated Use addExpectedPreparedStatement. + */ public void setupAddPreparedStatement(PreparedStatement prepared) { myPreparedStatements.addObjectToReturn(prepared); } - public void setupStatement(Statement statement) { - myStatement = statement; + /** + * Pass the SQL exception to throw if close is called + * during a test. + */ + public void setupCloseException(SQLException aCloseException) { + myCloseException = aCloseException; } - public void setupThrowExceptionOnPrepareOrCreate(SQLException exception) { - myStatementException = exception; + /** + * @deprecated Use setupIsClosed + */ + public void setupIsClose(boolean aIsClosed) { + myIsClosed = aIsClosed; + } + + /** + * Pass the value to return if isClosed is called during a test. + * This is returned unless an isClosedException has been set. + */ + public void setupIsClosed(boolean aIsClosed) { + myIsClosed = aIsClosed; + } + + /** + * Pass the SQL exception instance to throw if isClosed + * is called during a test. + */ + public void setupIsClosedException(SQLException aIsClosedException) { + myIsClosedException = aIsClosedException; } + /** + * Pass the DataBaseMetaData instance for use with tests. + */ public void setupMetaData(DatabaseMetaData metaData) { myMetaData = metaData; } - public void clearWarnings() throws SQLException { - notImplemented(); + /** + * Pass the Statement instance for use with tests. + */ + public void setupStatement(Statement statement) { + myStatement = statement; } - public void setupCloseException(SQLException aCloseException) { - myCloseException = aCloseException; + /** + * Pass the SQL exception to throw if preparedStatement or createStatement + * is called during a test. + */ + public void setupThrowExceptionOnPrepareOrCreate(SQLException exception) { + myStatementException = exception; + } + +// --------------------------------------------------------------------- throw + + /** + * Throw the Statement instance passed to + * setupThrowExceptionOnPrepareOrCreate, if any. + */ + private void throwStatementExceptionIfAny() throws SQLException { + if(null != myStatementException) { + throw myStatementException; + } } +// --------------------------------------------------------------- implemented + + /** + * Will throw the CloseException if it has been set, + * or otherwise increment the number or close calls. + */ public void close() throws SQLException { if(myCloseException != null) { throw myCloseException; @@ -74,16 +279,84 @@ myCloseCalls.inc(); } + /** + * Increments the number of commit calls. + */ public void commit() throws SQLException { myCommitCalls.inc(); } + /** + * Will throw either of the statement exceptions if one has been + * set, + * or otherwise return the Statement passed to + * setupStatement. + */ public Statement createStatement() throws SQLException { myCreateStatementCalls.inc(); throwStatementExceptionIfAny(); return myStatement; } + /** + * Returns the DatabaseMetaData instance passed to setupMetaData. + */ + public DatabaseMetaData getMetaData() + throws SQLException { + return myMetaData; + } + + /** + * Throw the isClosedException if it has been set, + * or otherwise return the value passed to setupIsClosed. + */ + public boolean isClosed() throws SQLException { + if(myIsClosedException != null) { + throw myIsClosedException; + } + return myIsClosed; + } + + /** + * Throws a statement exception if one has been registered + * (@see throwStatementExceptionIfAny) + * or returns the next PreparedStatement instance passed to + * setupAddPreparedStatement. + */ + public PreparedStatement prepareStatement(String sql) throws SQLException { + myPreparedStatementStrings.addActual(sql); + throwStatementExceptionIfAny(); + return (PreparedStatement) myPreparedStatements.nextReturnObject(); + } + + /** + * Increments the number of roll back calls. + */ + public void rollback() throws SQLException { + myRollbackCalls.inc(); + } + + /** + * Stores the value passed for comparison with the value passed + * to setupAutoCommit. + * The validate method will report any discrepency. + */ + public void setAutoCommit(boolean autoCommit) throws SQLException { + myAutoCommit.setActual(autoCommit); + } + +// ------------------------------------------------------------ notImplemented + + /** + * Calls notImplemented. + */ + public void clearWarnings() throws SQLException { + notImplemented(); + } + + /** + * Calls notImplemented. Returns null. + */ public Statement createStatement( int resultSetType, int resultSetConcurrency) @@ -92,67 +365,74 @@ return null; } + /** + * Calls notImplemented. Returns false. + */ public boolean getAutoCommit() throws SQLException { notImplemented(); return false; } + /** + * Calls notImplemented. Returns null. + */ public String getCatalog() throws SQLException { notImplemented(); return null; } - public DatabaseMetaData getMetaData() - throws SQLException { - return myMetaData; - } - + /** + * Calls notImplemented. Returns 0. + */ public int getTransactionIsolation() throws SQLException { notImplemented(); return 0; } + /** + * Calls notImplemented. Returns null. + */ public Map getTypeMap() throws SQLException { notImplemented(); return null; } + /** + * Calls notImplemented. Returns null. + */ public SQLWarning getWarnings() throws SQLException { notImplemented(); return null; } - public void setupIsClosedException(SQLException aIsClosedException) { - myIsClosedException = aIsClosedException; - } - - public void setupIsClose(boolean aIsClosed) { - myIsClosed = aIsClosed; - } - - public boolean isClosed() throws SQLException { - if(myIsClosedException != null) { - throw myIsClosedException; - } - return myIsClosed; - } - + /** + * Calls notImplemented. Returns false. + */ public boolean isReadOnly() throws SQLException { notImplemented(); return false; } + /** + * Calls notImplemented. Returns null. + */ public String nativeSQL(String sql) throws SQLException { notImplemented(); return null; } + /** + * Calls notImplemented. Returns null. + */ public CallableStatement prepareCall(String sql) throws SQLException { notImplemented(); return null; } + /** + * Calls notImplemented. Returns null. + */ public CallableStatement prepareCall( String sql, int resultSetType, @@ -162,12 +442,9 @@ return null; } - public PreparedStatement prepareStatement(String sql) throws SQLException { - myPreparedStatementStrings.addActual(sql); - throwStatementExceptionIfAny(); - return (PreparedStatement) myPreparedStatements.nextReturnObject(); - } - + /** + * Calls notImplemented. Returns null. + */ public PreparedStatement prepareStatement( String sql, int resultSetType, @@ -177,38 +454,33 @@ return null; } - public void rollback() throws SQLException { - myRollbackCalls.inc(); - } - - public void setExpectedAutoCommit(boolean autoCommit) { - myAutoCommit.setExpected(autoCommit); - } - - public void setAutoCommit(boolean autoCommit) throws SQLException { - myAutoCommit.setActual(autoCommit); - } - + /** + * Calls notImplemented. + */ public void setCatalog(String catalog) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void setReadOnly(boolean readOnly) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void setTransactionIsolation(int level) throws SQLException { notImplemented(); } + /** + * Calls notImplemented. + */ public void setTypeMap(Map map) throws SQLException { notImplemented(); } - private void throwStatementExceptionIfAny() throws SQLException { - if(null != myStatementException) { - throw myStatementException; - } - } -} +} // end CommonMockConnection |
From: Jeff M. <cus...@us...> - 2002-09-06 12:53:08
|
Update of /cvsroot/mockobjects/mockobjects-java/doc/html In directory usw-pr-cvs1:/tmp/cvs-serv5184/doc/html Modified Files: faq.html Log Message: Added some bits to the FAQ Index: faq.html =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/doc/html/faq.html,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- faq.html 2 Sep 2002 10:24:37 -0000 1.2 +++ faq.html 6 Sep 2002 12:53:04 -0000 1.3 @@ -2,11 +2,11 @@ <h2>General Questions About Mocks</h2> <h3>What's a mock object?</h3> - <p>A mock object is a "double agent" used to test the behavior + <p>A mock object is a "double agent" used to test the behaviour of other objects. First, a mock object acts as a faux implementation -of an interface or class that simulates the external behavior of a true implementation. +of an interface or class that mimics the external behaviour of a true implementation. Second, a mock object observes how other objects interact with its -methods and compares actual behavior with preset expectations. When a discrepancy +methods and compares actual behaviour with preset expectations. When a discrepancy occurs, a mock object can interrupt the test and report the anomaly. If the discrepancy cannot be noted during the test, a verification method called by the tester ensures that all expectations have been met or failures reported.<br> @@ -20,10 +20,10 @@ will be passed a certain set of parameters for use with a given SQL command. A mock object can be told to expect conditions such as these, so that it can report back when our expectations are not met. The MockObjects API has -refactored this mechanism into a framework of Expectation classes. </p> +re factored this mechanism into a framework of Expectation classes. </p> <h3>Why should I bother?</h3> -<p>Today, most developers recognize the value of unit testing. But many developers +<p>Today, most developers recognise the value of unit testing. But many developers also find that creating and maintaining non-trivial unit tests becomes difficult as products mature. Writing significant unit tests can tempt developers into making objects "test-aware". This can complicate production code and begins @@ -37,7 +37,7 @@ hardware devices.</p> <p> Mock objects can also simulate states that may be difficult or time-consuming -to realize in a runtime environment. A mock object can throw any exception +to realise in a runtime environment. A mock object can throw any exception or produce any error condition on demand. For example, using a real database, to see how an object will react to an offline database you would have to actually down the database. Using a mock JDBC connection, you can simulate @@ -62,7 +62,7 @@ without making changes to your production objects. Generally, the better designed your application, the easier it should be to test with mock objects. If an application does not test well, there are usually ways to improve its -design and provide better testability. In practice, many developers +design and provide better testability. In practise, many developers find that approaching new development with a test-first perspective helps them write better programs more quickly. Writing tests for features helps defines the objects we need to provide those features. Test-driven design @@ -71,9 +71,15 @@ <h3>What are some of the patterns used to create tests with mock objects?</h3> <h3>Who discovered mock objects?</h3> <h3>What is the difference between stub objects and mock objects?</h3> - - -<h2>About the Mock Object Implementation</h2> + <p> + A stub object is the most minimal implementation of a class providing +nothing more than the implementation of an interface. A mock object adds to this +the ability to preload an object with data which can be played back during a +test. In addition to this is can be given details of the expected interactions +that other objects will have with it and at the end of testing verify that these +have taken place. + </p> + <h2>About the Mock Object Implementation</h2> <h3>Why do I have to call setup???? to instead of set??? to add something to @@ -82,13 +88,24 @@ </p> - <h3>Who do I contribute changes back to the mock objects project?</h3> + <h3>How do I contribute changes back to the mock objects project?</h3> <p> + If you've made changes to any of the mock objects we'd love to see them an +hopefully include them back into our code base for other people to make use of. +The way to do this is to send them to our <a href="mailto:moc...@li...">development</a> mailing list. Our preferred format is to provide changes as unified diff format (diff -u), but anything will do really. </p> - <h3>What does it mean when I get a NotImplementedException?</h3> <p> + As a matter of course we try not to do anymore work than is necessary when +creating a mock. This means that if there are methods on a class which are not +used we don't write any mock code in them until someone has a need for it. In +order to make it easier to tell with methods have been implemented and which +haven't any method which has not been implemented will throw a +NotImplementedException when it is called. If this happens during a test you can +either write an implementation for the method and send us a patch for it, or +mail us with details of how you'd like to use the method and we'll try(spare +time permitting) to implement it. </p> @@ -118,7 +135,7 @@ <h3>Why are the internals of mock private when there just test class?</h3> - <h3>What is the best practice for integrating mocks into a project?</h3> + <h3>What is the best practise for integrating mocks into a project?</h3> <h2>Other Questions</h2> |
From: Jeff M. <cus...@us...> - 2002-09-06 11:26:51
|
Update of /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/helpers In directory usw-pr-cvs1:/tmp/cvs-serv13480/src/j2ee/common/com/mockobjects/helpers Modified Files: ServletTestHelper.java TagTestHelper.java Added Files: AbstractServletTestHelper.java FilterTestHelper.java Log Message: Added Servlet filter test helper --- NEW FILE: AbstractServletTestHelper.java --- package com.mockobjects.helpers; import com.mockobjects.servlet.*; /** * $Revision: 1.1 $ */ public abstract class AbstractServletTestHelper { protected final MockHttpServletRequest request = new MockHttpServletRequest(); protected final MockHttpServletResponse response = new MockHttpServletResponse(); protected final MockHttpSession httpSession = new MockHttpSession(); protected final MockRequestDispatcher requestDispatcher = new MockRequestDispatcher(); protected final MockServletContext servletContext = new MockServletContext(); protected final MockServletConfig servletConfig = new MockServletConfig(); public AbstractServletTestHelper() { request.setSession(httpSession); servletContext.setupGetRequestDispatcher(requestDispatcher); } public MockHttpServletRequest getRequest() { return request; } public MockHttpSession getHttpSession() { return httpSession; } public MockRequestDispatcher getRequestDispatcher() { return requestDispatcher; } public MockHttpServletResponse getResponse() { return response; } public MockServletContext getServletContext() { return servletContext; } public MockServletConfig getServletConfig() { return servletConfig; } } --- NEW FILE: FilterTestHelper.java --- package com.mockobjects.helpers; import com.mockobjects.servlet.MockFilterChain; import com.mockobjects.servlet.MockFilterConfig; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import java.io.IOException; /** * $Revision: 1.1 $ */ public class FilterTestHelper extends AbstractServletTestHelper { private final Filter filter; private final MockFilterChain filterChain = new MockFilterChain(); private final MockFilterConfig filterConfig = new MockFilterConfig(); public FilterTestHelper(Filter filter) { this.filter = filter; filterConfig.setupGetServletContext(servletContext); } public MockFilterChain getFilterChain() { return filterChain; } public MockFilterConfig getFilterConfig() { return filterConfig; } public void testInit() throws ServletException { filter.init(filterConfig); } public void testDoFilter() throws ServletException, IOException { filter.doFilter(request, response, filterChain); } } Index: ServletTestHelper.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/helpers/ServletTestHelper.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ServletTestHelper.java 28 Aug 2002 17:36:28 -0000 1.1 +++ ServletTestHelper.java 6 Sep 2002 11:26:48 -0000 1.2 @@ -1,9 +1,7 @@ package com.mockobjects.helpers; -import com.mockobjects.servlet.*; - -import javax.servlet.http.HttpServlet; import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; import java.io.IOException; /** @@ -12,49 +10,12 @@ * @see com.mockobjects.servlet.MockHttpServletRequest#setSession * @see com.mockobjects.servlet.MockServletContext#setupGetRequestDispatcher */ -public class ServletTestHelper { - protected final MockHttpServletRequest request = new MockHttpServletRequest(); - protected final MockHttpServletResponse response = new MockHttpServletResponse(); - protected final MockHttpSession httpSession = new MockHttpSession(); - protected final MockRequestDispatcher requestDispatcher = new MockRequestDispatcher(); - protected final MockServletContext servletContext = new MockServletContext(); - protected final MockServletConfig servletConfig = new MockServletConfig(); +public class ServletTestHelper extends AbstractServletTestHelper { private final HttpServlet testSubject; public ServletTestHelper(HttpServlet testSubject) { + super(); this.testSubject = testSubject; - request.setSession(httpSession); - servletContext.setupGetRequestDispatcher(requestDispatcher); - } - - protected ServletTestHelper(){ - this.testSubject = null; - request.setSession(httpSession); - servletContext.setupGetRequestDispatcher(requestDispatcher); - } - - public MockHttpServletRequest getRequest() { - return request; - } - - public MockHttpSession getHttpSession() { - return httpSession; - } - - public MockRequestDispatcher getRequestDispatcher() { - return requestDispatcher; - } - - public MockHttpServletResponse getResponse() { - return response; - } - - public MockServletContext getServletContext() { - return servletContext; - } - - public MockServletConfig getServletConfig() { - return servletConfig; } /** Index: TagTestHelper.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/j2ee/common/com/mockobjects/helpers/TagTestHelper.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- TagTestHelper.java 28 Aug 2002 18:27:36 -0000 1.2 +++ TagTestHelper.java 6 Sep 2002 11:26:48 -0000 1.3 @@ -17,7 +17,7 @@ * @see MockPageContext#setServletContext(); * @see MockPageContext#setSession(); */ -public class TagTestHelper extends ServletTestHelper { +public class TagTestHelper extends AbstractServletTestHelper { private final MockPageContext pageContext = new MockPageContext(); private final MockBodyContent bodyContent = new MockBodyContent(); private final MockJspWriter outWriter = new MockJspWriter(); |
From: Jeff M. <je...@mk...> - 2002-09-06 08:43:32
|
On Thu, 2002-09-05 at 22:12, Steve Freeman wrote: > > Fixed MapEntry's equality behaviour when working with arrays > > I know it's a bit late, but I'm not convinced by this one. Have you found > this to be a problem in real life? https://sourceforge.net/tracker/?func=detail&atid=118189&aid=600870&group_id=18189 > > Also, take a look at java.util.Arrays.equals(). I'll have a play. > > S. > > > > > ------------------------------------------------------- > This sf.net email is sponsored by: OSDN - Tired of that same old > cell phone? Get a new here for FREE! > https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev -- jeff martin information technologist mkodo limited mobile: 44 (0) 78 5547 8331 phone: 44 (0) 20 2226 4545 email: je...@mk... www.mkodo.com |
From: Steve F. <st...@m3...> - 2002-09-05 21:13:31
|
> Fixed MapEntry's equality behaviour when working with arrays I know it's a bit late, but I'm not convinced by this one. Have you found this to be a problem in real life? Also, take a look at java.util.Arrays.equals(). S. |
From: Jeff M. <cus...@us...> - 2002-09-05 08:39:27
|
Update of /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects In directory usw-pr-cvs1:/tmp/cvs-serv1044/src/core/com/mockobjects Modified Files: MapEntry.java Log Message: Fixed MapEntry's equality behaviour when working with arrays Index: MapEntry.java =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/src/core/com/mockobjects/MapEntry.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MapEntry.java 29 Jul 2001 19:50:24 -0000 1.1 +++ MapEntry.java 5 Sep 2002 08:39:22 -0000 1.2 @@ -1,9 +1,10 @@ package com.mockobjects; -import java.util.*; - import com.mockobjects.util.Null; +import java.lang.reflect.Array; +import java.util.Map; + /** * A public MapEntry data type that can be used where the Map.Entry interface is required * (needed because the Sun implementation is package protected) @@ -24,7 +25,47 @@ return false; } MapEntry other = (MapEntry) o; - return myKey.equals(other.getKey()) && myValue.equals(other.getValue()); + + if (myValue.getClass().isArray() && other.getValue().getClass().isArray()) { + return arrayEquals(other.getValue()); + } else { + return myKey.equals(other.getKey()) && myValue.equals(other.getValue()); + } + } + + private final boolean arrayEquals(Object anArray) { + int i = 0; + boolean endOfThisArray = false; + boolean endOfAnotherArray = false; + + while (true) { + Object valueOfThis = null; + Object valueOfAnother = null; + + try { + valueOfThis = Array.get(myValue, i); + } catch (ArrayIndexOutOfBoundsException e) { + endOfThisArray = true; + } + + try { + valueOfAnother = Array.get(anArray, i); + } catch (ArrayIndexOutOfBoundsException e) { + endOfAnotherArray = true; + } + + if (endOfThisArray && endOfAnotherArray) { + return true; + } + + if (valueOfThis != null || valueOfAnother != null) { + if (valueOfThis == null || !valueOfThis.equals(valueOfAnother)) { + return false; + } + } + + i++; + } } public Object getKey() { @@ -36,7 +77,20 @@ } public int hashCode() { - return myKey.hashCode() ^ myValue.hashCode(); + int hash = myKey.hashCode(); + if (myValue.getClass().isArray()) { + int i = 0; + + try { + while (true) { + hash = hash ^ Array.get(myValue, i++).hashCode(); + } + } catch (ArrayIndexOutOfBoundsException e) { + } + } else { + hash = hash ^ myValue.hashCode(); + } + return hash; } public Object setValue(Object aValue) { |