SOLR-2690: to hell with JVMs that don't consistently normalize the ID in the TimeZone's returned by TimeZone.getTimeZone ... we don't give a shit, all that matters is that the rules are hte same anyway

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1329934 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2012-04-24 18:50:46 +00:00
parent 9713155458
commit 0501fcc8d9
1 changed files with 26 additions and 10 deletions

View File

@ -28,6 +28,22 @@ import java.util.Locale;
public class TimeZoneUtilsTest extends LuceneTestCase {
private static void assertSameRules(final String label,
final TimeZone expected,
final TimeZone actual) {
if (null == expected && null == actual) return;
assertNotNull(label + ": expected is null", expected);
assertNotNull(label + ": actual is null", actual);
final boolean same = expected.hasSameRules(actual);
assertTrue(label + ": " + expected.toString() + " [[NOT SAME RULES]] " +
actual.toString(),
same);
}
public void testValidIds() throws Exception {
final Set<String> idsTested = new HashSet<String>();
@ -39,7 +55,7 @@ public class TimeZoneUtilsTest extends LuceneTestCase {
final TimeZone expected = TimeZone.getTimeZone(validId);
final TimeZone actual = TimeZoneUtils.getTimeZone(validId);
assertEquals(validId, expected, actual);
assertSameRules(validId, expected, actual);
idsTested.add(validId);
}
@ -56,7 +72,7 @@ public class TimeZoneUtilsTest extends LuceneTestCase {
"GMT-0800","GMT-08:00",
"GMT+23", "GMT+2300",
"GMT-23", "GMT-2300"}) {
assertEquals(input,
assertSameRules(input,
TimeZone.getTimeZone(input),
TimeZoneUtils.getTimeZone(input));
}
@ -70,7 +86,7 @@ public class TimeZoneUtilsTest extends LuceneTestCase {
"GMT-0800","GMT-08:00",
"GMT+23", "GMT+2300",
"GMT-23", "GMT-2300"}) {
assertEquals(input,
assertSameRules(input,
TimeZone.getTimeZone(input),
TimeZone.getTimeZone(input));
}
@ -110,7 +126,7 @@ public class TimeZoneUtilsTest extends LuceneTestCase {
String mins = String.format(Locale.US, TWO_DIGIT, min);
String input = "GMT" + (r.nextBoolean()?"+":"-")
+ hours + (r.nextBoolean() ? "" : ((r.nextBoolean()?":":"") + mins));
assertEquals(input,
assertSameRules(input,
TimeZone.getTimeZone(input),
TimeZoneUtils.getTimeZone(input));
}