Skip to content

Commit

Permalink
Fix assertions (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
perceptron8 authored Dec 17, 2022
1 parent d84cfcb commit 1b318c1
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 61 deletions.
7 changes: 4 additions & 3 deletions src/test/java/org/threeten/extra/AbstractDateTimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*/
package org.threeten.extra;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -101,7 +102,7 @@ public void basicTest_isSupported_TemporalField_null() {
public void basicTest_range_TemporalField_supported() {
for (TemporalAccessor sample : samples()) {
for (TemporalField field : validFields()) {
sample.range(field); // no exception
assertDoesNotThrow(() -> sample.range(field));
}
}
}
Expand Down Expand Up @@ -130,7 +131,7 @@ public void basicTest_get_TemporalField_supported() {
for (TemporalAccessor sample : samples()) {
for (TemporalField field : validFields()) {
if (sample.range(field).isIntValue()) {
sample.get(field); // no exception
assertDoesNotThrow(() -> sample.get(field));
} else {
assertThrows(DateTimeException.class, () -> sample.get(field), "Failed on " + sample + " " + field);
}
Expand Down Expand Up @@ -161,7 +162,7 @@ public void basicTest_get_TemporalField_null() {
public void basicTest_getLong_TemporalField_supported() {
for (TemporalAccessor sample : samples()) {
for (TemporalField field : validFields()) {
sample.getLong(field); // no exception
assertDoesNotThrow(() -> sample.getLong(field));
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/org/threeten/extra/TestDayOfYear.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import static java.time.temporal.ChronoField.YEAR;
import static java.time.temporal.ChronoField.YEAR_OF_ERA;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -175,7 +176,7 @@ public void test_serialization() throws IOException, ClassNotFoundException {
oos.writeObject(test);
}
try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) {
assertEquals(test, ois.readObject());
assertSame(test, ois.readObject());
}
}

Expand Down Expand Up @@ -204,7 +205,7 @@ public void test_of_int() {
for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) {
DayOfYear test = DayOfYear.of(i);
assertEquals(i, test.getValue());
assertEquals(test, DayOfYear.of(i));
assertSame(test, DayOfYear.of(i));
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/threeten/extra/TestDays.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public void test_deserializationSingleton() throws Exception {
//-----------------------------------------------------------------------
@Test
public void test_ZERO() {
assertSame(Days.of(0), Days.ZERO);
assertEquals(Days.of(0), Days.ZERO);
assertSame(Days.ZERO, Days.of(0));
assertEquals(Days.ZERO, Days.of(0));
assertEquals(0, Days.ZERO.getAmount());
assertFalse(Days.ZERO.isNegative());
assertTrue(Days.ZERO.isZero());
Expand All @@ -93,8 +93,8 @@ public void test_ZERO() {

@Test
public void test_ONE() {
assertSame(Days.of(1), Days.ONE);
assertEquals(Days.of(1), Days.ONE);
assertSame(Days.ONE, Days.of(1));
assertEquals(Days.ONE, Days.of(1));
assertEquals(1, Days.ONE.getAmount());
assertFalse(Days.ONE.isNegative());
assertFalse(Days.ONE.isZero());
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/threeten/extra/TestHours.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public void test_deserializationSingleton() throws Exception {
//-----------------------------------------------------------------------
@Test
public void test_ZERO() {
assertSame(Hours.of(0), Hours.ZERO);
assertEquals(Hours.of(0), Hours.ZERO);
assertSame(Hours.ZERO, Hours.of(0));
assertEquals(Hours.ZERO, Hours.of(0));
assertEquals(0, Hours.ZERO.getAmount());
assertFalse(Hours.ZERO.isNegative());
assertTrue(Hours.ZERO.isZero());
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/threeten/extra/TestMinutes.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public void test_deserializationSingleton() throws Exception {
//-----------------------------------------------------------------------
@Test
public void test_ZERO() {
assertSame(Minutes.of(0), Minutes.ZERO);
assertEquals(Minutes.of(0), Minutes.ZERO);
assertSame(Minutes.ZERO, Minutes.of(0));
assertEquals(Minutes.ZERO, Minutes.of(0));
assertEquals(0, Minutes.ZERO.getAmount());
assertFalse(Minutes.ZERO.isNegative());
assertTrue(Minutes.ZERO.isZero());
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/threeten/extra/TestMonths.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public void test_deserializationSingleton() throws Exception {
//-----------------------------------------------------------------------
@Test
public void test_ZERO() {
assertSame(Months.of(0), Months.ZERO);
assertEquals(Months.of(0), Months.ZERO);
assertSame(Months.ZERO, Months.of(0));
assertEquals(Months.ZERO, Months.of(0));
assertEquals(0, Months.ZERO.getAmount());
assertFalse(Months.ZERO.isNegative());
assertTrue(Months.ZERO.isZero());
Expand All @@ -93,8 +93,8 @@ public void test_ZERO() {

@Test
public void test_ONE() {
assertSame(Months.of(1), Months.ONE);
assertEquals(Months.of(1), Months.ONE);
assertSame(Months.ONE, Months.of(1));
assertEquals(Months.ONE, Months.of(1));
assertEquals(1, Months.ONE.getAmount());
assertFalse(Months.ONE.isNegative());
assertFalse(Months.ONE.isZero());
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/org/threeten/extra/TestOffsetDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import static java.time.temporal.ChronoField.YEAR_OF_ERA;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -386,15 +387,15 @@ public void constructor_nullDate() throws Throwable {
Constructor<OffsetDate> con = OffsetDate.class.getDeclaredConstructor(LocalDate.class, ZoneOffset.class);
con.setAccessible(true);
InvocationTargetException thrown = assertThrows(InvocationTargetException.class, () -> con.newInstance(null, OFFSET_PONE));
assertTrue(thrown.getCause() instanceof NullPointerException);
assertInstanceOf(NullPointerException.class, thrown.getCause());
}

@Test
public void constructor_nullOffset() throws Throwable {
Constructor<OffsetDate> con = OffsetDate.class.getDeclaredConstructor(LocalDate.class, ZoneOffset.class);
con.setAccessible(true);
InvocationTargetException thrown = assertThrows(InvocationTargetException.class, () -> con.newInstance(LocalDate.of(2008, 6, 30), null));
assertTrue(thrown.getCause() instanceof NullPointerException);
assertInstanceOf(NullPointerException.class, thrown.getCause());
}

//-----------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/threeten/extra/TestSeconds.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public void test_deserializationSingleton() throws Exception {
//-----------------------------------------------------------------------
@Test
public void test_ZERO() {
assertSame(Seconds.of(0), Seconds.ZERO);
assertEquals(Seconds.of(0), Seconds.ZERO);
assertSame(Seconds.ZERO, Seconds.of(0));
assertEquals(Seconds.ZERO, Seconds.of(0));
assertEquals(0, Seconds.ZERO.getAmount());
assertFalse(Seconds.ZERO.isNegative());
assertTrue(Seconds.ZERO.isZero());
Expand Down
64 changes: 32 additions & 32 deletions src/test/java/org/threeten/extra/TestTemporals.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
import static java.time.temporal.ChronoUnit.YEARS;
import static java.time.temporal.IsoFields.QUARTER_YEARS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -93,7 +94,7 @@ public class TestTemporals {
@Test
public void test_nextWorkingDay_serialization() throws IOException, ClassNotFoundException {
TemporalAdjuster test = Temporals.nextWorkingDay();
assertTrue(test instanceof Serializable);
assertInstanceOf(Serializable.class, test);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(test);
Expand All @@ -110,8 +111,8 @@ public void test_nextWorkingDay() {
LocalDate date = LocalDate.of(2007, month, i);
LocalDate test = (LocalDate) Temporals.nextWorkingDay().adjustInto(date);
assertTrue(test.isAfter(date));
assertFalse(test.getDayOfWeek().equals(SATURDAY));
assertFalse(test.getDayOfWeek().equals(SUNDAY));
assertNotEquals(SATURDAY, test.getDayOfWeek());
assertNotEquals(SUNDAY, test.getDayOfWeek());

switch (date.getDayOfWeek()) {
case FRIDAY:
Expand Down Expand Up @@ -160,13 +161,13 @@ public void test_nextWorkingDay_yearChange() {
@Test
public void test_nextWorkingDayOrSame_serialization() throws IOException, ClassNotFoundException {
TemporalAdjuster test = Temporals.nextWorkingDayOrSame();
assertTrue(test instanceof Serializable);
assertInstanceOf(Serializable.class, test);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(test);
}
try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) {
assertSame(ois.readObject(), test);
assertSame(test, ois.readObject());
}
}

Expand All @@ -176,13 +177,13 @@ public void test_nextWorkingDayOrSame() {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = LocalDate.of(2007, month, i);
LocalDate test = (LocalDate) Temporals.nextWorkingDayOrSame().adjustInto(date);
assertFalse(test.getDayOfWeek().equals(SATURDAY));
assertFalse(test.getDayOfWeek().equals(SUNDAY));
assertNotEquals(SATURDAY, test.getDayOfWeek());
assertNotEquals(SUNDAY, test.getDayOfWeek());

switch (date.getDayOfWeek()) {
case SATURDAY:
case SUNDAY:
assertEquals(test.getDayOfWeek(), MONDAY);
assertEquals(MONDAY, test.getDayOfWeek());
break;
default:
assertEquals(date.getDayOfWeek(), test.getDayOfWeek());
Expand All @@ -192,18 +193,18 @@ public void test_nextWorkingDayOrSame() {
int dayDiff = test.getDayOfYear() - date.getDayOfYear();
switch (date.getDayOfWeek()) {
case SATURDAY:
assertEquals(dayDiff, 2);
assertEquals(2, dayDiff);
break;
case SUNDAY:
assertEquals(dayDiff, 1);
assertEquals(1, dayDiff);
break;
default:
assertEquals(dayDiff, 0);
assertEquals(0, dayDiff);
}
} else {
assertEquals(test.getYear(), 2008);
assertEquals(test.getMonth(), JANUARY);
assertEquals(test.getDayOfMonth(), 1);
assertEquals(2008, test.getYear());
assertEquals(JANUARY, test.getMonth());
assertEquals(1, test.getDayOfMonth());
}
}
}
Expand All @@ -226,7 +227,7 @@ public void test_nextWorkingDayOrSame_yearChange() {
@Test
public void test_previousWorkingDay_serialization() throws IOException, ClassNotFoundException {
TemporalAdjuster test = Temporals.previousWorkingDay();
assertTrue(test instanceof Serializable);
assertInstanceOf(Serializable.class, test);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(test);
Expand All @@ -243,8 +244,8 @@ public void test_previousWorkingDay() {
LocalDate date = LocalDate.of(2007, month, i);
LocalDate test = (LocalDate) Temporals.previousWorkingDay().adjustInto(date);
assertTrue(test.isBefore(date));
assertFalse(test.getDayOfWeek().equals(SATURDAY));
assertFalse(test.getDayOfWeek().equals(SUNDAY));
assertNotEquals(SATURDAY, test.getDayOfWeek());
assertNotEquals(SUNDAY, test.getDayOfWeek());

switch (date.getDayOfWeek()) {
case MONDAY:
Expand Down Expand Up @@ -293,13 +294,13 @@ public void test_previousWorkingDay_yearChange() {
@Test
public void test_previousWorkingDayOrSame_serialization() throws IOException, ClassNotFoundException {
TemporalAdjuster test = Temporals.previousWorkingDayOrSame();
assertTrue(test instanceof Serializable);
assertInstanceOf(Serializable.class, test);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(test);
}
try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) {
assertSame(ois.readObject(), test);
assertSame(test, ois.readObject());
}
}

Expand All @@ -309,13 +310,13 @@ public void test_previousWorkingDayOrSame() {
for (int i = 1; i <= month.length(false); i++) {
LocalDate date = LocalDate.of(2007, month, i);
LocalDate test = (LocalDate) Temporals.previousWorkingDayOrSame().adjustInto(date);
assertFalse(test.getDayOfWeek().equals(SATURDAY));
assertFalse(test.getDayOfWeek().equals(SUNDAY));
assertNotEquals(SATURDAY, test.getDayOfWeek());
assertNotEquals(SUNDAY, test.getDayOfWeek());

switch (date.getDayOfWeek()) {
case SATURDAY:
case SUNDAY:
assertEquals(test.getDayOfWeek(), FRIDAY);
assertEquals(FRIDAY, test.getDayOfWeek());
break;
default:
assertEquals(date.getDayOfWeek(), test.getDayOfWeek());
Expand All @@ -325,18 +326,18 @@ public void test_previousWorkingDayOrSame() {
int dayDiff = test.getDayOfYear() - date.getDayOfYear();
switch (date.getDayOfWeek()) {
case SATURDAY:
assertEquals(dayDiff, -1);
assertEquals(-1, dayDiff);
break;
case SUNDAY:
assertEquals(dayDiff, -2);
assertEquals(-2, dayDiff);
break;
default:
assertEquals(dayDiff, 0);
assertEquals(0, dayDiff);
}
} else {
assertEquals(test.getYear(), 2006);
assertEquals(test.getMonth(), DECEMBER);
assertEquals(test.getDayOfMonth(), 29);
assertEquals(2006, test.getYear());
assertEquals(DECEMBER, test.getMonth());
assertEquals(29, test.getDayOfMonth());
}
}
}
Expand All @@ -347,11 +348,11 @@ public void test_previousWorkingDayOrSame_yearChange() {

LocalDate sunday = LocalDate.of(2011, JANUARY, 2);
Temporal test = Temporals.previousWorkingDayOrSame().adjustInto(sunday);
assertEquals(test, LocalDate.of(2010, DECEMBER, 31));
assertEquals(LocalDate.of(2010, DECEMBER, 31), test);

LocalDate saturday = LocalDate.of(2011, JANUARY, 1);
test = Temporals.previousWorkingDayOrSame().adjustInto(saturday);
assertEquals(test, LocalDate.of(2010, DECEMBER, 31));
assertEquals(LocalDate.of(2010, DECEMBER, 31), test);
}

//-----------------------------------------------------------------------
Expand Down Expand Up @@ -682,7 +683,6 @@ public static Object[][] data_durationConversions() {
public void test_durationToBigDecimalSeconds(Duration input, BigDecimal expected, double ignored) {
BigDecimal test = Temporals.durationToBigDecimalSeconds(input);
assertEquals(expected, test);
assertEquals(9, test.scale());
}

@ParameterizedTest
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/threeten/extra/TestWeeks.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public void test_deserializationSingleton() throws Exception {
//-----------------------------------------------------------------------
@Test
public void test_ZERO() {
assertSame(Weeks.of(0), Weeks.ZERO);
assertEquals(Weeks.of(0), Weeks.ZERO);
assertSame(Weeks.ZERO, Weeks.of(0));
assertEquals(Weeks.ZERO, Weeks.of(0));
assertEquals(0, Weeks.ZERO.getAmount());
assertFalse(Weeks.ZERO.isNegative());
assertTrue(Weeks.ZERO.isZero());
Expand All @@ -93,8 +93,8 @@ public void test_ZERO() {

@Test
public void test_ONE() {
assertSame(Weeks.of(1), Weeks.ONE);
assertEquals(Weeks.of(1), Weeks.ONE);
assertSame(Weeks.ONE, Weeks.of(1));
assertEquals(Weeks.ONE, Weeks.of(1));
assertEquals(1, Weeks.ONE.getAmount());
assertFalse(Weeks.ONE.isNegative());
assertFalse(Weeks.ONE.isZero());
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/threeten/extra/TestYears.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ public void test_deserializationSingleton() throws Exception {
//-----------------------------------------------------------------------
@Test
public void test_ZERO() {
assertSame(Years.of(0), Years.ZERO);
assertEquals(Years.of(0), Years.ZERO);
assertSame(Years.ZERO, Years.of(0));
assertEquals(Years.ZERO, Years.of(0));
assertEquals(0, Years.ZERO.getAmount());
assertFalse(Years.ZERO.isNegative());
assertTrue(Years.ZERO.isZero());
Expand All @@ -93,8 +93,8 @@ public void test_ZERO() {

@Test
public void test_ONE() {
assertSame(Years.of(1), Years.ONE);
assertEquals(Years.of(1), Years.ONE);
assertSame(Years.ONE, Years.of(1));
assertEquals(Years.ONE, Years.of(1));
assertEquals(1, Years.ONE.getAmount());
assertFalse(Years.ONE.isNegative());
assertFalse(Years.ONE.isZero());
Expand Down

0 comments on commit 1b318c1

Please sign in to comment.