Extract formatting tests of time zones into parameterized test
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1666577 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
04c8de2334
commit
442e8c2705
|
@ -260,26 +260,6 @@ public void testTimeZoneMatches() {
|
||||||
assertEquals(NEW_YORK, printer.getTimeZone());
|
assertEquals(NEW_YORK, printer.getTimeZone());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCalendarTimezoneRespected() {
|
|
||||||
final String[] availableZones = TimeZone.getAvailableIDs();
|
|
||||||
|
|
||||||
for (final String zone : availableZones) {
|
|
||||||
TimeZone anotherZone = TimeZone.getTimeZone(zone);
|
|
||||||
|
|
||||||
assertNotNull("Cannot find another timezone", anotherZone);
|
|
||||||
|
|
||||||
final String pattern = "h:mma z";
|
|
||||||
final Calendar cal = Calendar.getInstance(anotherZone);
|
|
||||||
|
|
||||||
final SimpleDateFormat sdf = new SimpleDateFormat(pattern);
|
|
||||||
sdf.setTimeZone(anotherZone);
|
|
||||||
final String expectedValue = sdf.format(cal.getTime());
|
|
||||||
final String actualValue = FastDateFormat.getInstance(pattern).format(cal);
|
|
||||||
assertEquals(expectedValue, actualValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTimeZoneAsZ() throws Exception {
|
public void testTimeZoneAsZ() throws Exception {
|
||||||
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package org.apache.commons.lang3.time;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.Parameterized;
|
||||||
|
|
||||||
|
@RunWith(Parameterized.class)
|
||||||
|
public class FastDatePrinterTimeZonesTest {
|
||||||
|
|
||||||
|
private static final String PATTERN = "h:mma z";
|
||||||
|
|
||||||
|
@Parameterized.Parameters
|
||||||
|
public static Collection<TimeZone> data() {
|
||||||
|
final String[] zoneIds = TimeZone.getAvailableIDs();
|
||||||
|
List<TimeZone> timeZones = new ArrayList<TimeZone>();
|
||||||
|
for (String zoneId : zoneIds) {
|
||||||
|
timeZones.add(TimeZone.getTimeZone(zoneId));
|
||||||
|
}
|
||||||
|
return timeZones;
|
||||||
|
}
|
||||||
|
|
||||||
|
private TimeZone timeZone;
|
||||||
|
|
||||||
|
public FastDatePrinterTimeZonesTest(TimeZone timeZone) {
|
||||||
|
this.timeZone = timeZone;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCalendarTimezoneRespected() {
|
||||||
|
final Calendar cal = Calendar.getInstance(timeZone);
|
||||||
|
|
||||||
|
final SimpleDateFormat sdf = new SimpleDateFormat(PATTERN);
|
||||||
|
sdf.setTimeZone(timeZone);
|
||||||
|
final String expectedValue = sdf.format(cal.getTime());
|
||||||
|
final String actualValue = FastDateFormat.getInstance(PATTERN).format(cal);
|
||||||
|
assertEquals(expectedValue, actualValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue