From: Jeff M. <je...@mk...> - 2002-04-17 11:51:05
|
On Wed, 2002-04-17 at 11:19, Oskar Hannesson wrote: > Hi. > I could not live with out the unit tests ... they make you feel so safe := ) >=20 > I ran my modified Unit test against your code and found three things > missing. > * Missing set-up method for getTableName() > * Missing set-up method for getColumnClassName() > * The getColumnLabel(...) should return the same value as > getColumName(...) (At least my Oracle JDBC drivers does so) >=20 > Also I saw that you used myNames.remove(0) when you retrieve the column > Name. > Shouldn't it be implemented like this : > public String getColumnName(int aColumnIndex) throws SQLException { > return (String)myNames.get(aColumnIndex-1); > } > In stead of: > public String getColumnName(int aColumnIndex) throws SQLException { > return (String)myNames.remove(0); > } The idea behind this this is to setup a list of the columns that are needed in the order they are required. So regardless of the number that's passed in you get the column name out that you setup in the test. What we should also have is a list of the expected indexes. private ExpectationList myColumnIndices =3D new ExpectationList("ColumnIndices"); ... public void addExpectedColumnIndices(int aColumnIndex) throws SQLException = { myColumnIndices.addExpected(aColumnIndex); } public String getColumnName(int aColumnIndex) throws SQLException { myColumnIndices.addActual(aColumnIndex); return (String)myNames.remove(0); } This way you separating out the two things your testing. 1. That your requesting the right columns in the right order=20 e.g 1,2,3,4 not 1,1,1,1,3,4 2. That the code that handles the column name behaves correctly given a know list of columns names. I'll put you path in with the above changes unless anyone yells at me first ;o) >=20 > Anyway I applied the above changes to MockResultSetMetaData and attached = it > to this mail plus the Unit test. > I put the unittest under the package "com.mockobjects.sql.test" >=20 > Regards. > Oskar H. >=20 > PS! Here is a diff -u of the code >=20 > --- > C:\tmp\mockobjects\mockobjects-java\src\jdk\common\com\mockobjects\sql\Mo= ckR > esultSetMetaData.java Tue Apr 16 17:04:02 2002 > +++ > C:\projects\MockObjects2\src\jdk\common\com\mockobjects\sql\MockResultSet= Met > aData.java Wed Apr 17 09:38:49 2002 > @@ -9,6 +9,8 @@ > implements ResultSetMetaData { >=20 > private Vector myNames =3D new Vector(); > + private Vector myTableNames =3D new Vector(); > + private Vector myColumnClassNames =3D new Vector(); >=20 > /** > * @see ResultSetMetaData#getColumnCount() > @@ -76,9 +78,8 @@ > /** > * @see ResultSetMetaData#getColumnLabel(int) > */ > - public String getColumnLabel(int arg0) throws SQLException { > - notImplemented(); > - return null; > + public String getColumnLabel(int aColumnIndex) throws SQLException { > + return getColumnName(aColumnIndex); > } >=20 > public void addColumnNames(String[] allNames) { > @@ -97,7 +98,7 @@ > * @see ResultSetMetaData#getColumnName(int) > */ > public String getColumnName(int aColumnIndex) throws SQLException { > - return (String)myNames.remove(0); > + return (String)myNames.get(aColumnIndex-1); > } >=20 > /** > @@ -127,9 +128,16 @@ > /** > * @see ResultSetMetaData#getTableName(int) > */ > - public String getTableName(int arg0) throws SQLException { > - notImplemented(); > - return null; > + public String getTableName(int aColumnIndex) throws SQLException { > + return (String)myTableNames.get(aColumnIndex-1); > + } > + > + public void addTableNames(String[] allNames) { > + if (myTableNames !=3D null) { > + for (int i =3D 0; i < allNames.length; i++) { > + myTableNames.add(allNames[i]); > + } > + } > } >=20 > /** > @@ -183,8 +191,15 @@ > /** > * @see ResultSetMetaData#getColumnClassName(int) > */ > - public String getColumnClassName(int arg0) throws SQLException { > - notImplemented(); > - return null; > + public String getColumnClassName(int aColumnIndex) throws SQLExcepti= on > { > + return (String)myColumnClassNames.get(aColumnIndex-1); > + } > + > + public void addColumnClassNames(String[] allNames) { > + if (myColumnClassNames !=3D null) { > + for (int i =3D 0; i < allNames.length; i++) { > + myColumnClassNames.add(allNames[i]); > + } > + } > } > } >=20 >=20 > ------------------- THE DIFF END ---------------------------- >=20 > -----Original Message----- > From: moc...@li... > [mailto:moc...@li...]On Behalf Of > Christian Trutz > Sent: 16. apr=EDl 2002 16:58 > To: Mockobjects > Subject: Re: [MO-java-dev] MockConnection >=20 >=20 > Hi Oskar, >=20 > some unit tests for MockResultSetMetaData would be very nice ;-) >=20 > Christian >=20 > -----Urspr=FCngliche Nachricht----- > Von: moc...@li... > [mailto:moc...@li...]Im Auftrag von > Oskar Hannesson > Gesendet: Dienstag, 16. April 2002 18:34 > An: 'Jeff Martin'; 'MockObjects' > Betreff: [MO-java-dev] MockConnection >=20 >=20 > Hi there! > It is nice to see the MockResultSetMetaData class finally make its way in= to > CVS , even though I posted similar code (+ unit test) some six months ago= :-( > When I started using Mockobjects last year I ran in to problems having > multiple Statements pr. connection. > The current version of MockConnection supports only one Statement pr. > connection so I modified it and posted it to this group. > The code never made it to the CVS so I ask: > Is someone currently working on this problem or should I try to re-commit= my > implementation and hope for a better response ? >=20 > I found some 8 months old code in CVS > (mockobjects-java/src/extensions/com/mockobjects/eziba/sql) which seem to= be > addressing some this problem. > Is this perhaps an upcoming version of the sql package? >=20 > Regards > Oskar Hannesson > deCODE Genetics > Addr: Sturlugata 8 , 101 Reykjavik, Iceland > Tel: (354) 570-1900 > Fax: (354) 570-1903 > Web: www.decode.com >=20 > PS! > I really hate relying on my own private version of MockObjects. >=20 >=20 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev >=20 >=20 >=20 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev --=20 |