You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Steve Cohen <sc...@javactivity.org> on 2005/04/01 04:38:34 UTC
Re: [net] [ftp] [patch] FTPTimestampParserImplTest.java and FTPClientConfigTest.java
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
Re: [net] [ftp] [patch] FTPTimestampParserImplTest.java and FTPClientConfigTest.java
Posted by Steve Cohen <sc...@javactivity.org>.
Yes it does, thank you very much.
Neeme Praks wrote:
>
> No, they don't pass on a machine that has a default locale set to
> something non-english.
>
> The problem is that the tests are assuming too much about the default
> locale.
> For example, if you create a new SimpleDateFormat without providing a
> locale or a set of DateFormatSymbols then that SimpleDateFormat will use
> the default stuff. And then the test code assumes that it will get
> english month names but, for example in my case, it will get Estonian
> month names and it will fail.
>
> I hope that clarified things up a bit?
>
> Rgds,
> Neeme
>
> Steve Cohen wrote:
>
>> 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?
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [net] [ftp] [patch] FTPTimestampParserImplTest.java and FTPClientConfigTest.java
Posted by Neeme Praks <ne...@apache.org>.
No, they don't pass on a machine that has a default locale set to
something non-english.
The problem is that the tests are assuming too much about the default
locale.
For example, if you create a new SimpleDateFormat without providing a
locale or a set of DateFormatSymbols then that SimpleDateFormat will use
the default stuff. And then the test code assumes that it will get
english month names but, for example in my case, it will get Estonian
month names and it will fail.
I hope that clarified things up a bit?
Rgds,
Neeme
Steve Cohen wrote:
> 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?
>