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 |