diff --git a/src/main/java/org/assertj/core/api/AbstractOffsetDateTimeAssert.java b/src/main/java/org/assertj/core/api/AbstractOffsetDateTimeAssert.java
index 08513b2ad63..9cd6ef0fae6 100644
--- a/src/main/java/org/assertj/core/api/AbstractOffsetDateTimeAssert.java
+++ b/src/main/java/org/assertj/core/api/AbstractOffsetDateTimeAssert.java
@@ -12,11 +12,6 @@
*/
package org.assertj.core.api;
-import org.assertj.core.internal.Failures;
-import org.assertj.core.internal.Objects;
-
-import java.time.OffsetDateTime;
-
import static org.assertj.core.error.ShouldBeAfter.shouldBeAfter;
import static org.assertj.core.error.ShouldBeAfterOrEqualsTo.shouldBeAfterOrEqualsTo;
import static org.assertj.core.error.ShouldBeBefore.shouldBeBefore;
@@ -27,6 +22,11 @@
import static org.assertj.core.error.ShouldBeEqualIgnoringSeconds.shouldBeEqualIgnoringSeconds;
import static org.assertj.core.error.ShouldBeEqualIgnoringTimezone.shouldBeEqualIgnoringTimezone;
+import java.time.OffsetDateTime;
+
+import org.assertj.core.internal.Failures;
+import org.assertj.core.internal.Objects;
+
/**
* Assertions for {@link java.time.OffsetDateTime} type from new Date & Time API introduced in Java 8.
*
@@ -37,646 +37,683 @@
public abstract class AbstractOffsetDateTimeAssert> extends
AbstractAssert {
- public static final String NULL_OFFSET_DATE_TIME_PARAMETER_MESSAGE = "The OffsetDateTime to compare actual with should not be null";
-
- /**
- * Creates a new {@link org.assertj.core.api.AbstractOffsetDateTimeAssert}
.
- *
- * @param selfType the "self type"
- * @param actual the actual value to verify
- */
- protected AbstractOffsetDateTimeAssert(OffsetDateTime actual, Class> selfType) {
- super(actual, selfType);
- }
-
- // visible for test
- protected OffsetDateTime getActual() {
- return actual;
- }
-
- /**
- * Verifies that the actual {@code OffsetDateTime} is strictly before the given one.
- *
- * Example : - *
- *
- * assertThat(parse("2000-01-01T23:59:59Z")).isBefore(parse("2000-01-02T00:00:00Z"));
- *
- *
- * @param other the given {@link java.time.OffsetDateTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
- * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
- * @throws AssertionError if the actual {@code OffsetDateTime} is not strictly before the given one.
- */
- public S isBefore(OffsetDateTime other) {
- Objects.instance().assertNotNull(info, actual);
- assertOffsetDateTimeParameterIsNotNull(other);
- if (!actual.isBefore(other)) {
- throw Failures.instance().failure(info, shouldBeBefore(actual, other));
- }
- return myself;
+ public static final String NULL_OFFSET_DATE_TIME_PARAMETER_MESSAGE = "The OffsetDateTime to compare actual with should not be null";
+
+ /**
+ * Creates a new {@link org.assertj.core.api.AbstractOffsetDateTimeAssert}
.
+ *
+ * @param selfType the "self type"
+ * @param actual the actual value to verify
+ */
+ protected AbstractOffsetDateTimeAssert(OffsetDateTime actual, Class> selfType) {
+ super(actual, selfType);
+ }
+
+ // visible for test
+ protected OffsetDateTime getActual() {
+ return actual;
+ }
+
+ /**
+ * Verifies that the actual {@code OffsetDateTime} is strictly before the given one.
+ * + * Example : + *
+ * + *
+ * assertThat(parse("2000-01-01T23:59:59Z")).isBefore(parse("2000-01-02T00:00:00Z"));
+ *
+ *
+ * @param other the given {@link java.time.OffsetDateTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
+ * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is not strictly before the given one.
+ */
+ public S isBefore(OffsetDateTime other) {
+ Objects.instance().assertNotNull(info, actual);
+ assertOffsetDateTimeParameterIsNotNull(other);
+ if (!actual.isBefore(other)) {
+ throw Failures.instance().failure(info, shouldBeBefore(actual, other));
}
-
- /**
- * Same assertion as {@link #isBefore(java.time.OffsetDateTime)} but the {@link java.time.OffsetDateTime} is built from given String, which
- * must follow ISO OffsetDateTime format to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.
- * - * Example : - *
- *
- * // use directly String in comparison to avoid writing the code to perform the conversion
- * assertThat(parse("2000-01-01T23:59:59Z")).isBefore("2000-01-02T00:00:00Z");
- *
- *
- * @param offsetDateTimeAsString String representing a {@link java.time.OffsetDateTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
- * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetDateTime}.
- * @throws AssertionError if the actual {@code OffsetDateTime} is not strictly before the {@link java.time.OffsetDateTime} built
- * from given String.
- */
- public S isBefore(String offsetDateTimeAsString) {
- assertOffsetDateTimeAsStringParameterIsNotNull(offsetDateTimeAsString);
- return isBefore(OffsetDateTime.parse(offsetDateTimeAsString));
+ return myself;
+ }
+
+ /**
+ * Same assertion as {@link #isBefore(java.time.OffsetDateTime)} but the {@link java.time.OffsetDateTime} is built
+ * from given String, which
+ * must follow ISO OffsetDateTime format to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.
+ * + * Example : + *
+ * + *
+ * // use directly String in comparison to avoid writing the code to perform the conversion
+ * assertThat(parse("2000-01-01T23:59:59Z")).isBefore("2000-01-02T00:00:00Z");
+ *
+ *
+ * @param offsetDateTimeAsString String representing a {@link java.time.OffsetDateTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
+ * @throws IllegalArgumentException if given String is null or can't be converted to a
+ * {@link java.time.OffsetDateTime}.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is not strictly before the
+ * {@link java.time.OffsetDateTime} built
+ * from given String.
+ */
+ public S isBefore(String offsetDateTimeAsString) {
+ assertOffsetDateTimeAsStringParameterIsNotNull(offsetDateTimeAsString);
+ return isBefore(OffsetDateTime.parse(offsetDateTimeAsString));
+ }
+
+ /**
+ * Verifies that the actual {@code OffsetDateTime} is before or equals to the given one.
+ * + * Example : + *
+ * + *
+ * assertThat(parse("2000-01-01T23:59:59Z")).isBeforeOrEqualTo(parse("2000-01-01T23:59:59Z"))
+ * .isBeforeOrEqualTo(parse("2000-01-02T00:00:00Z"));
+ *
+ *
+ * @param other the given {@link java.time.OffsetDateTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
+ * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is not before or equals to the given one.
+ */
+ public S isBeforeOrEqualTo(OffsetDateTime other) {
+ Objects.instance().assertNotNull(info, actual);
+ assertOffsetDateTimeParameterIsNotNull(other);
+ if (actual.isAfter(other)) {
+ throw Failures.instance().failure(info, shouldBeBeforeOrEqualsTo(actual, other));
}
-
- /**
- * Verifies that the actual {@code OffsetDateTime} is before or equals to the given one.
- * - * Example : - *
- *
- * assertThat(parse("2000-01-01T23:59:59Z")).isBeforeOrEqualTo(parse("2000-01-01T23:59:59Z"))
- * .isBeforeOrEqualTo(parse("2000-01-02T00:00:00Z"));
- *
- *
- * @param other the given {@link java.time.OffsetDateTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
- * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
- * @throws AssertionError if the actual {@code OffsetDateTime} is not before or equals to the given one.
- */
- public S isBeforeOrEqualTo(OffsetDateTime other) {
- Objects.instance().assertNotNull(info, actual);
- assertOffsetDateTimeParameterIsNotNull(other);
- if (actual.isAfter(other)) {
- throw Failures.instance().failure(info, shouldBeBeforeOrEqualsTo(actual, other));
- }
- return myself;
+ return myself;
+ }
+
+ /**
+ * Same assertion as {@link #isBeforeOrEqualTo(java.time.OffsetDateTime)} but the {@link java.time.OffsetDateTime} is
+ * built from given
+ * String, which must follow ISO OffsetDateTime format to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.
+ * + * Example : + *
+ * + *
+ * // use String in comparison to avoid conversion
+ * assertThat(parse("2000-01-01T23:59:59Z")).isBeforeOrEqualTo("2000-01-01T23:59:59Z")
+ * .isBeforeOrEqualTo("2000-01-02T00:00:00Z");
+ *
+ *
+ * @param offsetDateTimeAsString String representing a {@link java.time.OffsetDateTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
+ * @throws IllegalArgumentException if given String is null or can't be converted to a
+ * {@link java.time.OffsetDateTime}.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is not before or equals to the
+ * {@link java.time.OffsetDateTime} built from given String.
+ */
+ public S isBeforeOrEqualTo(String offsetDateTimeAsString) {
+ assertOffsetDateTimeAsStringParameterIsNotNull(offsetDateTimeAsString);
+ return isBeforeOrEqualTo(OffsetDateTime.parse(offsetDateTimeAsString));
+ }
+
+ /**
+ * Verifies that the actual {@code OffsetDateTime} is after or equals to the given one.
+ * + * Example : + *
+ * + *
+ * assertThat(parse("2000-01-01T00:00:00Z")).isAfterOrEqualTo(parse("2000-01-01T00:00:00Z"))
+ * .isAfterOrEqualTo(parse("1999-12-31T23:59:59Z"));
+ *
+ *
+ * @param other the given {@link java.time.OffsetDateTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
+ * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is not after or equals to the given one.
+ */
+ public S isAfterOrEqualTo(OffsetDateTime other) {
+ Objects.instance().assertNotNull(info, actual);
+ assertOffsetDateTimeParameterIsNotNull(other);
+ if (actual.isBefore(other)) {
+ throw Failures.instance().failure(info, shouldBeAfterOrEqualsTo(actual, other));
}
-
- /**
- * Same assertion as {@link #isBeforeOrEqualTo(java.time.OffsetDateTime)} but the {@link java.time.OffsetDateTime} is built from given
- * String, which must follow ISO OffsetDateTime format to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.
- * - * Example : - *
- *
- * // use String in comparison to avoid conversion
- * assertThat(parse("2000-01-01T23:59:59Z")).isBeforeOrEqualTo("2000-01-01T23:59:59Z")
- * .isBeforeOrEqualTo("2000-01-02T00:00:00Z");
- *
- *
- * @param offsetDateTimeAsString String representing a {@link java.time.OffsetDateTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
- * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetDateTime}.
- * @throws AssertionError if the actual {@code OffsetDateTime} is not before or equals to the {@link java.time.OffsetDateTime}
- * built from given String.
- */
- public S isBeforeOrEqualTo(String offsetDateTimeAsString) {
- assertOffsetDateTimeAsStringParameterIsNotNull(offsetDateTimeAsString);
- return isBeforeOrEqualTo(OffsetDateTime.parse(offsetDateTimeAsString));
+ return myself;
+ }
+
+ /**
+ * Same assertion as {@link #isAfterOrEqualTo(java.time.OffsetDateTime)} but the {@link java.time.OffsetDateTime} is
+ * built from given
+ * String, which must follow ISO OffsetDateTime format to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.
+ * + * Example : + *
+ * + *
+ * // use String in comparison to avoid conversion
+ * assertThat(parse("2000-01-01T00:00:00Z")).isAfterOrEqualTo("2000-01-01T00:00:00Z")
+ * .isAfterOrEqualTo("1999-12-31T23:59:59Z");
+ *
+ *
+ * @param offsetDateTimeAsString String representing a {@link java.time.OffsetDateTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
+ * @throws IllegalArgumentException if given String is null or can't be converted to a
+ * {@link java.time.OffsetDateTime}.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is not after or equals to the
+ * {@link java.time.OffsetDateTime} built from given String.
+ */
+ public S isAfterOrEqualTo(String offsetDateTimeAsString) {
+ assertOffsetDateTimeAsStringParameterIsNotNull(offsetDateTimeAsString);
+ return isAfterOrEqualTo(OffsetDateTime.parse(offsetDateTimeAsString));
+ }
+
+ /**
+ * Verifies that the actual {@code OffsetDateTime} is strictly after the given one.
+ * + * Example : + *
+ * + *
+ * assertThat(parse("2000-01-01T00:00:00Z")).isAfter(parse("1999-12-31T23:59:59Z"));
+ *
+ *
+ * @param other the given {@link java.time.OffsetDateTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
+ * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is not strictly after the given one.
+ */
+ public S isAfter(OffsetDateTime other) {
+ Objects.instance().assertNotNull(info, actual);
+ assertOffsetDateTimeParameterIsNotNull(other);
+ if (!actual.isAfter(other)) {
+ throw Failures.instance().failure(info, shouldBeAfter(actual, other));
}
-
- /**
- * Verifies that the actual {@code OffsetDateTime} is after or equals to the given one.
- * - * Example : - *
- *
- * assertThat(parse("2000-01-01T00:00:00Z")).isAfterOrEqualTo(parse("2000-01-01T00:00:00Z"))
- * .isAfterOrEqualTo(parse("1999-12-31T23:59:59Z"));
- *
- *
- * @param other the given {@link java.time.OffsetDateTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
- * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
- * @throws AssertionError if the actual {@code OffsetDateTime} is not after or equals to the given one.
- */
- public S isAfterOrEqualTo(OffsetDateTime other) {
- Objects.instance().assertNotNull(info, actual);
- assertOffsetDateTimeParameterIsNotNull(other);
- if (actual.isBefore(other)) {
- throw Failures.instance().failure(info, shouldBeAfterOrEqualsTo(actual, other));
- }
- return myself;
+ return myself;
+ }
+
+ /**
+ * Same assertion as {@link #isAfter(java.time.OffsetDateTime)} but the {@link java.time.OffsetDateTime} is built from
+ * given a String that
+ * must follow ISO OffsetDateTime format to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.
+ * + * Example : + *
+ * + *
+ * // use String in comparison to avoid conversion
+ * assertThat(parse("2000-01-01T00:00:00Z")).isAfter("1999-12-31T23:59:59Z");
+ *
+ *
+ * @param offsetDateTimeAsString String representing a {@link java.time.OffsetDateTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
+ * @throws IllegalArgumentException if given String is null or can't be converted to a
+ * {@link java.time.OffsetDateTime}.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is not strictly after the
+ * {@link java.time.OffsetDateTime} built from given String.
+ */
+ public S isAfter(String offsetDateTimeAsString) {
+ assertOffsetDateTimeAsStringParameterIsNotNull(offsetDateTimeAsString);
+ return isAfter(OffsetDateTime.parse(offsetDateTimeAsString));
+ }
+
+ /**
+ * Same assertion as {@link #isEqualTo(Object)} (where Object is expected to be {@link java.time.OffsetDateTime}) but
+ * here you
+ * pass {@link java.time.OffsetDateTime} String representation that must follow ISO OffsetDateTime format to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.
+ * + * Example : + *
+ * + *
+ * // use directly String in comparison to avoid writing the code to perform the conversion
+ * assertThat(parse("2000-01-01T00:00:00Z")).isEqualTo("2000-01-01T00:00:00Z");
+ *
+ *
+ * @param dateTimeAsString String representing a {@link java.time.OffsetDateTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
+ * @throws IllegalArgumentException if given String is null or can't be converted to a
+ * {@link java.time.OffsetDateTime}.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is not equal to the {@link java.time.OffsetDateTime}
+ * built from given String.
+ */
+ public S isEqualTo(String dateTimeAsString) {
+ assertOffsetDateTimeAsStringParameterIsNotNull(dateTimeAsString);
+ return isEqualTo(OffsetDateTime.parse(dateTimeAsString));
+ }
+
+ /**
+ * Same assertion as {@link #isNotEqualTo(Object)} (where Object is expected to be {@link java.time.OffsetDateTime})
+ * but here you
+ * pass {@link java.time.OffsetDateTime} String representation that must follow ISO OffsetDateTime format to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.
+ * + * Example : + *
+ * + *
+ * // use directly String in comparison to avoid writing the code to perform the conversion
+ * assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo("2000-01-15T00:00:00Z");
+ *
+ *
+ * @param dateTimeAsString String representing a {@link java.time.OffsetDateTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
+ * @throws IllegalArgumentException if given String is null or can't be converted to a
+ * {@link java.time.OffsetDateTime}.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is equal to the {@link java.time.OffsetDateTime} built
+ * from given String.
+ */
+ public S isNotEqualTo(String dateTimeAsString) {
+ assertOffsetDateTimeAsStringParameterIsNotNull(dateTimeAsString);
+ return isNotEqualTo(OffsetDateTime.parse(dateTimeAsString));
+ }
+
+ /**
+ * Same assertion as {@link #isIn(Object...)} (where Objects are expected to be {@link java.time.OffsetDateTime}) but
+ * here you
+ * pass {@link java.time.OffsetDateTime} String representations that must follow ISO OffsetDateTime format to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.
+ * + * Example : + *
+ * + *
+ * // use String based representation of OffsetDateTime
+ * assertThat(parse("2000-01-01T00:00:00Z")).isIn("1999-12-31T00:00:00Z", "2000-01-01T00:00:00Z");
+ *
+ *
+ * @param dateTimesAsString String array representing {@link java.time.OffsetDateTime}s.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
+ * @throws IllegalArgumentException if given String is null or can't be converted to a
+ * {@link java.time.OffsetDateTime}.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is not in the {@link java.time.OffsetDateTime}s built
+ * from given Strings.
+ */
+ public S isIn(String... dateTimesAsString) {
+ checkIsNotNullAndNotEmpty(dateTimesAsString);
+ return isIn(convertToOffsetDateTimeArray(dateTimesAsString));
+ }
+
+ /**
+ * Same assertion as {@link #isNotIn(Object...)} (where Objects are expected to be {@link java.time.OffsetDateTime})
+ * but here you
+ * pass {@link java.time.OffsetDateTime} String representations that must follow ISO OffsetDateTime format to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.
+ * + * Example : + *
+ * + *
+ * // use String based representation of OffsetDateTime
+ * assertThat(parse("2000-01-01T00:00:00Z")).isNotIn("1999-12-31T00:00:00Z", "2000-01-02T00:00:00Z");
+ *
+ *
+ * @param dateTimesAsString Array of String representing a {@link java.time.OffsetDateTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
+ * @throws IllegalArgumentException if given String is null or can't be converted to a
+ * {@link java.time.OffsetDateTime}.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is in the {@link java.time.OffsetDateTime}s built from
+ * given Strings.
+ */
+ public S isNotIn(String... dateTimesAsString) {
+ checkIsNotNullAndNotEmpty(dateTimesAsString);
+ return isNotIn(convertToOffsetDateTimeArray(dateTimesAsString));
+ }
+
+ /**
+ * Verifies that actual and given {@code OffsetDateTime} have same year, month, day, hour, minute and second fields,
+ * (nanosecond fields are ignored in comparison).
+ * + * Assertion can fail with OffsetDateTimes in same chronological nanosecond time window, e.g : + *
+ * 2000-01-01T00:00:01.000000000+01:00 and 2000-01-01T00:00:00.999999999+01:00. + *
+ * Assertion fails as second fields differ even if time difference is only 1ns. + *
+ * Code example : + *
+ * + *
+ * // successful assertions
+ * OffsetDateTime OffsetDateTime1 = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC);
+ * OffsetDateTime OffsetDateTime2 = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 456, ZoneOffset.UTC);
+ * assertThat(OffsetDateTime1).isEqualToIgnoringNanos(OffsetDateTime2);
+ *
+ * // failing assertions (even if time difference is only 1ns)
+ * OffsetDateTime OffsetDateTimeA = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC);
+ * OffsetDateTime OffsetDateTimeB = OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 999999999, ZoneOffset.UTC);
+ * assertThat(OffsetDateTimeA).isEqualToIgnoringNanos(OffsetDateTimeB);
+ *
+ *
+ * @param other the given {@link java.time.OffsetDateTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
+ * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is are not equal with nanoseconds ignored.
+ */
+ public S isEqualToIgnoringNanos(OffsetDateTime other) {
+ Objects.instance().assertNotNull(info, actual);
+ assertOffsetDateTimeParameterIsNotNull(other);
+ if (!areEqualIgnoringNanos(actual, other)) {
+ throw Failures.instance().failure(info, shouldBeEqualIgnoringNanos(actual, other));
}
-
- /**
- * Same assertion as {@link #isAfterOrEqualTo(java.time.OffsetDateTime)} but the {@link java.time.OffsetDateTime} is built from given
- * String, which must follow ISO OffsetDateTime format to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.
- * - * Example : - *
- *
- * // use String in comparison to avoid conversion
- * assertThat(parse("2000-01-01T00:00:00Z")).isAfterOrEqualTo("2000-01-01T00:00:00Z")
- * .isAfterOrEqualTo("1999-12-31T23:59:59Z");
- *
- *
- * @param offsetDateTimeAsString String representing a {@link java.time.OffsetDateTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
- * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetDateTime}.
- * @throws AssertionError if the actual {@code OffsetDateTime} is not after or equals to the {@link java.time.OffsetDateTime}
- * built from given String.
- */
- public S isAfterOrEqualTo(String offsetDateTimeAsString) {
- assertOffsetDateTimeAsStringParameterIsNotNull(offsetDateTimeAsString);
- return isAfterOrEqualTo(OffsetDateTime.parse(offsetDateTimeAsString));
+ return myself;
+ }
+
+ /**
+ * Verifies that actual and given {@code OffsetDateTime} have same year, month, day, hour, minute, second and
+ * nanosecond fields,
+ * (timezone fields are ignored in comparison).
+ * + * Code example : + *
+ * + *
+ * // successful assertions
+ * OffsetDateTime OffsetDateTime1 = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC);
+ * OffsetDateTime OffsetDateTime2 = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 0, ZoneOffset.MAX);
+ * assertThat(OffsetDateTime1).isEqualToIgnoringTimezone(OffsetDateTime2);
+ *
+ * // failing assertions
+ * OffsetDateTime OffsetDateTimeA = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC);
+ * OffsetDateTime OffsetDateTimeB = OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 999999999, ZoneOffset.UTC);
+ * assertThat(OffsetDateTimeA).isEqualToIgnoringTimezone(OffsetDateTimeB);
+ *
+ *
+ * @param other the given {@link java.time.OffsetDateTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
+ * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is are not equal with timezone ignored.
+ */
+ public S isEqualToIgnoringTimezone(OffsetDateTime other) {
+ Objects.instance().assertNotNull(info, actual);
+ assertOffsetDateTimeParameterIsNotNull(other);
+ if (!areEqualIgnoringTimezone(actual, other)) {
+ throw Failures.instance().failure(info, shouldBeEqualIgnoringTimezone(actual, other));
}
-
- /**
- * Verifies that the actual {@code OffsetDateTime} is strictly after the given one.
- * - * Example : - *
- *
- * assertThat(parse("2000-01-01T00:00:00Z")).isAfter(parse("1999-12-31T23:59:59Z"));
- *
- *
- * @param other the given {@link java.time.OffsetDateTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
- * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
- * @throws AssertionError if the actual {@code OffsetDateTime} is not strictly after the given one.
- */
- public S isAfter(OffsetDateTime other) {
- Objects.instance().assertNotNull(info, actual);
- assertOffsetDateTimeParameterIsNotNull(other);
- if (!actual.isAfter(other)) {
- throw Failures.instance().failure(info, shouldBeAfter(actual, other));
- }
- return myself;
+ return myself;
+ }
+
+ /**
+ * Verifies that actual and given {@link java.time.OffsetDateTime} have same year, month, day, hour and minute fields
+ * (second and
+ * nanosecond fields are ignored in comparison).
+ * + * Assertion can fail with OffsetDateTimes in same chronological second time window, e.g : + *
+ * 2000-01-01T00:01:00.000+01:00 and 2000-01-01T00:00:59.000+01:00. + *
+ * Assertion fails as minute fields differ even if time difference is only 1s. + *
+ * Code example : + *
+ * + *
+ * // successful assertions
+ * OffsetDateTime OffsetDateTime1 = OffsetDateTime.of(2000, 1, 1, 23, 50, 0, 0, ZoneOffset.UTC);
+ * OffsetDateTime OffsetDateTime2 = OffsetDateTime.of(2000, 1, 1, 23, 50, 10, 456, ZoneOffset.UTC);
+ * assertThat(OffsetDateTime1).isEqualToIgnoringSeconds(OffsetDateTime2);
+ *
+ * // failing assertions (even if time difference is only 1ms)
+ * OffsetDateTime OffsetDateTimeA = OffsetDateTime.of(2000, 1, 1, 23, 50, 00, 000, ZoneOffset.UTC);
+ * OffsetDateTime OffsetDateTimeB = OffsetDateTime.of(2000, 1, 1, 23, 49, 59, 999, ZoneOffset.UTC);
+ * assertThat(OffsetDateTimeA).isEqualToIgnoringSeconds(OffsetDateTimeB);
+ *
+ *
+ * @param other the given {@link java.time.OffsetDateTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
+ * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is are not equal with second and nanosecond fields
+ * ignored.
+ */
+ public S isEqualToIgnoringSeconds(OffsetDateTime other) {
+ Objects.instance().assertNotNull(info, actual);
+ assertOffsetDateTimeParameterIsNotNull(other);
+ if (!areEqualIgnoringSeconds(actual, other)) {
+ throw Failures.instance().failure(info, shouldBeEqualIgnoringSeconds(actual, other));
}
-
- /**
- * Same assertion as {@link #isAfter(java.time.OffsetDateTime)} but the {@link java.time.OffsetDateTime} is built from given a String that
- * must follow ISO OffsetDateTime format to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.
- * - * Example : - *
- *
- * // use String in comparison to avoid conversion
- * assertThat(parse("2000-01-01T00:00:00Z")).isAfter("1999-12-31T23:59:59Z");
- *
- *
- * @param offsetDateTimeAsString String representing a {@link java.time.OffsetDateTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
- * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetDateTime}.
- * @throws AssertionError if the actual {@code OffsetDateTime} is not strictly after the {@link java.time.OffsetDateTime} built
- * from given String.
- */
- public S isAfter(String offsetDateTimeAsString) {
- assertOffsetDateTimeAsStringParameterIsNotNull(offsetDateTimeAsString);
- return isAfter(OffsetDateTime.parse(offsetDateTimeAsString));
+ return myself;
+ }
+
+ /**
+ * Verifies that actual and given {@code OffsetDateTime} have same year, month, day and hour fields (minute, second
+ * and
+ * nanosecond fields are ignored in comparison).
+ * + * Assertion can fail with OffsetDateTimes in same chronological second time window, e.g : + *
+ * 2000-01-01T01:00:00.000+01:00 and 2000-01-01T00:59:59.000+01:00. + *
+ * Time difference is only 1s but hour fields differ. + *
+ * Code example : + *
+ * + *
+ * // successful assertions
+ * OffsetDateTime OffsetDateTime1 = OffsetDateTime.of(2000, 1, 1, 23, 50, 0, 0, ZoneOffset.UTC);
+ * OffsetDateTime OffsetDateTime2 = OffsetDateTime.of(2000, 1, 1, 23, 00, 2, 7, ZoneOffset.UTC);
+ * assertThat(OffsetDateTime1).isEqualToIgnoringMinutes(OffsetDateTime2);
+ *
+ * // failing assertions (even if time difference is only 1ms)
+ * OffsetDateTime OffsetDateTimeA = OffsetDateTime.of(2000, 1, 1, 01, 00, 00, 000, ZoneOffset.UTC);
+ * OffsetDateTime OffsetDateTimeB = OffsetDateTime.of(2000, 1, 1, 00, 59, 59, 999, ZoneOffset.UTC);
+ * assertThat(OffsetDateTimeA).isEqualToIgnoringMinutes(OffsetDateTimeB);
+ *
+ *
+ * @param other the given {@link java.time.OffsetDateTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
+ * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is are not equal ignoring minute, second and nanosecond
+ * fields.
+ */
+ public S isEqualToIgnoringMinutes(OffsetDateTime other) {
+ Objects.instance().assertNotNull(info, actual);
+ assertOffsetDateTimeParameterIsNotNull(other);
+ if (!areEqualIgnoringMinutes(actual, other)) {
+ throw Failures.instance().failure(info, shouldBeEqualIgnoringMinutes(actual, other));
}
-
- /**
- * Same assertion as {@link #isEqualTo(Object)} (where Object is expected to be {@link java.time.OffsetDateTime}) but here you
- * pass {@link java.time.OffsetDateTime} String representation that must follow ISO OffsetDateTime format to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.
- * - * Example : - *
- *
- * // use directly String in comparison to avoid writing the code to perform the conversion
- * assertThat(parse("2000-01-01T00:00:00Z")).isEqualTo("2000-01-01T00:00:00Z");
- *
- *
- * @param dateTimeAsString String representing a {@link java.time.OffsetDateTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
- * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetDateTime}.
- * @throws AssertionError if the actual {@code OffsetDateTime} is not equal to the {@link java.time.OffsetDateTime} built from
- * given String.
- */
- public S isEqualTo(String dateTimeAsString) {
- assertOffsetDateTimeAsStringParameterIsNotNull(dateTimeAsString);
- return isEqualTo(OffsetDateTime.parse(dateTimeAsString));
+ return myself;
+ }
+
+ /**
+ * Verifies that actual and given {@code OffsetDateTime} have same year, month and day fields (hour, minute, second
+ * and
+ * nanosecond fields are ignored in comparison).
+ * + * Assertion can fail with OffsetDateTimes in same chronological minute time window, e.g : + *
+ * 2000-01-01T23:59:00.000+01:00 and 2000-01-02T00:00:00.000+01:00. + *
+ * Time difference is only 1min but day fields differ. + *
+ * Code example : + *
+ * + *
+ * // successful assertions
+ * OffsetDateTime OffsetDateTime1 = OffsetDateTime.of(2000, 1, 1, 23, 59, 59, 999, ZoneOffset.UTC);
+ * OffsetDateTime OffsetDateTime2 = OffsetDateTime.of(2000, 1, 1, 00, 00, 00, 000, ZoneOffset.UTC);
+ * assertThat(OffsetDateTime1).isEqualToIgnoringHours(OffsetDateTime2);
+ *
+ * // failing assertions (even if time difference is only 1ms)
+ * OffsetDateTime OffsetDateTimeA = OffsetDateTime.of(2000, 1, 2, 00, 00, 00, 000, ZoneOffset.UTC);
+ * OffsetDateTime OffsetDateTimeB = OffsetDateTime.of(2000, 1, 1, 23, 59, 59, 999, ZoneOffset.UTC);
+ * assertThat(OffsetDateTimeA).isEqualToIgnoringHours(OffsetDateTimeB);
+ *
+ *
+ * @param other the given {@link java.time.OffsetDateTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
+ * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
+ * @throws AssertionError if the actual {@code OffsetDateTime} is are not equal with second and nanosecond fields
+ * ignored.
+ */
+ public S isEqualToIgnoringHours(OffsetDateTime other) {
+ Objects.instance().assertNotNull(info, actual);
+ assertOffsetDateTimeParameterIsNotNull(other);
+ if (!haveSameYearMonthAndDayOfMonth(actual, other)) {
+ throw Failures.instance().failure(info, shouldBeEqualIgnoringHours(actual, other));
}
-
- /**
- * Same assertion as {@link #isNotEqualTo(Object)} (where Object is expected to be {@link java.time.OffsetDateTime}) but here you
- * pass {@link java.time.OffsetDateTime} String representation that must follow ISO OffsetDateTime format to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.
- * - * Example : - *
- *
- * // use directly String in comparison to avoid writing the code to perform the conversion
- * assertThat(parse("2000-01-01T00:00:00Z")).isNotEqualTo("2000-01-15T00:00:00Z");
- *
- *
- * @param dateTimeAsString String representing a {@link java.time.OffsetDateTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
- * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetDateTime}.
- * @throws AssertionError if the actual {@code OffsetDateTime} is equal to the {@link java.time.OffsetDateTime} built from given
- * String.
- */
- public S isNotEqualTo(String dateTimeAsString) {
- assertOffsetDateTimeAsStringParameterIsNotNull(dateTimeAsString);
- return isNotEqualTo(OffsetDateTime.parse(dateTimeAsString));
- }
-
- /**
- * Same assertion as {@link #isIn(Object...)} (where Objects are expected to be {@link java.time.OffsetDateTime}) but here you
- * pass {@link java.time.OffsetDateTime} String representations that must follow ISO OffsetDateTime format to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.
- * - * Example : - *
- *
- * // use String based representation of OffsetDateTime
- * assertThat(parse("2000-01-01T00:00:00Z")).isIn("1999-12-31T00:00:00Z", "2000-01-01T00:00:00Z");
- *
- *
- * @param dateTimesAsString String array representing {@link java.time.OffsetDateTime}s.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
- * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetDateTime}.
- * @throws AssertionError if the actual {@code OffsetDateTime} is not in the {@link java.time.OffsetDateTime}s built from given
- * Strings.
- */
- public S isIn(String... dateTimesAsString) {
- checkIsNotNullAndNotEmpty(dateTimesAsString);
- return isIn(convertToOffsetDateTimeArray(dateTimesAsString));
+ return myself;
+ }
+
+ /**
+ * Returns true if both OffsetDateTime are in the same year, month and day of month, hour, minute and second, false
+ * otherwise.
+ *
+ * @param actual the actual OffsetDateTime. expected not be null
+ * @param other the other OffsetDateTime. expected not be null
+ * @return true if both OffsetDateTime are in the same year, month and day of month, hour, minute and second, false
+ * otherwise.
+ */
+ private static boolean areEqualIgnoringNanos(OffsetDateTime actual, OffsetDateTime other) {
+ return areEqualIgnoringSeconds(actual, other) && actual.getSecond() == other.getSecond();
+ }
+
+ /**
+ * Returns true if both OffsetDateTime are in the same year, month, day of month, hour and minute, false otherwise.
+ *
+ * @param actual the actual OffsetDateTime. expected not be null
+ * @param other the other OffsetDateTime. expected not be null
+ * @return true if both OffsetDateTime are in the same year, month, day of month, hour and minute, false otherwise.
+ */
+ private static boolean areEqualIgnoringSeconds(OffsetDateTime actual, OffsetDateTime other) {
+ return areEqualIgnoringMinutes(actual, other) && actual.getMinute() == other.getMinute();
+ }
+
+ /**
+ * Returns true if both OffsetDateTime are in the same year, month, day of month and hour, false otherwise.
+ *
+ * @param actual the actual OffsetDateTime. expected not be null
+ * @param other the other OffsetDateTime. expected not be null
+ * @return true if both OffsetDateTime are in the same year, month, day of month and hour, false otherwise.
+ */
+ private static boolean areEqualIgnoringMinutes(OffsetDateTime actual, OffsetDateTime other) {
+ return haveSameYearMonthAndDayOfMonth(actual, other) && actual.getHour() == other.getHour();
+ }
+
+ /**
+ * Returns true if both OffsetDateTime are in the same year, month and day of month, false otherwise.
+ *
+ * @param actual the actual OffsetDateTime. expected not be null
+ * @param other the other OffsetDateTime. expected not be null
+ * @return true if both OffsetDateTime are in the same year, month and day of month, false otherwise
+ */
+ private static boolean haveSameYearMonthAndDayOfMonth(OffsetDateTime actual, OffsetDateTime other) {
+ return haveSameYearAndMonth(actual, other) && actual.getDayOfMonth() == other.getDayOfMonth();
+ }
+
+ /**
+ * Returns true if both OffsetDateTime are in the same year and month, false otherwise.
+ *
+ * @param actual the actual OffsetDateTime. expected not be null
+ * @param other the other OffsetDateTime. expected not be null
+ * @return true if both OffsetDateTime are in the same year and month, false otherwise
+ */
+ private static boolean haveSameYearAndMonth(OffsetDateTime actual, OffsetDateTime other) {
+ return haveSameYear(actual, other) && actual.getMonth() == other.getMonth();
+ }
+
+ /**
+ * Returns true if both OffsetDateTime are in the same year, false otherwise.
+ *
+ * @param actual the actual OffsetDateTime. expected not be null
+ * @param other the other OffsetDateTime. expected not be null
+ * @return true if both OffsetDateTime are in the same year, false otherwise
+ */
+ private static boolean haveSameYear(OffsetDateTime actual, OffsetDateTime other) {
+ return actual.getYear() == other.getYear();
+ }
+
+ /**
+ * Returns true if both OffsetDateTime are in the same hour, minute, second and nanosecond false otherwise.
+ *
+ * @param actual the actual OffsetDateTime. expected not be null
+ * @param other the other OffsetDateTime. expected not be null
+ * @return true if both OffsetDateTime are in the same hour, minute, second and nanosecond false otherwise.
+ */
+ private static boolean areEqualIgnoringTimezone(OffsetDateTime actual, OffsetDateTime other) {
+ return areEqualIgnoringNanos(actual, other) && haveSameNano(actual, other);
+ }
+
+ /**
+ * Returns true if both OffsetDateTime are in the same nanosecond, false otherwise.
+ *
+ * @param actual the actual OffsetDateTime. expected not be null
+ * @param other the other OffsetDateTime. expected not be null
+ * @return true if both OffsetDateTime are in the same year, false otherwise
+ */
+ private static boolean haveSameNano(OffsetDateTime actual, OffsetDateTime other) {
+ return actual.getNano() == other.getNano();
+ }
+
+ private static Object[] convertToOffsetDateTimeArray(String... dateTimesAsString) {
+ OffsetDateTime[] dates = new OffsetDateTime[dateTimesAsString.length];
+ for (int i = 0; i < dateTimesAsString.length; i++) {
+ dates[i] = OffsetDateTime.parse(dateTimesAsString[i]);
}
-
- /**
- * Same assertion as {@link #isNotIn(Object...)} (where Objects are expected to be {@link java.time.OffsetDateTime}) but here you
- * pass {@link java.time.OffsetDateTime} String representations that must follow ISO OffsetDateTime format to allow calling {@link java.time.OffsetDateTime#parse(CharSequence)} method.
- * - * Example : - *
- *
- * // use String based representation of OffsetDateTime
- * assertThat(parse("2000-01-01T00:00:00Z")).isNotIn("1999-12-31T00:00:00Z", "2000-01-02T00:00:00Z");
- *
- *
- * @param dateTimesAsString Array of String representing a {@link java.time.OffsetDateTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
- * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetDateTime}.
- * @throws AssertionError if the actual {@code OffsetDateTime} is in the {@link java.time.OffsetDateTime}s built from given
- * Strings.
- */
- public S isNotIn(String... dateTimesAsString) {
- checkIsNotNullAndNotEmpty(dateTimesAsString);
- return isNotIn(convertToOffsetDateTimeArray(dateTimesAsString));
+ return dates;
+ }
+
+ private void checkIsNotNullAndNotEmpty(Object[] values) {
+ if (values == null) throw new IllegalArgumentException("The given OffsetDateTime array should not be null");
+ if (values.length == 0) throw new IllegalArgumentException("The given OffsetDateTime array should not be empty");
+ }
+
+ /**
+ * Check that the {@link java.time.OffsetDateTime} string representation to compare actual
+ * {@link java.time.OffsetDateTime} to is not null,
+ * otherwise throws a {@link IllegalArgumentException} with an explicit message
+ *
+ * @param offsetDateTimeAsString String representing the {@link java.time.OffsetDateTime} to compare actual with
+ * @throws IllegalArgumentException with an explicit message if the given {@link String} is null
+ */
+ private static void assertOffsetDateTimeAsStringParameterIsNotNull(String offsetDateTimeAsString) {
+ if (offsetDateTimeAsString == null) {
+ // @format:off
+ throw new IllegalArgumentException("The String representing the OffsetDateTime to compare actual with should not be null");
+ // @format:on
}
-
- private static Object[] convertToOffsetDateTimeArray(String... dateTimesAsString) {
- OffsetDateTime[] dates = new OffsetDateTime[dateTimesAsString.length];
- for (int i = 0; i < dateTimesAsString.length; i++) {
- dates[i] = OffsetDateTime.parse(dateTimesAsString[i]);
- }
- return dates;
- }
-
- private void checkIsNotNullAndNotEmpty(Object[] values) {
- if (values == null) {
- throw new IllegalArgumentException("The given OffsetDateTime array should not be null");
- }
- if (values.length == 0) {
- throw new IllegalArgumentException("The given OffsetDateTime array should not be empty");
- }
+ }
+
+ /**
+ * Check that the {@link java.time.OffsetDateTime} to compare actual {@link java.time.OffsetDateTime} to is not null,
+ * in that case throws a {@link IllegalArgumentException} with an explicit message
+ *
+ * @param other the {@link java.time.OffsetDateTime} to check
+ * @throws IllegalArgumentException with an explicit message if the given {@link java.time.OffsetDateTime} is null
+ */
+ private static void assertOffsetDateTimeParameterIsNotNull(OffsetDateTime other) {
+ if (other == null) {
+ throw new IllegalArgumentException("The OffsetDateTime to compare actual with should not be null");
}
+ }
- /**
- * Check that the {@link java.time.OffsetDateTime} string representation to compare actual {@link java.time.OffsetDateTime} to is not null,
- * otherwise throws a {@link IllegalArgumentException} with an explicit message
- *
- * @param offsetDateTimeAsString String representing the {@link java.time.OffsetDateTime} to compare actual with
- * @throws IllegalArgumentException with an explicit message if the given {@link String} is null
- */
- private static void assertOffsetDateTimeAsStringParameterIsNotNull(String offsetDateTimeAsString) {
- if (offsetDateTimeAsString == null) {
- throw new IllegalArgumentException(
- "The String representing the OffsetDateTime to compare actual with should not be null");
- }
- }
-
- /**
- * Check that the {@link java.time.OffsetDateTime} to compare actual {@link java.time.OffsetDateTime} to is not null, in that case throws a
- * {@link IllegalArgumentException} with an explicit message
- *
- * @param other the {@link java.time.OffsetDateTime} to check
- * @throws IllegalArgumentException with an explicit message if the given {@link java.time.OffsetDateTime} is null
- */
- private static void assertOffsetDateTimeParameterIsNotNull(OffsetDateTime other) {
- if (other == null) {
- throw new IllegalArgumentException("The OffsetDateTime to compare actual with should not be null");
- }
- }
-
- /**
- * Verifies that actual and given {@code OffsetDateTime} have same year, month, day, hour, minute and second fields,
- * (nanosecond fields are ignored in comparison).
- * - * Assertion can fail with OffsetDateTimes in same chronological nanosecond time window, e.g : - *
- * 2000-01-01T00:00:01.000000000 and 2000-01-01T00:00:00.999999999. - *
- * Assertion fails as second fields differ even if time difference is only 1ns. - *
- * Code example : - *
- *
- * // successful assertions
- * OffsetDateTime OffsetDateTime1 = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC);
- * OffsetDateTime OffsetDateTime2 = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 456, ZoneOffset.UTC);
- * assertThat(OffsetDateTime1).isEqualToIgnoringNanos(OffsetDateTime2);
- *
- * // failing assertions (even if time difference is only 1ms)
- * OffsetDateTime OffsetDateTimeA = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC);
- * OffsetDateTime OffsetDateTimeB = OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 999999999, ZoneOffset.UTC);
- * assertThat(OffsetDateTimeA).isEqualToIgnoringNanos(OffsetDateTimeB);
- *
- *
- * @param other the given {@link java.time.OffsetDateTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
- * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
- * @throws AssertionError if the actual {@code OffsetDateTime} is are not equal with nanoseconds ignored.
- */
- public S isEqualToIgnoringNanos(OffsetDateTime other) {
- Objects.instance().assertNotNull(info, actual);
- assertOffsetDateTimeParameterIsNotNull(other);
- if (!areEqualIgnoringNanos(actual, other)) {
- throw Failures.instance().failure(info, shouldBeEqualIgnoringNanos(actual, other));
- }
- return myself;
- }
-
- /**
- * Verifies that actual and given {@code OffsetDateTime} have same year, month, day, hour, minute, second and nanosecond fields,
- * (timezone fields are ignored in comparison).
- * - * Code example : - *
- *
- * // successful assertions
- * OffsetDateTime OffsetDateTime1 = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC);
- * OffsetDateTime OffsetDateTime2 = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 0, ZoneOffset.MAX);
- * assertThat(OffsetDateTime1).isEqualToIgnoringTimezone(OffsetDateTime2);
- *
- * // failing assertions
- * OffsetDateTime OffsetDateTimeA = OffsetDateTime.of(2000, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC);
- * OffsetDateTime OffsetDateTimeB = OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 999999999, ZoneOffset.UTC);
- * assertThat(OffsetDateTimeA).isEqualToIgnoringTimezone(OffsetDateTimeB);
- *
- *
- * @param other the given {@link java.time.OffsetDateTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
- * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
- * @throws AssertionError if the actual {@code OffsetDateTime} is are not equal with timezone ignored.
- */
- public S isEqualToIgnoringTimezone(OffsetDateTime other) {
- Objects.instance().assertNotNull(info, actual);
- assertOffsetDateTimeParameterIsNotNull(other);
- if (!areEqualIgnoringTimezone(actual, other)) {
- throw Failures.instance().failure(info, shouldBeEqualIgnoringTimezone(actual, other));
- }
- return myself;
- }
-
- /**
- * Verifies that actual and given {@link java.time.OffsetDateTime} have same year, month, day, hour and minute fields (second and
- * nanosecond fields are ignored in comparison).
- * - * Assertion can fail with OffsetDateTimes in same chronological second time window, e.g : - *
- * 2000-01-01T00:01:00.000 and 2000-01-01T00:00:59.000. - *
- * Assertion fails as minute fields differ even if time difference is only 1s. - *
- * Code example : - *
- *
- * // successful assertions
- * OffsetDateTime OffsetDateTime1 = OffsetDateTime.of(2000, 1, 1, 23, 50, 0, 0, ZoneOffset.UTC);
- * OffsetDateTime OffsetDateTime2 = OffsetDateTime.of(2000, 1, 1, 23, 50, 10, 456, ZoneOffset.UTC);
- * assertThat(OffsetDateTime1).isEqualToIgnoringSeconds(OffsetDateTime2);
- *
- * // failing assertions (even if time difference is only 1ms)
- * OffsetDateTime OffsetDateTimeA = OffsetDateTime.of(2000, 1, 1, 23, 50, 00, 000, ZoneOffset.UTC);
- * OffsetDateTime OffsetDateTimeB = OffsetDateTime.of(2000, 1, 1, 23, 49, 59, 999, ZoneOffset.UTC);
- * assertThat(OffsetDateTimeA).isEqualToIgnoringSeconds(OffsetDateTimeB);
- *
- *
- * @param other the given {@link java.time.OffsetDateTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
- * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
- * @throws AssertionError if the actual {@code OffsetDateTime} is are not equal with second and nanosecond fields
- * ignored.
- */
- public S isEqualToIgnoringSeconds(OffsetDateTime other) {
- Objects.instance().assertNotNull(info, actual);
- assertOffsetDateTimeParameterIsNotNull(other);
- if (!areEqualIgnoringSeconds(actual, other)) {
- throw Failures.instance().failure(info, shouldBeEqualIgnoringSeconds(actual, other));
- }
- return myself;
- }
-
- /**
- * Verifies that actual and given {@code OffsetDateTime} have same year, month, day and hour fields (minute, second and
- * nanosecond fields are ignored in comparison).
- * - * Assertion can fail with OffsetDateTimes in same chronological second time window, e.g : - *
- * 2000-01-01T01:00:00.000 and 2000-01-01T00:59:59.000. - *
- * Time difference is only 1s but hour fields differ. - *
- * Code example : - *
- *
- * // successful assertions
- * OffsetDateTime OffsetDateTime1 = OffsetDateTime.of(2000, 1, 1, 23, 50, 0, 0, ZoneOffset.UTC);
- * OffsetDateTime OffsetDateTime2 = OffsetDateTime.of(2000, 1, 1, 23, 00, 2, 7, ZoneOffset.UTC);
- * assertThat(OffsetDateTime1).isEqualToIgnoringMinutes(OffsetDateTime2);
- *
- * // failing assertions (even if time difference is only 1ms)
- * OffsetDateTime OffsetDateTimeA = OffsetDateTime.of(2000, 1, 1, 01, 00, 00, 000, ZoneOffset.UTC);
- * OffsetDateTime OffsetDateTimeB = OffsetDateTime.of(2000, 1, 1, 00, 59, 59, 999, ZoneOffset.UTC);
- * assertThat(OffsetDateTimeA).isEqualToIgnoringMinutes(OffsetDateTimeB);
- *
- *
- * @param other the given {@link java.time.OffsetDateTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
- * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
- * @throws AssertionError if the actual {@code OffsetDateTime} is are not equal ignoring minute, second and nanosecond
- * fields.
- */
- public S isEqualToIgnoringMinutes(OffsetDateTime other) {
- Objects.instance().assertNotNull(info, actual);
- assertOffsetDateTimeParameterIsNotNull(other);
- if (!areEqualIgnoringMinutes(actual, other)) {
- throw Failures.instance().failure(info, shouldBeEqualIgnoringMinutes(actual, other));
- }
- return myself;
- }
-
- /**
- * Verifies that actual and given {@code OffsetDateTime} have same year, month and day fields (hour, minute, second and
- * nanosecond fields are ignored in comparison).
- * - * Assertion can fail with OffsetDateTimes in same chronological minute time window, e.g : - *
- * 2000-01-01T23:59:00.000 and 2000-01-02T00:00:00.000. - *
- * Time difference is only 1min but day fields differ. - *
- * Code example : - *
- *
- * // successful assertions
- * OffsetDateTime OffsetDateTime1 = OffsetDateTime.of(2000, 1, 1, 23, 59, 59, 999, ZoneOffset.UTC);
- * OffsetDateTime OffsetDateTime2 = OffsetDateTime.of(2000, 1, 1, 00, 00, 00, 000, ZoneOffset.UTC);
- * assertThat(OffsetDateTime1).isEqualToIgnoringHours(OffsetDateTime2);
- *
- * // failing assertions (even if time difference is only 1ms)
- * OffsetDateTime OffsetDateTimeA = OffsetDateTime.of(2000, 1, 2, 00, 00, 00, 000, ZoneOffset.UTC);
- * OffsetDateTime OffsetDateTimeB = OffsetDateTime.of(2000, 1, 1, 23, 59, 59, 999, ZoneOffset.UTC);
- * assertThat(OffsetDateTimeA).isEqualToIgnoringHours(OffsetDateTimeB);
- *
- *
- * @param other the given {@link java.time.OffsetDateTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetDateTime} is {@code null}.
- * @throws IllegalArgumentException if other {@code OffsetDateTime} is {@code null}.
- * @throws AssertionError if the actual {@code OffsetDateTime} is are not equal with second and nanosecond fields
- * ignored.
- */
- public S isEqualToIgnoringHours(OffsetDateTime other) {
- Objects.instance().assertNotNull(info, actual);
- assertOffsetDateTimeParameterIsNotNull(other);
- if (!haveSameYearMonthAndDayOfMonth(actual, other)) {
- throw Failures.instance().failure(info, shouldBeEqualIgnoringHours(actual, other));
- }
- return myself;
- }
-
- /**
- * Returns true if both OffsetDateTime are in the same year, month and day of month, hour, minute and second, false
- * otherwise.
- *
- * @param actual the actual OffsetDateTime. expected not be null
- * @param other the other OffsetDateTime. expected not be null
- * @return true if both OffsetDateTime are in the same year, month and day of month, hour, minute and second, false
- * otherwise.
- */
- private static boolean areEqualIgnoringNanos(OffsetDateTime actual, OffsetDateTime other) {
- return areEqualIgnoringSeconds(actual, other) && actual.getSecond() == other.getSecond();
- }
-
- /**
- * Returns true if both OffsetDateTime are in the same year, month, day of month, hour and minute, false otherwise.
- *
- * @param actual the actual OffsetDateTime. expected not be null
- * @param other the other OffsetDateTime. expected not be null
- * @return true if both OffsetDateTime are in the same year, month, day of month, hour and minute, false otherwise.
- */
- private static boolean areEqualIgnoringSeconds(OffsetDateTime actual, OffsetDateTime other) {
- return areEqualIgnoringMinutes(actual, other) && actual.getMinute() == other.getMinute();
- }
-
- /**
- * Returns true if both OffsetDateTime are in the same year, month, day of month and hour, false otherwise.
- *
- * @param actual the actual OffsetDateTime. expected not be null
- * @param other the other OffsetDateTime. expected not be null
- * @return true if both OffsetDateTime are in the same year, month, day of month and hour, false otherwise.
- */
- private static boolean areEqualIgnoringMinutes(OffsetDateTime actual, OffsetDateTime other) {
- return haveSameYearMonthAndDayOfMonth(actual, other) && actual.getHour() == other.getHour();
- }
-
- /**
- * Returns true if both OffsetDateTime are in the same year, month and day of month, false otherwise.
- *
- * @param actual the actual OffsetDateTime. expected not be null
- * @param other the other OffsetDateTime. expected not be null
- * @return true if both OffsetDateTime are in the same year, month and day of month, false otherwise
- */
- private static boolean haveSameYearMonthAndDayOfMonth(OffsetDateTime actual, OffsetDateTime other) {
- return haveSameYearAndMonth(actual, other) && actual.getDayOfMonth() == other.getDayOfMonth();
- }
-
- /**
- * Returns true if both OffsetDateTime are in the same year and month, false otherwise.
- *
- * @param actual the actual OffsetDateTime. expected not be null
- * @param other the other OffsetDateTime. expected not be null
- * @return true if both OffsetDateTime are in the same year and month, false otherwise
- */
- private static boolean haveSameYearAndMonth(OffsetDateTime actual, OffsetDateTime other) {
- return haveSameYear(actual, other) && actual.getMonth() == other.getMonth();
- }
-
- /**
- * Returns true if both OffsetDateTime are in the same year, false otherwise.
- *
- * @param actual the actual OffsetDateTime. expected not be null
- * @param other the other OffsetDateTime. expected not be null
- * @return true if both OffsetDateTime are in the same year, false otherwise
- */
- private static boolean haveSameYear(OffsetDateTime actual, OffsetDateTime other) {
- return actual.getYear() == other.getYear();
- }
-
- /**
- * Returns true if both OffsetDateTime are in the same hour, minute, second and nanosecond false otherwise.
- *
- * @param actual the actual OffsetDateTime. expected not be null
- * @param other the other OffsetDateTime. expected not be null
- * @return true if both OffsetDateTime are in the same hour, minute, second and nanosecond false otherwise.
- */
- private static boolean areEqualIgnoringTimezone(OffsetDateTime actual, OffsetDateTime other) {
- return areEqualIgnoringNanos(actual, other) && haveSameNano(actual, other);
- }
-
- /**
- * Returns true if both OffsetDateTime are in the same nanosecond, false otherwise.
- *
- * @param actual the actual OffsetDateTime. expected not be null
- * @param other the other OffsetDateTime. expected not be null
- * @return true if both OffsetDateTime are in the same year, false otherwise
- */
- private static boolean haveSameNano(OffsetDateTime actual, OffsetDateTime other) {
- return actual.getNano() == other.getNano();
- }
}
\ No newline at end of file
diff --git a/src/main/java/org/assertj/core/api/AbstractOffsetTimeAssert.java b/src/main/java/org/assertj/core/api/AbstractOffsetTimeAssert.java
index 7045cceed09..3591d67bbcb 100644
--- a/src/main/java/org/assertj/core/api/AbstractOffsetTimeAssert.java
+++ b/src/main/java/org/assertj/core/api/AbstractOffsetTimeAssert.java
@@ -12,11 +12,6 @@
*/
package org.assertj.core.api;
-import org.assertj.core.internal.Failures;
-import org.assertj.core.internal.Objects;
-
-import java.time.OffsetTime;
-
import static org.assertj.core.error.ShouldBeAfter.shouldBeAfter;
import static org.assertj.core.error.ShouldBeAfterOrEqualsTo.shouldBeAfterOrEqualsTo;
import static org.assertj.core.error.ShouldBeBefore.shouldBeBefore;
@@ -26,6 +21,11 @@
import static org.assertj.core.error.ShouldBeEqualIgnoringTimezone.shouldBeEqualIgnoringTimezone;
import static org.assertj.core.error.ShouldHaveSameHourAs.shouldHaveSameHourAs;
+import java.time.OffsetTime;
+
+import org.assertj.core.internal.Failures;
+import org.assertj.core.internal.Objects;
+
/**
* Assertions for {@link java.time.OffsetTime} type from new Date & Time API introduced in Java 8.
*
@@ -34,563 +34,593 @@
public abstract class AbstractOffsetTimeAssert{@link org.assertj.core.api.AbstractOffsetTimeAssert}
.
- *
- * @param selfType the "self type"
- * @param actual the actual value to verify
- */
- protected AbstractOffsetTimeAssert(OffsetTime actual, Class> selfType) {
- super(actual, selfType);
- }
-
- // visible for test
- protected OffsetTime getActual() {
- return actual;
- }
-
- /**
- * Verifies that the actual {@code OffsetTime} is strictly before the given one.
- * - * Example : - *
- *
- * assertThat(parse("12:00:00Z")).isBefore(parse("13:00:00Z"));
- *
- *
- * @param other the given {@link java.time.OffsetTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
- * @throws IllegalArgumentException if other {@code OffsetTime} is {@code null}.
- * @throws AssertionError if the actual {@code OffsetTime} is not strictly before the given one.
- */
- public S isBefore(OffsetTime other) {
- Objects.instance().assertNotNull(info, actual);
- assertOffsetTimeParameterIsNotNull(other);
- if (!actual.isBefore(other)) {
- throw Failures.instance().failure(info, shouldBeBefore(actual, other));
- }
- return myself;
+ public static final String NULL_OFFSET_TIME_PARAMETER_MESSAGE = "The OffsetTime to compare actual with should not be null";
+
+ /**
+ * Creates a new {@link org.assertj.core.api.AbstractOffsetTimeAssert}
.
+ *
+ * @param selfType the "self type"
+ * @param actual the actual value to verify
+ */
+ protected AbstractOffsetTimeAssert(OffsetTime actual, Class> selfType) {
+ super(actual, selfType);
+ }
+
+ // visible for test
+ protected OffsetTime getActual() {
+ return actual;
+ }
+
+ /**
+ * Verifies that the actual {@code OffsetTime} is strictly before the given one.
+ * + * Example : + *
+ * + *
+ * assertThat(parse("12:00:00Z")).isBefore(parse("13:00:00Z"));
+ *
+ *
+ * @param other the given {@link java.time.OffsetTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
+ * @throws IllegalArgumentException if other {@code OffsetTime} is {@code null}.
+ * @throws AssertionError if the actual {@code OffsetTime} is not strictly before the given one.
+ */
+ public S isBefore(OffsetTime other) {
+ Objects.instance().assertNotNull(info, actual);
+ assertOffsetTimeParameterIsNotNull(other);
+ if (!actual.isBefore(other)) {
+ throw Failures.instance().failure(info, shouldBeBefore(actual, other));
}
-
- /**
- * Same assertion as {@link #isBefore(java.time.OffsetTime)} but the {@link java.time.OffsetTime} is built from given String, which
- * must follow ISO OffsetTime format to allow calling {@link java.time.OffsetTime#parse(CharSequence)} method.
- * - * Example : - *
- *
- * // you can express expected OffsetTime as String (AssertJ taking care of the conversion)
- * assertThat(parse("12:59Z")).isBefore("13:00Z");
- *
- *
- * @param offsetTimeAsString String representing a {@link java.time.OffsetTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
- * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetTime}.
- * @throws AssertionError if the actual {@code OffsetTime} is not strictly before the {@link java.time.OffsetTime} built
- * from given String.
- */
- public S isBefore(String offsetTimeAsString) {
- assertOffsetTimeAsStringParameterIsNotNull(offsetTimeAsString);
- return isBefore(OffsetTime.parse(offsetTimeAsString));
- }
-
- /**
- * Verifies that the actual {@code OffsetTime} is before or equals to the given one.
- * - * Example : - *
- *
- * assertThat(parse("12:00:00Z")).isBeforeOrEqualTo(parse("12:00:00Z"))
- * .isBeforeOrEqualTo(parse("12:00:01Z"));
- *
- *
- * @param other the given {@link java.time.OffsetTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
- * @throws IllegalArgumentException if other {@code OffsetTime} is {@code null}.
- * @throws AssertionError if the actual {@code OffsetTime} is not before or equals to the given one.
- */
- public S isBeforeOrEqualTo(OffsetTime other) {
- Objects.instance().assertNotNull(info, actual);
- assertOffsetTimeParameterIsNotNull(other);
- if (actual.isAfter(other)) {
- throw Failures.instance().failure(info, shouldBeBeforeOrEqualsTo(actual, other));
- }
- return myself;
- }
-
- /**
- * Same assertion as {@link #isBeforeOrEqualTo(java.time.OffsetTime)} but the {@link java.time.OffsetTime} is built from given
- * String, which must follow ISO OffsetTime format to allow calling {@link java.time.OffsetTime#parse(CharSequence)} method.
- * - * Example : - *
- *
- * // you can express expected OffsetTime as String (AssertJ taking care of the conversion)
- * assertThat(parse("12:00:00Z")).isBeforeOrEqualTo("12:00:00Z")
- * .isBeforeOrEqualTo("13:00:00Z");
- *
- *
- * @param offsetTimeAsString String representing a {@link java.time.OffsetTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
- * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetTime}.
- * @throws AssertionError if the actual {@code OffsetTime} is not before or equals to the {@link java.time.OffsetTime} built from
- * given String.
- */
- public S isBeforeOrEqualTo(String offsetTimeAsString) {
- assertOffsetTimeAsStringParameterIsNotNull(offsetTimeAsString);
- return isBeforeOrEqualTo(OffsetTime.parse(offsetTimeAsString));
+ return myself;
+ }
+
+ /**
+ * Same assertion as {@link #isBefore(java.time.OffsetTime)} but the {@link java.time.OffsetTime} is built from given
+ * String, which
+ * must follow ISO OffsetTime format to allow calling {@link java.time.OffsetTime#parse(CharSequence)} method.
+ * + * Example : + *
+ * + *
+ * // you can express expected OffsetTime as String (AssertJ taking care of the conversion)
+ * assertThat(parse("12:59Z")).isBefore("13:00Z");
+ *
+ *
+ * @param offsetTimeAsString String representing a {@link java.time.OffsetTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
+ * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetTime}.
+ * @throws AssertionError if the actual {@code OffsetTime} is not strictly before the {@link java.time.OffsetTime}
+ * built
+ * from given String.
+ */
+ public S isBefore(String offsetTimeAsString) {
+ assertOffsetTimeAsStringParameterIsNotNull(offsetTimeAsString);
+ return isBefore(OffsetTime.parse(offsetTimeAsString));
+ }
+
+ /**
+ * Verifies that the actual {@code OffsetTime} is before or equals to the given one.
+ * + * Example : + *
+ * + *
+ * assertThat(parse("12:00:00Z")).isBeforeOrEqualTo(parse("12:00:00Z"))
+ * .isBeforeOrEqualTo(parse("12:00:01Z"));
+ *
+ *
+ * @param other the given {@link java.time.OffsetTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
+ * @throws IllegalArgumentException if other {@code OffsetTime} is {@code null}.
+ * @throws AssertionError if the actual {@code OffsetTime} is not before or equals to the given one.
+ */
+ public S isBeforeOrEqualTo(OffsetTime other) {
+ Objects.instance().assertNotNull(info, actual);
+ assertOffsetTimeParameterIsNotNull(other);
+ if (actual.isAfter(other)) {
+ throw Failures.instance().failure(info, shouldBeBeforeOrEqualsTo(actual, other));
}
-
- /**
- * Verifies that the actual {@code OffsetTime} is after or equals to the given one.
- * - * Example : - *
- *
- * assertThat(parse("13:00:00Z")).isAfterOrEqualTo(parse("13:00:00Z"))
- * .isAfterOrEqualTo(parse("12:00:00Z"));
- *
- *
- * @param other the given {@link java.time.OffsetTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
- * @throws IllegalArgumentException if other {@code OffsetTime} is {@code null}.
- * @throws AssertionError if the actual {@code OffsetTime} is not after or equals to the given one.
- */
- public S isAfterOrEqualTo(OffsetTime other) {
- Objects.instance().assertNotNull(info, actual);
- assertOffsetTimeParameterIsNotNull(other);
- if (actual.isBefore(other)) {
- throw Failures.instance().failure(info, shouldBeAfterOrEqualsTo(actual, other));
- }
- return myself;
+ return myself;
+ }
+
+ /**
+ * Same assertion as {@link #isBeforeOrEqualTo(java.time.OffsetTime)} but the {@link java.time.OffsetTime} is built
+ * from given
+ * String, which must follow ISO OffsetTime format to allow calling {@link java.time.OffsetTime#parse(CharSequence)} method.
+ * + * Example : + *
+ * + *
+ * // you can express expected OffsetTime as String (AssertJ taking care of the conversion)
+ * assertThat(parse("12:00:00Z")).isBeforeOrEqualTo("12:00:00Z")
+ * .isBeforeOrEqualTo("13:00:00Z");
+ *
+ *
+ * @param offsetTimeAsString String representing a {@link java.time.OffsetTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
+ * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetTime}.
+ * @throws AssertionError if the actual {@code OffsetTime} is not before or equals to the {@link java.time.OffsetTime}
+ * built from
+ * given String.
+ */
+ public S isBeforeOrEqualTo(String offsetTimeAsString) {
+ assertOffsetTimeAsStringParameterIsNotNull(offsetTimeAsString);
+ return isBeforeOrEqualTo(OffsetTime.parse(offsetTimeAsString));
+ }
+
+ /**
+ * Verifies that the actual {@code OffsetTime} is after or equals to the given one.
+ * + * Example : + *
+ * + *
+ * assertThat(parse("13:00:00Z")).isAfterOrEqualTo(parse("13:00:00Z"))
+ * .isAfterOrEqualTo(parse("12:00:00Z"));
+ *
+ *
+ * @param other the given {@link java.time.OffsetTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
+ * @throws IllegalArgumentException if other {@code OffsetTime} is {@code null}.
+ * @throws AssertionError if the actual {@code OffsetTime} is not after or equals to the given one.
+ */
+ public S isAfterOrEqualTo(OffsetTime other) {
+ Objects.instance().assertNotNull(info, actual);
+ assertOffsetTimeParameterIsNotNull(other);
+ if (actual.isBefore(other)) {
+ throw Failures.instance().failure(info, shouldBeAfterOrEqualsTo(actual, other));
}
-
- /**
- * Same assertion as {@link #isAfterOrEqualTo(java.time.OffsetTime)} but the {@link java.time.OffsetTime} is built from given
- * String, which must follow ISO OffsetTime format to allow calling {@link java.time.OffsetTime#parse(CharSequence)} method.
- * - * Example : - *
- *
- * // you can express expected OffsetTime as String (AssertJ taking care of the conversion)
- * assertThat(parse("13:00:00Z")).isAfterOrEqualTo("13:00:00Z")
- * .isAfterOrEqualTo("12:00:00Z");
- *
- *
- * @param offsetTimeAsString String representing a {@link java.time.OffsetTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
- * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetTime}.
- * @throws AssertionError if the actual {@code OffsetTime} is not after or equals to the {@link java.time.OffsetTime} built from
- * given String.
- */
- public S isAfterOrEqualTo(String offsetTimeAsString) {
- assertOffsetTimeAsStringParameterIsNotNull(offsetTimeAsString);
- return isAfterOrEqualTo(OffsetTime.parse(offsetTimeAsString));
+ return myself;
+ }
+
+ /**
+ * Same assertion as {@link #isAfterOrEqualTo(java.time.OffsetTime)} but the {@link java.time.OffsetTime} is built
+ * from given
+ * String, which must follow ISO OffsetTime format to allow calling {@link java.time.OffsetTime#parse(CharSequence)} method.
+ * + * Example : + *
+ * + *
+ * // you can express expected OffsetTime as String (AssertJ taking care of the conversion)
+ * assertThat(parse("13:00:00Z")).isAfterOrEqualTo("13:00:00Z")
+ * .isAfterOrEqualTo("12:00:00Z");
+ *
+ *
+ * @param offsetTimeAsString String representing a {@link java.time.OffsetTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
+ * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetTime}.
+ * @throws AssertionError if the actual {@code OffsetTime} is not after or equals to the {@link java.time.OffsetTime}
+ * built from
+ * given String.
+ */
+ public S isAfterOrEqualTo(String offsetTimeAsString) {
+ assertOffsetTimeAsStringParameterIsNotNull(offsetTimeAsString);
+ return isAfterOrEqualTo(OffsetTime.parse(offsetTimeAsString));
+ }
+
+ /**
+ * Verifies that the actual {@code OffsetTime} is strictly after the given one.
+ * + * Example : + *
+ * + *
+ * assertThat(parse("13:00:00Z")).isAfter(parse("12:00:00Z"));
+ *
+ *
+ * @param other the given {@link java.time.OffsetTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
+ * @throws IllegalArgumentException if other {@code OffsetTime} is {@code null}.
+ * @throws AssertionError if the actual {@code OffsetTime} is not strictly after the given one.
+ */
+ public S isAfter(OffsetTime other) {
+ Objects.instance().assertNotNull(info, actual);
+ assertOffsetTimeParameterIsNotNull(other);
+ if (!actual.isAfter(other)) {
+ throw Failures.instance().failure(info, shouldBeAfter(actual, other));
}
-
- /**
- * Verifies that the actual {@code OffsetTime} is strictly after the given one.
- * - * Example : - *
- *
- * assertThat(parse("13:00:00Z")).isAfter(parse("12:00:00Z"));
- *
- *
- * @param other the given {@link java.time.OffsetTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
- * @throws IllegalArgumentException if other {@code OffsetTime} is {@code null}.
- * @throws AssertionError if the actual {@code OffsetTime} is not strictly after the given one.
- */
- public S isAfter(OffsetTime other) {
- Objects.instance().assertNotNull(info, actual);
- assertOffsetTimeParameterIsNotNull(other);
- if (!actual.isAfter(other)) {
- throw Failures.instance().failure(info, shouldBeAfter(actual, other));
- }
- return myself;
+ return myself;
+ }
+
+ /**
+ * Same assertion as {@link #isAfter(java.time.OffsetTime)} but the {@link java.time.OffsetTime} is built from given a
+ * String that
+ * must follow ISO OffsetTime format to allow calling {@link java.time.OffsetTime#parse(CharSequence)} method.
+ * + * Example : + *
+ * + *
+ * // you can express expected OffsetTime as String (AssertJ taking care of the conversion)
+ * assertThat(parse("13:00:00Z")).isAfter("12:00:00Z");
+ *
+ *
+ * @param offsetTimeAsString String representing a {@link java.time.OffsetTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
+ * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetTime}.
+ * @throws AssertionError if the actual {@code OffsetTime} is not strictly after the {@link java.time.OffsetTime}
+ * built
+ * from given String.
+ */
+ public S isAfter(String offsetTimeAsString) {
+ assertOffsetTimeAsStringParameterIsNotNull(offsetTimeAsString);
+ return isAfter(OffsetTime.parse(offsetTimeAsString));
+ }
+
+ /**
+ * Same assertion as {@link #isEqualTo(Object)} (where Object is expected to be {@link java.time.OffsetTime}) but here
+ * you
+ * pass {@link java.time.OffsetTime} String representation that must follow ISO OffsetTime format to allow calling {@link java.time.OffsetTime#parse(CharSequence)} method.
+ * + * Example : + *
+ * + *
+ * // you can express expected OffsetTime as String (AssertJ taking care of the conversion)
+ * assertThat(parse("13:00:00Z")).isEqualTo("13:00:00Z");
+ *
+ *
+ * @param offsetTimeAsString String representing a {@link java.time.OffsetTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
+ * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetTime}.
+ * @throws AssertionError if the actual {@code OffsetTime} is not equal to the {@link java.time.OffsetTime} built from
+ * given String.
+ */
+ public S isEqualTo(String offsetTimeAsString) {
+ assertOffsetTimeAsStringParameterIsNotNull(offsetTimeAsString);
+ return isEqualTo(OffsetTime.parse(offsetTimeAsString));
+ }
+
+ /**
+ * Same assertion as {@link #isNotEqualTo(Object)} (where Object is expected to be {@link java.time.OffsetTime}) but
+ * here you
+ * pass {@link java.time.OffsetTime} String representation that must follow ISO OffsetTime format to allow calling {@link java.time.OffsetTime#parse(CharSequence)} method.
+ * + * Example : + *
+ * + *
+ * // you can express expected OffsetTime as String (AssertJ taking care of the conversion)
+ * assertThat(parse("13:00:00Z")).isNotEqualTo("12:00:00Z");
+ *
+ *
+ * @param offsetTimeAsString String representing a {@link java.time.OffsetTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
+ * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetTime}.
+ * @throws AssertionError if the actual {@code OffsetTime} is equal to the {@link java.time.OffsetTime} built from
+ * given
+ * String.
+ */
+ public S isNotEqualTo(String offsetTimeAsString) {
+ assertOffsetTimeAsStringParameterIsNotNull(offsetTimeAsString);
+ return isNotEqualTo(OffsetTime.parse(offsetTimeAsString));
+ }
+
+ /**
+ * Same assertion as {@link #isIn(Object...)} (where Objects are expected to be {@link java.time.OffsetTime}) but here
+ * you
+ * pass {@link java.time.OffsetTime} String representations that must follow ISO OffsetTime format to allow calling {@link java.time.OffsetTime#parse(CharSequence)} method.
+ * + * Example : + *
+ * + *
+ * // you can express expected OffsetTimes as String (AssertJ taking care of the conversion)
+ * assertThat(parse("13:00:00Z")).isIn("12:00:00Z", "13:00:00Z");
+ *
+ *
+ * @param offsetTimesAsString String array representing {@link java.time.OffsetTime}s.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
+ * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetTime}.
+ * @throws AssertionError if the actual {@code OffsetTime} is not in the {@link java.time.OffsetTime}s built from
+ * given
+ * Strings.
+ */
+ public S isIn(String... offsetTimesAsString) {
+ checkIsNotNullAndNotEmpty(offsetTimesAsString);
+ return isIn(convertToOffsetTimeArray(offsetTimesAsString));
+ }
+
+ /**
+ * Same assertion as {@link #isNotIn(Object...)} (where Objects are expected to be {@link java.time.OffsetTime}) but
+ * here you
+ * pass {@link java.time.OffsetTime} String representations that must follow ISO OffsetTime format to allow calling {@link java.time.OffsetTime#parse(CharSequence)} method.
+ * + * Example : + *
+ * + *
+ * // you can express expected OffsetTimes as String (AssertJ taking care of the conversion)
+ * assertThat(parse("13:00:00Z")).isNotIn("12:00:00Z", "14:00:00Z");
+ *
+ *
+ * @param offsetTimesAsString Array of String representing a {@link java.time.OffsetTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
+ * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetTime}.
+ * @throws AssertionError if the actual {@code OffsetTime} is in the {@link java.time.OffsetTime}s built from given
+ * Strings.
+ */
+ public S isNotIn(String... offsetTimesAsString) {
+ checkIsNotNullAndNotEmpty(offsetTimesAsString);
+ return isNotIn(convertToOffsetTimeArray(offsetTimesAsString));
+ }
+
+ private static Object[] convertToOffsetTimeArray(String... offsetTimesAsString) {
+ OffsetTime[] dates = new OffsetTime[offsetTimesAsString.length];
+ for (int i = 0; i < offsetTimesAsString.length; i++) {
+ dates[i] = OffsetTime.parse(offsetTimesAsString[i]);
}
-
- /**
- * Same assertion as {@link #isAfter(java.time.OffsetTime)} but the {@link java.time.OffsetTime} is built from given a String that
- * must follow ISO OffsetTime format to allow calling {@link java.time.OffsetTime#parse(CharSequence)} method.
- * - * Example : - *
- *
- * // you can express expected OffsetTime as String (AssertJ taking care of the conversion)
- * assertThat(parse("13:00:00Z")).isAfter("12:00:00Z");
- *
- *
- * @param offsetTimeAsString String representing a {@link java.time.OffsetTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
- * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetTime}.
- * @throws AssertionError if the actual {@code OffsetTime} is not strictly after the {@link java.time.OffsetTime} built
- * from given String.
- */
- public S isAfter(String offsetTimeAsString) {
- assertOffsetTimeAsStringParameterIsNotNull(offsetTimeAsString);
- return isAfter(OffsetTime.parse(offsetTimeAsString));
- }
-
- /**
- * Same assertion as {@link #isEqualTo(Object)} (where Object is expected to be {@link java.time.OffsetTime}) but here you
- * pass {@link java.time.OffsetTime} String representation that must follow ISO OffsetTime format to allow calling {@link java.time.OffsetTime#parse(CharSequence)} method.
- * - * Example : - *
- *
- * // you can express expected OffsetTime as String (AssertJ taking care of the conversion)
- * assertThat(parse("13:00:00Z")).isEqualTo("13:00:00Z");
- *
- *
- * @param offsetTimeAsString String representing a {@link java.time.OffsetTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
- * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetTime}.
- * @throws AssertionError if the actual {@code OffsetTime} is not equal to the {@link java.time.OffsetTime} built from
- * given String.
- */
- public S isEqualTo(String offsetTimeAsString) {
- assertOffsetTimeAsStringParameterIsNotNull(offsetTimeAsString);
- return isEqualTo(OffsetTime.parse(offsetTimeAsString));
- }
-
- /**
- * Same assertion as {@link #isNotEqualTo(Object)} (where Object is expected to be {@link java.time.OffsetTime}) but here you
- * pass {@link java.time.OffsetTime} String representation that must follow ISO OffsetTime format to allow calling {@link java.time.OffsetTime#parse(CharSequence)} method.
- * - * Example : - *
- *
- * // you can express expected OffsetTime as String (AssertJ taking care of the conversion)
- * assertThat(parse("13:00:00Z")).isNotEqualTo("12:00:00Z");
- *
- *
- * @param offsetTimeAsString String representing a {@link java.time.OffsetTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
- * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetTime}.
- * @throws AssertionError if the actual {@code OffsetTime} is equal to the {@link java.time.OffsetTime} built from given
- * String.
- */
- public S isNotEqualTo(String offsetTimeAsString) {
- assertOffsetTimeAsStringParameterIsNotNull(offsetTimeAsString);
- return isNotEqualTo(OffsetTime.parse(offsetTimeAsString));
- }
-
- /**
- * Same assertion as {@link #isIn(Object...)} (where Objects are expected to be {@link java.time.OffsetTime}) but here you
- * pass {@link java.time.OffsetTime} String representations that must follow ISO OffsetTime format to allow calling {@link java.time.OffsetTime#parse(CharSequence)} method.
- * - * Example : - *
- *
- * // you can express expected OffsetTimes as String (AssertJ taking care of the conversion)
- * assertThat(parse("13:00:00Z")).isIn("12:00:00Z", "13:00:00Z");
- *
- *
- * @param offsetTimesAsString String array representing {@link java.time.OffsetTime}s.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
- * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetTime}.
- * @throws AssertionError if the actual {@code OffsetTime} is not in the {@link java.time.OffsetTime}s built from given
- * Strings.
- */
- public S isIn(String... offsetTimesAsString) {
- checkIsNotNullAndNotEmpty(offsetTimesAsString);
- return isIn(convertToOffsetTimeArray(offsetTimesAsString));
- }
-
- /**
- * Same assertion as {@link #isNotIn(Object...)} (where Objects are expected to be {@link java.time.OffsetTime}) but here you
- * pass {@link java.time.OffsetTime} String representations that must follow ISO OffsetTime format to allow calling {@link java.time.OffsetTime#parse(CharSequence)} method.
- * - * Example : - *
- *
- * // you can express expected OffsetTimes as String (AssertJ taking care of the conversion)
- * assertThat(parse("13:00:00Z")).isNotIn("12:00:00Z", "14:00:00Z");
- *
- *
- * @param offsetTimesAsString Array of String representing a {@link java.time.OffsetTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
- * @throws IllegalArgumentException if given String is null or can't be converted to a {@link java.time.OffsetTime}.
- * @throws AssertionError if the actual {@code OffsetTime} is in the {@link java.time.OffsetTime}s built from given
- * Strings.
- */
- public S isNotIn(String... offsetTimesAsString) {
- checkIsNotNullAndNotEmpty(offsetTimesAsString);
- return isNotIn(convertToOffsetTimeArray(offsetTimesAsString));
- }
-
- private static Object[] convertToOffsetTimeArray(String... offsetTimesAsString) {
- OffsetTime[] dates = new OffsetTime[offsetTimesAsString.length];
- for (int i = 0; i < offsetTimesAsString.length; i++) {
- dates[i] = OffsetTime.parse(offsetTimesAsString[i]);
- }
- return dates;
- }
-
- private void checkIsNotNullAndNotEmpty(Object[] values) {
- if (values == null) throw new IllegalArgumentException("The given OffsetTime array should not be null");
- if (values.length == 0) throw new IllegalArgumentException("The given OffsetTime array should not be empty");
- }
-
- /**
- * Check that the {@link java.time.OffsetTime} string representation to compare actual {@link java.time.OffsetTime} to is not null,
- * otherwise throws a {@link IllegalArgumentException} with an explicit message
- *
- * @param OffsetTimeAsString String representing the {@link java.time.OffsetTime} to compare actual with
- * @throws IllegalArgumentException with an explicit message if the given {@link String} is null
- */
- private static void assertOffsetTimeAsStringParameterIsNotNull(String OffsetTimeAsString) {
- // @format:off
+ return dates;
+ }
+
+ private void checkIsNotNullAndNotEmpty(Object[] values) {
+ if (values == null) throw new IllegalArgumentException("The given OffsetTime array should not be null");
+ if (values.length == 0) throw new IllegalArgumentException("The given OffsetTime array should not be empty");
+ }
+
+ /**
+ * Check that the {@link java.time.OffsetTime} string representation to compare actual {@link java.time.OffsetTime} to
+ * is not null,
+ * otherwise throws a {@link IllegalArgumentException} with an explicit message
+ *
+ * @param OffsetTimeAsString String representing the {@link java.time.OffsetTime} to compare actual with
+ * @throws IllegalArgumentException with an explicit message if the given {@link String} is null
+ */
+ private static void assertOffsetTimeAsStringParameterIsNotNull(String OffsetTimeAsString) {
+ // @format:off
if (OffsetTimeAsString == null) throw new IllegalArgumentException("The String representing the OffsetTime to compare actual with should not be null");
// @format:on
+ }
+
+ /**
+ * Check that the {@link java.time.OffsetTime} to compare actual {@link java.time.OffsetTime} to is not null, in that
+ * case throws a {@link IllegalArgumentException} with an explicit message
+ *
+ * @param other the {@link java.time.OffsetTime} to check
+ * @throws IllegalArgumentException with an explicit message if the given {@link java.time.OffsetTime} is null
+ */
+ private static void assertOffsetTimeParameterIsNotNull(OffsetTime other) {
+ if (other == null)
+ throw new IllegalArgumentException("The OffsetTime to compare actual with should not be null");
+ }
+
+ /**
+ * Verifies that actual and given {@code OffsetTime} have same hour, minute and second fields (nanosecond fields are
+ * ignored in comparison).
+ * + * Assertion can fail with OffsetTimes in same chronological nanosecond time window, e.g : + *
+ * 23:00:01.000000000+01:00 and 23:00:00.999999999+01:00. + *
+ * Assertion fails as second fields differ even if time difference is only 1ns. + *
+ * Code example : + *
+ * + *
+ * // successful assertions
+ * OffsetTime OffsetTime1 = OffsetTime.of(12, 0, 1, 0, ZoneOffset.UTC);
+ * OffsetTime OffsetTime2 = OffsetTime.of(12, 0, 1, 456, ZoneOffset.UTC);
+ * assertThat(OffsetTime1).isEqualToIgnoringNanos(OffsetTime2);
+ *
+ * // failing assertions (even if time difference is only 1ns)
+ * OffsetTime OffsetTimeA = OffsetTime.of(12, 0, 1, 0, ZoneOffset.UTC);
+ * OffsetTime OffsetTimeB = OffsetTime.of(12, 0, 0, 999999999, ZoneOffset.UTC);
+ * assertThat(OffsetTimeA).isEqualToIgnoringNanos(OffsetTimeB);
+ *
+ *
+ * @param other the given {@link java.time.OffsetTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
+ * @throws IllegalArgumentException if other {@code OffsetTime} is {@code null}.
+ * @throws AssertionError if the actual {@code OffsetTime} is not equal with nanoseconds ignored.
+ */
+ public S isEqualToIgnoringNanos(OffsetTime other) {
+ Objects.instance().assertNotNull(info, actual);
+ assertOffsetTimeParameterIsNotNull(other);
+ if (!areEqualIgnoringNanos(actual, other)) {
+ throw Failures.instance().failure(info, shouldBeEqualIgnoringNanos(actual, other));
}
-
- /**
- * Check that the {@link java.time.OffsetTime} to compare actual {@link java.time.OffsetTime} to is not null, in that case throws a
- * {@link IllegalArgumentException} with an explicit message
- *
- * @param other the {@link java.time.OffsetTime} to check
- * @throws IllegalArgumentException with an explicit message if the given {@link java.time.OffsetTime} is null
- */
- private static void assertOffsetTimeParameterIsNotNull(OffsetTime other) {
- if (other == null)
- throw new IllegalArgumentException("The OffsetTime to compare actual with should not be null");
- }
-
- /**
- * Verifies that actual and given {@code OffsetTime} have same hour, minute and second fields (nanosecond fields are
- * ignored in comparison).
- * - * Assertion can fail with OffsetTimes in same chronological nanosecond time window, e.g : - *
- * 23:00:01.000000000 and 23:00:00.999999999. - *
- * Assertion fails as second fields differ even if time difference is only 1ns. - *
- * Code example : - *
- *
- * // successful assertions
- * OffsetTime OffsetTime1 = OffsetTime.of(12, 0, 1, 0, ZoneOffset.UTC);
- * OffsetTime OffsetTime2 = OffsetTime.of(12, 0, 1, 456, ZoneOffset.UTC);
- * assertThat(OffsetTime1).isEqualToIgnoringNanos(OffsetTime2);
- *
- * // failing assertions (even if time difference is only 1ns)
- * OffsetTime OffsetTimeA = OffsetTime.of(12, 0, 1, 0, ZoneOffset.UTC);
- * OffsetTime OffsetTimeB = OffsetTime.of(12, 0, 0, 999999999, ZoneOffset.UTC);
- * assertThat(OffsetTimeA).isEqualToIgnoringNanos(OffsetTimeB);
- *
- *
- * @param other the given {@link java.time.OffsetTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
- * @throws IllegalArgumentException if other {@code OffsetTime} is {@code null}.
- * @throws AssertionError if the actual {@code OffsetTime} is not equal with nanoseconds ignored.
- */
- public S isEqualToIgnoringNanos(OffsetTime other) {
- Objects.instance().assertNotNull(info, actual);
- assertOffsetTimeParameterIsNotNull(other);
- if (!areEqualIgnoringNanos(actual, other)) {
- throw Failures.instance().failure(info, shouldBeEqualIgnoringNanos(actual, other));
- }
- return myself;
+ return myself;
+ }
+
+ /**
+ * Verifies that actual and given {@link java.time.OffsetTime} have same hour and minute fields (second and nanosecond
+ * fields are
+ * ignored in comparison).
+ * + * Assertion can fail with OffsetTimes in same chronological second time window, e.g : + *
+ * 23:01:00.000+01:00 and 23:00:59.000+01:00. + *
+ * Assertion fails as minute fields differ even if time difference is only 1s. + *
+ * Code example : + *
+ * + *
+ * // successful assertions
+ * OffsetTime OffsetTime1 = OffsetTime.of(23, 50, 0, 0, ZoneOffset.UTC);
+ * OffsetTime OffsetTime2 = OffsetTime.of(23, 50, 10, 456, ZoneOffset.UTC);
+ * assertThat(OffsetTime1).isEqualToIgnoringSeconds(OffsetTime2);
+ *
+ * // failing assertions (even if time difference is only 1ms)
+ * OffsetTime OffsetTimeA = OffsetTime.of(23, 50, 00, 000, ZoneOffset.UTC);
+ * OffsetTime OffsetTimeB = OffsetTime.of(23, 49, 59, 999, ZoneOffset.UTC);
+ * assertThat(OffsetTimeA).isEqualToIgnoringSeconds(OffsetTimeB);
+ *
+ *
+ * @param other the given {@link java.time.OffsetTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
+ * @throws IllegalArgumentException if other {@code OffsetTime} is {@code null}.
+ * @throws AssertionError if the actual {@code OffsetTime} is not equal with second and nanosecond fields
+ * ignored.
+ */
+ public S isEqualToIgnoringSeconds(OffsetTime other) {
+ Objects.instance().assertNotNull(info, actual);
+ assertOffsetTimeParameterIsNotNull(other);
+ if (!areEqualIgnoringSeconds(actual, other)) {
+ throw Failures.instance().failure(info, shouldBeEqualIgnoringSeconds(actual, other));
}
-
- /**
- * Verifies that actual and given {@link java.time.OffsetTime} have same hour and minute fields (second and nanosecond fields are
- * ignored in comparison).
- * - * Assertion can fail with OffsetTimes in same chronological second time window, e.g : - *
- * 23:01:00.000 and 23:00:59.000. - *
- * Assertion fails as minute fields differ even if time difference is only 1s. - *
- * Code example : - *
- *
- * // successful assertions
- * OffsetTime OffsetTime1 = OffsetTime.of(23, 50, 0, 0, ZoneOffset.UTC);
- * OffsetTime OffsetTime2 = OffsetTime.of(23, 50, 10, 456, ZoneOffset.UTC);
- * assertThat(OffsetTime1).isEqualToIgnoringSeconds(OffsetTime2);
- *
- * // failing assertions (even if time difference is only 1ms)
- * OffsetTime OffsetTimeA = OffsetTime.of(23, 50, 00, 000, ZoneOffset.UTC);
- * OffsetTime OffsetTimeB = OffsetTime.of(23, 49, 59, 999, ZoneOffset.UTC);
- * assertThat(OffsetTimeA).isEqualToIgnoringSeconds(OffsetTimeB);
- *
- *
- * @param other the given {@link java.time.OffsetTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
- * @throws IllegalArgumentException if other {@code OffsetTime} is {@code null}.
- * @throws AssertionError if the actual {@code OffsetTime} is not equal with second and nanosecond fields
- * ignored.
- */
- public S isEqualToIgnoringSeconds(OffsetTime other) {
- Objects.instance().assertNotNull(info, actual);
- assertOffsetTimeParameterIsNotNull(other);
- if (!areEqualIgnoringSeconds(actual, other)) {
- throw Failures.instance().failure(info, shouldBeEqualIgnoringSeconds(actual, other));
- }
- return myself;
+ return myself;
+ }
+
+ /**
+ * Verifies that actual and given {@link java.time.OffsetTime} have same hour, minute, second and nanosecond fields).
+ * + * Code examples : + *
+ * + *
+ * // successful assertions
+ * OffsetTime offsetTime = OffsetTime.of(12, 0, 0, 0, ZoneOffset.UTC);
+ * OffsetTime offsetTime2 = OffsetTime.of(12, 0, 0, 0, ZoneOffset.MAX);
+ * assertThat(offsetTime).isEqualToIgnoringTimezone(offsetTime2);
+ *
+ * // failing assertions (even if time difference is only 1ms)
+ * OffsetTime offsetTime = OffsetTime.of(12, 0, 0, 0, ZoneOffset.UTC);
+ * OffsetTime offsetTime2 = OffsetTime.of(12, 1, 0, 0, ZoneOffset.UTC);
+ * assertThat(offsetTime).isEqualToIgnoringTimezone(offsetTime2);
+ *
+ *
+ * @param other the given {@link java.time.OffsetTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
+ * @throws IllegalArgumentException if other {@code OffsetTime} is {@code null}.
+ * @throws AssertionError if the actual {@code OffsetTime} is not equal with timezone ignored.
+ */
+ public S isEqualToIgnoringTimezone(OffsetTime other) {
+ Objects.instance().assertNotNull(info, actual);
+ assertOffsetTimeParameterIsNotNull(other);
+ if (!areEqualIgnoringTimezone(actual, other)) {
+ throw Failures.instance().failure(info, shouldBeEqualIgnoringTimezone(actual, other));
}
-
- /**
- * Verifies that actual and given {@link java.time.OffsetTime} have same hour, minute, second and nanosecond fields).
- * - * Code example : - *
- *
- * // successful assertions
- * OffsetTime offsetTime = OffsetTime.of(12, 0, 0, 0, ZoneOffset.UTC);
- * OffsetTime offsetTime2 = OffsetTime.of(12, 0, 0, 0, ZoneOffset.MAX);
- * assertThat(offsetTime).isEqualToIgnoringTimezone(offsetTime2);
- *
- * // failing assertions (even if time difference is only 1ms)
- * OffsetTime offsetTime = OffsetTime.of(12, 0, 0, 0, ZoneOffset.UTC);
- * OffsetTime offsetTime2 = OffsetTime.of(12, 1, 0, 0, ZoneOffset.UTC);
- * assertThat(offsetTime).isEqualToIgnoringTimezone(null);
- * assertThat((OffsetTime)null).isEqualToIgnoringTimezone(null);
- * assertThat(offsetTime).isEqualToIgnoringTimezone(offsetTime2);
- *
- *
- * @param other the given {@link java.time.OffsetTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
- * @throws IllegalArgumentException if other {@code OffsetTime} is {@code null}.
- * @throws AssertionError if the actual {@code OffsetTime} is not equal with timezone ignored.
- */
- public S isEqualToIgnoringTimezone(OffsetTime other) {
- Objects.instance().assertNotNull(info, actual);
- assertOffsetTimeParameterIsNotNull(other);
- if (!areEqualIgnoringTimezone(actual, other)) {
- throw Failures.instance().failure(info, shouldBeEqualIgnoringTimezone(actual, other));
- }
- return myself;
- }
-
- /**
- * Verifies that actual and given {@code OffsetTime} have same hour fields (minute, second and nanosecond fields are
- * ignored in comparison).
- * - * Assertion can fail with OffsetTimes in same chronological second time window, e.g : - *
- * 01:00:00.000 and 00:59:59.000. - *
- * Time difference is only 1s but hour fields differ. - *
- * Code example : - *
- *
- * // successful assertions
- * OffsetTime OffsetTime1 = OffsetTime.of(23, 50, 0, 0, ZoneOffset.UTC);
- * OffsetTime OffsetTime2 = OffsetTime.of(23, 00, 2, 7, ZoneOffset.UTC);
- * assertThat(OffsetTime1).hasSameHourAs(OffsetTime2);
- *
- * // failing assertions (even if time difference is only 1ms)
- * OffsetTime OffsetTimeA = OffsetTime.of(01, 00, 00, 000, ZoneOffset.UTC);
- * OffsetTime OffsetTimeB = OffsetTime.of(00, 59, 59, 999, ZoneOffset.UTC);
- * assertThat(OffsetTimeA).hasSameHourAs(OffsetTimeB);
- *
- *
- * @param other the given {@link java.time.OffsetTime}.
- * @return this assertion object.
- * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
- * @throws IllegalArgumentException if other {@code OffsetTime} is {@code null}.
- * @throws AssertionError if the actual {@code OffsetTime} is not equal ignoring minute, second and nanosecond
- * fields.
- */
- public S hasSameHourAs(OffsetTime other) {
- Objects.instance().assertNotNull(info, actual);
- assertOffsetTimeParameterIsNotNull(other);
- if (!haveSameHourField(actual, other)) {
- throw Failures.instance().failure(info, shouldHaveSameHourAs(actual, other));
- }
- return myself;
- }
-
- /**
- * Returns true if both OffsetTime are in the same hour, minute and second, false
- * otherwise.
- *
- * @param actual the actual OffsetTime. expected not be null
- * @param other the other OffsetTime. expected not be null
- * @return true if both OffsetTime are in the same year, month and day of month, hour, minute and second, false
- * otherwise.
- */
- private static boolean areEqualIgnoringNanos(OffsetTime actual, OffsetTime other) {
- return areEqualIgnoringSeconds(actual, other) && haveSameSecond(actual, other);
- }
-
- /**
- * Returns true if both OffsetTime are in the same hour and minute, false otherwise.
- *
- * @param actual the actual OffsetTime. expected not be null
- * @param other the other OffsetTime. expected not be null
- * @return true if both OffsetTime are in the same hour and minute, false otherwise.
- */
- private static boolean areEqualIgnoringSeconds(OffsetTime actual, OffsetTime other) {
- return haveSameHourField(actual, other) && haveSameMinute(actual, other);
- }
-
- /**
- * Returns true if both OffsetTime are in the same hour, minute, second and nanosecond false otherwise.
- *
- * @param actual the actual OffsetTime. expected not be null
- * @param other the other OffsetTime. expected not be null
- * @return true if both OffsetTime are in the same hour, minute, second and nanosecond false otherwise.
- */
- private static boolean areEqualIgnoringTimezone(OffsetTime actual, OffsetTime other) {
- return areEqualIgnoringNanos(actual, other) && haveSameNano(actual, other);
- }
-
- private static boolean haveSameNano(OffsetTime actual, OffsetTime other) {
- return actual.getNano() == other.getNano();
- }
-
- private static boolean haveSameSecond(OffsetTime actual, OffsetTime other) {
- return actual.getSecond() == other.getSecond();
- }
-
- private static boolean haveSameMinute(OffsetTime actual, OffsetTime other) {
- return actual.getMinute() == other.getMinute();
- }
-
- private static boolean haveSameHourField(OffsetTime actual, OffsetTime other) {
- return actual.getHour() == other.getHour();
+ return myself;
+ }
+
+ /**
+ * Verifies that actual and given {@code OffsetTime} have same hour fields (minute, second and nanosecond fields are
+ * ignored in comparison).
+ * + * Assertion can fail with OffsetTimes in same chronological second time window, e.g : + *
+ * 01:00:00.000+01:00 and 00:59:59.000+01:00. + *
+ * Time difference is only 1s but hour fields differ. + *
+ * Code example : + *
+ * + *
+ * // successful assertions
+ * OffsetTime OffsetTime1 = OffsetTime.of(23, 50, 0, 0, ZoneOffset.UTC);
+ * OffsetTime OffsetTime2 = OffsetTime.of(23, 00, 2, 7, ZoneOffset.UTC);
+ * assertThat(OffsetTime1).hasSameHourAs(OffsetTime2);
+ *
+ * // failing assertions (even if time difference is only 1ms)
+ * OffsetTime OffsetTimeA = OffsetTime.of(01, 00, 00, 000, ZoneOffset.UTC);
+ * OffsetTime OffsetTimeB = OffsetTime.of(00, 59, 59, 999, ZoneOffset.UTC);
+ * assertThat(OffsetTimeA).hasSameHourAs(OffsetTimeB);
+ *
+ *
+ * @param other the given {@link java.time.OffsetTime}.
+ * @return this assertion object.
+ * @throws AssertionError if the actual {@code OffsetTime} is {@code null}.
+ * @throws IllegalArgumentException if other {@code OffsetTime} is {@code null}.
+ * @throws AssertionError if the actual {@code OffsetTime} is not equal ignoring minute, second and nanosecond
+ * fields.
+ */
+ public S hasSameHourAs(OffsetTime other) {
+ Objects.instance().assertNotNull(info, actual);
+ assertOffsetTimeParameterIsNotNull(other);
+ if (!haveSameHourField(actual, other)) {
+ throw Failures.instance().failure(info, shouldHaveSameHourAs(actual, other));
}
+ return myself;
+ }
+
+ /**
+ * Returns true if both OffsetTime are in the same hour, minute and second, false
+ * otherwise.
+ *
+ * @param actual the actual OffsetTime. expected not be null
+ * @param other the other OffsetTime. expected not be null
+ * @return true if both OffsetTime are in the same year, month and day of month, hour, minute and second, false
+ * otherwise.
+ */
+ private static boolean areEqualIgnoringNanos(OffsetTime actual, OffsetTime other) {
+ return areEqualIgnoringSeconds(actual, other) && haveSameSecond(actual, other);
+ }
+
+ /**
+ * Returns true if both OffsetTime are in the same hour and minute, false otherwise.
+ *
+ * @param actual the actual OffsetTime. expected not be null
+ * @param other the other OffsetTime. expected not be null
+ * @return true if both OffsetTime are in the same hour and minute, false otherwise.
+ */
+ private static boolean areEqualIgnoringSeconds(OffsetTime actual, OffsetTime other) {
+ return haveSameHourField(actual, other) && haveSameMinute(actual, other);
+ }
+
+ /**
+ * Returns true if both OffsetTime are in the same hour, minute, second and nanosecond false otherwise.
+ *
+ * @param actual the actual OffsetTime. expected not be null
+ * @param other the other OffsetTime. expected not be null
+ * @return true if both OffsetTime are in the same hour, minute, second and nanosecond false otherwise.
+ */
+ private static boolean areEqualIgnoringTimezone(OffsetTime actual, OffsetTime other) {
+ return areEqualIgnoringNanos(actual, other) && haveSameNano(actual, other);
+ }
+
+ private static boolean haveSameNano(OffsetTime actual, OffsetTime other) {
+ return actual.getNano() == other.getNano();
+ }
+
+ private static boolean haveSameSecond(OffsetTime actual, OffsetTime other) {
+ return actual.getSecond() == other.getSecond();
+ }
+
+ private static boolean haveSameMinute(OffsetTime actual, OffsetTime other) {
+ return actual.getMinute() == other.getMinute();
+ }
+
+ private static boolean haveSameHourField(OffsetTime actual, OffsetTime other) {
+ return actual.getHour() == other.getHour();
+ }
}
\ No newline at end of file
diff --git a/src/main/java/org/assertj/core/api/Assertions.java b/src/main/java/org/assertj/core/api/Assertions.java
index cebe849f9fc..7d78224b6f5 100644
--- a/src/main/java/org/assertj/core/api/Assertions.java
+++ b/src/main/java/org/assertj/core/api/Assertions.java
@@ -92,12 +92,11 @@
*/
public class Assertions {
-
/**
* Create assertion for {@link java.util.Optional}.
*
* @param optional the actual value.
- * @param {@link BigDecimalAssert}
.
*
* @param actual the actual value.
@@ -360,7 +348,7 @@ public static AbstractFileAssert> assertThat(File actual) {
* @param actual the path to test
* @return the created assertion object
*/
- public static AbstractPathAssert> assertThat(Path actual) {
+ public static AbstractPathAssert> assertThat(Path actual) {
return new PathAssert(actual);
}
@@ -670,9 +658,19 @@ public static AbstractLocalDateTimeAssert> assertThat(LocalDateTime localDateT
* @return the created assertion object.
*/
public static AbstractOffsetDateTimeAssert> assertThat(OffsetDateTime actual) {
- return new OffsetDateTimeAssert(actual);
+ return new OffsetDateTimeAssert(actual);
}
-
+
+ /**
+ * Create assertion for {@link java.time.OffsetTime}.
+ *
+ * @param actual the actual value.
+ * @return the created assertion object.
+ */
+ public static AbstractOffsetTimeAssert> assertThat(OffsetTime offsetTime) {
+ return new OffsetTimeAssert(offsetTime);
+ }
+
/**
* Creates a new instance of {@link LocalTimeAssert}
.
*
@@ -680,9 +678,9 @@ public static AbstractOffsetDateTimeAssert> assertThat(OffsetDateTime actual)
* @return the created assertion object.
*/
public static AbstractLocalTimeAssert> assertThat(LocalTime actual) {
- return new LocalTimeAssert(actual);
+ return new LocalTimeAssert(actual);
}
-
+
/**
* Creates a new instance of {@link LocalDateAssert}
.
*
@@ -690,9 +688,9 @@ public static AbstractLocalTimeAssert> assertThat(LocalTime actual) {
* @return the created assertion object.
*/
public static AbstractLocalDateAssert> assertThat(LocalDate localDate) {
- return new LocalDateAssert(localDate);
+ return new LocalDateAssert(localDate);
}
-
+
/**
* Creates a new instance of {@link ThrowableAssert}
.
*
diff --git a/src/test/java/org/assertj/core/api/Assertions_assertThat_with_OffsetTime_Test.java b/src/test/java/org/assertj/core/api/Assertions_assertThat_with_OffsetTime_Test.java
index 6a874e88cd9..d0799a0e324 100644
--- a/src/test/java/org/assertj/core/api/Assertions_assertThat_with_OffsetTime_Test.java
+++ b/src/test/java/org/assertj/core/api/Assertions_assertThat_with_OffsetTime_Test.java
@@ -36,13 +36,13 @@ public void before() {
@Test
public void should_create_Assert() {
- OffsetTimeAssert assertions = Assertions.assertThat(actual);
+ AbstractOffsetTimeAssert> assertions = Assertions.assertThat(actual);
assertNotNull(assertions);
}
@Test
public void should_pass_actual() {
- OffsetTimeAssert assertions = Assertions.assertThat(actual);
+ AbstractOffsetTimeAssert> assertions = Assertions.assertThat(actual);
assertSame(actual, assertions.actual);
}
}
diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssertBaseTest.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssertBaseTest.java
index 1866448ad6f..f95b6dfa1cf 100644
--- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssertBaseTest.java
+++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssertBaseTest.java
@@ -41,10 +41,11 @@ public class OffsetDateTimeAssertBaseTest extends BaseTest {
@DataPoint
public static OffsetDateTime offsetDateTime6 = OffsetDateTime.of(2000, 12, 14, 22, 15, 15, 876, ZoneOffset.UTC);
- protected static void testAssumptions(OffsetDateTime reference, OffsetDateTime dateBefore,
- OffsetDateTime dateAfter) {
- assumeTrue(dateBefore.isBefore(reference));
- assumeTrue(dateAfter.isAfter(reference));
+ protected static void testAssumptions(OffsetDateTime reference, OffsetDateTime before, OffsetDateTime equal,
+ OffsetDateTime after) {
+ assumeTrue(before.isBefore(reference));
+ assumeTrue(equal.isEqual(reference));
+ assumeTrue(after.isAfter(reference));
}
}
\ No newline at end of file
diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isAfterOrEqualTo_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isAfterOrEqualTo_Test.java
index 5d35a1eb625..51da983d875 100644
--- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isAfterOrEqualTo_Test.java
+++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isAfterOrEqualTo_Test.java
@@ -12,6 +12,7 @@
*/
package org.assertj.core.api.offsetdatetime;
+import static java.lang.String.format;
import static java.time.OffsetDateTime.of;
import static java.time.ZoneOffset.UTC;
import static org.assertj.core.api.Assertions.assertThat;
@@ -34,15 +35,17 @@
public class OffsetDateTimeAssert_isAfterOrEqualTo_Test extends OffsetDateTimeAssertBaseTest {
@Theory
- public void test_isAfterOrEqual_assertion(OffsetDateTime referenceDate, OffsetDateTime dateBefore,
+ public void test_isAfterOrEqual_assertion(OffsetDateTime reference, OffsetDateTime dateBefore, OffsetDateTime dateEqual,
OffsetDateTime dateAfter) {
// GIVEN
- testAssumptions(referenceDate, dateBefore, dateAfter);
+ testAssumptions(reference, dateBefore, dateEqual, dateAfter);
// WHEN
- assertThat(dateAfter).isAfterOrEqualTo(referenceDate);
- assertThat(referenceDate).isAfterOrEqualTo(referenceDate);
+ assertThat(dateAfter).isAfterOrEqualTo(reference);
+ assertThat(dateAfter).isAfterOrEqualTo(reference.toString());
+ assertThat(dateEqual).isAfterOrEqualTo(reference);
+ assertThat(dateEqual).isAfterOrEqualTo(reference.toString());
// THEN
- verify_that_isAfterOrEqual_assertion_fails_and_throws_AssertionError(dateBefore, referenceDate);
+ verify_that_isAfterOrEqual_assertion_fails_and_throws_AssertionError(dateBefore, reference);
}
@Test
@@ -50,11 +53,11 @@ public void test_isAfterOrEqual_assertion_error_message() {
try {
assertThat(of(2000, 1, 5, 3, 0, 5, 0, UTC)).isAfterOrEqualTo(of(2012, 1, 1, 3, 3, 3, 0, UTC));
} catch (AssertionError e) {
- assertThat(e).hasMessage("\n" +
- "Expecting:\n" +
- " <2000-01-05T03:00:05Z>\n" +
- "to be after or equals to:\n" +
- " <2012-01-01T03:03:03Z>");
+ assertThat(e).hasMessage(format("%n" +
+ "Expecting:%n" +
+ " <2000-01-05T03:00:05Z>%n" +
+ "to be after or equals to:%n" +
+ " <2012-01-01T03:03:03Z>"));
return;
}
fail("Should have thrown AssertionError");
diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isAfter_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isAfter_Test.java
index a0ccc3f18cb..018dc5e77e1 100644
--- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isAfter_Test.java
+++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isAfter_Test.java
@@ -12,6 +12,7 @@
*/
package org.assertj.core.api.offsetdatetime;
+import static java.lang.String.format;
import static java.time.OffsetDateTime.parse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
@@ -33,9 +34,10 @@
public class OffsetDateTimeAssert_isAfter_Test extends OffsetDateTimeAssertBaseTest {
@Theory
- public void test_isAfter_assertion(OffsetDateTime referenceDate, OffsetDateTime dateBefore, OffsetDateTime dateAfter) {
+ public void test_isAfter_assertion(OffsetDateTime referenceDate, OffsetDateTime dateBefore, OffsetDateTime dateEqual,
+ OffsetDateTime dateAfter) {
// GIVEN
- testAssumptions(referenceDate, dateBefore, dateAfter);
+ testAssumptions(referenceDate, dateBefore, dateEqual, dateAfter);
// WHEN
assertThat(dateAfter).isAfter(referenceDate);
assertThat(dateAfter).isAfter(referenceDate.toString());
@@ -49,11 +51,11 @@ public void test_isAfter_assertion_error_message() {
try {
assertThat(parse("2000-01-01T03:00:05.123Z")).isAfter(parse("2000-01-01T03:00:05.123456789Z"));
} catch (AssertionError e) {
- assertThat(e).hasMessage("\n" +
- "Expecting:\n" +
- " <2000-01-01T03:00:05.123Z>\n" +
- "to be strictly after:\n" +
- " <2000-01-01T03:00:05.123456789Z>");
+ assertThat(e).hasMessage(format("%n" +
+ "Expecting:%n" +
+ " <2000-01-01T03:00:05.123Z>%n" +
+ "to be strictly after:%n" +
+ " <2000-01-01T03:00:05.123456789Z>"));
return;
}
fail("Should have thrown AssertionError");
diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isBeforeOrEqualTo_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isBeforeOrEqualTo_Test.java
index c3fc632a06a..21ca3b02b7d 100644
--- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isBeforeOrEqualTo_Test.java
+++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isBeforeOrEqualTo_Test.java
@@ -12,6 +12,7 @@
*/
package org.assertj.core.api.offsetdatetime;
+import static java.lang.String.format;
import static java.time.OffsetDateTime.of;
import static java.time.ZoneOffset.UTC;
import static org.assertj.core.api.Assertions.assertThat;
@@ -34,15 +35,17 @@
public class OffsetDateTimeAssert_isBeforeOrEqualTo_Test extends OffsetDateTimeAssertBaseTest {
@Theory
- public void test_isBeforeOrEqual_assertion(OffsetDateTime referenceDate, OffsetDateTime dateBefore,
- OffsetDateTime dateAfter) {
+ public void test_isBeforeOrEqual_assertion(OffsetDateTime reference, OffsetDateTime dateBefore,
+ OffsetDateTime dateEqual, OffsetDateTime dateAfter) {
// GIVEN
- testAssumptions(referenceDate, dateBefore, dateAfter);
+ testAssumptions(reference, dateBefore, dateEqual, dateAfter);
// WHEN
- assertThat(dateBefore).isBeforeOrEqualTo(referenceDate);
- assertThat(referenceDate).isBeforeOrEqualTo(referenceDate);
+ assertThat(dateBefore).isBeforeOrEqualTo(reference);
+ assertThat(dateBefore).isBeforeOrEqualTo(reference.toString());
+ assertThat(dateEqual).isBeforeOrEqualTo(reference);
+ assertThat(dateEqual).isBeforeOrEqualTo(reference.toString());
// THEN
- verify_that_isBeforeOrEqual_assertion_fails_and_throws_AssertionError(dateAfter, referenceDate);
+ verify_that_isBeforeOrEqual_assertion_fails_and_throws_AssertionError(dateAfter, reference);
}
@Test
@@ -50,8 +53,10 @@ public void test_isBeforeOrEqual_assertion_error_message() {
try {
assertThat(of(2000, 1, 5, 3, 0, 5, 0, UTC)).isBeforeOrEqualTo(of(1998, 1, 1, 3, 3, 3, 0, UTC));
} catch (AssertionError e) {
- assertThat(e).hasMessage(
- "\nExpecting:\n <2000-01-05T03:00:05Z>\nto be before or equals to:\n <1998-01-01T03:03:03Z>");
+ assertThat(e).hasMessage(format("%nExpecting:%n" +
+ " <2000-01-05T03:00:05Z>%n" +
+ "to be before or equals to:%n" +
+ " <1998-01-01T03:03:03Z>"));
return;
}
fail("Should have thrown AssertionError");
diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isBefore_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isBefore_Test.java
index 385eea53603..a14500807fb 100644
--- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isBefore_Test.java
+++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isBefore_Test.java
@@ -12,6 +12,7 @@
*/
package org.assertj.core.api.offsetdatetime;
+import static java.lang.String.format;
import static java.time.OffsetDateTime.of;
import static java.time.ZoneOffset.UTC;
import static org.assertj.core.api.Assertions.assertThat;
@@ -34,14 +35,16 @@
public class OffsetDateTimeAssert_isBefore_Test extends OffsetDateTimeAssertBaseTest {
@Theory
- public void test_isBefore_assertion(OffsetDateTime referenceDate, OffsetDateTime dateBefore, OffsetDateTime dateAfter) {
+ public void test_isBefore_assertion(OffsetDateTime reference, OffsetDateTime dateBefore, OffsetDateTime dateEqual,
+ OffsetDateTime dateAfter) {
// GIVEN
- testAssumptions(referenceDate, dateBefore, dateAfter);
+ testAssumptions(reference, dateBefore, dateEqual, dateAfter);
// WHEN
- assertThat(dateBefore).isBefore(referenceDate);
+ assertThat(dateBefore).isBefore(reference);
+ assertThat(dateBefore).isBefore(reference.toString());
// THEN
- verify_that_isBefore_assertion_fails_and_throws_AssertionError(referenceDate, referenceDate);
- verify_that_isBefore_assertion_fails_and_throws_AssertionError(dateAfter, referenceDate);
+ verify_that_isBefore_assertion_fails_and_throws_AssertionError(reference, reference);
+ verify_that_isBefore_assertion_fails_and_throws_AssertionError(dateAfter, reference);
}
@Test
@@ -49,7 +52,10 @@ public void test_isBefore_assertion_error_message() {
try {
assertThat(of(2000, 1, 5, 3, 0, 5, 0, UTC)).isBefore(of(1998, 1, 1, 3, 3, 3, 0, UTC));
} catch (AssertionError e) {
- assertThat(e).hasMessage("\nExpecting:\n <2000-01-05T03:00:05Z>\nto be strictly before:\n <1998-01-01T03:03:03Z>");
+ assertThat(e).hasMessage(format("%nExpecting:%n" +
+ " <2000-01-05T03:00:05Z>%n" +
+ "to be strictly before:%n" +
+ " <1998-01-01T03:03:03Z>"));
return;
}
fail("Should have thrown AssertionError");
diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualToIgnoringHours_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualToIgnoringHours_Test.java
index dbb0ce6c61d..b2f82627eb9 100644
--- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualToIgnoringHours_Test.java
+++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualToIgnoringHours_Test.java
@@ -12,6 +12,7 @@
*/
package org.assertj.core.api.offsetdatetime;
+import static java.lang.String.format;
import static java.time.OffsetDateTime.of;
import static java.time.ZoneOffset.UTC;
import static org.assertj.core.api.AbstractOffsetDateTimeAssert.NULL_OFFSET_DATE_TIME_PARAMETER_MESSAGE;
@@ -37,9 +38,11 @@ public void should_fail_if_actual_is_not_equal_to_given_offsetdatetime_with_hour
try {
assertThat(refOffsetDateTime).isEqualToIgnoringHours(refOffsetDateTime.minusHours(1));
} catch (AssertionError e) {
- assertThat(e.getMessage())
- .isEqualTo(
- "\nExpecting:\n <2000-01-02T00:00Z>\nto have same year, month and day as:\n <2000-01-01T23:00Z>\nbut had not.");
+ assertThat(e).hasMessage(format("%n" +
+ "Expecting:%n" +
+ " <2000-01-02T00:00Z>%n" +
+ "to have same year, month and day as:%n" +
+ " <2000-01-01T23:00Z>%nbut had not."));
return;
}
failBecauseExpectedAssertionErrorWasNotThrown();
@@ -50,9 +53,12 @@ public void should_fail_as_hours_fields_are_different_even_if_time_difference_is
try {
assertThat(refOffsetDateTime).isEqualToIgnoringHours(refOffsetDateTime.minusNanos(1));
} catch (AssertionError e) {
- assertThat(e.getMessage())
- .isEqualTo(
- "\nExpecting:\n <2000-01-02T00:00Z>\nto have same year, month and day as:\n <2000-01-01T23:59:59.999999999Z>\nbut had not.");
+ assertThat(e).hasMessage(format("%n" +
+ "Expecting:%n" +
+ " <2000-01-02T00:00Z>%n" +
+ "to have same year, month and day as:%n" +
+ " <2000-01-01T23:59:59.999999999Z>%n" +
+ "but had not."));
return;
}
failBecauseExpectedAssertionErrorWasNotThrown();
diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualToIgnoringMinutes_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualToIgnoringMinutes_Test.java
index f34b505ff35..2a7ef9f9508 100644
--- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualToIgnoringMinutes_Test.java
+++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualToIgnoringMinutes_Test.java
@@ -12,6 +12,7 @@
*/
package org.assertj.core.api.offsetdatetime;
+import static java.lang.String.format;
import static java.time.OffsetDateTime.of;
import static java.time.ZoneOffset.UTC;
import static org.assertj.core.api.AbstractOffsetDateTimeAssert.NULL_OFFSET_DATE_TIME_PARAMETER_MESSAGE;
@@ -37,9 +38,11 @@ public void should_fail_if_actual_is_not_equal_to_given_offsetdatetime_with_minu
try {
assertThat(refOffsetDateTime).isEqualToIgnoringMinutes(refOffsetDateTime.minusMinutes(1));
} catch (AssertionError e) {
- assertThat(e.getMessage())
- .isEqualTo(
- "\nExpecting:\n <2000-01-01T23:00Z>\nto have same year, month, day and hour as:\n <2000-01-01T22:59Z>\nbut had not.");
+ assertThat(e).hasMessage(format("%n" +
+ "Expecting:%n" +
+ " <2000-01-01T23:00Z>%n" +
+ "to have same year, month, day and hour as:%n" +
+ " <2000-01-01T22:59Z>%nbut had not."));
return;
}
failBecauseExpectedAssertionErrorWasNotThrown();
@@ -50,9 +53,11 @@ public void should_fail_as_minutes_fields_are_different_even_if_time_difference_
try {
assertThat(refOffsetDateTime).isEqualToIgnoringMinutes(refOffsetDateTime.minusNanos(1));
} catch (AssertionError e) {
- assertThat(e.getMessage())
- .isEqualTo(
- "\nExpecting:\n <2000-01-01T23:00Z>\nto have same year, month, day and hour as:\n <2000-01-01T22:59:59.999999999Z>\nbut had not.");
+ assertThat(e).hasMessage(format("%n" +
+ "Expecting:%n" +
+ " <2000-01-01T23:00Z>%n" +
+ "to have same year, month, day and hour as:%n" +
+ " <2000-01-01T22:59:59.999999999Z>%nbut had not."));
return;
}
failBecauseExpectedAssertionErrorWasNotThrown();
diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualToIgnoringNanoseconds_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualToIgnoringNanoseconds_Test.java
index f29e1190e9a..feb892b9220 100644
--- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualToIgnoringNanoseconds_Test.java
+++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualToIgnoringNanoseconds_Test.java
@@ -12,6 +12,7 @@
*/
package org.assertj.core.api.offsetdatetime;
+import static java.lang.String.format;
import static java.time.OffsetDateTime.of;
import static java.time.ZoneOffset.UTC;
import static org.assertj.core.api.AbstractOffsetDateTimeAssert.NULL_OFFSET_DATE_TIME_PARAMETER_MESSAGE;
@@ -38,22 +39,27 @@ public void should_fail_if_actual_is_not_equal_to_given_offsetdatetime_with_nano
try {
assertThat(refOffsetDateTime).isEqualToIgnoringNanos(refOffsetDateTime.plusSeconds(1));
} catch (AssertionError e) {
- assertThat(e.getMessage())
- .isEqualTo(
- "\nExpecting:\n <2000-01-01T00:00:01Z>\nto have same year, month, day, hour, minute and second as:\n <2000-01-01T00:00:02Z>\nbut had not.");
+ assertThat(e).hasMessage(format("%nExpecting:%n" +
+ " <2000-01-01T00:00:01Z>%n" +
+ "to have same year, month, day, hour, minute and second as:%n" +
+ " <2000-01-01T00:00:02Z>%nb" +
+ "ut had not."));
return;
}
failBecauseExpectedAssertionErrorWasNotThrown();
}
@Test
- public void should_fail_as_seconds_fields_are_different_even_if_time_difference_is_less_than_a_second() {
+ public void should_fail_as_seconds_fields_are_different() {
try {
assertThat(refOffsetDateTime).isEqualToIgnoringNanos(refOffsetDateTime.minusNanos(1));
} catch (AssertionError e) {
- assertThat(e.getMessage())
- .isEqualTo(
- "\nExpecting:\n <2000-01-01T00:00:01Z>\nto have same year, month, day, hour, minute and second as:\n <2000-01-01T00:00:00.999999999Z>\nbut had not.");
+ assertThat(e).hasMessage(format("%n" +
+ "Expecting:%n" +
+ " <2000-01-01T00:00:01Z>%n" +
+ "to have same year, month, day, hour, minute and second as:%n" +
+ " <2000-01-01T00:00:00.999999999Z>%n" +
+ "but had not."));
return;
}
failBecauseExpectedAssertionErrorWasNotThrown();
diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualToIgnoringSeconds_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualToIgnoringSeconds_Test.java
index 188c8bd11fb..38421712f6e 100644
--- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualToIgnoringSeconds_Test.java
+++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualToIgnoringSeconds_Test.java
@@ -12,6 +12,7 @@
*/
package org.assertj.core.api.offsetdatetime;
+import static java.lang.String.format;
import static java.time.ZoneOffset.UTC;
import static org.assertj.core.api.AbstractOffsetDateTimeAssert.NULL_OFFSET_DATE_TIME_PARAMETER_MESSAGE;
import static org.assertj.core.api.Assertions.assertThat;
@@ -36,9 +37,12 @@ public void should_fail_if_actual_is_not_equal_to_given_offsetdatetime_with_seco
try {
assertThat(refOffsetDateTime).isEqualToIgnoringSeconds(refOffsetDateTime.plusMinutes(1));
} catch (AssertionError e) {
- assertThat(e.getMessage())
- .isEqualTo(
- "\nExpecting:\n <2000-01-01T23:51Z>\nto have same year, month, day, hour and minute as:\n <2000-01-01T23:52Z>\nbut had not.");
+ assertThat(e).hasMessage(format("%n" +
+ "Expecting:%n" +
+ " <2000-01-01T23:51Z>%n" +
+ "to have same year, month, day, hour and minute as:%n" +
+ " <2000-01-01T23:52Z>%n" +
+ "but had not."));
return;
}
failBecauseExpectedAssertionErrorWasNotThrown();
@@ -49,9 +53,12 @@ public void should_fail_as_seconds_fields_are_different_even_if_time_difference_
try {
assertThat(refOffsetDateTime).isEqualToIgnoringSeconds(refOffsetDateTime.minusNanos(1));
} catch (AssertionError e) {
- assertThat(e.getMessage())
- .isEqualTo(
- "\nExpecting:\n <2000-01-01T23:51Z>\nto have same year, month, day, hour and minute as:\n <2000-01-01T23:50:59.999999999Z>\nbut had not.");
+ assertThat(e).hasMessage(format("%n" +
+ "Expecting:%n" +
+ " <2000-01-01T23:51Z>%n" +
+ "to have same year, month, day, hour and minute as:%n" +
+ " <2000-01-01T23:50:59.999999999Z>%n" +
+ "but had not."));
return;
}
failBecauseExpectedAssertionErrorWasNotThrown();
diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualToIgnoringTimezone_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualToIgnoringTimezone_Test.java
index e80f716cb2f..b616b8a68f6 100644
--- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualToIgnoringTimezone_Test.java
+++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualToIgnoringTimezone_Test.java
@@ -12,6 +12,7 @@
*/
package org.assertj.core.api.offsetdatetime;
+import static java.lang.String.format;
import static java.time.OffsetDateTime.of;
import static java.time.ZoneOffset.MAX;
import static java.time.ZoneOffset.UTC;
@@ -37,11 +38,11 @@ public void should_fail_if_actual_is_not_equal_to_given_OffsetDateTime_with_time
try {
assertThat(actual).isEqualToIgnoringTimezone(of(2000, 1, 5, 12, 1, 0, 0, UTC));
} catch (AssertionError e) {
- assertThat(e).hasMessage("\nExpecting:\n " +
- "<2000-01-05T12:00+18:00>\n" +
- "to have same time fields except timezone as:\n" +
- " <2000-01-05T12:01Z>\n" +
- "but had not.");
+ assertThat(e).hasMessage(format("%nExpecting:%n " +
+ "<2000-01-05T12:00+18:00>%n" +
+ "to have same time fields except timezone as:%n" +
+ " <2000-01-05T12:01Z>%n" +
+ "but had not."));
return;
}
failBecauseExpectedAssertionErrorWasNotThrown();
diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualTo_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualTo_Test.java
index b01863b140e..37ede1692d9 100644
--- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualTo_Test.java
+++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isEqualTo_Test.java
@@ -34,11 +34,15 @@
public class OffsetDateTimeAssert_isEqualTo_Test extends OffsetDateTimeAssertBaseTest {
@Theory
- public void test_isEqualTo_assertion(OffsetDateTime referenceDate) {
+ public void test_isEqualTo_assertion(OffsetDateTime reference, OffsetDateTime dateBefore, OffsetDateTime dateEqual,
+ OffsetDateTime dateAfter) {
+ // GIVEN
+ testAssumptions(reference, dateBefore, dateEqual, dateAfter);
// WHEN
- assertThat(referenceDate).isEqualTo(referenceDate.toString());
+ assertThat(dateEqual).isEqualTo(reference);
+ assertThat(dateEqual).isEqualTo(reference.toString());
// THEN
- verify_that_isEqualTo_assertion_fails_and_throws_AssertionError(referenceDate);
+ verify_that_isEqualTo_assertion_fails_and_throws_AssertionError(reference);
}
@Test
diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isIn_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isIn_Test.java
index 2d2eb3047e8..c16a020291c 100644
--- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isIn_Test.java
+++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isIn_Test.java
@@ -12,6 +12,7 @@
*/
package org.assertj.core.api.offsetdatetime;
+import static java.lang.String.format;
import static java.time.OffsetDateTime.of;
import static java.time.ZoneOffset.UTC;
import static org.assertj.core.api.Assertions.assertThat;
@@ -46,7 +47,10 @@ public void test_isIn_assertion_error_message() {
try {
assertThat(of(2000, 1, 5, 3, 0, 5, 0, UTC)).isIn(of(2012, 1, 1, 3, 3, 3, 0, UTC).toString());
} catch (AssertionError e) {
- assertThat(e).hasMessage("\nExpecting:\n <2000-01-05T03:00:05Z>\nto be in:\n <[2012-01-01T03:03:03Z]>\n");
+ assertThat(e).hasMessage(format("%nExpecting:%n" +
+ " <2000-01-05T03:00:05Z>%n" +
+ "to be in:%n" +
+ " <[2012-01-01T03:03:03Z]>%n"));
return;
}
fail("Should have thrown AssertionError");
diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isNotEqualTo_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isNotEqualTo_Test.java
index b7091af5c0f..86ef691a2f6 100644
--- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isNotEqualTo_Test.java
+++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isNotEqualTo_Test.java
@@ -12,6 +12,7 @@
*/
package org.assertj.core.api.offsetdatetime;
+import static java.lang.String.format;
import static java.time.ZoneOffset.UTC;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
@@ -33,22 +34,27 @@
public class OffsetDateTimeAssert_isNotEqualTo_Test extends OffsetDateTimeAssertBaseTest {
@Theory
- public void test_isNotEqualTo_assertion(OffsetDateTime referenceDate) {
+ public void test_isNotEqualTo_assertion(OffsetDateTime reference, OffsetDateTime before, OffsetDateTime equal,
+ OffsetDateTime after) {
+ // GIVEN
+ testAssumptions(reference, before, equal, after);
// WHEN
- assertThat(referenceDate).isNotEqualTo(referenceDate.plusDays(1).toString());
+ assertThat(equal).isNotEqualTo(reference.plusDays(1));
+ assertThat(equal).isNotEqualTo(reference.plusDays(1).toString());
// THEN
- verify_that_isNotEqualTo_assertion_fails_and_throws_AssertionError(referenceDate);
+ verify_that_isNotEqualTo_assertion_fails_and_throws_AssertionError(reference);
}
@Test
public void test_isNotEqualTo_assertion_error_message() {
try {
- assertThat(OffsetDateTime.of(2000, 1, 5, 3, 0, 5, 0, UTC))
- .isNotEqualTo(OffsetDateTime.of(2000, 1, 5, 3, 0, 5, 0,
- UTC).toString());
+ String offsetDateTimeAsString = OffsetDateTime.of(2000, 1, 5, 3, 0, 5, 0, UTC).toString();
+ assertThat(OffsetDateTime.of(2000, 1, 5, 3, 0, 5, 0, UTC)).isNotEqualTo(offsetDateTimeAsString);
} catch (AssertionError e) {
- assertThat(e)
- .hasMessage("\nExpecting:\n <2000-01-05T03:00:05Z>\nnot to be equal to:\n <2000-01-05T03:00:05Z>\n");
+ assertThat(e).hasMessage(format("%nExpecting:%n"
+ + " <2000-01-05T03:00:05Z>%n"
+ + "not to be equal to:%n"
+ + " <2000-01-05T03:00:05Z>%n"));
return;
}
fail("Should have thrown AssertionError");
diff --git a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isNotIn_Test.java b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isNotIn_Test.java
index 21cea2df086..439f26433bb 100644
--- a/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isNotIn_Test.java
+++ b/src/test/java/org/assertj/core/api/offsetdatetime/OffsetDateTimeAssert_isNotIn_Test.java
@@ -12,6 +12,7 @@
*/
package org.assertj.core.api.offsetdatetime;
+import static java.lang.String.format;
import static java.time.ZoneOffset.UTC;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
@@ -43,15 +44,14 @@ public void test_isNotIn_assertion(OffsetDateTime referenceDate) {
@Test
public void test_isNotIn_assertion_error_message() {
try {
- assertThat(OffsetDateTime.of(2000, 1, 5, 3, 0, 5, 0, UTC))
- .isNotIn(OffsetDateTime.of(2000, 1, 5, 3, 0, 5, 0, UTC)
- .toString(),
- OffsetDateTime.of(2012, 1, 1, 3, 3, 3, 0, UTC)
- .toString());
+ String offsetDateTime1 = OffsetDateTime.of(2000, 1, 5, 3, 0, 5, 0, UTC).toString();
+ String offsetDateTime2 = OffsetDateTime.of(2012, 1, 1, 3, 3, 3, 0, UTC).toString();
+ assertThat(OffsetDateTime.of(2000, 1, 5, 3, 0, 5, 0, UTC)).isNotIn(offsetDateTime1, offsetDateTime2);
} catch (AssertionError e) {
- assertThat(e)
- .hasMessage(
- "\nExpecting:\n <2000-01-05T03:00:05Z>\nnot to be in:\n <[2000-01-05T03:00:05Z, 2012-01-01T03:03:03Z]>\n");
+ assertThat(e).hasMessage(format("%nExpecting:%n " +
+ "<2000-01-05T03:00:05Z>%n" +
+ "not to be in:%n" +
+ " <[2000-01-05T03:00:05Z, 2012-01-01T03:03:03Z]>%n"));
return;
}
fail("Should have thrown AssertionError");
diff --git a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssertBaseTest.java b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssertBaseTest.java
index 3e70916093e..455080b66e6 100644
--- a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssertBaseTest.java
+++ b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssertBaseTest.java
@@ -12,35 +12,37 @@
*/
package org.assertj.core.api.offsettime;
-import org.assertj.core.api.BaseTest;
-import org.junit.experimental.theories.DataPoint;
+import static org.junit.Assume.assumeTrue;
import java.time.OffsetTime;
import java.time.ZoneOffset;
-import static org.junit.Assume.assumeTrue;
+import org.assertj.core.api.BaseTest;
+import org.junit.experimental.theories.DataPoint;
/**
* Base test class for {@link org.assertj.core.api.AbstractOffsetTimeAssert} tests.
*/
public class OffsetTimeAssertBaseTest extends BaseTest {
- @DataPoint
- public static OffsetTime OffsetTime1 = OffsetTime.of(0, 0, 0, 0, ZoneOffset.UTC);
- @DataPoint
- public static OffsetTime OffsetTime2 = OffsetTime.of(23, 59, 59, 999, ZoneOffset.UTC);
- @DataPoint
- public static OffsetTime OffsetTime3 = OffsetTime.of(0, 0, 0, 1, ZoneOffset.UTC);
- @DataPoint
- public static OffsetTime OffsetTime4 = OffsetTime.of(22, 15, 15, 875, ZoneOffset.UTC);
- @DataPoint
- public static OffsetTime OffsetTime5 = OffsetTime.of(22, 15, 15, 874, ZoneOffset.UTC);
- @DataPoint
- public static OffsetTime OffsetTime6 = OffsetTime.of(22, 15, 15, 876, ZoneOffset.UTC);
+ @DataPoint
+ public static OffsetTime OffsetTime1 = OffsetTime.of(0, 0, 0, 0, ZoneOffset.UTC);
+ @DataPoint
+ public static OffsetTime OffsetTime2 = OffsetTime.of(23, 59, 59, 999, ZoneOffset.UTC);
+ @DataPoint
+ public static OffsetTime OffsetTime3 = OffsetTime.of(0, 0, 0, 1, ZoneOffset.UTC);
+ @DataPoint
+ public static OffsetTime OffsetTime4 = OffsetTime.of(22, 15, 15, 875, ZoneOffset.UTC);
+ @DataPoint
+ public static OffsetTime OffsetTime5 = OffsetTime.of(22, 15, 15, 874, ZoneOffset.UTC);
+ @DataPoint
+ public static OffsetTime OffsetTime6 = OffsetTime.of(22, 15, 15, 876, ZoneOffset.UTC);
- protected static void testAssumptions(OffsetTime reference, OffsetTime timeBefore, OffsetTime timeAfter) {
- assumeTrue(timeBefore.isBefore(reference));
- assumeTrue(timeAfter.isAfter(reference));
- }
+ protected static void testAssumptions(OffsetTime reference, OffsetTime timeBefore, OffsetTime timeEqual,
+ OffsetTime timeAfter) {
+ assumeTrue(timeBefore.isBefore(reference));
+ assumeTrue(timeEqual.isEqual(reference));
+ assumeTrue(timeAfter.isAfter(reference));
+ }
}
\ No newline at end of file
diff --git a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_hasSameHourAs_Test.java b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_hasSameHourAs_Test.java
index acb5668161e..595a352f36d 100644
--- a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_hasSameHourAs_Test.java
+++ b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_hasSameHourAs_Test.java
@@ -12,15 +12,16 @@
*/
package org.assertj.core.api.offsettime;
-import org.assertj.core.api.BaseTest;
-import org.junit.Test;
+import static java.lang.String.format;
+import static org.assertj.core.api.AbstractOffsetTimeAssert.NULL_OFFSET_TIME_PARAMETER_MESSAGE;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.util.FailureMessages.actualIsNull;
import java.time.OffsetTime;
import java.time.ZoneOffset;
-import static org.assertj.core.api.AbstractOffsetTimeAssert.NULL_OFFSET_TIME_PARAMETER_MESSAGE;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.util.FailureMessages.actualIsNull;
+import org.assertj.core.api.BaseTest;
+import org.junit.Test;
public class OffsetTimeAssert_hasSameHourAs_Test extends BaseTest {
@@ -28,52 +29,52 @@ public class OffsetTimeAssert_hasSameHourAs_Test extends BaseTest {
@Test
public void should_pass_if_actual_andexpected_have_same_hour() {
- assertThat(refOffsetTime).hasSameHourAs(refOffsetTime.plusMinutes(1));
+ assertThat(refOffsetTime).hasSameHourAs(refOffsetTime.plusMinutes(1));
}
@Test
- public void should_fail_if_actual_is_not_equal_to_given_OffsetTimetime_with_minute_ignored() {
- try {
- assertThat(refOffsetTime).hasSameHourAs(refOffsetTime.minusMinutes(1));
- } catch (AssertionError e) {
- assertThat(e).hasMessage("\n" +
- "Expecting:\n" +
- " <23:00Z>\n" +
- "to have same hour as:\n" +
- " <22:59Z>\n" +
- "but had not.");
- return;
- }
- failBecauseExpectedAssertionErrorWasNotThrown();
+ public void should_fail_if_actual_is_not_equal_to_given_offsetTime_with_minute_ignored() {
+ try {
+ assertThat(refOffsetTime).hasSameHourAs(refOffsetTime.minusMinutes(1));
+ } catch (AssertionError e) {
+ assertThat(e).hasMessage(format("%n" +
+ "Expecting:%n" +
+ " <23:00Z>%n" +
+ "to have same hour as:%n" +
+ " <22:59Z>%n" +
+ "but had not."));
+ return;
+ }
+ failBecauseExpectedAssertionErrorWasNotThrown();
}
@Test
public void should_fail_as_minutes_fields_are_different_even_if_time_difference_is_less_than_a_minute() {
- try {
- assertThat(refOffsetTime).hasSameHourAs(refOffsetTime.minusNanos(1));
- } catch (AssertionError e) {
- assertThat(e).hasMessage("\n" +
- "Expecting:\n" +
- " <23:00Z>\n" +
- "to have same hour as:\n" +
- " <22:59:59.999999999Z>\n" +
- "but had not.");
- return;
- }
- failBecauseExpectedAssertionErrorWasNotThrown();
+ try {
+ assertThat(refOffsetTime).hasSameHourAs(refOffsetTime.minusNanos(1));
+ } catch (AssertionError e) {
+ assertThat(e).hasMessage(format("%n" +
+ "Expecting:%n" +
+ " <23:00Z>%n" +
+ "to have same hour as:%n" +
+ " <22:59:59.999999999Z>%n" +
+ "but had not."));
+ return;
+ }
+ failBecauseExpectedAssertionErrorWasNotThrown();
}
@Test
public void should_fail_if_actual_is_null() {
- expectException(AssertionError.class, actualIsNull());
- OffsetTime actual = null;
- assertThat(actual).hasSameHourAs(OffsetTime.now());
+ expectException(AssertionError.class, actualIsNull());
+ OffsetTime actual = null;
+ assertThat(actual).hasSameHourAs(OffsetTime.now());
}
@Test
- public void should_throw_error_if_given_OffsetTimetime_is_null() {
- expectIllegalArgumentException(NULL_OFFSET_TIME_PARAMETER_MESSAGE);
- assertThat(refOffsetTime).hasSameHourAs(null);
+ public void should_throw_error_if_given_offsetTime_is_null() {
+ expectIllegalArgumentException(NULL_OFFSET_TIME_PARAMETER_MESSAGE);
+ assertThat(refOffsetTime).hasSameHourAs(null);
}
}
diff --git a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isAfterOrEqualTo_Test.java b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isAfterOrEqualTo_Test.java
index 438df6a8067..98e1c67d1a7 100644
--- a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isAfterOrEqualTo_Test.java
+++ b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isAfterOrEqualTo_Test.java
@@ -12,17 +12,18 @@
*/
package org.assertj.core.api.offsettime;
-import org.junit.Test;
-import org.junit.experimental.theories.Theories;
-import org.junit.experimental.theories.Theory;
-import org.junit.runner.RunWith;
+import static java.lang.String.format;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+import static org.assertj.core.util.FailureMessages.actualIsNull;
import java.time.OffsetTime;
import java.time.ZoneOffset;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
-import static org.assertj.core.util.FailureMessages.actualIsNull;
+import org.junit.Test;
+import org.junit.experimental.theories.Theories;
+import org.junit.experimental.theories.Theory;
+import org.junit.runner.RunWith;
/**
* @author Paweł Stawicki
@@ -33,66 +34,68 @@
public class OffsetTimeAssert_isAfterOrEqualTo_Test extends OffsetTimeAssertBaseTest {
@Theory
- public void test_isAfterOrEqual_assertion(OffsetTime referenceTime, OffsetTime timeBefore,
- OffsetTime timeAfter) {
- // GIVEN
- testAssumptions(referenceTime, timeBefore, timeAfter);
- // WHEN
- assertThat(timeAfter).isAfterOrEqualTo(referenceTime);
- assertThat(referenceTime).isAfterOrEqualTo(referenceTime);
- // THEN
- verify_that_isAfterOrEqual_assertion_fails_and_throws_AssertionError(timeBefore, referenceTime);
+ public void test_isAfterOrEqual_assertion(OffsetTime referenceTime, OffsetTime timeBefore, OffsetTime timeEqual,
+ OffsetTime timeAfter) {
+ // GIVEN
+ testAssumptions(referenceTime, timeBefore, timeEqual, timeAfter);
+ // WHEN
+ assertThat(timeAfter).isAfterOrEqualTo(referenceTime);
+ assertThat(timeAfter).isAfterOrEqualTo(referenceTime.toString());
+ assertThat(timeEqual).isAfterOrEqualTo(referenceTime);
+ assertThat(timeEqual).isAfterOrEqualTo(referenceTime.toString());
+ // THEN
+ verify_that_isAfterOrEqual_assertion_fails_and_throws_AssertionError(timeBefore, referenceTime);
}
@Test
public void test_isAfterOrEqual_assertion_error_message() {
- try {
- assertThat(OffsetTime.of(3, 0, 5, 0, ZoneOffset.UTC)).isAfterOrEqualTo(OffsetTime.of(3, 3, 3, 0, ZoneOffset.UTC));
- } catch (AssertionError e) {
- assertThat(e).hasMessage("\n" +
- "Expecting:\n" +
- " <03:00:05Z>\n" +
- "to be after or equals to:\n" +
- " <03:03:03Z>");
- return;
- }
- fail("Should have thrown AssertionError");
+ try {
+ assertThat(OffsetTime.of(3, 0, 5, 0, ZoneOffset.UTC)).isAfterOrEqualTo(OffsetTime.of(3, 3, 3, 0, ZoneOffset.UTC));
+ } catch (AssertionError e) {
+ assertThat(e).hasMessage(format("%n" +
+ "Expecting:%n" +
+ " <03:00:05Z>%n" +
+ "to be after or equals to:%n" +
+ " <03:03:03Z>"));
+ return;
+ }
+ fail("Should have thrown AssertionError");
}
@Test
public void should_fail_if_actual_is_null() {
- expectException(AssertionError.class, actualIsNull());
- OffsetTime actual = null;
- assertThat(actual).isAfterOrEqualTo(OffsetTime.now());
+ expectException(AssertionError.class, actualIsNull());
+ OffsetTime actual = null;
+ assertThat(actual).isAfterOrEqualTo(OffsetTime.now());
}
@Test
- public void should_fail_if_timeTime_parameter_is_null() {
- expectException(IllegalArgumentException.class, "The OffsetTime to compare actual with should not be null");
- assertThat(OffsetTime.now()).isAfterOrEqualTo((OffsetTime) null);
+ public void should_fail_if_offsetTime_parameter_is_null() {
+ expectException(IllegalArgumentException.class, "The OffsetTime to compare actual with should not be null");
+ assertThat(OffsetTime.now()).isAfterOrEqualTo((OffsetTime) null);
}
@Test
- public void should_fail_if_timeTime_as_string_parameter_is_null() {
- expectException(IllegalArgumentException.class,
- "The String representing the OffsetTime to compare actual with should not be null");
- assertThat(OffsetTime.now()).isAfterOrEqualTo((String) null);
+ public void should_fail_if_offsetTime_as_string_parameter_is_null() {
+ expectException(IllegalArgumentException.class,
+ "The String representing the OffsetTime to compare actual with should not be null");
+ assertThat(OffsetTime.now()).isAfterOrEqualTo((String) null);
}
private static void verify_that_isAfterOrEqual_assertion_fails_and_throws_AssertionError(OffsetTime timeToCheck,
- OffsetTime reference) {
- try {
- assertThat(timeToCheck).isAfterOrEqualTo(reference);
- } catch (AssertionError e) {
- // AssertionError was expected, test same assertion with String based parameter
- try {
- assertThat(timeToCheck).isAfterOrEqualTo(reference.toString());
- } catch (AssertionError e2) {
- // AssertionError was expected (again)
- return;
- }
- }
- fail("Should have thrown AssertionError");
+ OffsetTime reference) {
+ try {
+ assertThat(timeToCheck).isAfterOrEqualTo(reference);
+ } catch (AssertionError e) {
+ // AssertionError was expected, test same assertion with String based parameter
+ try {
+ assertThat(timeToCheck).isAfterOrEqualTo(reference.toString());
+ } catch (AssertionError e2) {
+ // AssertionError was expected (again)
+ return;
+ }
+ }
+ fail("Should have thrown AssertionError");
}
}
diff --git a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isAfter_Test.java b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isAfter_Test.java
index 15fde2e3e06..020f266963c 100644
--- a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isAfter_Test.java
+++ b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isAfter_Test.java
@@ -12,82 +12,84 @@
*/
package org.assertj.core.api.offsettime;
-import org.junit.Test;
-import org.junit.experimental.theories.Theories;
-import org.junit.experimental.theories.Theory;
-import org.junit.runner.RunWith;
-
-import java.time.OffsetTime;
-
+import static java.lang.String.format;
import static java.time.OffsetTime.parse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.util.FailureMessages.actualIsNull;
+import java.time.OffsetTime;
+
+import org.junit.Test;
+import org.junit.experimental.theories.Theories;
+import org.junit.experimental.theories.Theory;
+import org.junit.runner.RunWith;
+
@RunWith(Theories.class)
public class OffsetTimeAssert_isAfter_Test extends OffsetTimeAssertBaseTest {
@Theory
- public void test_isAfter_assertion(OffsetTime referenceTime, OffsetTime timeBefore, OffsetTime timeAfter) {
- // GIVEN
- testAssumptions(referenceTime, timeBefore, timeAfter);
- // WHEN
- assertThat(timeAfter).isAfter(referenceTime);
- assertThat(timeAfter).isAfter(referenceTime.toString());
- // THEN
- verify_that_isAfter_assertion_fails_and_throws_AssertionError(referenceTime, referenceTime);
- verify_that_isAfter_assertion_fails_and_throws_AssertionError(timeBefore, referenceTime);
+ public void test_isAfter_assertion(OffsetTime referenceTime, OffsetTime timeBefore, OffsetTime timeEqual,
+ OffsetTime timeAfter) {
+ // GIVEN
+ testAssumptions(referenceTime, timeBefore, timeEqual, timeAfter);
+ // WHEN
+ assertThat(timeAfter).isAfter(referenceTime);
+ assertThat(timeAfter).isAfter(referenceTime.toString());
+ // THEN
+ verify_that_isAfter_assertion_fails_and_throws_AssertionError(referenceTime, referenceTime);
+ verify_that_isAfter_assertion_fails_and_throws_AssertionError(timeBefore, referenceTime);
}
@Test
public void test_isAfter_assertion_error_message() {
- try {
- assertThat(parse("03:00:05.123Z")).isAfter(parse("03:00:05.123456789Z"));
- } catch (AssertionError e) {
- assertThat(e).hasMessage("\n" +
- "Expecting:\n" +
- " <03:00:05.123Z>\n" +
- "to be strictly after:\n" +
- " <03:00:05.123456789Z>");
- return;
- }
- fail("Should have thrown AssertionError");
+ try {
+ assertThat(parse("03:00:05.123Z")).isAfter(parse("03:00:05.123456789Z"));
+ } catch (AssertionError e) {
+ assertThat(e).hasMessage(format("%n" +
+ "Expecting:%n" +
+ " <03:00:05.123Z>%n" +
+ "to be strictly after:%n" +
+ " <03:00:05.123456789Z>"));
+ return;
+ }
+ fail("Should have thrown AssertionError");
}
@Test
public void should_fail_if_actual_is_null() {
- expectException(AssertionError.class, actualIsNull());
- OffsetTime actual = null;
- assertThat(actual).isAfter(OffsetTime.now());
+ expectException(AssertionError.class, actualIsNull());
+ OffsetTime actual = null;
+ assertThat(actual).isAfter(OffsetTime.now());
}
@Test
- public void should_fail_if_timeTime_parameter_is_null() {
- expectException(IllegalArgumentException.class, "The OffsetTime to compare actual with should not be null");
- assertThat(OffsetTime.now()).isAfter((OffsetTime) null);
+ public void should_fail_if_offsetTime_parameter_is_null() {
+ expectException(IllegalArgumentException.class, "The OffsetTime to compare actual with should not be null");
+ assertThat(OffsetTime.now()).isAfter((OffsetTime) null);
}
@Test
- public void should_fail_if_timeTime_as_string_parameter_is_null() {
- expectException(IllegalArgumentException.class,
- "The String representing the OffsetTime to compare actual with should not be null");
- assertThat(OffsetTime.now()).isAfter((String) null);
+ public void should_fail_if_offsetTime_as_string_parameter_is_null() {
+ expectException(IllegalArgumentException.class,
+ "The String representing the OffsetTime to compare actual with should not be null");
+ assertThat(OffsetTime.now()).isAfter((String) null);
}
private static void verify_that_isAfter_assertion_fails_and_throws_AssertionError(OffsetTime timeToCheck,
- OffsetTime reference) {
- try {
- assertThat(timeToCheck).isAfter(reference);
- } catch (AssertionError e) {
- // AssertionError was expected, test same assertion with String based parameter
- try {
- assertThat(timeToCheck).isAfter(reference.toString());
- } catch (AssertionError e2) {
- // AssertionError was expected (again)
- return;
- }
- }
- fail("Should have thrown AssertionError");
+ OffsetTime reference) {
+ try {
+ assertThat(timeToCheck).isAfter(reference);
+ } catch (AssertionError e) {
+ // AssertionError was expected, test same assertion with String based parameter
+ try {
+ assertThat(timeToCheck).isAfter(reference.toString());
+ } catch (AssertionError e2) {
+ // AssertionError was expected (again)
+ return;
+ }
+ }
+ fail("Should have thrown AssertionError");
}
}
diff --git a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isBeforeOrEqualTo_Test.java b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isBeforeOrEqualTo_Test.java
index 2de7db0ad90..60678edc25c 100644
--- a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isBeforeOrEqualTo_Test.java
+++ b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isBeforeOrEqualTo_Test.java
@@ -12,17 +12,18 @@
*/
package org.assertj.core.api.offsettime;
-import org.junit.Test;
-import org.junit.experimental.theories.Theories;
-import org.junit.experimental.theories.Theory;
-import org.junit.runner.RunWith;
+import static java.lang.String.format;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+import static org.assertj.core.util.FailureMessages.actualIsNull;
import java.time.OffsetTime;
import java.time.ZoneOffset;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
-import static org.assertj.core.util.FailureMessages.actualIsNull;
+import org.junit.Test;
+import org.junit.experimental.theories.Theories;
+import org.junit.experimental.theories.Theory;
+import org.junit.runner.RunWith;
/**
* @author Paweł Stawicki
@@ -33,66 +34,68 @@
public class OffsetTimeAssert_isBeforeOrEqualTo_Test extends OffsetTimeAssertBaseTest {
@Theory
- public void test_isBeforeOrEqual_assertion(OffsetTime referenceTime, OffsetTime timeBefore,
- OffsetTime timeAfter) {
- // GIVEN
- testAssumptions(referenceTime, timeBefore, timeAfter);
- // WHEN
- assertThat(timeBefore).isBeforeOrEqualTo(referenceTime);
- assertThat(referenceTime).isBeforeOrEqualTo(referenceTime);
- // THEN
- verify_that_isBeforeOrEqual_assertion_fails_and_throws_AssertionError(timeAfter, referenceTime);
+ public void test_isBeforeOrEqual_assertion(OffsetTime referenceTime, OffsetTime timeBefore, OffsetTime timeEqual,
+ OffsetTime timeAfter) {
+ // GIVEN
+ testAssumptions(referenceTime, timeBefore, timeEqual, timeAfter);
+ // WHEN
+ assertThat(timeBefore).isBeforeOrEqualTo(referenceTime);
+ assertThat(timeBefore).isBeforeOrEqualTo(referenceTime.toString());
+ assertThat(timeEqual).isBeforeOrEqualTo(referenceTime);
+ assertThat(timeEqual).isBeforeOrEqualTo(referenceTime.toString());
+ // THEN
+ verify_that_isBeforeOrEqual_assertion_fails_and_throws_AssertionError(timeAfter, referenceTime);
}
@Test
public void test_isBeforeOrEqual_assertion_error_message() {
- try {
- assertThat(OffsetTime.of(3, 0, 5, 0, ZoneOffset.UTC)).isBeforeOrEqualTo(OffsetTime.of(3, 0, 4, 0, ZoneOffset.UTC));
- } catch (AssertionError e) {
- assertThat(e).hasMessage("\n" +
- "Expecting:\n" +
- " <03:00:05Z>\n" +
- "to be before or equals to:\n" +
- " <03:00:04Z>");
- return;
- }
- fail("Should have thrown AssertionError");
+ try {
+ assertThat(OffsetTime.of(3, 0, 5, 0, ZoneOffset.UTC)).isBeforeOrEqualTo(OffsetTime.of(3, 0, 4, 0, ZoneOffset.UTC));
+ } catch (AssertionError e) {
+ assertThat(e).hasMessage(format("%n" +
+ "Expecting:%n" +
+ " <03:00:05Z>%n" +
+ "to be before or equals to:%n" +
+ " <03:00:04Z>"));
+ return;
+ }
+ fail("Should have thrown AssertionError");
}
@Test
public void should_fail_if_actual_is_null() {
- expectException(AssertionError.class, actualIsNull());
- OffsetTime actual = null;
- assertThat(actual).isBeforeOrEqualTo(OffsetTime.now());
+ expectException(AssertionError.class, actualIsNull());
+ OffsetTime actual = null;
+ assertThat(actual).isBeforeOrEqualTo(OffsetTime.now());
}
@Test
- public void should_fail_if_timeTime_parameter_is_null() {
- expectException(IllegalArgumentException.class, "The OffsetTime to compare actual with should not be null");
- assertThat(OffsetTime.now()).isBeforeOrEqualTo((OffsetTime) null);
+ public void should_fail_if_offsetTime_parameter_is_null() {
+ expectException(IllegalArgumentException.class, "The OffsetTime to compare actual with should not be null");
+ assertThat(OffsetTime.now()).isBeforeOrEqualTo((OffsetTime) null);
}
@Test
- public void should_fail_if_timeTime_as_string_parameter_is_null() {
- expectException(IllegalArgumentException.class,
- "The String representing the OffsetTime to compare actual with should not be null");
- assertThat(OffsetTime.now()).isBeforeOrEqualTo((String) null);
+ public void should_fail_if_offsetTime_as_string_parameter_is_null() {
+ expectException(IllegalArgumentException.class,
+ "The String representing the OffsetTime to compare actual with should not be null");
+ assertThat(OffsetTime.now()).isBeforeOrEqualTo((String) null);
}
private static void verify_that_isBeforeOrEqual_assertion_fails_and_throws_AssertionError(OffsetTime timeToCheck,
- OffsetTime reference) {
- try {
- assertThat(timeToCheck).isBeforeOrEqualTo(reference);
- } catch (AssertionError e) {
- // AssertionError was expected, test same assertion with String based parameter
- try {
- assertThat(timeToCheck).isBeforeOrEqualTo(reference.toString());
- } catch (AssertionError e2) {
- // AssertionError was expected (again)
- return;
- }
- }
- fail("Should have thrown AssertionError");
+ OffsetTime reference) {
+ try {
+ assertThat(timeToCheck).isBeforeOrEqualTo(reference);
+ } catch (AssertionError e) {
+ // AssertionError was expected, test same assertion with String based parameter
+ try {
+ assertThat(timeToCheck).isBeforeOrEqualTo(reference.toString());
+ } catch (AssertionError e2) {
+ // AssertionError was expected (again)
+ return;
+ }
+ }
+ fail("Should have thrown AssertionError");
}
}
diff --git a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isBefore_Test.java b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isBefore_Test.java
index f1d98ea53be..843d9cb3cf7 100644
--- a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isBefore_Test.java
+++ b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isBefore_Test.java
@@ -12,17 +12,18 @@
*/
package org.assertj.core.api.offsettime;
-import org.junit.Test;
-import org.junit.experimental.theories.Theories;
-import org.junit.experimental.theories.Theory;
-import org.junit.runner.RunWith;
+import static java.lang.String.format;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+import static org.assertj.core.util.FailureMessages.actualIsNull;
import java.time.OffsetTime;
import java.time.ZoneOffset;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
-import static org.assertj.core.util.FailureMessages.actualIsNull;
+import org.junit.Test;
+import org.junit.experimental.theories.Theories;
+import org.junit.experimental.theories.Theory;
+import org.junit.runner.RunWith;
/**
* @author Paweł Stawicki
@@ -33,65 +34,67 @@
public class OffsetTimeAssert_isBefore_Test extends OffsetTimeAssertBaseTest {
@Theory
- public void test_isBefore_assertion(OffsetTime referenceTime, OffsetTime timeBefore, OffsetTime timeAfter) {
- // GIVEN
- testAssumptions(referenceTime, timeBefore, timeAfter);
- // WHEN
- assertThat(timeBefore).isBefore(referenceTime);
- // THEN
- verify_that_isBefore_assertion_fails_and_throws_AssertionError(referenceTime, referenceTime);
- verify_that_isBefore_assertion_fails_and_throws_AssertionError(timeAfter, referenceTime);
+ public void test_isBefore_assertion(OffsetTime referenceTime, OffsetTime timeBefore, OffsetTime timeEqual,
+ OffsetTime timeAfter) {
+ // GIVEN
+ testAssumptions(referenceTime, timeBefore, timeEqual, timeAfter);
+ // WHEN
+ assertThat(timeBefore).isBefore(referenceTime);
+ assertThat(timeBefore).isBefore(referenceTime.toString());
+ // THEN
+ verify_that_isBefore_assertion_fails_and_throws_AssertionError(referenceTime, referenceTime);
+ verify_that_isBefore_assertion_fails_and_throws_AssertionError(timeAfter, referenceTime);
}
@Test
public void test_isBefore_assertion_error_message() {
- try {
- assertThat(OffsetTime.of(3, 0, 5, 0, ZoneOffset.UTC)).isBefore(OffsetTime.of(3, 0, 4, 0, ZoneOffset.UTC));
- } catch (AssertionError e) {
- assertThat(e).hasMessage("\n" +
- "Expecting:\n" +
- " <03:00:05Z>\n" +
- "to be strictly before:\n" +
- " <03:00:04Z>");
- return;
- }
- fail("Should have thrown AssertionError");
+ try {
+ assertThat(OffsetTime.of(3, 0, 5, 0, ZoneOffset.UTC)).isBefore(OffsetTime.of(3, 0, 4, 0, ZoneOffset.UTC));
+ } catch (AssertionError e) {
+ assertThat(e).hasMessage(format("%n" +
+ "Expecting:%n" +
+ " <03:00:05Z>%n" +
+ "to be strictly before:%n" +
+ " <03:00:04Z>"));
+ return;
+ }
+ fail("Should have thrown AssertionError");
}
@Test
public void should_fail_if_actual_is_null() {
- expectException(AssertionError.class, actualIsNull());
- OffsetTime actual = null;
- assertThat(actual).isBefore(OffsetTime.now());
+ expectException(AssertionError.class, actualIsNull());
+ OffsetTime actual = null;
+ assertThat(actual).isBefore(OffsetTime.now());
}
@Test
- public void should_fail_if_timeTime_parameter_is_null() {
- expectException(IllegalArgumentException.class, "The OffsetTime to compare actual with should not be null");
- assertThat(OffsetTime.now()).isBefore((OffsetTime) null);
+ public void should_fail_if_offsetTime_parameter_is_null() {
+ expectException(IllegalArgumentException.class, "The OffsetTime to compare actual with should not be null");
+ assertThat(OffsetTime.now()).isBefore((OffsetTime) null);
}
@Test
- public void should_fail_if_timeTime_as_string_parameter_is_null() {
- expectException(IllegalArgumentException.class,
- "The String representing the OffsetTime to compare actual with should not be null");
- assertThat(OffsetTime.now()).isBefore((String) null);
+ public void should_fail_if_offsetTime_as_string_parameter_is_null() {
+ expectException(IllegalArgumentException.class,
+ "The String representing the OffsetTime to compare actual with should not be null");
+ assertThat(OffsetTime.now()).isBefore((String) null);
}
private static void verify_that_isBefore_assertion_fails_and_throws_AssertionError(OffsetTime timeToTest,
- OffsetTime reference) {
- try {
- assertThat(timeToTest).isBefore(reference);
- } catch (AssertionError e) {
- // AssertionError was expected, test same assertion with String based parameter
- try {
- assertThat(timeToTest).isBefore(reference.toString());
- } catch (AssertionError e2) {
- // AssertionError was expected (again)
- return;
- }
- }
- fail("Should have thrown AssertionError");
+ OffsetTime reference) {
+ try {
+ assertThat(timeToTest).isBefore(reference);
+ } catch (AssertionError e) {
+ // AssertionError was expected, test same assertion with String based parameter
+ try {
+ assertThat(timeToTest).isBefore(reference.toString());
+ } catch (AssertionError e2) {
+ // AssertionError was expected (again)
+ return;
+ }
+ }
+ fail("Should have thrown AssertionError");
}
}
diff --git a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isEqualToIgnoringNanoseconds_Test.java b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isEqualToIgnoringNanoseconds_Test.java
index e10e0a5f500..175211180d2 100644
--- a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isEqualToIgnoringNanoseconds_Test.java
+++ b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isEqualToIgnoringNanoseconds_Test.java
@@ -12,15 +12,16 @@
*/
package org.assertj.core.api.offsettime;
-import org.assertj.core.api.BaseTest;
-import org.junit.Test;
+import static java.lang.String.format;
+import static org.assertj.core.api.AbstractOffsetTimeAssert.NULL_OFFSET_TIME_PARAMETER_MESSAGE;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.util.FailureMessages.actualIsNull;
import java.time.OffsetTime;
import java.time.ZoneOffset;
-import static org.assertj.core.api.AbstractOffsetTimeAssert.NULL_OFFSET_TIME_PARAMETER_MESSAGE;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.util.FailureMessages.actualIsNull;
+import org.assertj.core.api.BaseTest;
+import org.junit.Test;
public class OffsetTimeAssert_isEqualToIgnoringNanoseconds_Test extends BaseTest {
@@ -28,51 +29,51 @@ public class OffsetTimeAssert_isEqualToIgnoringNanoseconds_Test extends BaseTest
@Test
public void should_pass_if_actual_is_equal_to_other_ignoring_nanosecond_fields() {
- assertThat(refOffsetTime).isEqualToIgnoringNanos(refOffsetTime.withNano(55));
- assertThat(refOffsetTime).isEqualToIgnoringNanos(refOffsetTime.plusNanos(1));
+ assertThat(refOffsetTime).isEqualToIgnoringNanos(refOffsetTime.withNano(55));
+ assertThat(refOffsetTime).isEqualToIgnoringNanos(refOffsetTime.plusNanos(1));
}
@Test
public void should_fail_if_actual_is_not_equal_to_given_OffsetTime_with_nanoseconds_ignored() {
- try {
- assertThat(refOffsetTime).isEqualToIgnoringNanos(refOffsetTime.plusSeconds(1));
- } catch (AssertionError e) {
- assertThat(e).hasMessage("\nExpecting:\n " +
- "<00:00:01Z>\n" +
- "to have same hour, minute and second as:\n" +
- " <00:00:02Z>\n" +
- "but had not.");
- return;
- }
- failBecauseExpectedAssertionErrorWasNotThrown();
+ try {
+ assertThat(refOffsetTime).isEqualToIgnoringNanos(refOffsetTime.plusSeconds(1));
+ } catch (AssertionError e) {
+ assertThat(e).hasMessage(format("%nExpecting:%n " +
+ "<00:00:01Z>%n" +
+ "to have same hour, minute and second as:%n" +
+ " <00:00:02Z>%n" +
+ "but had not."));
+ return;
+ }
+ failBecauseExpectedAssertionErrorWasNotThrown();
}
@Test
- public void should_fail_as_seconds_fields_are_different_even_if_time_difference_is_less_than_a_second() {
- try {
- assertThat(refOffsetTime).isEqualToIgnoringNanos(refOffsetTime.minusNanos(1));
- } catch (AssertionError e) {
- assertThat(e).hasMessage("\nExpecting:\n" +
- " <00:00:01Z>\n" +
- "to have same hour, minute and second as:\n" +
- " <00:00:00.999999999Z>\n" +
- "but had not.");
- return;
- }
- failBecauseExpectedAssertionErrorWasNotThrown();
+ public void should_fail_as_seconds_fields_are_different() {
+ try {
+ assertThat(refOffsetTime).isEqualToIgnoringNanos(refOffsetTime.minusNanos(1));
+ } catch (AssertionError e) {
+ assertThat(e).hasMessage(format("%nExpecting:%n" +
+ " <00:00:01Z>%n" +
+ "to have same hour, minute and second as:%n" +
+ " <00:00:00.999999999Z>%n" +
+ "but had not."));
+ return;
+ }
+ failBecauseExpectedAssertionErrorWasNotThrown();
}
@Test
public void should_fail_if_actual_is_null() {
- expectException(AssertionError.class, actualIsNull());
- OffsetTime actual = null;
- assertThat(actual).isEqualToIgnoringNanos(OffsetTime.now());
+ expectException(AssertionError.class, actualIsNull());
+ OffsetTime actual = null;
+ assertThat(actual).isEqualToIgnoringNanos(OffsetTime.now());
}
@Test
- public void should_throw_error_if_given_OffsetTimetime_is_null() {
- expectIllegalArgumentException(NULL_OFFSET_TIME_PARAMETER_MESSAGE);
- assertThat(refOffsetTime).isEqualToIgnoringNanos(null);
+ public void should_throw_error_if_given_offsetTime_is_null() {
+ expectIllegalArgumentException(NULL_OFFSET_TIME_PARAMETER_MESSAGE);
+ assertThat(refOffsetTime).isEqualToIgnoringNanos(null);
}
}
diff --git a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isEqualToIgnoringSeconds_Test.java b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isEqualToIgnoringSeconds_Test.java
index d210800bfbc..2e8b7dbeff8 100644
--- a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isEqualToIgnoringSeconds_Test.java
+++ b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isEqualToIgnoringSeconds_Test.java
@@ -12,15 +12,16 @@
*/
package org.assertj.core.api.offsettime;
-import org.assertj.core.api.BaseTest;
-import org.junit.Test;
+import static java.lang.String.format;
+import static org.assertj.core.api.AbstractOffsetTimeAssert.NULL_OFFSET_TIME_PARAMETER_MESSAGE;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.util.FailureMessages.actualIsNull;
import java.time.OffsetTime;
import java.time.ZoneOffset;
-import static org.assertj.core.api.AbstractOffsetTimeAssert.NULL_OFFSET_TIME_PARAMETER_MESSAGE;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.util.FailureMessages.actualIsNull;
+import org.assertj.core.api.BaseTest;
+import org.junit.Test;
public class OffsetTimeAssert_isEqualToIgnoringSeconds_Test extends BaseTest {
@@ -28,50 +29,50 @@ public class OffsetTimeAssert_isEqualToIgnoringSeconds_Test extends BaseTest {
@Test
public void should_pass_if_actual_is_equal_to_other_ignoring_second_fields() {
- assertThat(refOffsetTime).isEqualToIgnoringSeconds(refOffsetTime.plusSeconds(1));
+ assertThat(refOffsetTime).isEqualToIgnoringSeconds(refOffsetTime.plusSeconds(1));
}
@Test
- public void should_fail_if_actual_is_not_equal_to_given_offsettime_with_second_ignored() {
- try {
- assertThat(refOffsetTime).isEqualToIgnoringSeconds(refOffsetTime.plusMinutes(1));
- } catch (AssertionError e) {
- assertThat(e).hasMessage("\nExpecting:\n" +
- " <23:51Z>\n" +
- "to have same hour and minute as:\n" +
- " <23:52Z>\n" +
- "but had not.");
- return;
- }
- failBecauseExpectedAssertionErrorWasNotThrown();
+ public void should_fail_if_actual_is_not_equal_to_given_offsetTime_with_second_ignored() {
+ try {
+ assertThat(refOffsetTime).isEqualToIgnoringSeconds(refOffsetTime.plusMinutes(1));
+ } catch (AssertionError e) {
+ assertThat(e).hasMessage(format("%nExpecting:%n" +
+ " <23:51Z>%n" +
+ "to have same hour and minute as:%n" +
+ " <23:52Z>%n" +
+ "but had not."));
+ return;
+ }
+ failBecauseExpectedAssertionErrorWasNotThrown();
}
@Test
public void should_fail_as_seconds_fields_are_different_even_if_time_difference_is_less_than_a_second() {
- try {
- assertThat(refOffsetTime).isEqualToIgnoringSeconds(refOffsetTime.minusNanos(1));
- } catch (AssertionError e) {
- assertThat(e).hasMessage("\nExpecting:\n" +
- " <23:51Z>\n" +
- "to have same hour and minute as:\n" +
- " <23:50:59.999999999Z>\n" +
- "but had not.");
- return;
- }
- failBecauseExpectedAssertionErrorWasNotThrown();
+ try {
+ assertThat(refOffsetTime).isEqualToIgnoringSeconds(refOffsetTime.minusNanos(1));
+ } catch (AssertionError e) {
+ assertThat(e).hasMessage(format("%nExpecting:%n" +
+ " <23:51Z>%n" +
+ "to have same hour and minute as:%n" +
+ " <23:50:59.999999999Z>%n" +
+ "but had not."));
+ return;
+ }
+ failBecauseExpectedAssertionErrorWasNotThrown();
}
@Test
public void should_fail_if_actual_is_null() {
- expectException(AssertionError.class, actualIsNull());
- OffsetTime actual = null;
- assertThat(actual).isEqualToIgnoringSeconds(OffsetTime.now());
+ expectException(AssertionError.class, actualIsNull());
+ OffsetTime actual = null;
+ assertThat(actual).isEqualToIgnoringSeconds(OffsetTime.now());
}
@Test
- public void should_throw_error_if_given_offsettime_is_null() {
- expectIllegalArgumentException(NULL_OFFSET_TIME_PARAMETER_MESSAGE);
- assertThat(refOffsetTime).isEqualToIgnoringSeconds(null);
+ public void should_throw_error_if_given_offsetTime_is_null() {
+ expectIllegalArgumentException(NULL_OFFSET_TIME_PARAMETER_MESSAGE);
+ assertThat(refOffsetTime).isEqualToIgnoringSeconds(null);
}
}
diff --git a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isEqualToIgnoringTimezone_Test.java b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isEqualToIgnoringTimezone_Test.java
index 68949b5ad5a..b9f043e71be 100644
--- a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isEqualToIgnoringTimezone_Test.java
+++ b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isEqualToIgnoringTimezone_Test.java
@@ -12,15 +12,16 @@
*/
package org.assertj.core.api.offsettime;
-import org.assertj.core.api.BaseTest;
-import org.junit.Test;
+import static java.lang.String.format;
+import static org.assertj.core.api.AbstractOffsetTimeAssert.NULL_OFFSET_TIME_PARAMETER_MESSAGE;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.util.FailureMessages.actualIsNull;
import java.time.OffsetTime;
import java.time.ZoneOffset;
-import static org.assertj.core.api.AbstractOffsetTimeAssert.NULL_OFFSET_TIME_PARAMETER_MESSAGE;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.util.FailureMessages.actualIsNull;
+import org.assertj.core.api.BaseTest;
+import org.junit.Test;
public class OffsetTimeAssert_isEqualToIgnoringTimezone_Test extends BaseTest {
@@ -28,35 +29,35 @@ public class OffsetTimeAssert_isEqualToIgnoringTimezone_Test extends BaseTest {
@Test
public void should_pass_if_actual_is_equal_to_other_ignoring_timezone_fields() {
- assertThat(actual).isEqualToIgnoringTimezone(OffsetTime.of(12, 0, 0, 0, ZoneOffset.UTC));
+ assertThat(actual).isEqualToIgnoringTimezone(OffsetTime.of(12, 0, 0, 0, ZoneOffset.UTC));
}
@Test
public void should_fail_if_actual_is_not_equal_to_given_OffsetTime_with_timezone_ignored() {
- try {
- assertThat(actual).isEqualToIgnoringTimezone(OffsetTime.of(12, 1, 0, 0, ZoneOffset.UTC));
- } catch (AssertionError e) {
- assertThat(e).hasMessage("\nExpecting:\n " +
- "<12:00+18:00>\n" +
- "to have same time fields except timezone as:\n" +
- " <12:01Z>\n" +
- "but had not.");
- return;
- }
- failBecauseExpectedAssertionErrorWasNotThrown();
+ try {
+ assertThat(actual).isEqualToIgnoringTimezone(OffsetTime.of(12, 1, 0, 0, ZoneOffset.UTC));
+ } catch (AssertionError e) {
+ assertThat(e).hasMessage(format("%nExpecting:%n " +
+ "<12:00+18:00>%n" +
+ "to have same time fields except timezone as:%n" +
+ " <12:01Z>%n" +
+ "but had not."));
+ return;
+ }
+ failBecauseExpectedAssertionErrorWasNotThrown();
}
@Test
public void should_fail_if_actual_is_null() {
- expectException(AssertionError.class, actualIsNull());
- OffsetTime actual = null;
- assertThat(actual).isEqualToIgnoringTimezone(OffsetTime.now());
+ expectException(AssertionError.class, actualIsNull());
+ OffsetTime actual = null;
+ assertThat(actual).isEqualToIgnoringTimezone(OffsetTime.now());
}
@Test
- public void should_throw_error_if_given_OffsetTimetime_is_null() {
- expectIllegalArgumentException(NULL_OFFSET_TIME_PARAMETER_MESSAGE);
- assertThat(actual).isEqualToIgnoringTimezone(null);
+ public void should_throw_error_if_given_offsetTime_is_null() {
+ expectIllegalArgumentException(NULL_OFFSET_TIME_PARAMETER_MESSAGE);
+ assertThat(actual).isEqualToIgnoringTimezone(null);
}
}
diff --git a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isEqualTo_Test.java b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isEqualTo_Test.java
index 374077a5439..edb7ff1a84d 100644
--- a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isEqualTo_Test.java
+++ b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isEqualTo_Test.java
@@ -12,24 +12,27 @@
*/
package org.assertj.core.api.offsettime;
-import org.junit.Test;
-import org.junit.experimental.theories.Theories;
-import org.junit.experimental.theories.Theory;
-import org.junit.runner.RunWith;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
import java.time.OffsetTime;
import java.time.ZoneOffset;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
+import org.junit.Test;
+import org.junit.experimental.theories.Theories;
+import org.junit.experimental.theories.Theory;
+import org.junit.runner.RunWith;
@RunWith(Theories.class)
public class OffsetTimeAssert_isEqualTo_Test extends OffsetTimeAssertBaseTest {
@Theory
- public void test_isEqualTo_assertion(OffsetTime referenceTime) {
+ public void test_isEqualTo_assertion(OffsetTime referenceTime, OffsetTime timeBefore, OffsetTime timeEqual,
+ OffsetTime timeAfter) {
+ testAssumptions(referenceTime, timeBefore, timeEqual, timeAfter);
// WHEN
- assertThat(referenceTime).isEqualTo(referenceTime.toString());
+ assertThat(timeEqual).isEqualTo(referenceTime);
+ assertThat(timeEqual).isEqualTo(referenceTime.toString());
// THEN
verify_that_isEqualTo_assertion_fails_and_throws_AssertionError(referenceTime);
}
@@ -46,9 +49,9 @@ public void test_isEqualTo_assertion_error_message() {
}
@Test
- public void should_fail_if_timeTime_as_string_parameter_is_null() {
+ public void should_fail_if_offsetTime_as_string_parameter_is_null() {
expectException(IllegalArgumentException.class,
- "The String representing the OffsetTime to compare actual with should not be null");
+ "The String representing the OffsetTime to compare actual with should not be null");
assertThat(OffsetTime.now()).isEqualTo((String) null);
}
diff --git a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isIn_Test.java b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isIn_Test.java
index f0446dcabbf..68135a2d137 100644
--- a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isIn_Test.java
+++ b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isIn_Test.java
@@ -12,16 +12,17 @@
*/
package org.assertj.core.api.offsettime;
-import org.junit.Test;
-import org.junit.experimental.theories.Theories;
-import org.junit.experimental.theories.Theory;
-import org.junit.runner.RunWith;
+import static java.lang.String.format;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
import java.time.OffsetTime;
import java.time.ZoneOffset;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
+import org.junit.Test;
+import org.junit.experimental.theories.Theories;
+import org.junit.experimental.theories.Theory;
+import org.junit.runner.RunWith;
/**
* Only test String based assertion (tests with {@link java.time.OffsetTime} are already defined in assertj-core)
@@ -34,47 +35,48 @@ public class OffsetTimeAssert_isIn_Test extends OffsetTimeAssertBaseTest {
@Theory
public void test_isIn_assertion(OffsetTime referenceTime) {
- // WHEN
- assertThat(referenceTime).isIn(referenceTime.toString(), referenceTime.plusHours(1).toString());
- // THEN
- verify_that_isIn_assertion_fails_and_throws_AssertionError(referenceTime);
+ // WHEN
+ assertThat(referenceTime).isIn(referenceTime, referenceTime.plusHours(1));
+ assertThat(referenceTime).isIn(referenceTime.toString(), referenceTime.plusHours(1).toString());
+ // THEN
+ verify_that_isIn_assertion_fails_and_throws_AssertionError(referenceTime);
}
@Test
public void test_isIn_assertion_error_message() {
- try {
- assertThat(OffsetTime.of(3, 0, 5, 0, ZoneOffset.UTC)).isIn("03:03:03Z");
- } catch (AssertionError e) {
- assertThat(e).hasMessage("\n" +
- "Expecting:\n" +
- " <03:00:05Z>\n" +
- "to be in:\n" +
- " <[03:03:03Z]>\n");
- return;
- }
- fail("Should have thrown AssertionError");
+ try {
+ assertThat(OffsetTime.of(3, 0, 5, 0, ZoneOffset.UTC)).isIn("03:03:03Z");
+ } catch (AssertionError e) {
+ assertThat(e).hasMessage(format("%n" +
+ "Expecting:%n" +
+ " <03:00:05Z>%n" +
+ "to be in:%n" +
+ " <[03:03:03Z]>%n"));
+ return;
+ }
+ fail("Should have thrown AssertionError");
}
@Test
- public void should_fail_if_timeTimes_as_string_array_parameter_is_null() {
- expectException(IllegalArgumentException.class, "The given OffsetTime array should not be null");
- assertThat(OffsetTime.now()).isIn((String[]) null);
+ public void should_fail_if_offsetTimes_as_string_array_parameter_is_null() {
+ expectException(IllegalArgumentException.class, "The given OffsetTime array should not be null");
+ assertThat(OffsetTime.now()).isIn((String[]) null);
}
@Test
- public void should_fail_if_timeTimes_as_string_array_parameter_is_empty() {
- expectException(IllegalArgumentException.class, "The given OffsetTime array should not be empty");
- assertThat(OffsetTime.now()).isIn(new String[0]);
+ public void should_fail_if_offsetTimes_as_string_array_parameter_is_empty() {
+ expectException(IllegalArgumentException.class, "The given OffsetTime array should not be empty");
+ assertThat(OffsetTime.now()).isIn(new String[0]);
}
private static void verify_that_isIn_assertion_fails_and_throws_AssertionError(OffsetTime reference) {
- try {
- assertThat(reference).isIn(reference.plusHours(1).toString(), reference.plusHours(2).toString());
- } catch (AssertionError e) {
- // AssertionError was expected
- return;
- }
- fail("Should have thrown AssertionError");
+ try {
+ assertThat(reference).isIn(reference.plusHours(1).toString(), reference.plusHours(2).toString());
+ } catch (AssertionError e) {
+ // AssertionError was expected
+ return;
+ }
+ fail("Should have thrown AssertionError");
}
}
diff --git a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isNotEqualTo_Test.java b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isNotEqualTo_Test.java
index 5be31b52903..28bd4cbe08a 100644
--- a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isNotEqualTo_Test.java
+++ b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isNotEqualTo_Test.java
@@ -12,16 +12,17 @@
*/
package org.assertj.core.api.offsettime;
-import org.junit.Test;
-import org.junit.experimental.theories.Theories;
-import org.junit.experimental.theories.Theory;
-import org.junit.runner.RunWith;
+import static java.lang.String.format;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
import java.time.OffsetTime;
import java.time.ZoneOffset;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
+import org.junit.Test;
+import org.junit.experimental.theories.Theories;
+import org.junit.experimental.theories.Theory;
+import org.junit.runner.RunWith;
/**
* Only test String based assertion (tests with {@link java.time.OffsetTime} are already defined in assertj-core)
@@ -34,42 +35,42 @@ public class OffsetTimeAssert_isNotEqualTo_Test extends OffsetTimeAssertBaseTest
@Theory
public void test_isNotEqualTo_assertion(OffsetTime referenceTime) {
- // WHEN
- assertThat(referenceTime).isNotEqualTo(referenceTime.plusHours(1).toString());
- // THEN
- verify_that_isNotEqualTo_assertion_fails_and_throws_AssertionError(referenceTime);
+ // WHEN
+ assertThat(referenceTime).isNotEqualTo(referenceTime.plusHours(1).toString());
+ // THEN
+ verify_that_isNotEqualTo_assertion_fails_and_throws_AssertionError(referenceTime);
}
@Test
public void test_isNotEqualTo_assertion_error_message() {
- try {
- assertThat(OffsetTime.of(3, 0, 5, 0, ZoneOffset.UTC)).isNotEqualTo("03:00:05Z");
- } catch (AssertionError e) {
- assertThat(e).hasMessage("\n" +
- "Expecting:\n" +
- " <03:00:05Z>\n" +
- "not to be equal to:\n" +
- " <03:00:05Z>\n");
- return;
- }
- fail("Should have thrown AssertionError");
+ try {
+ assertThat(OffsetTime.of(3, 0, 5, 0, ZoneOffset.UTC)).isNotEqualTo("03:00:05Z");
+ } catch (AssertionError e) {
+ assertThat(e).hasMessage(format("%n" +
+ "Expecting:%n" +
+ " <03:00:05Z>%n" +
+ "not to be equal to:%n" +
+ " <03:00:05Z>%n"));
+ return;
+ }
+ fail("Should have thrown AssertionError");
}
@Test
- public void should_fail_if_timeTime_as_string_parameter_is_null() {
- expectException(IllegalArgumentException.class,
- "The String representing the OffsetTime to compare actual with should not be null");
- assertThat(OffsetTime.now()).isNotEqualTo((String) null);
+ public void should_fail_if_offsetTime_as_string_parameter_is_null() {
+ expectException(IllegalArgumentException.class,
+ "The String representing the OffsetTime to compare actual with should not be null");
+ assertThat(OffsetTime.now()).isNotEqualTo((String) null);
}
private static void verify_that_isNotEqualTo_assertion_fails_and_throws_AssertionError(OffsetTime reference) {
- try {
- assertThat(reference).isNotEqualTo(reference.toString());
- } catch (AssertionError e) {
- // AssertionError was expected
- return;
- }
- fail("Should have thrown AssertionError");
+ try {
+ assertThat(reference).isNotEqualTo(reference.toString());
+ } catch (AssertionError e) {
+ // AssertionError was expected
+ return;
+ }
+ fail("Should have thrown AssertionError");
}
}
diff --git a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isNotIn_Test.java b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isNotIn_Test.java
index f9b83b40769..9dee6512cfe 100644
--- a/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isNotIn_Test.java
+++ b/src/test/java/org/assertj/core/api/offsettime/OffsetTimeAssert_isNotIn_Test.java
@@ -12,16 +12,17 @@
*/
package org.assertj.core.api.offsettime;
-import org.junit.Test;
-import org.junit.experimental.theories.Theories;
-import org.junit.experimental.theories.Theory;
-import org.junit.runner.RunWith;
+import static java.lang.String.format;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
import java.time.OffsetTime;
import java.time.ZoneOffset;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
+import org.junit.Test;
+import org.junit.experimental.theories.Theories;
+import org.junit.experimental.theories.Theory;
+import org.junit.runner.RunWith;
/**
* Only test String based assertion (tests with {@link java.time.OffsetTime} are already defined in assertj-core)
@@ -34,47 +35,47 @@ public class OffsetTimeAssert_isNotIn_Test extends OffsetTimeAssertBaseTest {
@Theory
public void test_isNotIn_assertion(OffsetTime referenceTime) {
- // WHEN
- assertThat(referenceTime).isNotIn(referenceTime.plusHours(1).toString(), referenceTime.plusHours(2).toString());
- // THEN
- verify_that_isNotIn_assertion_fails_and_throws_AssertionError(referenceTime);
+ // WHEN
+ assertThat(referenceTime).isNotIn(referenceTime.plusHours(1).toString(), referenceTime.plusHours(2).toString());
+ // THEN
+ verify_that_isNotIn_assertion_fails_and_throws_AssertionError(referenceTime);
}
@Test
public void test_isNotIn_assertion_error_message() {
- try {
- assertThat(OffsetTime.of(3, 0, 5, 0, ZoneOffset.UTC)).isNotIn("03:00:05Z", "03:03:03Z");
- } catch (AssertionError e) {
- assertThat(e).hasMessage("\n" +
- "Expecting:\n" +
- " <03:00:05Z>\n" +
- "not to be in:\n" +
- " <[03:00:05Z, 03:03:03Z]>\n");
- return;
- }
- fail("Should have thrown AssertionError");
+ try {
+ assertThat(OffsetTime.of(3, 0, 5, 0, ZoneOffset.UTC)).isNotIn("03:00:05Z", "03:03:03Z");
+ } catch (AssertionError e) {
+ assertThat(e).hasMessage(format("%n" +
+ "Expecting:%n" +
+ " <03:00:05Z>%n" +
+ "not to be in:%n" +
+ " <[03:00:05Z, 03:03:03Z]>%n"));
+ return;
+ }
+ fail("Should have thrown AssertionError");
}
@Test
- public void should_fail_if_timeTimes_as_string_array_parameter_is_null() {
- expectException(IllegalArgumentException.class, "The given OffsetTime array should not be null");
- assertThat(OffsetTime.now()).isNotIn((String[]) null);
+ public void should_fail_if_offsetTimes_as_string_array_parameter_is_null() {
+ expectException(IllegalArgumentException.class, "The given OffsetTime array should not be null");
+ assertThat(OffsetTime.now()).isNotIn((String[]) null);
}
@Test
- public void should_fail_if_timeTimes_as_string_array_parameter_is_empty() {
- expectException(IllegalArgumentException.class, "The given OffsetTime array should not be empty");
- assertThat(OffsetTime.now()).isNotIn(new String[0]);
+ public void should_fail_if_offsetTimes_as_string_array_parameter_is_empty() {
+ expectException(IllegalArgumentException.class, "The given OffsetTime array should not be empty");
+ assertThat(OffsetTime.now()).isNotIn(new String[0]);
}
private static void verify_that_isNotIn_assertion_fails_and_throws_AssertionError(OffsetTime reference) {
- try {
- assertThat(reference).isNotIn(reference.toString(), reference.plusHours(1).toString());
- } catch (AssertionError e) {
- // AssertionError was expected
- return;
- }
- fail("Should have thrown AssertionError");
+ try {
+ assertThat(reference).isNotIn(reference.toString(), reference.plusHours(1).toString());
+ } catch (AssertionError e) {
+ // AssertionError was expected
+ return;
+ }
+ fail("Should have thrown AssertionError");
}
}