Permalink
Browse files

Merge branch 'TheRealHaui-master'

  • Loading branch information...
jodastephen committed Oct 2, 2017
2 parents 66825d6 + cef7642 commit 1d337c696cdee8a68bdd9e52d766297d9ebf1343
@@ -149,6 +149,11 @@ static Chronology getLenientISOChronology() {
* @param zimap maps string ids to DateTimeZone objects.
*/
static void writeZoneInfoMap(DataOutputStream dout, Map<String, DateTimeZone> zimap) throws IOException {
if ( dout == null ){
throw new IllegalArgumentException("DataOutputStream must not be null.");
}
// Build the string pool.
Map<String, Short> idToIndex = new HashMap<String, Short>(zimap.size());
TreeMap<Short, String> indexToId = new TreeMap<Short, String>();
@@ -1183,4 +1183,89 @@ public void testMonthsAndMinutesAreConsideredSeparateAndCaseIsNotIgnored() {
period = formatter.parsePeriod(oneMinute);
assertEquals(Period.minutes(1), period);
}
public void testAppendSeparatorIfFieldsBeforeThrowsIllegalStateExceptionAndAppendPrefixTakingString() {
PeriodFormatterBuilder periodFormatterBuilder = new PeriodFormatterBuilder();
periodFormatterBuilder.appendPrefix("=9Z/])WG");
try {
periodFormatterBuilder.appendSeparatorIfFieldsBefore("=9Z/])WG");
fail("Expecting exception: IllegalStateException");
} catch (IllegalStateException e) {
assertEquals(PeriodFormatterBuilder.class.getName(), e.getStackTrace()[0].getClassName());
}
}
public void testAppendSeparatorIfFieldsBeforeThrowsIllegalStateExceptionAndAppendSeparatorIfFieldsAfter() {
PeriodFormatterBuilder periodFormatterBuilder = new PeriodFormatterBuilder();
periodFormatterBuilder.appendSeparatorIfFieldsAfter("3xmZ\"*'Q={=");
try {
periodFormatterBuilder.appendSeparatorIfFieldsBefore("3xmZ\"*'Q={=");
fail("Expecting exception: IllegalStateException");
} catch (IllegalStateException e) {
assertEquals(PeriodFormatterBuilder.class.getName(), e.getStackTrace()[0].getClassName());
}
}
public void testAppendSeparatorTaking3ArgumentsWithEmptyStringAndNull() {
PeriodFormatterBuilder periodFormatterBuilder = new PeriodFormatterBuilder();
try {
periodFormatterBuilder.appendSeparator("", null, null);
fail("Expecting exception: IllegalArgumentException");
} catch (IllegalArgumentException e) {
assertEquals(PeriodFormatterBuilder.class.getName(), e.getStackTrace()[0].getClassName());
}
}
public void testAppendSeparatorTaking3ArgumentsWithNullAndNonEmptyArray() {
PeriodFormatterBuilder periodFormatterBuilder = new PeriodFormatterBuilder();
String[] stringArray = new String[3];
try {
periodFormatterBuilder.appendSeparator(null, null, stringArray);
fail("Expecting exception: IllegalArgumentException");
} catch (IllegalArgumentException e) {
assertEquals(PeriodFormatterBuilder.class.getName(), e.getStackTrace()[0].getClassName());
}
}
public void testAppendSuffixTaking2StringArraysThrowsIllegalStateException() {
PeriodFormatterBuilder periodFormatterBuilder = new PeriodFormatterBuilder();
String[] stringArray = new String[1];
stringArray[0] = "8io`#&*f6&";
periodFormatterBuilder.appendSecondsWithMillis();
periodFormatterBuilder.appendSeparator("8io`#&*f6&", "NW7");
try {
periodFormatterBuilder.appendSuffix(stringArray, stringArray);
fail("Expecting exception: IllegalStateException");
} catch (IllegalStateException e) {
assertEquals(PeriodFormatterBuilder.class.getName(), e.getStackTrace()[0].getClassName());
}
}
public void testAppendLiteralThrowsIllegalArgumentException() {
PeriodFormatterBuilder periodFormatterBuilder = new PeriodFormatterBuilder();
try {
periodFormatterBuilder.appendLiteral(null);
fail("Expecting exception: IllegalArgumentException");
} catch (IllegalArgumentException e) {
assertEquals(PeriodFormatterBuilder.class.getName(), e.getStackTrace()[0].getClassName());
}
}
public void testAppendTakingPeriodFormatterThrowsIllegalArgumentException() {
PeriodFormatterBuilder periodFormatterBuilder = new PeriodFormatterBuilder();
try {
periodFormatterBuilder.append(null);
fail("Expecting exception: IllegalArgumentException");
} catch (IllegalArgumentException e) {
assertEquals(PeriodFormatterBuilder.class.getName(), e.getStackTrace()[0].getClassName());
}
}
}
@@ -0,0 +1,94 @@
/*
* Copyright 2017 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.tz;
import junit.framework.TestCase;
import org.joda.time.DateTimeZone;
import org.joda.time.MockZone;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.HashMap;
import java.util.Map;
/**
* Unit tests for class {@link ZoneInfoCompiler}.
*
* @date 2017-07-31
* @see ZoneInfoCompiler
**/
public class TestZoneInfoCompiler extends TestCase {
public void testParseDataFileWithTrue() throws IOException {
ZoneInfoCompiler zoneInfoCompiler = new ZoneInfoCompiler();
StringReader stringReader = new StringReader(" I ;>- ");
BufferedReader bufferedReader = new BufferedReader(stringReader, 2014);
zoneInfoCompiler.parseDataFile(bufferedReader, true);
}
public void testParseDataFileWithFalse() throws IOException {
ZoneInfoCompiler zoneInfoCompiler = new ZoneInfoCompiler();
StringReader stringReader = new StringReader("XYC5w.9eA}*U#A;mu");
BufferedReader bufferedReader = new BufferedReader(stringReader);
zoneInfoCompiler.parseDataFile(bufferedReader, false);
}
public void testTestOne() {
DateTimeZone dateTimeZone = DateTimeZone.forOffsetMillis(8);
assertTrue(ZoneInfoCompiler.test("+02:15", dateTimeZone));
}
public void testTestTwo() {
DateTimeZoneBuilder dateTimeZoneBuilder = new DateTimeZoneBuilder();
DateTimeZone dateTimeZone = dateTimeZoneBuilder.toDateTimeZone("7M6 _n'63", true);
assertTrue(ZoneInfoCompiler.test("7M6 _n'63", dateTimeZone));
}
public void testParseZoneCharFive() {
assertEquals('s', ZoneInfoCompiler.parseZoneChar('s'));
}
public void testParseYearAndParseYearReturningPositiveAndParseYearWithNegative() {
assertEquals(Integer.MAX_VALUE, ZoneInfoCompiler.parseYear("maximum", (-2512)));
}
public void testParseYearAndParseYearReturningNegativeOne() {
assertEquals(Integer.MIN_VALUE, ZoneInfoCompiler.parseYear("min", (-1881443201)));
}
public void testParseYearAndParseYearReturningNegativeTwo() {
assertEquals(Integer.MIN_VALUE, ZoneInfoCompiler.parseYear("minimum", (-1971487955)));
}
public void testWriteZoneInfoMapThrowsIllegalArgumentException() throws IOException {
Map<String, MockZone> hashMap = new HashMap<String, MockZone>();
MockZone mockZone = new MockZone(0L, 3022, 90);
hashMap.put(" - ", mockZone);
Map<String, DateTimeZone> hashMapTwo = new HashMap<String, DateTimeZone>(hashMap);
hashMapTwo.put("H)m^v1(", mockZone);
try {
ZoneInfoCompiler.writeZoneInfoMap(null, hashMapTwo);
fail("Expecting exception: IllegalArgumentException");
} catch (IllegalArgumentException e) {
assertEquals(ZoneInfoCompiler.class.getName(), e.getStackTrace()[0].getClassName());
}
}
}

0 comments on commit 1d337c6

Please sign in to comment.