From: Vincent M. <vm...@oc...> - 2002-12-17 11:09:21
|
Hi, I believe there is a common "bug" that can be found in several of our mocks objects. Here's an example, from MockResultSet.java (line 281): public ResultSetMetaData getMetaData() throws SQLException { return myMetaData; } If no setup has been done, it will return null. That's the problem. Imagine the following piece of code (that is part of a third party library): 1 protected void introspect() throws SQLException { 2 3 // Accumulate an ordered list of DynaProperties 4 ArrayList list = new ArrayList(); 5 ResultSetMetaData metadata = resultSet.getMetaData(); 6 int n = metadata.getColumnCount(); [...] If I have some of my code that class under test that calls introspect() and if I haven't set up the behaviour for getMetaData(), I will get a NPE. I was very lucky here as I was able to obtain the source code for this third party library and thus I could find out that the problem was that getMetaData was called. But we might not get that lucky every time! I believe the correct implementation should check if myMetaData has been set or not and if not, throw an exception stating it. What do you think? Thanks -Vincent |
From: Tim M. <tim...@po...> - 2002-12-18 00:27:12
|
Yes - that would be a good improvement - I think Ivan's mockmaker implementation does this with its ReturnValues object and the not enough values exception... we should roll this into a unified implementation (the flaw in the mockmaker stuff is that it doesn't tell you the name of the object that didn't have enough values (like expection list and set do) so its a bit mysterious. Tim -----Original Message----- From: moc...@li... [mailto:moc...@li...]On Behalf Of Vincent Massol Sent: 17 December 2002 11:09 To: 'MockObjects' Subject: [MO-java-dev] Important "bug" in the library Hi, I believe there is a common "bug" that can be found in several of our mocks objects. Here's an example, from MockResultSet.java (line 281): public ResultSetMetaData getMetaData() throws SQLException { return myMetaData; } If no setup has been done, it will return null. That's the problem. Imagine the following piece of code (that is part of a third party library): 1 protected void introspect() throws SQLException { 2 3 // Accumulate an ordered list of DynaProperties 4 ArrayList list = new ArrayList(); 5 ResultSetMetaData metadata = resultSet.getMetaData(); 6 int n = metadata.getColumnCount(); [...] If I have some of my code that class under test that calls introspect() and if I haven't set up the behaviour for getMetaData(), I will get a NPE. I was very lucky here as I was able to obtain the source code for this third party library and thus I could find out that the problem was that getMetaData was called. But we might not get that lucky every time! I believe the correct implementation should check if myMetaData has been set or not and if not, throw an exception stating it. What do you think? Thanks -Vincent ------------------------------------------------------- This sf.net email is sponsored by: With Great Power, Comes Great Responsibility Learn to use your power at OSDN's High Performance Computing Channel http://hpc.devchannel.org/ _______________________________________________ Mockobjects-java-dev mailing list Moc...@li... https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.427 / Virus Database: 240 - Release Date: 06/12/2002 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.427 / Virus Database: 240 - Release Date: 06/12/2002 |
From: <je...@mk...> - 2002-12-18 10:26:41
|
This would fit with the ReturnObjectList (return the next object in a list) and the ReturnObjectBag (same as ReturnObjectList except with a map of lists). This did go through my head when vincent mentioned it, but it'd be quite a bit of work to go through every object replacing return values with a ReturnValue object. private final ReturnValue value = new ReturnValue("value"); public void setupValue(Integer value){ value.setValue(value); } public Integer getValue(){ return (Integer)value.getValue(); } or you could have a map in MockObject to give you this public void setupValue(Integer value){ setMockValue("value", value); } public Integer getValue(){ return (Integer)getMockValue("value"); } thought you then need to think about scoping you might be able to sort that by maping agains object and key. Just thinking out loud really. Quoting Tim Mackinnon <tim...@po...>: > Yes - that would be a good improvement - I think Ivan's mockmaker > implementation does this with its ReturnValues object and the not enough > values exception... we should roll this into a unified implementation (the > flaw in the mockmaker stuff is that it doesn't tell you the name of the > object that didn't have enough values (like expection list and set do) so > its a bit mysterious. > > Tim > > -----Original Message----- > From: moc...@li... > [mailto:moc...@li...]On Behalf Of > Vincent Massol > Sent: 17 December 2002 11:09 > To: 'MockObjects' > Subject: [MO-java-dev] Important "bug" in the library > > > Hi, > > I believe there is a common "bug" that can be found in several of our > mocks objects. > > Here's an example, from MockResultSet.java (line 281): > > public ResultSetMetaData getMetaData() throws SQLException { > return myMetaData; > } > > If no setup has been done, it will return null. That's the problem. > Imagine the following piece of code (that is part of a third party > library): > > 1 protected void introspect() throws SQLException { > 2 > 3 // Accumulate an ordered list of DynaProperties > 4 ArrayList list = new ArrayList(); > 5 ResultSetMetaData metadata = resultSet.getMetaData(); > 6 int n = metadata.getColumnCount(); > [...] > > If I have some of my code that class under test that calls introspect() > and if I haven't set up the behaviour for getMetaData(), I will get a > NPE. > > I was very lucky here as I was able to obtain the source code for this > third party library and thus I could find out that the problem was that > getMetaData was called. But we might not get that lucky every time! > > I believe the correct implementation should check if myMetaData has been > set or not and if not, throw an exception stating it. > > What do you think? > > Thanks > -Vincent > > > > ------------------------------------------------------- > This sf.net email is sponsored by: > With Great Power, Comes Great Responsibility > Learn to use your power at OSDN's High Performance Computing Channel > http://hpc.devchannel.org/ > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev > > --- > Incoming mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.427 / Virus Database: 240 - Release Date: 06/12/2002 > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.427 / Virus Database: 240 - Release Date: 06/12/2002 > > > > ------------------------------------------------------- > This sf.net email is sponsored by: > With Great Power, Comes Great Responsibility > Learn to use your power at OSDN's High Performance Computing Channel > http://hpc.devchannel.org/ > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev > |