// ----------------------------------------------------------------------- public void testConstructor_Object_Chronology1() throws Throwable { DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1); Interval base = new Interval(dt1, dt2); Interval test = new Interval(base, BuddhistChronology.getInstance()); assertEquals(dt1.getMillis(), test.getStartMillis()); assertEquals(dt2.getMillis(), test.getEndMillis()); assertEquals(BuddhistChronology.getInstance(), test.getChronology()); }
/** * Checks if this chronology instance equals another. * * @param obj the object to compare to * @return true if equal * @since 1.6 */ public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof BuddhistChronology) { BuddhistChronology chrono = (BuddhistChronology) obj; return getZone().equals(chrono.getZone()); } return false; }
/** * This class is a Junit unit test for LocalDate. * * @author Stephen Colebourne */ public class TestLocalDate_Constructors extends TestCase { private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris"); private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London"); private static final Chronology ISO_UTC = ISOChronology.getInstanceUTC(); private static final Chronology BUDDHIST_UTC = BuddhistChronology.getInstanceUTC(); private static final Chronology GREGORIAN_UTC = GregorianChronology.getInstanceUTC(); private static final Chronology GREGORIAN_PARIS = GregorianChronology.getInstance(PARIS); private long TEST_TIME_NOW = (31L + 28L + 31L + 30L + 31L + 9L - 1L) * DateTimeConstants.MILLIS_PER_DAY; private long TEST_TIME1 = (31L + 28L + 31L + 6L - 1L) * DateTimeConstants.MILLIS_PER_DAY + 12L * DateTimeConstants.MILLIS_PER_HOUR + 24L * DateTimeConstants.MILLIS_PER_MINUTE; private long TEST_TIME1_ROUNDED = (31L + 28L + 31L + 6L - 1L) * DateTimeConstants.MILLIS_PER_DAY; private long TEST_TIME2 = (365L + 31L + 28L + 31L + 30L + 7L - 1L) * DateTimeConstants.MILLIS_PER_DAY + 14L * DateTimeConstants.MILLIS_PER_HOUR + 28L * DateTimeConstants.MILLIS_PER_MINUTE; private DateTimeZone zone = null; public static void main(String[] args) { junit.textui.TestRunner.run(suite()); } public static TestSuite suite() { return new TestSuite(TestLocalDate_Constructors.class); } public TestLocalDate_Constructors(String name) { super(name); } protected void setUp() throws Exception { DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW); zone = DateTimeZone.getDefault(); DateTimeZone.setDefault(LONDON); } protected void tearDown() throws Exception { DateTimeUtils.setCurrentMillisSystem(); DateTimeZone.setDefault(zone); zone = null; } // ----------------------------------------------------------------------- public void testParse_noFormatter() throws Throwable { assertEquals(new LocalDate(2010, 6, 30), LocalDate.parse("2010-06-30")); assertEquals(new LocalDate(2010, 1, 2), LocalDate.parse("2010-002")); } public void testParse_formatter() throws Throwable { DateTimeFormatter f = DateTimeFormat.forPattern("yyyy--dd MM").withChronology(ISOChronology.getInstance(PARIS)); assertEquals(new LocalDate(2010, 6, 30), LocalDate.parse("2010--30 06", f)); } // ----------------------------------------------------------------------- public void testFactory_FromCalendarFields() throws Exception { GregorianCalendar cal = new GregorianCalendar(1970, 1, 3, 4, 5, 6); cal.set(Calendar.MILLISECOND, 7); LocalDate expected = new LocalDate(1970, 2, 3); assertEquals(expected, LocalDate.fromCalendarFields(cal)); try { LocalDate.fromCalendarFields((Calendar) null); fail(); } catch (IllegalArgumentException ex) { } } // ----------------------------------------------------------------------- public void testFactory_FromDateFields() throws Exception { GregorianCalendar cal = new GregorianCalendar(1970, 1, 3, 4, 5, 6); cal.set(Calendar.MILLISECOND, 7); LocalDate expected = new LocalDate(1970, 2, 3); assertEquals(expected, LocalDate.fromDateFields(cal.getTime())); try { LocalDate.fromDateFields((Date) null); fail(); } catch (IllegalArgumentException ex) { } } // ----------------------------------------------------------------------- public void testConstructor() throws Throwable { LocalDate test = new LocalDate(); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(6, test.getMonthOfYear()); assertEquals(9, test.getDayOfMonth()); assertEquals(test, LocalDate.now()); } public void testConstructor_DateTimeZone() throws Throwable { DateTime dt = new DateTime(2005, 6, 8, 23, 59, 0, 0, LONDON); DateTimeUtils.setCurrentMillisFixed(dt.getMillis()); // 23:59 in London is 00:59 the following day in Paris LocalDate test = new LocalDate(LONDON); assertEquals(ISO_UTC, test.getChronology()); assertEquals(2005, test.getYear()); assertEquals(6, test.getMonthOfYear()); assertEquals(8, test.getDayOfMonth()); assertEquals(test, LocalDate.now(LONDON)); test = new LocalDate(PARIS); assertEquals(ISO_UTC, test.getChronology()); assertEquals(2005, test.getYear()); assertEquals(6, test.getMonthOfYear()); assertEquals(9, test.getDayOfMonth()); assertEquals(test, LocalDate.now(PARIS)); } public void testConstructor_nullDateTimeZone() throws Throwable { DateTime dt = new DateTime(2005, 6, 8, 23, 59, 0, 0, LONDON); DateTimeUtils.setCurrentMillisFixed(dt.getMillis()); // 23:59 in London is 00:59 the following day in Paris LocalDate test = new LocalDate((DateTimeZone) null); assertEquals(ISO_UTC, test.getChronology()); assertEquals(2005, test.getYear()); assertEquals(6, test.getMonthOfYear()); assertEquals(8, test.getDayOfMonth()); } public void testConstructor_Chronology() throws Throwable { LocalDate test = new LocalDate(GREGORIAN_PARIS); assertEquals(GREGORIAN_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(6, test.getMonthOfYear()); assertEquals(9, test.getDayOfMonth()); assertEquals(test, LocalDate.now(GREGORIAN_PARIS)); } public void testConstructor_nullChronology() throws Throwable { LocalDate test = new LocalDate((Chronology) null); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(6, test.getMonthOfYear()); assertEquals(9, test.getDayOfMonth()); } // ----------------------------------------------------------------------- public void testConstructor_long1() throws Throwable { LocalDate test = new LocalDate(TEST_TIME1); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(4, test.getMonthOfYear()); assertEquals(6, test.getDayOfMonth()); } public void testConstructor_long2() throws Throwable { LocalDate test = new LocalDate(TEST_TIME2); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1971, test.getYear()); assertEquals(5, test.getMonthOfYear()); assertEquals(7, test.getDayOfMonth()); } public void testConstructor_long1_DateTimeZone() throws Throwable { LocalDate test = new LocalDate(TEST_TIME1, PARIS); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(4, test.getMonthOfYear()); assertEquals(6, test.getDayOfMonth()); assertEquals(TEST_TIME1_ROUNDED, test.getLocalMillis()); } public void testConstructor_long2_DateTimeZone() throws Throwable { LocalDate test = new LocalDate(TEST_TIME2, PARIS); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1971, test.getYear()); assertEquals(5, test.getMonthOfYear()); assertEquals(7, test.getDayOfMonth()); } public void testConstructor_long3_DateTimeZone() throws Throwable { DateTime dt = new DateTime(2006, 6, 9, 0, 0, 0, 0, PARIS); DateTime dtUTC = new DateTime(2006, 6, 9, 0, 0, 0, 0, DateTimeZone.UTC); LocalDate test = new LocalDate(dt.getMillis(), PARIS); assertEquals(ISO_UTC, test.getChronology()); assertEquals(2006, test.getYear()); assertEquals(6, test.getMonthOfYear()); assertEquals(9, test.getDayOfMonth()); assertEquals(dtUTC.getMillis(), test.getLocalMillis()); } public void testConstructor_long4_DateTimeZone() throws Throwable { DateTime dt = new DateTime(2006, 6, 9, 23, 59, 59, 999, PARIS); DateTime dtUTC = new DateTime(2006, 6, 9, 0, 0, 0, 0, DateTimeZone.UTC); LocalDate test = new LocalDate(dt.getMillis(), PARIS); assertEquals(ISO_UTC, test.getChronology()); assertEquals(2006, test.getYear()); assertEquals(6, test.getMonthOfYear()); assertEquals(9, test.getDayOfMonth()); assertEquals(dtUTC.getMillis(), test.getLocalMillis()); } public void testConstructor_long_nullDateTimeZone() throws Throwable { LocalDate test = new LocalDate(TEST_TIME1, (DateTimeZone) null); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(4, test.getMonthOfYear()); assertEquals(6, test.getDayOfMonth()); } public void testConstructor_long1_Chronology() throws Throwable { LocalDate test = new LocalDate(TEST_TIME1, GREGORIAN_PARIS); assertEquals(GREGORIAN_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(4, test.getMonthOfYear()); assertEquals(6, test.getDayOfMonth()); } public void testConstructor_long2_Chronology() throws Throwable { LocalDate test = new LocalDate(TEST_TIME2, GREGORIAN_PARIS); assertEquals(GREGORIAN_UTC, test.getChronology()); assertEquals(1971, test.getYear()); assertEquals(5, test.getMonthOfYear()); assertEquals(7, test.getDayOfMonth()); } public void testConstructor_long_nullChronology() throws Throwable { LocalDate test = new LocalDate(TEST_TIME1, (Chronology) null); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(4, test.getMonthOfYear()); assertEquals(6, test.getDayOfMonth()); } // ----------------------------------------------------------------------- public void testConstructor_Object1() throws Throwable { Date date = new Date(TEST_TIME1); LocalDate test = new LocalDate(date); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(4, test.getMonthOfYear()); assertEquals(6, test.getDayOfMonth()); } public void testConstructor_nullObject() throws Throwable { LocalDate test = new LocalDate((Object) null); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(6, test.getMonthOfYear()); assertEquals(9, test.getDayOfMonth()); } public void testConstructor_ObjectString1() throws Throwable { LocalDate test = new LocalDate("1972-04-06"); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1972, test.getYear()); assertEquals(4, test.getMonthOfYear()); assertEquals(6, test.getDayOfMonth()); } public void testConstructor_ObjectString2() throws Throwable { LocalDate test = new LocalDate("1972-037"); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1972, test.getYear()); assertEquals(2, test.getMonthOfYear()); assertEquals(6, test.getDayOfMonth()); } public void testConstructor_ObjectString3() throws Throwable { LocalDate test = new LocalDate("1972-02"); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1972, test.getYear()); assertEquals(2, test.getMonthOfYear()); assertEquals(1, test.getDayOfMonth()); } public void testConstructor_ObjectStringEx1() throws Throwable { try { new LocalDate("1970-04-06T+14:00"); fail(); } catch (IllegalArgumentException ex) { } } public void testConstructor_ObjectStringEx2() throws Throwable { try { new LocalDate("1970-04-06T10:20:30.040"); fail(); } catch (IllegalArgumentException ex) { } } public void testConstructor_ObjectStringEx3() throws Throwable { try { new LocalDate("1970-04-06T10:20:30.040+14:00"); fail(); } catch (IllegalArgumentException ex) { } } public void testConstructor_ObjectStringEx4() throws Throwable { try { new LocalDate("T10:20:30.040"); fail(); } catch (IllegalArgumentException ex) { } } public void testConstructor_ObjectStringEx5() throws Throwable { try { new LocalDate("T10:20:30.040+14:00"); fail(); } catch (IllegalArgumentException ex) { } } public void testConstructor_ObjectStringEx6() throws Throwable { try { new LocalDate("10:20:30.040"); fail(); } catch (IllegalArgumentException ex) { } } public void testConstructor_ObjectStringEx7() throws Throwable { try { new LocalDate("10:20:30.040+14:00"); fail(); } catch (IllegalArgumentException ex) { } } public void testConstructor_ObjectLocalDate() throws Throwable { LocalDate date = new LocalDate(1970, 4, 6, BUDDHIST_UTC); LocalDate test = new LocalDate(date); assertEquals(BUDDHIST_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(4, test.getMonthOfYear()); assertEquals(6, test.getDayOfMonth()); } public void testConstructor_ObjectLocalTime() throws Throwable { LocalTime time = new LocalTime(10, 20, 30, 40, BUDDHIST_UTC); try { new LocalDate(time); fail(); } catch (IllegalArgumentException ex) { } } public void testConstructor_ObjectLocalDateTime() throws Throwable { LocalDateTime dt = new LocalDateTime(1970, 5, 6, 10, 20, 30, 40, BUDDHIST_UTC); LocalDate test = new LocalDate(dt); assertEquals(BUDDHIST_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(5, test.getMonthOfYear()); assertEquals(6, test.getDayOfMonth()); } public void testConstructor_ObjectYearMonthDay() throws Throwable { YearMonthDay date = new YearMonthDay(1970, 4, 6, BUDDHIST_UTC); LocalDate test = new LocalDate(date); assertEquals(BUDDHIST_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(4, test.getMonthOfYear()); assertEquals(6, test.getDayOfMonth()); } // ----------------------------------------------------------------------- public void testConstructor_Object_DateTimeZone() throws Throwable { Date date = new Date(TEST_TIME1); LocalDate test = new LocalDate(date, PARIS); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(4, test.getMonthOfYear()); assertEquals(6, test.getDayOfMonth()); } public void testConstructor_nullObject_DateTimeZone() throws Throwable { LocalDate test = new LocalDate((Object) null, PARIS); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(6, test.getMonthOfYear()); assertEquals(9, test.getDayOfMonth()); } public void testConstructor_Object_nullDateTimeZone() throws Throwable { Date date = new Date(TEST_TIME1); LocalDate test = new LocalDate(date, (DateTimeZone) null); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(4, test.getMonthOfYear()); assertEquals(6, test.getDayOfMonth()); } public void testConstructor_nullObject_nullDateTimeZone() throws Throwable { LocalDate test = new LocalDate((Object) null, (DateTimeZone) null); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(6, test.getMonthOfYear()); assertEquals(9, test.getDayOfMonth()); } public void testConstructor_Object_Chronology() throws Throwable { Date date = new Date(TEST_TIME1); LocalDate test = new LocalDate(date, GREGORIAN_PARIS); assertEquals(GREGORIAN_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(4, test.getMonthOfYear()); assertEquals(6, test.getDayOfMonth()); } public void testConstructor_nullObject_Chronology() throws Throwable { LocalDate test = new LocalDate((Object) null, GREGORIAN_PARIS); assertEquals(GREGORIAN_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(6, test.getMonthOfYear()); assertEquals(9, test.getDayOfMonth()); } public void testConstructor_Object_nullChronology() throws Throwable { Date date = new Date(TEST_TIME1); LocalDate test = new LocalDate(date, (Chronology) null); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(4, test.getMonthOfYear()); assertEquals(6, test.getDayOfMonth()); } public void testConstructor_nullObject_nullChronology() throws Throwable { LocalDate test = new LocalDate((Object) null, (Chronology) null); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(6, test.getMonthOfYear()); assertEquals(9, test.getDayOfMonth()); } // ----------------------------------------------------------------------- public void testConstructor_int_int_int() throws Throwable { LocalDate test = new LocalDate(1970, 6, 9); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(6, test.getMonthOfYear()); assertEquals(9, test.getDayOfMonth()); try { new LocalDate(Integer.MIN_VALUE, 6, 9); fail(); } catch (IllegalArgumentException ex) { } try { new LocalDate(Integer.MAX_VALUE, 6, 9); fail(); } catch (IllegalArgumentException ex) { } try { new LocalDate(1970, 0, 9); fail(); } catch (IllegalArgumentException ex) { } try { new LocalDate(1970, 13, 9); fail(); } catch (IllegalArgumentException ex) { } try { new LocalDate(1970, 6, 0); fail(); } catch (IllegalArgumentException ex) { } try { new LocalDate(1970, 6, 31); fail(); } catch (IllegalArgumentException ex) { } new LocalDate(1970, 7, 31); try { new LocalDate(1970, 7, 32); fail(); } catch (IllegalArgumentException ex) { } } public void testConstructor_int_int_int_Chronology() throws Throwable { LocalDate test = new LocalDate(1970, 6, 9, GREGORIAN_PARIS); assertEquals(GREGORIAN_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(6, test.getMonthOfYear()); assertEquals(9, test.getDayOfMonth()); try { new LocalDate(Integer.MIN_VALUE, 6, 9, GREGORIAN_PARIS); fail(); } catch (IllegalArgumentException ex) { } try { new LocalDate(Integer.MAX_VALUE, 6, 9, GREGORIAN_PARIS); fail(); } catch (IllegalArgumentException ex) { } try { new LocalDate(1970, 0, 9, GREGORIAN_PARIS); fail(); } catch (IllegalArgumentException ex) { } try { new LocalDate(1970, 13, 9, GREGORIAN_PARIS); fail(); } catch (IllegalArgumentException ex) { } try { new LocalDate(1970, 6, 0, GREGORIAN_PARIS); fail(); } catch (IllegalArgumentException ex) { } try { new LocalDate(1970, 6, 31, GREGORIAN_PARIS); fail(); } catch (IllegalArgumentException ex) { } new LocalDate(1970, 7, 31, GREGORIAN_PARIS); try { new LocalDate(1970, 7, 32, GREGORIAN_PARIS); fail(); } catch (IllegalArgumentException ex) { } } public void testConstructor_int_int_int_nullChronology() throws Throwable { LocalDate test = new LocalDate(1970, 6, 9, null); assertEquals(ISO_UTC, test.getChronology()); assertEquals(1970, test.getYear()); assertEquals(6, test.getMonthOfYear()); assertEquals(9, test.getDayOfMonth()); } }
/** * This class is a Junit unit test for LocalTime. * * @author Stephen Colebourne */ public class TestLocalTime_Basics extends TestCase { private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris"); private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London"); private static final DateTimeZone TOKYO = DateTimeZone.forID("Asia/Tokyo"); private static final Chronology COPTIC_PARIS = CopticChronology.getInstance(PARIS); private static final Chronology COPTIC_LONDON = CopticChronology.getInstance(LONDON); private static final Chronology COPTIC_TOKYO = CopticChronology.getInstance(TOKYO); private static final Chronology COPTIC_UTC = CopticChronology.getInstanceUTC(); private static final Chronology BUDDHIST_LONDON = BuddhistChronology.getInstance(LONDON); private long TEST_TIME_NOW = 10L * DateTimeConstants.MILLIS_PER_HOUR + 20L * DateTimeConstants.MILLIS_PER_MINUTE + 30L * DateTimeConstants.MILLIS_PER_SECOND + 40L; // private long TEST_TIME1 = // 1L * DateTimeConstants.MILLIS_PER_HOUR // + 2L * DateTimeConstants.MILLIS_PER_MINUTE // + 3L * DateTimeConstants.MILLIS_PER_SECOND // + 4L; private long TEST_TIME2 = 1L * DateTimeConstants.MILLIS_PER_DAY + 5L * DateTimeConstants.MILLIS_PER_HOUR + 6L * DateTimeConstants.MILLIS_PER_MINUTE + 7L * DateTimeConstants.MILLIS_PER_SECOND + 8L; private DateTimeZone zone = null; public static void main(String[] args) { junit.textui.TestRunner.run(suite()); } public static TestSuite suite() { return new TestSuite(TestLocalTime_Basics.class); } public TestLocalTime_Basics(String name) { super(name); } protected void setUp() throws Exception { DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW); zone = DateTimeZone.getDefault(); DateTimeZone.setDefault(LONDON); } protected void tearDown() throws Exception { DateTimeUtils.setCurrentMillisSystem(); DateTimeZone.setDefault(zone); zone = null; } // ----------------------------------------------------------------------- public void testGet_DateTimeFieldType() { LocalTime test = new LocalTime(10, 20, 30, 40); assertEquals(10, test.get(DateTimeFieldType.hourOfDay())); assertEquals(20, test.get(DateTimeFieldType.minuteOfHour())); assertEquals(30, test.get(DateTimeFieldType.secondOfMinute())); assertEquals(40, test.get(DateTimeFieldType.millisOfSecond())); assertEquals(TEST_TIME_NOW / 60000, test.get(DateTimeFieldType.minuteOfDay())); assertEquals(TEST_TIME_NOW / 1000, test.get(DateTimeFieldType.secondOfDay())); assertEquals(TEST_TIME_NOW, test.get(DateTimeFieldType.millisOfDay())); assertEquals(10, test.get(DateTimeFieldType.hourOfHalfday())); assertEquals(DateTimeConstants.AM, test.get(DateTimeFieldType.halfdayOfDay())); test = new LocalTime(12, 30); assertEquals(0, test.get(DateTimeFieldType.hourOfHalfday())); assertEquals(12, test.get(DateTimeFieldType.clockhourOfHalfday())); assertEquals(12, test.get(DateTimeFieldType.clockhourOfDay())); assertEquals(DateTimeConstants.PM, test.get(DateTimeFieldType.halfdayOfDay())); test = new LocalTime(14, 30); assertEquals(2, test.get(DateTimeFieldType.hourOfHalfday())); assertEquals(2, test.get(DateTimeFieldType.clockhourOfHalfday())); assertEquals(14, test.get(DateTimeFieldType.clockhourOfDay())); assertEquals(DateTimeConstants.PM, test.get(DateTimeFieldType.halfdayOfDay())); test = new LocalTime(0, 30); assertEquals(0, test.get(DateTimeFieldType.hourOfHalfday())); assertEquals(12, test.get(DateTimeFieldType.clockhourOfHalfday())); assertEquals(24, test.get(DateTimeFieldType.clockhourOfDay())); assertEquals(DateTimeConstants.AM, test.get(DateTimeFieldType.halfdayOfDay())); try { test.get(null); fail(); } catch (IllegalArgumentException ex) { } try { test.get(DateTimeFieldType.dayOfMonth()); fail(); } catch (IllegalArgumentException ex) { } } public void testSize() { LocalTime test = new LocalTime(10, 20, 30, 40); assertEquals(4, test.size()); } public void testGetFieldType_int() { LocalTime test = new LocalTime(10, 20, 30, 40); assertSame(DateTimeFieldType.hourOfDay(), test.getFieldType(0)); assertSame(DateTimeFieldType.minuteOfHour(), test.getFieldType(1)); assertSame(DateTimeFieldType.secondOfMinute(), test.getFieldType(2)); assertSame(DateTimeFieldType.millisOfSecond(), test.getFieldType(3)); try { test.getFieldType(-1); } catch (IndexOutOfBoundsException ex) { } try { test.getFieldType(5); } catch (IndexOutOfBoundsException ex) { } } public void testGetFieldTypes() { LocalTime test = new LocalTime(10, 20, 30, 40); DateTimeFieldType[] fields = test.getFieldTypes(); assertSame(DateTimeFieldType.hourOfDay(), fields[0]); assertSame(DateTimeFieldType.minuteOfHour(), fields[1]); assertSame(DateTimeFieldType.secondOfMinute(), fields[2]); assertSame(DateTimeFieldType.millisOfSecond(), fields[3]); assertNotSame(test.getFieldTypes(), test.getFieldTypes()); } public void testGetField_int() { LocalTime test = new LocalTime(10, 20, 30, 40, COPTIC_UTC); assertSame(COPTIC_UTC.hourOfDay(), test.getField(0)); assertSame(COPTIC_UTC.minuteOfHour(), test.getField(1)); assertSame(COPTIC_UTC.secondOfMinute(), test.getField(2)); assertSame(COPTIC_UTC.millisOfSecond(), test.getField(3)); try { test.getField(-1); } catch (IndexOutOfBoundsException ex) { } try { test.getField(5); } catch (IndexOutOfBoundsException ex) { } } public void testGetFields() { LocalTime test = new LocalTime(10, 20, 30, 40, COPTIC_UTC); DateTimeField[] fields = test.getFields(); assertSame(COPTIC_UTC.hourOfDay(), fields[0]); assertSame(COPTIC_UTC.minuteOfHour(), fields[1]); assertSame(COPTIC_UTC.secondOfMinute(), fields[2]); assertSame(COPTIC_UTC.millisOfSecond(), fields[3]); assertNotSame(test.getFields(), test.getFields()); } public void testGetValue_int() { LocalTime test = new LocalTime(10, 20, 30, 40, COPTIC_PARIS); assertEquals(10, test.getValue(0)); assertEquals(20, test.getValue(1)); assertEquals(30, test.getValue(2)); assertEquals(40, test.getValue(3)); try { test.getValue(-1); } catch (IndexOutOfBoundsException ex) { } try { test.getValue(5); } catch (IndexOutOfBoundsException ex) { } } public void testGetValues() { LocalTime test = new LocalTime(10, 20, 30, 40, COPTIC_UTC); int[] values = test.getValues(); assertEquals(10, values[0]); assertEquals(20, values[1]); assertEquals(30, values[2]); assertEquals(40, values[3]); assertNotSame(test.getValues(), test.getValues()); } public void testIsSupported_DateTimeFieldType() { LocalTime test = new LocalTime(10, 20, 30, 40); assertEquals(true, test.isSupported(DateTimeFieldType.hourOfDay())); assertEquals(true, test.isSupported(DateTimeFieldType.minuteOfHour())); assertEquals(true, test.isSupported(DateTimeFieldType.secondOfMinute())); assertEquals(true, test.isSupported(DateTimeFieldType.millisOfSecond())); assertEquals(true, test.isSupported(DateTimeFieldType.minuteOfDay())); assertEquals(true, test.isSupported(DateTimeFieldType.secondOfDay())); assertEquals(true, test.isSupported(DateTimeFieldType.millisOfDay())); assertEquals(true, test.isSupported(DateTimeFieldType.hourOfHalfday())); assertEquals(true, test.isSupported(DateTimeFieldType.halfdayOfDay())); assertEquals(true, test.isSupported(DateTimeFieldType.clockhourOfHalfday())); assertEquals(true, test.isSupported(DateTimeFieldType.clockhourOfDay())); assertEquals(false, test.isSupported(DateTimeFieldType.dayOfMonth())); assertEquals(false, test.isSupported((DateTimeFieldType) null)); DateTimeFieldType d = new DateTimeFieldType("hours") { private static final long serialVersionUID = 1L; public DurationFieldType getDurationType() { return DurationFieldType.hours(); } public DurationFieldType getRangeDurationType() { return null; } public DateTimeField getField(Chronology chronology) { return chronology.hourOfDay(); } }; assertEquals(false, test.isSupported(d)); d = new DateTimeFieldType("hourOfYear") { private static final long serialVersionUID = 1L; public DurationFieldType getDurationType() { return DurationFieldType.hours(); } public DurationFieldType getRangeDurationType() { return DurationFieldType.years(); } public DateTimeField getField(Chronology chronology) { return chronology.hourOfDay(); } }; assertEquals(false, test.isSupported(d)); } public void testIsSupported_DurationFieldType() { LocalTime test = new LocalTime(10, 20, 30, 40); assertEquals(true, test.isSupported(DurationFieldType.hours())); assertEquals(true, test.isSupported(DurationFieldType.minutes())); assertEquals(true, test.isSupported(DurationFieldType.seconds())); assertEquals(true, test.isSupported(DurationFieldType.millis())); assertEquals(true, test.isSupported(DurationFieldType.halfdays())); assertEquals(false, test.isSupported(DurationFieldType.days())); assertEquals(false, test.isSupported((DurationFieldType) null)); } @SuppressWarnings("deprecation") public void testEqualsHashCode() { LocalTime test1 = new LocalTime(10, 20, 30, 40, COPTIC_PARIS); LocalTime test2 = new LocalTime(10, 20, 30, 40, COPTIC_PARIS); assertEquals(true, test1.equals(test2)); assertEquals(true, test2.equals(test1)); assertEquals(true, test1.equals(test1)); assertEquals(true, test2.equals(test2)); assertEquals(true, test1.hashCode() == test2.hashCode()); assertEquals(true, test1.hashCode() == test1.hashCode()); assertEquals(true, test2.hashCode() == test2.hashCode()); LocalTime test3 = new LocalTime(15, 20, 30, 40); assertEquals(false, test1.equals(test3)); assertEquals(false, test2.equals(test3)); assertEquals(false, test3.equals(test1)); assertEquals(false, test3.equals(test2)); assertEquals(false, test1.hashCode() == test3.hashCode()); assertEquals(false, test2.hashCode() == test3.hashCode()); assertEquals(false, test1.equals("Hello")); assertEquals(true, test1.equals(new TimeOfDay(10, 20, 30, 40, COPTIC_UTC))); assertEquals(true, test1.hashCode() == new TimeOfDay(10, 20, 30, 40, COPTIC_UTC).hashCode()); assertEquals(true, test1.equals(new MockInstant())); assertEquals(false, test1.equals(MockPartial.EMPTY_INSTANCE)); } class MockInstant extends MockPartial { public Chronology getChronology() { return COPTIC_UTC; } public DateTimeField[] getFields() { return new DateTimeField[] { COPTIC_UTC.hourOfDay(), COPTIC_UTC.minuteOfHour(), COPTIC_UTC.secondOfMinute(), COPTIC_UTC.millisOfSecond(), }; } public int[] getValues() { return new int[] {10, 20, 30, 40}; } } // ----------------------------------------------------------------------- @SuppressWarnings("deprecation") public void testCompareTo() { LocalTime test1 = new LocalTime(10, 20, 30, 40); LocalTime test1a = new LocalTime(10, 20, 30, 40); assertEquals(0, test1.compareTo(test1a)); assertEquals(0, test1a.compareTo(test1)); assertEquals(0, test1.compareTo(test1)); assertEquals(0, test1a.compareTo(test1a)); LocalTime test2 = new LocalTime(10, 20, 35, 40); assertEquals(-1, test1.compareTo(test2)); assertEquals(+1, test2.compareTo(test1)); LocalTime test3 = new LocalTime(10, 20, 35, 40, GregorianChronology.getInstanceUTC()); assertEquals(-1, test1.compareTo(test3)); assertEquals(+1, test3.compareTo(test1)); assertEquals(0, test3.compareTo(test2)); DateTimeFieldType[] types = new DateTimeFieldType[] { DateTimeFieldType.hourOfDay(), DateTimeFieldType.minuteOfHour(), DateTimeFieldType.secondOfMinute(), DateTimeFieldType.millisOfSecond(), }; int[] values = new int[] {10, 20, 30, 40}; Partial p = new Partial(types, values); assertEquals(0, test1.compareTo(p)); assertEquals(0, test1.compareTo(new TimeOfDay(10, 20, 30, 40))); try { test1.compareTo(null); fail(); } catch (NullPointerException ex) { } // try { // test1.compareTo(new Date()); // fail(); // } catch (ClassCastException ex) {} } // ----------------------------------------------------------------------- public void testIsEqual_LocalTime() { LocalTime test1 = new LocalTime(10, 20, 30, 40); LocalTime test1a = new LocalTime(10, 20, 30, 40); assertEquals(true, test1.isEqual(test1a)); assertEquals(true, test1a.isEqual(test1)); assertEquals(true, test1.isEqual(test1)); assertEquals(true, test1a.isEqual(test1a)); LocalTime test2 = new LocalTime(10, 20, 35, 40); assertEquals(false, test1.isEqual(test2)); assertEquals(false, test2.isEqual(test1)); LocalTime test3 = new LocalTime(10, 20, 35, 40, GregorianChronology.getInstanceUTC()); assertEquals(false, test1.isEqual(test3)); assertEquals(false, test3.isEqual(test1)); assertEquals(true, test3.isEqual(test2)); try { new LocalTime(10, 20, 35, 40).isEqual(null); fail(); } catch (IllegalArgumentException ex) { } } // ----------------------------------------------------------------------- public void testIsBefore_LocalTime() { LocalTime test1 = new LocalTime(10, 20, 30, 40); LocalTime test1a = new LocalTime(10, 20, 30, 40); assertEquals(false, test1.isBefore(test1a)); assertEquals(false, test1a.isBefore(test1)); assertEquals(false, test1.isBefore(test1)); assertEquals(false, test1a.isBefore(test1a)); LocalTime test2 = new LocalTime(10, 20, 35, 40); assertEquals(true, test1.isBefore(test2)); assertEquals(false, test2.isBefore(test1)); LocalTime test3 = new LocalTime(10, 20, 35, 40, GregorianChronology.getInstanceUTC()); assertEquals(true, test1.isBefore(test3)); assertEquals(false, test3.isBefore(test1)); assertEquals(false, test3.isBefore(test2)); try { new LocalTime(10, 20, 35, 40).isBefore(null); fail(); } catch (IllegalArgumentException ex) { } } // ----------------------------------------------------------------------- public void testIsAfter_LocalTime() { LocalTime test1 = new LocalTime(10, 20, 30, 40); LocalTime test1a = new LocalTime(10, 20, 30, 40); assertEquals(false, test1.isAfter(test1a)); assertEquals(false, test1a.isAfter(test1)); assertEquals(false, test1.isAfter(test1)); assertEquals(false, test1a.isAfter(test1a)); LocalTime test2 = new LocalTime(10, 20, 35, 40); assertEquals(false, test1.isAfter(test2)); assertEquals(true, test2.isAfter(test1)); LocalTime test3 = new LocalTime(10, 20, 35, 40, GregorianChronology.getInstanceUTC()); assertEquals(false, test1.isAfter(test3)); assertEquals(true, test3.isAfter(test1)); assertEquals(false, test3.isAfter(test2)); try { new LocalTime(10, 20, 35, 40).isAfter(null); fail(); } catch (IllegalArgumentException ex) { } } // ----------------------------------------------------------------------- public void testWithField_DateTimeFieldType_int_1() { LocalTime test = new LocalTime(10, 20, 30, 40); LocalTime result = test.withField(DateTimeFieldType.hourOfDay(), 15); assertEquals(new LocalTime(10, 20, 30, 40), test); assertEquals(new LocalTime(15, 20, 30, 40), result); } public void testWithField_DateTimeFieldType_int_2() { LocalTime test = new LocalTime(10, 20, 30, 40); try { test.withField(null, 6); fail(); } catch (IllegalArgumentException ex) { } } public void testWithField_DateTimeFieldType_int_3() { LocalTime test = new LocalTime(10, 20, 30, 40); try { test.withField(DateTimeFieldType.dayOfMonth(), 6); fail(); } catch (IllegalArgumentException ex) { } } public void testWithField_DateTimeFieldType_int_4() { LocalTime test = new LocalTime(10, 20, 30, 40); LocalTime result = test.withField(DateTimeFieldType.hourOfDay(), 10); assertSame(test, result); } // ----------------------------------------------------------------------- public void testWithFieldAdded_DurationFieldType_int_1() { LocalTime test = new LocalTime(10, 20, 30, 40); LocalTime result = test.withFieldAdded(DurationFieldType.hours(), 6); assertEquals(new LocalTime(10, 20, 30, 40), test); assertEquals(new LocalTime(16, 20, 30, 40), result); } public void testWithFieldAdded_DurationFieldType_int_2() { LocalTime test = new LocalTime(10, 20, 30, 40); try { test.withFieldAdded(null, 0); fail(); } catch (IllegalArgumentException ex) { } } public void testWithFieldAdded_DurationFieldType_int_3() { LocalTime test = new LocalTime(10, 20, 30, 40); try { test.withFieldAdded(null, 6); fail(); } catch (IllegalArgumentException ex) { } } public void testWithFieldAdded_DurationFieldType_int_4() { LocalTime test = new LocalTime(10, 20, 30, 40); LocalTime result = test.withFieldAdded(DurationFieldType.hours(), 0); assertSame(test, result); } public void testWithFieldAdded_DurationFieldType_int_5() { LocalTime test = new LocalTime(10, 20, 30, 40); try { test.withFieldAdded(DurationFieldType.days(), 6); fail(); } catch (IllegalArgumentException ex) { } } public void testWithFieldAdded_DurationFieldType_int_6() { LocalTime test = new LocalTime(10, 20, 30, 40); LocalTime result = test.withFieldAdded(DurationFieldType.hours(), 16); assertEquals(new LocalTime(10, 20, 30, 40), test); assertEquals(new LocalTime(2, 20, 30, 40), result); } public void testWithFieldAdded_DurationFieldType_int_7() { LocalTime test = new LocalTime(23, 59, 59, 999); LocalTime result = test.withFieldAdded(DurationFieldType.millis(), 1); assertEquals(new LocalTime(0, 0, 0, 0), result); test = new LocalTime(23, 59, 59, 999); result = test.withFieldAdded(DurationFieldType.seconds(), 1); assertEquals(new LocalTime(0, 0, 0, 999), result); test = new LocalTime(23, 59, 59, 999); result = test.withFieldAdded(DurationFieldType.minutes(), 1); assertEquals(new LocalTime(0, 0, 59, 999), result); test = new LocalTime(23, 59, 59, 999); result = test.withFieldAdded(DurationFieldType.hours(), 1); assertEquals(new LocalTime(0, 59, 59, 999), result); } public void testWithFieldAdded_DurationFieldType_int_8() { LocalTime test = new LocalTime(0, 0, 0, 0); LocalTime result = test.withFieldAdded(DurationFieldType.millis(), -1); assertEquals(new LocalTime(23, 59, 59, 999), result); test = new LocalTime(0, 0, 0, 0); result = test.withFieldAdded(DurationFieldType.seconds(), -1); assertEquals(new LocalTime(23, 59, 59, 0), result); test = new LocalTime(0, 0, 0, 0); result = test.withFieldAdded(DurationFieldType.minutes(), -1); assertEquals(new LocalTime(23, 59, 0, 0), result); test = new LocalTime(0, 0, 0, 0); result = test.withFieldAdded(DurationFieldType.hours(), -1); assertEquals(new LocalTime(23, 0, 0, 0), result); } // ----------------------------------------------------------------------- public void testPlus_RP() { LocalTime test = new LocalTime(10, 20, 30, 40, BUDDHIST_LONDON); LocalTime result = test.plus(new Period(1, 2, 3, 4, 5, 6, 7, 8)); LocalTime expected = new LocalTime(15, 26, 37, 48, BUDDHIST_LONDON); assertEquals(expected, result); result = test.plus((ReadablePeriod) null); assertSame(test, result); } public void testPlusHours_int() { LocalTime test = new LocalTime(1, 2, 3, 4, BUDDHIST_LONDON); LocalTime result = test.plusHours(1); LocalTime expected = new LocalTime(2, 2, 3, 4, BUDDHIST_LONDON); assertEquals(expected, result); result = test.plusHours(0); assertSame(test, result); } public void testPlusMinutes_int() { LocalTime test = new LocalTime(1, 2, 3, 4, BUDDHIST_LONDON); LocalTime result = test.plusMinutes(1); LocalTime expected = new LocalTime(1, 3, 3, 4, BUDDHIST_LONDON); assertEquals(expected, result); result = test.plusMinutes(0); assertSame(test, result); } public void testPlusSeconds_int() { LocalTime test = new LocalTime(1, 2, 3, 4, BUDDHIST_LONDON); LocalTime result = test.plusSeconds(1); LocalTime expected = new LocalTime(1, 2, 4, 4, BUDDHIST_LONDON); assertEquals(expected, result); result = test.plusSeconds(0); assertSame(test, result); } public void testPlusMillis_int() { LocalTime test = new LocalTime(1, 2, 3, 4, BUDDHIST_LONDON); LocalTime result = test.plusMillis(1); LocalTime expected = new LocalTime(1, 2, 3, 5, BUDDHIST_LONDON); assertEquals(expected, result); result = test.plusMillis(0); assertSame(test, result); } // ----------------------------------------------------------------------- public void testMinus_RP() { LocalTime test = new LocalTime(10, 20, 30, 40, BUDDHIST_LONDON); LocalTime result = test.minus(new Period(1, 1, 1, 1, 1, 1, 1, 1)); LocalTime expected = new LocalTime(9, 19, 29, 39, BUDDHIST_LONDON); assertEquals(expected, result); result = test.minus((ReadablePeriod) null); assertSame(test, result); } public void testMinusHours_int() { LocalTime test = new LocalTime(1, 2, 3, 4, BUDDHIST_LONDON); LocalTime result = test.minusHours(1); LocalTime expected = new LocalTime(0, 2, 3, 4, BUDDHIST_LONDON); assertEquals(expected, result); result = test.minusHours(0); assertSame(test, result); } public void testMinusMinutes_int() { LocalTime test = new LocalTime(1, 2, 3, 4, BUDDHIST_LONDON); LocalTime result = test.minusMinutes(1); LocalTime expected = new LocalTime(1, 1, 3, 4, BUDDHIST_LONDON); assertEquals(expected, result); result = test.minusMinutes(0); assertSame(test, result); } public void testMinusSeconds_int() { LocalTime test = new LocalTime(1, 2, 3, 4, BUDDHIST_LONDON); LocalTime result = test.minusSeconds(1); LocalTime expected = new LocalTime(1, 2, 2, 4, BUDDHIST_LONDON); assertEquals(expected, result); result = test.minusSeconds(0); assertSame(test, result); } public void testMinusMillis_int() { LocalTime test = new LocalTime(1, 2, 3, 4, BUDDHIST_LONDON); LocalTime result = test.minusMillis(1); LocalTime expected = new LocalTime(1, 2, 3, 3, BUDDHIST_LONDON); assertEquals(expected, result); result = test.minusMillis(0); assertSame(test, result); } // ----------------------------------------------------------------------- public void testGetters() { LocalTime test = new LocalTime(10, 20, 30, 40); assertEquals(10, test.getHourOfDay()); assertEquals(20, test.getMinuteOfHour()); assertEquals(30, test.getSecondOfMinute()); assertEquals(40, test.getMillisOfSecond()); assertEquals(TEST_TIME_NOW, test.getMillisOfDay()); } // ----------------------------------------------------------------------- public void testWithers() { LocalTime test = new LocalTime(10, 20, 30, 40); check(test.withHourOfDay(6), 6, 20, 30, 40); check(test.withMinuteOfHour(6), 10, 6, 30, 40); check(test.withSecondOfMinute(6), 10, 20, 6, 40); check(test.withMillisOfSecond(6), 10, 20, 30, 6); check(test.withMillisOfDay(61234), 0, 1, 1, 234); try { test.withHourOfDay(-1); fail(); } catch (IllegalArgumentException ex) { } try { test.withHourOfDay(24); fail(); } catch (IllegalArgumentException ex) { } } // ----------------------------------------------------------------------- public void testToDateTimeTodayDefaultZone() { LocalTime base = new LocalTime(10, 20, 30, 40, COPTIC_PARIS); // PARIS irrelevant DateTime dt = new DateTime(2004, 6, 9, 6, 7, 8, 9); DateTimeUtils.setCurrentMillisFixed(dt.getMillis()); DateTime test = base.toDateTimeToday(); check(base, 10, 20, 30, 40); DateTime expected = new DateTime(dt.getMillis(), COPTIC_LONDON); expected = expected.hourOfDay().setCopy(10); expected = expected.minuteOfHour().setCopy(20); expected = expected.secondOfMinute().setCopy(30); expected = expected.millisOfSecond().setCopy(40); assertEquals(expected, test); } // ----------------------------------------------------------------------- public void testToDateTimeToday_Zone() { LocalTime base = new LocalTime(10, 20, 30, 40, COPTIC_PARIS); // PARIS irrelevant DateTime dt = new DateTime(2004, 6, 9, 6, 7, 8, 9); DateTimeUtils.setCurrentMillisFixed(dt.getMillis()); DateTime test = base.toDateTimeToday(TOKYO); check(base, 10, 20, 30, 40); DateTime expected = new DateTime(dt.getMillis(), COPTIC_TOKYO); expected = expected.hourOfDay().setCopy(10); expected = expected.minuteOfHour().setCopy(20); expected = expected.secondOfMinute().setCopy(30); expected = expected.millisOfSecond().setCopy(40); assertEquals(expected, test); } public void testToDateTimeToday_nullZone() { LocalTime base = new LocalTime(10, 20, 30, 40, COPTIC_PARIS); // PARIS irrelevant DateTime dt = new DateTime(2004, 6, 9, 6, 7, 8, 9); DateTimeUtils.setCurrentMillisFixed(dt.getMillis()); DateTime test = base.toDateTimeToday((DateTimeZone) null); check(base, 10, 20, 30, 40); DateTime expected = new DateTime(dt.getMillis(), COPTIC_LONDON); expected = expected.hourOfDay().setCopy(10); expected = expected.minuteOfHour().setCopy(20); expected = expected.secondOfMinute().setCopy(30); expected = expected.millisOfSecond().setCopy(40); assertEquals(expected, test); } // ----------------------------------------------------------------------- public void testToDateTime_RI() { LocalTime base = new LocalTime(10, 20, 30, 40, COPTIC_PARIS); DateTime dt = new DateTime(0L); // LONDON zone assertEquals("1970-01-01T01:00:00.000+01:00", dt.toString()); DateTime test = base.toDateTime(dt); check(base, 10, 20, 30, 40); assertEquals("1970-01-01T01:00:00.000+01:00", dt.toString()); assertEquals("1970-01-01T10:20:30.040+01:00", test.toString()); } public void testToDateTime_nullRI() { LocalTime base = new LocalTime(1, 2, 3, 4); DateTimeUtils.setCurrentMillisFixed(TEST_TIME2); DateTime test = base.toDateTime((ReadableInstant) null); check(base, 1, 2, 3, 4); assertEquals("1970-01-02T01:02:03.004+01:00", test.toString()); } // ----------------------------------------------------------------------- public void testProperty() { LocalTime test = new LocalTime(10, 20, 30, 40); assertEquals(test.hourOfDay(), test.property(DateTimeFieldType.hourOfDay())); assertEquals(test.minuteOfHour(), test.property(DateTimeFieldType.minuteOfHour())); assertEquals(test.secondOfMinute(), test.property(DateTimeFieldType.secondOfMinute())); assertEquals(test.millisOfSecond(), test.property(DateTimeFieldType.millisOfSecond())); assertEquals(test.millisOfDay(), test.property(DateTimeFieldType.millisOfDay())); assertEquals(test, test.property(DateTimeFieldType.minuteOfDay()).getLocalTime()); assertEquals(test, test.property(DateTimeFieldType.secondOfDay()).getLocalTime()); assertEquals(test, test.property(DateTimeFieldType.millisOfDay()).getLocalTime()); assertEquals(test, test.property(DateTimeFieldType.hourOfHalfday()).getLocalTime()); assertEquals(test, test.property(DateTimeFieldType.halfdayOfDay()).getLocalTime()); assertEquals(test, test.property(DateTimeFieldType.clockhourOfHalfday()).getLocalTime()); assertEquals(test, test.property(DateTimeFieldType.clockhourOfDay()).getLocalTime()); try { test.property(DateTimeFieldType.dayOfWeek()); fail(); } catch (IllegalArgumentException ex) { } try { test.property(null); fail(); } catch (IllegalArgumentException ex) { } } // ----------------------------------------------------------------------- public void testSerialization() throws Exception { LocalTime test = new LocalTime(10, 20, 30, 40, COPTIC_PARIS); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(test); oos.close(); byte[] bytes = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bais); LocalTime result = (LocalTime) ois.readObject(); ois.close(); assertEquals(test, result); assertTrue(Arrays.equals(test.getValues(), result.getValues())); assertTrue(Arrays.equals(test.getFields(), result.getFields())); assertEquals(test.getChronology(), result.getChronology()); } // ----------------------------------------------------------------------- public void testToString() { LocalTime test = new LocalTime(10, 20, 30, 40); assertEquals("10:20:30.040", test.toString()); } // ----------------------------------------------------------------------- public void testToString_String() { LocalTime test = new LocalTime(10, 20, 30, 40); assertEquals("\ufffd\ufffd\ufffd\ufffd 10", test.toString("yyyy HH")); assertEquals("10:20:30.040", test.toString((String) null)); } // ----------------------------------------------------------------------- public void testToString_String_Locale() { LocalTime test = new LocalTime(10, 20, 30, 40); assertEquals("10 20", test.toString("H m", Locale.ENGLISH)); assertEquals("10:20:30.040", test.toString(null, Locale.ENGLISH)); assertEquals("10 20", test.toString("H m", null)); assertEquals("10:20:30.040", test.toString(null, null)); } // ----------------------------------------------------------------------- public void testToString_DTFormatter() { LocalTime test = new LocalTime(10, 20, 30, 40); assertEquals( "\ufffd\ufffd\ufffd\ufffd 10", test.toString(DateTimeFormat.forPattern("yyyy HH"))); assertEquals("10:20:30.040", test.toString((DateTimeFormatter) null)); } // ----------------------------------------------------------------------- private void check(LocalTime test, int hour, int min, int sec, int milli) { assertEquals(hour, test.getHourOfDay()); assertEquals(min, test.getMinuteOfHour()); assertEquals(sec, test.getSecondOfMinute()); assertEquals(milli, test.getMillisOfSecond()); } }