diff -uNr jdbc/build.xml jdbc-new/build.xml --- jdbc/build.xml 2003-02-27 06:45:43.000000000 +0100 +++ jdbc-new/build.xml 2003-02-27 15:24:06.000000000 +0100 @@ -50,6 +50,9 @@ + + + @@ -278,8 +281,21 @@ - - + + + + + + + + + + + + + + + diff -uNr jdbc/org/postgresql/test/util/TestPSQLException.java jdbc-new/org/postgresql/test/util/TestPSQLException.java --- jdbc/org/postgresql/test/util/TestPSQLException.java 1970-01-01 01:00:00.000000000 +0100 +++ jdbc-new/org/postgresql/test/util/TestPSQLException.java 2003-02-27 15:24:07.000000000 +0100 @@ -0,0 +1,84 @@ +package org.postgresql.test.util; + +import java.io.*; +import java.sql.*; +import junit.framework.TestCase; +import org.postgresql.util.PSQLException; + +public class TestPSQLException extends TestCase { + private PrintWriter oldWriter; + private MockWriter mockWriter; + + private static class MockWriter extends PrintWriter { + static class BogusWriter extends Writer { + public void flush() {} + public void close() {} + public void write(char[] cbuf, int off, int len) {} + } + + public MockWriter() { + super(new BogusWriter()); + out = this; + } + + private boolean isNull = false; + private int methodCallNr = 1; + + // This method gets called from SQLExceptions constructor + // with the value of PSQLException.toString() as a parameter. + // We're only interested in the first call since that is + // the one containing the toString value + public void write(String val) { + if ((methodCallNr == 1) && (val == null)) { + isNull = true; + } + + methodCallNr++; + } + + public boolean isNull() { + return this.isNull; + } + } + + private void setLogWriter(PrintWriter pw) { + DriverManager.setLogWriter(pw); + } + + public TestPSQLException(String name) { + super(name); + } + + public void setUp() { + // Take a backup of the old logWriter + oldWriter = DriverManager.getLogWriter(); + + // Set a new logwriter + mockWriter = new MockWriter(); + setLogWriter(mockWriter); + } + + public void tearDown() { + // Restore the old logwriter + setLogWriter(oldWriter); + + oldWriter = null; + mockWriter = null; + } + + /** + * Checks if PSQLException.toString() returns null if it gets called from one + * of the constructors. This is checked by testing if an attempt was made to + * write a null value to the MockWriter + */ + public void testToStringNotNullInConstructor() { + PSQLException ex = new PSQLException("Bogus exception", new Exception()); + + // Did toString return null? + boolean isNull = mockWriter.isNull(); + + boolean expected = false; + boolean actual = isNull; + assertEquals("toString should not return null if called from the constructor", expected, actual); + } +} diff -uNr jdbc/org/postgresql/test/util/UtilTestSuite.java jdbc-new/org/postgresql/test/util/UtilTestSuite.java --- jdbc/org/postgresql/test/util/UtilTestSuite.java 1970-01-01 01:00:00.000000000 +0100 +++ jdbc-new/org/postgresql/test/util/UtilTestSuite.java 2003-02-27 15:24:27.000000000 +0100 @@ -0,0 +1,24 @@ +package org.postgresql.test.util; + +import junit.framework.TestSuite; +import junit.framework.TestCase; +import junit.framework.Test; + +/* + * Executes all known tests for classes in org.postgresql.util + */ +public class UtilTestSuite extends TestSuite +{ + /* + * The main entry point for JUnit + */ + public static TestSuite suite() + { + TestSuite suite = new TestSuite(); + + // PSQLException tests + suite.addTestSuite(TestPSQLException.class); + + return suite; + } +}