Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Enhance OffsetDate/OffsetTime tests

  • Loading branch information...
commit aa8cea8e0d8a4816b4de79320e990dae312a3314 1 parent c330c07
@jodastephen jodastephen authored
View
245 src/tck/java/javax/time/TCKOffsetDate.java
@@ -50,17 +50,10 @@
import static javax.time.calendrical.ChronoField.YEAR_OF_ERA;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -68,6 +61,8 @@
import javax.time.calendrical.ChronoField;
import javax.time.calendrical.ChronoUnit;
import javax.time.calendrical.DateTime;
+import javax.time.calendrical.DateTime.MinusAdjuster;
+import javax.time.calendrical.DateTime.PlusAdjuster;
import javax.time.calendrical.DateTime.WithAdjuster;
import javax.time.calendrical.DateTimeAccessor;
import javax.time.calendrical.DateTimeField;
@@ -138,30 +133,15 @@ public void setUp() {
return list;
}
+ //-----------------------------------------------------------------------
@Test(groups={"tck"})
- public void test_serialization() throws IOException, ClassNotFoundException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(TEST_2007_07_15_PONE);
- oos.close();
-
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(
- baos.toByteArray()));
- assertEquals(ois.readObject(), TEST_2007_07_15_PONE);
+ public void test_serialization() throws ClassNotFoundException, IOException {
+ assertSerializable(TEST_2007_07_15_PONE);
}
@Test(groups={"tck"})
- public void test_immutable() {
- Class<OffsetDate> cls = OffsetDate.class;
- assertTrue(Modifier.isPublic(cls.getModifiers()));
- assertTrue(Modifier.isFinal(cls.getModifiers()));
- Field[] fields = cls.getDeclaredFields();
- for (Field field : fields) {
- if (field.getName().contains("$") == false) {
- assertTrue(Modifier.isPrivate(field.getModifiers()));
- assertTrue(Modifier.isFinal(field.getModifiers()));
- }
- }
+ public void test_serialization_format() throws ClassNotFoundException, IOException {
+ assertEqualsSerialisedForm(OffsetDate.of(LocalDate.of(2012, 9, 16), ZoneOffset.of("+01:00")));
}
//-----------------------------------------------------------------------
@@ -187,10 +167,7 @@ public void now_Clock_allSecsInDay_utc() {
Instant instant = Instant.ofEpochSecond(i);
Clock clock = Clock.fixed(instant, ZoneId.UTC);
OffsetDate test = OffsetDate.now(clock);
- assertEquals(test.getYear(), 1970);
- assertEquals(test.getMonth(), Month.JANUARY);
- assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2));
- assertEquals(test.getOffset(), ZoneOffset.UTC);
+ check(test, 1970, 1, (i < 24 * 60 * 60 ? 1 : 2), ZoneOffset.UTC);
}
}
@@ -200,24 +177,18 @@ public void now_Clock_allSecsInDay_beforeEpoch() {
Instant instant = Instant.ofEpochSecond(i);
Clock clock = Clock.fixed(instant, ZoneId.UTC);
OffsetDate test = OffsetDate.now(clock);
- assertEquals(test.getYear(), 1969);
- assertEquals(test.getMonth(), Month.DECEMBER);
- assertEquals(test.getDayOfMonth(), (i >= -24 * 60 * 60 ? 31 : 30));
- assertEquals(test.getOffset(), ZoneOffset.UTC);
+ check(test, 1969, 12, (i >= -24 * 60 * 60 ? 31 : 30), ZoneOffset.UTC);
}
}
@Test(groups={"tck"})
public void now_Clock_offsets() {
- OffsetDateTime base = OffsetDateTime.of(1970, 1, 1, 12, 0, ZoneOffset.UTC);
+ Instant base = LocalDateTime.of(1970, 1, 1, 12, 0).toInstant(ZoneOffset.UTC);
for (int i = -9; i < 15; i++) {
ZoneOffset offset = ZoneOffset.ofHours(i);
- Clock clock = Clock.fixed(base.toInstant(), ZoneId.of(offset));
+ Clock clock = Clock.fixed(base, ZoneId.of(offset));
OffsetDate test = OffsetDate.now(clock);
- assertEquals(test.getYear(), 1970);
- assertEquals(test.getMonth(), Month.JANUARY);
- assertEquals(test.getDayOfMonth(), i >= 12 ? 2 : 1);
- assertEquals(test.getOffset(), offset);
+ check(test, 1970, 1, (i >= 12 ? 2 : 1), offset);
}
}
@@ -235,10 +206,11 @@ public void now_Clock_nullClock() {
// factories
//-----------------------------------------------------------------------
void check(OffsetDate test, int y, int mo, int d, ZoneOffset offset) {
+ assertEquals(test.getDate(), LocalDate.of(y, mo, d));
+ assertEquals(test.getOffset(), offset);
assertEquals(test.getYear(), y);
assertEquals(test.getMonth().getValue(), mo);
assertEquals(test.getDayOfMonth(), d);
- assertEquals(test.getOffset(), offset);
}
//-----------------------------------------------------------------------
@@ -343,21 +315,26 @@ public void factory_of_LocalDateZoneOffset_nullOffset() {
}
//-----------------------------------------------------------------------
- // from()
+ // from(DateTimeAccessor)
//-----------------------------------------------------------------------
@Test(groups={"tck"})
- public void test_factory_CalendricalObject() {
- assertEquals(OffsetDate.from(OffsetDate.of(2007, 7, 15, OFFSET_PONE)), OffsetDate.of(2007, 7, 15, OFFSET_PONE));
- assertEquals(OffsetDate.from(OffsetDateTime.of(2007, 7, 15, 17, 30, OFFSET_PONE)), OffsetDate.of(2007, 7, 15, OFFSET_PONE));
+ public void test_from_DateTimeAccessor_OD() {
+ assertEquals(OffsetDate.from(TEST_2007_07_15_PONE), TEST_2007_07_15_PONE);
+ }
+
+ @Test(groups={"tck"})
+ public void test_from_DateTimeAccessor_ZDT() {
+ ZonedDateTime base = ZonedDateTime.of(2007, 7, 15, 17, 30, 0, 0, ZoneId.of(OFFSET_PONE));
+ assertEquals(OffsetDate.from(base), TEST_2007_07_15_PONE);
}
@Test(expectedExceptions=DateTimeException.class, groups={"tck"})
- public void test_factory_CalendricalObject_invalid_noDerive() {
+ public void test_from_DateTimeAccessor_invalid_noDerive() {
OffsetDate.from(LocalTime.of(12, 30));
}
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
- public void test_factory_CalendricalObject_null() {
+ public void test_from_DateTimeAccessor_null() {
OffsetDate.from((DateTimeAccessor) null);
}
@@ -483,25 +460,14 @@ public void test_get_OffsetDate(int y, int m, int d, ZoneOffset offset) {
LocalDate localDate = LocalDate.of(y, m, d);
OffsetDate a = OffsetDate.of(localDate, offset);
+ assertEquals(a.getDate(), localDate);
+ assertEquals(a.getOffset(), offset);
+ assertEquals(a.toString(), localDate.toString() + offset.toString());
assertEquals(a.getYear(), localDate.getYear());
assertEquals(a.getMonth(), localDate.getMonth());
assertEquals(a.getDayOfMonth(), localDate.getDayOfMonth());
assertEquals(a.getDayOfYear(), localDate.getDayOfYear());
assertEquals(a.getDayOfWeek(), localDate.getDayOfWeek());
-
- assertEquals(a.toString(), localDate.toString() + offset.toString());
- assertEquals(a.getOffset(), offset);
- }
-
- @Test(dataProvider="sampleDates", groups={"tck"})
- public void test_getDOY(int y, int m, int d, ZoneOffset offset) {
- OffsetDate a = OffsetDate.of(y, m, d, offset);
- int total = 0;
- for (int i = 1; i < m; i++) {
- total += Month.of(i).length(isIsoLeap(y));
- }
- int doy = total + d;
- assertEquals(a.getDayOfYear(), doy);
}
//-----------------------------------------------------------------------
@@ -547,11 +513,27 @@ public void test_query_null() {
TEST_2007_07_15_PONE.query(null);
}
- //-------------------------------------------------------------------------
+ //-----------------------------------------------------------------------
+ // withOffset()
+ //-----------------------------------------------------------------------
+ @Test(groups={"tck"})
+ public void test_withOffset() {
+ OffsetDate base = OffsetDate.of(2008, 6, 30, OFFSET_PONE);
+ OffsetDate test = base.withOffset(OFFSET_PTWO);
+ assertEquals(test.getDate(), base.getDate());
+ assertEquals(test.getOffset(), OFFSET_PTWO);
+ }
+
+ @Test(groups={"tck"})
+ public void test_withOffset_noChange() {
+ OffsetDate base = OffsetDate.of(2008, 6, 30, OFFSET_PONE);
+ OffsetDate test = base.withOffset(OFFSET_PONE);
+ assertEquals(test, base);
+ }
+
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
public void test_withOffset_null() {
- OffsetDate base = OffsetDate.of(2008, 6, 30, OFFSET_PONE);
- base.withOffset(null);
+ TEST_2007_07_15_PONE.withOffset(null);
}
//-----------------------------------------------------------------------
@@ -593,6 +575,21 @@ public void test_with_adjustment_Month() {
assertEquals(test, OffsetDate.of(2007, 12, 15, OFFSET_PONE));
}
+ @Test(groups={"tck"})
+ public void test_with_adjustment_offsetUnchanged() {
+ OffsetDate base = OffsetDate.of(2008, 6, 30, OFFSET_PONE);
+ OffsetDate test = base.with(Year.of(2008));
+ assertEquals(test, base);
+ }
+
+ @Test(groups={"tck"})
+ public void test_with_adjustment_noChange() {
+ LocalDate date = LocalDate.of(2008, 6, 30);
+ OffsetDate base = OffsetDate.of(date, OFFSET_PONE);
+ OffsetDate test = base.with(date);
+ assertEquals(test, base);
+ }
+
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
public void test_with_adjustment_null() {
TEST_2007_07_15_PONE.with((WithAdjuster) null);
@@ -632,6 +629,12 @@ public void test_withYear_int_normal() {
assertEquals(t, OffsetDate.of(2008, 7, 15, OFFSET_PONE));
}
+ @Test(groups={"tck"})
+ public void test_withYear_int_noChange() {
+ OffsetDate t = TEST_2007_07_15_PONE.withYear(2007);
+ assertEquals(t, TEST_2007_07_15_PONE);
+ }
+
@Test(expectedExceptions=DateTimeException.class, groups={"tck"})
public void test_withYear_int_invalid() {
TEST_2007_07_15_PONE.withYear(Year.MIN_YEAR - 1);
@@ -653,6 +656,12 @@ public void test_withMonth_int_normal() {
assertEquals(t, OffsetDate.of(2007, 1, 15, OFFSET_PONE));
}
+ @Test(groups={"tck"})
+ public void test_withMonth_int_noChange() {
+ OffsetDate t = TEST_2007_07_15_PONE.withMonth(7);
+ assertEquals(t, TEST_2007_07_15_PONE);
+ }
+
@Test(expectedExceptions=DateTimeException.class, groups={"tck"})
public void test_withMonth_int_invalid() {
TEST_2007_07_15_PONE.withMonth(13);
@@ -699,6 +708,12 @@ public void test_withDayOfYear_normal() {
assertEquals(t, OffsetDate.of(2007, 2, 2, OFFSET_PONE));
}
+ @Test(groups={"tck"})
+ public void test_withDayOfYear_noChange() {
+ OffsetDate t = TEST_2007_07_15_PONE.withDayOfYear(31 + 28 + 31 + 30 + 31 + 30 + 15);
+ assertEquals(t, TEST_2007_07_15_PONE);
+ }
+
@Test(expectedExceptions=DateTimeException.class, groups={"tck"})
public void test_withDayOfYear_illegal() {
TEST_2007_07_15_PONE.withDayOfYear(367);
@@ -710,15 +725,33 @@ public void test_withDayOfYear_invalid() {
}
//-----------------------------------------------------------------------
- // plus(Period)
+ // plus(PlusAdjuster)
//-----------------------------------------------------------------------
@Test(groups={"tck"})
- public void test_plus_Period() {
+ public void test_plus_PlusAdjuster() {
MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
OffsetDate t = TEST_2007_07_15_PONE.plus(period);
assertEquals(t, OffsetDate.of(2008, 2, 15, OFFSET_PONE));
}
+ @Test(groups={"tck"})
+ public void test_plus_PlusAdjuster_noChange() {
+ MockSimplePeriod period = MockSimplePeriod.of(0, ChronoUnit.MONTHS);
+ OffsetDate t = TEST_2007_07_15_PONE.plus(period);
+ assertEquals(t, TEST_2007_07_15_PONE);
+ }
+
+ @Test(groups={"tck"})
+ public void test_plus_PlusAdjuster_zero() {
+ OffsetDate t = TEST_2007_07_15_PONE.plus(Period.ZERO);
+ assertEquals(t, TEST_2007_07_15_PONE);
+ }
+
+ @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
+ public void test_plus_PlusAdjuster_null() {
+ TEST_2007_07_15_PONE.plus((PlusAdjuster) null);
+ }
+
//-----------------------------------------------------------------------
// plusYears()
//-----------------------------------------------------------------------
@@ -735,6 +768,12 @@ public void test_plusYears_long_negative() {
}
@Test(groups={"tck"})
+ public void test_plusYears_long_noChange() {
+ OffsetDate t = TEST_2007_07_15_PONE.plusYears(0);
+ assertEquals(t, TEST_2007_07_15_PONE);
+ }
+
+ @Test(groups={"tck"})
public void test_plusYears_long_adjustDay() {
OffsetDate t = OffsetDate.of(2008, 2, 29, OFFSET_PONE).plusYears(1);
OffsetDate expected = OffsetDate.of(2009, 2, 28, OFFSET_PONE);
@@ -804,6 +843,12 @@ public void test_plusMonths_long_negativeOverYears() {
}
@Test(groups={"tck"})
+ public void test_plusMonths_long_noChange() {
+ OffsetDate t = TEST_2007_07_15_PONE.plusMonths(0);
+ assertEquals(t, TEST_2007_07_15_PONE);
+ }
+
+ @Test(groups={"tck"})
public void test_plusMonths_long_adjustDayFromLeapYear() {
OffsetDate t = OffsetDate.of(2008, 2, 29, OFFSET_PONE).plusMonths(12);
OffsetDate expected = OffsetDate.of(2009, 2, 28, OFFSET_PONE);
@@ -935,6 +980,12 @@ public void test_plusWeeks_negativeOverYears() {
}
@Test(groups={"tck"})
+ public void test_plusWeeks_noChange() {
+ OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(0);
+ assertEquals(t, TEST_2007_07_15_PONE);
+ }
+
+ @Test(groups={"tck"})
public void test_plusWeeks_maximum() {
OffsetDate t = OffsetDate.of(Year.MAX_YEAR, 12, 24, OFFSET_PONE).plusWeeks(1);
OffsetDate expected = OffsetDate.of(Year.MAX_YEAR, 12, 31, OFFSET_PONE);
@@ -1057,6 +1108,12 @@ public void test_plusDays_negativeOverYears() {
}
@Test(groups={"tck"})
+ public void test_plusDays_noChange() {
+ OffsetDate t = TEST_2007_07_15_PONE.plusDays(0);
+ assertEquals(t, TEST_2007_07_15_PONE);
+ }
+
+ @Test(groups={"tck"})
public void test_plusDays_maximum() {
OffsetDate t = OffsetDate.of(Year.MAX_YEAR, 12, 30, OFFSET_PONE).plusDays(1);
OffsetDate expected = OffsetDate.of(Year.MAX_YEAR, 12, 31, OFFSET_PONE);
@@ -1091,15 +1148,33 @@ public void test_plusDays_overflowTooSmall() {
}
//-----------------------------------------------------------------------
- // minus(Period)
+ // minus(MinusAdjuster)
//-----------------------------------------------------------------------
@Test(groups={"tck"})
- public void test_minus_PeriodProvider() {
+ public void test_minus_MinusAdjuster() {
MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS);
OffsetDate t = TEST_2007_07_15_PONE.minus(period);
assertEquals(t, OffsetDate.of(2006, 12, 15, OFFSET_PONE));
}
+ @Test(groups={"tck"})
+ public void test_minus_MinusAdjuster_noChange() {
+ MockSimplePeriod period = MockSimplePeriod.of(0, ChronoUnit.MONTHS);
+ OffsetDate t = TEST_2007_07_15_PONE.minus(period);
+ assertEquals(t, TEST_2007_07_15_PONE);
+ }
+
+ @Test(groups={"tck"})
+ public void test_minus_MinusAdjuster_zero() {
+ OffsetDate t = TEST_2007_07_15_PONE.minus(Period.ZERO);
+ assertEquals(t, TEST_2007_07_15_PONE);
+ }
+
+ @Test(expectedExceptions=NullPointerException.class, groups={"tck"})
+ public void test_plus_MinusAdjuster_null() {
+ TEST_2007_07_15_PONE.minus((MinusAdjuster) null);
+ }
+
//-----------------------------------------------------------------------
// minusYears()
//-----------------------------------------------------------------------
@@ -1116,6 +1191,12 @@ public void test_minusYears_long_negative() {
}
@Test(groups={"tck"})
+ public void test_minusYears_long_noChange() {
+ OffsetDate t = TEST_2007_07_15_PONE.minusYears(0);
+ assertEquals(t, TEST_2007_07_15_PONE);
+ }
+
+ @Test(groups={"tck"})
public void test_minusYears_long_adjustDay() {
OffsetDate t = OffsetDate.of(2008, 2, 29, OFFSET_PONE).minusYears(1);
OffsetDate expected = OffsetDate.of(2007, 2, 28, OFFSET_PONE);
@@ -1185,6 +1266,12 @@ public void test_minusMonths_long_negativeOverYears() {
}
@Test(groups={"tck"})
+ public void test_minusMonths_long_noChange() {
+ OffsetDate t = TEST_2007_07_15_PONE.minusMonths(0);
+ assertEquals(t, TEST_2007_07_15_PONE);
+ }
+
+ @Test(groups={"tck"})
public void test_minusMonths_long_adjustDayFromLeapYear() {
OffsetDate t = OffsetDate.of(2008, 2, 29, OFFSET_PONE).minusMonths(12);
OffsetDate expected = OffsetDate.of(2007, 2, 28, OFFSET_PONE);
@@ -1316,6 +1403,12 @@ public void test_minusWeeks_negativeOverYears() {
}
@Test(groups={"tck"})
+ public void test_minusWeeks_noChange() {
+ OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(0);
+ assertEquals(t, TEST_2007_07_15_PONE);
+ }
+
+ @Test(groups={"tck"})
public void test_minusWeeks_maximum() {
OffsetDate t = OffsetDate.of(Year.MAX_YEAR, 12, 24, OFFSET_PONE).minusWeeks(-1);
OffsetDate expected = OffsetDate.of(Year.MAX_YEAR, 12, 31, OFFSET_PONE);
@@ -1438,6 +1531,12 @@ public void test_minusDays_negativeOverYears() {
}
@Test(groups={"tck"})
+ public void test_minusDays_noChange() {
+ OffsetDate t = TEST_2007_07_15_PONE.minusDays(0);
+ assertEquals(t, TEST_2007_07_15_PONE);
+ }
+
+ @Test(groups={"tck"})
public void test_minusDays_maximum() {
OffsetDate t = OffsetDate.of(Year.MAX_YEAR, 12, 30, OFFSET_PONE).minusDays(-1);
OffsetDate expected = OffsetDate.of(Year.MAX_YEAR, 12, 31, OFFSET_PONE);
@@ -1682,7 +1781,7 @@ public void test_compareTo_date() {
assertEquals(b.compareTo(a) > 0, true);
assertEquals(a.compareTo(a) == 0, true);
assertEquals(b.compareTo(b) == 0, true);
- assertEquals(a.atTime(0, 0).toInstant().compareTo(b.atTime(0, 0).toInstant()) < 0, true);
+ assertEquals(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0, true);
}
@Test(groups={"tck"})
@@ -1693,7 +1792,7 @@ public void test_compareTo_offset() {
assertEquals(b.compareTo(a) > 0, true);
assertEquals(a.compareTo(a) == 0, true);
assertEquals(b.compareTo(b) == 0, true);
- assertEquals(a.atTime(0, 0).toInstant().compareTo(b.atTime(0, 0).toInstant()) < 0, true);
+ assertEquals(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0, true);
}
@Test(groups={"tck"})
@@ -1704,7 +1803,7 @@ public void test_compareTo_both() {
assertEquals(b.compareTo(a) > 0, true);
assertEquals(a.compareTo(a) == 0, true);
assertEquals(b.compareTo(b) == 0, true);
- assertEquals(a.atTime(0, 0).toInstant().compareTo(b.atTime(0, 0).toInstant()) < 0, true);
+ assertEquals(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0, true);
}
@Test(groups={"tck"})
@@ -1715,7 +1814,7 @@ public void test_compareTo_24hourDifference() {
assertEquals(b.compareTo(a) > 0, true);
assertEquals(a.compareTo(a) == 0, true);
assertEquals(b.compareTo(b) == 0, true);
- assertEquals(a.atTime(0, 0).toInstant().compareTo(b.atTime(0, 0).toInstant()) == 0, true);
+ assertEquals(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) == 0, true);
}
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
View
181 src/tck/java/javax/time/TCKOffsetTime.java
@@ -47,6 +47,7 @@
import static javax.time.calendrical.ChronoField.OFFSET_SECONDS;
import static javax.time.calendrical.ChronoField.SECOND_OF_DAY;
import static javax.time.calendrical.ChronoField.SECOND_OF_MINUTE;
+import static javax.time.calendrical.ChronoUnit.SECONDS;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
@@ -67,6 +68,8 @@
import javax.time.calendrical.ChronoField;
import javax.time.calendrical.ChronoUnit;
import javax.time.calendrical.DateTime;
+import javax.time.calendrical.DateTime.MinusAdjuster;
+import javax.time.calendrical.DateTime.PlusAdjuster;
import javax.time.calendrical.DateTime.WithAdjuster;
import javax.time.calendrical.DateTimeAccessor;
import javax.time.calendrical.DateTimeField;
@@ -351,21 +354,26 @@ public void factory_ofInstant_minYear() {
}
//-----------------------------------------------------------------------
- // from()
+ // from(DateTimeAccessor)
//-----------------------------------------------------------------------
@Test(groups={"tck"})
- public void test_factory_CalendricalObject() {
+ public void factory_from_DateTimeAccessor_OT() {
assertEquals(OffsetTime.from(OffsetTime.of(17, 30, OFFSET_PONE)), OffsetTime.of(17, 30, OFFSET_PONE));
- assertEquals(OffsetTime.from(OffsetDateTime.of(2007, 7, 15, 17, 30, OFFSET_PONE)), OffsetTime.of(17, 30, OFFSET_PONE));
+ }
+
+ @Test(groups={"tck"})
+ public void test_from_DateTimeAccessor_ZDT() {
+ ZonedDateTime base = ZonedDateTime.of(2007, 7, 15, 11, 30, 59, 500, ZoneId.of(OFFSET_PONE));
+ assertEquals(OffsetTime.from(base), TEST_11_30_59_500_PONE);
}
@Test(expectedExceptions=DateTimeException.class, groups={"tck"})
- public void test_factory_CalendricalObject_invalid_noDerive() {
+ public void factory_from_DateTimeAccessor_invalid_noDerive() {
OffsetTime.from(LocalDate.of(2007, 7, 15));
}
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
- public void test_factory_CalendricalObject_null() {
+ public void factory_from_DateTimeAccessor_null() {
OffsetTime.from((DateTimeAccessor) null);
}
@@ -534,6 +542,24 @@ public void test_query_null() {
TEST_11_30_59_500_PONE.query(null);
}
+ //-----------------------------------------------------------------------
+ // withOffsetSameLocal()
+ //-----------------------------------------------------------------------
+ @Test(groups={"tck"})
+ public void test_withOffsetSameLocal() {
+ OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
+ OffsetTime test = base.withOffsetSameLocal(OFFSET_PTWO);
+ assertEquals(test.getTime(), base.getTime());
+ assertEquals(test.getOffset(), OFFSET_PTWO);
+ }
+
+ @Test(groups={"tck"})
+ public void test_withOffsetSameLocal_noChange() {
+ OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
+ OffsetTime test = base.withOffsetSameLocal(OFFSET_PONE);
+ assertEquals(test, base);
+ }
+
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
public void test_withOffsetSameLocal_null() {
OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
@@ -551,6 +577,13 @@ public void test_withOffsetSameInstant() {
assertEquals(test, expected);
}
+ @Test(groups={"tck"})
+ public void test_withOffsetSameInstant_noChange() {
+ OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
+ OffsetTime test = base.withOffsetSameInstant(OFFSET_PONE);
+ assertEquals(test, base);
+ }
+
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
public void test_withOffsetSameInstant_null() {
OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
@@ -642,6 +675,13 @@ public void test_withHour_normal() {
assertEquals(test, OffsetTime.of(15, 30, 59, OFFSET_PONE));
}
+ @Test(groups={"tck"})
+ public void test_withHour_noChange() {
+ OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
+ OffsetTime test = base.withHour(11);
+ assertEquals(test, base);
+ }
+
//-----------------------------------------------------------------------
// withMinute()
//-----------------------------------------------------------------------
@@ -652,6 +692,13 @@ public void test_withMinute_normal() {
assertEquals(test, OffsetTime.of(11, 15, 59, OFFSET_PONE));
}
+ @Test(groups={"tck"})
+ public void test_withMinute_noChange() {
+ OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
+ OffsetTime test = base.withMinute(30);
+ assertEquals(test, base);
+ }
+
//-----------------------------------------------------------------------
// withSecond()
//-----------------------------------------------------------------------
@@ -662,6 +709,13 @@ public void test_withSecond_normal() {
assertEquals(test, OffsetTime.of(11, 30, 15, OFFSET_PONE));
}
+ @Test(groups={"tck"})
+ public void test_withSecond_noChange() {
+ OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
+ OffsetTime test = base.withSecond(59);
+ assertEquals(test, base);
+ }
+
//-----------------------------------------------------------------------
// withNano()
//-----------------------------------------------------------------------
@@ -672,19 +726,38 @@ public void test_withNanoOfSecond_normal() {
assertEquals(test, OffsetTime.of(11, 30, 59, 15, OFFSET_PONE));
}
+ @Test(groups={"tck"})
+ public void test_withNanoOfSecond_noChange() {
+ OffsetTime base = OffsetTime.of(11, 30, 59, 1, OFFSET_PONE);
+ OffsetTime test = base.withNano(1);
+ assertEquals(test, base);
+ }
+
//-----------------------------------------------------------------------
- // plus(Period)
+ // plus(PlusAdjuster)
//-----------------------------------------------------------------------
@Test(groups={"tck"})
- public void test_plus_Period() {
+ public void test_plus_PlusAdjuster() {
MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MINUTES);
OffsetTime t = TEST_11_30_59_500_PONE.plus(period);
assertEquals(t, OffsetTime.of(11, 37, 59, 500, OFFSET_PONE));
}
+ @Test(groups={"tck"})
+ public void test_plus_PlusAdjuster_noChange() {
+ OffsetTime t = TEST_11_30_59_500_PONE.plus(MockSimplePeriod.of(0, SECONDS));
+ assertEquals(t, TEST_11_30_59_500_PONE);
+ }
+
+ @Test(groups={"tck"})
+ public void test_plus_PlusAdjuster_zero() {
+ OffsetTime t = TEST_11_30_59_500_PONE.plus(Period.ZERO);
+ assertEquals(t, TEST_11_30_59_500_PONE);
+ }
+
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
- public void test_plus_Period_null() {
- TEST_11_30_59_500_PONE.plus((MockSimplePeriod) null);
+ public void test_plus_PlusAdjuster_null() {
+ TEST_11_30_59_500_PONE.plus((PlusAdjuster) null);
}
//-----------------------------------------------------------------------
@@ -697,6 +770,13 @@ public void test_plusHours() {
assertEquals(test, OffsetTime.of(0, 30, 59, OFFSET_PONE));
}
+ @Test(groups={"tck"})
+ public void test_plusHours_zero() {
+ OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
+ OffsetTime test = base.plusHours(0);
+ assertEquals(test, base);
+ }
+
//-----------------------------------------------------------------------
// plusMinutes()
//-----------------------------------------------------------------------
@@ -707,6 +787,13 @@ public void test_plusMinutes() {
assertEquals(test, OffsetTime.of(12, 0, 59, OFFSET_PONE));
}
+ @Test(groups={"tck"})
+ public void test_plusMinutes_zero() {
+ OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
+ OffsetTime test = base.plusMinutes(0);
+ assertEquals(test, base);
+ }
+
//-----------------------------------------------------------------------
// plusSeconds()
//-----------------------------------------------------------------------
@@ -717,6 +804,13 @@ public void test_plusSeconds() {
assertEquals(test, OffsetTime.of(11, 31, 0, OFFSET_PONE));
}
+ @Test(groups={"tck"})
+ public void test_plusSeconds_zero() {
+ OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
+ OffsetTime test = base.plusSeconds(0);
+ assertEquals(test, base);
+ }
+
//-----------------------------------------------------------------------
// plusNanos()
//-----------------------------------------------------------------------
@@ -727,19 +821,38 @@ public void test_plusNanos() {
assertEquals(test, OffsetTime.of(11, 30, 59, 1, OFFSET_PONE));
}
+ @Test(groups={"tck"})
+ public void test_plusNanos_zero() {
+ OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
+ OffsetTime test = base.plusNanos(0);
+ assertEquals(test, base);
+ }
+
//-----------------------------------------------------------------------
- // minus(Period)
+ // minus(MinusAdjuster)
//-----------------------------------------------------------------------
@Test(groups={"tck"})
- public void test_minus_Period() {
+ public void test_minus_MinusAdjuster() {
MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MINUTES);
OffsetTime t = TEST_11_30_59_500_PONE.minus(period);
assertEquals(t, OffsetTime.of(11, 23, 59, 500, OFFSET_PONE));
}
+ @Test(groups={"tck"})
+ public void test_minus_MinusAdjuster_noChange() {
+ OffsetTime t = TEST_11_30_59_500_PONE.minus(MockSimplePeriod.of(0, SECONDS));
+ assertEquals(t, TEST_11_30_59_500_PONE);
+ }
+
+ @Test(groups={"tck"})
+ public void test_minus_MinusAdjuster_zero() {
+ OffsetTime t = TEST_11_30_59_500_PONE.minus(Period.ZERO);
+ assertEquals(t, TEST_11_30_59_500_PONE);
+ }
+
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
- public void test_minus_Period_null() {
- TEST_11_30_59_500_PONE.minus((MockSimplePeriod) null);
+ public void test_minus_MinusAdjuster_null() {
+ TEST_11_30_59_500_PONE.minus((MinusAdjuster) null);
}
//-----------------------------------------------------------------------
@@ -752,6 +865,13 @@ public void test_minusHours() {
assertEquals(test, OffsetTime.of(0, 30, 59, OFFSET_PONE));
}
+ @Test(groups={"tck"})
+ public void test_minusHours_zero() {
+ OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
+ OffsetTime test = base.minusHours(0);
+ assertEquals(test, base);
+ }
+
//-----------------------------------------------------------------------
// minusMinutes()
//-----------------------------------------------------------------------
@@ -762,6 +882,13 @@ public void test_minusMinutes() {
assertEquals(test, OffsetTime.of(10, 40, 59, OFFSET_PONE));
}
+ @Test(groups={"tck"})
+ public void test_minusMinutes_zero() {
+ OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
+ OffsetTime test = base.minusMinutes(0);
+ assertEquals(test, base);
+ }
+
//-----------------------------------------------------------------------
// minusSeconds()
//-----------------------------------------------------------------------
@@ -772,6 +899,13 @@ public void test_minusSeconds() {
assertEquals(test, OffsetTime.of(11, 29, 59, OFFSET_PONE));
}
+ @Test(groups={"tck"})
+ public void test_minusSeconds_zero() {
+ OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
+ OffsetTime test = base.minusSeconds(0);
+ assertEquals(test, base);
+ }
+
//-----------------------------------------------------------------------
// minusNanos()
//-----------------------------------------------------------------------
@@ -782,6 +916,13 @@ public void test_minusNanos() {
assertEquals(test, OffsetTime.of(11, 30, 58, 999999999, OFFSET_PONE));
}
+ @Test(groups={"tck"})
+ public void test_minusNanos_zero() {
+ OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
+ OffsetTime test = base.minusNanos(0);
+ assertEquals(test, base);
+ }
+
//-----------------------------------------------------------------------
// compareTo()
//-----------------------------------------------------------------------
@@ -793,7 +934,7 @@ public void test_compareTo_time() {
assertEquals(b.compareTo(a) > 0, true);
assertEquals(a.compareTo(a) == 0, true);
assertEquals(b.compareTo(b) == 0, true);
- assertEquals(DATE.atTime(a).toInstant().compareTo(DATE.atTime(b).toInstant()) < 0, true);
+ assertEquals(convertInstant(a).compareTo(convertInstant(b)) < 0, true);
}
@Test(groups={"tck"})
@@ -804,7 +945,7 @@ public void test_compareTo_offset() {
assertEquals(b.compareTo(a) > 0, true);
assertEquals(a.compareTo(a) == 0, true);
assertEquals(b.compareTo(b) == 0, true);
- assertEquals(DATE.atTime(a).toInstant().compareTo(DATE.atTime(b).toInstant()) < 0, true);
+ assertEquals(convertInstant(a).compareTo(convertInstant(b)) < 0, true);
}
@Test(groups={"tck"})
@@ -815,7 +956,7 @@ public void test_compareTo_both() {
assertEquals(b.compareTo(a) > 0, true);
assertEquals(a.compareTo(a) == 0, true);
assertEquals(b.compareTo(b) == 0, true);
- assertEquals(DATE.atTime(a).toInstant().compareTo(DATE.atTime(b).toInstant()) < 0, true);
+ assertEquals(convertInstant(a).compareTo(convertInstant(b)) < 0, true);
}
@Test(groups={"tck"})
@@ -826,7 +967,7 @@ public void test_compareTo_bothNearStartOfDay() {
assertEquals(b.compareTo(a) > 0, true);
assertEquals(a.compareTo(a) == 0, true);
assertEquals(b.compareTo(b) == 0, true);
- assertEquals(DATE.atTime(a).toInstant().compareTo(DATE.atTime(b).toInstant()) < 0, true);
+ assertEquals(convertInstant(a).compareTo(convertInstant(b)) < 0, true);
}
@Test(groups={"tck"})
@@ -837,7 +978,7 @@ public void test_compareTo_hourDifference() {
assertEquals(b.compareTo(a) > 0, true);
assertEquals(a.compareTo(a) == 0, true);
assertEquals(b.compareTo(b) == 0, true);
- assertEquals(DATE.atTime(a).toInstant().compareTo(DATE.atTime(b).toInstant()) == 0, true);
+ assertEquals(convertInstant(a).compareTo(convertInstant(b)) == 0, true);
}
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
@@ -853,6 +994,10 @@ public void compareToNonOffsetTime() {
c.compareTo(new Object());
}
+ private Instant convertInstant(OffsetTime ot) {
+ return DATE.atTime(ot.getTime()).toInstant(ot.getOffset());
+ }
+
//-----------------------------------------------------------------------
// isAfter() / isBefore() / isEqual()
//-----------------------------------------------------------------------
View
310 src/test/java/javax/time/TestOffsetDate.java
@@ -1,310 +0,0 @@
-/*
-9 * Copyright (c) 2007-2012, Stephen Colebourne & Michael Nascimento Santos
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * * Neither the name of JSR-310 nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package javax.time;
-
-import static javax.time.calendrical.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH;
-import static javax.time.calendrical.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR;
-import static javax.time.calendrical.ChronoField.ALIGNED_WEEK_OF_MONTH;
-import static javax.time.calendrical.ChronoField.ALIGNED_WEEK_OF_YEAR;
-import static javax.time.calendrical.ChronoField.DAY_OF_MONTH;
-import static javax.time.calendrical.ChronoField.DAY_OF_WEEK;
-import static javax.time.calendrical.ChronoField.DAY_OF_YEAR;
-import static javax.time.calendrical.ChronoField.EPOCH_DAY;
-import static javax.time.calendrical.ChronoField.EPOCH_MONTH;
-import static javax.time.calendrical.ChronoField.ERA;
-import static javax.time.calendrical.ChronoField.MONTH_OF_YEAR;
-import static javax.time.calendrical.ChronoField.OFFSET_SECONDS;
-import static javax.time.calendrical.ChronoField.WEEK_OF_MONTH;
-import static javax.time.calendrical.ChronoField.WEEK_OF_YEAR;
-import static javax.time.calendrical.ChronoField.YEAR;
-import static javax.time.calendrical.ChronoField.YEAR_OF_ERA;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertSame;
-import static org.testng.Assert.assertTrue;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import javax.time.calendrical.ChronoField;
-import javax.time.calendrical.DateTimeAccessor;
-import javax.time.calendrical.DateTimeField;
-import javax.time.calendrical.JulianDayField;
-
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-
-/**
- * Test OffsetDate.
- */
-@Test
-public class TestOffsetDate extends AbstractDateTimeTest {
-
- private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1);
- private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2);
-
- private OffsetDate TEST_2007_07_15_PONE;
-
- @BeforeMethod(groups={"tck","implementation"})
- public void setUp() {
- TEST_2007_07_15_PONE = OffsetDate.of(2007, 7, 15, OFFSET_PONE);
- }
-
- //-----------------------------------------------------------------------
- @Override
- protected List<DateTimeAccessor> samples() {
- DateTimeAccessor[] array = {TEST_2007_07_15_PONE, };
- return Arrays.asList(array);
- }
-
- @Override
- protected List<DateTimeField> validFields() {
- DateTimeField[] array = {
- DAY_OF_WEEK,
- ALIGNED_DAY_OF_WEEK_IN_MONTH,
- ALIGNED_DAY_OF_WEEK_IN_YEAR,
- DAY_OF_MONTH,
- DAY_OF_YEAR,
- EPOCH_DAY,
- ALIGNED_WEEK_OF_MONTH,
- WEEK_OF_MONTH,
- ALIGNED_WEEK_OF_YEAR,
- WEEK_OF_YEAR,
- MONTH_OF_YEAR,
- EPOCH_MONTH,
- YEAR_OF_ERA,
- YEAR,
- ERA,
- OFFSET_SECONDS,
- JulianDayField.JULIAN_DAY,
- JulianDayField.MODIFIED_JULIAN_DAY,
- JulianDayField.RATA_DIE,
- };
- return Arrays.asList(array);
- }
-
- //-----------------------------------------------------------------------
- @Test(groups={"tck"})
- public void test_serialization_format() throws ClassNotFoundException, IOException {
- assertEqualsSerialisedForm(OffsetDate.of(2012, 9, 16, ZoneOffset.of("+01:00")));
- }
-
- @Test(groups={"tck"})
- public void test_serialization() throws ClassNotFoundException, IOException {
- assertSerializable(TEST_2007_07_15_PONE);
- }
-
- @Override
- protected List<DateTimeField> invalidFields() {
- List<DateTimeField> list = new ArrayList<>(Arrays.<DateTimeField>asList(ChronoField.values()));
- list.removeAll(validFields());
- return list;
- }
-
- //-----------------------------------------------------------------------
- @Test(groups={"implementation"})
- public void test_interfaces() {
- Object obj = TEST_2007_07_15_PONE;
- assertTrue(obj instanceof DateTimeAccessor);
- assertTrue(obj instanceof Serializable);
- assertTrue(obj instanceof Comparable<?>);
- }
-
- //-----------------------------------------------------------------------
- // factories
- //-----------------------------------------------------------------------
- void check(OffsetDate test, int y, int mo, int d, ZoneOffset offset) {
- assertEquals(test.getYear(), y);
- assertEquals(test.getMonth().getValue(), mo);
- assertEquals(test.getDayOfMonth(), d);
- assertEquals(test.getOffset(), offset);
- }
-
- //-----------------------------------------------------------------------
- // basics
- //-----------------------------------------------------------------------
- @DataProvider(name="sampleDates")
- Object[][] provider_sampleDates() {
- return new Object[][] {
- {2008, 7, 5, OFFSET_PTWO},
- {2007, 7, 5, OFFSET_PONE},
- {2006, 7, 5, OFFSET_PTWO},
- {2005, 7, 5, OFFSET_PONE},
- {2004, 1, 1, OFFSET_PTWO},
- {-1, 1, 2, OFFSET_PONE},
- {999999, 11, 20, ZoneOffset.ofHoursMinutesSeconds(6, 9, 12)},
- };
- }
-
- @Test(dataProvider="sampleDates", groups={"implementation"})
- public void test_get_Offset_LocalDate(int y, int m, int d, ZoneOffset offset) {
- LocalDate localDate = LocalDate.of(y, m, d);
- OffsetDate a = OffsetDate.of(localDate, offset);
-
- assertSame(a.getOffset(), offset);
- assertSame(a.getDate(), localDate);
- }
-
-
- //-----------------------------------------------------------------------
- // getDayOfWeek()
- //-----------------------------------------------------------------------
- @Test(groups={"implementation"})
- public void test_getDayOfWeek() {
- DayOfWeek dow = DayOfWeek.MONDAY;
- ZoneOffset[] offsets = new ZoneOffset[] {OFFSET_PONE, OFFSET_PTWO};
-
- for (Month month : Month.values()) {
- int length = month.length(false);
- for (int i = 1; i <= length; i++) {
- OffsetDate d = OffsetDate.of(2007, month, i, offsets[i % 2]);
- assertSame(d.getDayOfWeek(), dow);
- dow = dow.plus(1);
- }
- }
- }
-
- //-----------------------------------------------------------------------
- // withOffset()
- //-----------------------------------------------------------------------
- @Test(groups={"implementation"})
- public void test_withOffset() {
- OffsetDate base = OffsetDate.of(2008, 6, 30, OFFSET_PONE);
- OffsetDate test = base.withOffset(OFFSET_PTWO);
- assertSame(test.getDate(), base.getDate());
- assertSame(test.getOffset(), OFFSET_PTWO);
- }
-
- @Test(groups={"implementation"})
- public void test_withOffset_noChange() {
- OffsetDate base = OffsetDate.of(2008, 6, 30, OFFSET_PONE);
- OffsetDate test = base.withOffset(OFFSET_PONE);
- assertSame(test, base);
- }
-
- @Test(groups={"implementation"})
- public void test_with_adjustment_offsetUnchanged() {
- OffsetDate base = OffsetDate.of(2008, 6, 30, OFFSET_PONE);
- OffsetDate test = base.with(Year.of(2007));
- assertSame(test.getOffset(), base.getOffset());
- }
-
- @Test(groups={"implementation"})
- public void test_with_adjustment_noChange() {
- LocalDate date = LocalDate.of(2008, 6, 30);
- OffsetDate base = OffsetDate.of(date, OFFSET_PONE);
- OffsetDate test = base.with(date);
- assertSame(test, base);
- }
-
- @Test(groups={"implementation"})
- public void test_withYear_int_noChange() {
- OffsetDate t = TEST_2007_07_15_PONE.withYear(2007);
- assertSame(t, TEST_2007_07_15_PONE);
- }
-
- @Test(groups={"implementation"})
- public void test_withMonth_int_noChange() {
- OffsetDate t = TEST_2007_07_15_PONE.withMonth(7);
- assertSame(t, TEST_2007_07_15_PONE);
- }
-
- @Test(groups={"implementation"})
- public void test_withDayOfYear_noChange() {
- OffsetDate t = TEST_2007_07_15_PONE.withDayOfYear(31 + 28 + 31 + 30 + 31 + 30 + 15);
- assertSame(t, TEST_2007_07_15_PONE);
- }
-
- @Test(groups={"implementation"})
- public void test_plus_Period_zero() {
- OffsetDate t = TEST_2007_07_15_PONE.plus(MockSimplePeriod.ZERO_DAYS);
- assertSame(t, TEST_2007_07_15_PONE);
- }
-
- @Test(groups={"implementation"})
- public void test_plusYears_long_noChange() {
- OffsetDate t = TEST_2007_07_15_PONE.plusYears(0);
- assertSame(t, TEST_2007_07_15_PONE);
- }
-
- @Test(groups={"implementation"})
- public void test_plusMonths_long_noChange() {
- OffsetDate t = TEST_2007_07_15_PONE.plusMonths(0);
- assertSame(t, TEST_2007_07_15_PONE);
- }
-
- @Test(groups={"implementation"})
- public void test_plusWeeks_noChange() {
- OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(0);
- assertSame(t, TEST_2007_07_15_PONE);
- }
-
- @Test(groups={"implementation"})
- public void test_plusDays_noChange() {
- OffsetDate t = TEST_2007_07_15_PONE.plusDays(0);
- assertSame(t, TEST_2007_07_15_PONE);
- }
-
- @Test(groups={"implementation"})
- public void test_minus_PeriodProvider_zero() {
- OffsetDate t = TEST_2007_07_15_PONE.minus(MockSimplePeriod.ZERO_DAYS);
- assertSame(t, TEST_2007_07_15_PONE);
- }
-
- @Test(groups={"implementation"})
- public void test_minusYears_long_noChange() {
- OffsetDate t = TEST_2007_07_15_PONE.minusYears(0);
- assertSame(t, TEST_2007_07_15_PONE);
- }
-
- @Test(groups={"implementation"})
- public void test_minusMonths_long_noChange() {
- OffsetDate t = TEST_2007_07_15_PONE.minusMonths(0);
- assertSame(t, TEST_2007_07_15_PONE);
- }
-
- @Test(groups={"implementation"})
- public void test_minusWeeks_noChange() {
- OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(0);
- assertSame(t, TEST_2007_07_15_PONE);
- }
-
- @Test(groups={"implementation"})
- public void test_minusDays_noChange() {
- OffsetDate t = TEST_2007_07_15_PONE.minusDays(0);
- assertSame(t, TEST_2007_07_15_PONE);
- }
-
-}
View
300 src/test/java/javax/time/TestOffsetTime.java
@@ -1,300 +0,0 @@
-/*
- * Copyright (c) 2008-2012, Stephen Colebourne & Michael Nascimento Santos
- *
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * * Neither the name of JSR-310 nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package javax.time;
-
-import static javax.time.calendrical.ChronoField.AMPM_OF_DAY;
-import static javax.time.calendrical.ChronoField.CLOCK_HOUR_OF_AMPM;
-import static javax.time.calendrical.ChronoField.CLOCK_HOUR_OF_DAY;
-import static javax.time.calendrical.ChronoField.HOUR_OF_AMPM;
-import static javax.time.calendrical.ChronoField.HOUR_OF_DAY;
-import static javax.time.calendrical.ChronoField.MICRO_OF_DAY;
-import static javax.time.calendrical.ChronoField.MICRO_OF_SECOND;
-import static javax.time.calendrical.ChronoField.MILLI_OF_DAY;
-import static javax.time.calendrical.ChronoField.MILLI_OF_SECOND;
-import static javax.time.calendrical.ChronoField.MINUTE_OF_DAY;
-import static javax.time.calendrical.ChronoField.MINUTE_OF_HOUR;
-import static javax.time.calendrical.ChronoField.NANO_OF_DAY;
-import static javax.time.calendrical.ChronoField.NANO_OF_SECOND;
-import static javax.time.calendrical.ChronoField.OFFSET_SECONDS;
-import static javax.time.calendrical.ChronoField.SECOND_OF_DAY;
-import static javax.time.calendrical.ChronoField.SECOND_OF_MINUTE;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertSame;
-import static org.testng.Assert.assertTrue;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import javax.time.calendrical.ChronoField;
-import javax.time.calendrical.DateTimeAccessor;
-import javax.time.calendrical.DateTimeField;
-import javax.time.calendrical.JulianDayField;
-
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-
-/**
- * Test OffsetTime.
- */
-@Test
-public class TestOffsetTime extends AbstractDateTimeTest {
-
- private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1);
- private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2);
- private OffsetTime TEST_11_30_59_500_PONE;
-
- @BeforeMethod(groups={"tck","implementation"})
- public void setUp() {
- TEST_11_30_59_500_PONE = OffsetTime.of(11, 30, 59, 500, OFFSET_PONE);
- }
-
- //-----------------------------------------------------------------------
- @Override
- protected List<DateTimeAccessor> samples() {
- DateTimeAccessor[] array = {TEST_11_30_59_500_PONE, };
- return Arrays.asList(array);
- }
-
- @Override
- protected List<DateTimeField> validFields() {
- DateTimeField[] array = {
- NANO_OF_SECOND,
- NANO_OF_DAY,
- MICRO_OF_SECOND,
- MICRO_OF_DAY,
- MILLI_OF_SECOND,
- MILLI_OF_DAY,
- SECOND_OF_MINUTE,
- SECOND_OF_DAY,
- MINUTE_OF_HOUR,
- MINUTE_OF_DAY,
- CLOCK_HOUR_OF_AMPM,
- HOUR_OF_AMPM,
- CLOCK_HOUR_OF_DAY,
- HOUR_OF_DAY,
- AMPM_OF_DAY,
- OFFSET_SECONDS,
- };
- return Arrays.asList(array);
- }
-
- //-----------------------------------------------------------------------
- @Test(groups={"tck"})
- public void test_serialization() throws IOException, ClassNotFoundException {
- assertSerializable(TEST_11_30_59_500_PONE);
- }
-
- @Test(groups={"tck"})
- public void test_serialization_format() throws ClassNotFoundException, IOException {
- LocalTime time = LocalTime.of(22, 17, 59, 465 * 1000000);
- ZoneOffset offset = ZoneOffset.of("+01:00");
- assertEqualsSerialisedForm(OffsetTime.of(time, offset));
- }
-
- //-----------------------------------------------------------------------
- @Override
- protected List<DateTimeField> invalidFields() {
- List<DateTimeField> list = new ArrayList<>(Arrays.<DateTimeField>asList(ChronoField.values()));
- list.removeAll(validFields());
- list.add(JulianDayField.JULIAN_DAY);
- list.add(JulianDayField.MODIFIED_JULIAN_DAY);
- list.add(JulianDayField.RATA_DIE);
- return list;
- }
-
- //-----------------------------------------------------------------------
- @Test(groups={"implementation"})
- public void test_interfaces() {
- Object obj = TEST_11_30_59_500_PONE;
- assertTrue(obj instanceof DateTimeAccessor);
- assertTrue(obj instanceof Serializable);
- assertTrue(obj instanceof Comparable<?>);
- }
-
- //-----------------------------------------------------------------------
- // factories
- //-----------------------------------------------------------------------
- void check(OffsetTime test, int h, int m, int s, int n, ZoneOffset offset) {
- assertEquals(test.getHour(), h);
- assertEquals(test.getMinute(), m);
- assertEquals(test.getSecond(), s);
- assertEquals(test.getNano(), n);
- assertEquals(test.getOffset(), offset);
- }
-
- //-----------------------------------------------------------------------
- // basics
- //-----------------------------------------------------------------------
- @DataProvider(name="sampleTimes")
- Object[][] provider_sampleTimes() {
- return new Object[][] {
- {11, 30, 20, 500, OFFSET_PONE},
- {11, 0, 0, 0, OFFSET_PONE},
- {23, 59, 59, 999999999, OFFSET_PONE},
- };
- }
-
- @Test(dataProvider="sampleTimes", groups={"implementation"})
- public void test_get_same(int h, int m, int s, int n, ZoneOffset offset) {
- LocalTime localTime = LocalTime.of(h, m, s, n);
- OffsetTime a = OffsetTime.of(localTime, offset);
-
- assertSame(a.getOffset(), offset);
- assertSame(a.getTime(), localTime);
- }
-
- //-----------------------------------------------------------------------
- // withOffsetSameLocal()
- //-----------------------------------------------------------------------
- @Test(groups={"implementation"})
- public void test_withOffsetSameLocal() {
- OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
- OffsetTime test = base.withOffsetSameLocal(OFFSET_PTWO);
- assertSame(test.getTime(), base.getTime());
- assertSame(test.getOffset(), OFFSET_PTWO);
- }
-
- @Test(groups={"implementation"})
- public void test_withOffsetSameLocal_noChange() {
- OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
- OffsetTime test = base.withOffsetSameLocal(OFFSET_PONE);
- assertSame(test, base);
- }
-
- @Test(groups={"implementation"})
- public void test_withOffsetSameInstant_noChange() {
- OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
- OffsetTime test = base.withOffsetSameInstant(OFFSET_PONE);
- assertSame(test, base);
- }
-
- @Test(groups={"implementation"})
- public void test_withHour_noChange() {
- OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
- OffsetTime test = base.withHour(11);
- assertSame(test, base);
- }
-
- @Test(groups={"implementation"})
- public void test_withMinute_noChange() {
- OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
- OffsetTime test = base.withMinute(30);
- assertSame(test, base);
- }
-
- @Test(groups={"implementation"})
- public void test_withSecond_noChange() {
- OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
- OffsetTime test = base.withSecond(59);
- assertSame(test, base);
- }
-
- @Test(groups={"implementation"})
- public void test_withNanoOfSecond_noChange() {
- OffsetTime base = OffsetTime.of(11, 30, 59, 1, OFFSET_PONE);
- OffsetTime test = base.withNano(1);
- assertSame(test, base);
- }
-
- @Test(groups={"implementation"})
- public void test_plus_Period_zero() {
- OffsetTime t = TEST_11_30_59_500_PONE.plus(MockSimplePeriod.ZERO_SECONDS);
- assertSame(t, TEST_11_30_59_500_PONE);
- }
-
- @Test(groups={"implementation"})
- public void test_plusHours_zero() {
- OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
- OffsetTime test = base.plusHours(0);
- assertSame(test, base);
- }
-
- @Test(groups={"implementation"})
- public void test_plusMinutes_zero() {
- OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
- OffsetTime test = base.plusMinutes(0);
- assertSame(test, base);
- }
-
- @Test(groups={"implementation"})
- public void test_plusSeconds_zero() {
- OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
- OffsetTime test = base.plusSeconds(0);
- assertSame(test, base);
- }
-
- @Test(groups={"implementation"})
- public void test_plusNanos_zero() {
- OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
- OffsetTime test = base.plusNanos(0);
- assertSame(test, base);
- }
-
- @Test(groups={"implementation"})
- public void test_minus_Period_zero() {
- OffsetTime t = TEST_11_30_59_500_PONE.minus(MockSimplePeriod.ZERO_SECONDS);
- assertSame(t, TEST_11_30_59_500_PONE);
- }
-
- @Test(groups={"implementation"})
- public void test_minusHours_zero() {
- OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
- OffsetTime test = base.minusHours(0);
- assertSame(test, base);
- }
-
- @Test(groups={"implementation"})
- public void test_minusMinutes_zero() {
- OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
- OffsetTime test = base.minusMinutes(0);
- assertSame(test, base);
- }
-
- @Test(groups={"implementation"})
- public void test_minusSeconds_zero() {
- OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
- OffsetTime test = base.minusSeconds(0);
- assertSame(test, base);
- }
-
- @Test(groups={"implementation"})
- public void test_minusNanos_zero() {
- OffsetTime base = OffsetTime.of(11, 30, 59, OFFSET_PONE);
- OffsetTime test = base.minusNanos(0);
- assertSame(test, base);
- }
-
-}
Please sign in to comment.
Something went wrong with that request. Please try again.