Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 11484 invoked from network); 1 Apr 2005 02:38:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 1 Apr 2005 02:38:42 -0000 Received: (qmail 64831 invoked by uid 500); 1 Apr 2005 02:38:39 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 64546 invoked by uid 500); 1 Apr 2005 02:38:38 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 64531 invoked by uid 99); 1 Apr 2005 02:38:38 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (hermes.apache.org: local policy) Received: from smtpout04-04.prod.mesa1.secureserver.net (HELO smtpout04-04.prod.mesa1.secureserver.net) (64.202.165.199) by apache.org (qpsmtpd/0.28) with SMTP; Thu, 31 Mar 2005 18:38:37 -0800 Received: (qmail 30042 invoked from network); 1 Apr 2005 02:38:35 -0000 Received: from unknown (24.13.84.182) by smtpout04-04.prod.mesa1.secureserver.net (64.202.165.199) with ESMTP; 01 Apr 2005 02:38:35 -0000 Message-ID: <424CB42A.7000901@javactivity.org> Date: Thu, 31 Mar 2005 20:38:34 -0600 From: Steve Cohen User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jakarta Commons Developers List Subject: Re: [net] [ftp] [patch] FTPTimestampParserImplTest.java and FTPClientConfigTest.java References: <424C37A2.6080604@apache.org> In-Reply-To: <424C37A2.6080604@apache.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N What do you mean, "make the tests pass"? The tests, as written, already pass. Perhaps you are saying that the tests don't test everything they need to test. But you have not identified what those issues are. If you come up with a test case that shows a problem, then the solution is to add the test and fix the code as necessary. Or am I misunderstanding you? Neeme Praks wrote: > > Two patches to make the FTP timestamp parsing tests pass also on > non-english systems. > I'm not sure if this is the best way to fix those issues, though. > > Rgds, > Neeme > > > ------------------------------------------------------------------------ > > Index: FTPTimestampParserImplTest.java > =================================================================== > --- FTPTimestampParserImplTest.java (revision 159615) > +++ FTPTimestampParserImplTest.java (working copy) > @@ -15,6 +15,7 @@ > */ > package org.apache.commons.net.ftp.parser; > > +import java.text.DateFormatSymbols; > import java.text.ParseException; > import java.text.SimpleDateFormat; > import java.util.Calendar; > @@ -73,8 +74,19 @@ > > FTPTimestampParserImpl parser = new FTPTimestampParserImpl(); > > + // assume we are FTPing a server in Chicago, two hours ahead of > + // L. A. > + FTPClientConfig config = > + new FTPClientConfig(FTPClientConfig.SYST_UNIX); > + config.setDefaultDateFormatStr(FTPTimestampParser.DEFAULT_SDF); > + config.setRecentDateFormatStr(FTPTimestampParser.DEFAULT_RECENT_SDF); > + // 2 hours difference > + config.setServerTimeZoneId("America/Chicago"); > + parser.configure(config); > + > + > SimpleDateFormat sdf = > - new SimpleDateFormat(parser.getRecentDateFormatString()); > + new SimpleDateFormat(parser.getRecentDateFormatString(), parser.getRecentDateFormat().getDateFormatSymbols()); > // assume we're in the US Pacific Time Zone > TimeZone tzla = TimeZone.getTimeZone("America/Los_Angeles"); > sdf.setTimeZone(tzla); > @@ -84,17 +96,6 @@ > String fmtTimePlusThreeHours = sdf.format(threeHoursFromNow); > > > - // assume we are FTPing a server in Chicago, two hours ahead of > - // L. A. > - FTPClientConfig config = > - new FTPClientConfig(FTPClientConfig.SYST_UNIX); > - config.setDefaultDateFormatStr(FTPTimestampParser.DEFAULT_SDF); > - config.setRecentDateFormatStr(FTPTimestampParser.DEFAULT_RECENT_SDF); > - // 2 hours difference > - config.setServerTimeZoneId("America/Chicago"); > - parser.configure(config); > - > - > try { > Calendar parsed = parser.parseTimestamp(fmtTimePlusOneHour); > // the only difference should be the two hours > @@ -103,7 +104,7 @@ > (long)TWO_HOURS_OF_MILLISECONDS, > cal.getTime().getTime() - parsed.getTime().getTime()); > } catch (ParseException e){ > - fail("Unable to parse"); > + fail("Unable to parse " + fmtTimePlusOneHour); > } > > //but if the file's timestamp is THREE hours ahead of now, that should > @@ -123,13 +124,18 @@ > > public void testParser() { > FTPTimestampParserImpl parser = new FTPTimestampParserImpl(); > + Calendar cal = Calendar.getInstance(); > + cal.set(Calendar.YEAR, 2002); > + cal.set(Calendar.MONTH, 1); > + cal.set(Calendar.DAY_OF_MONTH, 22); > + SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy"); > try { > - parser.parseTimestamp("feb 22 2002"); > + parser.parseTimestamp(sdf.format(cal.getTime())); > } catch (ParseException e) { > fail("failed.to.parse.default"); > } > try { > - parser.parseTimestamp("f�v 22 2002"); > + parser.parseTimestamp("f�v 22 2002"); > fail("should.have.failed.to.parse.default"); > } catch (ParseException e) { > // this is the success case > @@ -140,14 +146,17 @@ > config.setRecentDateFormatStr("d MMM HH:mm"); > config.setServerLanguageCode("fr"); > parser.configure(config); > + DateFormatSymbols dfs = FTPClientConfig.lookupDateFormatSymbols("fr"); > + sdf = new SimpleDateFormat("MMM d yyyy", dfs); > try { > - parser.parseTimestamp("d�c 22 2002"); > + parser.parseTimestamp(sdf.format(cal.getTime())); > fail("incorrect.field.order"); > } catch (ParseException e) { > // this is the success case > } > + sdf = new SimpleDateFormat("d MMM yyyy", dfs); > try { > - parser.parseTimestamp("22 d�c 2002"); > + parser.parseTimestamp(sdf.format(cal.getTime())); > } catch (ParseException e) { > fail("failed.to.parse.french"); > } > @@ -159,27 +168,28 @@ > // this is the success case > } > try { > - parser.parseTimestamp("29 f�v 2002"); > + parser.parseTimestamp("29 f�v 2002"); > fail("nonexistent.date"); > } catch (ParseException e) { > // this is the success case > } > > try { > - parser.parseTimestamp("22 ao� 30:02"); > + parser.parseTimestamp("22 ao� 30:02"); > fail("bad.hour"); > } catch (ParseException e) { > // this is the success case > } > > try { > - parser.parseTimestamp("22 ao� 20:74"); > + parser.parseTimestamp("22 ao� 20:74"); > fail("bad.minute"); > } catch (ParseException e) { > // this is the success case > } > + sdf = new SimpleDateFormat("d MMM HH:mm", dfs); > try { > - parser.parseTimestamp("28 ao� 20:02"); > + parser.parseTimestamp(sdf.format(cal.getTime())); > } catch (ParseException e) { > fail("failed.to.parse.french.recent"); > } > > > ------------------------------------------------------------------------ > > Index: FTPClientConfigTest.java > =================================================================== > --- FTPClientConfigTest.java (revision 159615) > +++ FTPClientConfigTest.java (working copy) > @@ -67,6 +67,7 @@ > String tooLong = "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec|jan"; > String tooShort = "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov"; > String fakeLang = "abc|def|ghi|jkl|mno|pqr|stu|vwx|yza|bcd|efg|hij"; > + String standard = "jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec"; > > public void testSetShortMonthNames() { > } > @@ -153,12 +154,18 @@ > // should have failed > } > DateFormatSymbols dfs = null; > + DateFormatSymbols dfs2 = null; > try { > dfs = FTPClientConfig.getDateFormatSymbols(fakeLang); > } catch (Exception e){ > fail("rejected valid short month string"); > } > - SimpleDateFormat sdf1 = new SimpleDateFormat("MMM dd, yyyy"); > + try { > + dfs2 = FTPClientConfig.getDateFormatSymbols(standard); > + } catch (Exception e){ > + fail("rejected valid short month string"); > + } > + SimpleDateFormat sdf1 = new SimpleDateFormat("MMM dd, yyyy", dfs2); > SimpleDateFormat sdf2 = new SimpleDateFormat("MMM dd, yyyy", dfs); > > Date d1 = null; > @@ -166,7 +173,7 @@ > try { > d1 = sdf1.parse("dec 31, 2004"); > } catch (ParseException px) { > - fail("failed.to.parse.std"); > + fail("failed.to.parse.std " + px); > } > try { > d2 = sdf2.parse("hij 31, 2004"); --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org