pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mike Fowler <mike@mlfowler.com>
To: pgsql-jdbc@postgresql.org
Subject: Failing test in org.postgresql.test.jdbc2.DateTest
Date: Wed, 23 Feb 2011 16:42:18 +0000
Message-ID: <4D6538EA.8080905@mlfowler.com> (raw)

Hi all,

I have just pulled out the source from CVS and run the build and test 
and found a failure in the class noted in the subject. Specifically the 
test that fails is:

79    public void testSetDate() throws SQLException
80    {
...
111        ps.setObject(1, "1969-04-3", java.sql.Types.DATE);
112        assertEquals(1, ps.executeUpdate());
...
120        ps.setObject(1, java.sql.Date.valueOf("1912-5-1"), 
java.sql.Types.DATE);
121        assertEquals(1, ps.executeUpdate());
...

This only fails in my JDK 1.6 - it passes in 1.5. Looking at the 
java.sql.Date in the two source jars I have it's easy to see that the 
valueOf method has been completely rewritten in 1.6 (well, at least 
1.6.0_21 possibly earlier). Having looked at the API documentation has 
remained unchanged in 1.3, 1.4, 1.5 and 1.6 (1.2 I couldn't find by 
guessing) and reads:

* @param s a <code>String</code> object representing a date in
*        in the format "yyyy-mm-dd"

So it appears that the method now implements the API largely correctly, 
however as you can see above a single digit date is still accepted. 
Given that the API seems unchanged for so long, I'd recommend changing 
the tests to reflect the API.

I've attached a patch to do just that and it's been tested with the 
following JDKs:

1.4.2_19
1.5.0_22
1.6.0_21

Regards,

-- 
Mike Fowler
Registered Linux user: 379787

Attachments:

dateTest.patch (text/x-diff, 2.7K) download ? project-1.patch Index: org/postgresql/test/jdbc2/DateTest.java =================================================================== RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/test/jdbc2/DateTest.java,v retrieving revision 1.14 diff -c -r1.14 DateTest.java *** org/postgresql/test/jdbc2/DateTest.java 8 Jan 2008 06:56:31 -0000 1.14 --- org/postgresql/test/jdbc2/DateTest.java 23 Feb 2011 16:38:13 -0000 *************** *** 108,123 **** ps.setObject(1, "1934-02-28", java.sql.Types.DATE); assertEquals(1, ps.executeUpdate()); ! ps.setObject(1, "1969-04-3", java.sql.Types.DATE); assertEquals(1, ps.executeUpdate()); ps.setObject(1, "1982-08-03", java.sql.Types.DATE); assertEquals(1, ps.executeUpdate()); ! ps.setObject(1, "2012-3-15", java.sql.Types.DATE); assertEquals(1, ps.executeUpdate()); ! ps.setObject(1, java.sql.Date.valueOf("1912-5-1"), java.sql.Types.DATE); assertEquals(1, ps.executeUpdate()); ps.setObject(1, java.sql.Date.valueOf("1971-12-15"), java.sql.Types.DATE); --- 108,123 ---- ps.setObject(1, "1934-02-28", java.sql.Types.DATE); assertEquals(1, ps.executeUpdate()); ! ps.setObject(1, "1969-04-03", java.sql.Types.DATE); assertEquals(1, ps.executeUpdate()); ps.setObject(1, "1982-08-03", java.sql.Types.DATE); assertEquals(1, ps.executeUpdate()); ! ps.setObject(1, "2012-03-15", java.sql.Types.DATE); assertEquals(1, ps.executeUpdate()); ! ps.setObject(1, java.sql.Date.valueOf("1912-05-01"), java.sql.Types.DATE); assertEquals(1, ps.executeUpdate()); ps.setObject(1, java.sql.Date.valueOf("1971-12-15"), java.sql.Types.DATE); *************** *** 126,135 **** ps.setObject(1, java.sql.Date.valueOf("1984-12-03"), java.sql.Types.DATE); assertEquals(1, ps.executeUpdate()); ! ps.setObject(1, java.sql.Date.valueOf("2000-1-1"), java.sql.Types.DATE); assertEquals(1, ps.executeUpdate()); ! ps.setObject(1, java.sql.Date.valueOf("23456-1-1"), java.sql.Types.DATE); assertEquals(1, ps.executeUpdate()); // We can't use valueOf on BC dates. --- 126,135 ---- ps.setObject(1, java.sql.Date.valueOf("1984-12-03"), java.sql.Types.DATE); assertEquals(1, ps.executeUpdate()); ! ps.setObject(1, java.sql.Date.valueOf("2000-01-01"), java.sql.Types.DATE); assertEquals(1, ps.executeUpdate()); ! ps.setObject(1, java.sql.Date.valueOf("23456-01-01"), java.sql.Types.DATE); assertEquals(1, ps.executeUpdate()); // We can't use valueOf on BC dates.

view thread (6+ messages)  latest in thread

Message-ID: <4D6538EA.8080905@mlfowler.com>
Permalink:  ../4D6538EA.8080905@mlfowler.com/
Also on:    postgresql.org/message-id/4D6538EA.8080905@mlfowler.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: mike@mlfowler.com
  Subject: Re: Failing test in org.postgresql.test.jdbc2.DateTest
  In-Reply-To: <4D6538EA.8080905@mlfowler.com>
  References: <4D6538EA.8080905@mlfowler.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox