@RunWith(Parameterized.class)
public class DateFormatTests {
private static final String pattern = "yyyy-MM-dd HH:mm:ss.S z";
final private String input;
final private SimpleDateFormat format;
private XStream xstream = new XStream();
public DateFormatTests(String input)
{
this.format = new SimpleDateFormat(pattern, Locale.UK);
format.setTimeZone(TimeZone.getTimeZone("GMT"));
this.input = input;
}
@Test
public void testDateFormat() throws Exception
{
Date date = format.parse(input);
String xml = xstream.toXML(date);
Date output = (Date) xstream.fromXML(xml);
System.err.println(xml + " : " + format.format(output));
assertTrue(xml.contains(input));
}
@Parameters
public static List<Object[]> data() {
List<Object[]> params = new ArrayList<Object[]>();
// First two fail (in GMT timezone)...
params.add(new Object[]
{ "1970-01-01 11:20:34.0 GMT"}
);
params.add(new Object[]
{ "1971-01-01 11:20:34.0 GMT"}
);
params.add(new Object[]
{ "1972-01-01 11:20:34.0 GMT"}
);
params.add(new Object[]
{ "1973-01-01 11:20:34.0 GMT"}
);
params.add(new Object[]
{ "1974-01-01 11:20:34.0 GMT"}
);
return params;
}
}
@RunWith(Parameterized.class)
public class DateFormatTests {
private static final String pattern = "yyyy-MM-dd HH:mm:ss.S z";
final private String input;
final private SimpleDateFormat format;
private XStream xstream = new XStream();
public DateFormatTests(String input)
{ this.format = new SimpleDateFormat(pattern, Locale.UK); format.setTimeZone(TimeZone.getTimeZone("GMT")); this.input = input; }@Test
{ Date date = format.parse(input); String xml = xstream.toXML(date); Date output = (Date) xstream.fromXML(xml); System.err.println(xml + " : " + format.format(output)); assertTrue(xml.contains(input)); }public void testDateFormat() throws Exception
@Parameters
public static List<Object[]> data() {
List<Object[]> params = new ArrayList<Object[]>();
{ "1970-01-01 11:20:34.0 GMT"}// First two fail (in GMT timezone)...
params.add(new Object[]
);
{ "1971-01-01 11:20:34.0 GMT"}params.add(new Object[]
);
{ "1972-01-01 11:20:34.0 GMT"}params.add(new Object[]
);
{ "1973-01-01 11:20:34.0 GMT"}params.add(new Object[]
);
{ "1974-01-01 11:20:34.0 GMT"}params.add(new Object[]
);
return params;
}
}