From 2b7394b0b5dfc9519ed05d06c2bc33e4e6e13d1a Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sat, 1 Apr 2017 18:48:10 +0100 Subject: [PATCH 001/279] Add Seconds temporal amount class Fixes #73 --- src/changes/changes.xml | 4 + src/main/java/org/threeten/extra/Hours.java | 14 +- src/main/java/org/threeten/extra/Minutes.java | 14 +- src/main/java/org/threeten/extra/Seconds.java | 610 ++++++++++++++++++ .../java/org/threeten/extra/TestSeconds.java | 456 +++++++++++++ 5 files changed, 1084 insertions(+), 14 deletions(-) create mode 100644 src/main/java/org/threeten/extra/Seconds.java create mode 100644 src/test/java/org/threeten/extra/TestSeconds.java diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 79c6a7f6..3d87a130 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -8,6 +8,10 @@ + + Add Seconds temporal amount class. + See #73. + Add Temporals.parseFirstMatching(). This allows text to be parsed against a number of different formats. diff --git a/src/main/java/org/threeten/extra/Hours.java b/src/main/java/org/threeten/extra/Hours.java index 5d829167..12399453 100644 --- a/src/main/java/org/threeten/extra/Hours.java +++ b/src/main/java/org/threeten/extra/Hours.java @@ -191,17 +191,17 @@ public static Hours parse(CharSequence text) { //----------------------------------------------------------------------- /** - * Obtains a {@code Hours} consisting of the number of hours between two dates. + * Obtains a {@code Hours} consisting of the number of hours between two temporals. *

- * The start date is included, but the end date is not. + * The start temporal is included, but the end temporal is not. * The result of this method can be negative if the end is before the start. * - * @param startDateInclusive the start date, inclusive, not null - * @param endDateExclusive the end date, exclusive, not null - * @return the number of hours between this date and the end date, not null + * @param startInclusive the start temporal, inclusive, not null + * @param endExclusive the end temporal, exclusive, not null + * @return the number of hours between the start and end temporals, not null */ - public static Hours between(Temporal startDateInclusive, Temporal endDateExclusive) { - return of(Math.toIntExact(HOURS.between(startDateInclusive, endDateExclusive))); + public static Hours between(Temporal startInclusive, Temporal endExclusive) { + return of(Math.toIntExact(HOURS.between(startInclusive, endExclusive))); } //----------------------------------------------------------------------- diff --git a/src/main/java/org/threeten/extra/Minutes.java b/src/main/java/org/threeten/extra/Minutes.java index 87e3d588..8e49ba6d 100644 --- a/src/main/java/org/threeten/extra/Minutes.java +++ b/src/main/java/org/threeten/extra/Minutes.java @@ -231,17 +231,17 @@ public static Minutes parse(CharSequence text) { //----------------------------------------------------------------------- /** - * Obtains a {@code Minutes} consisting of the number of minutes between two dates. + * Obtains a {@code Minutes} consisting of the number of minutes between two temporals. *

- * The start date is included, but the end date is not. + * The start temporal is included, but the end temporal is not. * The result of this method can be negative if the end is before the start. * - * @param startDateInclusive the start date, inclusive, not null - * @param endDateExclusive the end date, exclusive, not null - * @return the number of minutes between this date and the end date, not null + * @param startInclusive the start temporal, inclusive, not null + * @param endExclusive the end temporal, exclusive, not null + * @return the number of minutes between the start and end temporals, not null */ - public static Minutes between(Temporal startDateInclusive, Temporal endDateExclusive) { - return of(Math.toIntExact(MINUTES.between(startDateInclusive, endDateExclusive))); + public static Minutes between(Temporal startInclusive, Temporal endExclusive) { + return of(Math.toIntExact(MINUTES.between(startInclusive, endExclusive))); } //----------------------------------------------------------------------- diff --git a/src/main/java/org/threeten/extra/Seconds.java b/src/main/java/org/threeten/extra/Seconds.java new file mode 100644 index 00000000..9c66cdef --- /dev/null +++ b/src/main/java/org/threeten/extra/Seconds.java @@ -0,0 +1,610 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.extra; + +import static java.time.temporal.ChronoUnit.SECONDS; + +import java.io.Serializable; +import java.time.DateTimeException; +import java.time.Duration; +import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoUnit; +import java.time.temporal.Temporal; +import java.time.temporal.TemporalAmount; +import java.time.temporal.TemporalUnit; +import java.time.temporal.UnsupportedTemporalTypeException; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * A second-based amount of time, such as '8 seconds'. + *

+ * This class models a quantity or amount of time in terms of seconds. + * It is a type-safe way of representing a number of seconds in an application. + * Note that {@link Duration} also models time in terms of seconds, but that + * class allows nanoseconds, which this class does not. + *

+ * The model is of a directed amount, meaning that the amount may be negative. + * + *

Implementation Requirements:

+ * This class is immutable and thread-safe. + *

+ * This class must be treated as a value type. Do not synchronize, rely on the + * identity hash code or use the distinction between equals() and ==. + */ +public final class Seconds + implements TemporalAmount, Comparable, Serializable { + + /** + * A constant for zero seconds. + */ + public static final Seconds ZERO = new Seconds(0); + + /** + * A serialization identifier for this class. + */ + private static final long serialVersionUID = 2602801843170589407L; + + /** + * The number of seconds per hour. + */ + private static final int SECONDS_PER_HOUR = 3600; + /** + * The number of seconds per minute. + */ + private static final int SECONDS_PER_MINUTE = 60; + + /** + * The pattern for parsing. + */ + private static final Pattern PATTERN = + Pattern.compile("([-+]?)PT" + + "(?:([-+]?[0-9]+)H)?" + + "(?:([-+]?[0-9]+)M)?" + + "(?:([-+]?[0-9]+)S)?", Pattern.CASE_INSENSITIVE); + + /** + * The number of seconds. + */ + private final int seconds; + + /** + * Obtains a {@code Seconds} representing a number of seconds. + *

+ * The resulting amount will have the specified seconds. + * + * @param seconds the number of seconds, positive or negative + * @return the number of seconds, not null + */ + public static Seconds of(int seconds) { + if (seconds == 0) { + return ZERO; + } + return new Seconds(seconds); + } + + /** + * Obtains a {@code Seconds} representing the number of seconds + * equivalent to a number of hours. + *

+ * The resulting amount will be second-based, with the number of seconds + * equal to the number of hours multiplied by 3600. + * + * @param hours the number of hours, positive or negative + * @return the amount with the input hours converted to seconds, not null + * @throws ArithmeticException if numeric overflow occurs + */ + public static Seconds ofHours(int hours) { + if (hours == 0) { + return ZERO; + } + return new Seconds(Math.multiplyExact(hours, SECONDS_PER_HOUR)); + } + + /** + * Obtains a {@code Seconds} representing the number of seconds + * equivalent to a number of hours. + *

+ * The resulting amount will be second-based, with the number of seconds + * equal to the number of minutes multiplied by 60. + * + * @param minutes the number of minutes, positive or negative + * @return the amount with the input minutes converted to seconds, not null + * @throws ArithmeticException if numeric overflow occurs + */ + public static Seconds ofMinutes(int minutes) { + if (minutes == 0) { + return ZERO; + } + return new Seconds(Math.multiplyExact(minutes, SECONDS_PER_MINUTE)); + } + + //----------------------------------------------------------------------- + /** + * Obtains an instance of {@code Seconds} from a temporal amount. + *

+ * This obtains an instance based on the specified amount. + * A {@code TemporalAmount} represents an amount of time, which may be + * date-based or time-based, which this factory extracts to a {@code Seconds}. + *

+ * The result is calculated by looping around each unit in the specified amount. + * Each amount is converted to seconds using {@link Temporals#convertAmount}. + * If the conversion yields a remainder, an exception is thrown. + * If the amount is zero, the unit is ignored. + * + * @param amount the temporal amount to convert, not null + * @return the equivalent amount, not null + * @throws DateTimeException if unable to convert to a {@code Seconds} + * @throws ArithmeticException if numeric overflow occurs + */ + public static Seconds from(TemporalAmount amount) { + if (amount instanceof Seconds) { + return (Seconds) amount; + } + Objects.requireNonNull(amount, "amount"); + int seconds = 0; + for (TemporalUnit unit : amount.getUnits()) { + long value = amount.get(unit); + if (value != 0) { + long[] converted = Temporals.convertAmount(value, unit, SECONDS); + if (converted[1] != 0) { + throw new DateTimeException( + "Amount could not be converted to a whole number of seconds: " + value + " " + unit); + } + seconds = Math.addExact(seconds, Math.toIntExact(converted[0])); + } + } + return of(seconds); + } + + //----------------------------------------------------------------------- + /** + * Obtains a {@code Seconds} from a text string such as {@code PTnS}. + *

+ * This will parse the string produced by {@code toString()} which is + * based on the ISO-8601 period format {@code PTnHnMnS}. + *

+ * The string starts with an optional sign, denoted by the ASCII negative + * or positive symbol. If negative, the whole amount is negated. + * The ASCII letters "P" and "T" are next in upper or lower case. + * There are then three sections, each consisting of a number and a suffix. + * At least one of the three sections must be present. + * The sections have suffixes in ASCII of "H", "M" and "S" for hours, minutes and seconds, + * accepted in upper or lower case. The suffixes must occur in order. + * The number part of each section must consist of ASCII digits. + * The number may be prefixed by the ASCII negative or positive symbol. + * The number must parse to an {@code int}. + *

+ * The leading plus/minus sign, and negative values for hours, minutes and + * seconds are not part of the ISO-8601 standard. + *

+ * For example, the following are valid inputs: + *

+     *   "PT2S"            -- Seconds.of(2)
+     *   "PT-2S"           -- Seconds.of(-2)
+     *   "-PT2S"           -- Seconds.of(-2)
+     *   "-PT-2S"          -- Seconds.of(2)
+     *   "PT3S"            -- Seconds.of(3 * 60)
+     *   "PT3H-2M7S"         -- Seconds.of(3 * 3600 - 2 * 60 + 7)
+     * 
+ * + * @param text the text to parse, not null + * @return the parsed period, not null + * @throws DateTimeParseException if the text cannot be parsed to a period + */ + public static Seconds parse(CharSequence text) { + Objects.requireNonNull(text, "text"); + Matcher matcher = PATTERN.matcher(text); + if (matcher.matches()) { + int negate = ("-".equals(matcher.group(1)) ? -1 : 1); + String hoursStr = matcher.group(2); + String minutesStr = matcher.group(3); + String secondsStr = matcher.group(4); + if (hoursStr != null || minutesStr != null || secondsStr != null) { + int seconds = 0; + if (secondsStr != null) { + try { + seconds = Integer.parseInt(secondsStr); + } catch (NumberFormatException ex) { + throw new DateTimeParseException("Text cannot be parsed to a Seconds, non-numeric seconds", text, 0, ex); + } + } + if (minutesStr != null) { + try { + int minutes = Math.multiplyExact(Integer.parseInt(minutesStr), SECONDS_PER_MINUTE); + seconds = Math.addExact(seconds, minutes); + } catch (NumberFormatException ex) { + throw new DateTimeParseException("Text cannot be parsed to a Seconds, non-numeric minutes", text, 0, ex); + } + } + if (hoursStr != null) { + try { + int hours = Math.multiplyExact(Integer.parseInt(hoursStr), SECONDS_PER_HOUR); + seconds = Math.addExact(seconds, hours); + } catch (NumberFormatException ex) { + throw new DateTimeParseException("Text cannot be parsed to a Seconds, non-numeric seconds", text, 0, ex); + } + } + return of(Math.multiplyExact(seconds, negate)); + } + } + throw new DateTimeParseException("Text cannot be parsed to a Seconds", text, 0); + } + + //----------------------------------------------------------------------- + /** + * Obtains a {@code Seconds} consisting of the number of seconds between two temporals. + *

+ * The start temporal is included, but the end temporal is not. + * The result of this method can be negative if the end is before the start. + * + * @param startInclusive the start temporal, inclusive, not null + * @param endExclusive the end temporal, exclusive, not null + * @return the number of seconds between the start and end temporals, not null + */ + public static Seconds between(Temporal startInclusive, Temporal endExclusive) { + return of(Math.toIntExact(SECONDS.between(startInclusive, endExclusive))); + } + + //----------------------------------------------------------------------- + /** + * Constructs an instance using a specific number of seconds. + * + * @param seconds the amount of seconds + */ + private Seconds(int seconds) { + this.seconds = seconds; + } + + /** + * Resolves singletons. + * + * @return the singleton instance + */ + private Object readResolve() { + return Seconds.of(seconds); + } + + //----------------------------------------------------------------------- + /** + * Gets the value of the requested unit. + *

+ * This returns a value for the supported unit - {@link ChronoUnit#SECONDS SECONDS}. + * All other units throw an exception. + * + * @param unit the {@code TemporalUnit} for which to return the value + * @return the long value of the unit + * @throws UnsupportedTemporalTypeException if the unit is not supported + */ + @Override + public long get(TemporalUnit unit) { + if (unit == SECONDS) { + return seconds; + } + throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); + } + + /** + * Gets the set of units supported by this amount. + *

+ * The single supported unit is {@link ChronoUnit#SECONDS SECONDS}. + *

+ * This set can be used in conjunction with {@link #get(TemporalUnit)} to + * access the entire state of the amount. + * + * @return a list containing the seconds unit, not null + */ + @Override + public List getUnits() { + return Collections.singletonList(SECONDS); + } + + //----------------------------------------------------------------------- + /** + * Gets the number of seconds in this amount. + * + * @return the number of seconds + */ + public int getAmount() { + return seconds; + } + + //----------------------------------------------------------------------- + /** + * Returns a copy of this amount with the specified amount added. + *

+ * The parameter is converted using {@link Seconds#from(TemporalAmount)}. + *

+ * This instance is immutable and unaffected by this method call. + * + * @param amountToAdd the amount to add, not null + * @return a {@code Seconds} based on this instance with the requested amount added, not null + * @throws DateTimeException if the specified amount contains an invalid unit + * @throws ArithmeticException if numeric overflow occurs + */ + public Seconds plus(TemporalAmount amountToAdd) { + return plus(Seconds.from(amountToAdd).getAmount()); + } + + /** + * Returns a copy of this amount with the specified number of seconds added. + *

+ * This instance is immutable and unaffected by this method call. + * + * @param seconds the amount of seconds to add, may be negative + * @return a {@code Seconds} based on this instance with the requested amount added, not null + * @throws ArithmeticException if the result overflows an int + */ + public Seconds plus(int seconds) { + if (seconds == 0) { + return this; + } + return of(Math.addExact(this.seconds, seconds)); + } + + //----------------------------------------------------------------------- + /** + * Returns a copy of this amount with the specified amount subtracted. + *

+ * The parameter is converted using {@link Seconds#from(TemporalAmount)}. + *

+ * This instance is immutable and unaffected by this method call. + * + * @param amountToAdd the amount to add, not null + * @return a {@code Seconds} based on this instance with the requested amount subtracted, not null + * @throws DateTimeException if the specified amount contains an invalid unit + * @throws ArithmeticException if numeric overflow occurs + */ + public Seconds minus(TemporalAmount amountToAdd) { + return minus(Seconds.from(amountToAdd).getAmount()); + } + + /** + * Returns a copy of this amount with the specified number of seconds subtracted. + *

+ * This instance is immutable and unaffected by this method call. + * + * @param seconds the amount of seconds to add, may be negative + * @return a {@code Seconds} based on this instance with the requested amount subtracted, not null + * @throws ArithmeticException if the result overflows an int + */ + public Seconds minus(int seconds) { + if (seconds == 0) { + return this; + } + return of(Math.subtractExact(this.seconds, seconds)); + } + + //----------------------------------------------------------------------- + /** + * Returns an instance with the amount multiplied by the specified scalar. + *

+ * This instance is immutable and unaffected by this method call. + * + * @param scalar the scalar to multiply by, not null + * @return the amount multiplied by the specified scalar, not null + * @throws ArithmeticException if numeric overflow occurs + */ + public Seconds multipliedBy(int scalar) { + if (scalar == 1) { + return this; + } + return of(Math.multiplyExact(seconds, scalar)); + } + + /** + * Returns an instance with the amount divided by the specified divisor. + *

+ * The calculation uses integer division, thus 3 divided by 2 is 1. + *

+ * This instance is immutable and unaffected by this method call. + * + * @param divisor the amount to divide by, may be negative + * @return the amount divided by the specified divisor, not null + * @throws ArithmeticException if the divisor is zero + */ + public Seconds dividedBy(int divisor) { + if (divisor == 1) { + return this; + } + return of(seconds / divisor); + } + + /** + * Returns an instance with the amount negated. + *

+ * This instance is immutable and unaffected by this method call. + * + * @return the negated amount, not null + * @throws ArithmeticException if numeric overflow occurs, which only happens if + * the amount is {@code Long.MIN_VALUE} + */ + public Seconds negated() { + return multipliedBy(-1); + } + + /** + * Returns a copy of this duration with a positive length. + *

+ * This method returns a positive duration by effectively removing the sign from any negative total length. + *

+ * This instance is immutable and unaffected by this method call. + * + * @return the absolute amount, not null + * @throws ArithmeticException if numeric overflow occurs, which only happens if + * the amount is {@code Long.MIN_VALUE} + */ + public Seconds abs() { + return seconds < 0 ? negated() : this; + } + + //------------------------------------------------------------------------- + /** + * Gets the number of seconds as a {@code Duration}. + *

+ * This returns a duration with the same number of seconds. + * + * @return the equivalent duration, not null + */ + public Duration toDuration() { + return Duration.ofSeconds(seconds); + } + + //----------------------------------------------------------------------- + /** + * Adds this amount to the specified temporal object. + *

+ * This returns a temporal object of the same observable type as the input + * with this amount added. + *

+ * In most cases, it is clearer to reverse the calling pattern by using + * {@link Temporal#plus(TemporalAmount)}. + *

+     *   // these two lines are equivalent, but the second approach is recommended
+     *   dateTime = thisAmount.addTo(dateTime);
+     *   dateTime = dateTime.plus(thisAmount);
+     * 
+ *

+ * Only non-zero amounts will be added. + *

+ * This instance is immutable and unaffected by this method call. + * + * @param temporal the temporal object to adjust, not null + * @return an object of the same type with the adjustment made, not null + * @throws DateTimeException if unable to add + * @throws UnsupportedTemporalTypeException if the SECONDS unit is not supported + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public Temporal addTo(Temporal temporal) { + if (seconds != 0) { + temporal = temporal.plus(seconds, SECONDS); + } + return temporal; + } + + /** + * Subtracts this amount from the specified temporal object. + *

+ * This returns a temporal object of the same observable type as the input + * with this amount subtracted. + *

+ * In most cases, it is clearer to reverse the calling pattern by using + * {@link Temporal#minus(TemporalAmount)}. + *

+     *   // these two lines are equivalent, but the second approach is recommended
+     *   dateTime = thisAmount.subtractFrom(dateTime);
+     *   dateTime = dateTime.minus(thisAmount);
+     * 
+ *

+ * Only non-zero amounts will be subtracted. + *

+ * This instance is immutable and unaffected by this method call. + * + * @param temporal the temporal object to adjust, not null + * @return an object of the same type with the adjustment made, not null + * @throws DateTimeException if unable to subtract + * @throws UnsupportedTemporalTypeException if the SECONDS unit is not supported + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public Temporal subtractFrom(Temporal temporal) { + if (seconds != 0) { + temporal = temporal.minus(seconds, SECONDS); + } + return temporal; + } + + //----------------------------------------------------------------------- + /** + * Compares this amount to the specified {@code Seconds}. + *

+ * The comparison is based on the total length of the amounts. + * It is "consistent with equals", as defined by {@link Comparable}. + * + * @param otherAmount the other amount, not null + * @return the comparator value, negative if less, positive if greater + */ + @Override + public int compareTo(Seconds otherAmount) { + int thisValue = this.seconds; + int otherValue = otherAmount.seconds; + return Integer.compare(thisValue, otherValue); + } + + //----------------------------------------------------------------------- + /** + * Checks if this amount is equal to the specified {@code Seconds}. + *

+ * The comparison is based on the total length of the durations. + * + * @param otherAmount the other amount, null returns false + * @return true if the other amount is equal to this one + */ + @Override + public boolean equals(Object otherAmount) { + if (this == otherAmount) { + return true; + } + if (otherAmount instanceof Seconds) { + Seconds other = (Seconds) otherAmount; + return this.seconds == other.seconds; + } + return false; + } + + /** + * A hash code for this amount. + * + * @return a suitable hash code + */ + @Override + public int hashCode() { + return seconds; + } + + //----------------------------------------------------------------------- + /** + * Returns a string representation of the number of seconds. + * This will be in the format 'PTnS' where n is the number of seconds. + * + * @return the number of seconds in ISO-8601 string format + */ + @Override + public String toString() { + return "PT" + seconds + "S"; + } + +} diff --git a/src/test/java/org/threeten/extra/TestSeconds.java b/src/test/java/org/threeten/extra/TestSeconds.java new file mode 100644 index 00000000..bdc399be --- /dev/null +++ b/src/test/java/org/threeten/extra/TestSeconds.java @@ -0,0 +1,456 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.extra; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertSame; +import static org.testng.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.time.Duration; +import java.time.LocalTime; +import java.time.format.DateTimeParseException; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * Test class. + */ +@Test +public class TestSeconds { + + //----------------------------------------------------------------------- + public void test_isSerializable() { + assertTrue(Serializable.class.isAssignableFrom(Seconds.class)); + } + + //----------------------------------------------------------------------- + public void test_deserializationSingleton() throws Exception { + Seconds orginal = Seconds.ZERO; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(baos); + out.writeObject(orginal); + out.close(); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStream in = new ObjectInputStream(bais); + Seconds ser = (Seconds) in.readObject(); + assertSame(Seconds.ZERO, ser); + } + + //----------------------------------------------------------------------- + public void test_ZERO() { + assertSame(Seconds.of(0), Seconds.ZERO); + assertSame(Seconds.of(0), Seconds.ZERO); + assertEquals(Seconds.ZERO.getAmount(), 0); + } + + //----------------------------------------------------------------------- + public void test_of() { + assertEquals(Seconds.of(0).getAmount(), 0); + assertEquals(Seconds.of(1).getAmount(), 1); + assertEquals(Seconds.of(2).getAmount(), 2); + assertEquals(Seconds.of(Integer.MAX_VALUE).getAmount(), Integer.MAX_VALUE); + assertEquals(Seconds.of(-1).getAmount(), -1); + assertEquals(Seconds.of(-2).getAmount(), -2); + assertEquals(Seconds.of(Integer.MIN_VALUE).getAmount(), Integer.MIN_VALUE); + } + + //----------------------------------------------------------------------- + public void test_ofHours() { + assertEquals(Seconds.ofHours(0).getAmount(), 0); + assertEquals(Seconds.ofHours(1).getAmount(), 3600); + assertEquals(Seconds.ofHours(2).getAmount(), 7200); + assertEquals(Seconds.ofHours(Integer.MAX_VALUE / 3600).getAmount(), (Integer.MAX_VALUE / 3600) * 3600); + assertEquals(Seconds.ofHours(-1).getAmount(), -3600); + assertEquals(Seconds.ofHours(-2).getAmount(), -7200); + assertEquals(Seconds.ofHours(Integer.MIN_VALUE / 3600).getAmount(), (Integer.MIN_VALUE / 3600) * 3600); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_ofHours_overflow() { + Seconds.ofHours((Integer.MAX_VALUE / 3600) + 3600); + } + + //----------------------------------------------------------------------- + public void test_ofMinutes() { + assertEquals(Seconds.ofMinutes(0).getAmount(), 0); + assertEquals(Seconds.ofMinutes(1).getAmount(), 60); + assertEquals(Seconds.ofMinutes(2).getAmount(), 120); + assertEquals(Seconds.ofMinutes(Integer.MAX_VALUE / 60).getAmount(), (Integer.MAX_VALUE / 60) * 60); + assertEquals(Seconds.ofMinutes(-1).getAmount(), -60); + assertEquals(Seconds.ofMinutes(-2).getAmount(), -120); + assertEquals(Seconds.ofMinutes(Integer.MIN_VALUE / 60).getAmount(), (Integer.MIN_VALUE / 60) * 60); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_ofMinutes_overflow() { + Seconds.ofMinutes((Integer.MAX_VALUE / 60) + 60); + } + + //----------------------------------------------------------------------- + @DataProvider(name = "parseValid") + Object[][] data_valid() { + return new Object[][] { + {"PT0S", 0}, + {"PT1S", 1}, + {"PT2S", 2}, + {"PT123456789S", 123456789}, + {"PT+0S", 0}, + {"PT+2S", 2}, + {"PT-0S", 0}, + {"PT-2S", -2}, + + {"PT0M", 0}, + {"PT1M", 60}, + {"PT2M", 120}, + {"PT1234M", 1234 * 60}, + {"PT+0M", 0}, + {"PT+2M", 120}, + {"PT-0M", 0}, + {"PT-2M", -120}, + + {"PT0H", 0}, + {"PT1H", 60 * 60}, + {"PT2H", 120 * 60}, + {"PT1234H", 1234 * 60 * 60}, + {"PT+0H", 0}, + {"PT+2H", 120 * 60}, + {"PT-0H", 0}, + {"PT-2H", -120 * 60}, + + {"PT0M0S", 0}, + {"PT2M3S", 2 * 60 + 3}, + {"PT+2M3S", 2 * 60 + 3}, + {"PT2M+3S", 2 * 60 + 3}, + {"PT-2M3S", -2 * 60 + 3}, + {"PT2M-3S", 2 * 60 - 3}, + {"PT-2M-3S", -2 * 60 - 3}, + + {"PT0H0S", 0}, + {"PT2H3S", 2 * 3600 + 3}, + {"PT+2H3S", 2 * 3600 + 3}, + {"PT2H+3S", 2 * 3600 + 3}, + {"PT-2H3S", -2 * 3600 + 3}, + {"PT2H-3S", 2 * 3600 - 3}, + {"PT-2H-3S", -2 * 3600 - 3}, + + {"PT0H0M0S", 0}, + {"PT2H4M3S", 2 * 3600 + 4 * 60 + 3}, + }; + } + + @Test(dataProvider = "parseValid") + public void test_parse_CharSequence_valid(String str, int expectedSeconds) { + assertEquals(Seconds.parse(str), Seconds.of(expectedSeconds)); + } + + @Test(dataProvider = "parseValid") + public void test_parse_CharSequence_valid_initialPlus(String str, int expectedSeconds) { + assertEquals(Seconds.parse("+" + str), Seconds.of(expectedSeconds)); + } + + @Test(dataProvider = "parseValid") + public void test_parse_CharSequence_valid_initialMinus(String str, int expectedSeconds) { + assertEquals(Seconds.parse("-" + str), Seconds.of(-expectedSeconds)); + } + + @DataProvider(name = "parseInvalid") + Object[][] data_invalid() { + return new Object[][] { + {"P3W"}, + {"P3D"}, + {"P3Q"}, + {"P1M2Y"}, + + {"3"}, + {"-3"}, + {"3S"}, + {"-3S"}, + {"P3"}, + {"P-3"}, + {"PS"}, + {"T3"}, + {"PT3"}, + }; + } + + @Test(expectedExceptions = DateTimeParseException.class, dataProvider = "parseInvalid") + public void test_parse_CharSequence_invalid(String str) { + Seconds.parse(str); + } + + @Test(expectedExceptions = NullPointerException.class) + public void test_parse_CharSequence_null() { + Seconds.parse((CharSequence) null); + } + + //----------------------------------------------------------------------- + public void test_plus_TemporalAmount_Seconds() { + Seconds test5 = Seconds.of(5); + assertEquals(Seconds.of(5), test5.plus(Seconds.of(0))); + assertEquals(Seconds.of(7), test5.plus(Seconds.of(2))); + assertEquals(Seconds.of(3), test5.plus(Seconds.of(-2))); + assertEquals(Seconds.of(Integer.MAX_VALUE), Seconds.of(Integer.MAX_VALUE - 1).plus(Seconds.of(1))); + assertEquals(Seconds.of(Integer.MIN_VALUE), Seconds.of(Integer.MIN_VALUE + 1).plus(Seconds.of(-1))); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_plus_TemporalAmount_overflowTooBig() { + Seconds.of(Integer.MAX_VALUE - 1).plus(Seconds.of(2)); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_plus_TemporalAmount_overflowTooSmall() { + Seconds.of(Integer.MIN_VALUE + 1).plus(Seconds.of(-2)); + } + + @Test(expectedExceptions = NullPointerException.class) + public void test_plus_TemporalAmount_null() { + Seconds.of(Integer.MIN_VALUE + 1).plus(null); + } + + //----------------------------------------------------------------------- + public void test_plus_int() { + Seconds test5 = Seconds.of(5); + assertEquals(Seconds.of(5), test5.plus(0)); + assertEquals(Seconds.of(7), test5.plus(2)); + assertEquals(Seconds.of(3), test5.plus(-2)); + assertEquals(Seconds.of(Integer.MAX_VALUE), Seconds.of(Integer.MAX_VALUE - 1).plus(1)); + assertEquals(Seconds.of(Integer.MIN_VALUE), Seconds.of(Integer.MIN_VALUE + 1).plus(-1)); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_plus_int_overflowTooBig() { + Seconds.of(Integer.MAX_VALUE - 1).plus(2); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_plus_int_overflowTooSmall() { + Seconds.of(Integer.MIN_VALUE + 1).plus(-2); + } + + //----------------------------------------------------------------------- + public void test_minus_TemporalAmount_Seconds() { + Seconds test5 = Seconds.of(5); + assertEquals(Seconds.of(5), test5.minus(Seconds.of(0))); + assertEquals(Seconds.of(3), test5.minus(Seconds.of(2))); + assertEquals(Seconds.of(7), test5.minus(Seconds.of(-2))); + assertEquals(Seconds.of(Integer.MAX_VALUE), Seconds.of(Integer.MAX_VALUE - 1).minus(Seconds.of(-1))); + assertEquals(Seconds.of(Integer.MIN_VALUE), Seconds.of(Integer.MIN_VALUE + 1).minus(Seconds.of(1))); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_minus_TemporalAmount_overflowTooBig() { + Seconds.of(Integer.MAX_VALUE - 1).minus(Seconds.of(-2)); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_minus_TemporalAmount_overflowTooSmall() { + Seconds.of(Integer.MIN_VALUE + 1).minus(Seconds.of(2)); + } + + @Test(expectedExceptions = NullPointerException.class) + public void test_minus_TemporalAmount_null() { + Seconds.of(Integer.MIN_VALUE + 1).minus(null); + } + + //----------------------------------------------------------------------- + public void test_minus_int() { + Seconds test5 = Seconds.of(5); + assertEquals(Seconds.of(5), test5.minus(0)); + assertEquals(Seconds.of(3), test5.minus(2)); + assertEquals(Seconds.of(7), test5.minus(-2)); + assertEquals(Seconds.of(Integer.MAX_VALUE), Seconds.of(Integer.MAX_VALUE - 1).minus(-1)); + assertEquals(Seconds.of(Integer.MIN_VALUE), Seconds.of(Integer.MIN_VALUE + 1).minus(1)); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_minus_int_overflowTooBig() { + Seconds.of(Integer.MAX_VALUE - 1).minus(-2); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_minus_int_overflowTooSmall() { + Seconds.of(Integer.MIN_VALUE + 1).minus(2); + } + + //----------------------------------------------------------------------- + public void test_multipliedBy() { + Seconds test5 = Seconds.of(5); + assertEquals(Seconds.of(0), test5.multipliedBy(0)); + assertEquals(Seconds.of(5), test5.multipliedBy(1)); + assertEquals(Seconds.of(10), test5.multipliedBy(2)); + assertEquals(Seconds.of(15), test5.multipliedBy(3)); + assertEquals(Seconds.of(-15), test5.multipliedBy(-3)); + } + + public void test_multipliedBy_negate() { + Seconds test5 = Seconds.of(5); + assertEquals(Seconds.of(-15), test5.multipliedBy(-3)); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_multipliedBy_overflowTooBig() { + Seconds.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_multipliedBy_overflowTooSmall() { + Seconds.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2); + } + + //----------------------------------------------------------------------- + public void test_dividedBy() { + Seconds test12 = Seconds.of(12); + assertEquals(Seconds.of(12), test12.dividedBy(1)); + assertEquals(Seconds.of(6), test12.dividedBy(2)); + assertEquals(Seconds.of(4), test12.dividedBy(3)); + assertEquals(Seconds.of(3), test12.dividedBy(4)); + assertEquals(Seconds.of(2), test12.dividedBy(5)); + assertEquals(Seconds.of(2), test12.dividedBy(6)); + assertEquals(Seconds.of(-4), test12.dividedBy(-3)); + } + + public void test_dividedBy_negate() { + Seconds test12 = Seconds.of(12); + assertEquals(Seconds.of(-4), test12.dividedBy(-3)); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_dividedBy_divideByZero() { + Seconds.of(1).dividedBy(0); + } + + //----------------------------------------------------------------------- + public void test_negated() { + assertEquals(Seconds.of(0), Seconds.of(0).negated()); + assertEquals(Seconds.of(-12), Seconds.of(12).negated()); + assertEquals(Seconds.of(12), Seconds.of(-12).negated()); + assertEquals(Seconds.of(-Integer.MAX_VALUE), Seconds.of(Integer.MAX_VALUE).negated()); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_negated_overflow() { + Seconds.of(Integer.MIN_VALUE).negated(); + } + + //----------------------------------------------------------------------- + public void test_abs() { + assertEquals(Seconds.of(0), Seconds.of(0).abs()); + assertEquals(Seconds.of(12), Seconds.of(12).abs()); + assertEquals(Seconds.of(12), Seconds.of(-12).abs()); + assertEquals(Seconds.of(Integer.MAX_VALUE), Seconds.of(Integer.MAX_VALUE).abs()); + assertEquals(Seconds.of(Integer.MAX_VALUE), Seconds.of(-Integer.MAX_VALUE).abs()); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_abs_overflow() { + Seconds.of(Integer.MIN_VALUE).abs(); + } + + //----------------------------------------------------------------------- + public void test_addTo() { + LocalTime base = LocalTime.of(11, 30); + assertEquals(Seconds.of(0).addTo(base), LocalTime.of(11, 30)); + assertEquals(Seconds.of(6).addTo(base), LocalTime.of(11, 30, 6)); + } + + //----------------------------------------------------------------------- + public void test_subtractFrom() { + LocalTime base = LocalTime.of(11, 30); + assertEquals(Seconds.of(0).subtractFrom(base), LocalTime.of(11, 30)); + assertEquals(Seconds.of(6).subtractFrom(base), LocalTime.of(11, 29, 54)); + } + + //----------------------------------------------------------------------- + public void test_toDuration() { + for (int i = -20; i < 20; i++) { + assertEquals(Seconds.of(i).toDuration(), Duration.ofSeconds(i)); + } + } + + //----------------------------------------------------------------------- + public void test_compareTo() { + Seconds test5 = Seconds.of(5); + Seconds test6 = Seconds.of(6); + assertEquals(0, test5.compareTo(test5)); + assertEquals(-1, test5.compareTo(test6)); + assertEquals(1, test6.compareTo(test5)); + } + + @Test(expectedExceptions = NullPointerException.class) + public void test_compareTo_null() { + Seconds test5 = Seconds.of(5); + test5.compareTo(null); + } + + //----------------------------------------------------------------------- + public void test_equals() { + Seconds test5 = Seconds.of(5); + Seconds test6 = Seconds.of(6); + assertEquals(true, test5.equals(test5)); + assertEquals(false, test5.equals(test6)); + assertEquals(false, test6.equals(test5)); + } + + public void test_equals_null() { + Seconds test5 = Seconds.of(5); + assertEquals(false, test5.equals(null)); + } + + public void test_equals_otherClass() { + Seconds test5 = Seconds.of(5); + assertEquals(false, test5.equals("")); + } + + //----------------------------------------------------------------------- + public void test_hashCode() { + Seconds test5 = Seconds.of(5); + Seconds test6 = Seconds.of(6); + assertEquals(true, test5.hashCode() == test5.hashCode()); + assertEquals(false, test5.hashCode() == test6.hashCode()); + } + + //----------------------------------------------------------------------- + public void test_toString() { + Seconds test5 = Seconds.of(5); + assertEquals("PT5S", test5.toString()); + Seconds testM1 = Seconds.of(-1); + assertEquals("PT-1S", testM1.toString()); + } + +} From 5a3413c85db15f54e477d238e679720f88ab4f47 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sat, 1 Apr 2017 19:16:28 +0100 Subject: [PATCH 002/279] Update Travis --- .github/maven-settings.xml | 13 ++++++ .travis.yml | 24 +++++++---- README.md | 9 +++++ pom.xml | 82 +++++++++++++++++--------------------- 4 files changed, 74 insertions(+), 54 deletions(-) create mode 100644 .github/maven-settings.xml diff --git a/.github/maven-settings.xml b/.github/maven-settings.xml new file mode 100644 index 00000000..5fbfc607 --- /dev/null +++ b/.github/maven-settings.xml @@ -0,0 +1,13 @@ + + + + github + + ${GITHUB_TOKEN} + + + + diff --git a/.travis.yml b/.travis.yml index c0898988..3a8f0f0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,18 @@ -# This file enables the Travis continuous integration system, which -# automatically builds and tests the project for each GitHub commit or -# pull request on three separate JDKs. -# -# For more information, see https://travis-ci.org - +sudo: false language: java - -jdk: +jdk: - oraclejdk8 +cache: + directories: + - "$HOME/.m2/repository" +before_cache: + - rm -rf $HOME/.m2/repository/org/threeten +install: + - mvn --version +script: + - mvn install -e -B + - if [[ $TRAVIS_TAG =~ ^v.*$ ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_JDK_VERSION" == "oraclejdk8" ]; then travis_wait 40 mvn site-deploy -e -B --settings .github/maven-settings.xml; fi +# secure keys for GITHUB_TOKEN +env: + global: + - secure: FaC3K5L6pGdJgvPcttpq8kV5i+UUsj5FWvETqm82BZWzLTYlQsCL4fl2XfssATiH7hIVioRffYoZP8rQbkNatVV+Pok6wZePSM9kOf7/AUOn0dvwXH718sbWlohOf3R3886/l5rjyJDDmauMABXzLrXxsTlbiQ85QNA0mCbqXJ4= diff --git a/README.md b/README.md index bfce2239..de2e5c52 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,12 @@ Available in the [Maven Central repository](http://search.maven.org/#artifactdet ### Support Please use GitHub [issues](https://github.com/ThreeTen/threeten-extra/issues) and Pull Requests for support. + + +### Release process + +* Update version (pom.xml, README.md, index.md, changes.xml) +* Commit and push +* `mvn clean deploy -Doss.repo -Dgpg.passphrase=""` +* Release project in [Nexus](https://oss.sonatype.org) +* Website will be built and released by Travis diff --git a/pom.xml b/pom.xml index 391cd616..de04537f 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ ThreeTen-Extra 1.1-SNAPSHOT Additional functionality that enhances JSR-310 dates and times in JDK 8 - https://www.threeten.org/threeten-extra + http://www.threeten.org/threeten-extra @@ -25,7 +25,6 @@ jodastephen Stephen Colebourne - Project Lead @@ -73,9 +72,9 @@ - scm:git:git@github.com:ThreeTen/threeten-extra.git - scm:git:git@github.com:ThreeTen/threeten-extra.git - https://github.com/ThreeTen/threeten-extra + scm:git:https://github.com/ThreeTen/threeten-extra.git + scm:git:https://github.com/ThreeTen/threeten-extra.git + http://github.com/ThreeTen/threeten-extra ThreeTen.org @@ -90,10 +89,11 @@ ${project.basedir} LICENSE.txt + NOTICE.txt - ${basedir}/src/main/resources + ${project.basedir}/src/main/resources @@ -133,7 +133,7 @@ reporter - org.testng.reporters.FailedReporter,org.testng.reporters.XMLReporter,org.testng.reporters.JUnitReportReporter + org.testng.reporters.JUnitReportReporter @@ -154,7 +154,7 @@ org.apache.felix maven-bundle-plugin - 2.4.0 + 3.3.0 bundle-manifest @@ -243,6 +243,11 @@ maven-assembly-plugin ${maven-assembly-plugin.version} + + org.apache.maven.plugins + maven-checkstyle-plugin + ${maven-checkstyle-plugin.version} + org.apache.maven.plugins maven-changes-plugin @@ -380,11 +385,6 @@ - - org.apache.maven.plugins - maven-checkstyle-plugin - ${maven-checkstyle-plugin.version} - @@ -397,7 +397,7 @@ com.google.guava guava - 19.0 + 20.0 test @@ -446,7 +446,7 @@ maven-surefire-report-plugin ${maven-surefire-report-plugin.version} - true + true @@ -509,14 +509,15 @@ - activate-jdk8 + repo-sign-artifacts - jdk8 + oss.repo + org.apache.maven.plugins maven-toolchains-plugin @@ -537,48 +538,37 @@ - - - - - repo-sign-artifacts - - - oss.repo - true - - - - + org.apache.maven.plugins - maven-toolchains-plugin + maven-gpg-plugin - validate + sign-artifacts + verify - toolchain + sign - - - - 1.8 - oracle - - - + - org.apache.maven.plugins - maven-gpg-plugin + de.jutzig + github-release-plugin + 1.1.1 + + Release v${project.version} + See the [release notes](http://www.threeten.org/threeten-extra/changes-report.html) for more information. + v${project.version} + true + - sign-artifacts - verify + github-releases + deploy - sign + release From 1e46bc95a9b81f7406157352365c709c97dbfea0 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sat, 1 Apr 2017 22:04:25 +0100 Subject: [PATCH 003/279] Use Assert not AssertJUnit --- .../org/threeten/extra/TestPackedFields.java | 90 +++++++++---------- .../org/threeten/extra/TestTemporals.java | 16 ++-- 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/test/java/org/threeten/extra/TestPackedFields.java b/src/test/java/org/threeten/extra/TestPackedFields.java index 76fa6683..f0354799 100644 --- a/src/test/java/org/threeten/extra/TestPackedFields.java +++ b/src/test/java/org/threeten/extra/TestPackedFields.java @@ -35,7 +35,7 @@ import static java.time.temporal.ChronoUnit.FOREVER; import static java.time.temporal.ChronoUnit.MINUTES; import static java.time.temporal.ChronoUnit.SECONDS; -import static org.testng.AssertJUnit.assertEquals; +import static org.testng.Assert.assertEquals; import java.time.DateTimeException; import java.time.LocalDate; @@ -57,15 +57,15 @@ public class TestPackedFields { // packedDate() //----------------------------------------------------------------------- public void test_date_basics() { - assertEquals("PackedDate", PackedFields.PACKED_DATE.toString()); - assertEquals(DAYS, PackedFields.PACKED_DATE.getBaseUnit()); - assertEquals(FOREVER, PackedFields.PACKED_DATE.getRangeUnit()); - assertEquals(true, PackedFields.PACKED_DATE.isDateBased()); - assertEquals(false, PackedFields.PACKED_DATE.isTimeBased()); - assertEquals(true, PackedFields.PACKED_DATE.isSupportedBy(LocalDate.of(2015, 3, 12))); - assertEquals(false, PackedFields.PACKED_DATE.isSupportedBy(LocalTime.of(11, 30))); - assertEquals(10000101, PackedFields.PACKED_DATE.range().getMinimum()); - assertEquals(99991231, PackedFields.PACKED_DATE.range().getMaximum()); + assertEquals(PackedFields.PACKED_DATE.toString(), "PackedDate"); + assertEquals(PackedFields.PACKED_DATE.getBaseUnit(), DAYS); + assertEquals(PackedFields.PACKED_DATE.getRangeUnit(), FOREVER); + assertEquals(PackedFields.PACKED_DATE.isDateBased(), true); + assertEquals(PackedFields.PACKED_DATE.isTimeBased(), false); + assertEquals(PackedFields.PACKED_DATE.isSupportedBy(LocalDate.of(2015, 3, 12)), true); + assertEquals(PackedFields.PACKED_DATE.isSupportedBy(LocalTime.of(11, 30)), false); + assertEquals(PackedFields.PACKED_DATE.range().getMinimum(), 10000101); + assertEquals(PackedFields.PACKED_DATE.range().getMaximum(), 99991231); } @Test(expectedExceptions = DateTimeException.class) @@ -74,9 +74,9 @@ public void test_date_rangeRefinedBy_time() { } public void test_date_getFrom() { - assertEquals(20151203, LocalDate.of(2015, 12, 3).get(PackedFields.PACKED_DATE)); - assertEquals(10000101, LocalDate.of(1000, 1, 1).get(PackedFields.PACKED_DATE)); - assertEquals(99991231, LocalDate.of(9999, 12, 31).get(PackedFields.PACKED_DATE)); + assertEquals(LocalDate.of(2015, 12, 3).get(PackedFields.PACKED_DATE), 20151203); + assertEquals(LocalDate.of(1000, 1, 1).get(PackedFields.PACKED_DATE), 10000101); + assertEquals(LocalDate.of(9999, 12, 31).get(PackedFields.PACKED_DATE), 99991231); } @Test(expectedExceptions = DateTimeException.class) @@ -90,7 +90,7 @@ public void test_date_getFrom_rangeHigh() { } public void test_date_adjustInto() { - assertEquals(LocalDate.of(2015, 12, 3), LocalDate.MIN.with(PackedFields.PACKED_DATE, 20151203)); + assertEquals(LocalDate.MIN.with(PackedFields.PACKED_DATE, 20151203), LocalDate.of(2015, 12, 3)); } @Test(expectedExceptions = DateTimeException.class) @@ -100,7 +100,7 @@ public void test_date_adjustInto_range() { public void test_date_resolve() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_DATE).toFormatter(); - assertEquals(LocalDate.of(2015, 12, 3), LocalDate.parse("20151203", f)); + assertEquals(LocalDate.parse("20151203", f), LocalDate.of(2015, 12, 3)); } @Test(expectedExceptions = DateTimeParseException.class) @@ -111,22 +111,22 @@ public void test_date_resolve_invalid_smart() { public void test_date_resolve_invalid_lenient() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_DATE).toFormatter(); - assertEquals(LocalDate.of(2016, 2, 3), LocalDate.parse("20151403", f.withResolverStyle(ResolverStyle.LENIENT))); + assertEquals(LocalDate.parse("20151403", f.withResolverStyle(ResolverStyle.LENIENT)), LocalDate.of(2016, 2, 3)); } //----------------------------------------------------------------------- // packedHourMin() //----------------------------------------------------------------------- public void test_hourMin_basics() { - assertEquals("PackedHourMin", PackedFields.PACKED_HOUR_MIN.toString()); - assertEquals(MINUTES, PackedFields.PACKED_HOUR_MIN.getBaseUnit()); - assertEquals(DAYS, PackedFields.PACKED_HOUR_MIN.getRangeUnit()); - assertEquals(false, PackedFields.PACKED_HOUR_MIN.isDateBased()); - assertEquals(true, PackedFields.PACKED_HOUR_MIN.isTimeBased()); - assertEquals(true, PackedFields.PACKED_HOUR_MIN.isSupportedBy(LocalTime.of(11, 30))); - assertEquals(false, PackedFields.PACKED_HOUR_MIN.isSupportedBy(LocalDate.of(2015, 3, 12))); - assertEquals(0, PackedFields.PACKED_HOUR_MIN.range().getMinimum()); - assertEquals(2359, PackedFields.PACKED_HOUR_MIN.range().getMaximum()); + assertEquals(PackedFields.PACKED_HOUR_MIN.toString(), "PackedHourMin"); + assertEquals(PackedFields.PACKED_HOUR_MIN.getBaseUnit(), MINUTES); + assertEquals(PackedFields.PACKED_HOUR_MIN.getRangeUnit(), DAYS); + assertEquals(PackedFields.PACKED_HOUR_MIN.isDateBased(), false); + assertEquals(PackedFields.PACKED_HOUR_MIN.isTimeBased(), true); + assertEquals(PackedFields.PACKED_HOUR_MIN.isSupportedBy(LocalTime.of(11, 30)), true); + assertEquals(PackedFields.PACKED_HOUR_MIN.isSupportedBy(LocalDate.of(2015, 3, 12)), false); + assertEquals(PackedFields.PACKED_HOUR_MIN.range().getMinimum(), 0); + assertEquals(PackedFields.PACKED_HOUR_MIN.range().getMaximum(), 2359); } @Test(expectedExceptions = DateTimeException.class) @@ -135,12 +135,12 @@ public void test_hourMin_rangeRefinedBy_time() { } public void test_hourMin_getFrom() { - assertEquals(1130, LocalTime.of(11, 30).get(PackedFields.PACKED_HOUR_MIN)); - assertEquals(121, LocalTime.of(1, 21).get(PackedFields.PACKED_HOUR_MIN)); + assertEquals(LocalTime.of(11, 30).get(PackedFields.PACKED_HOUR_MIN), 1130); + assertEquals(LocalTime.of(1, 21).get(PackedFields.PACKED_HOUR_MIN), 121); } public void test_hourMin_adjustInto() { - assertEquals(LocalTime.of(11, 30), LocalTime.MIDNIGHT.with(PackedFields.PACKED_HOUR_MIN, 1130)); + assertEquals(LocalTime.MIDNIGHT.with(PackedFields.PACKED_HOUR_MIN, 1130), LocalTime.of(11, 30)); } @Test(expectedExceptions = DateTimeException.class) @@ -150,7 +150,7 @@ public void test_hourMin_adjustInto_value() { public void test_hourMin_resolve() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_HOUR_MIN).toFormatter(); - assertEquals(LocalTime.of(11, 30), LocalTime.parse("1130", f)); + assertEquals(LocalTime.parse("1130", f), LocalTime.of(11, 30)); } @Test(expectedExceptions = DateTimeParseException.class) @@ -161,22 +161,22 @@ public void test_hourMin_resolve_invalid_smart() { public void test_hourMin_resolve_invalid_lenient() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_HOUR_MIN).toFormatter(); - assertEquals(LocalTime.of(12, 13), LocalTime.parse("1173", f.withResolverStyle(ResolverStyle.LENIENT))); + assertEquals(LocalTime.parse("1173", f.withResolverStyle(ResolverStyle.LENIENT)), LocalTime.of(12, 13)); } //----------------------------------------------------------------------- // packedTime() //----------------------------------------------------------------------- public void test_time_basics() { - assertEquals("PackedTime", PackedFields.PACKED_TIME.toString()); - assertEquals(SECONDS, PackedFields.PACKED_TIME.getBaseUnit()); - assertEquals(DAYS, PackedFields.PACKED_TIME.getRangeUnit()); - assertEquals(false, PackedFields.PACKED_TIME.isDateBased()); - assertEquals(true, PackedFields.PACKED_TIME.isTimeBased()); - assertEquals(true, PackedFields.PACKED_TIME.isSupportedBy(LocalTime.of(11, 30))); - assertEquals(false, PackedFields.PACKED_TIME.isSupportedBy(LocalDate.of(2015, 3, 12))); - assertEquals(0, PackedFields.PACKED_TIME.range().getMinimum()); - assertEquals(235959, PackedFields.PACKED_TIME.range().getMaximum()); + assertEquals(PackedFields.PACKED_TIME.toString(), "PackedTime"); + assertEquals(PackedFields.PACKED_TIME.getBaseUnit(), SECONDS); + assertEquals(PackedFields.PACKED_TIME.getRangeUnit(), DAYS); + assertEquals(PackedFields.PACKED_TIME.isDateBased(), false); + assertEquals(PackedFields.PACKED_TIME.isTimeBased(), true); + assertEquals(PackedFields.PACKED_TIME.isSupportedBy(LocalTime.of(11, 30)), true); + assertEquals(PackedFields.PACKED_TIME.isSupportedBy(LocalDate.of(2015, 3, 12)), false); + assertEquals(PackedFields.PACKED_TIME.range().getMinimum(), 0); + assertEquals(PackedFields.PACKED_TIME.range().getMaximum(), 235959); } @Test(expectedExceptions = DateTimeException.class) @@ -185,13 +185,13 @@ public void test_time_rangeRefinedBy_time() { } public void test_time_getFrom() { - assertEquals(113052, LocalTime.of(11, 30, 52).get(PackedFields.PACKED_TIME)); - assertEquals(113000, LocalTime.of(11, 30).get(PackedFields.PACKED_TIME)); - assertEquals(12100, LocalTime.of(1, 21).get(PackedFields.PACKED_TIME)); + assertEquals(LocalTime.of(11, 30, 52).get(PackedFields.PACKED_TIME), 113052); + assertEquals(LocalTime.of(11, 30).get(PackedFields.PACKED_TIME), 113000); + assertEquals(LocalTime.of(1, 21).get(PackedFields.PACKED_TIME), 12100); } public void test_time_adjustInto() { - assertEquals(LocalTime.of(11, 30, 52), LocalTime.MIDNIGHT.with(PackedFields.PACKED_TIME, 113052)); + assertEquals(LocalTime.MIDNIGHT.with(PackedFields.PACKED_TIME, 113052), LocalTime.of(11, 30, 52)); } @Test(expectedExceptions = DateTimeException.class) @@ -201,7 +201,7 @@ public void test_time_adjustInto_value() { public void test_time_resolve() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_TIME).toFormatter(); - assertEquals(LocalTime.of(11, 30, 52), LocalTime.parse("113052", f)); + assertEquals(LocalTime.parse("113052", f), LocalTime.of(11, 30, 52)); } @Test(expectedExceptions = DateTimeParseException.class) @@ -212,7 +212,7 @@ public void test_time_resolve_invalid_smart() { public void test_time_resolve_invalid_lenient() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_TIME).toFormatter(); - assertEquals(LocalTime.of(12, 14, 1), LocalTime.parse("117361", f.withResolverStyle(ResolverStyle.LENIENT))); + assertEquals(LocalTime.parse("117361", f.withResolverStyle(ResolverStyle.LENIENT)), LocalTime.of(12, 14, 1)); } } diff --git a/src/test/java/org/threeten/extra/TestTemporals.java b/src/test/java/org/threeten/extra/TestTemporals.java index c3a0ec36..1e533dea 100644 --- a/src/test/java/org/threeten/extra/TestTemporals.java +++ b/src/test/java/org/threeten/extra/TestTemporals.java @@ -52,11 +52,11 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static java.time.temporal.IsoFields.QUARTER_YEARS; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertSame; import static org.testng.Assert.assertThrows; -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertFalse; -import static org.testng.AssertJUnit.assertSame; -import static org.testng.AssertJUnit.assertTrue; +import static org.testng.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -146,11 +146,11 @@ public void test_nextWorkingDay() { public void test_nextWorkingDay_yearChange() { LocalDate friday = LocalDate.of(2010, DECEMBER, 31); Temporal test = Temporals.nextWorkingDay().adjustInto(friday); - assertEquals(LocalDate.of(2011, JANUARY, 3), test); + assertEquals(test, LocalDate.of(2011, JANUARY, 3)); LocalDate saturday = LocalDate.of(2011, DECEMBER, 31); test = Temporals.nextWorkingDay().adjustInto(saturday); - assertEquals(LocalDate.of(2012, JANUARY, 2), test); + assertEquals(test, LocalDate.of(2012, JANUARY, 2)); } //----------------------------------------------------------------------- @@ -214,11 +214,11 @@ public void test_previousWorkingDay() { public void test_previousWorkingDay_yearChange() { LocalDate monday = LocalDate.of(2011, JANUARY, 3); Temporal test = Temporals.previousWorkingDay().adjustInto(monday); - assertEquals(LocalDate.of(2010, DECEMBER, 31), test); + assertEquals(test, LocalDate.of(2010, DECEMBER, 31)); LocalDate sunday = LocalDate.of(2011, JANUARY, 2); test = Temporals.previousWorkingDay().adjustInto(sunday); - assertEquals(LocalDate.of(2010, DECEMBER, 31), test); + assertEquals(test, LocalDate.of(2010, DECEMBER, 31)); } //----------------------------------------------------------------------- From 9a9622c6e69492ca0995d2a2ff8626cb488a5a82 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sat, 1 Apr 2017 23:46:02 +0100 Subject: [PATCH 004/279] Add PeriodDuration combining Period and Duration Fixes #74 --- src/changes/changes.xml | 4 + .../org/threeten/extra/PeriodDuration.java | 667 ++++++++++++++++++ .../threeten/extra/TestPeriodDuration.java | 390 ++++++++++ 3 files changed, 1061 insertions(+) create mode 100644 src/main/java/org/threeten/extra/PeriodDuration.java create mode 100644 src/test/java/org/threeten/extra/TestPeriodDuration.java diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 3d87a130..bb5f6451 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -8,6 +8,10 @@ + + Add PeriodDuration, combining Period and Duration. + See #74. + Add Seconds temporal amount class. See #73. diff --git a/src/main/java/org/threeten/extra/PeriodDuration.java b/src/main/java/org/threeten/extra/PeriodDuration.java new file mode 100644 index 00000000..c1236704 --- /dev/null +++ b/src/main/java/org/threeten/extra/PeriodDuration.java @@ -0,0 +1,667 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.extra; + +import static java.time.temporal.ChronoUnit.DAYS; +import static java.time.temporal.ChronoUnit.MONTHS; +import static java.time.temporal.ChronoUnit.NANOS; +import static java.time.temporal.ChronoUnit.SECONDS; +import static java.time.temporal.ChronoUnit.YEARS; + +import java.io.Serializable; +import java.time.DateTimeException; +import java.time.Duration; +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.Period; +import java.time.chrono.ChronoPeriod; +import java.time.chrono.IsoChronology; +import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoUnit; +import java.time.temporal.IsoFields; +import java.time.temporal.Temporal; +import java.time.temporal.TemporalAmount; +import java.time.temporal.TemporalQueries; +import java.time.temporal.TemporalUnit; +import java.time.temporal.UnsupportedTemporalTypeException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Locale; +import java.util.Objects; + +/** + * An amount of time in the ISO-8601 calendar system that combines a period and a duration. + *

+ * This class models a quantity or amount of time in terms of a {@code Period} and {@code Duration}. + * A period is a date-based amount of time, consisting of years, months and days. + * A duration is a time-based amount of time, consisting of seconds and nanoseconds. + * See the {@link Period} and {@link Duration} classes for more details. + *

+ * The days in a period take account of daylight saving changes (23 or 25 hour days). + * When performing calculations, the period is added first, then the duration. + *

+ * The model is of a directed amount, meaning that the amount may be negative. + * + *

Implementation Requirements:

+ * This class is immutable and thread-safe. + *

+ * This class must be treated as a value type. Do not synchronize, rely on the + * identity hash code or use the distinction between equals() and ==. + */ +public final class PeriodDuration + implements TemporalAmount, Serializable { + + /** + * A constant for a duration of zero. + */ + public static final PeriodDuration ZERO = new PeriodDuration(Period.ZERO, Duration.ZERO); + + /** + * A serialization identifier for this class. + */ + private static final long serialVersionUID = 8815521625671589L; + /** + * The supported units. + */ + private static final List SUPPORTED_UNITS = + Collections.unmodifiableList(Arrays.asList(YEARS, MONTHS, DAYS, SECONDS, NANOS)); + /** + * The number of seconds per day. + */ + private static final long SECONDS_PER_DAY = 86400; + + /** + * The period. + */ + private final Period period; + /** + * The duration. + */ + private final Duration duration; + + //----------------------------------------------------------------------- + /** + * Obtains an instance based on a period and duration. + *

+ * The total amount of time of the resulting instance is the period plus the duration. + * + * @param period the period, not null + * @param duration the duration, not null + * @return the combined period-duration, not null + */ + public static PeriodDuration of(Period period, Duration duration) { + Objects.requireNonNull(period, "The period must not be null"); + Objects.requireNonNull(duration, "The duration must not be null"); + return new PeriodDuration(period, duration); + } + + /** + * Obtains an instance based on a period. + *

+ * The duration will be zero. + * + * @param period the period, not null + * @return the combined period-duration, not null + */ + public static PeriodDuration of(Period period) { + Objects.requireNonNull(period, "The period must not be null"); + return new PeriodDuration(period, Duration.ZERO); + } + + /** + * Obtains an instance based on a duration. + *

+ * The period will be zero. + * + * @param duration the duration, not null + * @return the combined period-duration, not null + */ + public static PeriodDuration of(Duration duration) { + Objects.requireNonNull(duration, "The duration must not be null"); + return new PeriodDuration(Period.ZERO, duration); + } + + //----------------------------------------------------------------------- + /** + * Obtains an instance from a temporal amount. + *

+ * This obtains an instance based on the specified amount. + * A {@code TemporalAmount} represents an amount of time which this factory + * extracts to a {@code PeriodDuration}. + *

+ * The result is calculated by looping around each unit in the specified amount. + * Any amount that is zero is ignore. + * If a unit has an exact duration, it will be totalled using {@link Duration#plus(Duration)}. + * If the unit is days or weeks, it will be totalled into the days part of the period. + * If the unit is months or quarters, it will be totalled into the months part of the period. + * If the unit is years, decades, centuries or millennia, it will be totalled into the years part of the period. + * + * @param amount the temporal amount to convert, not null + * @return the equivalent duration, not null + * @throws DateTimeException if unable to convert to a {@code Duration} + * @throws ArithmeticException if numeric overflow occurs + */ + public static PeriodDuration from(TemporalAmount amount) { + if (amount instanceof PeriodDuration) { + return (PeriodDuration) amount; + } + if (amount instanceof Period) { + return PeriodDuration.of((Period) amount); + } + if (amount instanceof Duration) { + return PeriodDuration.of((Duration) amount); + } + if (amount instanceof ChronoPeriod) { + if (IsoChronology.INSTANCE.equals(((ChronoPeriod) amount).getChronology()) == false) { + throw new DateTimeException("Period requires ISO chronology: " + amount); + } + } + Objects.requireNonNull(amount, "amount"); + int years = 0; + int months = 0; + int days = 0; + Duration duration = Duration.ZERO; + for (TemporalUnit unit : amount.getUnits()) { + long value = amount.get(unit); + if (value != 0) { + // ignore unless non-zero + if (unit.isDurationEstimated()) { + if (unit == ChronoUnit.DAYS) { + days = Math.addExact(days, Math.toIntExact(value)); + } else if (unit == ChronoUnit.WEEKS) { + days = Math.addExact(days, Math.toIntExact(Math.multiplyExact(value, 7))); + } else if (unit == ChronoUnit.MONTHS) { + months = Math.addExact(months, Math.toIntExact(value)); + } else if (unit == IsoFields.QUARTER_YEARS) { + months = Math.addExact(months, Math.toIntExact(Math.multiplyExact(value, 3))); + } else if (unit == ChronoUnit.YEARS) { + years = Math.addExact(years, Math.toIntExact(value)); + } else if (unit == ChronoUnit.DECADES) { + years = Math.addExact(years, Math.toIntExact(Math.multiplyExact(value, 10))); + } else if (unit == ChronoUnit.CENTURIES) { + years = Math.addExact(years, Math.toIntExact(Math.multiplyExact(value, 100))); + } else if (unit == ChronoUnit.MILLENNIA) { + years = Math.addExact(years, Math.toIntExact(Math.multiplyExact(value, 1000))); + } else { + throw new DateTimeException("Unknown unit: " + unit); + } + } else { + // total of exact durations + duration = duration.plus(amount.get(unit), unit); + } + } + } + return PeriodDuration.of(Period.of(years, months, days), duration); + } + + //----------------------------------------------------------------------- + /** + * Obtains an instance from a text string such as {@code PnYnMnDTnHnMnS}. + *

+ * This will parse the string produced by {@code toString()} which is + * based on the ISO-8601 period formats {@code PnYnMnDTnHnMnS} and {@code PnW}. + *

+ * The string starts with an optional sign, denoted by the ASCII negative + * or positive symbol. If negative, the whole amount is negated. + * The ASCII letter "P" is next in upper or lower case. + * There are then a number of sections, each consisting of a number and a suffix. + * At least one of the sections must be present. + * The sections have suffixes in ASCII of "Y" for years, "M" for months, + * "W" for weeks, "D" for days, "H" for hours, "M" for minutes, "S" for seconds, + * accepted in upper or lower case. Note that the ASCII letter "T" separates + * the date and time parts and must be present if any time part is present. + * The suffixes must occur in order. + * The number part of each section must consist of ASCII digits. + * The number may be prefixed by the ASCII negative or positive symbol. + * The number must parse to an {@code int}. + * Any week-based input is multiplied by 7 and treated as a number of days. + *

+ * The leading plus/minus sign, and negative values for weeks and days are + * not part of the ISO-8601 standard. + *

+ * For example, the following are valid inputs: + *

+     *   "P2Y"             -- PeriodDuration.of(Period.ofYears(2))
+     *   "P3M"             -- PeriodDuration.of(Period.ofMonths(3))
+     *   "P4W"             -- PeriodDuration.of(Period.ofWeeks(4))
+     *   "P5D"             -- PeriodDuration.of(Period.ofDays(5))
+     *   "PT6H"            -- PeriodDuration.of(Duration.ofHours(6))
+     *   "P1Y2M3D"         -- PeriodDuration.of(Period.of(1, 2, 3))
+     *   "P1Y2M3W4DT8H"    -- PeriodDuration.of(Period.of(1, 2, 25), Duration.ofHours(8))
+     *   "P-1Y2M"          -- PeriodDuration.of(Period.of(-1, 2, 0))
+     *   "-P1Y2M"          -- PeriodDuration.of(Period.of(-1, -2, 0))
+     * 
+ * + * @param text the text to parse, not null + * @return the parsed period, not null + * @throws DateTimeParseException if the text cannot be parsed to a period + */ + public static PeriodDuration parse(CharSequence text) { + Objects.requireNonNull(text, "text"); + String upper = text.toString().toUpperCase(Locale.ENGLISH); + String negate = ""; + if (upper.startsWith("+")) { + upper = upper.substring(1); + } else if (upper.startsWith("-")) { + upper = upper.substring(1); + negate = "-"; + } + // duration only, parse original text so it does negation + if (upper.startsWith("PT")) { + return PeriodDuration.of(Duration.parse(text)); + } + // period only, parse original text so it does negation + int tpos = upper.indexOf('T'); + if (tpos < 0) { + return PeriodDuration.of(Period.parse(text)); + } + // period and duration + Period period = Period.parse(negate + upper.substring(0, tpos)); + Duration duration = Duration.parse(negate + "P" + upper.substring(tpos)); + return PeriodDuration.of(period, duration); + } + + //----------------------------------------------------------------------- + /** + * Obtains an instance consisting of the amount of time between two temporals. + *

+ * The start is included, but the end is not. + * The result of this method can be negative if the end is before the start. + *

+ * The calculation examines the temporals and extracts {@link LocalDate} and {@link LocalTime}. + * If the time is missing, it will be defaulted to midnight. + * If one date is missing, it will be defaulted to the other date. + * It then finds the amount of time between the two dates and between the two times. + * + * @param startInclusive the start, inclusive, not null + * @param endExclusive the end, exclusive, not null + * @return the number of days between this date and the end date, not null + */ + public static PeriodDuration between(Temporal startInclusive, Temporal endExclusive) { + LocalDate startDate = startInclusive.query(TemporalQueries.localDate()); + LocalDate endDate = endExclusive.query(TemporalQueries.localDate()); + Period period = Period.ZERO; + if (startDate != null && endDate != null) { + period = Period.between(startDate, endDate); + } + LocalTime startTime = startInclusive.query(TemporalQueries.localTime()); + LocalTime endTime = endExclusive.query(TemporalQueries.localTime()); + startTime = startTime != null ? startTime : LocalTime.MIDNIGHT; + endTime = endTime != null ? endTime : LocalTime.MIDNIGHT; + Duration duration = Duration.between(startTime, endTime); + return PeriodDuration.of(period, duration); + } + + //----------------------------------------------------------------------- + /** + * Constructs an instance. + * + * @param period the period + * @param duration the duration + */ + private PeriodDuration(Period period, Duration duration) { + this.period = period; + this.duration = duration; + } + + /** + * Resolves singletons. + * + * @return the singleton instance + */ + private Object readResolve() { + return PeriodDuration.of(period, duration); + } + + //----------------------------------------------------------------------- + /** + * Gets the value of the requested unit. + *

+ * This returns a value for the supported units - {@link ChronoUnit#YEARS}, + * {@link ChronoUnit#MONTHS}, {@link ChronoUnit#DAYS}, {@link ChronoUnit#SECONDS} + * and {@link ChronoUnit#NANOS}. + * All other units throw an exception. + * Note that hours and minutes throw an exception. + * + * @param unit the {@code TemporalUnit} for which to return the value + * @return the long value of the unit + * @throws UnsupportedTemporalTypeException if the unit is not supported + */ + @Override + public long get(TemporalUnit unit) { + if (unit instanceof ChronoUnit) { + switch ((ChronoUnit) unit) { + case YEARS: + return period.getYears(); + case MONTHS: + return period.getMonths(); + case DAYS: + return period.getDays(); + case SECONDS: + return duration.getSeconds(); + case NANOS: + return duration.getNano(); + default: + break; + } + } + throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); + } + + /** + * Gets the set of units supported by this amount. + *

+ * This returns the list {@link ChronoUnit#YEARS}, {@link ChronoUnit#MONTHS}, + * {@link ChronoUnit#DAYS}, {@link ChronoUnit#SECONDS} and {@link ChronoUnit#NANOS}. + *

+ * This set can be used in conjunction with {@link #get(TemporalUnit)} + * to access the entire state of the amount. + * + * @return a list containing the days unit, not null + */ + @Override + public List getUnits() { + return SUPPORTED_UNITS; + } + + //----------------------------------------------------------------------- + /** + * Gets the period part. + * + * @return the period part + */ + public Period getPeriod() { + return period; + } + + /** + * Returns a copy of this period-duration with a different period. + *

+ * This instance is immutable and unaffected by this method call. + * + * @param period the new period + * @return the updated period-duration + */ + public PeriodDuration withPeriod(Period period) { + return PeriodDuration.of(period, duration); + } + + /** + * Gets the duration part. + * + * @return the duration part + */ + public Duration getDuration() { + return duration; + } + + /** + * Returns a copy of this period-duration with a different duration. + *

+ * This instance is immutable and unaffected by this method call. + * + * @param duration the new duration + * @return the updated period-duration + */ + public PeriodDuration withDuration(Duration duration) { + return PeriodDuration.of(period, duration); + } + + //----------------------------------------------------------------------- + /** + * Checks if all parts of this amount are zero. + *

+ * This returns true if both {@link Period#isZero()} and {@link Duration#isZero()} + * return true. + * + * @return true if this period is zero-length + */ + public boolean isZero() { + return period.isZero() && duration.isZero(); + } + + //----------------------------------------------------------------------- + /** + * Returns a copy of this amount with the specified amount added. + *

+ * The parameter is converted using {@link PeriodDuration#from(TemporalAmount)}. + * The period and duration are combined separately. + *

+ * This instance is immutable and unaffected by this method call. + * + * @param amountToAdd the amount to add, not null + * @return a {@code Days} based on this instance with the requested amount added, not null + * @throws DateTimeException if the specified amount contains an invalid unit + * @throws ArithmeticException if numeric overflow occurs + */ + public PeriodDuration plus(TemporalAmount amountToAdd) { + PeriodDuration other = PeriodDuration.from(amountToAdd); + return of(period.plus(other.period), duration.plus(other.duration)); + } + + //----------------------------------------------------------------------- + /** + * Returns a copy of this amount with the specified amount subtracted. + *

+ * The parameter is converted using {@link PeriodDuration#from(TemporalAmount)}. + * The period and duration are combined separately. + *

+ * This instance is immutable and unaffected by this method call. + * + * @param amountToAdd the amount to add, not null + * @return a {@code Days} based on this instance with the requested amount subtracted, not null + * @throws DateTimeException if the specified amount contains an invalid unit + * @throws ArithmeticException if numeric overflow occurs + */ + public PeriodDuration minus(TemporalAmount amountToAdd) { + PeriodDuration other = PeriodDuration.from(amountToAdd); + return of(period.minus(other.period), duration.minus(other.duration)); + } + + //----------------------------------------------------------------------- + /** + * Returns an instance with the amount multiplied by the specified scalar. + *

+ * This instance is immutable and unaffected by this method call. + * + * @param scalar the scalar to multiply by, not null + * @return the amount multiplied by the specified scalar, not null + * @throws ArithmeticException if numeric overflow occurs + */ + public PeriodDuration multipliedBy(int scalar) { + if (scalar == 1) { + return this; + } + return of(period.multipliedBy(scalar), duration.multipliedBy(scalar)); + } + + /** + * Returns an instance with the amount negated. + *

+ * This instance is immutable and unaffected by this method call. + * + * @return the negated amount, not null + * @throws ArithmeticException if numeric overflow occurs, which only happens if + * the amount is {@code Long.MIN_VALUE} + */ + public PeriodDuration negated() { + return multipliedBy(-1); + } + + //----------------------------------------------------------------------- + /** + * Returns a copy of this instance with the years and months exactly normalized. + *

+ * This normalizes the years and months units, leaving the days unit unchanged. + * The result is exact, always representing the same amount of time. + *

+ * The months unit is adjusted to have an absolute value less than 11, + * with the years unit being adjusted to compensate. For example, a period of + * "1 year and 15 months" will be normalized to "2 years and 3 months". + *

+ * The sign of the years and months units will be the same after normalization. + * For example, a period of "1 year and -25 months" will be normalized to + * "-1 year and -1 month". + *

+ * Note that no normalization is performed on the days or duration. + *

+ * This instance is immutable and unaffected by this method call. + * + * @return a {@code PeriodDuration} based on this one with excess months normalized to years, not null + * @throws ArithmeticException if numeric overflow occurs + */ + public PeriodDuration normalized() { + return withPeriod(period.normalized()); + } + + /** + * Returns a copy of this instance with the days and duration inexactly normalized. + *

+ * This normalizes the days and duration, leaving the years and months unchanged. + * The result is inexact, as it assumes a 24 hour day. + *

+ * This combines the duration seconds with the number of days and shares the total + * seconds between the two fields. For example, a period of + * "2 days and 86401 seconds" will be normalized to "3 days and 1 second". + *

+ * The sign of the days and duration will be the same after normalization. + * For example, a period of "1 day and -172801 seconds" will be normalized to + * "-1 day and -1 second". + *

+ * Note that no normalization is performed on the years or months. + *

+ * This instance is immutable and unaffected by this method call. + * + * @return a {@code PeriodDuration} based on this one with excess duration normalized to days, not null + * @throws ArithmeticException if numeric overflow occurs + */ + public PeriodDuration normalizedInexactDuration() { + long totalSecs = period.getDays() * SECONDS_PER_DAY + duration.getSeconds(); + int splitDays = Math.toIntExact(totalSecs / SECONDS_PER_DAY); + long splitSecs = totalSecs % SECONDS_PER_DAY; + if (splitDays == period.getDays() && splitSecs == duration.getSeconds()) { + return this; + } + return PeriodDuration.of(period.withDays(splitDays), duration.withSeconds(splitSecs)); + } + + //----------------------------------------------------------------------- + /** + * Adds this amount to the specified temporal object. + *

+ * This returns a temporal object of the same observable type as the input + * with this amount added. This simply adds the period and duration to the temporal. + *

+ * This instance is immutable and unaffected by this method call. + * + * @param temporal the temporal object to adjust, not null + * @return an object of the same type with the adjustment made, not null + * @throws DateTimeException if unable to add + * @throws UnsupportedTemporalTypeException if the DAYS unit is not supported + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public Temporal addTo(Temporal temporal) { + return temporal.plus(period).plus(duration); + } + + /** + * Subtracts this amount from the specified temporal object. + *

+ * This returns a temporal object of the same observable type as the input + * with this amount subtracted. This simply subtracts the period and duration from the temporal. + *

+ * This instance is immutable and unaffected by this method call. + * + * @param temporal the temporal object to adjust, not null + * @return an object of the same type with the adjustment made, not null + * @throws DateTimeException if unable to subtract + * @throws UnsupportedTemporalTypeException if the DAYS unit is not supported + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public Temporal subtractFrom(Temporal temporal) { + return temporal.minus(period).minus(duration); + } + + //----------------------------------------------------------------------- + /** + * Checks if this amount is equal to the specified {@code PeriodDuration}. + *

+ * The comparison is based on the underlying period and duration. + * + * @param otherAmount the other amount, null returns false + * @return true if the other amount is equal to this one + */ + @Override + public boolean equals(Object otherAmount) { + if (this == otherAmount) { + return true; + } + if (otherAmount instanceof PeriodDuration) { + PeriodDuration other = (PeriodDuration) otherAmount; + return this.period.equals(other.period) && this.duration.equals(other.duration); + } + return false; + } + + /** + * A hash code for this amount. + * + * @return a suitable hash code + */ + @Override + public int hashCode() { + return period.hashCode() ^ duration.hashCode(); + } + + //----------------------------------------------------------------------- + /** + * Returns a string representation of the amount. + * This will be in the format 'PnYnMnDTnHnMnS', with sections omitted as necessary. + * An empty amount will return "PT0S". + * + * @return the period in ISO-8601 string format + */ + @Override + public String toString() { + if (period.isZero()) { + return duration.toString(); + } + if (duration.isZero()) { + return period.toString(); + } + return period.toString() + duration.toString().substring(1); + } + +} diff --git a/src/test/java/org/threeten/extra/TestPeriodDuration.java b/src/test/java/org/threeten/extra/TestPeriodDuration.java new file mode 100644 index 00000000..08fc4e9d --- /dev/null +++ b/src/test/java/org/threeten/extra/TestPeriodDuration.java @@ -0,0 +1,390 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.extra; + +import static java.time.temporal.ChronoUnit.DAYS; +import static java.time.temporal.ChronoUnit.ERAS; +import static java.time.temporal.ChronoUnit.MONTHS; +import static java.time.temporal.ChronoUnit.NANOS; +import static java.time.temporal.ChronoUnit.SECONDS; +import static java.time.temporal.ChronoUnit.YEARS; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertThrows; +import static org.testng.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.time.Duration; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.Period; +import java.time.format.DateTimeParseException; +import java.util.Arrays; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * Test class. + */ +@Test +public class TestPeriodDuration { + + private static final Period P1Y2M3D = Period.of(1, 2, 3); + private static final Duration DUR_5 = Duration.ofSeconds(5); + private static final Duration DUR_6 = Duration.ofSeconds(6); + + //----------------------------------------------------------------------- + public void test_isSerializable() { + assertTrue(Serializable.class.isAssignableFrom(PeriodDuration.class)); + } + + //----------------------------------------------------------------------- + public void test_deserializationSingleton() throws Exception { + PeriodDuration orginal = PeriodDuration.ZERO; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(baos); + out.writeObject(orginal); + out.close(); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStream in = new ObjectInputStream(bais); + PeriodDuration ser = (PeriodDuration) in.readObject(); + assertEquals(PeriodDuration.ZERO, ser); + } + + //----------------------------------------------------------------------- + public void test_ZERO() { + assertEquals(PeriodDuration.of(Period.ZERO, Duration.ZERO), PeriodDuration.ZERO); + assertEquals(PeriodDuration.of(Period.ZERO), PeriodDuration.ZERO); + assertEquals(PeriodDuration.of(Duration.ZERO), PeriodDuration.ZERO); + assertEquals(PeriodDuration.ZERO.getPeriod(), Period.ZERO); + assertEquals(PeriodDuration.ZERO.getDuration(), Duration.ZERO); + assertEquals(PeriodDuration.ZERO.isZero(), true); + assertEquals(PeriodDuration.ZERO.getUnits(), Arrays.asList(YEARS, MONTHS, DAYS, SECONDS, NANOS)); + assertEquals(PeriodDuration.ZERO.get(YEARS), 0); + assertEquals(PeriodDuration.ZERO.get(MONTHS), 0); + assertEquals(PeriodDuration.ZERO.get(DAYS), 0); + assertEquals(PeriodDuration.ZERO.get(SECONDS), 0); + assertEquals(PeriodDuration.ZERO.get(NANOS), 0); + assertThrows(() -> PeriodDuration.ZERO.get(ERAS)); + } + + //----------------------------------------------------------------------- + public void test_of_both() { + PeriodDuration test = PeriodDuration.of(P1Y2M3D, Duration.ofSeconds(4)); + assertEquals(test.getPeriod(), P1Y2M3D); + assertEquals(test.getDuration(), Duration.ofSeconds(4)); + assertEquals(test.isZero(), false); + assertEquals(test.get(YEARS), 1); + assertEquals(test.get(MONTHS), 2); + assertEquals(test.get(DAYS), 3); + assertEquals(test.get(SECONDS), 4); + assertEquals(test.get(NANOS), 0); + } + + public void test_of_period() { + PeriodDuration test = PeriodDuration.of(P1Y2M3D); + assertEquals(test.getPeriod(), P1Y2M3D); + assertEquals(test.getDuration(), Duration.ZERO); + assertEquals(test.isZero(), false); + assertEquals(test.get(YEARS), 1); + assertEquals(test.get(MONTHS), 2); + assertEquals(test.get(DAYS), 3); + assertEquals(test.get(SECONDS), 0); + assertEquals(test.get(NANOS), 0); + } + + public void test_of_duration() { + PeriodDuration test = PeriodDuration.of(Duration.ofSeconds(4)); + assertEquals(test.getPeriod(), Period.ZERO); + assertEquals(test.getDuration(), Duration.ofSeconds(4)); + assertEquals(test.isZero(), false); + assertEquals(test.get(YEARS), 0); + assertEquals(test.get(MONTHS), 0); + assertEquals(test.get(DAYS), 0); + assertEquals(test.get(SECONDS), 4); + assertEquals(test.get(NANOS), 0); + } + + //----------------------------------------------------------------------- + public void test_between_dates() { + PeriodDuration test = PeriodDuration.between(LocalDate.of(2012, 6, 20), LocalDate.of(2012, 8, 25)); + assertEquals(test.getPeriod(), Period.between(LocalDate.of(2012, 6, 20), LocalDate.of(2012, 8, 25))); + assertEquals(test.getDuration(), Duration.ZERO); + } + + public void test_between_times() { + PeriodDuration test = PeriodDuration.between(LocalTime.of(11, 20), LocalTime.of(12, 25)); + assertEquals(test.getPeriod(), Period.ZERO); + assertEquals(test.getDuration(), Duration.between(LocalTime.of(11, 20), LocalTime.of(12, 25))); + } + + public void test_between_mixed1() { + PeriodDuration test = PeriodDuration.between(LocalDate.of(2012, 6, 20), LocalTime.of(11, 25)); + assertEquals(test.getPeriod(), Period.ZERO); + assertEquals(test.getDuration(), Duration.ofHours(11).plusMinutes(25)); + } + + public void test_between_mixed2() { + PeriodDuration test = PeriodDuration.between(LocalDate.of(2012, 6, 20), LocalDateTime.of(2012, 7, 22, 11, 25)); + assertEquals(test.getPeriod(), Period.of(0, 1, 2)); + assertEquals(test.getDuration(), Duration.ofHours(11).plusMinutes(25)); + } + + //----------------------------------------------------------------------- + public void test_from() { + assertEquals(PeriodDuration.from(PeriodDuration.of(P1Y2M3D)), PeriodDuration.from(PeriodDuration.of(P1Y2M3D))); + assertEquals(PeriodDuration.from(Period.ofYears(2)), PeriodDuration.of(Period.ofYears(2))); + assertEquals(PeriodDuration.from(Duration.ofSeconds(2)), PeriodDuration.of(Duration.ofSeconds(2))); + assertEquals(PeriodDuration.from(Years.of(2)), PeriodDuration.of(Period.ofYears(2))); + assertEquals(PeriodDuration.from(Months.of(2)), PeriodDuration.of(Period.ofMonths(2))); + assertEquals(PeriodDuration.from(Weeks.of(2)), PeriodDuration.of(Period.ofWeeks(2))); + assertEquals(PeriodDuration.from(Days.of(2)), PeriodDuration.of(Period.ofDays(2))); + assertEquals(PeriodDuration.from(Hours.of(2)), PeriodDuration.of(Duration.ofHours(2))); + } + + //----------------------------------------------------------------------- + @DataProvider(name = "parseValid") + Object[][] data_valid() { + return new Object[][] { + {"P1Y2M3W4DT5H6M7S", Period.of(1, 2, 3 * 7 + 4), Duration.ofHours(5).plusMinutes(6).plusSeconds(7)}, + {"P3Y", Period.ofYears(3), Duration.ZERO}, + {"P3M", Period.ofMonths(3), Duration.ZERO}, + {"P3W", Period.ofWeeks(3), Duration.ZERO}, + {"P3D", Period.ofDays(3), Duration.ZERO}, + + {"PT0S", Period.of(0, 0, 0), Duration.ofSeconds(0)}, + {"PT1S", Period.of(0, 0, 0), Duration.ofSeconds(1)}, + {"PT2S", Period.of(0, 0, 0), Duration.ofSeconds(2)}, + {"PT123456789S", Period.of(0, 0, 0), Duration.ofSeconds(123456789)}, + {"PT+0S", Period.of(0, 0, 0), Duration.ofSeconds(0)}, + {"PT+2S", Period.of(0, 0, 0), Duration.ofSeconds(2)}, + {"PT-0S", Period.of(0, 0, 0), Duration.ofSeconds(0)}, + {"PT-2S", Period.of(0, 0, 0), Duration.ofSeconds(-2)}, + + {"P+0M", Period.of(0, 0, 0), Duration.ZERO}, + {"P+2M", Period.of(0, 2, 0), Duration.ZERO}, + {"P-0M", Period.of(0, 0, 0), Duration.ZERO}, + {"P-2M", Period.of(0, -2, 0), Duration.ZERO}, + }; + } + + @Test(dataProvider = "parseValid") + public void test_parse_CharSequence_valid(String str, Period period, Duration duration) { + assertEquals(PeriodDuration.parse(str), PeriodDuration.of(period, duration)); + } + + @Test(dataProvider = "parseValid") + public void test_parse_CharSequence_valid_initialPlus(String str, Period period, Duration duration) { + assertEquals(PeriodDuration.parse("+" + str), PeriodDuration.of(period, duration)); + } + + @Test(dataProvider = "parseValid") + public void test_parse_CharSequence_valid_initialMinus(String str, Period period, Duration duration) { + assertEquals(PeriodDuration.parse("-" + str), PeriodDuration.of(period, duration).negated()); + } + + @DataProvider(name = "parseInvalid") + Object[][] data_invalid() { + return new Object[][] { + {"P3Q"}, + {"P1M2Y"}, + + {"3"}, + {"-3"}, + {"3H"}, + {"-3H"}, + {"P3"}, + {"P-3"}, + {"PH"}, + {"T"}, + {"T3H"}, + }; + } + + @Test(expectedExceptions = DateTimeParseException.class, dataProvider = "parseInvalid") + public void test_parse_CharSequence_invalid(String str) { + PeriodDuration.parse(str); + } + + @Test(expectedExceptions = NullPointerException.class) + public void test_parse_CharSequence_null() { + PeriodDuration.parse((CharSequence) null); + } + + //----------------------------------------------------------------------- + public void test_plus_TemporalAmount_PeriodDuration() { + PeriodDuration test = PeriodDuration.of(P1Y2M3D, DUR_5); + assertEquals(test.plus(Period.of(3, 2, 1)), PeriodDuration.of(Period.of(4, 4, 4), DUR_5)); + assertEquals(test.plus(Duration.ofSeconds(4)), PeriodDuration.of(P1Y2M3D, Duration.ofSeconds(9))); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_plus_TemporalAmount_overflowTooBig() { + PeriodDuration.of(Period.of(Integer.MAX_VALUE - 1, 0, 0)).plus(PeriodDuration.of(Period.ofYears(2))); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_plus_TemporalAmount_overflowTooSmall() { + PeriodDuration.of(Period.of(Integer.MIN_VALUE + 1, 0, 0)).plus(PeriodDuration.of(Period.ofYears(-2))); + } + + @Test(expectedExceptions = NullPointerException.class) + public void test_plus_TemporalAmount_null() { + P1Y2M3D.plus(null); + } + + //----------------------------------------------------------------------- + public void test_minus_TemporalAmount_PeriodDuration() { + PeriodDuration test = PeriodDuration.of(P1Y2M3D, DUR_5); + assertEquals(test.minus(Period.of(1, 1, 1)), PeriodDuration.of(Period.of(0, 1, 2), DUR_5)); + assertEquals(test.minus(Duration.ofSeconds(4)), PeriodDuration.of(P1Y2M3D, Duration.ofSeconds(1))); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_minus_TemporalAmount_overflowTooBig() { + PeriodDuration.of(Period.of(Integer.MAX_VALUE - 1, 0, 0)).minus(PeriodDuration.of(Period.ofYears(-2))); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_minus_TemporalAmount_overflowTooSmall() { + PeriodDuration.of(Period.of(Integer.MIN_VALUE + 1, 0, 0)).minus(PeriodDuration.of(Period.ofYears(2))); + } + + @Test(expectedExceptions = NullPointerException.class) + public void test_minus_TemporalAmount_null() { + P1Y2M3D.minus(null); + } + + //----------------------------------------------------------------------- + public void test_multipliedBy() { + PeriodDuration test = PeriodDuration.of(P1Y2M3D, DUR_5); + assertEquals(test.multipliedBy(0), PeriodDuration.ZERO); + assertEquals(test.multipliedBy(1), test); + assertEquals(test.multipliedBy(5), PeriodDuration.of(Period.of(5, 10, 15), Duration.ofSeconds(25))); + assertEquals(test.multipliedBy(-3), PeriodDuration.of(Period.of(-3, -6, -9), Duration.ofSeconds(-15))); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_multipliedBy_overflowTooBig() { + PeriodDuration.of(Period.ofYears(Integer.MAX_VALUE / 2 + 1)).multipliedBy(2); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_multipliedBy_overflowTooSmall() { + PeriodDuration.of(Period.ofYears(Integer.MIN_VALUE / 2 - 1)).multipliedBy(2); + } + + //----------------------------------------------------------------------- + public void test_negated() { + assertEquals(PeriodDuration.of(P1Y2M3D, DUR_5).negated(), PeriodDuration.of(P1Y2M3D.negated(), DUR_5.negated())); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_negated_overflow() { + PeriodDuration.of(Duration.ofSeconds(Long.MIN_VALUE)).negated(); + } + + //----------------------------------------------------------------------- + public void test_normalized() { + assertEquals(PeriodDuration.of(P1Y2M3D, DUR_5).normalized(), PeriodDuration.of(P1Y2M3D.normalized(), DUR_5)); + } + + //----------------------------------------------------------------------- + public void test_normalizedInexactDuration() { + assertEquals( + PeriodDuration.of(P1Y2M3D, Duration.ofHours(5)).normalizedInexactDuration(), + PeriodDuration.of(P1Y2M3D, Duration.ofHours(5))); + assertEquals( + PeriodDuration.of(P1Y2M3D, Duration.ofHours(25)).normalizedInexactDuration(), + PeriodDuration.of(P1Y2M3D.plusDays(1), Duration.ofHours(1))); + assertEquals( + PeriodDuration.of(P1Y2M3D, Duration.ofHours(-73)).normalizedInexactDuration(), + PeriodDuration.of(P1Y2M3D.plusDays(-3), Duration.ofHours(-1))); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_normalizedInexactDuration_overflow() { + PeriodDuration.of(Duration.ofSeconds(Long.MIN_VALUE)).normalizedInexactDuration(); + } + + //----------------------------------------------------------------------- + public void test_addTo() { + LocalDateTime base = LocalDateTime.of(2012, 6, 20, 11, 30, 0); + assertEquals(PeriodDuration.of(P1Y2M3D, DUR_5).addTo(base), LocalDateTime.of(2013, 8, 23, 11, 30, 5)); + } + + //----------------------------------------------------------------------- + public void test_subtractFrom() { + LocalDateTime base = LocalDateTime.of(2012, 6, 20, 11, 30, 0); + assertEquals(PeriodDuration.of(P1Y2M3D, DUR_5).subtractFrom(base), LocalDateTime.of(2011, 4, 17, 11, 29, 55)); + } + + //----------------------------------------------------------------------- + public void test_equals() { + PeriodDuration test5 = PeriodDuration.of(P1Y2M3D, DUR_5); + PeriodDuration test6 = PeriodDuration.of(P1Y2M3D, DUR_6); + assertEquals(test5.equals(test5), true); + assertEquals(test5.equals(test6), false); + assertEquals(test6.equals(test5), false); + } + + public void test_equals_null() { + PeriodDuration test = PeriodDuration.of(P1Y2M3D, DUR_5); + assertEquals(test.equals(null), false); + } + + public void test_equals_otherClass() { + PeriodDuration test = PeriodDuration.of(P1Y2M3D, DUR_5); + assertEquals(test.equals(""), false); + } + + //----------------------------------------------------------------------- + public void test_hashCode() { + PeriodDuration test5 = PeriodDuration.of(P1Y2M3D, DUR_5); + PeriodDuration test6 = PeriodDuration.of(P1Y2M3D, DUR_6); + assertEquals(test5.hashCode() == test5.hashCode(), true); + assertEquals(test5.hashCode() == test6.hashCode(), false); + } + + //----------------------------------------------------------------------- + public void test_toString() { + assertEquals("P1Y2M3DT5S", PeriodDuration.of(P1Y2M3D, DUR_5).toString()); + assertEquals("P1Y2M3D", PeriodDuration.of(P1Y2M3D, Duration.ZERO).toString()); + assertEquals("PT5S", PeriodDuration.of(Period.ZERO, DUR_5).toString()); + } + +} From 3f2bebf28d754256b1a1e948412b6677724868a2 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 2 Apr 2017 01:05:16 +0100 Subject: [PATCH 005/279] Extend formats Parsed by Interval Allow years, months, weeks and days via `PeriodDuration` See #70 --- src/changes/changes.xml | 4 ++++ .../java/org/threeten/extra/Interval.java | 21 +++++++++---------- .../java/org/threeten/extra/TestInterval.java | 7 +++++++ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index bb5f6451..f57c5b6d 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -12,6 +12,10 @@ Add PeriodDuration, combining Period and Duration. See #74. + + Extend formats Parsed by Interval, allowing years, months, weeks and days. + See #70. + Add Seconds temporal amount class. See #73. diff --git a/src/main/java/org/threeten/extra/Interval.java b/src/main/java/org/threeten/extra/Interval.java index f4b900fb..d4849c7e 100644 --- a/src/main/java/org/threeten/extra/Interval.java +++ b/src/main/java/org/threeten/extra/Interval.java @@ -132,12 +132,11 @@ public static Interval of(Instant startInclusive, Duration duration) { *

  • a representations of an {@link OffsetDateTime}, followed by a forward slash, * followed by a representation of a {@link OffsetDateTime} *
  • a representation of an {@link OffsetDateTime}, followed by a forward slash, - * followed by a representation of a {@link Duration} - *
  • a representation of a {@link Duration}, followed by a forward slash, + * followed by a representation of a {@link PeriodDuration} + *
  • a representation of a {@link PeriodDuration}, followed by a forward slash, * followed by a representation of an {@link OffsetDateTime} * * - * * @param text the text to parse, not null * @return the parsed interval, not null * @throws DateTimeParseException if the text cannot be parsed @@ -149,21 +148,21 @@ public static Interval parse(CharSequence text) { char firstChar = text.charAt(0); if (firstChar == 'P' || firstChar == 'p') { // duration followed by instant - Duration duration = Duration.parse(text.subSequence(0, i)); - Instant end = OffsetDateTime.parse(text.subSequence(i + 1, text.length())).toInstant(); - return Interval.of(end.minus(duration), end); + PeriodDuration amount = PeriodDuration.parse(text.subSequence(0, i)); + OffsetDateTime end = OffsetDateTime.parse(text.subSequence(i + 1, text.length())); + return Interval.of(end.minus(amount).toInstant(), end.toInstant()); } else { // instant followed by instant or duration - Instant start = OffsetDateTime.parse(text.subSequence(0, i)).toInstant(); + OffsetDateTime start = OffsetDateTime.parse(text.subSequence(0, i)); if (i + 1 < text.length()) { char c = text.charAt(i + 1); if (c == 'P' || c == 'p') { - Duration duration = Duration.parse(text.subSequence(i + 1, text.length())); - return Interval.of(start, start.plus(duration)); + PeriodDuration amount = PeriodDuration.parse(text.subSequence(i + 1, text.length())); + return Interval.of(start.toInstant(), start.plus(amount).toInstant()); } } - Instant end = OffsetDateTime.parse(text.subSequence(i + 1, text.length())).toInstant(); - return Interval.of(start, end); + OffsetDateTime end = OffsetDateTime.parse(text.subSequence(i + 1, text.length())); + return Interval.of(start.toInstant(), end.toInstant()); } } } diff --git a/src/test/java/org/threeten/extra/TestInterval.java b/src/test/java/org/threeten/extra/TestInterval.java index 7a735b70..12415371 100644 --- a/src/test/java/org/threeten/extra/TestInterval.java +++ b/src/test/java/org/threeten/extra/TestInterval.java @@ -32,6 +32,7 @@ package org.threeten.extra; import static java.time.temporal.ChronoUnit.HOURS; +import static java.time.temporal.ChronoUnit.MONTHS; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; @@ -165,6 +166,12 @@ public void test_parse_CharSequence_DurationInstant() { assertEquals(test.getEnd(), NOW2); } + public void test_parse_CharSequence_PeriodDurationInstant() { + Interval test = Interval.parse("P6MT5H/" + NOW2); + assertEquals(test.getStart(), NOW2.atZone(ZoneOffset.UTC).minus(6, MONTHS).minus(5, HOURS).toInstant()); + assertEquals(test.getEnd(), NOW2); + } + public void test_parse_CharSequence_DurationInstant_caseInsensitive() { Interval test = Interval.parse("pt6h/" + NOW2); assertEquals(test.getStart(), NOW2.minus(6, HOURS)); From 050ef5fb45ea2b84c979f54cb5c108ee6a37716a Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 11 Apr 2017 16:57:03 +0100 Subject: [PATCH 006/279] Rename normalized methods --- .../java/org/threeten/extra/PeriodDuration.java | 8 ++++---- .../org/threeten/extra/TestPeriodDuration.java | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/threeten/extra/PeriodDuration.java b/src/main/java/org/threeten/extra/PeriodDuration.java index c1236704..28aa6b01 100644 --- a/src/main/java/org/threeten/extra/PeriodDuration.java +++ b/src/main/java/org/threeten/extra/PeriodDuration.java @@ -540,15 +540,15 @@ public PeriodDuration negated() { * @return a {@code PeriodDuration} based on this one with excess months normalized to years, not null * @throws ArithmeticException if numeric overflow occurs */ - public PeriodDuration normalized() { + public PeriodDuration normalizedYears() { return withPeriod(period.normalized()); } /** - * Returns a copy of this instance with the days and duration inexactly normalized. + * Returns a copy of this instance with the days and duration normalized using the standard day of 24 hours. *

    * This normalizes the days and duration, leaving the years and months unchanged. - * The result is inexact, as it assumes a 24 hour day. + * The result uses a standard day length of 24 hours. *

    * This combines the duration seconds with the number of days and shares the total * seconds between the two fields. For example, a period of @@ -565,7 +565,7 @@ public PeriodDuration normalized() { * @return a {@code PeriodDuration} based on this one with excess duration normalized to days, not null * @throws ArithmeticException if numeric overflow occurs */ - public PeriodDuration normalizedInexactDuration() { + public PeriodDuration normalizedStandardDays() { long totalSecs = period.getDays() * SECONDS_PER_DAY + duration.getSeconds(); int splitDays = Math.toIntExact(totalSecs / SECONDS_PER_DAY); long splitSecs = totalSecs % SECONDS_PER_DAY; diff --git a/src/test/java/org/threeten/extra/TestPeriodDuration.java b/src/test/java/org/threeten/extra/TestPeriodDuration.java index 08fc4e9d..c580c99d 100644 --- a/src/test/java/org/threeten/extra/TestPeriodDuration.java +++ b/src/test/java/org/threeten/extra/TestPeriodDuration.java @@ -319,26 +319,26 @@ public void test_negated_overflow() { } //----------------------------------------------------------------------- - public void test_normalized() { - assertEquals(PeriodDuration.of(P1Y2M3D, DUR_5).normalized(), PeriodDuration.of(P1Y2M3D.normalized(), DUR_5)); + public void test_normalizedYears() { + assertEquals(PeriodDuration.of(P1Y2M3D, DUR_5).normalizedYears(), PeriodDuration.of(P1Y2M3D.normalized(), DUR_5)); } //----------------------------------------------------------------------- - public void test_normalizedInexactDuration() { + public void test_normalizedStandardDays() { assertEquals( - PeriodDuration.of(P1Y2M3D, Duration.ofHours(5)).normalizedInexactDuration(), + PeriodDuration.of(P1Y2M3D, Duration.ofHours(5)).normalizedStandardDays(), PeriodDuration.of(P1Y2M3D, Duration.ofHours(5))); assertEquals( - PeriodDuration.of(P1Y2M3D, Duration.ofHours(25)).normalizedInexactDuration(), + PeriodDuration.of(P1Y2M3D, Duration.ofHours(25)).normalizedStandardDays(), PeriodDuration.of(P1Y2M3D.plusDays(1), Duration.ofHours(1))); assertEquals( - PeriodDuration.of(P1Y2M3D, Duration.ofHours(-73)).normalizedInexactDuration(), + PeriodDuration.of(P1Y2M3D, Duration.ofHours(-73)).normalizedStandardDays(), PeriodDuration.of(P1Y2M3D.plusDays(-3), Duration.ofHours(-1))); } @Test(expectedExceptions = ArithmeticException.class) - public void test_normalizedInexactDuration_overflow() { - PeriodDuration.of(Duration.ofSeconds(Long.MIN_VALUE)).normalizedInexactDuration(); + public void test_normalizedStandardDaysn_overflow() { + PeriodDuration.of(Duration.ofSeconds(Long.MIN_VALUE)).normalizedStandardDays(); } //----------------------------------------------------------------------- From 949b263afe612ff4e8087a8e8888971ef4da59fe Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 11 Apr 2017 17:00:09 +0100 Subject: [PATCH 007/279] Extend parsing of Intervals Allow end instant to have no offset, implying it from the start See #75 --- src/changes/changes.xml | 6 +- .../java/org/threeten/extra/Interval.java | 20 +++++- .../org/threeten/extra/PeriodDuration.java | 2 + .../java/org/threeten/extra/TestInterval.java | 63 ++++++------------- 4 files changed, 44 insertions(+), 47 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index f57c5b6d..e24c6580 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -13,7 +13,11 @@ See #74. - Extend formats Parsed by Interval, allowing years, months, weeks and days. + Extend formats parsed by Interval, allowing end instant to have offset inferred from start instant. + See #75. + + + Extend formats parsed by Interval, allowing years, months, weeks and days. See #70. diff --git a/src/main/java/org/threeten/extra/Interval.java b/src/main/java/org/threeten/extra/Interval.java index d4849c7e..ec813637 100644 --- a/src/main/java/org/threeten/extra/Interval.java +++ b/src/main/java/org/threeten/extra/Interval.java @@ -35,8 +35,11 @@ import java.time.DateTimeException; import java.time.Duration; import java.time.Instant; +import java.time.LocalDateTime; import java.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; +import java.time.temporal.TemporalAccessor; import java.util.Objects; /** @@ -131,11 +134,16 @@ public static Interval of(Instant startInclusive, Duration duration) { *

      *
    • a representations of an {@link OffsetDateTime}, followed by a forward slash, * followed by a representation of a {@link OffsetDateTime} + *
    • a representations of an {@link OffsetDateTime}, followed by a forward slash, + * followed by a representation of a {@link LocalDateTime}, where the end offset is implied. *
    • a representation of an {@link OffsetDateTime}, followed by a forward slash, * followed by a representation of a {@link PeriodDuration} *
    • a representation of a {@link PeriodDuration}, followed by a forward slash, * followed by a representation of an {@link OffsetDateTime} *
    + *

    + * ISO-8601 supports a very wide range of possible inputs, many of which are not supported here. + * For example, basic format, week-based dates, ordinal dates and date-style period formats are not supported. * * @param text the text to parse, not null * @return the parsed interval, not null @@ -161,8 +169,16 @@ public static Interval parse(CharSequence text) { return Interval.of(start.toInstant(), start.plus(amount).toInstant()); } } - OffsetDateTime end = OffsetDateTime.parse(text.subSequence(i + 1, text.length())); - return Interval.of(start.toInstant(), end.toInstant()); + // infer offset from start if not specified by end + String remStr = text.subSequence(i + 1, text.length()).toString(); + TemporalAccessor temporal = DateTimeFormatter.ISO_DATE_TIME.parseBest(remStr, OffsetDateTime::from, LocalDateTime::from); + if (temporal instanceof OffsetDateTime) { + OffsetDateTime odt = (OffsetDateTime) temporal; + return Interval.of(start.toInstant(), odt.toInstant()); + } else { + LocalDateTime ldt = (LocalDateTime) temporal; + return Interval.of(start.toInstant(), ldt.toInstant(start.getOffset())); + } } } } diff --git a/src/main/java/org/threeten/extra/PeriodDuration.java b/src/main/java/org/threeten/extra/PeriodDuration.java index 28aa6b01..6be9247a 100644 --- a/src/main/java/org/threeten/extra/PeriodDuration.java +++ b/src/main/java/org/threeten/extra/PeriodDuration.java @@ -249,6 +249,8 @@ public static PeriodDuration from(TemporalAmount amount) { * The leading plus/minus sign, and negative values for weeks and days are * not part of the ISO-8601 standard. *

    + * Note that the date style format {@code PYYYY-MM-DDTHH:MM:SS} is not supported. + *

    * For example, the following are valid inputs: *

          *   "P2Y"             -- PeriodDuration.of(Period.ofYears(2))
    diff --git a/src/test/java/org/threeten/extra/TestInterval.java b/src/test/java/org/threeten/extra/TestInterval.java
    index 12415371..f457b8a0 100644
    --- a/src/test/java/org/threeten/extra/TestInterval.java
    +++ b/src/test/java/org/threeten/extra/TestInterval.java
    @@ -154,52 +154,27 @@ public void test_of_Instant_Duration_nullDuration() {
         }
     
         //-----------------------------------------------------------------------
    -    public void test_parse_CharSequence() {
    -        Interval test = Interval.parse(NOW1 + "/" + NOW2);
    -        assertEquals(test.getStart(), NOW1);
    -        assertEquals(test.getEnd(), NOW2);
    -    }
    -
    -    public void test_parse_CharSequence_DurationInstant() {
    -        Interval test = Interval.parse(Duration.ofHours(6) + "/" + NOW2);
    -        assertEquals(test.getStart(), NOW2.minus(6, HOURS));
    -        assertEquals(test.getEnd(), NOW2);
    -    }
    -
    -    public void test_parse_CharSequence_PeriodDurationInstant() {
    -        Interval test = Interval.parse("P6MT5H/" + NOW2);
    -        assertEquals(test.getStart(), NOW2.atZone(ZoneOffset.UTC).minus(6, MONTHS).minus(5, HOURS).toInstant());
    -        assertEquals(test.getEnd(), NOW2);
    -    }
    -
    -    public void test_parse_CharSequence_DurationInstant_caseInsensitive() {
    -        Interval test = Interval.parse("pt6h/" + NOW2);
    -        assertEquals(test.getStart(), NOW2.minus(6, HOURS));
    -        assertEquals(test.getEnd(), NOW2);
    -    }
    -
    -    public void test_parse_CharSequence_InstantDuration() {
    -        Interval test = Interval.parse(NOW1 + "/" + Duration.ofHours(6));
    -        assertEquals(test.getStart(), NOW1);
    -        assertEquals(test.getEnd(), NOW1.plus(6, HOURS));
    -    }
    -
    -    public void test_parse_CharSequence_InstantDuration_caseInsensitive() {
    -        Interval test = Interval.parse(NOW1 + "/pt6h");
    -        assertEquals(test.getStart(), NOW1);
    -        assertEquals(test.getEnd(), NOW1.plus(6, HOURS));
    -    }
    -
    -    public void test_parse_CharSequence_empty() {
    -        Interval test = Interval.parse(NOW1 + "/" + NOW1);
    -        assertEquals(test.getStart(), NOW1);
    -        assertEquals(test.getEnd(), NOW1);
    +    @DataProvider(name = "parseValid")
    +    Object[][] data_parseValid() {
    +        return new Object[][] {
    +            {NOW1 + "/" + NOW2, NOW1, NOW2},
    +            {Duration.ofHours(6) + "/" + NOW2, NOW2.minus(6, HOURS), NOW2},
    +            {"P6MT5H/" + NOW2, NOW2.atZone(ZoneOffset.UTC).minus(6, MONTHS).minus(5, HOURS).toInstant(), NOW2},
    +            {"pt6h/" + NOW2, NOW2.minus(6, HOURS), NOW2},
    +            {NOW1 + "/" + Duration.ofHours(6), NOW1, NOW1.plus(6, HOURS)},
    +            {NOW1 + "/pt6h", NOW1, NOW1.plus(6, HOURS)},
    +            {NOW1 + "/" + NOW1, NOW1, NOW1},
    +            {NOW1.atOffset(ZoneOffset.ofHours(2)) + "/" + NOW2.atOffset(ZoneOffset.ofHours(2)), NOW1, NOW2},
    +            {NOW1.atOffset(ZoneOffset.ofHours(2)) + "/" + NOW2.atOffset(ZoneOffset.ofHours(3)), NOW1, NOW2},
    +            {NOW1.atOffset(ZoneOffset.ofHours(2)) + "/" + NOW2.atOffset(ZoneOffset.ofHours(2)).toLocalDateTime(), NOW1, NOW2},
    +        };
         }
         
    -    public void test_parseCharSequence_InstantInstant_with_timezones() {
    -    	Interval test = Interval.parse(NOW1.atOffset(ZoneOffset.ofHours(2)).toString() + "/" + NOW2.atOffset(ZoneOffset.ofHours(2)).toString());
    -    	assertEquals(test.getStart(), NOW1);
    -    	assertEquals(test.getEnd(), NOW2);
    +    @Test(dataProvider = "parseValid")
    +    public void test_parse_CharSequence(String input, Instant start, Instant end) {
    +        Interval test = Interval.parse(input);
    +        assertEquals(test.getStart(), start);
    +        assertEquals(test.getEnd(), end);
         }
     
         @Test(expectedExceptions = DateTimeException.class)
    
    From f28aa8a70509bb5281c06daedacfa40ad559a910 Mon Sep 17 00:00:00 2001
    From: Stephen Colebourne 
    Date: Sun, 16 Apr 2017 08:08:22 +0100
    Subject: [PATCH 008/279] Fix incorrect method name in Hours
    
    toPeriod() should have been toDuration()
    Fixes #76
    ---
     src/changes/changes.xml                         |  5 +++++
     src/main/java/org/threeten/extra/Hours.java     | 16 +++++++++++++++-
     src/test/java/org/threeten/extra/TestHours.java |  2 ++
     3 files changed, 22 insertions(+), 1 deletion(-)
    
    diff --git a/src/changes/changes.xml b/src/changes/changes.xml
    index e24c6580..393d88ef 100644
    --- a/src/changes/changes.xml
    +++ b/src/changes/changes.xml
    @@ -8,6 +8,11 @@
       
         
         
    +      
    +        Fix incorrect method name in Hours.
    +        toPeriod() should have been toDuration().
    +        Fixes #76.
    +      
           
             Add PeriodDuration, combining Period and Duration.
             See #74.
    diff --git a/src/main/java/org/threeten/extra/Hours.java b/src/main/java/org/threeten/extra/Hours.java
    index 12399453..2fef754a 100644
    --- a/src/main/java/org/threeten/extra/Hours.java
    +++ b/src/main/java/org/threeten/extra/Hours.java
    @@ -400,14 +400,28 @@ public Hours abs() {
         /**
          * Gets the number of hours as a {@code Duration}.
          * 

    - * This returns a duration with the same number of months. + * This returns a duration with the same number of hours. * * @return the equivalent duration, not null + * @deprecated Use {@link #toDuration()} */ + @Deprecated public Duration toPeriod() { return Duration.ofHours(hours); } + //------------------------------------------------------------------------- + /** + * Gets the number of hours as a {@code Duration}. + *

    + * This returns a duration with the same number of hours. + * + * @return the equivalent duration, not null + */ + public Duration toDuration() { + return Duration.ofHours(hours); + } + //----------------------------------------------------------------------- /** * Adds this amount to the specified temporal object. diff --git a/src/test/java/org/threeten/extra/TestHours.java b/src/test/java/org/threeten/extra/TestHours.java index f1d43fe2..6cc4995d 100644 --- a/src/test/java/org/threeten/extra/TestHours.java +++ b/src/test/java/org/threeten/extra/TestHours.java @@ -346,9 +346,11 @@ public void test_subtractFrom() { } //----------------------------------------------------------------------- + @SuppressWarnings("deprecation") public void test_toDuration() { for (int i = -20; i < 20; i++) { assertEquals(Hours.of(i).toPeriod(), Duration.ofHours(i)); + assertEquals(Hours.of(i).toDuration(), Duration.ofHours(i)); } } From e29622d5cadf8a89f1a362e5b532d778c7744c4f Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 16 Apr 2017 08:39:48 +0100 Subject: [PATCH 009/279] Extend parsing of Hours/Minutes/Seconds Allow parsing of days Fixes #77 --- src/main/java/org/threeten/extra/Hours.java | 67 ++++++++++++------ src/main/java/org/threeten/extra/Minutes.java | 59 +++++++++++----- src/main/java/org/threeten/extra/Seconds.java | 70 ++++++++++++------- .../java/org/threeten/extra/TestHours.java | 14 +++- .../java/org/threeten/extra/TestMinutes.java | 14 +++- .../java/org/threeten/extra/TestSeconds.java | 15 +++- 6 files changed, 171 insertions(+), 68 deletions(-) diff --git a/src/main/java/org/threeten/extra/Hours.java b/src/main/java/org/threeten/extra/Hours.java index 2fef754a..585cc375 100644 --- a/src/main/java/org/threeten/extra/Hours.java +++ b/src/main/java/org/threeten/extra/Hours.java @@ -75,12 +75,19 @@ public final class Hours */ private static final long serialVersionUID = -8494096666041369608L; + /** + * The number of hours per day. + */ + private static final int HOURS_PER_DAY = 24; + /** * The pattern for parsing. */ private static final Pattern PATTERN = - Pattern.compile("([-+]?)PT" - + "(?:([-+]?[0-9]+)H)?", Pattern.CASE_INSENSITIVE); + Pattern.compile("([-+]?)P" + + "(?:([-+]?[0-9]+)D)?" + + "(?:T" + + "(?:([-+]?[0-9]+)H)?)?", Pattern.CASE_INSENSITIVE); /** * The number of hours. @@ -145,19 +152,25 @@ public static Hours from(TemporalAmount amount) { /** * Obtains a {@code Hours} from a text string such as {@code PTnH}. *

    - * This will parse the string produced by {@code toString()} which is - * based on the ISO-8601 period format {@code PTnH}. + * This will parse the string produced by {@code toString()} and other + * related formats based on ISO-8601 {@code PnDTnH}. *

    * The string starts with an optional sign, denoted by the ASCII negative * or positive symbol. If negative, the whole amount is negated. - * The ASCII letters "P" and "T" are next in upper or lower case. - * The section has the suffix "H" in ASCII in either upper or lower case. - * The number part must consist of ASCII digits. The number may be prefixed - * by the ASCII negative or positive symbol. The number must parse to an - * {@code int}. - *

    - * The leading plus/minus sign, and negative value for hours is not part of - * the ISO-8601 standard. + * The ASCII letter "P" is next in upper or lower case. + * There are two sections consisting of a number and a suffix. + * There is one section for days suffixed by "D", + * followed by one section for hours suffixed by "H". + * At least one section must be present. + * If the hours section is present it must be prefixed by "T". + * If the hours section is omitted the "T" must be omitted. + * Letters must be in ASCII upper or lower case. + * The number part of each section must consist of ASCII digits. + * The number may be prefixed by the ASCII negative or positive symbol. + * The number must parse to an {@code int}. + *

    + * The leading plus/minus sign, and negative values for days and hours + * are not part of the ISO-8601 standard. *

    * For example, the following are valid inputs: *

    @@ -165,6 +178,8 @@ public static Hours from(TemporalAmount amount) {
          *   "PT-HM"           -- Hours.of(-2)
          *   "-PT2H"           -- Hours.of(-2)
          *   "-PT-2H"          -- Hours.of(2)
    +     *   "P3D"             -- Hours.of(3 * 24)
    +     *   "P3DT2H"          -- Hours.of(3 * 24 + 2)
          * 
    * * @param text the text to parse, not null @@ -176,17 +191,29 @@ public static Hours parse(CharSequence text) { Matcher matcher = PATTERN.matcher(text); if (matcher.matches()) { int negate = ("-".equals(matcher.group(1)) ? -1 : 1); - String hoursStr = matcher.group(2); - if (hoursStr != null) { - try { - int hours = Integer.parseInt(hoursStr); - return of(negate * hours); - } catch (NumberFormatException ex) { - throw new DateTimeParseException("Text cannot be parsed to Hours, non-numeric hours", text, 0, ex); + String daysStr = matcher.group(2); + String hoursStr = matcher.group(3); + if (daysStr != null || hoursStr != null) { + int hours = 0; + if (hoursStr != null) { + try { + hours = Integer.parseInt(hoursStr); + } catch (NumberFormatException ex) { + throw new DateTimeParseException("Text cannot be parsed to Hours, non-numeric hours", text, 0, ex); + } + } + if (daysStr != null) { + try { + int daysAsHours = Math.multiplyExact(Integer.parseInt(daysStr), HOURS_PER_DAY); + hours = Math.addExact(hours, daysAsHours); + } catch (NumberFormatException ex) { + throw new DateTimeParseException("Text cannot be parsed to Hours, non-numeric days", text, 0, ex); + } } + return of(Math.multiplyExact(hours, negate)); } } - throw new DateTimeParseException("Text cannot be parsed to a Hours", text, 0); + throw new DateTimeParseException("Text cannot be parsed to Hours", text, 0); } //----------------------------------------------------------------------- diff --git a/src/main/java/org/threeten/extra/Minutes.java b/src/main/java/org/threeten/extra/Minutes.java index 8e49ba6d..bbb93d1c 100644 --- a/src/main/java/org/threeten/extra/Minutes.java +++ b/src/main/java/org/threeten/extra/Minutes.java @@ -75,6 +75,10 @@ public final class Minutes */ private static final long serialVersionUID = 2602801843170589407L; + /** + * The number of minutes per day. + */ + private static final int MINUTES_PER_DAY = 24 * 60; /** * The number of minutes per hour. */ @@ -84,9 +88,11 @@ public final class Minutes * The pattern for parsing. */ private static final Pattern PATTERN = - Pattern.compile("([-+]?)PT" + Pattern.compile("([-+]?)P" + + "(?:([-+]?[0-9]+)D)?" + + "(?:T" + "(?:([-+]?[0-9]+)H)?" - + "(?:([-+]?[0-9]+)M)?", Pattern.CASE_INSENSITIVE); + + "(?:([-+]?[0-9]+)M)?)?", Pattern.CASE_INSENSITIVE); /** * The number of minutes. @@ -168,22 +174,26 @@ public static Minutes from(TemporalAmount amount) { /** * Obtains a {@code Minutes} from a text string such as {@code PTnM}. *

    - * This will parse the string produced by {@code toString()} which is - * based on the ISO-8601 period format {@code PTnHnM}. + * This will parse the string produced by {@code toString()} and other + * related formats based on ISO-8601 {@code PnDTnHnM}. *

    * The string starts with an optional sign, denoted by the ASCII negative * or positive symbol. If negative, the whole amount is negated. - * The ASCII letters "P" and "T" are next in upper or lower case. - * There are then two sections, each consisting of a number and a suffix. - * At least one of the two sections must be present. - * The sections have suffixes in ASCII of "H" and "M" for hours and minutes, - * accepted in upper or lower case. The suffixes must occur in order. + * The ASCII letter "P" is next in upper or lower case. + * There are three sections consisting of a number and a suffix. + * There is one section for days suffixed by "D", + * followed by one section for hours suffixed by "H", + * followed by one section for minutes suffixed by "M". + * At least one section must be present. + * If the hours or minutes section is present it must be prefixed by "T". + * If the hours or minutes section is omitted the "T" must be omitted. + * Letters must be in ASCII upper or lower case. * The number part of each section must consist of ASCII digits. * The number may be prefixed by the ASCII negative or positive symbol. * The number must parse to an {@code int}. *

    - * The leading plus/minus sign, and negative values for hours and minutes are - * not part of the ISO-8601 standard. + * The leading plus/minus sign, and negative values for days, hours and + * minutes are not part of the ISO-8601 standard. *

    * For example, the following are valid inputs: *

    @@ -193,6 +203,8 @@ public static Minutes from(TemporalAmount amount) {
          *   "-PT-2M"          -- Minutes.of(2)
          *   "PT3H"            -- Minutes.of(3 * 60)
          *   "PT3H-2M"         -- Minutes.of(3 * 60 - 2)
    +     *   "P3D"             -- Minutes.of(3 * 24 * 60)
    +     *   "P3DT2M"          -- Minutes.of(3 * 24 * 60 + 2)
          * 
    * * @param text the text to parse, not null @@ -204,29 +216,38 @@ public static Minutes parse(CharSequence text) { Matcher matcher = PATTERN.matcher(text); if (matcher.matches()) { int negate = ("-".equals(matcher.group(1)) ? -1 : 1); - String hoursStr = matcher.group(2); - String minutesStr = matcher.group(3); - if (hoursStr != null || minutesStr != null) { + String daysStr = matcher.group(2); + String hoursStr = matcher.group(3); + String minutesStr = matcher.group(4); + if (daysStr != null || hoursStr != null || minutesStr != null) { int minutes = 0; if (minutesStr != null) { try { minutes = Integer.parseInt(minutesStr); } catch (NumberFormatException ex) { - throw new DateTimeParseException("Text cannot be parsed to a Minutes, non-numeric minutes", text, 0, ex); + throw new DateTimeParseException("Text cannot be parsed to Minutes, non-numeric minutes", text, 0, ex); } } if (hoursStr != null) { try { - int hours = Math.multiplyExact(Integer.parseInt(hoursStr), MINUTES_PER_HOUR); - minutes = Math.addExact(minutes, hours); + int hoursAsMins = Math.multiplyExact(Integer.parseInt(hoursStr), MINUTES_PER_HOUR); + minutes = Math.addExact(minutes, hoursAsMins); + } catch (NumberFormatException ex) { + throw new DateTimeParseException("Text cannot be parsed to Minutes, non-numeric hours", text, 0, ex); + } + } + if (daysStr != null) { + try { + int daysAsMins = Math.multiplyExact(Integer.parseInt(daysStr), MINUTES_PER_DAY); + minutes = Math.addExact(minutes, daysAsMins); } catch (NumberFormatException ex) { - throw new DateTimeParseException("Text cannot be parsed to a Minutes, non-numeric minutes", text, 0, ex); + throw new DateTimeParseException("Text cannot be parsed to Minutes, non-numeric days", text, 0, ex); } } return of(Math.multiplyExact(minutes, negate)); } } - throw new DateTimeParseException("Text cannot be parsed to a Minutes", text, 0); + throw new DateTimeParseException("Text cannot be parsed to Minutes", text, 0); } //----------------------------------------------------------------------- diff --git a/src/main/java/org/threeten/extra/Seconds.java b/src/main/java/org/threeten/extra/Seconds.java index 9c66cdef..95e53545 100644 --- a/src/main/java/org/threeten/extra/Seconds.java +++ b/src/main/java/org/threeten/extra/Seconds.java @@ -77,6 +77,10 @@ public final class Seconds */ private static final long serialVersionUID = 2602801843170589407L; + /** + * The number of seconds per day. + */ + private static final int SECONDS_PER_DAY = 86400; /** * The number of seconds per hour. */ @@ -90,10 +94,12 @@ public final class Seconds * The pattern for parsing. */ private static final Pattern PATTERN = - Pattern.compile("([-+]?)PT" + Pattern.compile("([-+]?)P" + + "(?:([-+]?[0-9]+)D)?" + + "(?:T" + "(?:([-+]?[0-9]+)H)?" + "(?:([-+]?[0-9]+)M)?" - + "(?:([-+]?[0-9]+)S)?", Pattern.CASE_INSENSITIVE); + + "(?:([-+]?[0-9]+)S)?)?", Pattern.CASE_INSENSITIVE); /** * The number of seconds. @@ -193,22 +199,27 @@ public static Seconds from(TemporalAmount amount) { /** * Obtains a {@code Seconds} from a text string such as {@code PTnS}. *

    - * This will parse the string produced by {@code toString()} which is - * based on the ISO-8601 period format {@code PTnHnMnS}. + * This will parse the string produced by {@code toString()} and other + * related formats based on ISO-8601 {@code PnDTnHnMnS}. *

    * The string starts with an optional sign, denoted by the ASCII negative * or positive symbol. If negative, the whole amount is negated. - * The ASCII letters "P" and "T" are next in upper or lower case. - * There are then three sections, each consisting of a number and a suffix. - * At least one of the three sections must be present. - * The sections have suffixes in ASCII of "H", "M" and "S" for hours, minutes and seconds, - * accepted in upper or lower case. The suffixes must occur in order. + * The ASCII letter "P" is next in upper or lower case. + * There are four sections consisting of a number and a suffix. + * There is one section for days suffixed by "D", + * followed by one section for hours suffixed by "H", + * followed by one section for minutes suffixed by "M", + * followed by one section for seconds suffixed by "S". + * At least one section must be present. + * If the hours, minutes or seconds section is present it must be prefixed by "T". + * If the hours, minutes or seconds section is omitted the "T" must be omitted. + * Letters must be in ASCII upper or lower case. * The number part of each section must consist of ASCII digits. * The number may be prefixed by the ASCII negative or positive symbol. * The number must parse to an {@code int}. *

    - * The leading plus/minus sign, and negative values for hours, minutes and - * seconds are not part of the ISO-8601 standard. + * The leading plus/minus sign, and negative values for days, hours, minutes + * and seconds are not part of the ISO-8601 standard. *

    * For example, the following are valid inputs: *

    @@ -217,7 +228,9 @@ public static Seconds from(TemporalAmount amount) {
          *   "-PT2S"           -- Seconds.of(-2)
          *   "-PT-2S"          -- Seconds.of(2)
          *   "PT3S"            -- Seconds.of(3 * 60)
    -     *   "PT3H-2M7S"         -- Seconds.of(3 * 3600 - 2 * 60 + 7)
    +     *   "PT3H-2M7S"       -- Seconds.of(3 * 3600 - 2 * 60 + 7)
    +     *   "P2D"             -- Seconds.of(2 * 86400)
    +     *   "P2DT3H"          -- Seconds.of(2 * 86400 + 3 * 3600)
          * 
    * * @param text the text to parse, not null @@ -229,38 +242,47 @@ public static Seconds parse(CharSequence text) { Matcher matcher = PATTERN.matcher(text); if (matcher.matches()) { int negate = ("-".equals(matcher.group(1)) ? -1 : 1); - String hoursStr = matcher.group(2); - String minutesStr = matcher.group(3); - String secondsStr = matcher.group(4); - if (hoursStr != null || minutesStr != null || secondsStr != null) { + String daysStr = matcher.group(2); + String hoursStr = matcher.group(3); + String minutesStr = matcher.group(4); + String secondsStr = matcher.group(5); + if (daysStr != null || hoursStr != null || minutesStr != null || secondsStr != null) { int seconds = 0; if (secondsStr != null) { try { seconds = Integer.parseInt(secondsStr); } catch (NumberFormatException ex) { - throw new DateTimeParseException("Text cannot be parsed to a Seconds, non-numeric seconds", text, 0, ex); + throw new DateTimeParseException("Text cannot be parsed to Seconds, non-numeric seconds", text, 0, ex); } } if (minutesStr != null) { try { - int minutes = Math.multiplyExact(Integer.parseInt(minutesStr), SECONDS_PER_MINUTE); - seconds = Math.addExact(seconds, minutes); + int minutesAsSecs = Math.multiplyExact(Integer.parseInt(minutesStr), SECONDS_PER_MINUTE); + seconds = Math.addExact(seconds, minutesAsSecs); } catch (NumberFormatException ex) { - throw new DateTimeParseException("Text cannot be parsed to a Seconds, non-numeric minutes", text, 0, ex); + throw new DateTimeParseException("Text cannot be parsed to Seconds, non-numeric minutes", text, 0, ex); } } if (hoursStr != null) { try { - int hours = Math.multiplyExact(Integer.parseInt(hoursStr), SECONDS_PER_HOUR); - seconds = Math.addExact(seconds, hours); + int hoursAsSecs = Math.multiplyExact(Integer.parseInt(hoursStr), SECONDS_PER_HOUR); + seconds = Math.addExact(seconds, hoursAsSecs); + } catch (NumberFormatException ex) { + throw new DateTimeParseException("Text cannot be parsed to Seconds, non-numeric hours", text, 0, ex); + } + } + if (daysStr != null) { + try { + int daysAsSecs = Math.multiplyExact(Integer.parseInt(daysStr), SECONDS_PER_DAY); + seconds = Math.addExact(seconds, daysAsSecs); } catch (NumberFormatException ex) { - throw new DateTimeParseException("Text cannot be parsed to a Seconds, non-numeric seconds", text, 0, ex); + throw new DateTimeParseException("Text cannot be parsed to Seconds, non-numeric days", text, 0, ex); } } return of(Math.multiplyExact(seconds, negate)); } } - throw new DateTimeParseException("Text cannot be parsed to a Seconds", text, 0); + throw new DateTimeParseException("Text cannot be parsed to Seconds", text, 0); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestHours.java b/src/test/java/org/threeten/extra/TestHours.java index 6cc4995d..b54e183e 100644 --- a/src/test/java/org/threeten/extra/TestHours.java +++ b/src/test/java/org/threeten/extra/TestHours.java @@ -101,6 +101,18 @@ Object[][] data_valid() { {"PT+2H", 2}, {"PT-0H", 0}, {"PT-2H", -2}, + + {"P0D", 0 * 24}, + {"P1D", 1 * 24}, + {"P2D", 2 * 24}, + {"P1234567D", 1234567 * 24}, + {"P+0D", 0 * 24}, + {"P+2D", 2 * 24}, + {"P-0D", 0 * 24}, + {"P-2D", -2 * 24}, + + {"P0DT0H", 0}, + {"P1DT2H", 1 * 24+ 2}, }; } @@ -123,7 +135,6 @@ public void test_parse_CharSequence_valid_initialMinus(String str, int expectedD Object[][] data_invalid() { return new Object[][] { {"P3W"}, - {"P3D"}, {"P3Q"}, {"P1M2Y"}, @@ -131,6 +142,7 @@ Object[][] data_invalid() { {"-3"}, {"3H"}, {"-3H"}, + {"P3H"}, {"P3"}, {"P-3"}, {"PH"}, diff --git a/src/test/java/org/threeten/extra/TestMinutes.java b/src/test/java/org/threeten/extra/TestMinutes.java index a7f44e5a..88f578eb 100644 --- a/src/test/java/org/threeten/extra/TestMinutes.java +++ b/src/test/java/org/threeten/extra/TestMinutes.java @@ -127,6 +127,15 @@ Object[][] data_valid() { {"PT-0H", 0}, {"PT-2H", -120}, + {"P0D", 0}, + {"P1D", 1 * 24 * 60}, + {"P2D", 2 * 24 * 60}, + {"P1234D", 1234 * 24 * 60}, + {"P+0D", 0}, + {"P+2D", 2 * 24 * 60}, + {"P-0D", 0}, + {"P-2D", -2 * 24 * 60}, + {"PT0H0M", 0}, {"PT2H3M", 123}, {"PT+2H3M", 123}, @@ -134,6 +143,9 @@ Object[][] data_valid() { {"PT-2H3M", -117}, {"PT2H-3M", 117}, {"PT-2H-3M", -123}, + + {"P0DT0H0M", 0}, + {"P5DT2H4M", 5 * 24 * 60 + 2 * 60 + 4}, }; } @@ -156,7 +168,6 @@ public void test_parse_CharSequence_valid_initialMinus(String str, int expectedM Object[][] data_invalid() { return new Object[][] { {"P3W"}, - {"P3D"}, {"P3Q"}, {"P1M2Y"}, @@ -164,6 +175,7 @@ Object[][] data_invalid() { {"-3"}, {"3M"}, {"-3M"}, + {"P3M"}, {"P3"}, {"P-3"}, {"PM"}, diff --git a/src/test/java/org/threeten/extra/TestSeconds.java b/src/test/java/org/threeten/extra/TestSeconds.java index bdc399be..71d0e83c 100644 --- a/src/test/java/org/threeten/extra/TestSeconds.java +++ b/src/test/java/org/threeten/extra/TestSeconds.java @@ -152,6 +152,15 @@ Object[][] data_valid() { {"PT-0H", 0}, {"PT-2H", -120 * 60}, + {"P0D", 0}, + {"P1D", 60 * 60 * 24}, + {"P2D", 120 * 60 * 24}, + {"P1234D", 1234 * 60 * 60 * 24}, + {"P+0D", 0}, + {"P+2D", 120 * 60 * 24}, + {"P-0D", 0}, + {"P-2D", -120 * 60 * 24}, + {"PT0M0S", 0}, {"PT2M3S", 2 * 60 + 3}, {"PT+2M3S", 2 * 60 + 3}, @@ -168,8 +177,8 @@ Object[][] data_valid() { {"PT2H-3S", 2 * 3600 - 3}, {"PT-2H-3S", -2 * 3600 - 3}, - {"PT0H0M0S", 0}, - {"PT2H4M3S", 2 * 3600 + 4 * 60 + 3}, + {"P0DT0H0M0S", 0}, + {"P5DT2H4M3S", 5 * 86400 + 2 * 3600 + 4 * 60 + 3}, }; } @@ -192,7 +201,6 @@ public void test_parse_CharSequence_valid_initialMinus(String str, int expectedS Object[][] data_invalid() { return new Object[][] { {"P3W"}, - {"P3D"}, {"P3Q"}, {"P1M2Y"}, @@ -200,6 +208,7 @@ Object[][] data_invalid() { {"-3"}, {"3S"}, {"-3S"}, + {"P3S"}, {"P3"}, {"P-3"}, {"PS"}, From bab6c5d6141a043ab02d771a7721029cfadbac79 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 24 Apr 2017 16:44:55 +0100 Subject: [PATCH 010/279] Update release notes --- src/changes/changes.xml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 393d88ef..791f14a8 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -8,14 +8,18 @@ + + Add PeriodDuration, combining Period and Duration. + See #74. + Fix incorrect method name in Hours. toPeriod() should have been toDuration(). Fixes #76. - Add PeriodDuration, combining Period and Duration. - See #74. + Extend formats parsed by Hours, Minutes and Seconds. + Fixes #77. Extend formats parsed by Interval, allowing end instant to have offset inferred from start instant. From 4da871a854dfc35d5930c74ee1cd14ace50f971d Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 24 Apr 2017 16:39:29 +0100 Subject: [PATCH 011/279] Enhance documentation --- src/site/markdown/index.md | 1 + src/site/markdown/userguide.md | 1 + 2 files changed, 2 insertions(+) diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index 371153b3..ec8b30cf 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -26,6 +26,7 @@ The following features are included: [`Months`](apidocs/org/threeten/extra/Months.html) and [`Years`](apidocs/org/threeten/extra/Years.html) - amounts of time * [`Interval`](apidocs/org/threeten/extra/Interval.html) - an interval between two instants +* [`PeriodDuration`](apidocs/org/threeten/extra/PeriodDuration.html) - combines `Period` and `Duration` * Weekend adjusters * [Coptic](apidocs/org/threeten/extra/chrono/CopticChronology.html) calendar system * [Ethiopic](apidocs/org/threeten/extra/chrono/EthiopicChronology.html) calendar system diff --git a/src/site/markdown/userguide.md b/src/site/markdown/userguide.md index 040561c6..ac10a493 100644 --- a/src/site/markdown/userguide.md +++ b/src/site/markdown/userguide.md @@ -20,6 +20,7 @@ These include: * [`Months`](apidocs/org/threeten/extra/Months.html) - an amount of time measured in months * [`Years`](apidocs/org/threeten/extra/Years.html) - an amount of time measured in years * [`Interval`](apidocs/org/threeten/extra/Interval.html) - an interval between two instants +* [`PeriodDuration`](apidocs/org/threeten/extra/PeriodDuration.html) - combines a `Period` and a `Duration` ## Calendar systems From 0dbe5199f462978975f31f6fb23ea83b877169cc Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 24 Apr 2017 16:40:32 +0100 Subject: [PATCH 012/279] Release v1.1 --- README.md | 4 ++-- pom.xml | 2 +- src/changes/changes.xml | 2 +- src/site/markdown/index.md | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index de2e5c52..fc48d5f1 100644 --- a/README.md +++ b/README.md @@ -17,12 +17,12 @@ Various documentation is available: ### Releases -Release 1.0 is the current release. +Release 1.1 is the current release. This release is considered stable and worthy of the 1.x tag. ThreeTen-Extra requires Java SE 8 or later and has no dependencies. -Available in the [Maven Central repository](http://search.maven.org/#artifactdetails|org.threeten|threeten-extra|1.0|jar) +Available in the [Maven Central repository](http://search.maven.org/#artifactdetails|org.threeten|threeten-extra|1.1|jar) ### Support diff --git a/pom.xml b/pom.xml index de04537f..274373bb 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ threeten-extra jar ThreeTen-Extra - 1.1-SNAPSHOT + 1.1 Additional functionality that enhances JSR-310 dates and times in JDK 8 http://www.threeten.org/threeten-extra diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 791f14a8..5cfdee23 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,7 +7,7 @@ - + Add PeriodDuration, combining Period and Duration. See #74. diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index ec8b30cf..c29b0c73 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -47,18 +47,18 @@ Various documentation is available: ## Releases -Release 1.0 is the current release. +Release 1.1 is the current release. This release is considered stable and worthy of the 1.x tag. ThreeTen-Extra requires Java SE 8 or later and has no [dependencies](dependencies.html). -Available in [Maven Central](http://search.maven.org/#artifactdetails%7Corg.threeten%7Cthreeten-extra%7C1.0%7Cjar). +Available in [Maven Central](http://search.maven.org/#artifactdetails%7Corg.threeten%7Cthreeten-extra%7C1.1%7Cjar). ```xml org.threeten threeten-extra - 1.0 + 1.1 ``` From 4465a45d7e775d8a86345fb55381ee202dde20c5 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 24 Apr 2017 16:53:12 +0100 Subject: [PATCH 013/279] Bump version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 274373bb..2218b679 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ threeten-extra jar ThreeTen-Extra - 1.1 + 1.2-SNAPSHOT Additional functionality that enhances JSR-310 dates and times in JDK 8 http://www.threeten.org/threeten-extra From 5fb0df0b4aeb2f17099380a8490fe0e3068a12e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Raupach?= Date: Tue, 9 May 2017 17:04:07 +0200 Subject: [PATCH 014/279] YearWeek added method plusWeeks(long) added method minusWeeks(long) --- .../java/org/threeten/extra/YearWeek.java | 54 +++++++++++ .../java/org/threeten/extra/TestYearWeek.java | 94 +++++++++++++------ 2 files changed, 119 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/threeten/extra/YearWeek.java b/src/main/java/org/threeten/extra/YearWeek.java index 17cbae23..ff585096 100644 --- a/src/main/java/org/threeten/extra/YearWeek.java +++ b/src/main/java/org/threeten/extra/YearWeek.java @@ -473,6 +473,60 @@ public boolean is53WeekYear() { public int lengthOfYear() { return (is53WeekYear() ? 371 : 364); } + + //----------------------------------------------------------------------- + /** + * Returns a copy of this year-week with the specified number of weeks added. + * *

    + * This instance is immutable and unaffected by this method call. + * + * @param weeksToAdd the weeks to add, may be negative + * @return the year-week with the weeks added, not null + */ + public YearWeek plusWeeks(long weeksToAdd) { + if (weeksToAdd == 0) { + return this; + } + if (weeksToAdd < 0) { + return minusWeeks(-weeksToAdd); + } + YearWeek yearWeek = this; + while (weeksToAdd-- > 0) { + int weeksInYear = yearWeek.is53WeekYear() ? 53 : 52; + if (yearWeek.week < weeksInYear) { + yearWeek = YearWeek.of(yearWeek.year, yearWeek.week + 1); + } else { + yearWeek = YearWeek.of(yearWeek.year + 1, 1); + } + } + return yearWeek; + } + + /** + * Returns a copy of this year-week with the specified number of weeks subtracted. + * *

    + * This instance is immutable and unaffected by this method call. + * + * @param weeksToSubtract the weeks to subtract, may be negative + * @return the year-week with the weeks subtracted, not null + */ + public YearWeek minusWeeks(long weeksToSubtract) { + if (weeksToSubtract == 0) { + return this; + } + if (weeksToSubtract < 0) { + return plusWeeks(-weeksToSubtract); + } + YearWeek yearWeek = this; + while (weeksToSubtract-- > 0) { + if (yearWeek.week > 1) { + yearWeek = YearWeek.of(yearWeek.year, yearWeek.week - 1); + } else { + yearWeek = YearWeek.of(yearWeek.year - 1, weekRange(yearWeek.year - 1)); + } + } + return yearWeek; + } //----------------------------------------------------------------------- /** diff --git a/src/test/java/org/threeten/extra/TestYearWeek.java b/src/test/java/org/threeten/extra/TestYearWeek.java index 443b8764..8549b52b 100644 --- a/src/test/java/org/threeten/extra/TestYearWeek.java +++ b/src/test/java/org/threeten/extra/TestYearWeek.java @@ -258,25 +258,25 @@ Object[][] provider_sampleAtDay() { {2014, 52, MONDAY, 2014, 12, 22}, {2014, 52, TUESDAY, 2014, 12, 23}, {2014, 52, WEDNESDAY, 2014, 12, 24}, - {2014, 52, THURSDAY, 2014, 12, 25}, + {2014, 52, THURSDAY, 2014, 12, 25}, {2014, 52, FRIDAY, 2014, 12, 26}, - {2014, 52, SATURDAY, 2014, 12, 27}, + {2014, 52, SATURDAY, 2014, 12, 27}, {2014, 52, SUNDAY, 2014, 12, 28}, - {2015, 1, MONDAY, 2014, 12, 29}, - {2015, 1, TUESDAY, 2014, 12, 30}, - {2015, 1, WEDNESDAY, 2014, 12, 31}, - {2015, 1, THURSDAY, 2015, 1, 1}, - {2015, 1, FRIDAY, 2015, 1, 2}, - {2015, 1, SATURDAY, 2015, 1, 3}, - {2015, 1, SUNDAY, 2015, 1, 4}, - {2017, 1, MONDAY, 2017, 1, 2}, - {2017, 1, TUESDAY, 2017, 1, 3}, - {2017, 1, WEDNESDAY, 2017, 1, 4}, - {2017, 1, THURSDAY, 2017, 1, 5}, - {2017, 1, FRIDAY, 2017, 1, 6}, - {2017, 1, SATURDAY, 2017, 1, 7}, - {2017, 1, SUNDAY, 2017, 1, 8}, - {2025, 1, MONDAY, 2024, 12, 30} + {2015, 1, MONDAY, 2014, 12, 29}, + {2015, 1, TUESDAY, 2014, 12, 30}, + {2015, 1, WEDNESDAY, 2014, 12, 31}, + {2015, 1, THURSDAY, 2015, 1, 1}, + {2015, 1, FRIDAY, 2015, 1, 2}, + {2015, 1, SATURDAY, 2015, 1, 3}, + {2015, 1, SUNDAY, 2015, 1, 4}, + {2017, 1, MONDAY, 2017, 1, 2}, + {2017, 1, TUESDAY, 2017, 1, 3}, + {2017, 1, WEDNESDAY, 2017, 1, 4}, + {2017, 1, THURSDAY, 2017, 1, 5}, + {2017, 1, FRIDAY, 2017, 1, 6}, + {2017, 1, SATURDAY, 2017, 1, 7}, + {2017, 1, SUNDAY, 2017, 1, 8}, + {2025, 1, MONDAY, 2024, 12, 30} }; } @@ -640,10 +640,10 @@ public void test_parse_CharSequenceDateTimeFormatter_nullDateTimeFormatter() { //----------------------------------------------------------------------- public void test_format() { DateTimeFormatter f = new DateTimeFormatterBuilder() - .appendValue(WEEK_BASED_YEAR, 4) - .appendLiteral('-') - .appendValue(WEEK_OF_WEEK_BASED_YEAR, 2) - .toFormatter(); + .appendValue(WEEK_BASED_YEAR, 4) + .appendLiteral('-') + .appendValue(WEEK_OF_WEEK_BASED_YEAR, 2) + .toFormatter(); assertEquals(TEST.format(f), "2015-01"); } @@ -722,14 +722,50 @@ public void test_withWeek_sameWeek() { assertEquals(YearWeek.of(2014, 2).withWeek(2), YearWeek.of(2014, 2)); } - @Test(expectedExceptions = DateTimeException.class) - public void test_withWeek_int_max() { - TEST.withWeek(Integer.MAX_VALUE); - } - - @Test(expectedExceptions = DateTimeException.class) - public void test_withWeek_int_min() { - TEST.withWeek(Integer.MIN_VALUE); + //----------------------------------------------------------------------- + // plusWeeks(long) + //----------------------------------------------------------------------- + public void test_plusWeeks() { + assertEquals(TEST.plusWeeks(0), TEST); + assertEquals(TEST.plusWeeks(1), YearWeek.of(2015, 2)); + assertEquals(TEST.plusWeeks(2), YearWeek.of(2015, 3)); + assertEquals(TEST.plusWeeks(51), YearWeek.of(2015, 52)); + assertEquals(TEST.plusWeeks(52), YearWeek.of(2015, 53)); + assertEquals(TEST.plusWeeks(53), YearWeek.of(2016, 1)); + assertEquals(TEST.plusWeeks(314), YearWeek.of(2021, 1)); + } + + public void test_plusWeeks_negative() { + assertEquals(TEST.plusWeeks(0), TEST); + assertEquals(TEST.plusWeeks(-1), YearWeek.of(2014, 52)); + assertEquals(TEST.plusWeeks(-2), YearWeek.of(2014, 51)); + assertEquals(TEST.plusWeeks(-51), YearWeek.of(2014, 2)); + assertEquals(TEST.plusWeeks(-52), YearWeek.of(2014, 1)); + assertEquals(TEST.plusWeeks(-53), YearWeek.of(2013, 52)); + assertEquals(TEST.plusWeeks(-261), YearWeek.of(2009, 53)); + } + + //----------------------------------------------------------------------- + // minusWeeks(long) + //----------------------------------------------------------------------- + public void test_minusWeeks() { + assertEquals(TEST.minusWeeks(0), TEST); + assertEquals(TEST.minusWeeks(1), YearWeek.of(2014, 52)); + assertEquals(TEST.minusWeeks(2), YearWeek.of(2014, 51)); + assertEquals(TEST.minusWeeks(51), YearWeek.of(2014, 2)); + assertEquals(TEST.minusWeeks(52), YearWeek.of(2014, 1)); + assertEquals(TEST.minusWeeks(53), YearWeek.of(2013, 52)); + assertEquals(TEST.minusWeeks(261), YearWeek.of(2009, 53)); + } + + public void test_minusWeeks_negative() { + assertEquals(TEST.minusWeeks(0), TEST); + assertEquals(TEST.minusWeeks(-1), YearWeek.of(2015, 2)); + assertEquals(TEST.minusWeeks(-2), YearWeek.of(2015, 3)); + assertEquals(TEST.minusWeeks(-51), YearWeek.of(2015, 52)); + assertEquals(TEST.minusWeeks(-52), YearWeek.of(2015, 53)); + assertEquals(TEST.minusWeeks(-53), YearWeek.of(2016, 1)); + assertEquals(TEST.minusWeeks(-314), YearWeek.of(2021, 1)); } //----------------------------------------------------------------------- From 9b32ab2927bf692468e1184f13350246519264c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Raupach?= Date: Wed, 10 May 2017 08:15:51 +0200 Subject: [PATCH 015/279] changes.xml Added entry for plusWeeks/minusWeek in YearWeek --- src/changes/changes.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 5cfdee23..f1111faa 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,6 +7,12 @@ + + + Add plusWeeks/minusWeeks to YearWeek + See #78 + + Add PeriodDuration, combining Period and Duration. From 7c958101d5794bd463c437e6299bb7551c0d3e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Raupach?= Date: Wed, 10 May 2017 08:38:34 +0200 Subject: [PATCH 016/279] plusWeeks/minusWeek in YearWeek Methods now use LocalDate instead of a for-loop. --- .../java/org/threeten/extra/YearWeek.java | 32 +++++-------------- .../java/org/threeten/extra/TestYearWeek.java | 22 ++++++++++++- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/threeten/extra/YearWeek.java b/src/main/java/org/threeten/extra/YearWeek.java index ff585096..ee039bf2 100644 --- a/src/main/java/org/threeten/extra/YearWeek.java +++ b/src/main/java/org/threeten/extra/YearWeek.java @@ -487,19 +487,9 @@ public YearWeek plusWeeks(long weeksToAdd) { if (weeksToAdd == 0) { return this; } - if (weeksToAdd < 0) { - return minusWeeks(-weeksToAdd); - } - YearWeek yearWeek = this; - while (weeksToAdd-- > 0) { - int weeksInYear = yearWeek.is53WeekYear() ? 53 : 52; - if (yearWeek.week < weeksInYear) { - yearWeek = YearWeek.of(yearWeek.year, yearWeek.week + 1); - } else { - yearWeek = YearWeek.of(yearWeek.year + 1, 1); - } - } - return yearWeek; + long daysToAdd = weeksToAdd * 7; + LocalDate mondayOfWeek = atDay(DayOfWeek.MONDAY).plusDays(daysToAdd); + return YearWeek.from(mondayOfWeek); } /** @@ -514,18 +504,12 @@ public YearWeek minusWeeks(long weeksToSubtract) { if (weeksToSubtract == 0) { return this; } - if (weeksToSubtract < 0) { - return plusWeeks(-weeksToSubtract); - } - YearWeek yearWeek = this; - while (weeksToSubtract-- > 0) { - if (yearWeek.week > 1) { - yearWeek = YearWeek.of(yearWeek.year, yearWeek.week - 1); - } else { - yearWeek = YearWeek.of(yearWeek.year - 1, weekRange(yearWeek.year - 1)); - } + if (weeksToSubtract == 0) { + return this; } - return yearWeek; + long daysToAdd = weeksToSubtract * 7; + LocalDate mondayOfWeek = atDay(DayOfWeek.MONDAY).minusDays(daysToAdd); + return YearWeek.from(mondayOfWeek); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestYearWeek.java b/src/test/java/org/threeten/extra/TestYearWeek.java index 8549b52b..b532c69c 100644 --- a/src/test/java/org/threeten/extra/TestYearWeek.java +++ b/src/test/java/org/threeten/extra/TestYearWeek.java @@ -744,7 +744,17 @@ public void test_plusWeeks_negative() { assertEquals(TEST.plusWeeks(-53), YearWeek.of(2013, 52)); assertEquals(TEST.plusWeeks(-261), YearWeek.of(2009, 53)); } - + + @Test(expectedExceptions = ArithmeticException.class) + public void test_plusWeeks_max_long() { + TEST.plusWeeks(Long.MAX_VALUE); + } + + @Test(expectedExceptions = DateTimeException.class) + public void test_plusWeeks_min_long() { + TEST.plusWeeks(Long.MIN_VALUE); + } + //----------------------------------------------------------------------- // minusWeeks(long) //----------------------------------------------------------------------- @@ -767,6 +777,16 @@ public void test_minusWeeks_negative() { assertEquals(TEST.minusWeeks(-53), YearWeek.of(2016, 1)); assertEquals(TEST.minusWeeks(-314), YearWeek.of(2021, 1)); } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_minWeeks_max_long() { + TEST.plusWeeks(Long.MAX_VALUE); + } + + @Test(expectedExceptions = DateTimeException.class) + public void test_minWeeks_min_long() { + TEST.plusWeeks(Long.MIN_VALUE); + } //----------------------------------------------------------------------- // query(TemporalQuery) From 31d58962746d86cfc19e89131995c205e62c5427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Raupach?= Date: Wed, 10 May 2017 09:25:49 +0200 Subject: [PATCH 017/279] Accidently removed the methods test_withWeek_int_max and test_withWeek_int_min --- .../java/org/threeten/extra/TestYearWeek.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/threeten/extra/TestYearWeek.java b/src/test/java/org/threeten/extra/TestYearWeek.java index b532c69c..fd6af5b7 100644 --- a/src/test/java/org/threeten/extra/TestYearWeek.java +++ b/src/test/java/org/threeten/extra/TestYearWeek.java @@ -722,6 +722,16 @@ public void test_withWeek_sameWeek() { assertEquals(YearWeek.of(2014, 2).withWeek(2), YearWeek.of(2014, 2)); } + @Test(expectedExceptions = DateTimeException.class) + public void test_withWeek_int_max() { + TEST.withWeek(Integer.MAX_VALUE); + } + + @Test(expectedExceptions = DateTimeException.class) + public void test_withWeek_int_min() { + TEST.withWeek(Integer.MIN_VALUE); + } + //----------------------------------------------------------------------- // plusWeeks(long) //----------------------------------------------------------------------- @@ -734,7 +744,7 @@ public void test_plusWeeks() { assertEquals(TEST.plusWeeks(53), YearWeek.of(2016, 1)); assertEquals(TEST.plusWeeks(314), YearWeek.of(2021, 1)); } - + public void test_plusWeeks_negative() { assertEquals(TEST.plusWeeks(0), TEST); assertEquals(TEST.plusWeeks(-1), YearWeek.of(2014, 52)); @@ -744,17 +754,17 @@ public void test_plusWeeks_negative() { assertEquals(TEST.plusWeeks(-53), YearWeek.of(2013, 52)); assertEquals(TEST.plusWeeks(-261), YearWeek.of(2009, 53)); } - + @Test(expectedExceptions = ArithmeticException.class) public void test_plusWeeks_max_long() { TEST.plusWeeks(Long.MAX_VALUE); } - + @Test(expectedExceptions = DateTimeException.class) public void test_plusWeeks_min_long() { TEST.plusWeeks(Long.MIN_VALUE); } - + //----------------------------------------------------------------------- // minusWeeks(long) //----------------------------------------------------------------------- @@ -767,7 +777,7 @@ public void test_minusWeeks() { assertEquals(TEST.minusWeeks(53), YearWeek.of(2013, 52)); assertEquals(TEST.minusWeeks(261), YearWeek.of(2009, 53)); } - + public void test_minusWeeks_negative() { assertEquals(TEST.minusWeeks(0), TEST); assertEquals(TEST.minusWeeks(-1), YearWeek.of(2015, 2)); @@ -777,12 +787,12 @@ public void test_minusWeeks_negative() { assertEquals(TEST.minusWeeks(-53), YearWeek.of(2016, 1)); assertEquals(TEST.minusWeeks(-314), YearWeek.of(2021, 1)); } - + @Test(expectedExceptions = ArithmeticException.class) public void test_minWeeks_max_long() { TEST.plusWeeks(Long.MAX_VALUE); } - + @Test(expectedExceptions = DateTimeException.class) public void test_minWeeks_min_long() { TEST.plusWeeks(Long.MIN_VALUE); From b6a603fd2cce8dffebd92e7fd6f625a04e73d1c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Raupach?= Date: Thu, 11 May 2017 08:16:03 +0200 Subject: [PATCH 018/279] plusWeeks/minusWeek in YearWeek Implementation uses LocalDate and with plusWeeks/minusWeeks --- src/main/java/org/threeten/extra/YearWeek.java | 9 ++------- src/test/java/org/threeten/extra/TestYearWeek.java | 4 ++-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/threeten/extra/YearWeek.java b/src/main/java/org/threeten/extra/YearWeek.java index ee039bf2..3119c58c 100644 --- a/src/main/java/org/threeten/extra/YearWeek.java +++ b/src/main/java/org/threeten/extra/YearWeek.java @@ -487,8 +487,7 @@ public YearWeek plusWeeks(long weeksToAdd) { if (weeksToAdd == 0) { return this; } - long daysToAdd = weeksToAdd * 7; - LocalDate mondayOfWeek = atDay(DayOfWeek.MONDAY).plusDays(daysToAdd); + LocalDate mondayOfWeek = atDay(DayOfWeek.MONDAY).plusWeeks(weeksToAdd); return YearWeek.from(mondayOfWeek); } @@ -504,11 +503,7 @@ public YearWeek minusWeeks(long weeksToSubtract) { if (weeksToSubtract == 0) { return this; } - if (weeksToSubtract == 0) { - return this; - } - long daysToAdd = weeksToSubtract * 7; - LocalDate mondayOfWeek = atDay(DayOfWeek.MONDAY).minusDays(daysToAdd); + LocalDate mondayOfWeek = atDay(DayOfWeek.MONDAY).minusWeeks(weeksToSubtract); return YearWeek.from(mondayOfWeek); } diff --git a/src/test/java/org/threeten/extra/TestYearWeek.java b/src/test/java/org/threeten/extra/TestYearWeek.java index fd6af5b7..7dc675a8 100644 --- a/src/test/java/org/threeten/extra/TestYearWeek.java +++ b/src/test/java/org/threeten/extra/TestYearWeek.java @@ -760,7 +760,7 @@ public void test_plusWeeks_max_long() { TEST.plusWeeks(Long.MAX_VALUE); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expectedExceptions = ArithmeticException.class) public void test_plusWeeks_min_long() { TEST.plusWeeks(Long.MIN_VALUE); } @@ -793,7 +793,7 @@ public void test_minWeeks_max_long() { TEST.plusWeeks(Long.MAX_VALUE); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expectedExceptions = ArithmeticException.class) public void test_minWeeks_min_long() { TEST.plusWeeks(Long.MIN_VALUE); } From 11a6aa6ad5c728e360e046dbb83aff8223d05242 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 5 Jun 2017 22:57:56 +0100 Subject: [PATCH 019/279] Add YearWeek.plusYears() minusYears() --- src/changes/changes.xml | 12 +- .../java/org/threeten/extra/YearWeek.java | 104 ++++++++++++------ .../java/org/threeten/extra/TestYearWeek.java | 56 ++++++++++ 3 files changed, 135 insertions(+), 37 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index f1111faa..a205fc6b 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,10 +7,14 @@ - - - Add plusWeeks/minusWeeks to YearWeek - See #78 + + + Add plusYears/minusYears to YearWeek. + See #78. + + + Add plusWeeks/minusWeeks to YearWeek. + See #78. diff --git a/src/main/java/org/threeten/extra/YearWeek.java b/src/main/java/org/threeten/extra/YearWeek.java index 3119c58c..6bd1ad2c 100644 --- a/src/main/java/org/threeten/extra/YearWeek.java +++ b/src/main/java/org/threeten/extra/YearWeek.java @@ -473,39 +473,6 @@ public boolean is53WeekYear() { public int lengthOfYear() { return (is53WeekYear() ? 371 : 364); } - - //----------------------------------------------------------------------- - /** - * Returns a copy of this year-week with the specified number of weeks added. - * *

    - * This instance is immutable and unaffected by this method call. - * - * @param weeksToAdd the weeks to add, may be negative - * @return the year-week with the weeks added, not null - */ - public YearWeek plusWeeks(long weeksToAdd) { - if (weeksToAdd == 0) { - return this; - } - LocalDate mondayOfWeek = atDay(DayOfWeek.MONDAY).plusWeeks(weeksToAdd); - return YearWeek.from(mondayOfWeek); - } - - /** - * Returns a copy of this year-week with the specified number of weeks subtracted. - * *

    - * This instance is immutable and unaffected by this method call. - * - * @param weeksToSubtract the weeks to subtract, may be negative - * @return the year-week with the weeks subtracted, not null - */ - public YearWeek minusWeeks(long weeksToSubtract) { - if (weeksToSubtract == 0) { - return this; - } - LocalDate mondayOfWeek = atDay(DayOfWeek.MONDAY).minusWeeks(weeksToSubtract); - return YearWeek.from(mondayOfWeek); - } //----------------------------------------------------------------------- /** @@ -545,6 +512,77 @@ public YearWeek withWeek(int week) { return with(year, week); } + //----------------------------------------------------------------------- + /** + * Returns a copy of this year-week with the specified number of years added. + *

    + * If the week of this instance is 53 and the new year does not have 53 weeks, + * the week will be adjusted to be 52. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param yearsToAdd the years to add, may be negative + * @return the year-week with the years added, not null + */ + public YearWeek plusYears(long yearsToAdd) { + if (yearsToAdd == 0) { + return this; + } + int newYear = Math.toIntExact(Math.addExact(year, yearsToAdd)); + return withYear(newYear); + } + + /** + * Returns a copy of this year-week with the specified number of weeks added. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param weeksToAdd the weeks to add, may be negative + * @return the year-week with the weeks added, not null + */ + public YearWeek plusWeeks(long weeksToAdd) { + if (weeksToAdd == 0) { + return this; + } + LocalDate mondayOfWeek = atDay(DayOfWeek.MONDAY).plusWeeks(weeksToAdd); + return YearWeek.from(mondayOfWeek); + } + + /** + * Returns a copy of this year-week with the specified number of years subtracted. + *

    + * If the week of this instance is 53 and the new year does not have 53 weeks, + * the week will be adjusted to be 52. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param yearsToSubtract the years to subtract, may be negative + * @return the year-week with the years subtracted, not null + */ + public YearWeek minusYears(long yearsToSubtract) { + if (yearsToSubtract == 0) { + return this; + } + int newYear = Math.toIntExact(Math.subtractExact(year, yearsToSubtract)); + return withYear(newYear); + } + + /** + * Returns a copy of this year-week with the specified number of weeks subtracted. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param weeksToSubtract the weeks to subtract, may be negative + * @return the year-week with the weeks subtracted, not null + */ + public YearWeek minusWeeks(long weeksToSubtract) { + if (weeksToSubtract == 0) { + return this; + } + LocalDate mondayOfWeek = atDay(DayOfWeek.MONDAY).minusWeeks(weeksToSubtract); + return YearWeek.from(mondayOfWeek); + } + //----------------------------------------------------------------------- /** * Queries this year-week using the specified query. diff --git a/src/test/java/org/threeten/extra/TestYearWeek.java b/src/test/java/org/threeten/extra/TestYearWeek.java index 7dc675a8..b54b32ee 100644 --- a/src/test/java/org/threeten/extra/TestYearWeek.java +++ b/src/test/java/org/threeten/extra/TestYearWeek.java @@ -732,6 +732,34 @@ public void test_withWeek_int_min() { TEST.withWeek(Integer.MIN_VALUE); } + //----------------------------------------------------------------------- + // plusYears(long) + //----------------------------------------------------------------------- + public void test_plusYears() { + assertEquals(TEST.plusYears(-2), YearWeek.of(2013, 1)); + assertEquals(TEST.plusYears(-1), YearWeek.of(2014, 1)); + assertEquals(TEST.plusYears(0), TEST); + assertEquals(TEST.plusYears(1), YearWeek.of(2016, 1)); + assertEquals(TEST.plusYears(2), YearWeek.of(2017, 1)); + } + + public void test_plusYears_changeWeek() { + assertEquals(YearWeek.of(2015, 53).plusYears(-1), YearWeek.of(2014, 52)); + assertEquals(YearWeek.of(2015, 53).plusYears(0), YearWeek.of(2015, 53)); + assertEquals(YearWeek.of(2015, 53).plusYears(1), YearWeek.of(2016, 52)); + assertEquals(YearWeek.of(2015, 53).plusYears(5), YearWeek.of(2020, 53)); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_plusYears_max_long() { + TEST.plusYears(Long.MAX_VALUE); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_plusYears_min_long() { + TEST.plusYears(Long.MIN_VALUE); + } + //----------------------------------------------------------------------- // plusWeeks(long) //----------------------------------------------------------------------- @@ -765,6 +793,34 @@ public void test_plusWeeks_min_long() { TEST.plusWeeks(Long.MIN_VALUE); } + //----------------------------------------------------------------------- + // minusYears(long) + //----------------------------------------------------------------------- + public void test_minusYears() { + assertEquals(TEST.minusYears(-2), YearWeek.of(2017, 1)); + assertEquals(TEST.minusYears(-1), YearWeek.of(2016, 1)); + assertEquals(TEST.minusYears(0), TEST); + assertEquals(TEST.minusYears(1), YearWeek.of(2014, 1)); + assertEquals(TEST.minusYears(2), YearWeek.of(2013, 1)); + } + + public void test_minusYears_changeWeek() { + assertEquals(YearWeek.of(2015, 53).minusYears(-5), YearWeek.of(2020, 53)); + assertEquals(YearWeek.of(2015, 53).minusYears(-1), YearWeek.of(2016, 52)); + assertEquals(YearWeek.of(2015, 53).minusYears(0), YearWeek.of(2015, 53)); + assertEquals(YearWeek.of(2015, 53).minusYears(1), YearWeek.of(2014, 52)); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_minusYears_max_long() { + TEST.minusYears(Long.MAX_VALUE); + } + + @Test(expectedExceptions = ArithmeticException.class) + public void test_minusYears_min_long() { + TEST.minusYears(Long.MIN_VALUE); + } + //----------------------------------------------------------------------- // minusWeeks(long) //----------------------------------------------------------------------- From e5b33655bbdd453bc7d216b6e54d217502cc2527 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 5 Jun 2017 23:25:25 +0100 Subject: [PATCH 020/279] Release v1.2 --- README.md | 4 ++-- pom.xml | 2 +- src/changes/changes.xml | 2 +- src/site/markdown/index.md | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index fc48d5f1..b89eb573 100644 --- a/README.md +++ b/README.md @@ -17,12 +17,12 @@ Various documentation is available: ### Releases -Release 1.1 is the current release. +Release 1.2 is the current release. This release is considered stable and worthy of the 1.x tag. ThreeTen-Extra requires Java SE 8 or later and has no dependencies. -Available in the [Maven Central repository](http://search.maven.org/#artifactdetails|org.threeten|threeten-extra|1.1|jar) +Available in the [Maven Central repository](http://search.maven.org/#artifactdetails|org.threeten|threeten-extra|1.2|jar) ### Support diff --git a/pom.xml b/pom.xml index 2218b679..7b392bc3 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ threeten-extra jar ThreeTen-Extra - 1.2-SNAPSHOT + 1.2 Additional functionality that enhances JSR-310 dates and times in JDK 8 http://www.threeten.org/threeten-extra diff --git a/src/changes/changes.xml b/src/changes/changes.xml index a205fc6b..352474aa 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,7 +7,7 @@ - + Add plusYears/minusYears to YearWeek. See #78. diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index c29b0c73..48d33abd 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -47,18 +47,18 @@ Various documentation is available: ## Releases -Release 1.1 is the current release. +Release 1.2 is the current release. This release is considered stable and worthy of the 1.x tag. ThreeTen-Extra requires Java SE 8 or later and has no [dependencies](dependencies.html). -Available in [Maven Central](http://search.maven.org/#artifactdetails%7Corg.threeten%7Cthreeten-extra%7C1.1%7Cjar). +Available in [Maven Central](http://search.maven.org/#artifactdetails%7Corg.threeten%7Cthreeten-extra%7C1.2%7Cjar). ```xml org.threeten threeten-extra - 1.1 + 1.2 ``` From aeec1857e8d441d5c7123257a443861809ab2810 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 6 Jun 2017 16:58:03 +0100 Subject: [PATCH 021/279] Bump version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7b392bc3..5b4daa1a 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ threeten-extra jar ThreeTen-Extra - 1.2 + 1.3-SNAPSHOT Additional functionality that enhances JSR-310 dates and times in JDK 8 http://www.threeten.org/threeten-extra From 84248f98c8c6047fe2553d4ece0976f070fd3202 Mon Sep 17 00:00:00 2001 From: Carlo Dapor Date: Thu, 22 Jun 2017 00:29:33 +0200 Subject: [PATCH 022/279] Interval#parse accepts 4 different formats, which should be reflected in the documentation. Also, added an minimal / maximal bounds check. --- src/main/java/org/threeten/extra/Interval.java | 2 +- src/test/java/org/threeten/extra/TestInterval.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/threeten/extra/Interval.java b/src/main/java/org/threeten/extra/Interval.java index ec813637..6dcb9b91 100644 --- a/src/main/java/org/threeten/extra/Interval.java +++ b/src/main/java/org/threeten/extra/Interval.java @@ -130,7 +130,7 @@ public static Interval of(Instant startInclusive, Duration duration) { * Obtains an instance of {@code Interval} from a text string such as * {@code 2007-12-03T10:15:30Z/2007-12-04T10:15:30Z}, where the end instant is exclusive. *

    - * The string must consist of one of the following three formats: + * The string must consist of one of the following four formats: *

      *
    • a representations of an {@link OffsetDateTime}, followed by a forward slash, * followed by a representation of a {@link OffsetDateTime} diff --git a/src/test/java/org/threeten/extra/TestInterval.java b/src/test/java/org/threeten/extra/TestInterval.java index f457b8a0..2d21e0c4 100644 --- a/src/test/java/org/threeten/extra/TestInterval.java +++ b/src/test/java/org/threeten/extra/TestInterval.java @@ -45,6 +45,7 @@ import java.time.DateTimeException; import java.time.Duration; import java.time.Instant; +import java.time.OffsetDateTime; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.format.DateTimeParseException; @@ -153,6 +154,10 @@ public void test_of_Instant_Duration_nullDuration() { Interval.of(NOW1, (Duration) null); } + /* Lower and upper bound for Intervals */ + private static final Instant MIN_OFFSET_DATE_TIME = OffsetDateTime.MIN.plusDays(1L).toInstant(); + private static final Instant MAX_OFFSET_DATE_TIME = OffsetDateTime.MAX.minusDays(1L).toInstant(); + //----------------------------------------------------------------------- @DataProvider(name = "parseValid") Object[][] data_parseValid() { @@ -167,6 +172,7 @@ Object[][] data_parseValid() { {NOW1.atOffset(ZoneOffset.ofHours(2)) + "/" + NOW2.atOffset(ZoneOffset.ofHours(2)), NOW1, NOW2}, {NOW1.atOffset(ZoneOffset.ofHours(2)) + "/" + NOW2.atOffset(ZoneOffset.ofHours(3)), NOW1, NOW2}, {NOW1.atOffset(ZoneOffset.ofHours(2)) + "/" + NOW2.atOffset(ZoneOffset.ofHours(2)).toLocalDateTime(), NOW1, NOW2}, + {MIN_OFFSET_DATE_TIME.toString() + '/' + MAX_OFFSET_DATE_TIME, MIN_OFFSET_DATE_TIME, MAX_OFFSET_DATE_TIME} }; } From e87d6355515c2793f211cd12d1b4fa99b6c6e114 Mon Sep 17 00:00:00 2001 From: Michael Hixson Date: Fri, 7 Jul 2017 21:59:42 -0700 Subject: [PATCH 023/279] Add MutableClock --- .../java/org/threeten/extra/MutableClock.java | 511 ++++++++++++++++++ .../org/threeten/extra/TestMutableClock.java | 392 ++++++++++++++ 2 files changed, 903 insertions(+) create mode 100644 src/main/java/org/threeten/extra/MutableClock.java create mode 100644 src/test/java/org/threeten/extra/TestMutableClock.java diff --git a/src/main/java/org/threeten/extra/MutableClock.java b/src/main/java/org/threeten/extra/MutableClock.java new file mode 100644 index 00000000..ea9b6de2 --- /dev/null +++ b/src/main/java/org/threeten/extra/MutableClock.java @@ -0,0 +1,511 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.extra; + +import static java.time.Instant.EPOCH; +import static java.time.ZoneOffset.UTC; + +import java.io.InvalidObjectException; +import java.io.ObjectInputStream; +import java.io.Serializable; +import java.time.Clock; +import java.time.DateTimeException; +import java.time.Duration; +import java.time.Instant; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.temporal.TemporalAdjuster; +import java.time.temporal.TemporalAmount; +import java.time.temporal.TemporalField; +import java.time.temporal.TemporalUnit; +import java.time.temporal.UnsupportedTemporalTypeException; +import java.util.Objects; + +/** + * A clock that does not advance on its own and that must be updated manually. + *

      + * This class is designed for testing clock-sensitive components through + * controlled simulation of the passage of time. This class differs from {@link + * Clock#fixed(Instant, ZoneId)} and {@link Clock#offset(Clock, Duration)} in + * that it permits arbitrary, unrestricted updates to its instant. This allows + * for testing patterns that are not well-supported by the {@code fixed} and + * {@code offset} clocks such as the following pattern: + *

        + *
      1. Create the clock-sensitive component to be tested + *
      2. Verify some behavior of the component in the initial state + *
      3. Advance the clock without recreating the component + *
      4. Verify that the component behaves as expected given the (artificial) + * delta in clock time since the initial state + *
      + *

      + * This class is mutable. The time-zone of the clock is fixed, but the instant + * may be updated at will. + *

      + * The instant may be set to any value even if that new value is less than the + * previous value. Caution should be exercised when moving the clock backwards, + * since clock-sensitive components are likely to assume that time is + * monotonically increasing. + *

      + * Update semantics are expressed in terms of {@link ZonedDateTime}. The steps + * of each update are as follows: + *

        + *
      1. The clock captures its own state in a {@code ZonedDateTime} via {@link + * ZonedDateTime#now(Clock)} (or the equivalent thereof) + *
      2. The update operation is applied to that {@code ZonedDateTime}, producing + * a new {@code ZonedDateTime} + *
      3. The resulting {@code ZonedDateTime} is converted to an instant via {@link + * ZonedDateTime#toInstant()} (or the equivalent thereof) + *
      4. The clock's instant is set to that new instant + *
      + *

      + * Therefore, whenever there is a question about what argument types, units, + * fields, or values an update operation supports, or what the result will be, + * refer to the corresponding method of {@code ZonedDateTime}. Links are + * provided from the documentation of each update operation of this class to the + * corresponding method of {@code ZonedDateTime}. + *

      + * While update semantics are expressed in terms of {@code ZonedDateTime}, that + * imposes no requirements on implementation details. The implementation may + * avoid using {@code ZonedDateTime} completely or only sometimes, for + * convenience, efficiency, or any other reason. + * + *

      Implementation Requirements:

      + * This class is thread-safe. Updates are atomic and synchronized. + * + * @serial exclude + */ +public final class MutableClock + extends Clock + implements Serializable { + + /** + * Serialization version. + */ + private static final long serialVersionUID = -6152029959790119695L; + + /** + * The mutable instant of this clock. + */ + private final InstantHolder instantHolder; + + /** + * The fixed time-zone of this clock. + */ + private final ZoneId zone; + + /** + * Obtains a new {@code MutableClock} set to the epoch of + * 1970-01-01T00:00:00Z, converting to date and time using the UTC + * time-zone. + *

      + * Use this method when a {@code MutableClock} is needed and neither its + * initial value nor its time-zone are important. + * + * @return a new {@code MutableClock}, not null + */ + public static MutableClock epochUTC() { + return MutableClock.of(EPOCH, UTC); + } + + /** + * Obtains a new {@code MutableClock} set to the specified instant, + * converting to date and time using the specified time-zone. + * + * @param instant the initial value for the clock, not null + * @param zone the time-zone to use, not null + * @return a new {@code MutableClock}, not null + */ + public static MutableClock of(Instant instant, ZoneId zone) { + Objects.requireNonNull(instant, "instant"); + Objects.requireNonNull(zone, "zone"); + return new MutableClock(new InstantHolder(instant), zone); + } + + /** + * Constructor. + * + * @param instantHolder the mutable instant, validated not null + * @param zone the fixed time-zone, validated not null + */ + private MutableClock(InstantHolder instantHolder, ZoneId zone) { + this.instantHolder = instantHolder; + this.zone = zone; + } + + /** + * Overrides the instant of this clock with the specified value. + * + * @param instant the new instant for this clock, not null + */ + public void setInstant(Instant instant) { + Objects.requireNonNull(instant, "instant"); + instantHolder.set(instant); + } + + /** + * Adds the specified amount to this clock. + *

      + * Atomically updates this clock to the value of the following expression: + *

      +     *   ZonedDateTime.now(thisClock)
      +     *                .plus(amountToAdd)
      +     *                .toInstant()
      +     * 
      + * + * @param amountToAdd the amount to add, not null + * @throws DateTimeException if the addition cannot be made + * @throws ArithmeticException if numeric overflow occurs + * @see ZonedDateTime#plus(TemporalAmount) + */ + public void add(TemporalAmount amountToAdd) { + Objects.requireNonNull(amountToAdd, "amountToAdd"); + synchronized (instantHolder) { + ZonedDateTime current = ZonedDateTime.ofInstant(instantHolder.get(), zone); + ZonedDateTime result = current.plus(amountToAdd); + instantHolder.set(result.toInstant()); + } + } + + /** + * Adds the specified amount to this clock. + *

      + * Atomically updates this clock to the value of the following expression: + *

      +     *   ZonedDateTime.now(thisClock)
      +     *                .plus(amountToAdd, unit)
      +     *                .toInstant()
      +     * 
      + * + * @param amountToAdd the amount of the specified unit to add, not null + * @param unit the unit of the amount to add, not null + * @throws DateTimeException if the unit cannot be added + * @throws UnsupportedTemporalTypeException if the unit is not supported + * @throws ArithmeticException if numeric overflow occurs + * @see ZonedDateTime#plus(long, TemporalUnit) + */ + public void add(long amountToAdd, TemporalUnit unit) { + Objects.requireNonNull(unit, "unit"); + synchronized (instantHolder) { + ZonedDateTime current = ZonedDateTime.ofInstant(instantHolder.get(), zone); + ZonedDateTime result = current.plus(amountToAdd, unit); + instantHolder.set(result.toInstant()); + } + } + + /** + * Subtracts the specified amount from this clock. + *

      + * Atomically updates this clock to the value of the following expression: + *

      +     *   ZonedDateTime.now(thisClock)
      +     *                .minus(amountToSubtract)
      +     *                .toInstant()
      +     * 
      + * + * @param amountToSubtract the amount to subtract, not null + * @throws DateTimeException if the subtraction cannot be made + * @throws ArithmeticException if numeric overflow occurs + * @see ZonedDateTime#minus(TemporalAmount) + */ + public void subtract(TemporalAmount amountToSubtract) { + Objects.requireNonNull(amountToSubtract, "amountToSubtract"); + synchronized (instantHolder) { + ZonedDateTime current = ZonedDateTime.ofInstant(instantHolder.get(), zone); + ZonedDateTime result = current.minus(amountToSubtract); + instantHolder.set(result.toInstant()); + } + } + + /** + * Subtracts the specified amount from this clock. + *

      + * Atomically updates this clock to the value of the following expression: + *

      +     *   ZonedDateTime.now(thisClock)
      +     *                .minus(amountToSubtract, unit)
      +     *                .toInstant()
      +     * 
      + * + * @param amountToSubtract the amount of the specified unit to subtract, not null + * @param unit the unit of the amount to subtract, not null + * @throws DateTimeException if the unit cannot be subtracted + * @throws UnsupportedTemporalTypeException if the unit is not supported + * @throws ArithmeticException if numeric overflow occurs + * @see ZonedDateTime#minus(long, TemporalUnit) + */ + public void subtract(long amountToSubtract, TemporalUnit unit) { + Objects.requireNonNull(unit, "unit"); + synchronized (instantHolder) { + ZonedDateTime current = ZonedDateTime.ofInstant(instantHolder.get(), zone); + ZonedDateTime result = current.minus(amountToSubtract, unit); + instantHolder.set(result.toInstant()); + } + } + + /** + * Adjusts this clock. + *

      + * Atomically updates this clock to the value of the following expression: + *

      +     *   ZonedDateTime.now(thisClock)
      +     *                .with(adjuster)
      +     *                .toInstant()
      +     * 
      + * + * @param adjuster the adjuster to use, not null + * @throws DateTimeException if the adjustment cannot be made + * @throws ArithmeticException if numeric overflow occurs + * @see ZonedDateTime#with(TemporalAdjuster) + */ + public void set(TemporalAdjuster adjuster) { + Objects.requireNonNull(adjuster, "adjuster"); + synchronized (instantHolder) { + ZonedDateTime current = ZonedDateTime.ofInstant(instantHolder.get(), zone); + ZonedDateTime result = current.with(adjuster); + instantHolder.set(result.toInstant()); + } + } + + /** + * Alters the specified field of this clock. + *

      + * Atomically updates this clock to the value of the following expression: + *

      +     *   ZonedDateTime.now(thisClock)
      +     *                .with(field, newValue)
      +     *                .toInstant()
      +     * 
      + * + * @param field the field to set, not null + * @param newValue the new value of the field + * @throws DateTimeException if the field cannot be set + * @throws UnsupportedTemporalTypeException if the field is not supported + * @throws ArithmeticException if numeric overflow occurs + * @see ZonedDateTime#with(TemporalField, long) + */ + public void set(TemporalField field, long newValue) { + Objects.requireNonNull(field, "field"); + synchronized (instantHolder) { + ZonedDateTime current = ZonedDateTime.ofInstant(instantHolder.get(), zone); + ZonedDateTime result = current.with(field, newValue); + instantHolder.set(result.toInstant()); + } + } + + @Override + public ZoneId getZone() { + return zone; + } + + /** + * Returns a {@code MutableClock} that uses the specified time-zone and that + * has shared updates with this clock. + *

      + * Two clocks with shared updates always have the same instant, and all + * updates applied to either clock affect both clocks. + * + * @param zone the time-zone to use for the returned clock, not null + * @return a view of this clock in the specified time-zone, not null + */ + @Override + public MutableClock withZone(ZoneId zone) { + Objects.requireNonNull(zone, "zone"); + if (zone.equals(this.zone)) { + return this; + } + return new MutableClock(instantHolder, zone); + } + + @Override + public Instant instant() { + return instantHolder.get(); + } + + /** + * Returns {@code true} if {@code obj} is a {@code MutableClock} that uses + * the same time-zone as this clock and has shared updates with this clock. + *

      + * Two clocks with shared updates always have the same instant, and all + * updates applied to either clock affect both clocks. + *

      + * A deserialized {@code MutableClock} is not equal to the original clock + * that was serialized, since the two clocks do not have shared updates. + * + * @param obj the object to check, null returns {@code false} + * @return {@code true} if this is equal to the other clock + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof MutableClock) { + MutableClock other = (MutableClock) obj; + return instantHolder == other.instantHolder && zone.equals(other.zone); + } + return false; + } + + /** + * A hash code for this clock, which is constant for this instance. + * + * @return a constant hash code for this instance + */ + @Override + public int hashCode() { + return System.identityHashCode(instantHolder) ^ zone.hashCode(); + } + + @Override + public String toString() { + return "MutableClock[" + instant() + "," + getZone() + "]"; + } + + /** + * Returns the serialization proxy to replace this {@code MutableClock}. + * + * @return the serialization proxy, not null + */ + private Object writeReplace() { + return new SerializationProxy(this); + } + + /** + * Throws {@link InvalidObjectException}. + * + * @param s ignored + * @throws InvalidObjectException always + */ + private void readObject(ObjectInputStream s) throws InvalidObjectException { + throw new InvalidObjectException("Proxy required"); + } + + /** + * The serialized form of a {@code MutableClock}. + * + * @serial include + */ + private static final class SerializationProxy + implements Serializable { + + /** + * Serialization version. + */ + private static final long serialVersionUID = 8602110640241828260L; + + /** + * A snapshot of the instant of the {@code MutableClock}, taken when the + * clock was serialized, not null. + * + * @serial + */ + private final Instant instant; + + /** + * The time-zone of the {@code MutableClock}, not null. + * + * @serial + */ + private final ZoneId zone; + + /** + * Constructor. + * + * @param clock the {@code MutableClock} to be serialized, validated not null + */ + SerializationProxy(MutableClock clock) { + instant = clock.instant(); + zone = clock.getZone(); + } + + /** + * Returns the {@code MutableClock} to replace this serialization proxy. + * + * @return the {@code MutableClock}, not null + * @throws InvalidObjectException if the instant or time-zone is null + */ + private Object readResolve() throws InvalidObjectException { + if (instant == null) { + throw new InvalidObjectException("null instant"); + } + if (zone == null) { + throw new InvalidObjectException("null zone"); + } + return MutableClock.of(instant, zone); + } + } + + /** + * An identity-having holder object for a mutable instant value. + *

      + * Clocks have shared updates when they share a holder object. Clocks rely + * on the identity of the holder object in their {@code equals} and {@code + * hashCode} methods. + *

      + * Reads of the value are volatile and are never stale. Blind writes to the + * value are volatile and do not need to synchronize. Atomic read-and-write + * operations must synchronize on the holder object instance. + */ + private static final class InstantHolder { + /** + * The current value. + */ + private volatile Instant value; + + /** + * Constructor. + * + * @param value the initial value, validated not null + */ + InstantHolder(Instant value) { + this.value = value; + } + + /** + * Reads the value. + * + * @return the current value, not null + */ + Instant get() { + return value; + } + + /** + * Writes the value. + * + * @param value the new value, validated not null + */ + void set(Instant value) { + this.value = value; + } + } +} diff --git a/src/test/java/org/threeten/extra/TestMutableClock.java b/src/test/java/org/threeten/extra/TestMutableClock.java new file mode 100644 index 00000000..01deac1b --- /dev/null +++ b/src/test/java/org/threeten/extra/TestMutableClock.java @@ -0,0 +1,392 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.extra; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotEquals; +import static org.testng.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.time.DayOfWeek; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.Period; +import java.time.Year; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.temporal.ChronoField; +import java.time.temporal.ChronoUnit; +import java.time.temporal.TemporalAdjusters; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import org.testng.annotations.Test; + +/** + * Test class. + */ +@Test +public class TestMutableClock { + + public void test_of() { + assertEquals( + MutableClock.of(Instant.EPOCH, ZoneOffset.UTC).instant(), + Instant.EPOCH); + assertEquals( + MutableClock.of(Instant.MIN, ZoneOffset.UTC).instant(), + Instant.MIN); + assertEquals( + MutableClock.of(Instant.MAX, ZoneOffset.UTC).instant(), + Instant.MAX); + assertEquals( + MutableClock.of(Instant.EPOCH, ZoneOffset.UTC).getZone(), + ZoneOffset.UTC); + assertEquals( + MutableClock.of(Instant.EPOCH, ZoneOffset.MIN).getZone(), + ZoneOffset.MIN); + assertEquals( + MutableClock.of(Instant.EPOCH, ZoneOffset.MAX).getZone(), + ZoneOffset.MAX); + } + + @Test(expectedExceptions = NullPointerException.class) + public void test_of_nullInstant() { + MutableClock.of(null, ZoneOffset.UTC); + } + + @Test(expectedExceptions = NullPointerException.class) + public void test_of_nullZone() { + MutableClock.of(Instant.EPOCH, null); + } + + public void test_epochUTC() { + assertEquals(MutableClock.epochUTC().instant(), Instant.EPOCH); + assertEquals(MutableClock.epochUTC().getZone(), ZoneOffset.UTC); + } + + public void test_setInstant() { + MutableClock clock = MutableClock.epochUTC(); + assertEquals(clock.instant(), Instant.EPOCH); + clock.setInstant(Instant.MIN); + assertEquals(clock.instant(), Instant.MIN); + clock.setInstant(Instant.MAX); + assertEquals(clock.instant(), Instant.MAX); + clock.setInstant(Instant.EPOCH.plusSeconds(10)); + assertEquals(clock.instant(), Instant.EPOCH.plusSeconds(10)); + } + + @Test(expectedExceptions = NullPointerException.class) + public void test_setInstant_null() { + MutableClock.epochUTC().setInstant(null); + } + + public void test_add_amountOnly() { + MutableClock clock = MutableClock.epochUTC(); + clock.add(Duration.ofNanos(3)); + clock.add(Period.ofMonths(2)); + clock.add(Duration.ofSeconds(-5)); + clock.add(Period.ofWeeks(-7)); + clock.add(Duration.ZERO); + clock.add(Period.ZERO); + assertEquals( + clock.instant(), + ZonedDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC) + .plusNanos(3) + .plusMonths(2) + .minusSeconds(5) + .minusWeeks(7) + .toInstant()); + } + + @Test(expectedExceptions = NullPointerException.class) + public void test_add_amountOnly_null() { + MutableClock.epochUTC().add(null); + } + + public void test_add_amountAndUnit() { + MutableClock clock = MutableClock.epochUTC(); + clock.add(3, ChronoUnit.NANOS); + clock.add(2, ChronoUnit.MONTHS); + clock.add(-5, ChronoUnit.SECONDS); + clock.add(-7, ChronoUnit.WEEKS); + clock.add(0, ChronoUnit.MILLIS); + clock.add(0, ChronoUnit.YEARS); + assertEquals( + clock.instant(), + ZonedDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC) + .plusNanos(3) + .plusMonths(2) + .minusSeconds(5) + .minusWeeks(7) + .toInstant()); + } + + @Test(expectedExceptions = NullPointerException.class) + public void test_add_amountAndUnit_nullUnit() { + MutableClock.epochUTC().add(0, null); + } + + public void test_subtract_amountOnly() { + MutableClock clock = MutableClock.epochUTC(); + clock.subtract(Duration.ofNanos(3)); + clock.subtract(Period.ofMonths(2)); + clock.subtract(Duration.ofSeconds(-5)); + clock.subtract(Period.ofWeeks(-7)); + clock.subtract(Duration.ZERO); + clock.subtract(Period.ZERO); + assertEquals( + clock.instant(), + ZonedDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC) + .minusNanos(3) + .minusMonths(2) + .plusSeconds(5) + .plusWeeks(7) + .toInstant()); + } + + @Test(expectedExceptions = NullPointerException.class) + public void test_subtract_amountOnly_null() { + MutableClock.epochUTC().subtract(null); + } + + public void test_subtract_amountAndUnit() { + MutableClock clock = MutableClock.epochUTC(); + clock.subtract(3, ChronoUnit.NANOS); + clock.subtract(2, ChronoUnit.MONTHS); + clock.subtract(-5, ChronoUnit.SECONDS); + clock.subtract(-7, ChronoUnit.WEEKS); + clock.subtract(0, ChronoUnit.MILLIS); + clock.subtract(0, ChronoUnit.YEARS); + assertEquals( + clock.instant(), + ZonedDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC) + .minusNanos(3) + .minusMonths(2) + .plusSeconds(5) + .plusWeeks(7) + .toInstant()); + } + + @Test(expectedExceptions = NullPointerException.class) + public void test_subtract_amountAndUnit_nullUnit() { + MutableClock.epochUTC().subtract(0, null); + } + + public void test_set_adjuster() { + MutableClock clock = MutableClock.epochUTC(); + clock.set(LocalDate.of(0, 1, 2)); + clock.set(LocalTime.of(3, 4, 5)); + clock.set(TemporalAdjusters.firstDayOfNextMonth()); + clock.set(TemporalAdjusters.next(DayOfWeek.WEDNESDAY)); + assertEquals( + clock.instant(), + LocalDateTime.of(0, 1, 2, 3, 4, 5) + .with(TemporalAdjusters.firstDayOfNextMonth()) + .with(TemporalAdjusters.next(DayOfWeek.WEDNESDAY)) + .atZone(ZoneOffset.UTC) + .toInstant()); + clock.set(Instant.EPOCH); + assertEquals(clock.instant(), Instant.EPOCH); + } + + @Test(expectedExceptions = NullPointerException.class) + public void test_set_adjuster_null() { + MutableClock.epochUTC().set(null); + } + + public void test_set_fieldAndValue() { + MutableClock clock = MutableClock.epochUTC(); + clock.set(ChronoField.YEAR, 0); + clock.set(ChronoField.MONTH_OF_YEAR, 1); + clock.set(ChronoField.DAY_OF_MONTH, 2); + clock.set(ChronoField.HOUR_OF_DAY, 3); + clock.set(ChronoField.MINUTE_OF_HOUR, 4); + clock.set(ChronoField.SECOND_OF_MINUTE, 5); + assertEquals( + clock.instant(), + LocalDateTime.of(0, 1, 2, 3, 4, 5) + .atZone(ZoneOffset.UTC) + .toInstant()); + } + + @Test(expectedExceptions = NullPointerException.class) + public void test_set_fieldAndValue_nullField() { + MutableClock.epochUTC().set(null, 0); + } + + public void test_getZone() { + MutableClock clock = MutableClock.epochUTC(); + MutableClock withOtherZone = clock.withZone(ZoneOffset.MIN); + MutableClock ofOtherZone = MutableClock.of(Instant.EPOCH, ZoneOffset.MAX); + assertEquals(clock.getZone(), ZoneOffset.UTC); + assertEquals(withOtherZone.getZone(), ZoneOffset.MIN); + assertEquals(ofOtherZone.getZone(), ZoneOffset.MAX); + } + + public void test_withZone() { + MutableClock clock = MutableClock.epochUTC(); + MutableClock withOtherZone = clock.withZone(ZoneOffset.MIN); + MutableClock withSameZone = withOtherZone.withZone(ZoneOffset.UTC); + clock.setInstant(Instant.MIN); + assertEquals(withOtherZone.instant(), Instant.MIN); + assertEquals(withSameZone.instant(), Instant.MIN); + assertEquals(withOtherZone.getZone(), ZoneOffset.MIN); + assertEquals(withSameZone.getZone(), ZoneOffset.UTC); + assertNotEquals(withOtherZone, clock); + assertEquals(withSameZone, clock); + } + + @Test(expectedExceptions = NullPointerException.class) + public void test_withZone_null() { + MutableClock.epochUTC().withZone(null); + } + + public void test_instant() { + MutableClock clock = MutableClock.epochUTC(); + MutableClock withOtherZone = clock.withZone(ZoneOffset.MIN); + assertEquals(clock.instant(), Instant.EPOCH); + clock.add(Duration.ofSeconds(5)); + assertEquals(clock.instant(), Instant.EPOCH.plusSeconds(5)); + clock.setInstant(Instant.MIN); + assertEquals(clock.instant(), Instant.MIN); + assertEquals(withOtherZone.instant(), Instant.MIN); + } + + public void test_equals() { + MutableClock clock = MutableClock.epochUTC(); + MutableClock withOtherZone = clock.withZone(ZoneOffset.MIN); + MutableClock withSameZone = withOtherZone.withZone(ZoneOffset.UTC); + MutableClock independent = MutableClock.epochUTC(); + assertEquals(clock, clock); + assertNotEquals(null, clock); + assertNotEquals("", clock); + assertNotEquals(withOtherZone, clock); + assertEquals(withSameZone, clock); + assertNotEquals(independent, clock); + } + + public void test_hashCode_isConstant() { + MutableClock clock = MutableClock.epochUTC(); + int hash = clock.hashCode(); + clock.add(Period.ofMonths(1)); + assertEquals(clock.hashCode(), hash); + clock.add(1, ChronoUnit.DAYS); + assertEquals(clock.hashCode(), hash); + clock.subtract(Duration.ofSeconds(1)); + assertEquals(clock.hashCode(), hash); + clock.subtract(1, ChronoUnit.HOURS); + assertEquals(clock.hashCode(), hash); + clock.set(Year.of(2000)); + assertEquals(clock.hashCode(), hash); + clock.set(ChronoField.INSTANT_SECONDS, -1); + assertEquals(clock.hashCode(), hash); + } + + public void test_hashCode_sameWhenSharedUpdates() { + MutableClock clock = MutableClock.epochUTC(); + MutableClock withOtherZone = clock.withZone(ZoneOffset.MIN); + MutableClock withSameZone = withOtherZone.withZone(ZoneOffset.UTC); + assertEquals(clock.hashCode(), withSameZone.hashCode()); + } + + public void test_toString() { + MutableClock clock = MutableClock.epochUTC(); + assertEquals( + clock.toString(), + "MutableClock[1970-01-01T00:00:00Z,Z]"); + clock.add(Period.ofYears(30)); + assertEquals( + clock.toString(), + "MutableClock[2000-01-01T00:00:00Z,Z]"); + MutableClock withOtherZone = clock.withZone(ZoneOffset.MIN); + assertEquals( + withOtherZone.toString(), + "MutableClock[2000-01-01T00:00:00Z,-18:00]"); + } + + public void test_isSerializable() { + assertTrue(Serializable.class.isAssignableFrom(MutableClock.class)); + } + + public void test_serialization() throws Exception { + MutableClock original = MutableClock.epochUTC(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream out = new ObjectOutputStream(baos); + out.writeObject(original); + out.close(); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ObjectInputStream in = new ObjectInputStream(bais); + MutableClock ser = (MutableClock) in.readObject(); + assertEquals(ser.instant(), original.instant()); + assertEquals(ser.getZone(), original.getZone()); + // no shared updates + assertNotEquals(ser, original); + original.add(Duration.ofSeconds(1)); + assertNotEquals(ser.instant(), original.instant()); + } + + public void test_updatesAreAtomic() throws Exception { + MutableClock clock = MutableClock.epochUTC(); + Duration increment = Duration.ofSeconds(1); + Callable applyOneUpdate = () -> { + clock.add(increment); + return null; + }; + int updateCount = 10000; + List> tasks = Collections.nCopies(updateCount, applyOneUpdate); + int threads = Runtime.getRuntime().availableProcessors() * 4; + ExecutorService service = Executors.newFixedThreadPool(threads); + try { + service.invokeAll(tasks); + service.shutdown(); + service.awaitTermination(1, TimeUnit.MINUTES); + } finally { + if (!service.isTerminated()) { + service.shutdownNow(); + } + } + assertEquals( + clock.instant(), + Instant.EPOCH.plus(increment.multipliedBy(updateCount))); + } +} From b878b85ad1d9e13bd2b4d1c438449e191a60a3b9 Mon Sep 17 00:00:00 2001 From: Michael Hixson Date: Sat, 8 Jul 2017 07:00:30 -0700 Subject: [PATCH 024/279] Remove the MutableClock.subtract* instance methods --- .../java/org/threeten/extra/MutableClock.java | 52 +------------------ .../org/threeten/extra/TestMutableClock.java | 50 ------------------ 2 files changed, 1 insertion(+), 101 deletions(-) diff --git a/src/main/java/org/threeten/extra/MutableClock.java b/src/main/java/org/threeten/extra/MutableClock.java index ea9b6de2..d38e9bdc 100644 --- a/src/main/java/org/threeten/extra/MutableClock.java +++ b/src/main/java/org/threeten/extra/MutableClock.java @@ -205,7 +205,7 @@ public void add(TemporalAmount amountToAdd) { * .toInstant() *

    * - * @param amountToAdd the amount of the specified unit to add, not null + * @param amountToAdd the amount of the specified unit to add, may be negative * @param unit the unit of the amount to add, not null * @throws DateTimeException if the unit cannot be added * @throws UnsupportedTemporalTypeException if the unit is not supported @@ -221,56 +221,6 @@ public void add(long amountToAdd, TemporalUnit unit) { } } - /** - * Subtracts the specified amount from this clock. - *

    - * Atomically updates this clock to the value of the following expression: - *

    -     *   ZonedDateTime.now(thisClock)
    -     *                .minus(amountToSubtract)
    -     *                .toInstant()
    -     * 
    - * - * @param amountToSubtract the amount to subtract, not null - * @throws DateTimeException if the subtraction cannot be made - * @throws ArithmeticException if numeric overflow occurs - * @see ZonedDateTime#minus(TemporalAmount) - */ - public void subtract(TemporalAmount amountToSubtract) { - Objects.requireNonNull(amountToSubtract, "amountToSubtract"); - synchronized (instantHolder) { - ZonedDateTime current = ZonedDateTime.ofInstant(instantHolder.get(), zone); - ZonedDateTime result = current.minus(amountToSubtract); - instantHolder.set(result.toInstant()); - } - } - - /** - * Subtracts the specified amount from this clock. - *

    - * Atomically updates this clock to the value of the following expression: - *

    -     *   ZonedDateTime.now(thisClock)
    -     *                .minus(amountToSubtract, unit)
    -     *                .toInstant()
    -     * 
    - * - * @param amountToSubtract the amount of the specified unit to subtract, not null - * @param unit the unit of the amount to subtract, not null - * @throws DateTimeException if the unit cannot be subtracted - * @throws UnsupportedTemporalTypeException if the unit is not supported - * @throws ArithmeticException if numeric overflow occurs - * @see ZonedDateTime#minus(long, TemporalUnit) - */ - public void subtract(long amountToSubtract, TemporalUnit unit) { - Objects.requireNonNull(unit, "unit"); - synchronized (instantHolder) { - ZonedDateTime current = ZonedDateTime.ofInstant(instantHolder.get(), zone); - ZonedDateTime result = current.minus(amountToSubtract, unit); - instantHolder.set(result.toInstant()); - } - } - /** * Adjusts this clock. *

    diff --git a/src/test/java/org/threeten/extra/TestMutableClock.java b/src/test/java/org/threeten/extra/TestMutableClock.java index 01deac1b..10aae154 100644 --- a/src/test/java/org/threeten/extra/TestMutableClock.java +++ b/src/test/java/org/threeten/extra/TestMutableClock.java @@ -166,52 +166,6 @@ public void test_add_amountAndUnit_nullUnit() { MutableClock.epochUTC().add(0, null); } - public void test_subtract_amountOnly() { - MutableClock clock = MutableClock.epochUTC(); - clock.subtract(Duration.ofNanos(3)); - clock.subtract(Period.ofMonths(2)); - clock.subtract(Duration.ofSeconds(-5)); - clock.subtract(Period.ofWeeks(-7)); - clock.subtract(Duration.ZERO); - clock.subtract(Period.ZERO); - assertEquals( - clock.instant(), - ZonedDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC) - .minusNanos(3) - .minusMonths(2) - .plusSeconds(5) - .plusWeeks(7) - .toInstant()); - } - - @Test(expectedExceptions = NullPointerException.class) - public void test_subtract_amountOnly_null() { - MutableClock.epochUTC().subtract(null); - } - - public void test_subtract_amountAndUnit() { - MutableClock clock = MutableClock.epochUTC(); - clock.subtract(3, ChronoUnit.NANOS); - clock.subtract(2, ChronoUnit.MONTHS); - clock.subtract(-5, ChronoUnit.SECONDS); - clock.subtract(-7, ChronoUnit.WEEKS); - clock.subtract(0, ChronoUnit.MILLIS); - clock.subtract(0, ChronoUnit.YEARS); - assertEquals( - clock.instant(), - ZonedDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC) - .minusNanos(3) - .minusMonths(2) - .plusSeconds(5) - .plusWeeks(7) - .toInstant()); - } - - @Test(expectedExceptions = NullPointerException.class) - public void test_subtract_amountAndUnit_nullUnit() { - MutableClock.epochUTC().subtract(0, null); - } - public void test_set_adjuster() { MutableClock clock = MutableClock.epochUTC(); clock.set(LocalDate.of(0, 1, 2)); @@ -312,10 +266,6 @@ public void test_hashCode_isConstant() { assertEquals(clock.hashCode(), hash); clock.add(1, ChronoUnit.DAYS); assertEquals(clock.hashCode(), hash); - clock.subtract(Duration.ofSeconds(1)); - assertEquals(clock.hashCode(), hash); - clock.subtract(1, ChronoUnit.HOURS); - assertEquals(clock.hashCode(), hash); clock.set(Year.of(2000)); assertEquals(clock.hashCode(), hash); clock.set(ChronoField.INSTANT_SECONDS, -1); From e2ca3abb761488f9dc2d9de1d9a66e68bb8902da Mon Sep 17 00:00:00 2001 From: Michael Hixson Date: Sat, 8 Jul 2017 13:09:08 -0700 Subject: [PATCH 025/279] Make minor tweaks to MutableClock's javadocs --- .../java/org/threeten/extra/MutableClock.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/threeten/extra/MutableClock.java b/src/main/java/org/threeten/extra/MutableClock.java index d38e9bdc..433cbe39 100644 --- a/src/main/java/org/threeten/extra/MutableClock.java +++ b/src/main/java/org/threeten/extra/MutableClock.java @@ -53,8 +53,8 @@ /** * A clock that does not advance on its own and that must be updated manually. *

    - * This class is designed for testing clock-sensitive components through - * controlled simulation of the passage of time. This class differs from {@link + * This class is designed for testing clock-sensitive components by simulating + * the passage of time. This class differs from {@link * Clock#fixed(Instant, ZoneId)} and {@link Clock#offset(Clock, Duration)} in * that it permits arbitrary, unrestricted updates to its instant. This allows * for testing patterns that are not well-supported by the {@code fixed} and @@ -92,15 +92,15 @@ * refer to the corresponding method of {@code ZonedDateTime}. Links are * provided from the documentation of each update operation of this class to the * corresponding method of {@code ZonedDateTime}. + * + *

    Implementation Requirements:

    + * This class is thread-safe. Updates are atomic and synchronized. *

    * While update semantics are expressed in terms of {@code ZonedDateTime}, that * imposes no requirements on implementation details. The implementation may * avoid using {@code ZonedDateTime} completely or only sometimes, for * convenience, efficiency, or any other reason. * - *

    Implementation Requirements:

    - * This class is thread-safe. Updates are atomic and synchronized. - * * @serial exclude */ public final class MutableClock @@ -128,7 +128,9 @@ public final class MutableClock * time-zone. *

    * Use this method when a {@code MutableClock} is needed and neither its - * initial value nor its time-zone are important. + * initial value nor its time-zone are important. This is often true when + * testing behavior that depends on elapsed relative time rather + * than absolute time. * * @return a new {@code MutableClock}, not null */ @@ -390,7 +392,7 @@ private static final class SerializationProxy /** * Constructor. * - * @param clock the {@code MutableClock} to be serialized, validated not null + * @param clock the {@code MutableClock} to be serialized, not null */ SerializationProxy(MutableClock clock) { instant = clock.instant(); From cfc50be654358b05a8f7511f117ee22e35efb464 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 10 Jul 2017 21:18:34 +0100 Subject: [PATCH 026/279] Update after PR --- pom.xml | 4 ++++ src/changes/changes.xml | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/pom.xml b/pom.xml index 5b4daa1a..e7a0ef6d 100644 --- a/pom.xml +++ b/pom.xml @@ -45,6 +45,10 @@ Christian Heinemann https://github.com/cheinema + + Michael Hixson + https://github.com/michaelhixson + Stephen A. Imhoff https://github.com/Clockwork-Muse diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 352474aa..33860114 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,6 +7,12 @@ + + + Add MutableClock. + See #83, #84. + + Add plusYears/minusYears to YearWeek. From 8e4418fb2f7c53e4ba9fb50ae7e0f70fec36dd53 Mon Sep 17 00:00:00 2001 From: Carlo Dapor Date: Sun, 26 Nov 2017 12:20:58 +0100 Subject: [PATCH 027/279] YearWeek calculation slightly incorrect for leap years involving the last week of the year This PR fixes and closes #86. --- .../java/org/threeten/extra/YearWeek.java | 8 +++- .../java/org/threeten/extra/TestYearWeek.java | 47 ++++++++++--------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/threeten/extra/YearWeek.java b/src/main/java/org/threeten/extra/YearWeek.java index 6bd1ad2c..dd8b1439 100644 --- a/src/main/java/org/threeten/extra/YearWeek.java +++ b/src/main/java/org/threeten/extra/YearWeek.java @@ -222,7 +222,7 @@ public static YearWeek from(TemporalAccessor temporal) { } Objects.requireNonNull(temporal, "temporal"); try { - if (IsoChronology.INSTANCE.equals(Chronology.from(temporal)) == false) { + if (!IsoChronology.INSTANCE.equals(Chronology.from(temporal))) { temporal = LocalDate.from(temporal); } return of(temporal.get(WEEK_BASED_YEAR), (int) temporal.getLong(WEEK_OF_WEEK_BASED_YEAR)); @@ -640,7 +640,7 @@ public R query(TemporalQuery query) { */ @Override public Temporal adjustInto(Temporal temporal) { - if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) { + if (!Chronology.from(temporal).equals(IsoChronology.INSTANCE)) { throw new DateTimeException("Adjustment only supported on ISO date-time"); } return temporal.with(WEEK_BASED_YEAR, year).with(WEEK_OF_WEEK_BASED_YEAR, week); @@ -678,6 +678,10 @@ public LocalDate atDay(DayOfWeek dayOfWeek) { Objects.requireNonNull(dayOfWeek, "dayOfWeek"); int correction = LocalDate.of(year, 1, 4).getDayOfWeek().getValue() + 3; int dayOfYear = week * 7 + dayOfWeek.getValue() - correction; + int maxDaysOfYear = Year.isLeap(year) ? 366 : 365; + if (dayOfYear > maxDaysOfYear) { + return LocalDate.ofYearDay(year + 1, dayOfYear - maxDaysOfYear); + } if (dayOfYear > 0) { return LocalDate.ofYearDay(year, dayOfYear); } else { diff --git a/src/test/java/org/threeten/extra/TestYearWeek.java b/src/test/java/org/threeten/extra/TestYearWeek.java index b54b32ee..02f138de 100644 --- a/src/test/java/org/threeten/extra/TestYearWeek.java +++ b/src/test/java/org/threeten/extra/TestYearWeek.java @@ -255,28 +255,33 @@ Object[][] provider_53WeekYear() { @DataProvider(name = "sampleAtDay") Object[][] provider_sampleAtDay() { return new Object[][]{ - {2014, 52, MONDAY, 2014, 12, 22}, - {2014, 52, TUESDAY, 2014, 12, 23}, + {2014, 52, MONDAY, 2014, 12, 22}, + {2014, 52, TUESDAY, 2014, 12, 23}, {2014, 52, WEDNESDAY, 2014, 12, 24}, - {2014, 52, THURSDAY, 2014, 12, 25}, - {2014, 52, FRIDAY, 2014, 12, 26}, - {2014, 52, SATURDAY, 2014, 12, 27}, - {2014, 52, SUNDAY, 2014, 12, 28}, - {2015, 1, MONDAY, 2014, 12, 29}, - {2015, 1, TUESDAY, 2014, 12, 30}, - {2015, 1, WEDNESDAY, 2014, 12, 31}, - {2015, 1, THURSDAY, 2015, 1, 1}, - {2015, 1, FRIDAY, 2015, 1, 2}, - {2015, 1, SATURDAY, 2015, 1, 3}, - {2015, 1, SUNDAY, 2015, 1, 4}, - {2017, 1, MONDAY, 2017, 1, 2}, - {2017, 1, TUESDAY, 2017, 1, 3}, - {2017, 1, WEDNESDAY, 2017, 1, 4}, - {2017, 1, THURSDAY, 2017, 1, 5}, - {2017, 1, FRIDAY, 2017, 1, 6}, - {2017, 1, SATURDAY, 2017, 1, 7}, - {2017, 1, SUNDAY, 2017, 1, 8}, - {2025, 1, MONDAY, 2024, 12, 30} + {2014, 52, THURSDAY, 2014, 12, 25}, + {2014, 52, FRIDAY, 2014, 12, 26}, + {2014, 52, SATURDAY, 2014, 12, 27}, + {2014, 52, SUNDAY, 2014, 12, 28}, + {2015, 1, MONDAY, 2014, 12, 29}, + {2015, 1, TUESDAY, 2014, 12, 30}, + {2015, 1, WEDNESDAY, 2014, 12, 31}, + {2015, 1, THURSDAY, 2015, 1, 1}, + {2015, 1, FRIDAY, 2015, 1, 2}, + {2015, 1, SATURDAY, 2015, 1, 3}, + {2015, 1, SUNDAY, 2015, 1, 4}, + {2015, 53, FRIDAY, 2016, 1, 1}, + {2015, 53, SATURDAY, 2016, 1, 2}, + {2015, 53, SUNDAY, 2016, 1, 3}, + {2016, 1, MONDAY, 2016, 1, 4}, + {2016, 52, SUNDAY, 2017, 1, 1}, + {2017, 1, MONDAY, 2017, 1, 2}, + {2017, 1, TUESDAY, 2017, 1, 3}, + {2017, 1, WEDNESDAY, 2017, 1, 4}, + {2017, 1, THURSDAY, 2017, 1, 5}, + {2017, 1, FRIDAY, 2017, 1, 6}, + {2017, 1, SATURDAY, 2017, 1, 7}, + {2017, 1, SUNDAY, 2017, 1, 8}, + {2025, 1, MONDAY, 2024, 12, 30}, }; } From b07008fa55d413a7db97c0e36a3f2407f9b595b4 Mon Sep 17 00:00:00 2001 From: Carlo Dapor Date: Sun, 26 Nov 2017 13:05:49 +0100 Subject: [PATCH 028/279] prerequisite tag reserved for maven-plugin projects When building this project, a warning is issues at the beginning: ```log [INFO] Scanning for projects... [WARNING] The project org.threeten:threeten-extra:jar:1.3-SNAPSHOT uses prerequisites which is only intended for maven-plugin projects but not for non maven-plugin projects. For such purposes you should use the maven-enforcer-plugin. See https://maven.apache.org/enforcer/enforcer-rules/requireMavenVersion.html ``` The mentioned maven-enforcer-plugin achieves the same purpose, just for NON maven-plugin projects. --- pom.xml | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index e7a0ef6d..7a84eea2 100644 --- a/pom.xml +++ b/pom.xml @@ -102,6 +102,25 @@ + + org.apache.maven.plugins + maven-enforcer-plugin + + + enforce-maven + + enforce + + + + + 3.0.4 + + + + + + org.apache.maven.plugins maven-checkstyle-plugin @@ -277,6 +296,11 @@ maven-dependency-plugin ${maven-dependency-plugin.version} + + org.apache.maven.plugins + maven-enforcer-plugin + ${maven-enforcer-plugin.version} + org.apache.maven.plugins maven-gpg-plugin @@ -394,9 +418,6 @@ - - 3.0.4 - com.google.guava @@ -592,6 +613,7 @@ 3.3 2.8.2 2.10 + 3.0.0-M1 1.6 2.5.2 2.6 From f955f0cadf4995fe360744e26803e970f4d7a075 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 26 Nov 2017 15:33:19 +0000 Subject: [PATCH 029/279] Ensure that Interval parser covers MIN/MAX Special cases for Instant.MIN/MAX Fixes #80 --- .../java/org/threeten/extra/Interval.java | 100 +++++++++++++----- .../java/org/threeten/extra/TestInterval.java | 11 +- 2 files changed, 83 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/threeten/extra/Interval.java b/src/main/java/org/threeten/extra/Interval.java index 6dcb9b91..adc2d375 100644 --- a/src/main/java/org/threeten/extra/Interval.java +++ b/src/main/java/org/threeten/extra/Interval.java @@ -37,6 +37,7 @@ import java.time.Instant; import java.time.LocalDateTime; import java.time.OffsetDateTime; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.time.temporal.TemporalAccessor; @@ -153,38 +154,83 @@ public static Interval parse(CharSequence text) { Objects.requireNonNull(text, "text"); for (int i = 0; i < text.length(); i++) { if (text.charAt(i) == '/') { - char firstChar = text.charAt(0); - if (firstChar == 'P' || firstChar == 'p') { - // duration followed by instant - PeriodDuration amount = PeriodDuration.parse(text.subSequence(0, i)); - OffsetDateTime end = OffsetDateTime.parse(text.subSequence(i + 1, text.length())); - return Interval.of(end.minus(amount).toInstant(), end.toInstant()); - } else { - // instant followed by instant or duration - OffsetDateTime start = OffsetDateTime.parse(text.subSequence(0, i)); - if (i + 1 < text.length()) { - char c = text.charAt(i + 1); - if (c == 'P' || c == 'p') { - PeriodDuration amount = PeriodDuration.parse(text.subSequence(i + 1, text.length())); - return Interval.of(start.toInstant(), start.plus(amount).toInstant()); - } - } - // infer offset from start if not specified by end - String remStr = text.subSequence(i + 1, text.length()).toString(); - TemporalAccessor temporal = DateTimeFormatter.ISO_DATE_TIME.parseBest(remStr, OffsetDateTime::from, LocalDateTime::from); - if (temporal instanceof OffsetDateTime) { - OffsetDateTime odt = (OffsetDateTime) temporal; - return Interval.of(start.toInstant(), odt.toInstant()); - } else { - LocalDateTime ldt = (LocalDateTime) temporal; - return Interval.of(start.toInstant(), ldt.toInstant(start.getOffset())); - } - } + return parseSplit(text.subSequence(0, i), text.subSequence(i + 1, text.length())); } } throw new DateTimeParseException("Interval cannot be parsed, no forward slash found", text, 0); } + private static Interval parseSplit(CharSequence startStr, CharSequence endStr) { + char firstChar = startStr.charAt(0); + if (firstChar == 'P' || firstChar == 'p') { + // duration followed by instant + PeriodDuration amount = PeriodDuration.parse(startStr); + try { + OffsetDateTime end = OffsetDateTime.parse(endStr); + return Interval.of(end.minus(amount).toInstant(), end.toInstant()); + } catch (DateTimeParseException ex) { + // handle case where Instant is outside the bounds of OffsetDateTime + Instant end = Instant.parse(endStr); + // addition of PeriodDuration only supported by OffsetDateTime, + // but to make that work need to move point being subtracted from closer to EPOCH + long move = end.isBefore(Instant.EPOCH) ? 1000 * 86400 : -1000 * 86400; + Instant start = end.plusSeconds(move).atOffset(ZoneOffset.UTC).minus(amount).toInstant().minusSeconds(move); + return Interval.of(start, end); + } + } + // instant followed by instant or duration + OffsetDateTime start; + try { + start = OffsetDateTime.parse(startStr); + } catch (DateTimeParseException ex) { + return parseStartExtended(startStr, endStr); + } + if (endStr.length() > 0) { + char c = endStr.charAt(0); + if (c == 'P' || c == 'p') { + PeriodDuration amount = PeriodDuration.parse(endStr); + return Interval.of(start.toInstant(), start.plus(amount).toInstant()); + } + } + return parseEndDateTime(start.toInstant(), start.getOffset(), endStr); + } + + // handle case where Instant is outside the bounds of OffsetDateTime + private static Interval parseStartExtended(CharSequence startStr, CharSequence endStr) { + Instant start = Instant.parse(startStr); + if (endStr.length() > 0) { + char c = endStr.charAt(0); + if (c == 'P' || c == 'p') { + PeriodDuration amount = PeriodDuration.parse(endStr); + // addition of PeriodDuration only supported by OffsetDateTime, + // but to make that work need to move point being added to closer to EPOCH + long move = start.isBefore(Instant.EPOCH) ? 1000 * 86400 : -1000 * 86400; + Instant end = start.plusSeconds(move).atOffset(ZoneOffset.UTC).plus(amount).toInstant().minusSeconds(move); + return Interval.of(start, end); + } + } + // infer offset from start if not specified by end + return parseEndDateTime(start, ZoneOffset.UTC, endStr); + } + + // parse when there are two date-times + private static Interval parseEndDateTime(Instant start, ZoneOffset offset, CharSequence endStr) { + try { + TemporalAccessor temporal = DateTimeFormatter.ISO_DATE_TIME.parseBest(endStr, OffsetDateTime::from, LocalDateTime::from); + if (temporal instanceof OffsetDateTime) { + OffsetDateTime odt = (OffsetDateTime) temporal; + return Interval.of(start, odt.toInstant()); + } else { + // infer offset from start if not specified by end + LocalDateTime ldt = (LocalDateTime) temporal; + return Interval.of(start, ldt.toInstant(offset)); + } + } catch (DateTimeParseException ex) { + Instant end = Instant.parse(endStr); + return Interval.of(start, end); + } + } + //----------------------------------------------------------------------- /** * Constructor. diff --git a/src/test/java/org/threeten/extra/TestInterval.java b/src/test/java/org/threeten/extra/TestInterval.java index 2d21e0c4..9f9a7d0b 100644 --- a/src/test/java/org/threeten/extra/TestInterval.java +++ b/src/test/java/org/threeten/extra/TestInterval.java @@ -161,18 +161,27 @@ public void test_of_Instant_Duration_nullDuration() { //----------------------------------------------------------------------- @DataProvider(name = "parseValid") Object[][] data_parseValid() { + Instant minPlusOneDay = Instant.MIN.plus(Duration.ofDays(1)); + Instant maxMinusOneDay = Instant.MAX.minus(Duration.ofDays(1)); return new Object[][] { {NOW1 + "/" + NOW2, NOW1, NOW2}, {Duration.ofHours(6) + "/" + NOW2, NOW2.minus(6, HOURS), NOW2}, {"P6MT5H/" + NOW2, NOW2.atZone(ZoneOffset.UTC).minus(6, MONTHS).minus(5, HOURS).toInstant(), NOW2}, {"pt6h/" + NOW2, NOW2.minus(6, HOURS), NOW2}, + {"pt6h/" + Instant.MAX, Instant.MAX.minus(6, HOURS), Instant.MAX}, + {"pt6h/" + minPlusOneDay, minPlusOneDay.minus(6, HOURS), minPlusOneDay}, {NOW1 + "/" + Duration.ofHours(6), NOW1, NOW1.plus(6, HOURS)}, {NOW1 + "/pt6h", NOW1, NOW1.plus(6, HOURS)}, + {Instant.MIN + "/pt6h", Instant.MIN, Instant.MIN.plus(6, HOURS)}, + {maxMinusOneDay + "/Pt6h", maxMinusOneDay, maxMinusOneDay.plus(6, HOURS)}, {NOW1 + "/" + NOW1, NOW1, NOW1}, {NOW1.atOffset(ZoneOffset.ofHours(2)) + "/" + NOW2.atOffset(ZoneOffset.ofHours(2)), NOW1, NOW2}, {NOW1.atOffset(ZoneOffset.ofHours(2)) + "/" + NOW2.atOffset(ZoneOffset.ofHours(3)), NOW1, NOW2}, {NOW1.atOffset(ZoneOffset.ofHours(2)) + "/" + NOW2.atOffset(ZoneOffset.ofHours(2)).toLocalDateTime(), NOW1, NOW2}, - {MIN_OFFSET_DATE_TIME.toString() + '/' + MAX_OFFSET_DATE_TIME, MIN_OFFSET_DATE_TIME, MAX_OFFSET_DATE_TIME} + {MIN_OFFSET_DATE_TIME.toString() + "/" + MAX_OFFSET_DATE_TIME, MIN_OFFSET_DATE_TIME, MAX_OFFSET_DATE_TIME}, + {NOW1 + "/" + Instant.MAX, NOW1, Instant.MAX}, + {Instant.MIN.toString() + "/" + NOW2, Instant.MIN, NOW2}, + {Instant.MIN.toString() + "/" + Instant.MAX, Instant.MIN, Instant.MAX} }; } From 927168febfe6e80e661bb178becd5b0a4e172f3b Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 26 Nov 2017 15:42:50 +0000 Subject: [PATCH 030/279] Update changes.xml --- src/changes/changes.xml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 33860114..f67cc7ac 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,7 +7,15 @@ - + + + Interval.parse now handles Instant.MIN/MAX. + See #80. + + + YearWeek.atDay now correctly handles the end of the year. + See #87. + Add MutableClock. See #83, #84. From 118b55dfd0c5f284f52a923188e5287d85aae317 Mon Sep 17 00:00:00 2001 From: "Bruno P. Kinoshita" Date: Fri, 5 Jan 2018 12:14:32 +1300 Subject: [PATCH 031/279] Update Interval javadocs and an exception message --- src/main/java/org/threeten/extra/Interval.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/threeten/extra/Interval.java b/src/main/java/org/threeten/extra/Interval.java index adc2d375..1fad1368 100644 --- a/src/main/java/org/threeten/extra/Interval.java +++ b/src/main/java/org/threeten/extra/Interval.java @@ -99,7 +99,7 @@ public static Interval of(Instant startInclusive, Instant endExclusive) { Objects.requireNonNull(startInclusive, "startInclusive"); Objects.requireNonNull(endExclusive, "endExclusive"); if (endExclusive.isBefore(startInclusive)) { - throw new DateTimeException("End instant must on or after start instant"); + throw new DateTimeException("End instant must be equal or after start instant"); } return new Interval(startInclusive, endExclusive); } @@ -477,7 +477,7 @@ public Interval span(Interval other) { /** * Checks if this interval is after the specified instant. *

    - * The result is true if the this instant starts after the specified instant. + * The result is true if this instant starts after the specified instant. * An empty interval behaves as though it is an instant for comparison purposes. * * @param instant the other instant to compare to, not null @@ -490,7 +490,7 @@ public boolean isAfter(Instant instant) { /** * Checks if this interval is before the specified instant. *

    - * The result is true if the this instant ends before the specified instant. + * The result is true if this instant ends before the specified instant. * Since intervals do not include their end points, this will return true if the * instant equals the end of the interval. * An empty interval behaves as though it is an instant for comparison purposes. @@ -506,7 +506,7 @@ public boolean isBefore(Instant instant) { /** * Checks if this interval is after the specified interval. *

    - * The result is true if the this instant starts after the end of the specified interval. + * The result is true if this instant starts after the end of the specified interval. * Since intervals do not include their end points, this will return true if the * instant equals the end of the interval. * An empty interval behaves as though it is an instant for comparison purposes. @@ -521,7 +521,7 @@ public boolean isAfter(Interval interval) { /** * Checks if this interval is before the specified interval. *

    - * The result is true if the this instant ends before the start of the specified interval. + * The result is true if this instant ends before the start of the specified interval. * Since intervals do not include their end points, this will return true if the * two intervals abut. * An empty interval behaves as though it is an instant for comparison purposes. From ddf6a10b5522ca0d680073c5a36221015faa89d6 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 8 Jan 2018 10:42:42 +0000 Subject: [PATCH 032/279] Update after PR --- pom.xml | 4 ++++ src/changes/changes.xml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/pom.xml b/pom.xml index 7a84eea2..e9f4913e 100644 --- a/pom.xml +++ b/pom.xml @@ -53,6 +53,10 @@ Stephen A. Imhoff https://github.com/Clockwork-Muse + + Bruno P. Kinoshita + https://github.com/kinow + Steven McCoy https://github.com/steve-o diff --git a/src/changes/changes.xml b/src/changes/changes.xml index f67cc7ac..6ebe99fc 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -8,6 +8,10 @@ + + Error message and Javadoc fixes in Interval. + See #89. + Interval.parse now handles Instant.MIN/MAX. See #80. From a23e68842b35271246196f4357258a113671a321 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 8 Jan 2018 11:19:21 +0000 Subject: [PATCH 033/279] Additional test for YearWeek See #87 See #90 --- .../java/org/threeten/extra/TestYearWeek.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/org/threeten/extra/TestYearWeek.java b/src/test/java/org/threeten/extra/TestYearWeek.java index 02f138de..906e48e0 100644 --- a/src/test/java/org/threeten/extra/TestYearWeek.java +++ b/src/test/java/org/threeten/extra/TestYearWeek.java @@ -447,6 +447,21 @@ public void test_atDay(int weekBasedYear, int weekOfWeekBasedYear, DayOfWeek day assertEquals(actual, expected); } + @Test + public void test_atDay_loop20years() { + YearWeek yearWeek = YearWeek.of(1998, 51); + LocalDate expected = LocalDate.of(1998, 12, 14); + for (int i = 0; i < (20 * 53); i++) { + for (int j = 1; j <= 7; j++) { + DayOfWeek dow = DayOfWeek.of(j); + LocalDate actual = yearWeek.atDay(dow); + assertEquals(actual, expected); + expected = expected.plusDays(1); + } + yearWeek = yearWeek.plusWeeks(1); + } + } + @Test(expectedExceptions = NullPointerException.class) public void test_atDay_null() { TEST.atDay(null); From f0734c484e439ba363278c676af290d272b43c9a Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 8 Jan 2018 11:34:27 +0000 Subject: [PATCH 034/279] Fix broken Javadoc links --- .../java/org/threeten/extra/chrono/AccountingChronology.java | 3 ++- .../org/threeten/extra/chrono/BritishCutoverChronology.java | 3 ++- .../java/org/threeten/extra/chrono/CopticChronology.java | 5 +++-- .../java/org/threeten/extra/chrono/DiscordianChronology.java | 3 ++- .../java/org/threeten/extra/chrono/EthiopicChronology.java | 5 +++-- .../threeten/extra/chrono/InternationalFixedChronology.java | 3 ++- .../java/org/threeten/extra/chrono/JulianChronology.java | 3 ++- src/main/java/org/threeten/extra/chrono/PaxChronology.java | 3 ++- .../org/threeten/extra/chrono/Symmetry010Chronology.java | 3 ++- .../org/threeten/extra/chrono/Symmetry454Chronology.java | 3 ++- 10 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/threeten/extra/chrono/AccountingChronology.java b/src/main/java/org/threeten/extra/chrono/AccountingChronology.java index 3def5e1a..7fba51dc 100644 --- a/src/main/java/org/threeten/extra/chrono/AccountingChronology.java +++ b/src/main/java/org/threeten/extra/chrono/AccountingChronology.java @@ -44,6 +44,7 @@ import java.time.chrono.AbstractChronology; import java.time.chrono.ChronoLocalDateTime; import java.time.chrono.ChronoZonedDateTime; +import java.time.chrono.Chronology; import java.time.chrono.Era; import java.time.temporal.ChronoField; import java.time.temporal.ChronoUnit; @@ -248,7 +249,7 @@ int getDays0001ToIso1970() { *

    * The ID uniquely identifies the {@code Chronology}, * but does not differentiate between instances of {@code AccountingChronology}. - * It cannot be used to lookup the {@code Chronology} using {@link #of(String)}, + * It cannot be used to lookup the {@code Chronology} using {@link Chronology#of(String)}, * because each instance requires setup. * * @return the chronology ID - 'Accounting' diff --git a/src/main/java/org/threeten/extra/chrono/BritishCutoverChronology.java b/src/main/java/org/threeten/extra/chrono/BritishCutoverChronology.java index 5cd61052..ee8f936a 100644 --- a/src/main/java/org/threeten/extra/chrono/BritishCutoverChronology.java +++ b/src/main/java/org/threeten/extra/chrono/BritishCutoverChronology.java @@ -40,6 +40,7 @@ import java.time.chrono.AbstractChronology; import java.time.chrono.ChronoLocalDateTime; import java.time.chrono.ChronoZonedDateTime; +import java.time.chrono.Chronology; import java.time.chrono.Era; import java.time.chrono.IsoChronology; import java.time.format.ResolverStyle; @@ -183,7 +184,7 @@ public LocalDate getCutover() { * Gets the ID of the chronology - 'BritishCutover'. *

    * The ID uniquely identifies the {@code Chronology}. - * It can be used to lookup the {@code Chronology} using {@link #of(String)}. + * It can be used to lookup the {@code Chronology} using {@link Chronology#of(String)}. * * @return the chronology ID - 'BritishCutover' * @see #getCalendarType() diff --git a/src/main/java/org/threeten/extra/chrono/CopticChronology.java b/src/main/java/org/threeten/extra/chrono/CopticChronology.java index 46479e74..4cb39ce7 100644 --- a/src/main/java/org/threeten/extra/chrono/CopticChronology.java +++ b/src/main/java/org/threeten/extra/chrono/CopticChronology.java @@ -38,6 +38,7 @@ import java.time.ZoneId; import java.time.chrono.ChronoLocalDateTime; import java.time.chrono.ChronoZonedDateTime; +import java.time.chrono.Chronology; import java.time.chrono.Era; import java.time.format.ResolverStyle; import java.time.temporal.TemporalAccessor; @@ -108,7 +109,7 @@ private Object readResolve() { * Gets the ID of the chronology - 'Coptic'. *

    * The ID uniquely identifies the {@code Chronology}. - * It can be used to lookup the {@code Chronology} using {@link #of(String)}. + * It can be used to lookup the {@code Chronology} using {@link Chronology#of(String)}. * * @return the chronology ID - 'Coptic' * @see #getCalendarType() @@ -123,7 +124,7 @@ public String getId() { *

    * The calendar type is an identifier defined by the * Unicode Locale Data Markup Language (LDML) specification. - * It can be used to lookup the {@code Chronology} using {@link #of(String)}. + * It can be used to lookup the {@code Chronology} using {@link Chronology#of(String)}. * It can also be used as part of a locale, accessible via * {@link Locale#getUnicodeLocaleType(String)} with the key 'ca'. * diff --git a/src/main/java/org/threeten/extra/chrono/DiscordianChronology.java b/src/main/java/org/threeten/extra/chrono/DiscordianChronology.java index 6b0152cb..13d23323 100644 --- a/src/main/java/org/threeten/extra/chrono/DiscordianChronology.java +++ b/src/main/java/org/threeten/extra/chrono/DiscordianChronology.java @@ -39,6 +39,7 @@ import java.time.chrono.AbstractChronology; import java.time.chrono.ChronoLocalDateTime; import java.time.chrono.ChronoZonedDateTime; +import java.time.chrono.Chronology; import java.time.chrono.Era; import java.time.format.ResolverStyle; import java.time.temporal.ChronoField; @@ -172,7 +173,7 @@ private Object readResolve() { * Gets the ID of the chronology - 'Discordian'. *

    * The ID uniquely identifies the {@code Chronology}. - * It can be used to lookup the {@code Chronology} using {@link #of(String)}. + * It can be used to lookup the {@code Chronology} using {@link Chronology#of(String)}. * * @return the chronology ID - 'Discordian' * @see #getCalendarType() diff --git a/src/main/java/org/threeten/extra/chrono/EthiopicChronology.java b/src/main/java/org/threeten/extra/chrono/EthiopicChronology.java index 3442006b..7f33b7d1 100644 --- a/src/main/java/org/threeten/extra/chrono/EthiopicChronology.java +++ b/src/main/java/org/threeten/extra/chrono/EthiopicChronology.java @@ -38,6 +38,7 @@ import java.time.ZoneId; import java.time.chrono.ChronoLocalDateTime; import java.time.chrono.ChronoZonedDateTime; +import java.time.chrono.Chronology; import java.time.chrono.Era; import java.time.format.ResolverStyle; import java.time.temporal.TemporalAccessor; @@ -108,7 +109,7 @@ private Object readResolve() { * Gets the ID of the chronology - 'Ethiopic'. *

    * The ID uniquely identifies the {@code Chronology}. - * It can be used to lookup the {@code Chronology} using {@link #of(String)}. + * It can be used to lookup the {@code Chronology} using {@link Chronology#of(String)}. * * @return the chronology ID - 'Ethiopic' * @see #getCalendarType() @@ -123,7 +124,7 @@ public String getId() { *

    * The calendar type is an identifier defined by the * Unicode Locale Data Markup Language (LDML) specification. - * It can be used to lookup the {@code Chronology} using {@link #of(String)}. + * It can be used to lookup the {@code Chronology} using {@link Chronology#of(String)}. * It can also be used as part of a locale, accessible via * {@link Locale#getUnicodeLocaleType(String)} with the key 'ca'. * diff --git a/src/main/java/org/threeten/extra/chrono/InternationalFixedChronology.java b/src/main/java/org/threeten/extra/chrono/InternationalFixedChronology.java index b585be4e..b080c895 100644 --- a/src/main/java/org/threeten/extra/chrono/InternationalFixedChronology.java +++ b/src/main/java/org/threeten/extra/chrono/InternationalFixedChronology.java @@ -39,6 +39,7 @@ import java.time.chrono.AbstractChronology; import java.time.chrono.ChronoLocalDateTime; import java.time.chrono.ChronoZonedDateTime; +import java.time.chrono.Chronology; import java.time.chrono.Era; import java.time.temporal.ChronoField; import java.time.temporal.TemporalAccessor; @@ -183,7 +184,7 @@ private Object readResolve() { * Gets the ID of the chronology - 'Ifc'. *

    * The ID uniquely identifies the {@code Chronology}. - * It can be used to lookup the {@code Chronology} using {@link #of(String)}. + * It can be used to lookup the {@code Chronology} using {@link Chronology#of(String)}. * * @return the chronology ID - 'Ifc' * @see #getCalendarType() diff --git a/src/main/java/org/threeten/extra/chrono/JulianChronology.java b/src/main/java/org/threeten/extra/chrono/JulianChronology.java index d9bca63d..ca73e03f 100644 --- a/src/main/java/org/threeten/extra/chrono/JulianChronology.java +++ b/src/main/java/org/threeten/extra/chrono/JulianChronology.java @@ -39,6 +39,7 @@ import java.time.chrono.AbstractChronology; import java.time.chrono.ChronoLocalDateTime; import java.time.chrono.ChronoZonedDateTime; +import java.time.chrono.Chronology; import java.time.chrono.Era; import java.time.format.ResolverStyle; import java.time.temporal.ChronoField; @@ -128,7 +129,7 @@ private Object readResolve() { * Gets the ID of the chronology - 'Julian'. *

    * The ID uniquely identifies the {@code Chronology}. - * It can be used to lookup the {@code Chronology} using {@link #of(String)}. + * It can be used to lookup the {@code Chronology} using {@link Chronology#of(String)}. * * @return the chronology ID - 'Julian' * @see #getCalendarType() diff --git a/src/main/java/org/threeten/extra/chrono/PaxChronology.java b/src/main/java/org/threeten/extra/chrono/PaxChronology.java index c7b4c48e..1cc8c479 100644 --- a/src/main/java/org/threeten/extra/chrono/PaxChronology.java +++ b/src/main/java/org/threeten/extra/chrono/PaxChronology.java @@ -39,6 +39,7 @@ import java.time.chrono.AbstractChronology; import java.time.chrono.ChronoLocalDateTime; import java.time.chrono.ChronoZonedDateTime; +import java.time.chrono.Chronology; import java.time.chrono.Era; import java.time.format.ResolverStyle; import java.time.temporal.ChronoField; @@ -164,7 +165,7 @@ private Object readResolve() { * Gets the ID of the chronology - 'Pax'. *

    * The ID uniquely identifies the {@code Chronology}. - * It can be used to lookup the {@code Chronology} using {@link #of(String)}. + * It can be used to lookup the {@code Chronology} using {@link Chronology#of(String)}. * * @return the chronology ID - 'Pax' * @see #getCalendarType() diff --git a/src/main/java/org/threeten/extra/chrono/Symmetry010Chronology.java b/src/main/java/org/threeten/extra/chrono/Symmetry010Chronology.java index 894d0a56..7d7827c5 100644 --- a/src/main/java/org/threeten/extra/chrono/Symmetry010Chronology.java +++ b/src/main/java/org/threeten/extra/chrono/Symmetry010Chronology.java @@ -39,6 +39,7 @@ import java.time.chrono.AbstractChronology; import java.time.chrono.ChronoLocalDateTime; import java.time.chrono.ChronoZonedDateTime; +import java.time.chrono.Chronology; import java.time.chrono.Era; import java.time.chrono.IsoEra; import java.time.temporal.ChronoField; @@ -215,7 +216,7 @@ private Object readResolve() { * Gets the ID of the chronology - 'Sym010'. *

    * The ID uniquely identifies the {@code Chronology}. - * It can be used to lookup the {@code Chronology} using {@link #of(String)}. + * It can be used to lookup the {@code Chronology} using {@link Chronology#of(String)}. * * @return the chronology ID - 'Sym010' * @see #getCalendarType() diff --git a/src/main/java/org/threeten/extra/chrono/Symmetry454Chronology.java b/src/main/java/org/threeten/extra/chrono/Symmetry454Chronology.java index f395833f..e707d078 100644 --- a/src/main/java/org/threeten/extra/chrono/Symmetry454Chronology.java +++ b/src/main/java/org/threeten/extra/chrono/Symmetry454Chronology.java @@ -39,6 +39,7 @@ import java.time.chrono.AbstractChronology; import java.time.chrono.ChronoLocalDateTime; import java.time.chrono.ChronoZonedDateTime; +import java.time.chrono.Chronology; import java.time.chrono.Era; import java.time.chrono.IsoEra; import java.time.temporal.ChronoField; @@ -208,7 +209,7 @@ private Object readResolve() { * Gets the ID of the chronology - 'Sym454'. *

    * The ID uniquely identifies the {@code Chronology}. - * It can be used to lookup the {@code Chronology} using {@link #of(String)}. + * It can be used to lookup the {@code Chronology} using {@link Chronology#of(String)}. * * @return the chronology ID - 'Sym454' * @see #getCalendarType() From a50bfe1e2f80bf054d5c5386b1d18b416760efa4 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 8 Jan 2018 11:49:53 +0000 Subject: [PATCH 035/279] Ensure resources are closed in tests --- .../org/threeten/extra/TestDayOfMonth.java | 13 ++++--- .../org/threeten/extra/TestDayOfYear.java | 13 ++++--- .../java/org/threeten/extra/TestDays.java | 15 ++++---- .../java/org/threeten/extra/TestHours.java | 15 ++++---- .../java/org/threeten/extra/TestInterval.java | 15 ++++---- .../threeten/extra/TestLocalDateRange.java | 17 +++++----- .../java/org/threeten/extra/TestMinutes.java | 15 ++++---- .../java/org/threeten/extra/TestMonths.java | 15 ++++---- .../org/threeten/extra/TestMutableClock.java | 26 +++++++------- .../threeten/extra/TestPeriodDuration.java | 17 +++++----- .../java/org/threeten/extra/TestSeconds.java | 15 ++++---- .../org/threeten/extra/TestTemporals.java | 34 +++++++++---------- .../java/org/threeten/extra/TestWeeks.java | 15 ++++---- .../org/threeten/extra/TestYearQuarter.java | 13 ++++--- .../java/org/threeten/extra/TestYears.java | 15 ++++---- .../threeten/extra/scale/TestTaiInstant.java | 17 +++++----- .../threeten/extra/scale/TestUtcInstant.java | 17 +++++----- .../threeten/extra/scale/TestUtcRules.java | 13 +++---- 18 files changed, 142 insertions(+), 158 deletions(-) diff --git a/src/test/java/org/threeten/extra/TestDayOfMonth.java b/src/test/java/org/threeten/extra/TestDayOfMonth.java index 3ef1b28e..6cc1cb7a 100644 --- a/src/test/java/org/threeten/extra/TestDayOfMonth.java +++ b/src/test/java/org/threeten/extra/TestDayOfMonth.java @@ -127,13 +127,12 @@ public void test_interfaces() { public void test_serialization() throws IOException, ClassNotFoundException { DayOfMonth test = DayOfMonth.of(1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(test); - oos.close(); - - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream( - baos.toByteArray())); - assertEquals(ois.readObject(), test); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertEquals(ois.readObject(), test); + } } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestDayOfYear.java b/src/test/java/org/threeten/extra/TestDayOfYear.java index fef88590..9fd9f158 100644 --- a/src/test/java/org/threeten/extra/TestDayOfYear.java +++ b/src/test/java/org/threeten/extra/TestDayOfYear.java @@ -116,13 +116,12 @@ public void test_interfaces() { public void test_serialization() throws IOException, ClassNotFoundException { DayOfYear test = DayOfYear.of(1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(test); - oos.close(); - - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream( - baos.toByteArray())); - assertEquals(ois.readObject(), test); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertEquals(ois.readObject(), test); + } } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestDays.java b/src/test/java/org/threeten/extra/TestDays.java index 743b60b6..66d3dd43 100644 --- a/src/test/java/org/threeten/extra/TestDays.java +++ b/src/test/java/org/threeten/extra/TestDays.java @@ -62,15 +62,14 @@ public void test_isSerializable() { //----------------------------------------------------------------------- public void test_deserializationSingleton() throws Exception { - Days orginal = Days.ZERO; + Days test = Days.ZERO; ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(baos); - out.writeObject(orginal); - out.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream in = new ObjectInputStream(bais); - Days ser = (Days) in.readObject(); - assertSame(Days.ZERO, ser); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertSame(ois.readObject(), test); + } } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestHours.java b/src/test/java/org/threeten/extra/TestHours.java index b54e183e..6dc1a8be 100644 --- a/src/test/java/org/threeten/extra/TestHours.java +++ b/src/test/java/org/threeten/extra/TestHours.java @@ -60,15 +60,14 @@ public void test_isSerializable() { //----------------------------------------------------------------------- public void test_deserializationSingleton() throws Exception { - Hours orginal = Hours.ZERO; + Hours test = Hours.ZERO; ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(baos); - out.writeObject(orginal); - out.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream in = new ObjectInputStream(bais); - Hours ser = (Hours) in.readObject(); - assertSame(Hours.ZERO, ser); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertSame(ois.readObject(), test); + } } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestInterval.java b/src/test/java/org/threeten/extra/TestInterval.java index 9f9a7d0b..93981680 100644 --- a/src/test/java/org/threeten/extra/TestInterval.java +++ b/src/test/java/org/threeten/extra/TestInterval.java @@ -71,15 +71,14 @@ public void test_isSerializable() { //----------------------------------------------------------------------- public void test_serialization() throws Exception { - Interval orginal = Interval.of(Instant.EPOCH, NOW1); + Interval test = Interval.of(Instant.EPOCH, NOW1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(baos); - out.writeObject(orginal); - out.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream in = new ObjectInputStream(bais); - Interval ser = (Interval) in.readObject(); - assertEquals(ser, orginal); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertEquals(ois.readObject(), test); + } } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestLocalDateRange.java b/src/test/java/org/threeten/extra/TestLocalDateRange.java index 1b836b12..117e9d4d 100644 --- a/src/test/java/org/threeten/extra/TestLocalDateRange.java +++ b/src/test/java/org/threeten/extra/TestLocalDateRange.java @@ -274,15 +274,14 @@ public void test_isSerializable() { } public void test_serialization() throws Exception { - LocalDateRange original = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); + LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(baos); - out.writeObject(original); - out.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream in = new ObjectInputStream(bais); - LocalDateRange ser = (LocalDateRange) in.readObject(); - assertEquals(ser, original); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertEquals(ois.readObject(), test); + } } //----------------------------------------------------------------------- @@ -964,7 +963,7 @@ public void crossCheckGuava_intersection( } if (extra == null) { assertEquals(extra, guava); - } else { + } else if (guava != null) { assertEquals(extra.getStart(), guava.lowerEndpoint()); assertEquals(extra.getEnd(), guava.upperEndpoint()); } diff --git a/src/test/java/org/threeten/extra/TestMinutes.java b/src/test/java/org/threeten/extra/TestMinutes.java index 88f578eb..7541abbf 100644 --- a/src/test/java/org/threeten/extra/TestMinutes.java +++ b/src/test/java/org/threeten/extra/TestMinutes.java @@ -60,15 +60,14 @@ public void test_isSerializable() { //----------------------------------------------------------------------- public void test_deserializationSingleton() throws Exception { - Minutes orginal = Minutes.ZERO; + Minutes test = Minutes.ZERO; ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(baos); - out.writeObject(orginal); - out.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream in = new ObjectInputStream(bais); - Minutes ser = (Minutes) in.readObject(); - assertSame(Minutes.ZERO, ser); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertSame(ois.readObject(), test); + } } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestMonths.java b/src/test/java/org/threeten/extra/TestMonths.java index 17b01a7d..074938a6 100644 --- a/src/test/java/org/threeten/extra/TestMonths.java +++ b/src/test/java/org/threeten/extra/TestMonths.java @@ -62,15 +62,14 @@ public void test_isSerializable() { //----------------------------------------------------------------------- public void test_deserializationSingleton() throws Exception { - Months orginal = Months.ZERO; + Months test = Months.ZERO; ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(baos); - out.writeObject(orginal); - out.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream in = new ObjectInputStream(bais); - Months ser = (Months) in.readObject(); - assertSame(Months.ZERO, ser); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertSame(ois.readObject(), test); + } } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestMutableClock.java b/src/test/java/org/threeten/extra/TestMutableClock.java index 10aae154..12cc949e 100644 --- a/src/test/java/org/threeten/extra/TestMutableClock.java +++ b/src/test/java/org/threeten/extra/TestMutableClock.java @@ -299,20 +299,20 @@ public void test_isSerializable() { } public void test_serialization() throws Exception { - MutableClock original = MutableClock.epochUTC(); + MutableClock test = MutableClock.epochUTC(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(baos); - out.writeObject(original); - out.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream in = new ObjectInputStream(bais); - MutableClock ser = (MutableClock) in.readObject(); - assertEquals(ser.instant(), original.instant()); - assertEquals(ser.getZone(), original.getZone()); - // no shared updates - assertNotEquals(ser, original); - original.add(Duration.ofSeconds(1)); - assertNotEquals(ser.instant(), original.instant()); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + MutableClock ser = (MutableClock) ois.readObject(); + assertEquals(ser.instant(), test.instant()); + assertEquals(ser.getZone(), test.getZone()); + // no shared updates + assertNotEquals(ser, test); + test.add(Duration.ofSeconds(1)); + assertNotEquals(ser.instant(), test.instant()); + } } public void test_updatesAreAtomic() throws Exception { diff --git a/src/test/java/org/threeten/extra/TestPeriodDuration.java b/src/test/java/org/threeten/extra/TestPeriodDuration.java index c580c99d..cbc4a794 100644 --- a/src/test/java/org/threeten/extra/TestPeriodDuration.java +++ b/src/test/java/org/threeten/extra/TestPeriodDuration.java @@ -73,16 +73,15 @@ public void test_isSerializable() { } //----------------------------------------------------------------------- - public void test_deserializationSingleton() throws Exception { - PeriodDuration orginal = PeriodDuration.ZERO; + public void test_serialization() throws Exception { + PeriodDuration test = PeriodDuration.of(P1Y2M3D, DUR_5); ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(baos); - out.writeObject(orginal); - out.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream in = new ObjectInputStream(bais); - PeriodDuration ser = (PeriodDuration) in.readObject(); - assertEquals(PeriodDuration.ZERO, ser); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertEquals(ois.readObject(), test); + } } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestSeconds.java b/src/test/java/org/threeten/extra/TestSeconds.java index 71d0e83c..4d6c6901 100644 --- a/src/test/java/org/threeten/extra/TestSeconds.java +++ b/src/test/java/org/threeten/extra/TestSeconds.java @@ -60,15 +60,14 @@ public void test_isSerializable() { //----------------------------------------------------------------------- public void test_deserializationSingleton() throws Exception { - Seconds orginal = Seconds.ZERO; + Seconds test = Seconds.ZERO; ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(baos); - out.writeObject(orginal); - out.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream in = new ObjectInputStream(bais); - Seconds ser = (Seconds) in.readObject(); - assertSame(Seconds.ZERO, ser); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertSame(ois.readObject(), test); + } } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestTemporals.java b/src/test/java/org/threeten/extra/TestTemporals.java index 1e533dea..e3465916 100644 --- a/src/test/java/org/threeten/extra/TestTemporals.java +++ b/src/test/java/org/threeten/extra/TestTemporals.java @@ -90,16 +90,15 @@ public class TestTemporals { //----------------------------------------------------------------------- @Test public void test_nextWorkingDay_serialization() throws IOException, ClassNotFoundException { - TemporalAdjuster nextWorkingDay = Temporals.nextWorkingDay(); - assertTrue(nextWorkingDay instanceof Serializable); - + TemporalAdjuster test = Temporals.nextWorkingDay(); + assertTrue(test instanceof Serializable); ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(nextWorkingDay); - oos.close(); - - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - assertSame(ois.readObject(), nextWorkingDay); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertSame(ois.readObject(), test); + } } @Test @@ -158,16 +157,15 @@ public void test_nextWorkingDay_yearChange() { //----------------------------------------------------------------------- @Test public void test_previousWorkingDay_serialization() throws IOException, ClassNotFoundException { - TemporalAdjuster previousWorkingDay = Temporals.previousWorkingDay(); - assertTrue(previousWorkingDay instanceof Serializable); - + TemporalAdjuster test = Temporals.previousWorkingDay(); + assertTrue(test instanceof Serializable); ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(previousWorkingDay); - oos.close(); - - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - assertSame(ois.readObject(), previousWorkingDay); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertSame(ois.readObject(), test); + } } @Test diff --git a/src/test/java/org/threeten/extra/TestWeeks.java b/src/test/java/org/threeten/extra/TestWeeks.java index 08d703fa..dc87df74 100644 --- a/src/test/java/org/threeten/extra/TestWeeks.java +++ b/src/test/java/org/threeten/extra/TestWeeks.java @@ -62,15 +62,14 @@ public void test_isSerializable() { //----------------------------------------------------------------------- public void test_deserializationSingleton() throws Exception { - Weeks orginal = Weeks.ZERO; + Weeks test = Weeks.ZERO; ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(baos); - out.writeObject(orginal); - out.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream in = new ObjectInputStream(bais); - Weeks ser = (Weeks) in.readObject(); - assertSame(Weeks.ZERO, ser); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertSame(ois.readObject(), test); + } } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestYearQuarter.java b/src/test/java/org/threeten/extra/TestYearQuarter.java index 3239efea..4fbf7e72 100644 --- a/src/test/java/org/threeten/extra/TestYearQuarter.java +++ b/src/test/java/org/threeten/extra/TestYearQuarter.java @@ -135,13 +135,12 @@ public void test_interfaces() { public void test_serialization() throws IOException, ClassNotFoundException { YearQuarter test = YearQuarter.of(2012, 1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(test); - oos.close(); - - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream( - baos.toByteArray())); - assertEquals(ois.readObject(), test); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertEquals(ois.readObject(), test); + } } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestYears.java b/src/test/java/org/threeten/extra/TestYears.java index 6d57d6b9..23521d4d 100644 --- a/src/test/java/org/threeten/extra/TestYears.java +++ b/src/test/java/org/threeten/extra/TestYears.java @@ -62,15 +62,14 @@ public void test_isSerializable() { //----------------------------------------------------------------------- public void test_deserializationSingleton() throws Exception { - Years orginal = Years.ZERO; + Years test = Years.ZERO; ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(baos); - out.writeObject(orginal); - out.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream in = new ObjectInputStream(bais); - Years ser = (Years) in.readObject(); - assertSame(Years.ZERO, ser); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertSame(ois.readObject(), test); + } } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/scale/TestTaiInstant.java b/src/test/java/org/threeten/extra/scale/TestTaiInstant.java index d17557c4..ab270b00 100644 --- a/src/test/java/org/threeten/extra/scale/TestTaiInstant.java +++ b/src/test/java/org/threeten/extra/scale/TestTaiInstant.java @@ -64,16 +64,15 @@ public void test_interfaces() { // serialization //----------------------------------------------------------------------- @Test - public void test_deserialization() throws Exception { - TaiInstant orginal = TaiInstant.ofTaiSeconds(2, 3); + public void test_serialization() throws Exception { + TaiInstant test = TaiInstant.ofTaiSeconds(2, 3); ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(baos); - out.writeObject(orginal); - out.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream in = new ObjectInputStream(bais); - TaiInstant ser = (TaiInstant) in.readObject(); - assertEquals(TaiInstant.ofTaiSeconds(2, 3), ser); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertEquals(ois.readObject(), test); + } } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/scale/TestUtcInstant.java b/src/test/java/org/threeten/extra/scale/TestUtcInstant.java index bee05847..fd4e993d 100644 --- a/src/test/java/org/threeten/extra/scale/TestUtcInstant.java +++ b/src/test/java/org/threeten/extra/scale/TestUtcInstant.java @@ -74,16 +74,15 @@ public void test_interfaces() { // serialization //----------------------------------------------------------------------- @Test - public void test_deserialization() throws Exception { - UtcInstant orginal = UtcInstant.ofModifiedJulianDay(2, 3); + public void test_serialization() throws Exception { + UtcInstant test = UtcInstant.ofModifiedJulianDay(2, 3); ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream out = new ObjectOutputStream(baos); - out.writeObject(orginal); - out.close(); - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - ObjectInputStream in = new ObjectInputStream(bais); - UtcInstant ser = (UtcInstant) in.readObject(); - assertEquals(UtcInstant.ofModifiedJulianDay(2, 3), ser); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertEquals(ois.readObject(), test); + } } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/scale/TestUtcRules.java b/src/test/java/org/threeten/extra/scale/TestUtcRules.java index f0b3012c..1fd325c9 100644 --- a/src/test/java/org/threeten/extra/scale/TestUtcRules.java +++ b/src/test/java/org/threeten/extra/scale/TestUtcRules.java @@ -76,14 +76,15 @@ public void test_interfaces() { //----------------------------------------------------------------------- // serialize //----------------------------------------------------------------------- - public void test_serialize() throws Exception { + public void test_serialization() throws Exception { SystemUtcRules test = SystemUtcRules.INSTANCE; // use real rules, not our hacked copy ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(test); - oos.close(); - ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - assertSame(ois.readObject(), test); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertSame(ois.readObject(), test); + } } //----------------------------------------------------------------------- From ea52d02453ca18401694e0cb34e876925bfcca42 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 8 Jan 2018 14:34:43 +0000 Subject: [PATCH 036/279] Ensure compilation on Java 9 --- src/main/java/org/threeten/extra/chrono/AccountingDate.java | 2 +- .../java/org/threeten/extra/chrono/BritishCutoverDate.java | 4 ++-- src/main/java/org/threeten/extra/chrono/CopticDate.java | 2 +- src/main/java/org/threeten/extra/chrono/DiscordianDate.java | 2 +- src/main/java/org/threeten/extra/chrono/EthiopicDate.java | 2 +- .../org/threeten/extra/chrono/InternationalFixedDate.java | 2 +- src/main/java/org/threeten/extra/chrono/JulianDate.java | 2 +- src/main/java/org/threeten/extra/chrono/PaxDate.java | 2 +- src/main/java/org/threeten/extra/chrono/Symmetry010Date.java | 2 +- src/main/java/org/threeten/extra/chrono/Symmetry454Date.java | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/threeten/extra/chrono/AccountingDate.java b/src/main/java/org/threeten/extra/chrono/AccountingDate.java index cf14c1df..1d500af9 100644 --- a/src/main/java/org/threeten/extra/chrono/AccountingDate.java +++ b/src/main/java/org/threeten/extra/chrono/AccountingDate.java @@ -445,7 +445,7 @@ public AccountingDate minus(long amountToSubtract, TemporalUnit unit) { @Override // for covariant return type @SuppressWarnings("unchecked") public ChronoLocalDateTime atTime(LocalTime localTime) { - return (ChronoLocalDateTime) ChronoLocalDate.super.atTime(localTime); + return (ChronoLocalDateTime) super.atTime(localTime); } @Override diff --git a/src/main/java/org/threeten/extra/chrono/BritishCutoverDate.java b/src/main/java/org/threeten/extra/chrono/BritishCutoverDate.java index 17d69f55..3bcdf2c4 100644 --- a/src/main/java/org/threeten/extra/chrono/BritishCutoverDate.java +++ b/src/main/java/org/threeten/extra/chrono/BritishCutoverDate.java @@ -469,7 +469,7 @@ public BritishCutoverDate minus(long amountToSubtract, TemporalUnit unit) { @Override // for covariant return type @SuppressWarnings("unchecked") public ChronoLocalDateTime atTime(LocalTime localTime) { - return (ChronoLocalDateTime) ChronoLocalDate.super.atTime(localTime); + return (ChronoLocalDateTime) super.atTime(localTime); } @Override @@ -520,7 +520,7 @@ public R query(TemporalQuery query) { if (query == TemporalQueries.localDate()) { return (R) isoDate; } - return ChronoLocalDate.super.query(query); + return super.query(query); } //------------------------------------------------------------------------- diff --git a/src/main/java/org/threeten/extra/chrono/CopticDate.java b/src/main/java/org/threeten/extra/chrono/CopticDate.java index 003352ad..1698811b 100644 --- a/src/main/java/org/threeten/extra/chrono/CopticDate.java +++ b/src/main/java/org/threeten/extra/chrono/CopticDate.java @@ -380,7 +380,7 @@ public CopticDate minus(long amountToSubtract, TemporalUnit unit) { @Override // for covariant return type @SuppressWarnings("unchecked") public ChronoLocalDateTime atTime(LocalTime localTime) { - return (ChronoLocalDateTime) ChronoLocalDate.super.atTime(localTime); + return (ChronoLocalDateTime) super.atTime(localTime); } @Override diff --git a/src/main/java/org/threeten/extra/chrono/DiscordianDate.java b/src/main/java/org/threeten/extra/chrono/DiscordianDate.java index a6372678..8fb8a949 100644 --- a/src/main/java/org/threeten/extra/chrono/DiscordianDate.java +++ b/src/main/java/org/threeten/extra/chrono/DiscordianDate.java @@ -665,7 +665,7 @@ public DiscordianDate minus(long amountToSubtract, TemporalUnit unit) { @Override // for covariant return type @SuppressWarnings("unchecked") public ChronoLocalDateTime atTime(LocalTime localTime) { - return (ChronoLocalDateTime) ChronoLocalDate.super.atTime(localTime); + return (ChronoLocalDateTime) super.atTime(localTime); } @Override diff --git a/src/main/java/org/threeten/extra/chrono/EthiopicDate.java b/src/main/java/org/threeten/extra/chrono/EthiopicDate.java index 78aacb78..b9bb1318 100644 --- a/src/main/java/org/threeten/extra/chrono/EthiopicDate.java +++ b/src/main/java/org/threeten/extra/chrono/EthiopicDate.java @@ -382,7 +382,7 @@ public EthiopicDate minus(long amountToSubtract, TemporalUnit unit) { @Override // for covariant return type @SuppressWarnings("unchecked") public ChronoLocalDateTime atTime(LocalTime localTime) { - return (ChronoLocalDateTime) ChronoLocalDate.super.atTime(localTime); + return (ChronoLocalDateTime) super.atTime(localTime); } @Override diff --git a/src/main/java/org/threeten/extra/chrono/InternationalFixedDate.java b/src/main/java/org/threeten/extra/chrono/InternationalFixedDate.java index 5fd9f597..b8f3799d 100644 --- a/src/main/java/org/threeten/extra/chrono/InternationalFixedDate.java +++ b/src/main/java/org/threeten/extra/chrono/InternationalFixedDate.java @@ -677,7 +677,7 @@ public InternationalFixedDate minus(long amountToSubtract, TemporalUnit unit) { @Override // for covariant return type @SuppressWarnings("unchecked") public ChronoLocalDateTime atTime(LocalTime localTime) { - return (ChronoLocalDateTime) ChronoLocalDate.super.atTime(localTime); + return (ChronoLocalDateTime) super.atTime(localTime); } @Override diff --git a/src/main/java/org/threeten/extra/chrono/JulianDate.java b/src/main/java/org/threeten/extra/chrono/JulianDate.java index aaf287f1..b0d72fd0 100644 --- a/src/main/java/org/threeten/extra/chrono/JulianDate.java +++ b/src/main/java/org/threeten/extra/chrono/JulianDate.java @@ -437,7 +437,7 @@ public JulianDate minus(long amountToSubtract, TemporalUnit unit) { @Override // for covariant return type @SuppressWarnings("unchecked") public ChronoLocalDateTime atTime(LocalTime localTime) { - return (ChronoLocalDateTime) ChronoLocalDate.super.atTime(localTime); + return (ChronoLocalDateTime) super.atTime(localTime); } @Override diff --git a/src/main/java/org/threeten/extra/chrono/PaxDate.java b/src/main/java/org/threeten/extra/chrono/PaxDate.java index c0c95c23..85a6c7f2 100644 --- a/src/main/java/org/threeten/extra/chrono/PaxDate.java +++ b/src/main/java/org/threeten/extra/chrono/PaxDate.java @@ -622,7 +622,7 @@ public PaxDate minus(long amountToSubtract, TemporalUnit unit) { @Override // for covariant return type @SuppressWarnings("unchecked") public ChronoLocalDateTime atTime(LocalTime localTime) { - return (ChronoLocalDateTime) ChronoLocalDate.super.atTime(localTime); + return (ChronoLocalDateTime) super.atTime(localTime); } @Override diff --git a/src/main/java/org/threeten/extra/chrono/Symmetry010Date.java b/src/main/java/org/threeten/extra/chrono/Symmetry010Date.java index 5777b443..df1b1417 100644 --- a/src/main/java/org/threeten/extra/chrono/Symmetry010Date.java +++ b/src/main/java/org/threeten/extra/chrono/Symmetry010Date.java @@ -575,7 +575,7 @@ public Symmetry010Date minus(long amountToSubtract, TemporalUnit unit) { @Override // for covariant return type @SuppressWarnings("unchecked") public ChronoLocalDateTime atTime(LocalTime localTime) { - return (ChronoLocalDateTime) ChronoLocalDate.super.atTime(localTime); + return (ChronoLocalDateTime) super.atTime(localTime); } @Override diff --git a/src/main/java/org/threeten/extra/chrono/Symmetry454Date.java b/src/main/java/org/threeten/extra/chrono/Symmetry454Date.java index 517c1e07..ff6c705a 100644 --- a/src/main/java/org/threeten/extra/chrono/Symmetry454Date.java +++ b/src/main/java/org/threeten/extra/chrono/Symmetry454Date.java @@ -593,7 +593,7 @@ public Symmetry454Date minus(long amountToSubtract, TemporalUnit unit) { @Override // for covariant return type @SuppressWarnings("unchecked") public ChronoLocalDateTime atTime(LocalTime localTime) { - return (ChronoLocalDateTime) ChronoLocalDate.super.atTime(localTime); + return (ChronoLocalDateTime) super.atTime(localTime); } @Override From 26c8e04cf013f8840ac114f4862c16e710f53d21 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 8 Jan 2018 15:46:23 +0000 Subject: [PATCH 037/279] Fix for Java 9 JDK-8062804 fixed `TemporalField` but broke ThreeTen-Extra Remove the tests which should never have worked And work around the new bug in the JDK using `getLong()` --- .../java/org/threeten/extra/PackedFields.java | 6 ++--- src/main/java/org/threeten/extra/Quarter.java | 4 +++- .../java/org/threeten/extra/YearQuarter.java | 22 ++++++++++++++++++- .../java/org/threeten/extra/YearWeek.java | 5 ++++- .../org/threeten/extra/TestDayOfMonth.java | 6 +++++ .../org/threeten/extra/TestDayOfYear.java | 6 +++++ .../java/org/threeten/extra/TestQuarter.java | 7 ++++++ .../chrono/TestAccountingChronology.java | 3 --- .../extra/chrono/TestJulianChronology.java | 3 --- 9 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/threeten/extra/PackedFields.java b/src/main/java/org/threeten/extra/PackedFields.java index 91b34e91..cd7fa1cb 100644 --- a/src/main/java/org/threeten/extra/PackedFields.java +++ b/src/main/java/org/threeten/extra/PackedFields.java @@ -155,7 +155,7 @@ public boolean isSupportedBy(TemporalAccessor temporal) { @Override public ValueRange rangeRefinedBy(TemporalAccessor temporal) { - if (isSupportedBy(temporal) == false) { + if (!temporal.isSupported(this)) { throw new DateTimeException("Unsupported field: " + this); } return range(); @@ -260,7 +260,7 @@ public boolean isSupportedBy(TemporalAccessor temporal) { @Override public ValueRange rangeRefinedBy(TemporalAccessor temporal) { - if (isSupportedBy(temporal) == false) { + if (!temporal.isSupported(this)) { throw new DateTimeException("Unsupported field: " + this); } return range(); @@ -351,7 +351,7 @@ public boolean isSupportedBy(TemporalAccessor temporal) { @Override public ValueRange rangeRefinedBy(TemporalAccessor temporal) { - if (isSupportedBy(temporal) == false) { + if (!temporal.isSupported(this)) { throw new DateTimeException("Unsupported field: " + this); } return range(); diff --git a/src/main/java/org/threeten/extra/Quarter.java b/src/main/java/org/threeten/extra/Quarter.java index 5f29118b..4d60561f 100644 --- a/src/main/java/org/threeten/extra/Quarter.java +++ b/src/main/java/org/threeten/extra/Quarter.java @@ -173,7 +173,9 @@ public static Quarter from(TemporalAccessor temporal) { if (IsoChronology.INSTANCE.equals(Chronology.from(temporal)) == false) { temporal = LocalDate.from(temporal); } - return of(temporal.get(QUARTER_OF_YEAR)); + // need to use getLong() as JDK Parsed class get() doesn't work properly + int qoy = Math.toIntExact(temporal.getLong(QUARTER_OF_YEAR)); + return of(qoy); } catch (DateTimeException ex) { throw new DateTimeException("Unable to obtain Quarter from TemporalAccessor: " + temporal + " of type " + temporal.getClass().getName(), ex); diff --git a/src/main/java/org/threeten/extra/YearQuarter.java b/src/main/java/org/threeten/extra/YearQuarter.java index d7ff44ba..b930c070 100644 --- a/src/main/java/org/threeten/extra/YearQuarter.java +++ b/src/main/java/org/threeten/extra/YearQuarter.java @@ -229,7 +229,10 @@ public static YearQuarter from(TemporalAccessor temporal) { if (IsoChronology.INSTANCE.equals(Chronology.from(temporal)) == false) { temporal = LocalDate.from(temporal); } - return of(temporal.get(YEAR), temporal.get(QUARTER_OF_YEAR)); + // need to use getLong() as JDK Parsed class get() doesn't work properly + int year = Math.toIntExact(temporal.getLong(YEAR)); + int qoy = Math.toIntExact(temporal.getLong(QUARTER_OF_YEAR)); + return of(year, qoy); } catch (DateTimeException ex) { throw new DateTimeException("Unable to obtain YearQuarter from TemporalAccessor: " + temporal + " of type " + temporal.getClass().getName(), ex); @@ -403,6 +406,9 @@ public boolean isSupported(TemporalUnit unit) { */ @Override public ValueRange range(TemporalField field) { + if (field == QUARTER_OF_YEAR) { + return QUARTER_OF_YEAR.range(); + } if (field == YEAR_OF_ERA) { return (getYear() <= 0 ? ValueRange.of(1, Year.MAX_VALUE + 1) : ValueRange.of(1, Year.MAX_VALUE)); } @@ -437,6 +443,20 @@ public ValueRange range(TemporalField field) { */ @Override public int get(TemporalField field) { + if (field == QUARTER_OF_YEAR) { + return quarter.getValue(); + } else if (field instanceof ChronoField) { + switch ((ChronoField) field) { + case YEAR_OF_ERA: + return (year < 1 ? 1 - year : year); + case YEAR: + return year; + case ERA: + return (year < 1 ? 0 : 1); + default: + throw new UnsupportedTemporalTypeException("Unsupported field: " + field); + } + } return Temporal.super.get(field); } diff --git a/src/main/java/org/threeten/extra/YearWeek.java b/src/main/java/org/threeten/extra/YearWeek.java index dd8b1439..b08ec591 100644 --- a/src/main/java/org/threeten/extra/YearWeek.java +++ b/src/main/java/org/threeten/extra/YearWeek.java @@ -225,7 +225,10 @@ public static YearWeek from(TemporalAccessor temporal) { if (!IsoChronology.INSTANCE.equals(Chronology.from(temporal))) { temporal = LocalDate.from(temporal); } - return of(temporal.get(WEEK_BASED_YEAR), (int) temporal.getLong(WEEK_OF_WEEK_BASED_YEAR)); + // need to use getLong() as JDK Parsed class get() doesn't work properly + int year = Math.toIntExact(temporal.getLong(WEEK_BASED_YEAR)); + int week = Math.toIntExact(temporal.getLong(WEEK_OF_WEEK_BASED_YEAR)); + return of(year, week); } catch (DateTimeException ex) { throw new DateTimeException("Unable to obtain YearWeek from TemporalAccessor: " + temporal + " of type " + temporal.getClass().getName(), ex); diff --git a/src/test/java/org/threeten/extra/TestDayOfMonth.java b/src/test/java/org/threeten/extra/TestDayOfMonth.java index 6cc1cb7a..42ec6df6 100644 --- a/src/test/java/org/threeten/extra/TestDayOfMonth.java +++ b/src/test/java/org/threeten/extra/TestDayOfMonth.java @@ -92,6 +92,7 @@ import java.time.YearMonth; import java.time.ZoneId; import java.time.chrono.IsoChronology; +import java.time.format.DateTimeFormatter; import java.time.temporal.Temporal; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjuster; @@ -237,6 +238,11 @@ public void test_from_TemporalAccessor_null() { DayOfMonth.from((TemporalAccessor) null); } + public void test_from_parse_CharSequence() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d"); + assertEquals(formatter.parse("3", DayOfMonth::from), DayOfMonth.of(3)); + } + //----------------------------------------------------------------------- // isSupported(TemporalField) //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestDayOfYear.java b/src/test/java/org/threeten/extra/TestDayOfYear.java index 9fd9f158..aebef97f 100644 --- a/src/test/java/org/threeten/extra/TestDayOfYear.java +++ b/src/test/java/org/threeten/extra/TestDayOfYear.java @@ -78,6 +78,7 @@ import java.time.Year; import java.time.ZoneId; import java.time.chrono.IsoChronology; +import java.time.format.DateTimeFormatter; import java.time.temporal.Temporal; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjuster; @@ -178,6 +179,11 @@ public void test_from_TemporalAccessor_null() { DayOfYear.from((TemporalAccessor) null); } + public void test_from_parse_CharSequence() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("D"); + assertEquals(formatter.parse("76", DayOfYear::from), DayOfYear.of(76)); + } + //----------------------------------------------------------------------- // isSupported(TemporalField) //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestQuarter.java b/src/test/java/org/threeten/extra/TestQuarter.java index dd6c6840..2d36130b 100644 --- a/src/test/java/org/threeten/extra/TestQuarter.java +++ b/src/test/java/org/threeten/extra/TestQuarter.java @@ -65,6 +65,7 @@ import static java.time.temporal.IsoFields.QUARTER_YEARS; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; +import static org.threeten.extra.Quarter.Q3; import java.io.Serializable; import java.time.DateTimeException; @@ -73,6 +74,7 @@ import java.time.LocalTime; import java.time.Month; import java.time.chrono.IsoChronology; +import java.time.format.DateTimeFormatter; import java.time.format.TextStyle; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalQueries; @@ -187,6 +189,11 @@ public void test_from_TemporalAccessor_null() { Quarter.from((TemporalAccessor) null); } + public void test_from_parse_CharSequence() { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("'Q'Q"); + assertEquals(formatter.parse("Q3", Quarter::from), Q3); + } + //----------------------------------------------------------------------- // getDisplayName() //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java b/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java index df613bf1..64942b05 100644 --- a/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java @@ -63,7 +63,6 @@ import java.time.Period; import java.time.chrono.Era; import java.time.chrono.IsoEra; -import java.time.temporal.IsoFields; import java.time.temporal.TemporalAdjusters; import java.time.temporal.TemporalField; import java.time.temporal.TemporalUnit; @@ -458,8 +457,6 @@ Object[][] data_ranges() { {2011, 13, 23, DAY_OF_MONTH, 1, 28}, {2011, 13, 23, DAY_OF_YEAR, 1, 364}, {2011, 13, 23, ALIGNED_WEEK_OF_MONTH, 1, 4}, - - {2011, 2, 23, IsoFields.QUARTER_OF_YEAR, 1, 4}, }; } diff --git a/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java b/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java index 23e1b8da..22205e0a 100644 --- a/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java @@ -63,7 +63,6 @@ import java.time.chrono.Chronology; import java.time.chrono.Era; import java.time.chrono.IsoEra; -import java.time.temporal.IsoFields; import java.time.temporal.TemporalAdjusters; import java.time.temporal.TemporalField; import java.time.temporal.TemporalUnit; @@ -426,8 +425,6 @@ Object[][] data_ranges() { {2011, 2, 23, DAY_OF_MONTH, 1, 28}, {2011, 2, 23, DAY_OF_YEAR, 1, 365}, {2011, 2, 23, ALIGNED_WEEK_OF_MONTH, 1, 4}, - - {2011, 2, 23, IsoFields.QUARTER_OF_YEAR, 1, 4}, }; } From e622cf81b803965e2e3de340b35257e250757f0f Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 8 Jan 2018 18:11:14 +0000 Subject: [PATCH 038/279] Update build for Java SE 9 and add module-info Add support for releasing via nexus plugin --- .gitignore | 2 + .travis.yml | 5 +- README.md | 6 +- pom.xml | 503 +++++++++++++++++++++++---------- src/changes/changes.xml | 4 + src/main/java/module-info.java | 47 +++ 6 files changed, 419 insertions(+), 148 deletions(-) create mode 100644 src/main/java/module-info.java diff --git a/.gitignore b/.gitignore index 8470331c..bfab9001 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ /*.iml /*.ipr /*.iws +/pom.xml.releaseBackup +/release.properties diff --git a/.travis.yml b/.travis.yml index 3a8f0f0b..ccd50e69 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ sudo: false language: java jdk: + - oraclejdk9 - oraclejdk8 cache: directories: @@ -10,8 +11,8 @@ before_cache: install: - mvn --version script: - - mvn install -e -B - - if [[ $TRAVIS_TAG =~ ^v.*$ ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_JDK_VERSION" == "oraclejdk8" ]; then travis_wait 40 mvn site-deploy -e -B --settings .github/maven-settings.xml; fi + - mvn install site -e -B + - if [[ $TRAVIS_TAG =~ ^v.*$ ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_JDK_VERSION" == "oraclejdk9" ]; then travis_wait 40 mvn clean install site-deploy -e -B --settings .github/maven-settings.xml; fi # secure keys for GITHUB_TOKEN env: global: diff --git a/README.md b/README.md index b89eb573..fb72e413 100644 --- a/README.md +++ b/README.md @@ -31,8 +31,6 @@ Please use GitHub [issues](https://github.com/ThreeTen/threeten-extra/issues) an ### Release process -* Update version (pom.xml, README.md, index.md, changes.xml) -* Commit and push -* `mvn clean deploy -Doss.repo -Dgpg.passphrase=""` -* Release project in [Nexus](https://oss.sonatype.org) +* Update manual parts of version (README.md, index.md, changes.xml) +* `mvn clean release:clean release:prepare release:perform` * Website will be built and released by Travis diff --git a/pom.xml b/pom.xml index e9f4913e..59ced5e1 100644 --- a/pom.xml +++ b/pom.xml @@ -1,16 +1,17 @@ - + + + + + 4.0.0 org.threeten threeten-extra jar ThreeTen-Extra 1.3-SNAPSHOT - Additional functionality that enhances JSR-310 dates and times in JDK 8 + Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later http://www.threeten.org/threeten-extra @@ -83,6 +84,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git http://github.com/ThreeTen/threeten-extra + HEAD ThreeTen.org @@ -92,6 +94,9 @@ + + src/main/resources + META-INF ${project.basedir} @@ -100,12 +105,20 @@ NOTICE.txt - - ${project.basedir}/src/main/resources - + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + + org.jacoco + jacoco-maven-plugin + + org.apache.maven.plugins maven-enforcer-plugin @@ -118,53 +131,14 @@ - 3.0.4 + 3.5.0 - - org.apache.maven.plugins - maven-checkstyle-plugin - - - run-checkstyle - process-sources - - checkstyle - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/Test*.java - - -Xmx2G - classes - 4 - - - - usedefaultlisteners - false - - - listener - org.testng.reporters.ExitCodeListener - - - reporter - org.testng.reporters.JUnitReportReporter - - - - + org.apache.maven.plugins maven-jar-plugin @@ -178,10 +152,18 @@ + org.apache.felix maven-bundle-plugin - 3.3.0 + 2.5.4 + + + biz.aQute.bnd + biz.aQute.bndlib + 3.5.0 + + bundle-manifest @@ -189,9 +171,15 @@ manifest + + + org.threeten.extra,org.threeten.extra.chrono,org.threeten.extra.scale + + + org.apache.maven.plugins maven-javadoc-plugin @@ -205,6 +193,7 @@ + org.apache.maven.plugins maven-source-plugin @@ -218,26 +207,8 @@ + - org.apache.maven.plugins - maven-site-plugin - - true - - - - lt.velykis.maven.skins - reflow-velocity-tools - 1.1.1 - - - org.apache.velocity - velocity - 1.7 - - - - com.github.github site-maven-plugin 0.12 @@ -270,11 +241,6 @@ maven-assembly-plugin ${maven-assembly-plugin.version} - - org.apache.maven.plugins - maven-checkstyle-plugin - ${maven-checkstyle-plugin.version} - org.apache.maven.plugins maven-changes-plugin @@ -355,11 +321,6 @@ maven-resources-plugin ${maven-resources-plugin.version} - - org.apache.maven.plugins - maven-site-plugin - ${maven-site-plugin.version} - org.apache.maven.plugins maven-source-plugin @@ -380,6 +341,85 @@ maven-toolchains-plugin ${maven-toolchains-plugin.version} + + + org.apache.maven.plugins + maven-release-plugin + ${maven-release-plugin.version} + + -Doss.repo + true + v@{project.version} + true + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${maven-checkstyle-plugin.version} + + + run-checkstyle + process-sources + + checkstyle + + + + + module-info.java + + + + + com.github.spotbugs + spotbugs-maven-plugin + ${spotbugs-maven-plugin.version} + + + + org.jacoco + jacoco-maven-plugin + ${jacoco-maven-plugin.version} + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + package + + report + + + + + + + org.apache.maven.plugins + maven-site-plugin + ${maven-site-plugin.version} + + true + + + + lt.velykis.maven.skins + reflow-velocity-tools + 1.1.1 + + + org.apache.velocity + velocity + 1.7 + + + + org.eclipse.m2e lifecycle-mapping @@ -391,26 +431,13 @@ org.apache.felix maven-bundle-plugin - [2.4.0,) + [2.5.4,) manifest - - - - - - org.apache.maven.plugins - maven-toolchains-plugin - [1.0,) - - toolchain - - - - + @@ -426,7 +453,7 @@ com.google.guava guava - 20.0 + 23.5-jre test @@ -440,6 +467,7 @@ + org.apache.maven.plugins maven-project-info-reports-plugin @@ -458,6 +486,19 @@ + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${maven-checkstyle-plugin.version} + + false + false + false + module-info.java + + + org.apache.maven.plugins maven-javadoc-plugin @@ -470,6 +511,7 @@ + org.apache.maven.plugins maven-surefire-report-plugin @@ -478,6 +520,7 @@ true + org.apache.maven.plugins maven-changes-plugin @@ -490,26 +533,34 @@ + org.apache.maven.plugins - maven-jxr-plugin - ${maven-jxr-plugin.version} - - - - jxr - - - + maven-pmd-plugin + ${maven-pmd-plugin.version} + + 100 + ${maven.compiler.target} + + module-info.java + + + - org.apache.maven.plugins - maven-checkstyle-plugin - ${maven-checkstyle-plugin.version} + com.github.spotbugs + spotbugs-maven-plugin + ${spotbugs-maven-plugin.version} + + + + org.jacoco + jacoco-maven-plugin + ${jacoco-maven-plugin.version} - checkstyle + report @@ -537,8 +588,138 @@ + + + java8 + + [1.6,9) + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + module-info.java + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + module-info.java + + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + module-info.java + + + + + + + + + java9plus + + [9,) + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + default-compile + + 9 + + + + + base-compile + + compile + + + + module-info.java + + + + + + + + 9 + + ${joda.release.version} + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + compile + + copy-dependencies + + + ${project.build.directory}/dependencies + true + true + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + --module-path ${project.build.directory}/dependencies + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + --module-path ${project.build.directory}/dependencies + + + + + + - repo-sign-artifacts + release-artifacts oss.repo @@ -546,26 +727,25 @@ - + org.apache.maven.plugins - maven-toolchains-plugin + maven-enforcer-plugin - validate + enforce-java - toolchain + enforce + + + + [9,) + + + - - - - 1.8 - oracle - - - @@ -581,14 +761,37 @@ + + + org.apache.maven.plugins + maven-assembly-plugin + + false + + src/main/assembly/dist.xml + + gnu + + + + make-assembly + install + + single + + + + + + de.jutzig github-release-plugin 1.1.1 Release v${project.version} - See the [release notes](http://www.threeten.org/threeten-extra/changes-report.html) for more information. + See the [change notes](http://www.threeten.org/threeten-extra/changes-report.html) for more information. v${project.version} true @@ -602,6 +805,19 @@ + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${nexus-staging-maven-plugin.version} + true + + https://oss.sonatype.org/ + sonatype-joda-staging + Releasing ${project.groupId}:${project.artifactId}:${project.version} + false + + @@ -610,43 +826,46 @@ - 2.5.5 - 2.11 - 2.16 - 2.6.1 - 3.3 + 3.1.0 + 2.12.1 + 3.0.0 + 3.0.0 + 3.7.0 2.8.2 - 2.10 + 3.0.2 3.0.0-M1 1.6 2.5.2 - 2.6 - 2.10.3 + 3.0.2 + 3.0.0-M1 2.5 - 3.4 - 3.5 - 2.8 + 3.5 + 3.8 + 2.9 + 2.5.3 2.4 - 2.7 + 3.0.2 + 3.4 - 2.4 - 2.18.1 - 2.18.1 + 3.0.1 + 2.20.1 + 2.20.1 1.1 + 0.8.0 + 1.6.8 + 3.1.1 1.8 1.8 1.8 true - true - true - true false true - -Xdoclint:none + none - ${project.basedir}/src/main/checkstyle/checkstyle.xml + src/main/checkstyle/checkstyle.xml + false UTF-8 UTF-8 diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 6ebe99fc..df97932a 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -8,6 +8,10 @@ + + Support Java 9. + Update and redesign build. + Error message and Javadoc fixes in Interval. See #89. diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java new file mode 100644 index 00000000..2e23120f --- /dev/null +++ b/src/main/java/module-info.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * ThreeTen-Extra provides additional date-time classes that complement those in Java SE 8. + *

    + * Not every piece of date/time logic is destined for the JDK. Some concepts are too + * specialized or too bulky to make it in. This project provides some of those additional + * classes as a well-tested and reliable module. + */ +module org.threeten.extra { + + // export all packages + exports org.threeten.extra; + exports org.threeten.extra.chrono; + exports org.threeten.extra.scale; + +} From f650452a777f9aec0f5e16b1532c61277ea3fd7e Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 8 Jan 2018 18:29:20 +0000 Subject: [PATCH 039/279] Fix issues spotbugs dislikes --- src/main/java/org/threeten/extra/MutableClock.java | 4 ++-- .../java/org/threeten/extra/chrono/BritishCutoverDate.java | 2 ++ src/main/java/org/threeten/extra/chrono/JulianDate.java | 4 ++++ src/main/java/org/threeten/extra/scale/SystemUtcRules.java | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/threeten/extra/MutableClock.java b/src/main/java/org/threeten/extra/MutableClock.java index 433cbe39..d09ecc9b 100644 --- a/src/main/java/org/threeten/extra/MutableClock.java +++ b/src/main/java/org/threeten/extra/MutableClock.java @@ -115,12 +115,12 @@ public final class MutableClock /** * The mutable instant of this clock. */ - private final InstantHolder instantHolder; + private transient final InstantHolder instantHolder; /** * The fixed time-zone of this clock. */ - private final ZoneId zone; + private transient final ZoneId zone; /** * Obtains a new {@code MutableClock} set to the epoch of diff --git a/src/main/java/org/threeten/extra/chrono/BritishCutoverDate.java b/src/main/java/org/threeten/extra/chrono/BritishCutoverDate.java index 3bcdf2c4..fb4eb5a1 100644 --- a/src/main/java/org/threeten/extra/chrono/BritishCutoverDate.java +++ b/src/main/java/org/threeten/extra/chrono/BritishCutoverDate.java @@ -370,6 +370,8 @@ BritishCutoverDate resolvePrevious(int year, int month, int dayOfMonth) { case 11: dayOfMonth = Math.min(dayOfMonth, 30); break; + default: + break; } return create(year, month, dayOfMonth); } diff --git a/src/main/java/org/threeten/extra/chrono/JulianDate.java b/src/main/java/org/threeten/extra/chrono/JulianDate.java index b0d72fd0..9f01ee0a 100644 --- a/src/main/java/org/threeten/extra/chrono/JulianDate.java +++ b/src/main/java/org/threeten/extra/chrono/JulianDate.java @@ -255,6 +255,8 @@ private static JulianDate resolvePreviousValid(int prolepticYear, int month, int case 11: day = Math.min(day, 30); break; + default: + break; } return new JulianDate(prolepticYear, month, day); } @@ -285,6 +287,8 @@ static JulianDate create(int prolepticYear, int month, int dayOfMonth) { case 11: dom = 30; break; + default: + break; } if (dayOfMonth > dom) { if (dayOfMonth == 29) { diff --git a/src/main/java/org/threeten/extra/scale/SystemUtcRules.java b/src/main/java/org/threeten/extra/scale/SystemUtcRules.java index 1c9f65f9..ecd4c1fb 100644 --- a/src/main/java/org/threeten/extra/scale/SystemUtcRules.java +++ b/src/main/java/org/threeten/extra/scale/SystemUtcRules.java @@ -239,7 +239,7 @@ private static Data loadLeapSeconds() { * @throws Exception if an error occurs */ private static Data loadLeapSeconds(URL url) throws ClassNotFoundException, IOException { - List lines = new ArrayList<>(); + List lines; try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8))) { lines = reader.lines().collect(Collectors.toList()); } From 5955c0d1ee4135c94459b9822a741ae9a2649deb Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 8 Jan 2018 19:53:54 +0000 Subject: [PATCH 040/279] Switch from TestNG to Junit 4 --- pom.xml | 12 +- src/changes/changes.xml | 3 + .../java/org/threeten/extra/TestAmPm.java | 44 ++-- .../org/threeten/extra/TestDayOfMonth.java | 65 +++-- .../org/threeten/extra/TestDayOfYear.java | 74 ++++-- .../java/org/threeten/extra/TestDays.java | 116 +++++--- .../java/org/threeten/extra/TestHours.java | 94 ++++--- .../java/org/threeten/extra/TestInterval.java | 128 ++++++--- .../threeten/extra/TestLocalDateRange.java | 173 ++++++++---- .../java/org/threeten/extra/TestMinutes.java | 96 ++++--- .../java/org/threeten/extra/TestMonths.java | 114 +++++--- .../org/threeten/extra/TestMutableClock.java | 42 ++- .../org/threeten/extra/TestPackedFields.java | 42 ++- .../threeten/extra/TestPeriodDuration.java | 88 +++++-- .../java/org/threeten/extra/TestQuarter.java | 66 ++--- .../java/org/threeten/extra/TestSeconds.java | 99 ++++--- .../org/threeten/extra/TestTemporals.java | 75 +++--- .../java/org/threeten/extra/TestWeeks.java | 100 ++++--- .../org/threeten/extra/TestYearQuarter.java | 131 +++++---- .../java/org/threeten/extra/TestYearWeek.java | 149 +++++++---- .../java/org/threeten/extra/TestYears.java | 101 ++++--- .../chrono/TestAccountingChronology.java | 146 +++++----- .../TestAccountingChronologyBuilder.java | 94 ++++--- .../chrono/TestBritishCutoverChronology.java | 172 +++++++----- .../extra/chrono/TestCopticChronology.java | 132 ++++++---- .../chrono/TestDiscordianChronology.java | 166 +++++++----- .../extra/chrono/TestEthiopicChronology.java | 139 ++++++---- .../TestInternationalFixedChronology.java | 208 ++++++++------- .../extra/chrono/TestJulianChronology.java | 134 ++++++---- .../extra/chrono/TestPaxChronology.java | 159 ++++++----- .../chrono/TestSymmetry010Chronology.java | 245 +++++++++-------- .../chrono/TestSymmetry454Chronology.java | 249 ++++++++++-------- .../threeten/extra/scale/TestTaiInstant.java | 85 +++--- .../threeten/extra/scale/TestUtcInstant.java | 103 ++++---- .../threeten/extra/scale/TestUtcRules.java | 71 +++-- 35 files changed, 2407 insertions(+), 1508 deletions(-) diff --git a/pom.xml b/pom.xml index 59ced5e1..357213c4 100644 --- a/pom.xml +++ b/pom.xml @@ -457,9 +457,15 @@ test - org.testng - testng - 6.10 + junit + junit + 4.12 + test + + + com.tngtech.java + junit-dataprovider + 1.10.0 test diff --git a/src/changes/changes.xml b/src/changes/changes.xml index df97932a..c4157b25 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -12,6 +12,9 @@ Support Java 9. Update and redesign build. + + Switch from TestNG to JUnit 4. + Error message and Javadoc fixes in Interval. See #89. diff --git a/src/test/java/org/threeten/extra/TestAmPm.java b/src/test/java/org/threeten/extra/TestAmPm.java index 3c1a6ee3..44748c41 100644 --- a/src/test/java/org/threeten/extra/TestAmPm.java +++ b/src/test/java/org/threeten/extra/TestAmPm.java @@ -62,8 +62,8 @@ import static java.time.temporal.ChronoField.YEAR; import static java.time.temporal.ChronoField.YEAR_OF_ERA; import static java.time.temporal.ChronoUnit.HALF_DAYS; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.io.Serializable; import java.time.DateTimeException; @@ -75,19 +75,13 @@ import java.time.temporal.UnsupportedTemporalTypeException; import java.util.Locale; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.Test; /** * Test AmPm. */ -@Test public class TestAmPm { - @BeforeMethod - public void setUp() { - } - //----------------------------------------------------------------------- @Test public void test_interfaces() { @@ -108,12 +102,12 @@ public void test_of_int_singleton_equals() { } } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_int_valueTooLow() { AmPm.of(-1); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_int_valueTooHigh() { AmPm.of(2); } @@ -131,12 +125,12 @@ public void test_ofHour_int_singleton() { } } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_ofHour_int_valueTooLow() { AmPm.ofHour(-1); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_ofHour_int_valueTooHigh() { AmPm.ofHour(24); } @@ -150,12 +144,12 @@ public void test_from_TemporalAccessor() { assertEquals(AmPm.from(LocalTime.of(17, 30)), AmPm.PM); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_from_TemporalAccessor_invalid_noDerive() { AmPm.from(LocalDate.of(2007, 7, 30)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_from_TemporalAccessor_null() { AmPm.from((TemporalAccessor) null); } @@ -168,12 +162,12 @@ public void test_getDisplayName() { assertEquals(AmPm.AM.getDisplayName(TextStyle.SHORT, Locale.US), "AM"); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_getDisplayName_nullStyle() { AmPm.AM.getDisplayName(null, Locale.US); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_getDisplayName_nullLocale() { AmPm.AM.getDisplayName(TextStyle.FULL, null); } @@ -181,6 +175,7 @@ public void test_getDisplayName_nullLocale() { //----------------------------------------------------------------------- // isSupported() //----------------------------------------------------------------------- + @Test public void test_isSupported() { AmPm test = AmPm.AM; assertEquals(test.isSupported(null), false); @@ -219,16 +214,17 @@ public void test_isSupported() { //----------------------------------------------------------------------- // range() //----------------------------------------------------------------------- + @Test public void test_range() { assertEquals(AmPm.AM.range(AMPM_OF_DAY), AMPM_OF_DAY.range()); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_range_invalidField() { AmPm.AM.range(MONTH_OF_YEAR); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_range_null() { AmPm.AM.range(null); } @@ -236,17 +232,18 @@ public void test_range_null() { //----------------------------------------------------------------------- // get() //----------------------------------------------------------------------- + @Test public void test_get() { assertEquals(AmPm.AM.get(AMPM_OF_DAY), 0); assertEquals(AmPm.PM.get(AMPM_OF_DAY), 1); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_get_invalidField() { AmPm.PM.get(MONTH_OF_YEAR); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_get_null() { AmPm.PM.get(null); } @@ -254,17 +251,18 @@ public void test_get_null() { //----------------------------------------------------------------------- // getLong() //----------------------------------------------------------------------- + @Test public void test_getLong() { assertEquals(AmPm.AM.getLong(AMPM_OF_DAY), 0); assertEquals(AmPm.PM.getLong(AMPM_OF_DAY), 1); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_getLong_invalidField() { AmPm.PM.getLong(MONTH_OF_YEAR); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_getLong_null() { AmPm.PM.getLong(null); } diff --git a/src/test/java/org/threeten/extra/TestDayOfMonth.java b/src/test/java/org/threeten/extra/TestDayOfMonth.java index 42ec6df6..e3e038d0 100644 --- a/src/test/java/org/threeten/extra/TestDayOfMonth.java +++ b/src/test/java/org/threeten/extra/TestDayOfMonth.java @@ -73,8 +73,8 @@ import static java.time.temporal.ChronoField.SECOND_OF_MINUTE; import static java.time.temporal.ChronoField.YEAR; import static java.time.temporal.ChronoField.YEAR_OF_ERA; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -100,24 +100,19 @@ import java.time.temporal.TemporalQueries; import java.time.temporal.UnsupportedTemporalTypeException; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.Test; /** * Test DayOfMonth. */ -@Test public class TestDayOfMonth { private static final int MAX_LENGTH = 31; private static final DayOfMonth TEST = DayOfMonth.of(12); private static final ZoneId PARIS = ZoneId.of("Europe/Paris"); - @BeforeMethod - public void setUp() { - } - //----------------------------------------------------------------------- + @Test public void test_interfaces() { assertTrue(Serializable.class.isAssignableFrom(DayOfMonth.class)); assertTrue(Comparable.class.isAssignableFrom(DayOfMonth.class)); @@ -125,6 +120,7 @@ public void test_interfaces() { assertTrue(TemporalAccessor.class.isAssignableFrom(DayOfMonth.class)); } + @Test public void test_serialization() throws IOException, ClassNotFoundException { DayOfMonth test = DayOfMonth.of(1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -139,6 +135,7 @@ public void test_serialization() throws IOException, ClassNotFoundException { //----------------------------------------------------------------------- // of(int) //----------------------------------------------------------------------- + @Test public void test_of_int_singleton() { for (int i = 1; i <= MAX_LENGTH; i++) { DayOfMonth test = DayOfMonth.of(i); @@ -147,12 +144,12 @@ public void test_of_int_singleton() { } } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_int_tooLow() { DayOfMonth.of(0); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_int_tooHigh() { DayOfMonth.of(32); } @@ -160,6 +157,7 @@ public void test_of_int_tooHigh() { //----------------------------------------------------------------------- // from(TemporalAccessor) //----------------------------------------------------------------------- + @Test public void test_from_TemporalAccessor_notLeapYear() { LocalDate date = LocalDate.of(2007, 1, 1); for (int i = 1; i <= 31; i++) { // Jan @@ -212,6 +210,7 @@ public void test_from_TemporalAccessor_notLeapYear() { } } + @Test public void test_from_TemporalAccessor_leapYear() { LocalDate date = LocalDate.of(2008, 1, 1); for (int i = 1; i <= 31; i++) { // Jan @@ -228,16 +227,17 @@ public void test_from_TemporalAccessor_leapYear() { } } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_from_TemporalAccessor_noDerive() { DayOfMonth.from(LocalTime.NOON); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_from_TemporalAccessor_null() { DayOfMonth.from((TemporalAccessor) null); } + @Test public void test_from_parse_CharSequence() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d"); assertEquals(formatter.parse("3", DayOfMonth::from), DayOfMonth.of(3)); @@ -246,6 +246,7 @@ public void test_from_parse_CharSequence() { //----------------------------------------------------------------------- // isSupported(TemporalField) //----------------------------------------------------------------------- + @Test public void test_isSupported() { assertEquals(TEST.isSupported((TemporalField) null), false); assertEquals(TEST.isSupported(NANO_OF_SECOND), false); @@ -283,16 +284,17 @@ public void test_isSupported() { //----------------------------------------------------------------------- // range(TemporalField) //----------------------------------------------------------------------- + @Test public void test_range() { assertEquals(TEST.range(DAY_OF_MONTH), DAY_OF_MONTH.range()); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_range_invalidField() { TEST.range(MONTH_OF_YEAR); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_range_null() { TEST.range((TemporalField) null); } @@ -300,16 +302,17 @@ public void test_range_null() { //----------------------------------------------------------------------- // get(TemporalField) //----------------------------------------------------------------------- + @Test public void test_get() { assertEquals(TEST.get(DAY_OF_MONTH), 12); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_get_invalidField() { TEST.get(MONTH_OF_YEAR); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_get_null() { TEST.get((TemporalField) null); } @@ -317,16 +320,17 @@ public void test_get_null() { //----------------------------------------------------------------------- // getLong(TemporalField) //----------------------------------------------------------------------- + @Test public void test_getLong() { assertEquals(TEST.getLong(DAY_OF_MONTH), 12L); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_getLong_invalidField() { TEST.getLong(MONTH_OF_YEAR); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_getLong_null() { TEST.getLong((TemporalField) null); } @@ -420,6 +424,7 @@ public void test_query() { //----------------------------------------------------------------------- // adjustInto(Temporal) //----------------------------------------------------------------------- + @Test public void test_adjustInto() { LocalDate base = LocalDate.of(2007, 1, 1); LocalDate expected = base; @@ -430,21 +435,21 @@ public void test_adjustInto() { } } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_adjustInto_april31() { LocalDate base = LocalDate.of(2007, 4, 1); DayOfMonth test = DayOfMonth.of(31); test.adjustInto(base); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_adjustInto_february29_notLeapYear() { LocalDate base = LocalDate.of(2007, 2, 1); DayOfMonth test = DayOfMonth.of(29); test.adjustInto(base); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_adjustInto_null() { TEST.adjustInto((Temporal) null); } @@ -486,7 +491,7 @@ public void test_atMonth_Month_28() { assertEquals(test.atMonth(DECEMBER), MonthDay.of(12, 28)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_atMonth_null() { TEST.atMonth((Month) null); } @@ -528,12 +533,12 @@ public void test_atMonth_int_28() { assertEquals(test.atMonth(12), MonthDay.of(12, 28)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_atMonth_tooLow() { TEST.atMonth(0); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_atMonth_tooHigh() { TEST.atMonth(13); } @@ -576,7 +581,7 @@ public void test_atYearMonth_28() { assertEquals(test.atYearMonth(YearMonth.of(2012, 12)), LocalDate.of(2012, 12, 28)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_atYearMonth_null() { TEST.atYearMonth((YearMonth) null); } @@ -584,6 +589,7 @@ public void test_atYearMonth_null() { //----------------------------------------------------------------------- // compareTo() //----------------------------------------------------------------------- + @Test public void test_compareTo() { for (int i = 1; i <= MAX_LENGTH; i++) { DayOfMonth a = DayOfMonth.of(i); @@ -603,7 +609,7 @@ public void test_compareTo() { } } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_compareTo_nullDayOfMonth() { DayOfMonth doy = null; DayOfMonth test = DayOfMonth.of(1); @@ -613,6 +619,7 @@ public void test_compareTo_nullDayOfMonth() { //----------------------------------------------------------------------- // equals() / hashCode() //----------------------------------------------------------------------- + @Test public void test_equals() { for (int i = 1; i <= MAX_LENGTH; i++) { DayOfMonth a = DayOfMonth.of(i); @@ -624,12 +631,14 @@ public void test_equals() { } } + @Test public void test_equals_nullDayOfMonth() { DayOfMonth doy = null; DayOfMonth test = DayOfMonth.of(1); assertEquals(test.equals(doy), false); } + @Test public void test_equals_incorrectType() { DayOfMonth test = DayOfMonth.of(1); assertEquals(test.equals("Incorrect type"), false); @@ -638,6 +647,7 @@ public void test_equals_incorrectType() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- + @Test public void test_toString() { for (int i = 1; i <= MAX_LENGTH; i++) { DayOfMonth a = DayOfMonth.of(i); @@ -648,6 +658,7 @@ public void test_toString() { //----------------------------------------------------------------------- // now(Clock) //----------------------------------------------------------------------- + @Test public void test_now_clock() { for (int i = 1; i <= 31; i++) { // Jan Instant instant = LocalDate.of(2008, 1, i).atStartOfDay(PARIS).toInstant(); diff --git a/src/test/java/org/threeten/extra/TestDayOfYear.java b/src/test/java/org/threeten/extra/TestDayOfYear.java index aebef97f..3340af52 100644 --- a/src/test/java/org/threeten/extra/TestDayOfYear.java +++ b/src/test/java/org/threeten/extra/TestDayOfYear.java @@ -61,8 +61,8 @@ import static java.time.temporal.ChronoField.SECOND_OF_MINUTE; import static java.time.temporal.ChronoField.YEAR; import static java.time.temporal.ChronoField.YEAR_OF_ERA; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -86,13 +86,11 @@ import java.time.temporal.TemporalQueries; import java.time.temporal.UnsupportedTemporalTypeException; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.Test; /** * Test DayOfYear. */ -@Test public class TestDayOfYear { private static final Year YEAR_STANDARD = Year.of(2007); @@ -102,11 +100,8 @@ public class TestDayOfYear { private static final DayOfYear TEST = DayOfYear.of(12); private static final ZoneId PARIS = ZoneId.of("Europe/Paris"); - @BeforeMethod - public void setUp() { - } - //----------------------------------------------------------------------- + @Test public void test_interfaces() { assertTrue(Serializable.class.isAssignableFrom(DayOfYear.class)); assertTrue(Comparable.class.isAssignableFrom(DayOfYear.class)); @@ -114,6 +109,7 @@ public void test_interfaces() { assertTrue(TemporalAccessor.class.isAssignableFrom(DayOfYear.class)); } + @Test public void test_serialization() throws IOException, ClassNotFoundException { DayOfYear test = DayOfYear.of(1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -128,6 +124,7 @@ public void test_serialization() throws IOException, ClassNotFoundException { //----------------------------------------------------------------------- // of(int) //----------------------------------------------------------------------- + @Test public void test_of_int() { for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) { DayOfYear test = DayOfYear.of(i); @@ -136,12 +133,12 @@ public void test_of_int() { } } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_int_tooLow() { DayOfYear.of(0); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_int_tooHigh() { DayOfYear.of(367); } @@ -149,6 +146,7 @@ public void test_of_int_tooHigh() { //----------------------------------------------------------------------- // from(TemporalAccessor) //----------------------------------------------------------------------- + @Test public void test_from_TemporalAccessor_notLeapYear() { LocalDate date = LocalDate.of(2007, 1, 1); for (int i = 1; i <= STANDARD_YEAR_LENGTH; i++) { @@ -160,6 +158,7 @@ public void test_from_TemporalAccessor_notLeapYear() { assertEquals(test.getValue(), 1); } + @Test public void test_from_TemporalAccessor_leapYear() { LocalDate date = LocalDate.of(2008, 1, 1); for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) { @@ -169,16 +168,17 @@ public void test_from_TemporalAccessor_leapYear() { } } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_from_TemporalAccessor_noDerive() { DayOfYear.from(LocalTime.NOON); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_from_TemporalAccessor_null() { DayOfYear.from((TemporalAccessor) null); } + @Test public void test_from_parse_CharSequence() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("D"); assertEquals(formatter.parse("76", DayOfYear::from), DayOfYear.of(76)); @@ -187,6 +187,7 @@ public void test_from_parse_CharSequence() { //----------------------------------------------------------------------- // isSupported(TemporalField) //----------------------------------------------------------------------- + @Test public void test_isSupported() { assertEquals(TEST.isSupported((TemporalField) null), false); assertEquals(TEST.isSupported(NANO_OF_SECOND), false); @@ -224,16 +225,17 @@ public void test_isSupported() { //----------------------------------------------------------------------- // range(TemporalField) //----------------------------------------------------------------------- + @Test public void test_range() { assertEquals(TEST.range(DAY_OF_YEAR), DAY_OF_YEAR.range()); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_range_invalidField() { TEST.range(MONTH_OF_YEAR); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_range_null() { TEST.range((TemporalField) null); } @@ -241,16 +243,17 @@ public void test_range_null() { //----------------------------------------------------------------------- // get(TemporalField) //----------------------------------------------------------------------- + @Test public void test_get() { assertEquals(TEST.get(DAY_OF_YEAR), 12); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_get_invalidField() { TEST.get(MONTH_OF_YEAR); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_get_null() { TEST.get((TemporalField) null); } @@ -258,16 +261,17 @@ public void test_get_null() { //----------------------------------------------------------------------- // getLong(TemporalField) //----------------------------------------------------------------------- + @Test public void test_getLong() { assertEquals(TEST.getLong(DAY_OF_YEAR), 12L); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_getLong_invalidField() { TEST.getLong(MONTH_OF_YEAR); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_getLong_null() { TEST.getLong((TemporalField) null); } @@ -283,6 +287,7 @@ public void test_isValidYearMonth_366() { assertEquals(test.isValidYear(2013), false); } + @Test public void test_isValidYearMonth_365() { DayOfYear test = DayOfYear.of(365); assertEquals(test.isValidYear(2011), true); @@ -307,6 +312,7 @@ public void test_query() { //----------------------------------------------------------------------- // adjustInto(Temporal) //----------------------------------------------------------------------- + @Test public void test_adjustInto_fromStartOfYear_notLeapYear() { LocalDate base = LocalDate.of(2007, 1, 1); LocalDate expected = base; @@ -317,6 +323,7 @@ public void test_adjustInto_fromStartOfYear_notLeapYear() { } } + @Test public void test_adjustInto_fromEndOfYear_notLeapYear() { LocalDate base = LocalDate.of(2007, 12, 31); LocalDate expected = LocalDate.of(2007, 1, 1); @@ -327,20 +334,21 @@ public void test_adjustInto_fromEndOfYear_notLeapYear() { } } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_adjustInto_fromStartOfYear_notLeapYear_day366() { LocalDate base = LocalDate.of(2007, 1, 1); DayOfYear test = DayOfYear.of(LEAP_YEAR_LENGTH); test.adjustInto(base); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_adjustInto_fromEndOfYear_notLeapYear_day366() { LocalDate base = LocalDate.of(2007, 12, 31); DayOfYear test = DayOfYear.of(LEAP_YEAR_LENGTH); test.adjustInto(base); } + @Test public void test_adjustInto_fromStartOfYear_leapYear() { LocalDate base = LocalDate.of(2008, 1, 1); LocalDate expected = base; @@ -351,6 +359,7 @@ public void test_adjustInto_fromStartOfYear_leapYear() { } } + @Test public void test_adjustInto_fromEndOfYear_leapYear() { LocalDate base = LocalDate.of(2008, 12, 31); LocalDate expected = LocalDate.of(2008, 1, 1); @@ -361,7 +370,7 @@ public void test_adjustInto_fromEndOfYear_leapYear() { } } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_adjustInto_null() { TEST.adjustInto((Temporal) null); } @@ -369,6 +378,7 @@ public void test_adjustInto_null() { //----------------------------------------------------------------------- // atYear(Year) //----------------------------------------------------------------------- + @Test public void test_atYear_Year_notLeapYear() { LocalDate expected = LocalDate.of(2007, 1, 1); for (int i = 1; i <= STANDARD_YEAR_LENGTH; i++) { @@ -378,12 +388,13 @@ public void test_atYear_Year_notLeapYear() { } } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_atYear_fromStartOfYear_notLeapYear_day366() { DayOfYear test = DayOfYear.of(LEAP_YEAR_LENGTH); test.atYear(YEAR_STANDARD); } + @Test public void test_atYear_Year_leapYear() { LocalDate expected = LocalDate.of(2008, 1, 1); for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) { @@ -393,7 +404,7 @@ public void test_atYear_Year_leapYear() { } } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_atYear_Year_nullYear() { TEST.atYear((Year) null); } @@ -401,6 +412,7 @@ public void test_atYear_Year_nullYear() { //----------------------------------------------------------------------- // atYear(int) //----------------------------------------------------------------------- + @Test public void test_atYear_int_notLeapYear() { LocalDate expected = LocalDate.of(2007, 1, 1); for (int i = 1; i <= STANDARD_YEAR_LENGTH; i++) { @@ -410,12 +422,13 @@ public void test_atYear_int_notLeapYear() { } } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_atYear_int_fromStartOfYear_notLeapYear_day366() { DayOfYear test = DayOfYear.of(LEAP_YEAR_LENGTH); test.atYear(2007); } + @Test public void test_atYear_int_leapYear() { LocalDate expected = LocalDate.of(2008, 1, 1); for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) { @@ -425,7 +438,7 @@ public void test_atYear_int_leapYear() { } } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_atYear_int_invalidDay() { TEST.atYear(Year.MIN_VALUE - 1); } @@ -433,6 +446,7 @@ public void test_atYear_int_invalidDay() { //----------------------------------------------------------------------- // compareTo() //----------------------------------------------------------------------- + @Test public void test_compareTo() { for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) { DayOfYear a = DayOfYear.of(i); @@ -452,7 +466,7 @@ public void test_compareTo() { } } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_compareTo_nullDayOfYear() { DayOfYear doy = null; DayOfYear test = DayOfYear.of(1); @@ -462,6 +476,7 @@ public void test_compareTo_nullDayOfYear() { //----------------------------------------------------------------------- // equals() / hashCode() //----------------------------------------------------------------------- + @Test public void test_equals() { for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) { DayOfYear a = DayOfYear.of(i); @@ -473,12 +488,14 @@ public void test_equals() { } } + @Test public void test_equals_nullDayOfYear() { DayOfYear doy = null; DayOfYear test = DayOfYear.of(1); assertEquals(test.equals(doy), false); } + @Test public void test_equals_incorrectType() { DayOfYear test = DayOfYear.of(1); assertEquals(test.equals("Incorrect type"), false); @@ -487,6 +504,7 @@ public void test_equals_incorrectType() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- + @Test public void test_toString() { for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) { DayOfYear a = DayOfYear.of(i); @@ -497,6 +515,7 @@ public void test_toString() { //----------------------------------------------------------------------- // now(Clock) //----------------------------------------------------------------------- + @Test public void test_now_clock_notLeapYear() { LocalDate date = LocalDate.of(2007, 1, 1); for (int i = 1; i <= STANDARD_YEAR_LENGTH; i++) { @@ -508,6 +527,7 @@ public void test_now_clock_notLeapYear() { } } + @Test public void test_now_clock_leapYear() { LocalDate date = LocalDate.of(2008, 1, 1); for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) { diff --git a/src/test/java/org/threeten/extra/TestDays.java b/src/test/java/org/threeten/extra/TestDays.java index 66d3dd43..abe73cc1 100644 --- a/src/test/java/org/threeten/extra/TestDays.java +++ b/src/test/java/org/threeten/extra/TestDays.java @@ -31,9 +31,9 @@ */ package org.threeten.extra; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertSame; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -46,21 +46,27 @@ import java.time.format.DateTimeParseException; import java.time.temporal.TemporalAmount; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test class. */ -@Test +@RunWith(DataProviderRunner.class) public class TestDays { //----------------------------------------------------------------------- + @Test public void test_isSerializable() { assertTrue(Serializable.class.isAssignableFrom(Days.class)); } //----------------------------------------------------------------------- + @Test public void test_deserializationSingleton() throws Exception { Days test = Days.ZERO; ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -73,12 +79,14 @@ public void test_deserializationSingleton() throws Exception { } //----------------------------------------------------------------------- + @Test public void test_ZERO() { assertSame(Days.of(0), Days.ZERO); assertSame(Days.of(0), Days.ZERO); assertEquals(Days.ZERO.getAmount(), 0); } + @Test public void test_ONE() { assertSame(Days.of(1), Days.ONE); assertSame(Days.of(1), Days.ONE); @@ -86,6 +94,7 @@ public void test_ONE() { } //----------------------------------------------------------------------- + @Test public void test_of() { assertEquals(Days.of(0).getAmount(), 0); assertEquals(Days.of(1).getAmount(), 1); @@ -97,6 +106,7 @@ public void test_of() { } //----------------------------------------------------------------------- + @Test public void test_ofWeeks() { assertEquals(Days.ofWeeks(0).getAmount(), 0); assertEquals(Days.ofWeeks(1).getAmount(), 7); @@ -107,50 +117,55 @@ public void test_ofWeeks() { assertEquals(Days.ofWeeks(Integer.MIN_VALUE / 7).getAmount(), (Integer.MIN_VALUE / 7) * 7); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_ofWeeks_overflow() { Days.ofWeeks((Integer.MAX_VALUE / 7) + 7); } //----------------------------------------------------------------------- + @Test public void test_from_Period_P0D() { assertEquals(Days.from(Period.ofDays(0)), Days.of(0)); } + @Test public void test_from_Period_P2D() { assertEquals(Days.from(Period.ofDays(2)), Days.of(2)); } + @Test public void test_from_P2W() { assertEquals(Days.from(new MockWeeksDays(2, 0)), Days.of(14)); } + @Test public void test_from_P2W3D() { assertEquals(Days.from(new MockWeeksDays(2, 3)), Days.of(17)); } + @Test public void test_from_Duration() { assertEquals(Days.from(Duration.ofDays(2)), Days.of(2)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_from_wrongUnit_remainder() { Days.from(Duration.ofHours(3)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_from_wrongUnit_noConversion() { Days.from(Period.ofMonths(2)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_from_null() { Days.from((TemporalAmount) null); } //----------------------------------------------------------------------- - @DataProvider(name = "parseValid") - Object[][] data_valid() { + @DataProvider + public static Object[][] data_valid() { return new Object[][] { {"P0D", 0}, {"P1D", 1}, @@ -180,23 +195,26 @@ Object[][] data_valid() { }; } - @Test(dataProvider = "parseValid") + @Test + @UseDataProvider("data_valid") public void test_parse_CharSequence_valid(String str, int expectedDays) { assertEquals(Days.parse(str), Days.of(expectedDays)); } - @Test(dataProvider = "parseValid") + @Test + @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, int expectedDays) { assertEquals(Days.parse("+" + str), Days.of(expectedDays)); } - @Test(dataProvider = "parseValid") + @Test + @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, int expectedDays) { assertEquals(Days.parse("-" + str), Days.of(-expectedDays)); } - @DataProvider(name = "parseInvalid") - Object[][] data_invalid() { + @DataProvider + public static Object[][] data_invalid() { return new Object[][] { {"P3Y"}, {"P3M"}, @@ -215,17 +233,19 @@ Object[][] data_invalid() { }; } - @Test(expectedExceptions = DateTimeParseException.class, dataProvider = "parseInvalid") + @Test(expected = DateTimeParseException.class) + @UseDataProvider("data_invalid") public void test_parse_CharSequence_invalid(String str) { Days.parse(str); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_parse_CharSequence_null() { Days.parse((CharSequence) null); } //----------------------------------------------------------------------- + @Test public void test_plus_TemporalAmount_Days() { Days test5 = Days.of(5); assertEquals(Days.of(5), test5.plus(Days.of(0))); @@ -235,6 +255,7 @@ public void test_plus_TemporalAmount_Days() { assertEquals(Days.of(Integer.MIN_VALUE), Days.of(Integer.MIN_VALUE + 1).plus(Days.of(-1))); } + @Test public void test_plus_TemporalAmount_Period() { Days test5 = Days.of(5); assertEquals(Days.of(5), test5.plus(Period.ofDays(0))); @@ -244,32 +265,33 @@ public void test_plus_TemporalAmount_Period() { assertEquals(Days.of(Integer.MIN_VALUE), Days.of(Integer.MIN_VALUE + 1).plus(Period.ofDays(-1))); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_plus_TemporalAmount_PeriodYears() { Days.of(1).plus(Period.ofYears(2)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_plus_TemporalAmount_Duration() { Days.of(1).plus(Duration.ofHours(2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_TemporalAmount_overflowTooBig() { Days.of(Integer.MAX_VALUE - 1).plus(Days.of(2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_TemporalAmount_overflowTooSmall() { Days.of(Integer.MIN_VALUE + 1).plus(Days.of(-2)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_plus_TemporalAmount_null() { Days.of(Integer.MIN_VALUE + 1).plus(null); } //----------------------------------------------------------------------- + @Test public void test_plus_int() { Days test5 = Days.of(5); assertEquals(Days.of(5), test5.plus(0)); @@ -279,17 +301,18 @@ public void test_plus_int() { assertEquals(Days.of(Integer.MIN_VALUE), Days.of(Integer.MIN_VALUE + 1).plus(-1)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_int_overflowTooBig() { Days.of(Integer.MAX_VALUE - 1).plus(2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_int_overflowTooSmall() { Days.of(Integer.MIN_VALUE + 1).plus(-2); } //----------------------------------------------------------------------- + @Test public void test_minus_TemporalAmount_Days() { Days test5 = Days.of(5); assertEquals(Days.of(5), test5.minus(Days.of(0))); @@ -299,6 +322,7 @@ public void test_minus_TemporalAmount_Days() { assertEquals(Days.of(Integer.MIN_VALUE), Days.of(Integer.MIN_VALUE + 1).minus(Days.of(1))); } + @Test public void test_minus_TemporalAmount_Period() { Days test5 = Days.of(5); assertEquals(Days.of(5), test5.minus(Period.ofDays(0))); @@ -308,32 +332,33 @@ public void test_minus_TemporalAmount_Period() { assertEquals(Days.of(Integer.MIN_VALUE), Days.of(Integer.MIN_VALUE + 1).minus(Period.ofDays(1))); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_minus_TemporalAmount_PeriodYears() { Days.of(1).minus(Period.ofYears(2)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_minus_TemporalAmount_Duration() { Days.of(1).minus(Duration.ofHours(2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_TemporalAmount_overflowTooBig() { Days.of(Integer.MAX_VALUE - 1).minus(Days.of(-2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_TemporalAmount_overflowTooSmall() { Days.of(Integer.MIN_VALUE + 1).minus(Days.of(2)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_minus_TemporalAmount_null() { Days.of(Integer.MIN_VALUE + 1).minus(null); } //----------------------------------------------------------------------- + @Test public void test_minus_int() { Days test5 = Days.of(5); assertEquals(Days.of(5), test5.minus(0)); @@ -343,17 +368,18 @@ public void test_minus_int() { assertEquals(Days.of(Integer.MIN_VALUE), Days.of(Integer.MIN_VALUE + 1).minus(1)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_int_overflowTooBig() { Days.of(Integer.MAX_VALUE - 1).minus(-2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_int_overflowTooSmall() { Days.of(Integer.MIN_VALUE + 1).minus(2); } //----------------------------------------------------------------------- + @Test public void test_multipliedBy() { Days test5 = Days.of(5); assertEquals(Days.of(0), test5.multipliedBy(0)); @@ -363,22 +389,24 @@ public void test_multipliedBy() { assertEquals(Days.of(-15), test5.multipliedBy(-3)); } + @Test public void test_multipliedBy_negate() { Days test5 = Days.of(5); assertEquals(Days.of(-15), test5.multipliedBy(-3)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_multipliedBy_overflowTooBig() { Days.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_multipliedBy_overflowTooSmall() { Days.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2); } //----------------------------------------------------------------------- + @Test public void test_dividedBy() { Days test12 = Days.of(12); assertEquals(Days.of(12), test12.dividedBy(1)); @@ -390,17 +418,19 @@ public void test_dividedBy() { assertEquals(Days.of(-4), test12.dividedBy(-3)); } + @Test public void test_dividedBy_negate() { Days test12 = Days.of(12); assertEquals(Days.of(-4), test12.dividedBy(-3)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_dividedBy_divideByZero() { Days.of(1).dividedBy(0); } //----------------------------------------------------------------------- + @Test public void test_negated() { assertEquals(Days.of(0), Days.of(0).negated()); assertEquals(Days.of(-12), Days.of(12).negated()); @@ -408,12 +438,13 @@ public void test_negated() { assertEquals(Days.of(-Integer.MAX_VALUE), Days.of(Integer.MAX_VALUE).negated()); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_negated_overflow() { Days.of(Integer.MIN_VALUE).negated(); } //----------------------------------------------------------------------- + @Test public void test_abs() { assertEquals(Days.of(0), Days.of(0).abs()); assertEquals(Days.of(12), Days.of(12).abs()); @@ -422,12 +453,13 @@ public void test_abs() { assertEquals(Days.of(Integer.MAX_VALUE), Days.of(-Integer.MAX_VALUE).abs()); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_abs_overflow() { Days.of(Integer.MIN_VALUE).abs(); } //----------------------------------------------------------------------- + @Test public void test_toPeriod() { for (int i = -20; i < 20; i++) { assertEquals(Days.of(i).toPeriod(), Period.ofDays(i)); @@ -435,6 +467,7 @@ public void test_toPeriod() { } //----------------------------------------------------------------------- + @Test public void test_compareTo() { Days test5 = Days.of(5); Days test6 = Days.of(6); @@ -443,13 +476,14 @@ public void test_compareTo() { assertEquals(1, test6.compareTo(test5)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_compareTo_null() { Days test5 = Days.of(5); test5.compareTo(null); } //----------------------------------------------------------------------- + @Test public void test_equals() { Days test5 = Days.of(5); Days test6 = Days.of(6); @@ -458,17 +492,20 @@ public void test_equals() { assertEquals(false, test6.equals(test5)); } + @Test public void test_equals_null() { Days test5 = Days.of(5); assertEquals(false, test5.equals(null)); } + @Test public void test_equals_otherClass() { Days test5 = Days.of(5); assertEquals(false, test5.equals("")); } //----------------------------------------------------------------------- + @Test public void test_hashCode() { Days test5 = Days.of(5); Days test6 = Days.of(6); @@ -477,6 +514,7 @@ public void test_hashCode() { } //----------------------------------------------------------------------- + @Test public void test_toString() { Days test5 = Days.of(5); assertEquals("P5D", test5.toString()); diff --git a/src/test/java/org/threeten/extra/TestHours.java b/src/test/java/org/threeten/extra/TestHours.java index 6dc1a8be..7278e199 100644 --- a/src/test/java/org/threeten/extra/TestHours.java +++ b/src/test/java/org/threeten/extra/TestHours.java @@ -31,9 +31,9 @@ */ package org.threeten.extra; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertSame; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -44,21 +44,27 @@ import java.time.LocalTime; import java.time.format.DateTimeParseException; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test class. */ -@Test +@RunWith(DataProviderRunner.class) public class TestHours { //----------------------------------------------------------------------- + @Test public void test_isSerializable() { assertTrue(Serializable.class.isAssignableFrom(Hours.class)); } //----------------------------------------------------------------------- + @Test public void test_deserializationSingleton() throws Exception { Hours test = Hours.ZERO; ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -71,6 +77,7 @@ public void test_deserializationSingleton() throws Exception { } //----------------------------------------------------------------------- + @Test public void test_ZERO() { assertSame(Hours.of(0), Hours.ZERO); assertSame(Hours.of(0), Hours.ZERO); @@ -78,6 +85,7 @@ public void test_ZERO() { } //----------------------------------------------------------------------- + @Test public void test_of() { assertEquals(Hours.of(0).getAmount(), 0); assertEquals(Hours.of(1).getAmount(), 1); @@ -89,8 +97,8 @@ public void test_of() { } //----------------------------------------------------------------------- - @DataProvider(name = "parseValid") - Object[][] data_valid() { + @DataProvider + public static Object[][] data_valid() { return new Object[][] { {"PT0H", 0}, {"PT1H", 1}, @@ -115,23 +123,26 @@ Object[][] data_valid() { }; } - @Test(dataProvider = "parseValid") + @Test + @UseDataProvider("data_valid") public void test_parse_CharSequence_valid(String str, int expectedDays) { assertEquals(Hours.parse(str), Hours.of(expectedDays)); } - @Test(dataProvider = "parseValid") + @Test + @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, int expectedDays) { assertEquals(Hours.parse("+" + str), Hours.of(expectedDays)); } - @Test(dataProvider = "parseValid") + @Test + @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, int expectedDays) { assertEquals(Hours.parse("-" + str), Hours.of(-expectedDays)); } - @DataProvider(name = "parseInvalid") - Object[][] data_invalid() { + @DataProvider + public static Object[][] data_invalid() { return new Object[][] { {"P3W"}, {"P3Q"}, @@ -150,17 +161,19 @@ Object[][] data_invalid() { }; } - @Test(expectedExceptions = DateTimeParseException.class, dataProvider = "parseInvalid") + @Test(expected = DateTimeParseException.class) + @UseDataProvider("data_invalid") public void test_parse_CharSequence_invalid(String str) { Hours.parse(str); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_parse_CharSequence_null() { Hours.parse((CharSequence) null); } //----------------------------------------------------------------------- + @Test public void test_plus_TemporalAmount_Hours() { Hours test5 = Hours.of(5); assertEquals(Hours.of(5), test5.plus(Hours.of(0))); @@ -170,6 +183,7 @@ public void test_plus_TemporalAmount_Hours() { assertEquals(Hours.of(Integer.MIN_VALUE), Hours.of(Integer.MIN_VALUE + 1).plus(Hours.of(-1))); } + @Test public void test_plus_TemporalAmount_Period() { Hours test5 = Hours.of(5); assertEquals(Hours.of(5), test5.plus(Duration.ofHours(0))); @@ -179,22 +193,23 @@ public void test_plus_TemporalAmount_Period() { assertEquals(Hours.of(Integer.MIN_VALUE), Hours.of(Integer.MIN_VALUE + 1).plus(Duration.ofHours(-1))); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_TemporalAmount_overflowTooBig() { Hours.of(Integer.MAX_VALUE - 1).plus(Hours.of(2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_TemporalAmount_overflowTooSmall() { Hours.of(Integer.MIN_VALUE + 1).plus(Hours.of(-2)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_plus_TemporalAmount_null() { Hours.of(Integer.MIN_VALUE + 1).plus(null); } //----------------------------------------------------------------------- + @Test public void test_plus_int() { Hours test5 = Hours.of(5); assertEquals(Hours.of(5), test5.plus(0)); @@ -204,17 +219,18 @@ public void test_plus_int() { assertEquals(Hours.of(Integer.MIN_VALUE), Hours.of(Integer.MIN_VALUE + 1).plus(-1)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_int_overflowTooBig() { Hours.of(Integer.MAX_VALUE - 1).plus(2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_int_overflowTooSmall() { Hours.of(Integer.MIN_VALUE + 1).plus(-2); } //----------------------------------------------------------------------- + @Test public void test_minus_TemporalAmount_Hours() { Hours test5 = Hours.of(5); assertEquals(Hours.of(5), test5.minus(Hours.of(0))); @@ -224,6 +240,7 @@ public void test_minus_TemporalAmount_Hours() { assertEquals(Hours.of(Integer.MIN_VALUE), Hours.of(Integer.MIN_VALUE + 1).minus(Hours.of(1))); } + @Test public void test_minus_TemporalAmount_Duration() { Hours test5 = Hours.of(5); assertEquals(Hours.of(5), test5.minus(Duration.ofHours(0))); @@ -233,22 +250,23 @@ public void test_minus_TemporalAmount_Duration() { assertEquals(Hours.of(Integer.MIN_VALUE), Hours.of(Integer.MIN_VALUE + 1).minus(Duration.ofHours(1))); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_TemporalAmount_overflowTooBig() { Hours.of(Integer.MAX_VALUE - 1).minus(Hours.of(-2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_TemporalAmount_overflowTooSmall() { Hours.of(Integer.MIN_VALUE + 1).minus(Hours.of(2)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_minus_TemporalAmount_null() { Hours.of(Integer.MIN_VALUE + 1).minus(null); } //----------------------------------------------------------------------- + @Test public void test_minus_int() { Hours test5 = Hours.of(5); assertEquals(Hours.of(5), test5.minus(0)); @@ -258,17 +276,18 @@ public void test_minus_int() { assertEquals(Hours.of(Integer.MIN_VALUE), Hours.of(Integer.MIN_VALUE + 1).minus(1)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_int_overflowTooBig() { Hours.of(Integer.MAX_VALUE - 1).minus(-2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_int_overflowTooSmall() { Hours.of(Integer.MIN_VALUE + 1).minus(2); } //----------------------------------------------------------------------- + @Test public void test_multipliedBy() { Hours test5 = Hours.of(5); assertEquals(Hours.of(0), test5.multipliedBy(0)); @@ -278,22 +297,24 @@ public void test_multipliedBy() { assertEquals(Hours.of(-15), test5.multipliedBy(-3)); } + @Test public void test_multipliedBy_negate() { Hours test5 = Hours.of(5); assertEquals(Hours.of(-15), test5.multipliedBy(-3)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_multipliedBy_overflowTooBig() { Hours.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_multipliedBy_overflowTooSmall() { Hours.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2); } //----------------------------------------------------------------------- + @Test public void test_dividedBy() { Hours test12 = Hours.of(12); assertEquals(Hours.of(12), test12.dividedBy(1)); @@ -305,17 +326,19 @@ public void test_dividedBy() { assertEquals(Hours.of(-4), test12.dividedBy(-3)); } + @Test public void test_dividedBy_negate() { Hours test12 = Hours.of(12); assertEquals(Hours.of(-4), test12.dividedBy(-3)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_dividedBy_divideByZero() { Hours.of(1).dividedBy(0); } //----------------------------------------------------------------------- + @Test public void test_negated() { assertEquals(Hours.of(0), Hours.of(0).negated()); assertEquals(Hours.of(-12), Hours.of(12).negated()); @@ -323,12 +346,13 @@ public void test_negated() { assertEquals(Hours.of(-Integer.MAX_VALUE), Hours.of(Integer.MAX_VALUE).negated()); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_negated_overflow() { Hours.of(Integer.MIN_VALUE).negated(); } //----------------------------------------------------------------------- + @Test public void test_abs() { assertEquals(Hours.of(0), Hours.of(0).abs()); assertEquals(Hours.of(12), Hours.of(12).abs()); @@ -337,12 +361,13 @@ public void test_abs() { assertEquals(Hours.of(Integer.MAX_VALUE), Hours.of(-Integer.MAX_VALUE).abs()); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_abs_overflow() { Hours.of(Integer.MIN_VALUE).abs(); } //----------------------------------------------------------------------- + @Test public void test_addTo() { LocalTime base = LocalTime.of(11, 30); assertEquals(Hours.of(0).addTo(base), LocalTime.of(11, 30)); @@ -350,6 +375,7 @@ public void test_addTo() { } //----------------------------------------------------------------------- + @Test public void test_subtractFrom() { LocalTime base = LocalTime.of(11, 30); assertEquals(Hours.of(0).subtractFrom(base), LocalTime.of(11, 30)); @@ -366,6 +392,7 @@ public void test_toDuration() { } //----------------------------------------------------------------------- + @Test public void test_compareTo() { Hours test5 = Hours.of(5); Hours test6 = Hours.of(6); @@ -374,13 +401,14 @@ public void test_compareTo() { assertEquals(1, test6.compareTo(test5)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_compareTo_null() { Hours test5 = Hours.of(5); test5.compareTo(null); } //----------------------------------------------------------------------- + @Test public void test_equals() { Hours test5 = Hours.of(5); Hours test6 = Hours.of(6); @@ -389,17 +417,20 @@ public void test_equals() { assertEquals(false, test6.equals(test5)); } + @Test public void test_equals_null() { Hours test5 = Hours.of(5); assertEquals(false, test5.equals(null)); } + @Test public void test_equals_otherClass() { Hours test5 = Hours.of(5); assertEquals(false, test5.equals("")); } //----------------------------------------------------------------------- + @Test public void test_hashCode() { Hours test5 = Hours.of(5); Hours test6 = Hours.of(6); @@ -408,6 +439,7 @@ public void test_hashCode() { } //----------------------------------------------------------------------- + @Test public void test_toString() { Hours test5 = Hours.of(5); assertEquals("PT5H", test5.toString()); diff --git a/src/test/java/org/threeten/extra/TestInterval.java b/src/test/java/org/threeten/extra/TestInterval.java index 93981680..d6d8a387 100644 --- a/src/test/java/org/threeten/extra/TestInterval.java +++ b/src/test/java/org/threeten/extra/TestInterval.java @@ -33,9 +33,9 @@ import static java.time.temporal.ChronoUnit.HOURS; import static java.time.temporal.ChronoUnit.MONTHS; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -50,26 +50,32 @@ import java.time.ZonedDateTime; import java.time.format.DateTimeParseException; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test class. */ -@Test +@RunWith(DataProviderRunner.class) public class TestInterval { - Instant NOW1 = ZonedDateTime.of(2014, 12, 1, 1, 0, 0, 0, ZoneOffset.UTC).toInstant(); - Instant NOW2 = NOW1.plusSeconds(60); - Instant NOW3 = NOW2.plusSeconds(60); - Instant NOW4 = NOW3.plusSeconds(60); + static Instant NOW1 = ZonedDateTime.of(2014, 12, 1, 1, 0, 0, 0, ZoneOffset.UTC).toInstant(); + static Instant NOW2 = NOW1.plusSeconds(60); + static Instant NOW3 = NOW2.plusSeconds(60); + static Instant NOW4 = NOW3.plusSeconds(60); //----------------------------------------------------------------------- + @Test public void test_isSerializable() { assertTrue(Serializable.class.isAssignableFrom(Interval.class)); } //----------------------------------------------------------------------- + @Test public void test_serialization() throws Exception { Interval test = Interval.of(Instant.EPOCH, NOW1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -82,6 +88,7 @@ public void test_serialization() throws Exception { } //----------------------------------------------------------------------- + @Test public void test_ALL() { Interval test = Interval.ALL; assertEquals(test.getStart(), Instant.MIN); @@ -92,6 +99,7 @@ public void test_ALL() { } //----------------------------------------------------------------------- + @Test public void test_of_Instant_Instant() { Interval test = Interval.of(NOW1, NOW2); assertEquals(test.getStart(), NOW1); @@ -101,6 +109,7 @@ public void test_of_Instant_Instant() { assertEquals(test.isUnboundedEnd(), false); } + @Test public void test_of_Instant_Instant_empty() { Interval test = Interval.of(NOW1, NOW1); assertEquals(test.getStart(), NOW1); @@ -110,45 +119,47 @@ public void test_of_Instant_Instant_empty() { assertEquals(test.isUnboundedEnd(), false); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_Instant_Instant_badOrder() { Interval.of(NOW2, NOW1); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_of_Instant_Instant_nullStart() { Interval.of(null, NOW2); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_of_Instant_Instant_nullEnd() { Interval.of(NOW1, (Instant) null); } //----------------------------------------------------------------------- + @Test public void test_of_Instant_Duration() { Interval test = Interval.of(NOW1, Duration.ofSeconds(60)); assertEquals(test.getStart(), NOW1); assertEquals(test.getEnd(), NOW2); } + @Test public void test_of_Instant_Duration_zero() { Interval test = Interval.of(NOW1, Duration.ZERO); assertEquals(test.getStart(), NOW1); assertEquals(test.getEnd(), NOW1); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_Instant_Duration_negative() { Interval.of(NOW2, Duration.ofSeconds(-1)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_of_Instant_Duration_nullInstant() { Interval.of(null, Duration.ZERO); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_of_Instant_Duration_nullDuration() { Interval.of(NOW1, (Duration) null); } @@ -158,8 +169,8 @@ public void test_of_Instant_Duration_nullDuration() { private static final Instant MAX_OFFSET_DATE_TIME = OffsetDateTime.MAX.minusDays(1L).toInstant(); //----------------------------------------------------------------------- - @DataProvider(name = "parseValid") - Object[][] data_parseValid() { + @DataProvider + public static Object[][] data_parseValid() { Instant minPlusOneDay = Instant.MIN.plus(Duration.ofDays(1)); Instant maxMinusOneDay = Instant.MAX.minus(Duration.ofDays(1)); return new Object[][] { @@ -184,29 +195,31 @@ Object[][] data_parseValid() { }; } - @Test(dataProvider = "parseValid") + @Test + @UseDataProvider("data_parseValid") public void test_parse_CharSequence(String input, Instant start, Instant end) { Interval test = Interval.parse(input); assertEquals(test.getStart(), start); assertEquals(test.getEnd(), end); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_parse_CharSequence_badOrder() { Interval.parse(NOW2 + "/" + NOW1); } - @Test(expectedExceptions = DateTimeParseException.class) + @Test(expected = DateTimeParseException.class) public void test_parse_CharSequence_badFormat() { Interval.parse(NOW2 + "-" + NOW1); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_parse_CharSequence_null() { Interval.parse(null); } //----------------------------------------------------------------------- + @Test public void test_withStart() { Interval base = Interval.of(NOW1, NOW3); Interval test = base.withStart(NOW2); @@ -214,19 +227,20 @@ public void test_withStart() { assertEquals(test.getEnd(), NOW3); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_withStart_badOrder() { Interval base = Interval.of(NOW1, NOW2); base.withStart(NOW3); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_withStart_null() { Interval base = Interval.of(NOW1, NOW2); base.withStart(null); } //----------------------------------------------------------------------- + @Test public void test_withEnd() { Interval base = Interval.of(NOW1, NOW3); Interval test = base.withEnd(NOW2); @@ -234,19 +248,20 @@ public void test_withEnd() { assertEquals(test.getEnd(), NOW2); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_withEnd_badOrder() { Interval base = Interval.of(NOW2, NOW3); base.withEnd(NOW1); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_withEnd_null() { Interval base = Interval.of(NOW1, NOW2); base.withEnd(null); } //----------------------------------------------------------------------- + @Test public void test_contains_Instant() { Interval test = Interval.of(NOW1, NOW2); assertEquals(test.contains(NOW1.minusSeconds(1)), false); @@ -256,6 +271,7 @@ public void test_contains_Instant() { assertEquals(test.contains(NOW2), false); } + @Test public void test_contains_Instant_baseEmpty() { Interval test = Interval.of(NOW1, NOW1); assertEquals(test.contains(NOW1.minusSeconds(1)), false); @@ -263,6 +279,7 @@ public void test_contains_Instant_baseEmpty() { assertEquals(test.contains(NOW1.plusSeconds(1)), false); } + @Test public void test_contains_max() { Interval test = Interval.of(NOW2, Instant.MAX); assertEquals(test.contains(Instant.MIN), false); @@ -272,13 +289,14 @@ public void test_contains_max() { assertEquals(test.contains(Instant.MAX), true); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_contains_Instant_null() { Interval base = Interval.of(NOW1, NOW2); base.contains((Instant) null); } //----------------------------------------------------------------------- + @Test public void test_encloses_Interval() { Interval test = Interval.of(NOW1, NOW2); // completely before @@ -299,6 +317,7 @@ public void test_encloses_Interval() { assertEquals(test.encloses(Interval.of(NOW2.plusSeconds(1), NOW2.plusSeconds(2))), false); } + @Test public void test_encloses_Interval_empty() { Interval test = Interval.of(NOW1, NOW1); // completely before @@ -312,13 +331,14 @@ public void test_encloses_Interval_empty() { assertEquals(test.encloses(Interval.of(NOW1.plusSeconds(1), NOW1.plusSeconds(2))), false); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_encloses_Interval_null() { Interval base = Interval.of(NOW1, NOW2); base.encloses((Interval) null); } //----------------------------------------------------------------------- + @Test public void test_abuts_Interval() { Interval test = Interval.of(NOW1, NOW2); // completely before @@ -339,6 +359,7 @@ public void test_abuts_Interval() { assertEquals(test.abuts(Interval.of(NOW2.plusSeconds(1), NOW2.plusSeconds(2))), false); } + @Test public void test_abuts_Interval_empty() { Interval test = Interval.of(NOW1, NOW1); // completely before @@ -351,13 +372,14 @@ public void test_abuts_Interval_empty() { assertEquals(test.abuts(Interval.of(NOW1.plusSeconds(1), NOW1.plusSeconds(2))), false); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_abuts_Interval_null() { Interval base = Interval.of(NOW1, NOW2); base.abuts((Interval) null); } //----------------------------------------------------------------------- + @Test public void test_isConnected_Interval() { Interval test = Interval.of(NOW1, NOW2); // completely before @@ -378,6 +400,7 @@ public void test_isConnected_Interval() { assertEquals(test.isConnected(Interval.of(NOW2.plusSeconds(1), NOW2.plusSeconds(2))), false); } + @Test public void test_isConnected_Interval_empty() { Interval test = Interval.of(NOW1, NOW1); // completely before @@ -390,13 +413,14 @@ public void test_isConnected_Interval_empty() { assertEquals(test.isConnected(Interval.of(NOW1.plusSeconds(1), NOW1.plusSeconds(2))), false); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_isConnected_Interval_null() { Interval base = Interval.of(NOW1, NOW2); base.isConnected((Interval) null); } //----------------------------------------------------------------------- + @Test public void test_overlaps_Interval() { Interval test = Interval.of(NOW1, NOW2); // completely before @@ -417,6 +441,7 @@ public void test_overlaps_Interval() { assertEquals(test.overlaps(Interval.of(NOW2.plusSeconds(1), NOW2.plusSeconds(2))), false); } + @Test public void test_overlaps_Interval_empty() { Interval test = Interval.of(NOW1, NOW1); // completely before @@ -429,15 +454,15 @@ public void test_overlaps_Interval_empty() { assertEquals(test.overlaps(Interval.of(NOW1.plusSeconds(1), NOW1.plusSeconds(2))), false); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_overlaps_Interval_null() { Interval base = Interval.of(NOW1, NOW2); base.overlaps((Interval) null); } //----------------------------------------------------------------------- - @DataProvider(name = "intersection") - Object[][] data_intersection() { + @DataProvider + public static Object[][] data_intersection() { return new Object[][] { // adjacent { NOW1, NOW2, NOW2, NOW4, NOW2, NOW2 }, @@ -452,7 +477,8 @@ Object[][] data_intersection() { }; } - @Test(dataProvider = "intersection") + @Test + @UseDataProvider("data_intersection") public void test_intersection( Instant start1, Instant end1, Instant start2, Instant end2, Instant expStart, Instant expEnd) { @@ -463,7 +489,8 @@ public void test_intersection( assertEquals(test1.intersection(test2), expected); } - @Test(dataProvider = "intersection") + @Test + @UseDataProvider("data_intersection") public void test_intersection_reverse( Instant start1, Instant end1, Instant start2, Instant end2, Instant expStart, Instant expEnd) { @@ -474,7 +501,7 @@ public void test_intersection_reverse( assertEquals(test2.intersection(test1), expected); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_intersectionBad() { Interval test1 = Interval.of(NOW1, NOW2); Interval test2 = Interval.of(NOW3, NOW4); @@ -482,14 +509,15 @@ public void test_intersectionBad() { test1.intersection(test2); } + @Test public void test_intersection_same() { Interval test = Interval.of(NOW2, NOW4); assertEquals(test.intersection(test), test); } //----------------------------------------------------------------------- - @DataProvider(name = "union") - Object[][] data_union() { + @DataProvider + public static Object[][] data_union() { return new Object[][] { // adjacent { NOW1, NOW2, NOW2, NOW4, NOW1, NOW4 }, @@ -504,7 +532,8 @@ Object[][] data_union() { }; } - @Test(dataProvider = "union") + @Test + @UseDataProvider("data_union") public void test_unionAndSpan( Instant start1, Instant end1, Instant start2, Instant end2, Instant expStart, Instant expEnd) { @@ -516,7 +545,8 @@ public void test_unionAndSpan( assertEquals(test1.span(test2), expected); } - @Test(dataProvider = "union") + @Test + @UseDataProvider("data_union") public void test_unionAndSpan_reverse( Instant start1, Instant end1, Instant start2, Instant end2, Instant expStart, Instant expEnd) { @@ -528,7 +558,8 @@ public void test_unionAndSpan_reverse( assertEquals(test2.span(test1), expected); } - @Test(dataProvider = "union") + @Test + @UseDataProvider("data_union") public void test_span_enclosesInputs( Instant start1, Instant end1, Instant start2, Instant end2, Instant expStart, Instant expEnd) { @@ -539,7 +570,7 @@ public void test_span_enclosesInputs( assertEquals(expected.encloses(test2), true); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_union_disconnected() { Interval test1 = Interval.of(NOW1, NOW2); Interval test2 = Interval.of(NOW3, NOW4); @@ -547,6 +578,7 @@ public void test_union_disconnected() { test1.union(test2); } + @Test public void test_span_disconnected() { Interval test1 = Interval.of(NOW1, NOW2); Interval test2 = Interval.of(NOW3, NOW4); @@ -554,6 +586,7 @@ public void test_span_disconnected() { assertEquals(test1.span(test2), Interval.of(NOW1, NOW4)); } + @Test public void test_unionAndSpan_same() { Interval test = Interval.of(NOW2, NOW4); assertEquals(test.union(test), test); @@ -561,6 +594,7 @@ public void test_unionAndSpan_same() { } //----------------------------------------------------------------------- + @Test public void test_isAfter_Instant() { Interval test = Interval.of(NOW1, NOW2); assertEquals(test.isAfter(NOW1.minusSeconds(2)), true); @@ -570,6 +604,7 @@ public void test_isAfter_Instant() { assertEquals(test.isAfter(NOW2.plusSeconds(1)), false); } + @Test public void test_isAfter_Instant_empty() { Interval test = Interval.of(NOW1, NOW1); assertEquals(test.isAfter(NOW1.minusSeconds(2)), true); @@ -579,6 +614,7 @@ public void test_isAfter_Instant_empty() { } //----------------------------------------------------------------------- + @Test public void test_isBefore_Instant() { Interval test = Interval.of(NOW1, NOW2); assertEquals(test.isBefore(NOW1.minusSeconds(1)), false); @@ -587,6 +623,7 @@ public void test_isBefore_Instant() { assertEquals(test.isBefore(NOW2.plusSeconds(1)), true); } + @Test public void test_isBefore_Instant_empty() { Interval test = Interval.of(NOW1, NOW1); assertEquals(test.isBefore(NOW1.minusSeconds(1)), false); @@ -595,6 +632,7 @@ public void test_isBefore_Instant_empty() { } //----------------------------------------------------------------------- + @Test public void test_isAfter_Interval() { Interval test = Interval.of(NOW1, NOW2); // completely before @@ -615,6 +653,7 @@ public void test_isAfter_Interval() { assertEquals(test.isAfter(Interval.of(NOW2.plusSeconds(1), NOW2.plusSeconds(2))), false); } + @Test public void test_isAfter_Interval_empty() { Interval test = Interval.of(NOW1, NOW1); // completely before @@ -628,6 +667,7 @@ public void test_isAfter_Interval_empty() { } //----------------------------------------------------------------------- + @Test public void test_isBefore_Interval() { Interval test = Interval.of(NOW1, NOW2); // completely before @@ -648,6 +688,7 @@ public void test_isBefore_Interval() { assertEquals(test.isBefore(Interval.of(NOW2.plusSeconds(1), NOW2.plusSeconds(2))), true); } + @Test public void test_isBefore_Interval_empty() { Interval test = Interval.of(NOW1, NOW1); // completely before @@ -661,12 +702,14 @@ public void test_isBefore_Interval_empty() { } //----------------------------------------------------------------------- + @Test public void test_toDuration() { Interval test = Interval.of(NOW1, NOW2); assertEquals(test.toDuration(), Duration.between(NOW1, NOW2)); } //----------------------------------------------------------------------- + @Test public void test_equals() { Interval a = Interval.of(NOW1, NOW2); Interval a2 = Interval.of(NOW1, NOW2); @@ -682,6 +725,7 @@ public void test_equals() { } //----------------------------------------------------------------------- + @Test public void test_toString() { Interval test = Interval.of(NOW1, NOW2); assertEquals(test.toString(), NOW1 + "/" + NOW2); diff --git a/src/test/java/org/threeten/extra/TestLocalDateRange.java b/src/test/java/org/threeten/extra/TestLocalDateRange.java index 117e9d4d..626cb768 100644 --- a/src/test/java/org/threeten/extra/TestLocalDateRange.java +++ b/src/test/java/org/threeten/extra/TestLocalDateRange.java @@ -31,9 +31,9 @@ */ package org.threeten.extra; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -46,19 +46,22 @@ import java.time.format.DateTimeParseException; import java.time.temporal.ChronoUnit; import java.util.ArrayList; -import java.util.Iterator; +import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Test; +import org.junit.runner.RunWith; import com.google.common.collect.Range; +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test date range. */ -@Test +@RunWith(DataProviderRunner.class) public class TestLocalDateRange { private static final LocalDate DATE_2012_07_01 = LocalDate.of(2012, 7, 1); @@ -71,6 +74,7 @@ public class TestLocalDateRange { private static final LocalDate DATE_2012_08_31 = LocalDate.of(2012, 8, 31); //----------------------------------------------------------------------- + @Test public void test_ALL() { LocalDateRange test = LocalDateRange.ALL; assertEquals(test.getStart(), LocalDate.MIN); @@ -83,6 +87,7 @@ public void test_ALL() { } //----------------------------------------------------------------------- + @Test public void test_of() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); assertEquals(test.getStart(), DATE_2012_07_28); @@ -94,6 +99,7 @@ public void test_of() { assertEquals(test.toString(), "2012-07-28/2012-07-31"); } + @Test public void test_of_MIN() { LocalDateRange test = LocalDateRange.of(LocalDate.MIN, DATE_2012_07_31); assertEquals(test.getStart(), LocalDate.MIN); @@ -105,6 +111,7 @@ public void test_of_MIN() { assertEquals(test.toString(), "-999999999-01-01/2012-07-31"); } + @Test public void test_of_MAX() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, LocalDate.MAX); assertEquals(test.getStart(), DATE_2012_07_28); @@ -116,6 +123,7 @@ public void test_of_MAX() { assertEquals(test.toString(), "2012-07-28/+999999999-12-31"); } + @Test public void test_of_MIN_MAX() { LocalDateRange test = LocalDateRange.of(LocalDate.MIN, LocalDate.MAX); assertEquals(test.getStart(), LocalDate.MIN); @@ -127,6 +135,7 @@ public void test_of_MIN_MAX() { assertEquals(test.toString(), "-999999999-01-01/+999999999-12-31"); } + @Test public void test_of_MIN_MIN() { LocalDateRange test = LocalDateRange.of(LocalDate.MIN, LocalDate.MIN); assertEquals(test.getStart(), LocalDate.MIN); @@ -138,6 +147,7 @@ public void test_of_MIN_MIN() { assertEquals(test.toString(), "-999999999-01-01/-999999999-01-01"); } + @Test public void test_of_empty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_30, DATE_2012_07_30); assertEquals(test.getStart(), DATE_2012_07_30); @@ -149,12 +159,13 @@ public void test_of_empty() { assertEquals(test.toString(), "2012-07-30/2012-07-30"); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_badOrder() { LocalDateRange.of(DATE_2012_07_31, DATE_2012_07_30); } //----------------------------------------------------------------------- + @Test public void test_ofClosed() { LocalDateRange test = LocalDateRange.ofClosed(DATE_2012_07_28, DATE_2012_07_30); assertEquals(test.getStart(), DATE_2012_07_28); @@ -165,6 +176,7 @@ public void test_ofClosed() { assertEquals(test.toString(), "2012-07-28/2012-07-31"); } + @Test public void test_ofClosed_MIN() { LocalDateRange test = LocalDateRange.ofClosed(LocalDate.MIN, DATE_2012_07_30); assertEquals(test.getStart(), LocalDate.MIN); @@ -175,6 +187,7 @@ public void test_ofClosed_MIN() { assertEquals(test.toString(), "-999999999-01-01/2012-07-31"); } + @Test public void test_ofClosed_MAX() { LocalDateRange test = LocalDateRange.ofClosed(DATE_2012_07_28, LocalDate.MAX); assertEquals(test.getStart(), DATE_2012_07_28); @@ -185,6 +198,7 @@ public void test_ofClosed_MAX() { assertEquals(test.toString(), "2012-07-28/+999999999-12-31"); } + @Test public void test_ofClosed_MIN_MAX() { LocalDateRange test = LocalDateRange.ofClosed(LocalDate.MIN, LocalDate.MAX); assertEquals(test.getStart(), LocalDate.MIN); @@ -195,12 +209,13 @@ public void test_ofClosed_MIN_MAX() { assertEquals(test.toString(), "-999999999-01-01/+999999999-12-31"); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_ofClosed_badOrder() { LocalDateRange.ofClosed(DATE_2012_07_31, DATE_2012_07_30); } //----------------------------------------------------------------------- + @Test public void test_of_period() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, Period.ofDays(3)); assertEquals(test.getStart(), DATE_2012_07_28); @@ -211,68 +226,76 @@ public void test_of_period() { assertEquals(test.toString(), "2012-07-28/2012-07-31"); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_period_negative() { LocalDateRange.of(DATE_2012_07_31, Period.ofDays(-1)); } //----------------------------------------------------------------------- + @Test public void test_parse_CharSequence() { LocalDateRange test = LocalDateRange.parse(DATE_2012_07_27 + "/" + DATE_2012_07_29); assertEquals(test.getStart(), DATE_2012_07_27); assertEquals(test.getEnd(), DATE_2012_07_29); } + @Test public void test_parse_CharSequence_PeriodLocalDate() { LocalDateRange test = LocalDateRange.parse("P2D/" + DATE_2012_07_29); assertEquals(test.getStart(), DATE_2012_07_27); assertEquals(test.getEnd(), DATE_2012_07_29); } + @Test public void test_parse_CharSequence_PeriodLocalDate_case() { LocalDateRange test = LocalDateRange.parse("p2d/" + DATE_2012_07_29); assertEquals(test.getStart(), DATE_2012_07_27); assertEquals(test.getEnd(), DATE_2012_07_29); } + @Test public void test_parse_CharSequence_LocalDatePeriod() { LocalDateRange test = LocalDateRange.parse(DATE_2012_07_27 + "/P2D"); assertEquals(test.getStart(), DATE_2012_07_27); assertEquals(test.getEnd(), DATE_2012_07_29); } + @Test public void test_parse_CharSequence_LocalDatePeriod_case() { LocalDateRange test = LocalDateRange.parse(DATE_2012_07_27 + "/p2d"); assertEquals(test.getStart(), DATE_2012_07_27); assertEquals(test.getEnd(), DATE_2012_07_29); } + @Test public void test_parse_CharSequence_empty() { LocalDateRange test = LocalDateRange.parse(DATE_2012_07_27 + "/" + DATE_2012_07_27); assertEquals(test.getStart(), DATE_2012_07_27); assertEquals(test.getEnd(), DATE_2012_07_27); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_parse_CharSequence_badOrder() { LocalDateRange.parse(DATE_2012_07_29 + "/" + DATE_2012_07_27); } - @Test(expectedExceptions = DateTimeParseException.class) + @Test(expected = DateTimeParseException.class) public void test_parse_CharSequence_badFormat() { LocalDateRange.parse(DATE_2012_07_29 + "-" + DATE_2012_07_27); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_parse_CharSequence_null() { LocalDateRange.parse(null); } //----------------------------------------------------------------------- + @Test public void test_isSerializable() { assertTrue(Serializable.class.isAssignableFrom(LocalDateRange.class)); } + @Test public void test_serialization() throws Exception { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -285,6 +308,7 @@ public void test_serialization() throws Exception { } //----------------------------------------------------------------------- + @Test public void test_withStart() { LocalDateRange base = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); LocalDateRange test = base.withStart(DATE_2012_07_27); @@ -293,6 +317,7 @@ public void test_withStart() { assertEquals(test.getEnd(), DATE_2012_07_31); } + @Test public void test_withStart_adjuster() { LocalDateRange base = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); LocalDateRange test = base.withStart(date -> date.minus(1, ChronoUnit.WEEKS)); @@ -301,6 +326,7 @@ public void test_withStart_adjuster() { assertEquals(test.getEnd(), DATE_2012_07_31); } + @Test public void test_withStart_min() { LocalDateRange base = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); LocalDateRange test = base.withStart(LocalDate.MIN); @@ -309,6 +335,7 @@ public void test_withStart_min() { assertEquals(test.getEnd(), DATE_2012_07_31); } + @Test public void test_withStart_empty() { LocalDateRange base = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); LocalDateRange test = base.withStart(DATE_2012_07_31); @@ -317,13 +344,14 @@ public void test_withStart_empty() { assertEquals(test.getEnd(), DATE_2012_07_31); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_withStart_invalid() { LocalDateRange base = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_30); base.withStart(DATE_2012_07_31); } //----------------------------------------------------------------------- + @Test public void test_withEnd() { LocalDateRange base = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); LocalDateRange test = base.withEnd(DATE_2012_07_30); @@ -332,6 +360,7 @@ public void test_withEnd() { assertEquals(test.getEnd(), DATE_2012_07_30); } + @Test public void test_withEnd_adjuster() { LocalDateRange base = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); LocalDateRange test = base.withEnd(date -> date.plus(1, ChronoUnit.WEEKS)); @@ -340,6 +369,7 @@ public void test_withEnd_adjuster() { assertEquals(test.getEnd(), DATE_2012_07_31.plusWeeks(1)); } + @Test public void test_withEnd_max() { LocalDateRange base = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); LocalDateRange test = base.withEnd(LocalDate.MAX); @@ -348,6 +378,7 @@ public void test_withEnd_max() { assertEquals(test.getEnd(), LocalDate.MAX); } + @Test public void test_withEnd_empty() { LocalDateRange base = LocalDateRange.of(DATE_2012_07_30, DATE_2012_07_31); LocalDateRange test = base.withEnd(DATE_2012_07_30); @@ -356,13 +387,14 @@ public void test_withEnd_empty() { assertEquals(test.getEnd(), DATE_2012_07_30); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_withEnd_invalid() { LocalDateRange base = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); base.withEnd(DATE_2012_07_27); } //----------------------------------------------------------------------- + @Test public void test_contains() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); assertEquals(test.contains(LocalDate.MIN), false); @@ -375,6 +407,7 @@ public void test_contains() { assertEquals(test.contains(LocalDate.MAX), false); } + @Test public void test_contains_baseEmpty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28); assertEquals(test.contains(LocalDate.MIN), false); @@ -384,6 +417,7 @@ public void test_contains_baseEmpty() { assertEquals(test.contains(LocalDate.MAX), false); } + @Test public void test_contains_max() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, LocalDate.MAX); assertEquals(test.contains(LocalDate.MIN), false); @@ -397,8 +431,8 @@ public void test_contains_max() { } //----------------------------------------------------------------------- - @DataProvider(name = "queries") - Object[][] data_queries() { + @DataProvider + public static Object[][] data_queries() { return new Object[][] { // before start { DATE_2012_07_01, DATE_2012_07_27, false, false, false, false }, @@ -446,35 +480,40 @@ Object[][] data_queries() { }; } - @Test(dataProvider = "queries") + @Test + @UseDataProvider("data_queries") public void test_encloses( LocalDate start, LocalDate end, boolean isEnclosedBy, boolean abuts, boolean isConnected, boolean overlaps) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); assertEquals(test.encloses(LocalDateRange.of(start, end)), isEnclosedBy); } - @Test(dataProvider = "queries") + @Test + @UseDataProvider("data_queries") public void test_abuts( LocalDate start, LocalDate end, boolean isEnclosedBy, boolean abuts, boolean isConnected, boolean overlaps) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); assertEquals(test.abuts(LocalDateRange.of(start, end)), abuts); } - @Test(dataProvider = "queries") + @Test + @UseDataProvider("data_queries") public void test_isConnected( LocalDate start, LocalDate end, boolean isEnclosedBy, boolean abuts, boolean isConnected, boolean overlaps) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); assertEquals(test.isConnected(LocalDateRange.of(start, end)), isConnected); } - @Test(dataProvider = "queries") + @Test + @UseDataProvider("data_queries") public void test_overlaps( LocalDate start, LocalDate end, boolean isEnclosedBy, boolean abuts, boolean isConnected, boolean overlaps) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); assertEquals(test.overlaps(LocalDateRange.of(start, end)), overlaps); } - @Test(dataProvider = "queries") + @Test + @UseDataProvider("data_queries") public void test_crossCheck( LocalDate start, LocalDate end, boolean isEnclosedBy, boolean abuts, boolean isConnected, boolean overlaps) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); @@ -483,6 +522,7 @@ public void test_crossCheck( assertEquals(test.overlaps(input), test.isConnected(input) && !test.abuts(input)); } + @Test public void test_encloses_max() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, LocalDate.MAX); assertEquals(test.encloses(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28)), true); @@ -493,6 +533,7 @@ public void test_encloses_max() { assertEquals(test.encloses(LocalDateRange.of(DATE_2012_07_27, LocalDate.MAX)), false); } + @Test public void test_encloses_baseEmpty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28); assertEquals(test.encloses(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_27)), false); @@ -505,6 +546,7 @@ public void test_encloses_baseEmpty() { assertEquals(test.encloses(LocalDateRange.of(DATE_2012_07_28, LocalDate.MAX)), false); } + @Test public void test_encloses_baseEmptyMax() { assertEquals(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) .encloses(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX)), true); @@ -518,6 +560,7 @@ public void test_encloses_baseEmptyMax() { .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2))), false); } + @Test public void test_abuts_baseEmpty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28); assertEquals(test.abuts(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_27)), false); @@ -527,6 +570,7 @@ public void test_abuts_baseEmpty() { assertEquals(test.abuts(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_29)), true); } + @Test public void test_abuts_baseEmptyMax() { assertEquals(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) .abuts(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX)), false); @@ -540,6 +584,7 @@ public void test_abuts_baseEmptyMax() { .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2))), false); } + @Test public void test_isConnected_baseEmpty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28); assertEquals(test.isConnected(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_27)), false); @@ -547,6 +592,7 @@ public void test_isConnected_baseEmpty() { assertEquals(test.isConnected(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29)), false); } + @Test public void test_isConnected_baseEmptyMax() { assertEquals(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) .isConnected(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX)), true); @@ -560,6 +606,7 @@ public void test_isConnected_baseEmptyMax() { .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2))), false); } + @Test public void test_overlaps_baseEmpty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28); assertEquals(test.overlaps(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_27)), false); @@ -567,6 +614,7 @@ public void test_overlaps_baseEmpty() { assertEquals(test.overlaps(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29)), false); } + @Test public void test_overlaps_baseEmptyMax() { assertEquals(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) .overlaps(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX)), true); @@ -581,8 +629,8 @@ public void test_overlaps_baseEmptyMax() { } //----------------------------------------------------------------------- - @DataProvider(name = "intersection") - Object[][] data_intersection() { + @DataProvider + public static Object[][] data_intersection() { return new Object[][] { // adjacent { DATE_2012_07_01, DATE_2012_07_28, DATE_2012_07_28, DATE_2012_07_30, DATE_2012_07_28, DATE_2012_07_28 }, @@ -597,7 +645,8 @@ Object[][] data_intersection() { }; } - @Test(dataProvider = "intersection") + @Test + @UseDataProvider("data_intersection") public void test_intersection( LocalDate start1, LocalDate end1, LocalDate start2, LocalDate end2, LocalDate expStart, LocalDate expEnd) { @@ -608,7 +657,8 @@ public void test_intersection( assertEquals(test1.intersection(test2), expected); } - @Test(dataProvider = "intersection") + @Test + @UseDataProvider("data_intersection") public void test_intersection_reverse( LocalDate start1, LocalDate end1, LocalDate start2, LocalDate end2, LocalDate expStart, LocalDate expEnd) { @@ -619,7 +669,7 @@ public void test_intersection_reverse( assertEquals(test2.intersection(test1), expected); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_intersectionBad() { LocalDateRange test1 = LocalDateRange.of(DATE_2012_07_01, DATE_2012_07_28); LocalDateRange test2 = LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_30); @@ -627,14 +677,15 @@ public void test_intersectionBad() { test1.intersection(test2); } + @Test public void test_intersection_same() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); assertEquals(test.intersection(test), test); } //----------------------------------------------------------------------- - @DataProvider(name = "union") - Object[][] data_union() { + @DataProvider + public static Object[][] data_union() { return new Object[][] { // adjacent { DATE_2012_07_01, DATE_2012_07_28, DATE_2012_07_28, DATE_2012_07_30, DATE_2012_07_01, DATE_2012_07_30 }, @@ -649,7 +700,8 @@ Object[][] data_union() { }; } - @Test(dataProvider = "union") + @Test + @UseDataProvider("data_union") public void test_unionAndSpan( LocalDate start1, LocalDate end1, LocalDate start2, LocalDate end2, LocalDate expStart, LocalDate expEnd) { @@ -661,7 +713,8 @@ public void test_unionAndSpan( assertEquals(test1.span(test2), expected); } - @Test(dataProvider = "union") + @Test + @UseDataProvider("data_union") public void test_unionAndSpan_reverse( LocalDate start1, LocalDate end1, LocalDate start2, LocalDate end2, LocalDate expStart, LocalDate expEnd) { @@ -673,7 +726,8 @@ public void test_unionAndSpan_reverse( assertEquals(test2.span(test1), expected); } - @Test(dataProvider = "union") + @Test + @UseDataProvider("data_union") public void test_span_enclosesInputs( LocalDate start1, LocalDate end1, LocalDate start2, LocalDate end2, LocalDate expStart, LocalDate expEnd) { @@ -684,7 +738,7 @@ public void test_span_enclosesInputs( assertEquals(expected.encloses(test2), true); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_union_disconnected() { LocalDateRange test1 = LocalDateRange.of(DATE_2012_07_01, DATE_2012_07_28); LocalDateRange test2 = LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_30); @@ -692,6 +746,7 @@ public void test_union_disconnected() { test1.union(test2); } + @Test public void test_span_disconnected() { LocalDateRange test1 = LocalDateRange.of(DATE_2012_07_01, DATE_2012_07_28); LocalDateRange test2 = LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_30); @@ -699,6 +754,7 @@ public void test_span_disconnected() { assertEquals(test1.span(test2), LocalDateRange.of(DATE_2012_07_01, DATE_2012_07_30)); } + @Test public void test_unionAndSpan_same() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); assertEquals(test.union(test), test); @@ -706,6 +762,7 @@ public void test_unionAndSpan_same() { } //----------------------------------------------------------------------- + @Test public void test_stream() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); List result = test.stream().collect(Collectors.toList()); @@ -716,8 +773,8 @@ public void test_stream() { } //----------------------------------------------------------------------- - @DataProvider(name = "isBefore") - Object[][] data_isBefore() { + @DataProvider + public static Object[][] data_isBefore() { return new Object[][] { // before start { DATE_2012_07_01, DATE_2012_07_27, false }, @@ -759,18 +816,21 @@ Object[][] data_isBefore() { }; } - @Test(dataProvider = "isBefore") + @Test + @UseDataProvider("data_isBefore") public void test_isBefore_range(LocalDate start, LocalDate end, boolean before) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); assertEquals(test.isBefore(LocalDateRange.of(start, end)), before); } - @Test(dataProvider = "isBefore") + @Test + @UseDataProvider("data_isBefore") public void test_isBefore_date(LocalDate start, LocalDate end, boolean before) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); assertEquals(test.isBefore(start), before); } + @Test public void test_isBefore_range_empty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29); assertEquals(test.isBefore(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_28)), false); @@ -781,6 +841,7 @@ public void test_isBefore_range_empty() { assertEquals(test.isBefore(LocalDateRange.of(DATE_2012_07_30, DATE_2012_07_31)), true); } + @Test public void test_isBefore_date_empty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29); assertEquals(test.isBefore(DATE_2012_07_28), false); @@ -789,8 +850,8 @@ public void test_isBefore_date_empty() { } //----------------------------------------------------------------------- - @DataProvider(name = "isAfter") - Object[][] data_isAfter() { + @DataProvider + public static Object[][] data_isAfter() { return new Object[][] { // before start { DATE_2012_07_01, DATE_2012_07_27, true }, @@ -835,18 +896,21 @@ Object[][] data_isAfter() { }; } - @Test(dataProvider = "isAfter") + @Test + @UseDataProvider("data_isAfter") public void test_isAfter_range(LocalDate start, LocalDate end, boolean before) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); assertEquals(test.isAfter(LocalDateRange.of(start, end)), before); } - @Test(dataProvider = "isAfter") + @Test + @UseDataProvider("data_isAfter") public void test_isAfter_date(LocalDate start, LocalDate end, boolean before) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); assertEquals(test.isAfter(end.minusDays(1)), before); } + @Test public void test_isAfter_range_empty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29); assertEquals(test.isAfter(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_28)), true); @@ -858,6 +922,7 @@ public void test_isAfter_range_empty() { assertEquals(test.isAfter(LocalDateRange.of(DATE_2012_07_30, DATE_2012_07_31)), false); } + @Test public void test_isAfter_date_empty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29); assertEquals(test.isAfter(DATE_2012_07_28), true); @@ -866,12 +931,14 @@ public void test_isAfter_date_empty() { } //----------------------------------------------------------------------- + @Test public void test_lengthInDays() { assertEquals(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_29).lengthInDays(), 2); assertEquals(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_29).lengthInDays(), 1); assertEquals(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29).lengthInDays(), 0); } + @Test public void test_toPeriod() { assertEquals(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_29).toPeriod(), Period.ofDays(2)); assertEquals(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_29).toPeriod(), Period.ofDays(1)); @@ -879,6 +946,7 @@ public void test_toPeriod() { } //----------------------------------------------------------------------- + @Test public void test_equals() { LocalDateRange a = LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_29); LocalDateRange a2 = LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_29); @@ -894,9 +962,9 @@ public void test_equals() { } //----------------------------------------------------------------------- - @DataProvider(name = "crossCheckGuava") - Iterator data_crossCheckGuava() { - List list = new ArrayList<>(); + @DataProvider + public static List> data_crossCheckGuava() { + List> list = new ArrayList<>(); for (int i1 = 1; i1 < 5; i1++) { for (int j1 = i1; j1 < 5; j1++) { LocalDate date11 = LocalDate.of(2016, 1, i1); @@ -909,16 +977,16 @@ Iterator data_crossCheckGuava() { LocalDate date22 = LocalDate.of(2016, 1, j2); LocalDateRange extraRange2 = LocalDateRange.of(date21, date22); Range guavaRange2 = Range.closedOpen(date21, date22); - Object[] array = {extraRange1, extraRange2, guavaRange1, guavaRange2}; - list.add(array); + list.add(Arrays.asList(extraRange1, extraRange2, guavaRange1, guavaRange2)); } } } } - return list.iterator(); + return list; } - @Test(dataProvider = "crossCheckGuava") + @Test + @UseDataProvider("data_crossCheckGuava") public void crossCheckGuava_encloses( LocalDateRange extraRange1, LocalDateRange extraRange2, @@ -930,7 +998,8 @@ public void crossCheckGuava_encloses( assertEquals(extra, guava); } - @Test(dataProvider = "crossCheckGuava") + @Test + @UseDataProvider("data_crossCheckGuava") public void crossCheckGuava_isConnected( LocalDateRange extraRange1, LocalDateRange extraRange2, @@ -942,7 +1011,8 @@ public void crossCheckGuava_isConnected( assertEquals(extra, guava); } - @Test(dataProvider = "crossCheckGuava") + @Test + @UseDataProvider("data_crossCheckGuava") public void crossCheckGuava_intersection( LocalDateRange extraRange1, LocalDateRange extraRange2, @@ -969,7 +1039,8 @@ public void crossCheckGuava_intersection( } } - @Test(dataProvider = "crossCheckGuava") + @Test + @UseDataProvider("data_crossCheckGuava") public void crossCheckGuava_span( LocalDateRange extraRange1, LocalDateRange extraRange2, diff --git a/src/test/java/org/threeten/extra/TestMinutes.java b/src/test/java/org/threeten/extra/TestMinutes.java index 7541abbf..bdf2a322 100644 --- a/src/test/java/org/threeten/extra/TestMinutes.java +++ b/src/test/java/org/threeten/extra/TestMinutes.java @@ -31,9 +31,9 @@ */ package org.threeten.extra; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertSame; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -44,21 +44,27 @@ import java.time.LocalTime; import java.time.format.DateTimeParseException; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test class. */ -@Test +@RunWith(DataProviderRunner.class) public class TestMinutes { //----------------------------------------------------------------------- + @Test public void test_isSerializable() { assertTrue(Serializable.class.isAssignableFrom(Minutes.class)); } //----------------------------------------------------------------------- + @Test public void test_deserializationSingleton() throws Exception { Minutes test = Minutes.ZERO; ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -71,6 +77,7 @@ public void test_deserializationSingleton() throws Exception { } //----------------------------------------------------------------------- + @Test public void test_ZERO() { assertSame(Minutes.of(0), Minutes.ZERO); assertSame(Minutes.of(0), Minutes.ZERO); @@ -78,6 +85,7 @@ public void test_ZERO() { } //----------------------------------------------------------------------- + @Test public void test_of() { assertEquals(Minutes.of(0).getAmount(), 0); assertEquals(Minutes.of(1).getAmount(), 1); @@ -89,6 +97,7 @@ public void test_of() { } //----------------------------------------------------------------------- + @Test public void test_ofHours() { assertEquals(Minutes.ofHours(0).getAmount(), 0); assertEquals(Minutes.ofHours(1).getAmount(), 60); @@ -99,14 +108,14 @@ public void test_ofHours() { assertEquals(Minutes.ofHours(Integer.MIN_VALUE / 60).getAmount(), (Integer.MIN_VALUE / 60) * 60); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_ofHours_overflow() { Minutes.ofHours((Integer.MAX_VALUE / 60) + 60); } //----------------------------------------------------------------------- - @DataProvider(name = "parseValid") - Object[][] data_valid() { + @DataProvider + public static Object[][] data_valid() { return new Object[][] { {"PT0M", 0}, {"PT1M", 1}, @@ -148,23 +157,26 @@ Object[][] data_valid() { }; } - @Test(dataProvider = "parseValid") + @Test + @UseDataProvider("data_valid") public void test_parse_CharSequence_valid(String str, int expectedMinutes) { assertEquals(Minutes.parse(str), Minutes.of(expectedMinutes)); } - @Test(dataProvider = "parseValid") + @Test + @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, int expectedMinutes) { assertEquals(Minutes.parse("+" + str), Minutes.of(expectedMinutes)); } - @Test(dataProvider = "parseValid") + @Test + @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, int expectedMinutes) { assertEquals(Minutes.parse("-" + str), Minutes.of(-expectedMinutes)); } - @DataProvider(name = "parseInvalid") - Object[][] data_invalid() { + @DataProvider + public static Object[][] data_invalid() { return new Object[][] { {"P3W"}, {"P3Q"}, @@ -185,17 +197,19 @@ Object[][] data_invalid() { }; } - @Test(expectedExceptions = DateTimeParseException.class, dataProvider = "parseInvalid") + @Test(expected = DateTimeParseException.class) + @UseDataProvider("data_invalid") public void test_parse_CharSequence_invalid(String str) { Minutes.parse(str); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_parse_CharSequence_null() { Minutes.parse((CharSequence) null); } //----------------------------------------------------------------------- + @Test public void test_plus_TemporalAmount_Minutes() { Minutes test5 = Minutes.of(5); assertEquals(Minutes.of(5), test5.plus(Minutes.of(0))); @@ -205,22 +219,23 @@ public void test_plus_TemporalAmount_Minutes() { assertEquals(Minutes.of(Integer.MIN_VALUE), Minutes.of(Integer.MIN_VALUE + 1).plus(Minutes.of(-1))); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_TemporalAmount_overflowTooBig() { Minutes.of(Integer.MAX_VALUE - 1).plus(Minutes.of(2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_TemporalAmount_overflowTooSmall() { Minutes.of(Integer.MIN_VALUE + 1).plus(Minutes.of(-2)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_plus_TemporalAmount_null() { Minutes.of(Integer.MIN_VALUE + 1).plus(null); } //----------------------------------------------------------------------- + @Test public void test_plus_int() { Minutes test5 = Minutes.of(5); assertEquals(Minutes.of(5), test5.plus(0)); @@ -230,17 +245,18 @@ public void test_plus_int() { assertEquals(Minutes.of(Integer.MIN_VALUE), Minutes.of(Integer.MIN_VALUE + 1).plus(-1)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_int_overflowTooBig() { Minutes.of(Integer.MAX_VALUE - 1).plus(2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_int_overflowTooSmall() { Minutes.of(Integer.MIN_VALUE + 1).plus(-2); } //----------------------------------------------------------------------- + @Test public void test_minus_TemporalAmount_Minutes() { Minutes test5 = Minutes.of(5); assertEquals(Minutes.of(5), test5.minus(Minutes.of(0))); @@ -250,22 +266,23 @@ public void test_minus_TemporalAmount_Minutes() { assertEquals(Minutes.of(Integer.MIN_VALUE), Minutes.of(Integer.MIN_VALUE + 1).minus(Minutes.of(1))); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_TemporalAmount_overflowTooBig() { Minutes.of(Integer.MAX_VALUE - 1).minus(Minutes.of(-2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_TemporalAmount_overflowTooSmall() { Minutes.of(Integer.MIN_VALUE + 1).minus(Minutes.of(2)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_minus_TemporalAmount_null() { Minutes.of(Integer.MIN_VALUE + 1).minus(null); } //----------------------------------------------------------------------- + @Test public void test_minus_int() { Minutes test5 = Minutes.of(5); assertEquals(Minutes.of(5), test5.minus(0)); @@ -275,17 +292,18 @@ public void test_minus_int() { assertEquals(Minutes.of(Integer.MIN_VALUE), Minutes.of(Integer.MIN_VALUE + 1).minus(1)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_int_overflowTooBig() { Minutes.of(Integer.MAX_VALUE - 1).minus(-2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_int_overflowTooSmall() { Minutes.of(Integer.MIN_VALUE + 1).minus(2); } //----------------------------------------------------------------------- + @Test public void test_multipliedBy() { Minutes test5 = Minutes.of(5); assertEquals(Minutes.of(0), test5.multipliedBy(0)); @@ -295,22 +313,24 @@ public void test_multipliedBy() { assertEquals(Minutes.of(-15), test5.multipliedBy(-3)); } + @Test public void test_multipliedBy_negate() { Minutes test5 = Minutes.of(5); assertEquals(Minutes.of(-15), test5.multipliedBy(-3)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_multipliedBy_overflowTooBig() { Minutes.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_multipliedBy_overflowTooSmall() { Minutes.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2); } //----------------------------------------------------------------------- + @Test public void test_dividedBy() { Minutes test12 = Minutes.of(12); assertEquals(Minutes.of(12), test12.dividedBy(1)); @@ -322,17 +342,19 @@ public void test_dividedBy() { assertEquals(Minutes.of(-4), test12.dividedBy(-3)); } + @Test public void test_dividedBy_negate() { Minutes test12 = Minutes.of(12); assertEquals(Minutes.of(-4), test12.dividedBy(-3)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_dividedBy_divideByZero() { Minutes.of(1).dividedBy(0); } //----------------------------------------------------------------------- + @Test public void test_negated() { assertEquals(Minutes.of(0), Minutes.of(0).negated()); assertEquals(Minutes.of(-12), Minutes.of(12).negated()); @@ -340,12 +362,13 @@ public void test_negated() { assertEquals(Minutes.of(-Integer.MAX_VALUE), Minutes.of(Integer.MAX_VALUE).negated()); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_negated_overflow() { Minutes.of(Integer.MIN_VALUE).negated(); } //----------------------------------------------------------------------- + @Test public void test_abs() { assertEquals(Minutes.of(0), Minutes.of(0).abs()); assertEquals(Minutes.of(12), Minutes.of(12).abs()); @@ -354,12 +377,13 @@ public void test_abs() { assertEquals(Minutes.of(Integer.MAX_VALUE), Minutes.of(-Integer.MAX_VALUE).abs()); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_abs_overflow() { Minutes.of(Integer.MIN_VALUE).abs(); } //----------------------------------------------------------------------- + @Test public void test_addTo() { LocalTime base = LocalTime.of(11, 30); assertEquals(Minutes.of(0).addTo(base), LocalTime.of(11, 30)); @@ -367,6 +391,7 @@ public void test_addTo() { } //----------------------------------------------------------------------- + @Test public void test_subtractFrom() { LocalTime base = LocalTime.of(11, 30); assertEquals(Minutes.of(0).subtractFrom(base), LocalTime.of(11, 30)); @@ -374,6 +399,7 @@ public void test_subtractFrom() { } //----------------------------------------------------------------------- + @Test public void test_toDuration() { for (int i = -20; i < 20; i++) { assertEquals(Minutes.of(i).toDuration(), Duration.ofMinutes(i)); @@ -381,6 +407,7 @@ public void test_toDuration() { } //----------------------------------------------------------------------- + @Test public void test_compareTo() { Minutes test5 = Minutes.of(5); Minutes test6 = Minutes.of(6); @@ -389,13 +416,14 @@ public void test_compareTo() { assertEquals(1, test6.compareTo(test5)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_compareTo_null() { Minutes test5 = Minutes.of(5); test5.compareTo(null); } //----------------------------------------------------------------------- + @Test public void test_equals() { Minutes test5 = Minutes.of(5); Minutes test6 = Minutes.of(6); @@ -404,17 +432,20 @@ public void test_equals() { assertEquals(false, test6.equals(test5)); } + @Test public void test_equals_null() { Minutes test5 = Minutes.of(5); assertEquals(false, test5.equals(null)); } + @Test public void test_equals_otherClass() { Minutes test5 = Minutes.of(5); assertEquals(false, test5.equals("")); } //----------------------------------------------------------------------- + @Test public void test_hashCode() { Minutes test5 = Minutes.of(5); Minutes test6 = Minutes.of(6); @@ -423,6 +454,7 @@ public void test_hashCode() { } //----------------------------------------------------------------------- + @Test public void test_toString() { Minutes test5 = Minutes.of(5); assertEquals("PT5M", test5.toString()); diff --git a/src/test/java/org/threeten/extra/TestMonths.java b/src/test/java/org/threeten/extra/TestMonths.java index 074938a6..326f2b38 100644 --- a/src/test/java/org/threeten/extra/TestMonths.java +++ b/src/test/java/org/threeten/extra/TestMonths.java @@ -31,9 +31,9 @@ */ package org.threeten.extra; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertSame; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -46,21 +46,27 @@ import java.time.format.DateTimeParseException; import java.time.temporal.TemporalAmount; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test class. */ -@Test +@RunWith(DataProviderRunner.class) public class TestMonths { //----------------------------------------------------------------------- + @Test public void test_isSerializable() { assertTrue(Serializable.class.isAssignableFrom(Months.class)); } //----------------------------------------------------------------------- + @Test public void test_deserializationSingleton() throws Exception { Months test = Months.ZERO; ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -73,12 +79,14 @@ public void test_deserializationSingleton() throws Exception { } //----------------------------------------------------------------------- + @Test public void test_ZERO() { assertSame(Months.of(0), Months.ZERO); assertSame(Months.of(0), Months.ZERO); assertEquals(Months.ZERO.getAmount(), 0); } + @Test public void test_ONE() { assertSame(Months.of(1), Months.ONE); assertSame(Months.of(1), Months.ONE); @@ -86,6 +94,7 @@ public void test_ONE() { } //----------------------------------------------------------------------- + @Test public void test_of() { assertEquals(Months.of(0).getAmount(), 0); assertEquals(Months.of(1).getAmount(), 1); @@ -97,6 +106,7 @@ public void test_of() { } //----------------------------------------------------------------------- + @Test public void test_ofYears() { assertEquals(Months.ofYears(0).getAmount(), 0); assertEquals(Months.ofYears(1).getAmount(), 12); @@ -107,45 +117,50 @@ public void test_ofYears() { assertEquals(Months.ofYears(Integer.MIN_VALUE / 12).getAmount(), (Integer.MIN_VALUE / 12) * 12); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_ofYears_overflow() { Months.ofYears((Integer.MAX_VALUE / 12) + 12); } //----------------------------------------------------------------------- + @Test public void test_from_Period_P0M() { assertEquals(Months.from(Period.ofMonths(0)), Months.of(0)); } + @Test public void test_from_Period_P2M() { assertEquals(Months.from(Period.ofMonths(2)), Months.of(2)); } + @Test public void test_from_P2Y() { assertEquals(Months.from(new MockYearsMonths(2, 0)), Months.of(24)); } + @Test public void test_from_P2Y3M() { assertEquals(Months.from(new MockYearsMonths(2, 3)), Months.of(27)); } + @Test public void test_from_yearsAndMonths() { assertEquals(Months.from(Period.of(3, 5, 0)), Months.of(41)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_from_wrongUnit_noConversion() { Months.from(Period.ofDays(2)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_from_null() { Months.from((TemporalAmount) null); } //----------------------------------------------------------------------- - @DataProvider(name = "parseValid") - Object[][] data_valid() { + @DataProvider + public static Object[][] data_valid() { return new Object[][] { {"P0M", 0}, {"P1M", 1}, @@ -175,23 +190,26 @@ Object[][] data_valid() { }; } - @Test(dataProvider = "parseValid") + @Test + @UseDataProvider("data_valid") public void test_parse_CharSequence_valid(String str, int expectedDays) { assertEquals(Months.parse(str), Months.of(expectedDays)); } - @Test(dataProvider = "parseValid") + @Test + @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, int expectedDays) { assertEquals(Months.parse("+" + str), Months.of(expectedDays)); } - @Test(dataProvider = "parseValid") + @Test + @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, int expectedDays) { assertEquals(Months.parse("-" + str), Months.of(-expectedDays)); } - @DataProvider(name = "parseInvalid") - Object[][] data_invalid() { + @DataProvider + public static Object[][] data_invalid() { return new Object[][] { {"P3W"}, {"P3D"}, @@ -208,17 +226,19 @@ Object[][] data_invalid() { }; } - @Test(expectedExceptions = DateTimeParseException.class, dataProvider = "parseInvalid") + @Test(expected = DateTimeParseException.class) + @UseDataProvider("data_invalid") public void test_parse_CharSequence_invalid(String str) { Months.parse(str); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_parse_CharSequence_null() { Months.parse((CharSequence) null); } //----------------------------------------------------------------------- + @Test public void test_plus_TemporalAmount_Months() { Months test5 = Months.of(5); assertEquals(Months.of(5), test5.plus(Months.of(0))); @@ -228,6 +248,7 @@ public void test_plus_TemporalAmount_Months() { assertEquals(Months.of(Integer.MIN_VALUE), Months.of(Integer.MIN_VALUE + 1).plus(Months.of(-1))); } + @Test public void test_plus_TemporalAmount_Period() { Months test5 = Months.of(5); assertEquals(Months.of(5), test5.plus(Period.ofMonths(0))); @@ -237,32 +258,33 @@ public void test_plus_TemporalAmount_Period() { assertEquals(Months.of(Integer.MIN_VALUE), Months.of(Integer.MIN_VALUE + 1).plus(Period.ofMonths(-1))); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_plus_TemporalAmount_PeriodDays() { Months.of(1).plus(Period.ofDays(2)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_plus_TemporalAmount_Duration() { Months.of(1).plus(Duration.ofHours(2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_TemporalAmount_overflowTooBig() { Months.of(Integer.MAX_VALUE - 1).plus(Months.of(2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_TemporalAmount_overflowTooSmall() { Months.of(Integer.MIN_VALUE + 1).plus(Months.of(-2)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_plus_TemporalAmount_null() { Months.of(Integer.MIN_VALUE + 1).plus(null); } //----------------------------------------------------------------------- + @Test public void test_plus_int() { Months test5 = Months.of(5); assertEquals(Months.of(5), test5.plus(0)); @@ -272,17 +294,18 @@ public void test_plus_int() { assertEquals(Months.of(Integer.MIN_VALUE), Months.of(Integer.MIN_VALUE + 1).plus(-1)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_int_overflowTooBig() { Months.of(Integer.MAX_VALUE - 1).plus(2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_int_overflowTooSmall() { Months.of(Integer.MIN_VALUE + 1).plus(-2); } //----------------------------------------------------------------------- + @Test public void test_minus_TemporalAmount_Months() { Months test5 = Months.of(5); assertEquals(Months.of(5), test5.minus(Months.of(0))); @@ -292,6 +315,7 @@ public void test_minus_TemporalAmount_Months() { assertEquals(Months.of(Integer.MIN_VALUE), Months.of(Integer.MIN_VALUE + 1).minus(Months.of(1))); } + @Test public void test_minus_TemporalAmount_Period() { Months test5 = Months.of(5); assertEquals(Months.of(5), test5.minus(Period.ofMonths(0))); @@ -301,32 +325,33 @@ public void test_minus_TemporalAmount_Period() { assertEquals(Months.of(Integer.MIN_VALUE), Months.of(Integer.MIN_VALUE + 1).minus(Period.ofMonths(1))); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_minus_TemporalAmount_PeriodDays() { Months.of(1).minus(Period.ofDays(2)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_minus_TemporalAmount_Duration() { Months.of(1).minus(Duration.ofHours(2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_TemporalAmount_overflowTooBig() { Months.of(Integer.MAX_VALUE - 1).minus(Months.of(-2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_TemporalAmount_overflowTooSmall() { Months.of(Integer.MIN_VALUE + 1).minus(Months.of(2)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_minus_TemporalAmount_null() { Months.of(Integer.MIN_VALUE + 1).minus(null); } //----------------------------------------------------------------------- + @Test public void test_minus_int() { Months test5 = Months.of(5); assertEquals(Months.of(5), test5.minus(0)); @@ -336,17 +361,18 @@ public void test_minus_int() { assertEquals(Months.of(Integer.MIN_VALUE), Months.of(Integer.MIN_VALUE + 1).minus(1)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_int_overflowTooBig() { Months.of(Integer.MAX_VALUE - 1).minus(-2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_int_overflowTooSmall() { Months.of(Integer.MIN_VALUE + 1).minus(2); } //----------------------------------------------------------------------- + @Test public void test_multipliedBy() { Months test5 = Months.of(5); assertEquals(Months.of(0), test5.multipliedBy(0)); @@ -356,22 +382,24 @@ public void test_multipliedBy() { assertEquals(Months.of(-15), test5.multipliedBy(-3)); } + @Test public void test_multipliedBy_negate() { Months test5 = Months.of(5); assertEquals(Months.of(-15), test5.multipliedBy(-3)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_multipliedBy_overflowTooBig() { Months.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_multipliedBy_overflowTooSmall() { Months.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2); } //----------------------------------------------------------------------- + @Test public void test_dividedBy() { Months test12 = Months.of(12); assertEquals(Months.of(12), test12.dividedBy(1)); @@ -383,17 +411,19 @@ public void test_dividedBy() { assertEquals(Months.of(-4), test12.dividedBy(-3)); } + @Test public void test_dividedBy_negate() { Months test12 = Months.of(12); assertEquals(Months.of(-4), test12.dividedBy(-3)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_dividedBy_divideByZero() { Months.of(1).dividedBy(0); } //----------------------------------------------------------------------- + @Test public void test_negated() { assertEquals(Months.of(0), Months.of(0).negated()); assertEquals(Months.of(-12), Months.of(12).negated()); @@ -401,12 +431,13 @@ public void test_negated() { assertEquals(Months.of(-Integer.MAX_VALUE), Months.of(Integer.MAX_VALUE).negated()); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_negated_overflow() { Months.of(Integer.MIN_VALUE).negated(); } //----------------------------------------------------------------------- + @Test public void test_abs() { assertEquals(Months.of(0), Months.of(0).abs()); assertEquals(Months.of(12), Months.of(12).abs()); @@ -415,12 +446,13 @@ public void test_abs() { assertEquals(Months.of(Integer.MAX_VALUE), Months.of(-Integer.MAX_VALUE).abs()); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_abs_overflow() { Months.of(Integer.MIN_VALUE).abs(); } //----------------------------------------------------------------------- + @Test public void test_toPeriod() { for (int i = -20; i < 20; i++) { assertEquals(Months.of(i).toPeriod(), Period.ofMonths(i)); @@ -428,6 +460,7 @@ public void test_toPeriod() { } //----------------------------------------------------------------------- + @Test public void test_compareTo() { Months test5 = Months.of(5); Months test6 = Months.of(6); @@ -436,13 +469,14 @@ public void test_compareTo() { assertEquals(1, test6.compareTo(test5)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_compareTo_null() { Months test5 = Months.of(5); test5.compareTo(null); } //----------------------------------------------------------------------- + @Test public void test_equals() { Months test5 = Months.of(5); Months test6 = Months.of(6); @@ -451,17 +485,20 @@ public void test_equals() { assertEquals(false, test6.equals(test5)); } + @Test public void test_equals_null() { Months test5 = Months.of(5); assertEquals(false, test5.equals(null)); } + @Test public void test_equals_otherClass() { Months test5 = Months.of(5); assertEquals(false, test5.equals("")); } //----------------------------------------------------------------------- + @Test public void test_hashCode() { Months test5 = Months.of(5); Months test6 = Months.of(6); @@ -470,6 +507,7 @@ public void test_hashCode() { } //----------------------------------------------------------------------- + @Test public void test_toString() { Months test5 = Months.of(5); assertEquals("P5M", test5.toString()); diff --git a/src/test/java/org/threeten/extra/TestMutableClock.java b/src/test/java/org/threeten/extra/TestMutableClock.java index 12cc949e..e7861e77 100644 --- a/src/test/java/org/threeten/extra/TestMutableClock.java +++ b/src/test/java/org/threeten/extra/TestMutableClock.java @@ -31,9 +31,9 @@ */ package org.threeten.extra; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotEquals; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -60,14 +60,14 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import org.testng.annotations.Test; +import org.junit.Test; /** * Test class. */ -@Test public class TestMutableClock { + @Test public void test_of() { assertEquals( MutableClock.of(Instant.EPOCH, ZoneOffset.UTC).instant(), @@ -89,21 +89,23 @@ public void test_of() { ZoneOffset.MAX); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_of_nullInstant() { MutableClock.of(null, ZoneOffset.UTC); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_of_nullZone() { MutableClock.of(Instant.EPOCH, null); } + @Test public void test_epochUTC() { assertEquals(MutableClock.epochUTC().instant(), Instant.EPOCH); assertEquals(MutableClock.epochUTC().getZone(), ZoneOffset.UTC); } + @Test public void test_setInstant() { MutableClock clock = MutableClock.epochUTC(); assertEquals(clock.instant(), Instant.EPOCH); @@ -115,11 +117,12 @@ public void test_setInstant() { assertEquals(clock.instant(), Instant.EPOCH.plusSeconds(10)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_setInstant_null() { MutableClock.epochUTC().setInstant(null); } + @Test public void test_add_amountOnly() { MutableClock clock = MutableClock.epochUTC(); clock.add(Duration.ofNanos(3)); @@ -138,11 +141,12 @@ public void test_add_amountOnly() { .toInstant()); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_add_amountOnly_null() { MutableClock.epochUTC().add(null); } + @Test public void test_add_amountAndUnit() { MutableClock clock = MutableClock.epochUTC(); clock.add(3, ChronoUnit.NANOS); @@ -161,11 +165,12 @@ public void test_add_amountAndUnit() { .toInstant()); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_add_amountAndUnit_nullUnit() { MutableClock.epochUTC().add(0, null); } + @Test public void test_set_adjuster() { MutableClock clock = MutableClock.epochUTC(); clock.set(LocalDate.of(0, 1, 2)); @@ -183,11 +188,12 @@ public void test_set_adjuster() { assertEquals(clock.instant(), Instant.EPOCH); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_set_adjuster_null() { MutableClock.epochUTC().set(null); } + @Test public void test_set_fieldAndValue() { MutableClock clock = MutableClock.epochUTC(); clock.set(ChronoField.YEAR, 0); @@ -203,11 +209,12 @@ public void test_set_fieldAndValue() { .toInstant()); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_set_fieldAndValue_nullField() { MutableClock.epochUTC().set(null, 0); } + @Test public void test_getZone() { MutableClock clock = MutableClock.epochUTC(); MutableClock withOtherZone = clock.withZone(ZoneOffset.MIN); @@ -217,6 +224,7 @@ public void test_getZone() { assertEquals(ofOtherZone.getZone(), ZoneOffset.MAX); } + @Test public void test_withZone() { MutableClock clock = MutableClock.epochUTC(); MutableClock withOtherZone = clock.withZone(ZoneOffset.MIN); @@ -230,11 +238,12 @@ public void test_withZone() { assertEquals(withSameZone, clock); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_withZone_null() { MutableClock.epochUTC().withZone(null); } + @Test public void test_instant() { MutableClock clock = MutableClock.epochUTC(); MutableClock withOtherZone = clock.withZone(ZoneOffset.MIN); @@ -246,6 +255,7 @@ public void test_instant() { assertEquals(withOtherZone.instant(), Instant.MIN); } + @Test public void test_equals() { MutableClock clock = MutableClock.epochUTC(); MutableClock withOtherZone = clock.withZone(ZoneOffset.MIN); @@ -259,6 +269,7 @@ public void test_equals() { assertNotEquals(independent, clock); } + @Test public void test_hashCode_isConstant() { MutableClock clock = MutableClock.epochUTC(); int hash = clock.hashCode(); @@ -272,6 +283,7 @@ public void test_hashCode_isConstant() { assertEquals(clock.hashCode(), hash); } + @Test public void test_hashCode_sameWhenSharedUpdates() { MutableClock clock = MutableClock.epochUTC(); MutableClock withOtherZone = clock.withZone(ZoneOffset.MIN); @@ -279,6 +291,7 @@ public void test_hashCode_sameWhenSharedUpdates() { assertEquals(clock.hashCode(), withSameZone.hashCode()); } + @Test public void test_toString() { MutableClock clock = MutableClock.epochUTC(); assertEquals( @@ -294,10 +307,12 @@ public void test_toString() { "MutableClock[2000-01-01T00:00:00Z,-18:00]"); } + @Test public void test_isSerializable() { assertTrue(Serializable.class.isAssignableFrom(MutableClock.class)); } + @Test public void test_serialization() throws Exception { MutableClock test = MutableClock.epochUTC(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -315,6 +330,7 @@ public void test_serialization() throws Exception { } } + @Test public void test_updatesAreAtomic() throws Exception { MutableClock clock = MutableClock.epochUTC(); Duration increment = Duration.ofSeconds(1); diff --git a/src/test/java/org/threeten/extra/TestPackedFields.java b/src/test/java/org/threeten/extra/TestPackedFields.java index f0354799..89d51116 100644 --- a/src/test/java/org/threeten/extra/TestPackedFields.java +++ b/src/test/java/org/threeten/extra/TestPackedFields.java @@ -35,7 +35,7 @@ import static java.time.temporal.ChronoUnit.FOREVER; import static java.time.temporal.ChronoUnit.MINUTES; import static java.time.temporal.ChronoUnit.SECONDS; -import static org.testng.Assert.assertEquals; +import static org.junit.Assert.assertEquals; import java.time.DateTimeException; import java.time.LocalDate; @@ -45,17 +45,17 @@ import java.time.format.DateTimeParseException; import java.time.format.ResolverStyle; -import org.testng.annotations.Test; +import org.junit.Test; /** * Test PackedFields. */ -@Test public class TestPackedFields { //----------------------------------------------------------------------- // packedDate() //----------------------------------------------------------------------- + @Test public void test_date_basics() { assertEquals(PackedFields.PACKED_DATE.toString(), "PackedDate"); assertEquals(PackedFields.PACKED_DATE.getBaseUnit(), DAYS); @@ -68,47 +68,51 @@ public void test_date_basics() { assertEquals(PackedFields.PACKED_DATE.range().getMaximum(), 99991231); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_date_rangeRefinedBy_time() { PackedFields.PACKED_DATE.rangeRefinedBy(LocalTime.of(11, 30)); } + @Test public void test_date_getFrom() { assertEquals(LocalDate.of(2015, 12, 3).get(PackedFields.PACKED_DATE), 20151203); assertEquals(LocalDate.of(1000, 1, 1).get(PackedFields.PACKED_DATE), 10000101); assertEquals(LocalDate.of(9999, 12, 31).get(PackedFields.PACKED_DATE), 99991231); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_date_getFrom_rangeLow() { PackedFields.PACKED_DATE.getFrom(LocalDate.of(999, 12, 31)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_date_getFrom_rangeHigh() { PackedFields.PACKED_DATE.getFrom(LocalDate.of(10000, 1, 1)); } + @Test public void test_date_adjustInto() { assertEquals(LocalDate.MIN.with(PackedFields.PACKED_DATE, 20151203), LocalDate.of(2015, 12, 3)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_date_adjustInto_range() { LocalDate.MIN.with(PackedFields.PACKED_DATE, 1230101); } + @Test public void test_date_resolve() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_DATE).toFormatter(); assertEquals(LocalDate.parse("20151203", f), LocalDate.of(2015, 12, 3)); } - @Test(expectedExceptions = DateTimeParseException.class) + @Test(expected = DateTimeParseException.class) public void test_date_resolve_invalid_smart() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_DATE).toFormatter(); LocalDate.parse("20151403", f.withResolverStyle(ResolverStyle.SMART)); } + @Test public void test_date_resolve_invalid_lenient() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_DATE).toFormatter(); assertEquals(LocalDate.parse("20151403", f.withResolverStyle(ResolverStyle.LENIENT)), LocalDate.of(2016, 2, 3)); @@ -117,6 +121,7 @@ public void test_date_resolve_invalid_lenient() { //----------------------------------------------------------------------- // packedHourMin() //----------------------------------------------------------------------- + @Test public void test_hourMin_basics() { assertEquals(PackedFields.PACKED_HOUR_MIN.toString(), "PackedHourMin"); assertEquals(PackedFields.PACKED_HOUR_MIN.getBaseUnit(), MINUTES); @@ -129,36 +134,40 @@ public void test_hourMin_basics() { assertEquals(PackedFields.PACKED_HOUR_MIN.range().getMaximum(), 2359); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_hourMin_rangeRefinedBy_time() { PackedFields.PACKED_HOUR_MIN.rangeRefinedBy(LocalDate.of(2015, 12, 3)); } + @Test public void test_hourMin_getFrom() { assertEquals(LocalTime.of(11, 30).get(PackedFields.PACKED_HOUR_MIN), 1130); assertEquals(LocalTime.of(1, 21).get(PackedFields.PACKED_HOUR_MIN), 121); } + @Test public void test_hourMin_adjustInto() { assertEquals(LocalTime.MIDNIGHT.with(PackedFields.PACKED_HOUR_MIN, 1130), LocalTime.of(11, 30)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_hourMin_adjustInto_value() { LocalDate.MIN.with(PackedFields.PACKED_HOUR_MIN, 1273); } + @Test public void test_hourMin_resolve() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_HOUR_MIN).toFormatter(); assertEquals(LocalTime.parse("1130", f), LocalTime.of(11, 30)); } - @Test(expectedExceptions = DateTimeParseException.class) + @Test(expected = DateTimeParseException.class) public void test_hourMin_resolve_invalid_smart() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_HOUR_MIN).toFormatter(); LocalTime.parse("1173", f.withResolverStyle(ResolverStyle.SMART)); } + @Test public void test_hourMin_resolve_invalid_lenient() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_HOUR_MIN).toFormatter(); assertEquals(LocalTime.parse("1173", f.withResolverStyle(ResolverStyle.LENIENT)), LocalTime.of(12, 13)); @@ -167,6 +176,7 @@ public void test_hourMin_resolve_invalid_lenient() { //----------------------------------------------------------------------- // packedTime() //----------------------------------------------------------------------- + @Test public void test_time_basics() { assertEquals(PackedFields.PACKED_TIME.toString(), "PackedTime"); assertEquals(PackedFields.PACKED_TIME.getBaseUnit(), SECONDS); @@ -179,37 +189,41 @@ public void test_time_basics() { assertEquals(PackedFields.PACKED_TIME.range().getMaximum(), 235959); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_time_rangeRefinedBy_time() { PackedFields.PACKED_TIME.rangeRefinedBy(LocalDate.of(2015, 12, 3)); } + @Test public void test_time_getFrom() { assertEquals(LocalTime.of(11, 30, 52).get(PackedFields.PACKED_TIME), 113052); assertEquals(LocalTime.of(11, 30).get(PackedFields.PACKED_TIME), 113000); assertEquals(LocalTime.of(1, 21).get(PackedFields.PACKED_TIME), 12100); } + @Test public void test_time_adjustInto() { assertEquals(LocalTime.MIDNIGHT.with(PackedFields.PACKED_TIME, 113052), LocalTime.of(11, 30, 52)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_time_adjustInto_value() { LocalDate.MIN.with(PackedFields.PACKED_TIME, 127310); } + @Test public void test_time_resolve() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_TIME).toFormatter(); assertEquals(LocalTime.parse("113052", f), LocalTime.of(11, 30, 52)); } - @Test(expectedExceptions = DateTimeParseException.class) + @Test(expected = DateTimeParseException.class) public void test_time_resolve_invalid_smart() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_TIME).toFormatter(); LocalTime.parse("117361", f.withResolverStyle(ResolverStyle.SMART)); } + @Test public void test_time_resolve_invalid_lenient() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_TIME).toFormatter(); assertEquals(LocalTime.parse("117361", f.withResolverStyle(ResolverStyle.LENIENT)), LocalTime.of(12, 14, 1)); diff --git a/src/test/java/org/threeten/extra/TestPeriodDuration.java b/src/test/java/org/threeten/extra/TestPeriodDuration.java index cbc4a794..396b98eb 100644 --- a/src/test/java/org/threeten/extra/TestPeriodDuration.java +++ b/src/test/java/org/threeten/extra/TestPeriodDuration.java @@ -37,15 +37,15 @@ import static java.time.temporal.ChronoUnit.NANOS; import static java.time.temporal.ChronoUnit.SECONDS; import static java.time.temporal.ChronoUnit.YEARS; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertThrows; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import java.time.DateTimeException; import java.time.Duration; import java.time.LocalDate; import java.time.LocalDateTime; @@ -54,13 +54,17 @@ import java.time.format.DateTimeParseException; import java.util.Arrays; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test class. */ -@Test +@RunWith(DataProviderRunner.class) public class TestPeriodDuration { private static final Period P1Y2M3D = Period.of(1, 2, 3); @@ -68,11 +72,13 @@ public class TestPeriodDuration { private static final Duration DUR_6 = Duration.ofSeconds(6); //----------------------------------------------------------------------- + @Test public void test_isSerializable() { assertTrue(Serializable.class.isAssignableFrom(PeriodDuration.class)); } //----------------------------------------------------------------------- + @Test public void test_serialization() throws Exception { PeriodDuration test = PeriodDuration.of(P1Y2M3D, DUR_5); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -85,6 +91,7 @@ public void test_serialization() throws Exception { } //----------------------------------------------------------------------- + @Test public void test_ZERO() { assertEquals(PeriodDuration.of(Period.ZERO, Duration.ZERO), PeriodDuration.ZERO); assertEquals(PeriodDuration.of(Period.ZERO), PeriodDuration.ZERO); @@ -98,10 +105,15 @@ public void test_ZERO() { assertEquals(PeriodDuration.ZERO.get(DAYS), 0); assertEquals(PeriodDuration.ZERO.get(SECONDS), 0); assertEquals(PeriodDuration.ZERO.get(NANOS), 0); - assertThrows(() -> PeriodDuration.ZERO.get(ERAS)); + } + + @Test(expected = DateTimeException.class) + public void test_ZERO_getEra() { + PeriodDuration.ZERO.get(ERAS); } //----------------------------------------------------------------------- + @Test public void test_of_both() { PeriodDuration test = PeriodDuration.of(P1Y2M3D, Duration.ofSeconds(4)); assertEquals(test.getPeriod(), P1Y2M3D); @@ -114,6 +126,7 @@ public void test_of_both() { assertEquals(test.get(NANOS), 0); } + @Test public void test_of_period() { PeriodDuration test = PeriodDuration.of(P1Y2M3D); assertEquals(test.getPeriod(), P1Y2M3D); @@ -126,6 +139,7 @@ public void test_of_period() { assertEquals(test.get(NANOS), 0); } + @Test public void test_of_duration() { PeriodDuration test = PeriodDuration.of(Duration.ofSeconds(4)); assertEquals(test.getPeriod(), Period.ZERO); @@ -139,24 +153,28 @@ public void test_of_duration() { } //----------------------------------------------------------------------- + @Test public void test_between_dates() { PeriodDuration test = PeriodDuration.between(LocalDate.of(2012, 6, 20), LocalDate.of(2012, 8, 25)); assertEquals(test.getPeriod(), Period.between(LocalDate.of(2012, 6, 20), LocalDate.of(2012, 8, 25))); assertEquals(test.getDuration(), Duration.ZERO); } + @Test public void test_between_times() { PeriodDuration test = PeriodDuration.between(LocalTime.of(11, 20), LocalTime.of(12, 25)); assertEquals(test.getPeriod(), Period.ZERO); assertEquals(test.getDuration(), Duration.between(LocalTime.of(11, 20), LocalTime.of(12, 25))); } + @Test public void test_between_mixed1() { PeriodDuration test = PeriodDuration.between(LocalDate.of(2012, 6, 20), LocalTime.of(11, 25)); assertEquals(test.getPeriod(), Period.ZERO); assertEquals(test.getDuration(), Duration.ofHours(11).plusMinutes(25)); } + @Test public void test_between_mixed2() { PeriodDuration test = PeriodDuration.between(LocalDate.of(2012, 6, 20), LocalDateTime.of(2012, 7, 22, 11, 25)); assertEquals(test.getPeriod(), Period.of(0, 1, 2)); @@ -164,6 +182,7 @@ public void test_between_mixed2() { } //----------------------------------------------------------------------- + @Test public void test_from() { assertEquals(PeriodDuration.from(PeriodDuration.of(P1Y2M3D)), PeriodDuration.from(PeriodDuration.of(P1Y2M3D))); assertEquals(PeriodDuration.from(Period.ofYears(2)), PeriodDuration.of(Period.ofYears(2))); @@ -176,8 +195,8 @@ public void test_from() { } //----------------------------------------------------------------------- - @DataProvider(name = "parseValid") - Object[][] data_valid() { + @DataProvider + public static Object[][] data_valid() { return new Object[][] { {"P1Y2M3W4DT5H6M7S", Period.of(1, 2, 3 * 7 + 4), Duration.ofHours(5).plusMinutes(6).plusSeconds(7)}, {"P3Y", Period.ofYears(3), Duration.ZERO}, @@ -201,23 +220,26 @@ Object[][] data_valid() { }; } - @Test(dataProvider = "parseValid") + @Test + @UseDataProvider("data_valid") public void test_parse_CharSequence_valid(String str, Period period, Duration duration) { assertEquals(PeriodDuration.parse(str), PeriodDuration.of(period, duration)); } - @Test(dataProvider = "parseValid") + @Test + @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, Period period, Duration duration) { assertEquals(PeriodDuration.parse("+" + str), PeriodDuration.of(period, duration)); } - @Test(dataProvider = "parseValid") + @Test + @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, Period period, Duration duration) { assertEquals(PeriodDuration.parse("-" + str), PeriodDuration.of(period, duration).negated()); } - @DataProvider(name = "parseInvalid") - Object[][] data_invalid() { + @DataProvider + public static Object[][] data_invalid() { return new Object[][] { {"P3Q"}, {"P1M2Y"}, @@ -234,61 +256,65 @@ Object[][] data_invalid() { }; } - @Test(expectedExceptions = DateTimeParseException.class, dataProvider = "parseInvalid") + @Test(expected = DateTimeParseException.class) + @UseDataProvider("data_invalid") public void test_parse_CharSequence_invalid(String str) { PeriodDuration.parse(str); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_parse_CharSequence_null() { PeriodDuration.parse((CharSequence) null); } //----------------------------------------------------------------------- + @Test public void test_plus_TemporalAmount_PeriodDuration() { PeriodDuration test = PeriodDuration.of(P1Y2M3D, DUR_5); assertEquals(test.plus(Period.of(3, 2, 1)), PeriodDuration.of(Period.of(4, 4, 4), DUR_5)); assertEquals(test.plus(Duration.ofSeconds(4)), PeriodDuration.of(P1Y2M3D, Duration.ofSeconds(9))); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_TemporalAmount_overflowTooBig() { PeriodDuration.of(Period.of(Integer.MAX_VALUE - 1, 0, 0)).plus(PeriodDuration.of(Period.ofYears(2))); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_TemporalAmount_overflowTooSmall() { PeriodDuration.of(Period.of(Integer.MIN_VALUE + 1, 0, 0)).plus(PeriodDuration.of(Period.ofYears(-2))); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_plus_TemporalAmount_null() { P1Y2M3D.plus(null); } //----------------------------------------------------------------------- + @Test public void test_minus_TemporalAmount_PeriodDuration() { PeriodDuration test = PeriodDuration.of(P1Y2M3D, DUR_5); assertEquals(test.minus(Period.of(1, 1, 1)), PeriodDuration.of(Period.of(0, 1, 2), DUR_5)); assertEquals(test.minus(Duration.ofSeconds(4)), PeriodDuration.of(P1Y2M3D, Duration.ofSeconds(1))); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_TemporalAmount_overflowTooBig() { PeriodDuration.of(Period.of(Integer.MAX_VALUE - 1, 0, 0)).minus(PeriodDuration.of(Period.ofYears(-2))); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_TemporalAmount_overflowTooSmall() { PeriodDuration.of(Period.of(Integer.MIN_VALUE + 1, 0, 0)).minus(PeriodDuration.of(Period.ofYears(2))); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_minus_TemporalAmount_null() { P1Y2M3D.minus(null); } //----------------------------------------------------------------------- + @Test public void test_multipliedBy() { PeriodDuration test = PeriodDuration.of(P1Y2M3D, DUR_5); assertEquals(test.multipliedBy(0), PeriodDuration.ZERO); @@ -297,32 +323,35 @@ public void test_multipliedBy() { assertEquals(test.multipliedBy(-3), PeriodDuration.of(Period.of(-3, -6, -9), Duration.ofSeconds(-15))); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_multipliedBy_overflowTooBig() { PeriodDuration.of(Period.ofYears(Integer.MAX_VALUE / 2 + 1)).multipliedBy(2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_multipliedBy_overflowTooSmall() { PeriodDuration.of(Period.ofYears(Integer.MIN_VALUE / 2 - 1)).multipliedBy(2); } //----------------------------------------------------------------------- + @Test public void test_negated() { assertEquals(PeriodDuration.of(P1Y2M3D, DUR_5).negated(), PeriodDuration.of(P1Y2M3D.negated(), DUR_5.negated())); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_negated_overflow() { PeriodDuration.of(Duration.ofSeconds(Long.MIN_VALUE)).negated(); } //----------------------------------------------------------------------- + @Test public void test_normalizedYears() { assertEquals(PeriodDuration.of(P1Y2M3D, DUR_5).normalizedYears(), PeriodDuration.of(P1Y2M3D.normalized(), DUR_5)); } //----------------------------------------------------------------------- + @Test public void test_normalizedStandardDays() { assertEquals( PeriodDuration.of(P1Y2M3D, Duration.ofHours(5)).normalizedStandardDays(), @@ -335,24 +364,27 @@ public void test_normalizedStandardDays() { PeriodDuration.of(P1Y2M3D.plusDays(-3), Duration.ofHours(-1))); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_normalizedStandardDaysn_overflow() { PeriodDuration.of(Duration.ofSeconds(Long.MIN_VALUE)).normalizedStandardDays(); } //----------------------------------------------------------------------- + @Test public void test_addTo() { LocalDateTime base = LocalDateTime.of(2012, 6, 20, 11, 30, 0); assertEquals(PeriodDuration.of(P1Y2M3D, DUR_5).addTo(base), LocalDateTime.of(2013, 8, 23, 11, 30, 5)); } //----------------------------------------------------------------------- + @Test public void test_subtractFrom() { LocalDateTime base = LocalDateTime.of(2012, 6, 20, 11, 30, 0); assertEquals(PeriodDuration.of(P1Y2M3D, DUR_5).subtractFrom(base), LocalDateTime.of(2011, 4, 17, 11, 29, 55)); } //----------------------------------------------------------------------- + @Test public void test_equals() { PeriodDuration test5 = PeriodDuration.of(P1Y2M3D, DUR_5); PeriodDuration test6 = PeriodDuration.of(P1Y2M3D, DUR_6); @@ -361,17 +393,20 @@ public void test_equals() { assertEquals(test6.equals(test5), false); } + @Test public void test_equals_null() { PeriodDuration test = PeriodDuration.of(P1Y2M3D, DUR_5); assertEquals(test.equals(null), false); } + @Test public void test_equals_otherClass() { PeriodDuration test = PeriodDuration.of(P1Y2M3D, DUR_5); assertEquals(test.equals(""), false); } //----------------------------------------------------------------------- + @Test public void test_hashCode() { PeriodDuration test5 = PeriodDuration.of(P1Y2M3D, DUR_5); PeriodDuration test6 = PeriodDuration.of(P1Y2M3D, DUR_6); @@ -380,6 +415,7 @@ public void test_hashCode() { } //----------------------------------------------------------------------- + @Test public void test_toString() { assertEquals("P1Y2M3DT5S", PeriodDuration.of(P1Y2M3D, DUR_5).toString()); assertEquals("P1Y2M3D", PeriodDuration.of(P1Y2M3D, Duration.ZERO).toString()); diff --git a/src/test/java/org/threeten/extra/TestQuarter.java b/src/test/java/org/threeten/extra/TestQuarter.java index 2d36130b..ba96bde4 100644 --- a/src/test/java/org/threeten/extra/TestQuarter.java +++ b/src/test/java/org/threeten/extra/TestQuarter.java @@ -63,8 +63,8 @@ import static java.time.temporal.ChronoField.YEAR_OF_ERA; import static java.time.temporal.IsoFields.QUARTER_OF_YEAR; import static java.time.temporal.IsoFields.QUARTER_YEARS; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.threeten.extra.Quarter.Q3; import java.io.Serializable; @@ -81,20 +81,19 @@ import java.time.temporal.UnsupportedTemporalTypeException; import java.util.Locale; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test Quarter. */ -@Test +@RunWith(DataProviderRunner.class) public class TestQuarter { - @BeforeMethod - public void setUp() { - } - //----------------------------------------------------------------------- @Test public void test_interfaces() { @@ -115,12 +114,12 @@ public void test_of_int_singleton() { } } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_int_valueTooLow() { Quarter.of(0); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_int_valueTooHigh() { Quarter.of(5); } @@ -144,12 +143,12 @@ public void test_ofMonth_int_singleton() { assertEquals(Quarter.ofMonth(12), Quarter.Q4); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_ofMonth_int_valueTooLow() { Quarter.ofMonth(0); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_ofMonth_int_valueTooHigh() { Quarter.ofMonth(13); } @@ -179,16 +178,17 @@ public void test_from_TemporalAccessor_Month() { assertEquals(Quarter.from(Month.DECEMBER), Quarter.Q4); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_from_TemporalAccessorl_invalid_noDerive() { Quarter.from(LocalTime.of(12, 30)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_from_TemporalAccessor_null() { Quarter.from((TemporalAccessor) null); } + @Test public void test_from_parse_CharSequence() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("'Q'Q"); assertEquals(formatter.parse("Q3", Quarter::from), Q3); @@ -202,12 +202,12 @@ public void test_getDisplayName() { assertEquals(Quarter.Q1.getDisplayName(TextStyle.SHORT, Locale.US), "Q1"); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_getDisplayName_nullStyle() { Quarter.Q1.getDisplayName(null, Locale.US); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_getDisplayName_nullLocale() { Quarter.Q1.getDisplayName(TextStyle.FULL, null); } @@ -215,6 +215,7 @@ public void test_getDisplayName_nullLocale() { //----------------------------------------------------------------------- // isSupported() //----------------------------------------------------------------------- + @Test public void test_isSupported() { Quarter test = Quarter.Q1; assertEquals(test.isSupported(null), false); @@ -254,16 +255,17 @@ public void test_isSupported() { //----------------------------------------------------------------------- // range() //----------------------------------------------------------------------- + @Test public void test_range() { assertEquals(Quarter.Q1.range(QUARTER_OF_YEAR), QUARTER_OF_YEAR.range()); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_range_invalidField() { Quarter.Q1.range(MONTH_OF_YEAR); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_range_null() { Quarter.Q1.range(null); } @@ -271,6 +273,7 @@ public void test_range_null() { //----------------------------------------------------------------------- // get() //----------------------------------------------------------------------- + @Test public void test_get() { assertEquals(Quarter.Q1.get(QUARTER_OF_YEAR), 1); assertEquals(Quarter.Q2.get(QUARTER_OF_YEAR), 2); @@ -278,12 +281,12 @@ public void test_get() { assertEquals(Quarter.Q4.get(QUARTER_OF_YEAR), 4); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_get_invalidField() { Quarter.Q2.get(MONTH_OF_YEAR); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_get_null() { Quarter.Q2.get(null); } @@ -291,6 +294,7 @@ public void test_get_null() { //----------------------------------------------------------------------- // getLong() //----------------------------------------------------------------------- + @Test public void test_getLong() { assertEquals(Quarter.Q1.getLong(QUARTER_OF_YEAR), 1); assertEquals(Quarter.Q2.getLong(QUARTER_OF_YEAR), 2); @@ -298,12 +302,12 @@ public void test_getLong() { assertEquals(Quarter.Q4.getLong(QUARTER_OF_YEAR), 4); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_getLong_invalidField() { Quarter.Q2.getLong(MONTH_OF_YEAR); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_getLong_null() { Quarter.Q2.getLong(null); } @@ -311,8 +315,8 @@ public void test_getLong_null() { //----------------------------------------------------------------------- // plus(long), plus(long,unit) //----------------------------------------------------------------------- - @DataProvider(name = "plus") - Object[][] data_plus() { + @DataProvider + public static Object[][] data_plus() { return new Object[][] { {1, -5, 4}, {1, -4, 1}, @@ -328,7 +332,8 @@ Object[][] data_plus() { }; } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_plus_long(int base, long amount, int expected) { assertEquals(Quarter.of(base).plus(amount), Quarter.of(expected)); } @@ -336,8 +341,8 @@ public void test_plus_long(int base, long amount, int expected) { //----------------------------------------------------------------------- // minus(long), minus(long,unit) //----------------------------------------------------------------------- - @DataProvider(name = "minus") - Object[][] data_minus() { + @DataProvider + public static Object[][] data_minus() { return new Object[][] { {1, -5, 2}, {1, -4, 1}, @@ -353,7 +358,8 @@ Object[][] data_minus() { }; } - @Test(dataProvider = "minus") + @Test + @UseDataProvider("data_minus") public void test_minus_long(int base, long amount, int expected) { assertEquals(Quarter.of(base).minus(amount), Quarter.of(expected)); } diff --git a/src/test/java/org/threeten/extra/TestSeconds.java b/src/test/java/org/threeten/extra/TestSeconds.java index 4d6c6901..0cb922d0 100644 --- a/src/test/java/org/threeten/extra/TestSeconds.java +++ b/src/test/java/org/threeten/extra/TestSeconds.java @@ -31,9 +31,9 @@ */ package org.threeten.extra; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertSame; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -44,21 +44,27 @@ import java.time.LocalTime; import java.time.format.DateTimeParseException; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test class. */ -@Test +@RunWith(DataProviderRunner.class) public class TestSeconds { //----------------------------------------------------------------------- + @Test public void test_isSerializable() { assertTrue(Serializable.class.isAssignableFrom(Seconds.class)); } //----------------------------------------------------------------------- + @Test public void test_deserializationSingleton() throws Exception { Seconds test = Seconds.ZERO; ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -71,6 +77,7 @@ public void test_deserializationSingleton() throws Exception { } //----------------------------------------------------------------------- + @Test public void test_ZERO() { assertSame(Seconds.of(0), Seconds.ZERO); assertSame(Seconds.of(0), Seconds.ZERO); @@ -78,6 +85,7 @@ public void test_ZERO() { } //----------------------------------------------------------------------- + @Test public void test_of() { assertEquals(Seconds.of(0).getAmount(), 0); assertEquals(Seconds.of(1).getAmount(), 1); @@ -89,6 +97,7 @@ public void test_of() { } //----------------------------------------------------------------------- + @Test public void test_ofHours() { assertEquals(Seconds.ofHours(0).getAmount(), 0); assertEquals(Seconds.ofHours(1).getAmount(), 3600); @@ -99,12 +108,13 @@ public void test_ofHours() { assertEquals(Seconds.ofHours(Integer.MIN_VALUE / 3600).getAmount(), (Integer.MIN_VALUE / 3600) * 3600); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_ofHours_overflow() { Seconds.ofHours((Integer.MAX_VALUE / 3600) + 3600); } //----------------------------------------------------------------------- + @Test public void test_ofMinutes() { assertEquals(Seconds.ofMinutes(0).getAmount(), 0); assertEquals(Seconds.ofMinutes(1).getAmount(), 60); @@ -115,14 +125,14 @@ public void test_ofMinutes() { assertEquals(Seconds.ofMinutes(Integer.MIN_VALUE / 60).getAmount(), (Integer.MIN_VALUE / 60) * 60); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_ofMinutes_overflow() { Seconds.ofMinutes((Integer.MAX_VALUE / 60) + 60); } //----------------------------------------------------------------------- - @DataProvider(name = "parseValid") - Object[][] data_valid() { + @DataProvider + public static Object[][] data_valid() { return new Object[][] { {"PT0S", 0}, {"PT1S", 1}, @@ -181,23 +191,26 @@ Object[][] data_valid() { }; } - @Test(dataProvider = "parseValid") + @Test + @UseDataProvider("data_valid") public void test_parse_CharSequence_valid(String str, int expectedSeconds) { assertEquals(Seconds.parse(str), Seconds.of(expectedSeconds)); } - @Test(dataProvider = "parseValid") + @Test + @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, int expectedSeconds) { assertEquals(Seconds.parse("+" + str), Seconds.of(expectedSeconds)); } - @Test(dataProvider = "parseValid") + @Test + @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, int expectedSeconds) { assertEquals(Seconds.parse("-" + str), Seconds.of(-expectedSeconds)); } - @DataProvider(name = "parseInvalid") - Object[][] data_invalid() { + @DataProvider + public static Object[][] data_invalid() { return new Object[][] { {"P3W"}, {"P3Q"}, @@ -216,17 +229,19 @@ Object[][] data_invalid() { }; } - @Test(expectedExceptions = DateTimeParseException.class, dataProvider = "parseInvalid") + @Test(expected = DateTimeParseException.class) + @UseDataProvider("data_invalid") public void test_parse_CharSequence_invalid(String str) { Seconds.parse(str); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_parse_CharSequence_null() { Seconds.parse((CharSequence) null); } //----------------------------------------------------------------------- + @Test public void test_plus_TemporalAmount_Seconds() { Seconds test5 = Seconds.of(5); assertEquals(Seconds.of(5), test5.plus(Seconds.of(0))); @@ -236,22 +251,23 @@ public void test_plus_TemporalAmount_Seconds() { assertEquals(Seconds.of(Integer.MIN_VALUE), Seconds.of(Integer.MIN_VALUE + 1).plus(Seconds.of(-1))); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_TemporalAmount_overflowTooBig() { Seconds.of(Integer.MAX_VALUE - 1).plus(Seconds.of(2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_TemporalAmount_overflowTooSmall() { Seconds.of(Integer.MIN_VALUE + 1).plus(Seconds.of(-2)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_plus_TemporalAmount_null() { Seconds.of(Integer.MIN_VALUE + 1).plus(null); } //----------------------------------------------------------------------- + @Test public void test_plus_int() { Seconds test5 = Seconds.of(5); assertEquals(Seconds.of(5), test5.plus(0)); @@ -261,17 +277,18 @@ public void test_plus_int() { assertEquals(Seconds.of(Integer.MIN_VALUE), Seconds.of(Integer.MIN_VALUE + 1).plus(-1)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_int_overflowTooBig() { Seconds.of(Integer.MAX_VALUE - 1).plus(2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_int_overflowTooSmall() { Seconds.of(Integer.MIN_VALUE + 1).plus(-2); } //----------------------------------------------------------------------- + @Test public void test_minus_TemporalAmount_Seconds() { Seconds test5 = Seconds.of(5); assertEquals(Seconds.of(5), test5.minus(Seconds.of(0))); @@ -281,22 +298,23 @@ public void test_minus_TemporalAmount_Seconds() { assertEquals(Seconds.of(Integer.MIN_VALUE), Seconds.of(Integer.MIN_VALUE + 1).minus(Seconds.of(1))); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_TemporalAmount_overflowTooBig() { Seconds.of(Integer.MAX_VALUE - 1).minus(Seconds.of(-2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_TemporalAmount_overflowTooSmall() { Seconds.of(Integer.MIN_VALUE + 1).minus(Seconds.of(2)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_minus_TemporalAmount_null() { Seconds.of(Integer.MIN_VALUE + 1).minus(null); } //----------------------------------------------------------------------- + @Test public void test_minus_int() { Seconds test5 = Seconds.of(5); assertEquals(Seconds.of(5), test5.minus(0)); @@ -306,17 +324,18 @@ public void test_minus_int() { assertEquals(Seconds.of(Integer.MIN_VALUE), Seconds.of(Integer.MIN_VALUE + 1).minus(1)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_int_overflowTooBig() { Seconds.of(Integer.MAX_VALUE - 1).minus(-2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_int_overflowTooSmall() { Seconds.of(Integer.MIN_VALUE + 1).minus(2); } //----------------------------------------------------------------------- + @Test public void test_multipliedBy() { Seconds test5 = Seconds.of(5); assertEquals(Seconds.of(0), test5.multipliedBy(0)); @@ -326,22 +345,24 @@ public void test_multipliedBy() { assertEquals(Seconds.of(-15), test5.multipliedBy(-3)); } + @Test public void test_multipliedBy_negate() { Seconds test5 = Seconds.of(5); assertEquals(Seconds.of(-15), test5.multipliedBy(-3)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_multipliedBy_overflowTooBig() { Seconds.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_multipliedBy_overflowTooSmall() { Seconds.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2); } //----------------------------------------------------------------------- + @Test public void test_dividedBy() { Seconds test12 = Seconds.of(12); assertEquals(Seconds.of(12), test12.dividedBy(1)); @@ -353,17 +374,19 @@ public void test_dividedBy() { assertEquals(Seconds.of(-4), test12.dividedBy(-3)); } + @Test public void test_dividedBy_negate() { Seconds test12 = Seconds.of(12); assertEquals(Seconds.of(-4), test12.dividedBy(-3)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_dividedBy_divideByZero() { Seconds.of(1).dividedBy(0); } //----------------------------------------------------------------------- + @Test public void test_negated() { assertEquals(Seconds.of(0), Seconds.of(0).negated()); assertEquals(Seconds.of(-12), Seconds.of(12).negated()); @@ -371,12 +394,13 @@ public void test_negated() { assertEquals(Seconds.of(-Integer.MAX_VALUE), Seconds.of(Integer.MAX_VALUE).negated()); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_negated_overflow() { Seconds.of(Integer.MIN_VALUE).negated(); } //----------------------------------------------------------------------- + @Test public void test_abs() { assertEquals(Seconds.of(0), Seconds.of(0).abs()); assertEquals(Seconds.of(12), Seconds.of(12).abs()); @@ -385,12 +409,13 @@ public void test_abs() { assertEquals(Seconds.of(Integer.MAX_VALUE), Seconds.of(-Integer.MAX_VALUE).abs()); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_abs_overflow() { Seconds.of(Integer.MIN_VALUE).abs(); } //----------------------------------------------------------------------- + @Test public void test_addTo() { LocalTime base = LocalTime.of(11, 30); assertEquals(Seconds.of(0).addTo(base), LocalTime.of(11, 30)); @@ -398,6 +423,7 @@ public void test_addTo() { } //----------------------------------------------------------------------- + @Test public void test_subtractFrom() { LocalTime base = LocalTime.of(11, 30); assertEquals(Seconds.of(0).subtractFrom(base), LocalTime.of(11, 30)); @@ -405,6 +431,7 @@ public void test_subtractFrom() { } //----------------------------------------------------------------------- + @Test public void test_toDuration() { for (int i = -20; i < 20; i++) { assertEquals(Seconds.of(i).toDuration(), Duration.ofSeconds(i)); @@ -412,6 +439,7 @@ public void test_toDuration() { } //----------------------------------------------------------------------- + @Test public void test_compareTo() { Seconds test5 = Seconds.of(5); Seconds test6 = Seconds.of(6); @@ -420,13 +448,14 @@ public void test_compareTo() { assertEquals(1, test6.compareTo(test5)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_compareTo_null() { Seconds test5 = Seconds.of(5); test5.compareTo(null); } //----------------------------------------------------------------------- + @Test public void test_equals() { Seconds test5 = Seconds.of(5); Seconds test6 = Seconds.of(6); @@ -435,17 +464,20 @@ public void test_equals() { assertEquals(false, test6.equals(test5)); } + @Test public void test_equals_null() { Seconds test5 = Seconds.of(5); assertEquals(false, test5.equals(null)); } + @Test public void test_equals_otherClass() { Seconds test5 = Seconds.of(5); assertEquals(false, test5.equals("")); } //----------------------------------------------------------------------- + @Test public void test_hashCode() { Seconds test5 = Seconds.of(5); Seconds test6 = Seconds.of(6); @@ -454,6 +486,7 @@ public void test_hashCode() { } //----------------------------------------------------------------------- + @Test public void test_toString() { Seconds test5 = Seconds.of(5); assertEquals("PT5S", test5.toString()); diff --git a/src/test/java/org/threeten/extra/TestTemporals.java b/src/test/java/org/threeten/extra/TestTemporals.java index e3465916..7662e528 100644 --- a/src/test/java/org/threeten/extra/TestTemporals.java +++ b/src/test/java/org/threeten/extra/TestTemporals.java @@ -52,11 +52,10 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static java.time.temporal.IsoFields.QUARTER_YEARS; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertSame; -import static org.testng.Assert.assertThrows; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -76,13 +75,17 @@ import java.time.temporal.UnsupportedTemporalTypeException; import java.util.concurrent.TimeUnit; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test Temporals. */ -@Test +@RunWith(DataProviderRunner.class) public class TestTemporals { //----------------------------------------------------------------------- @@ -222,38 +225,40 @@ public void test_previousWorkingDay_yearChange() { //----------------------------------------------------------------------- // parseFirstMatching() //----------------------------------------------------------------------- - @DataProvider(name = "parseFirstMatching") - Object[][] data_parseFirstMatching() { + @DataProvider + public static Object[][] data_parseFirstMatching() { return new Object[][] { {"2016-09-06", DateTimeFormatter.ISO_LOCAL_DATE, DateTimeFormatter.BASIC_ISO_DATE}, {"20160906", DateTimeFormatter.ISO_LOCAL_DATE, DateTimeFormatter.BASIC_ISO_DATE}, }; } - @Test(dataProvider = "parseFirstMatching") + @Test + @UseDataProvider("data_parseFirstMatching") public void test_parseFirstMatching(String text, DateTimeFormatter fmt1, DateTimeFormatter fmt2) { assertEquals(Temporals.parseFirstMatching(text, LocalDate::from, fmt1, fmt2), LocalDate.of(2016, 9, 6)); } + @Test(expected = DateTimeParseException.class) public void test_parseFirstMatching_zero() { - assertThrows(DateTimeParseException.class, () -> Temporals.parseFirstMatching("2016-09-06", LocalDate::from)); + Temporals.parseFirstMatching("2016-09-06", LocalDate::from); } + @Test public void test_parseFirstMatching_one() { assertEquals(Temporals.parseFirstMatching("2016-09-06", LocalDate::from, DateTimeFormatter.ISO_LOCAL_DATE), LocalDate.of(2016, 9, 6)); } + @Test(expected = DateTimeParseException.class) public void test_parseFirstMatching_twoNoMatch() { - assertThrows( - DateTimeParseException.class, - () -> Temporals.parseFirstMatching("2016", LocalDate::from, DateTimeFormatter.ISO_LOCAL_DATE, DateTimeFormatter.BASIC_ISO_DATE)); + Temporals.parseFirstMatching("2016", LocalDate::from, DateTimeFormatter.ISO_LOCAL_DATE, DateTimeFormatter.BASIC_ISO_DATE); } //----------------------------------------------------------------------- // chronoUnit() / timeUnit() //----------------------------------------------------------------------- - @DataProvider(name = "timeUnitConversion") - Object[][] data_timeUnitConversion() { + @DataProvider + public static Object[][] data_timeUnitConversion() { return new Object[][] { {ChronoUnit.NANOS, TimeUnit.NANOSECONDS}, {ChronoUnit.MICROS, TimeUnit.MICROSECONDS}, @@ -265,27 +270,29 @@ Object[][] data_timeUnitConversion() { }; } - @Test(dataProvider = "timeUnitConversion") + @Test + @UseDataProvider("data_timeUnitConversion") public void test_timeUnit(ChronoUnit chronoUnit, TimeUnit timeUnit) { assertEquals(Temporals.timeUnit(chronoUnit), timeUnit); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void test_timeUnit_unknown() { Temporals.timeUnit(ChronoUnit.MONTHS); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_timeUnit_null() { Temporals.timeUnit(null); } - @Test(dataProvider = "timeUnitConversion") + @Test + @UseDataProvider("data_timeUnitConversion") public void test_chronoUnit(ChronoUnit chronoUnit, TimeUnit timeUnit) { assertEquals(Temporals.chronoUnit(timeUnit), chronoUnit); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_chronoUnit_null() { Temporals.chronoUnit(null); } @@ -293,8 +300,8 @@ public void test_chronoUnit_null() { //----------------------------------------------------------------------- // convertAmount() //------------------------------------------------------------------------- - @DataProvider(name = "convertAmount") - Object[][] data_convertAmount() { + @DataProvider + public static Object[][] data_convertAmount() { return new Object[][] { {2L, NANOS, SECONDS, 0L, 2L}, {999_999_999L, NANOS, SECONDS, 0L, 999_999_999L}, @@ -440,7 +447,8 @@ Object[][] data_convertAmount() { }; } - @Test(dataProvider = "convertAmount") + @Test + @UseDataProvider("data_convertAmount") public void test_convertAmount( long fromAmount, TemporalUnit fromUnit, TemporalUnit resultUnit, long resultWhole, long resultRemainder) { @@ -449,7 +457,8 @@ public void test_convertAmount( assertEquals(result[1], resultRemainder); } - @Test(dataProvider = "convertAmount") + @Test + @UseDataProvider("data_convertAmount") public void test_convertAmount_negative( long fromAmount, TemporalUnit fromUnit, TemporalUnit resultUnit, long resultWhole, long resultRemainder) { @@ -480,8 +489,8 @@ public void test_convertAmountSameUnit_nonZero() { } } - @DataProvider(name = "convertAmountInvalid") - Object[][] data_convertAmountInvalid() { + @DataProvider + public static Object[][] data_convertAmountInvalid() { return new Object[][] { {SECONDS, MONTHS}, {SECONDS, QUARTER_YEARS}, @@ -499,13 +508,14 @@ Object[][] data_convertAmountInvalid() { }; } - @Test(dataProvider = "convertAmountInvalid", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_convertAmountInvalid") public void test_convertAmountInvalid(TemporalUnit fromUnit, TemporalUnit resultUnit) { Temporals.convertAmount(1, fromUnit, resultUnit); } - @DataProvider(name = "convertAmountInvalidUnsupported") - Object[][] data_convertAmountInvalidUnsupported() { + @DataProvider + public static Object[][] data_convertAmountInvalidUnsupported() { return new Object[][] { {SECONDS, ERAS}, {ERAS, SECONDS}, @@ -522,7 +532,8 @@ Object[][] data_convertAmountInvalidUnsupported() { }; } - @Test(dataProvider = "convertAmountInvalidUnsupported", expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) + @UseDataProvider("data_convertAmountInvalidUnsupported") public void test_convertAmountInvalidUnsupported(TemporalUnit fromUnit, TemporalUnit resultUnit) { Temporals.convertAmount(1, fromUnit, resultUnit); } diff --git a/src/test/java/org/threeten/extra/TestWeeks.java b/src/test/java/org/threeten/extra/TestWeeks.java index dc87df74..962f241e 100644 --- a/src/test/java/org/threeten/extra/TestWeeks.java +++ b/src/test/java/org/threeten/extra/TestWeeks.java @@ -31,9 +31,9 @@ */ package org.threeten.extra; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertSame; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -46,21 +46,27 @@ import java.time.format.DateTimeParseException; import java.time.temporal.TemporalAmount; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test class. */ -@Test +@RunWith(DataProviderRunner.class) public class TestWeeks { //----------------------------------------------------------------------- + @Test public void test_isSerializable() { assertTrue(Serializable.class.isAssignableFrom(Weeks.class)); } //----------------------------------------------------------------------- + @Test public void test_deserializationSingleton() throws Exception { Weeks test = Weeks.ZERO; ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -73,12 +79,14 @@ public void test_deserializationSingleton() throws Exception { } //----------------------------------------------------------------------- + @Test public void test_ZERO() { assertSame(Weeks.of(0), Weeks.ZERO); assertSame(Weeks.of(0), Weeks.ZERO); assertEquals(Weeks.ZERO.getAmount(), 0); } + @Test public void test_ONE() { assertSame(Weeks.of(1), Weeks.ONE); assertSame(Weeks.of(1), Weeks.ONE); @@ -86,6 +94,7 @@ public void test_ONE() { } //----------------------------------------------------------------------- + @Test public void test_of() { assertEquals(Weeks.of(1).getAmount(), 1); assertEquals(Weeks.of(2).getAmount(), 2); @@ -96,38 +105,43 @@ public void test_of() { } //----------------------------------------------------------------------- + @Test public void test_from_P0W() { assertEquals(Weeks.from(Period.ofWeeks(0)), Weeks.of(0)); } + @Test public void test_from_P2W() { assertEquals(Weeks.from(Period.ofWeeks(2)), Weeks.of(2)); } + @Test public void test_from_P14D() { assertEquals(Weeks.from(Period.ofDays(14)), Weeks.of(2)); } + @Test public void test_from_Duration() { assertEquals(Weeks.from(Duration.ofDays(14)), Weeks.of(2)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_from_wrongUnit_remainder() { Weeks.from(Period.ofDays(3)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_from_wrongUnit_noConversion() { Weeks.from(Period.ofMonths(2)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_from_null() { Weeks.from((TemporalAmount) null); } //----------------------------------------------------------------------- + @Test public void test_parse_CharSequence() { assertEquals(Weeks.parse("P0W"), Weeks.of(0)); assertEquals(Weeks.parse("P1W"), Weeks.of(1)); @@ -138,8 +152,8 @@ public void test_parse_CharSequence() { assertEquals(Weeks.parse("-P-2W"), Weeks.of(2)); } - @DataProvider(name = "parseInvalid") - Object[][] data_invalid() { + @DataProvider + public static Object[][] data_invalid() { return new Object[][] { {"P3Y"}, {"P3M"}, @@ -155,17 +169,19 @@ Object[][] data_invalid() { }; } - @Test(expectedExceptions = DateTimeParseException.class, dataProvider = "parseInvalid") + @Test(expected = DateTimeParseException.class) + @UseDataProvider("data_invalid") public void test_parse_CharSequence_invalid(String str) { Weeks.parse(str); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_parse_CharSequence_null() { Weeks.parse((CharSequence) null); } //----------------------------------------------------------------------- + @Test public void test_plus_TemporalAmount_Weeks() { Weeks test5 = Weeks.of(5); assertEquals(Weeks.of(5), test5.plus(Weeks.of(0))); @@ -175,6 +191,7 @@ public void test_plus_TemporalAmount_Weeks() { assertEquals(Weeks.of(Integer.MIN_VALUE), Weeks.of(Integer.MIN_VALUE + 1).plus(Weeks.of(-1))); } + @Test public void test_plus_TemporalAmount_Period() { Weeks test5 = Weeks.of(5); assertEquals(Weeks.of(5), test5.plus(Period.ofWeeks(0))); @@ -184,32 +201,33 @@ public void test_plus_TemporalAmount_Period() { assertEquals(Weeks.of(Integer.MIN_VALUE), Weeks.of(Integer.MIN_VALUE + 1).plus(Period.ofWeeks(-1))); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_plus_TemporalAmount_PeriodMonths() { Weeks.of(1).plus(Period.ofMonths(2)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_plus_TemporalAmount_Duration() { Weeks.of(1).plus(Duration.ofHours(2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_TemporalAmount_overflowTooBig() { Weeks.of(Integer.MAX_VALUE - 1).plus(Weeks.of(2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_TemporalAmount_overflowTooSmall() { Weeks.of(Integer.MIN_VALUE + 1).plus(Weeks.of(-2)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_plus_TemporalAmount_null() { Weeks.of(Integer.MIN_VALUE + 1).plus(null); } //----------------------------------------------------------------------- + @Test public void test_plus_int() { Weeks test5 = Weeks.of(5); assertEquals(Weeks.of(5), test5.plus(0)); @@ -219,17 +237,18 @@ public void test_plus_int() { assertEquals(Weeks.of(Integer.MIN_VALUE), Weeks.of(Integer.MIN_VALUE + 1).plus(-1)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_int_overflowTooBig() { Weeks.of(Integer.MAX_VALUE - 1).plus(2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_int_overflowTooSmall() { Weeks.of(Integer.MIN_VALUE + 1).plus(-2); } //----------------------------------------------------------------------- + @Test public void test_minus_TemporalAmount_Weeks() { Weeks test5 = Weeks.of(5); assertEquals(Weeks.of(5), test5.minus(Weeks.of(0))); @@ -239,6 +258,7 @@ public void test_minus_TemporalAmount_Weeks() { assertEquals(Weeks.of(Integer.MIN_VALUE), Weeks.of(Integer.MIN_VALUE + 1).minus(Weeks.of(1))); } + @Test public void test_minus_TemporalAmount_Period() { Weeks test5 = Weeks.of(5); assertEquals(Weeks.of(5), test5.minus(Period.ofWeeks(0))); @@ -248,32 +268,33 @@ public void test_minus_TemporalAmount_Period() { assertEquals(Weeks.of(Integer.MIN_VALUE), Weeks.of(Integer.MIN_VALUE + 1).minus(Period.ofWeeks(1))); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_minus_TemporalAmount_PeriodMonths() { Weeks.of(1).minus(Period.ofMonths(2)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_minus_TemporalAmount_Duration() { Weeks.of(1).minus(Duration.ofHours(2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_TemporalAmount_overflowTooBig() { Weeks.of(Integer.MAX_VALUE - 1).minus(Weeks.of(-2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_TemporalAmount_overflowTooSmall() { Weeks.of(Integer.MIN_VALUE + 1).minus(Weeks.of(2)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_minus_TemporalAmount_null() { Weeks.of(Integer.MIN_VALUE + 1).minus(null); } //----------------------------------------------------------------------- + @Test public void test_minus_int() { Weeks test5 = Weeks.of(5); assertEquals(Weeks.of(5), test5.minus(0)); @@ -283,17 +304,18 @@ public void test_minus_int() { assertEquals(Weeks.of(Integer.MIN_VALUE), Weeks.of(Integer.MIN_VALUE + 1).minus(1)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_int_overflowTooBig() { Weeks.of(Integer.MAX_VALUE - 1).minus(-2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_int_overflowTooSmall() { Weeks.of(Integer.MIN_VALUE + 1).minus(2); } //----------------------------------------------------------------------- + @Test public void test_multipliedBy() { Weeks test5 = Weeks.of(5); assertEquals(Weeks.of(0), test5.multipliedBy(0)); @@ -303,22 +325,24 @@ public void test_multipliedBy() { assertEquals(Weeks.of(-15), test5.multipliedBy(-3)); } + @Test public void test_multipliedBy_negate() { Weeks test5 = Weeks.of(5); assertEquals(Weeks.of(-15), test5.multipliedBy(-3)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_multipliedBy_overflowTooBig() { Weeks.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_multipliedBy_overflowTooSmall() { Weeks.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2); } //----------------------------------------------------------------------- + @Test public void test_dividedBy() { Weeks test12 = Weeks.of(12); assertEquals(Weeks.of(12), test12.dividedBy(1)); @@ -330,17 +354,19 @@ public void test_dividedBy() { assertEquals(Weeks.of(-4), test12.dividedBy(-3)); } + @Test public void test_dividedBy_negate() { Weeks test12 = Weeks.of(12); assertEquals(Weeks.of(-4), test12.dividedBy(-3)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_dividedBy_divideByZero() { Weeks.of(1).dividedBy(0); } //----------------------------------------------------------------------- + @Test public void test_negated() { assertEquals(Weeks.of(0), Weeks.of(0).negated()); assertEquals(Weeks.of(-12), Weeks.of(12).negated()); @@ -348,12 +374,13 @@ public void test_negated() { assertEquals(Weeks.of(-Integer.MAX_VALUE), Weeks.of(Integer.MAX_VALUE).negated()); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_negated_overflow() { Weeks.of(Integer.MIN_VALUE).negated(); } //----------------------------------------------------------------------- + @Test public void test_abs() { assertEquals(Weeks.of(0), Weeks.of(0).abs()); assertEquals(Weeks.of(12), Weeks.of(12).abs()); @@ -362,12 +389,13 @@ public void test_abs() { assertEquals(Weeks.of(Integer.MAX_VALUE), Weeks.of(-Integer.MAX_VALUE).abs()); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_abs_overflow() { Weeks.of(Integer.MIN_VALUE).abs(); } //----------------------------------------------------------------------- + @Test public void test_toPeriod() { for (int i = -20; i < 20; i++) { assertEquals(Weeks.of(i).toPeriod(), Period.ofWeeks(i)); @@ -375,6 +403,7 @@ public void test_toPeriod() { } //----------------------------------------------------------------------- + @Test public void test_compareTo() { Weeks test5 = Weeks.of(5); Weeks test6 = Weeks.of(6); @@ -383,13 +412,14 @@ public void test_compareTo() { assertEquals(1, test6.compareTo(test5)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_compareTo_null() { Weeks test5 = Weeks.of(5); test5.compareTo(null); } //----------------------------------------------------------------------- + @Test public void test_equals() { Weeks test5 = Weeks.of(5); Weeks test6 = Weeks.of(6); @@ -398,17 +428,20 @@ public void test_equals() { assertEquals(false, test6.equals(test5)); } + @Test public void test_equals_null() { Weeks test5 = Weeks.of(5); assertEquals(false, test5.equals(null)); } + @Test public void test_equals_otherClass() { Weeks test5 = Weeks.of(5); assertEquals(false, test5.equals("")); } //----------------------------------------------------------------------- + @Test public void test_hashCode() { Weeks test5 = Weeks.of(5); Weeks test6 = Weeks.of(6); @@ -417,6 +450,7 @@ public void test_hashCode() { } //----------------------------------------------------------------------- + @Test public void test_toString() { Weeks test5 = Weeks.of(5); assertEquals("P5W", test5.toString()); diff --git a/src/test/java/org/threeten/extra/TestYearQuarter.java b/src/test/java/org/threeten/extra/TestYearQuarter.java index 4fbf7e72..6826655e 100644 --- a/src/test/java/org/threeten/extra/TestYearQuarter.java +++ b/src/test/java/org/threeten/extra/TestYearQuarter.java @@ -78,8 +78,8 @@ import static java.time.temporal.IsoFields.DAY_OF_QUARTER; import static java.time.temporal.IsoFields.QUARTER_OF_YEAR; import static java.time.temporal.IsoFields.QUARTER_YEARS; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.threeten.extra.Quarter.Q1; import static org.threeten.extra.Quarter.Q2; import static org.threeten.extra.Quarter.Q3; @@ -107,24 +107,19 @@ import java.time.temporal.UnsupportedTemporalTypeException; import java.time.temporal.ValueRange; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; +import org.junit.Test; /** * Test YearQuarter. */ -@Test public class TestYearQuarter { private static final YearQuarter TEST = YearQuarter.of(2012, Q2); private static final int STANDARD_YEAR_LENGTH = 365; private static final int LEAP_YEAR_LENGTH = 366; - @BeforeMethod - public void setUp() { - } - //----------------------------------------------------------------------- + @Test public void test_interfaces() { assertTrue(Serializable.class.isAssignableFrom(YearQuarter.class)); assertTrue(Comparable.class.isAssignableFrom(YearQuarter.class)); @@ -132,6 +127,7 @@ public void test_interfaces() { assertTrue(TemporalAccessor.class.isAssignableFrom(YearQuarter.class)); } + @Test public void test_serialization() throws IOException, ClassNotFoundException { YearQuarter test = YearQuarter.of(2012, 1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -146,6 +142,7 @@ public void test_serialization() throws IOException, ClassNotFoundException { //----------------------------------------------------------------------- // of(int,Quarter) //----------------------------------------------------------------------- + @Test public void test_of_int_Quarter() { for (int year = -100; year <= 100; year++) { for (Quarter quarter : Quarter.values()) { @@ -157,17 +154,17 @@ public void test_of_int_Quarter() { } } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_int_Quarter_yearTooLow() { YearQuarter.of(Year.MIN_VALUE - 1, Quarter.Q2); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_int_Quarter_yearTooHigh() { YearQuarter.of(Year.MAX_VALUE + 1, Quarter.Q2); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_of_int_Quarter_null() { YearQuarter.of(2012, (Quarter) null); } @@ -175,6 +172,7 @@ public void test_of_int_Quarter_null() { //----------------------------------------------------------------------- // of(int,int) //----------------------------------------------------------------------- + @Test public void test_of_int_int() { for (int year = -100; year <= 100; year++) { for (int quarter = 1; quarter <= 4; quarter++) { @@ -188,22 +186,22 @@ public void test_of_int_int() { } } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_int_int_yearTooLow() { YearQuarter.of(Year.MIN_VALUE - 1, 1); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_int_int_yearTooHigh() { YearQuarter.of(Year.MAX_VALUE + 1, 1); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_int_int_quarterTooLow() { YearQuarter.of(2012, 0); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_int_int_quarterTooHigh() { YearQuarter.of(2012, 5); } @@ -211,6 +209,7 @@ public void test_of_int_int_quarterTooHigh() { //----------------------------------------------------------------------- // from(TemporalAccessor) //----------------------------------------------------------------------- + @Test public void test_from_TemporalAccessor_notLeapYear() { LocalDate date = LocalDate.of(2007, 1, 1); for (int i = 1; i <= STANDARD_YEAR_LENGTH; i++) { @@ -221,6 +220,7 @@ public void test_from_TemporalAccessor_notLeapYear() { } } + @Test public void test_from_TemporalAccessor_leapYear() { LocalDate date = LocalDate.of(2008, 1, 1); for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) { @@ -231,12 +231,12 @@ public void test_from_TemporalAccessor_leapYear() { } } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_from_TemporalAccessor_noDerive() { YearQuarter.from(LocalTime.NOON); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_from_TemporalAccessor_null() { YearQuarter.from((TemporalAccessor) null); } @@ -244,25 +244,27 @@ public void test_from_TemporalAccessor_null() { //----------------------------------------------------------------------- // parse(CharSequence) //----------------------------------------------------------------------- + @Test public void test_parse_CharSequence() { assertEquals(YearQuarter.parse("2012-Q3"), YearQuarter.of(2012, Q3)); } + @Test public void test_parse_CharSequence_caseInsensitive() { assertEquals(YearQuarter.parse("2012-q3"), YearQuarter.of(2012, Q3)); } - @Test(expectedExceptions = DateTimeParseException.class) + @Test(expected = DateTimeParseException.class) public void test_parse_CharSequenceDate_invalidYear() { YearQuarter.parse("12345-Q3"); } - @Test(expectedExceptions = DateTimeParseException.class) + @Test(expected = DateTimeParseException.class) public void test_parse_CharSequenceDate_invalidQuarter() { YearQuarter.parse("2012-Q0"); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_parse_CharSequenceDate_nullCharSequence() { YearQuarter.parse((CharSequence) null); } @@ -270,24 +272,25 @@ public void test_parse_CharSequenceDate_nullCharSequence() { //----------------------------------------------------------------------- // parse(CharSequence,DateTimeFormatter) //----------------------------------------------------------------------- + @Test public void test_parse_CharSequenceDateTimeFormatter() { DateTimeFormatter f = DateTimeFormatter.ofPattern("'Q'Q uuuu"); assertEquals(YearQuarter.parse("Q3 2012", f), YearQuarter.of(2012, Q3)); } - @Test(expectedExceptions = DateTimeParseException.class) + @Test(expected = DateTimeParseException.class) public void test_parse_CharSequenceDateDateTimeFormatter_invalidQuarter() { DateTimeFormatter f = DateTimeFormatter.ofPattern("'Q'Q uuuu"); YearQuarter.parse("Q0 2012", f); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_parse_CharSequenceDateTimeFormatter_nullCharSequence() { DateTimeFormatter f = DateTimeFormatter.ofPattern("'Q'Q uuuu"); YearQuarter.parse((CharSequence) null, f); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_parse_CharSequenceDateTimeFormatter_nullDateTimeFormatter() { YearQuarter.parse("", (DateTimeFormatter) null); } @@ -295,6 +298,7 @@ public void test_parse_CharSequenceDateTimeFormatter_nullDateTimeFormatter() { //----------------------------------------------------------------------- // isSupported(TemporalField) //----------------------------------------------------------------------- + @Test public void test_isSupported_TemporalField() { assertEquals(TEST.isSupported((TemporalField) null), false); assertEquals(TEST.isSupported(NANO_OF_SECOND), false); @@ -334,6 +338,7 @@ public void test_isSupported_TemporalField() { //----------------------------------------------------------------------- // isSupported(TemporalUnit) //----------------------------------------------------------------------- + @Test public void test_isSupported_TemporalUnit() { assertEquals(TEST.isSupported((TemporalUnit) null), false); assertEquals(TEST.isSupported(NANOS), false); @@ -357,6 +362,7 @@ public void test_isSupported_TemporalUnit() { //----------------------------------------------------------------------- // range(TemporalField) //----------------------------------------------------------------------- + @Test public void test_range() { assertEquals(TEST.range(QUARTER_OF_YEAR), QUARTER_OF_YEAR.range()); assertEquals(TEST.range(YEAR), YEAR.range()); @@ -364,12 +370,12 @@ public void test_range() { assertEquals(TEST.range(ERA), ERA.range()); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_range_invalidField() { TEST.range(MONTH_OF_YEAR); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_range_null() { TEST.range((TemporalField) null); } @@ -377,6 +383,7 @@ public void test_range_null() { //----------------------------------------------------------------------- // get(TemporalField) //----------------------------------------------------------------------- + @Test public void test_get() { assertEquals(TEST.get(QUARTER_OF_YEAR), 2); assertEquals(TEST.get(YEAR), 2012); @@ -384,12 +391,12 @@ public void test_get() { assertEquals(TEST.get(ERA), 1); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_get_invalidField() { TEST.get(MONTH_OF_YEAR); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_get_null() { TEST.get((TemporalField) null); } @@ -397,6 +404,7 @@ public void test_get_null() { //----------------------------------------------------------------------- // getLong(TemporalField) //----------------------------------------------------------------------- + @Test public void test_getLong() { assertEquals(TEST.getLong(QUARTER_OF_YEAR), 2L); assertEquals(TEST.getLong(YEAR), 2012L); @@ -404,12 +412,12 @@ public void test_getLong() { assertEquals(TEST.getLong(ERA), 1L); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_getLong_invalidField() { TEST.getLong(MONTH_OF_YEAR); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_getLong_null() { TEST.getLong((TemporalField) null); } @@ -417,6 +425,7 @@ public void test_getLong_null() { //----------------------------------------------------------------------- // isLeapYear(int) //----------------------------------------------------------------------- + @Test public void test_isLeapYear_int() { for (int year = -500; year <= 500; year++) { for (Quarter quarter : Quarter.values()) { @@ -483,6 +492,7 @@ public void test_isValidDay_int_outOfRange() { //----------------------------------------------------------------------- // lengthOfQuarter() //----------------------------------------------------------------------- + @Test public void test_lengthOfQuarter() { for (int year = -500; year <= 500; year++) { assertEquals(YearQuarter.of(year, Q1).lengthOfQuarter(), Year.isLeap(year) ? 91 : 90); @@ -495,24 +505,27 @@ public void test_lengthOfQuarter() { //----------------------------------------------------------------------- // with(TemporalAdjuster) //----------------------------------------------------------------------- + @Test public void test_with_TemporalAdjuster_Quarter() { assertEquals(YearQuarter.of(2007, Q2).with(Q1), YearQuarter.of(2007, Q1)); } + @Test public void test_with_TemporalAdjuster_Year() { assertEquals(YearQuarter.of(2007, Q2).with(Year.of(2012)), YearQuarter.of(2012, Q2)); } + @Test public void test_with_TemporalAdjuster_YearQuarter() { assertEquals(YearQuarter.of(2007, Q2).with(YearQuarter.of(2012, Q3)), YearQuarter.of(2012, Q3)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_with_TemporalAdjuster_LocalDate() { YearQuarter.of(2007, Q2).with(LocalDate.of(2012, 6, 30)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_with_TemporalAdjuster_null() { YearQuarter.of(2007, Q2).with((TemporalAdjuster) null); } @@ -520,16 +533,17 @@ public void test_with_TemporalAdjuster_null() { //----------------------------------------------------------------------- // withYear(int) //----------------------------------------------------------------------- + @Test public void test_withYear() { assertEquals(YearQuarter.of(2007, Q2).withYear(2012), YearQuarter.of(2012, Q2)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_withYear_int_quarterTooLow() { TEST.withYear(Year.MIN_VALUE - 1); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_withYear_int_quarterTooHigh() { TEST.withYear(Year.MAX_VALUE + 1); } @@ -537,16 +551,17 @@ public void test_withYear_int_quarterTooHigh() { //----------------------------------------------------------------------- // withQuarter(int) //----------------------------------------------------------------------- + @Test public void test_withQuarter_int() { assertEquals(YearQuarter.of(2007, Q2).withQuarter(1), YearQuarter.of(2007, Q1)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_withQuarter_int_quarterTooLow() { TEST.withQuarter(0); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_withQuarter_int_quarterTooHigh() { TEST.withQuarter(5); } @@ -554,6 +569,7 @@ public void test_withQuarter_int_quarterTooHigh() { //----------------------------------------------------------------------- // plus(long,TemporalUnit) //----------------------------------------------------------------------- + @Test public void test_plus_longTemporalUnit() { assertEquals(YearQuarter.of(2007, Q2).plus(5, YEARS), YearQuarter.of(2012, Q2)); assertEquals(YearQuarter.of(2007, Q2).plus(0, YEARS), YearQuarter.of(2007, Q2)); @@ -566,6 +582,7 @@ public void test_plus_longTemporalUnit() { //----------------------------------------------------------------------- // plusYears(int) //----------------------------------------------------------------------- + @Test public void test_plusYears() { assertEquals(YearQuarter.of(2007, Q2).plusYears(5), YearQuarter.of(2012, Q2)); assertEquals(YearQuarter.of(2007, Q2).plusYears(0), YearQuarter.of(2007, Q2)); @@ -575,6 +592,7 @@ public void test_plusYears() { //----------------------------------------------------------------------- // plusQuarters(int) //----------------------------------------------------------------------- + @Test public void test_plusQuarters() { assertEquals(YearQuarter.of(2007, Q2).plusQuarters(5), YearQuarter.of(2008, Q3)); assertEquals(YearQuarter.of(2007, Q2).plusQuarters(0), YearQuarter.of(2007, Q2)); @@ -584,6 +602,7 @@ public void test_plusQuarters() { //----------------------------------------------------------------------- // minus(long,TemporalUnit) //----------------------------------------------------------------------- + @Test public void test_minus_longTemporalUnit() { assertEquals(YearQuarter.of(2007, Q2).minus(5, YEARS), YearQuarter.of(2002, Q2)); assertEquals(YearQuarter.of(2007, Q2).minus(0, YEARS), YearQuarter.of(2007, Q2)); @@ -596,6 +615,7 @@ public void test_minus_longTemporalUnit() { //----------------------------------------------------------------------- // minusYears(int) //----------------------------------------------------------------------- + @Test public void test_minusYears() { assertEquals(YearQuarter.of(2007, Q2).minusYears(5), YearQuarter.of(2002, Q2)); assertEquals(YearQuarter.of(2007, Q2).minusYears(0), YearQuarter.of(2007, Q2)); @@ -605,6 +625,7 @@ public void test_minusYears() { //----------------------------------------------------------------------- // minusQuarters(int) //----------------------------------------------------------------------- + @Test public void test_minusQuarters() { assertEquals(YearQuarter.of(2007, Q2).minusQuarters(5), YearQuarter.of(2006, Q1)); assertEquals(YearQuarter.of(2007, Q2).minusQuarters(0), YearQuarter.of(2007, Q2)); @@ -614,6 +635,7 @@ public void test_minusQuarters() { //----------------------------------------------------------------------- // lengthOfYear() //----------------------------------------------------------------------- + @Test public void test_lengthOfYear() { for (int year = -500; year <= 500; year++) { for (Quarter quarter : Quarter.values()) { @@ -640,6 +662,7 @@ public void test_query() { //----------------------------------------------------------------------- // adjustInto(Temporal) //----------------------------------------------------------------------- + @Test public void test_adjustInto_Temporal() { for (int month = 1; month < 12; month++) { for (int dom = 1; dom < 28; dom++) { @@ -650,19 +673,21 @@ public void test_adjustInto_Temporal() { } } + @Test public void test_adjustInto_Temporal_lastValidDay_nonLeap() { LocalDate base = LocalDate.of(2007, 5, 31); LocalDate expected = LocalDate.of(2011, 2, 28); assertEquals(YearQuarter.of(2011, Q1).adjustInto(base), expected); } + @Test public void test_adjustInto_Temporal_lastValidDay_leap() { LocalDate base = LocalDate.of(2007, 5, 31); LocalDate expected = LocalDate.of(2012, 2, 29); assertEquals(YearQuarter.of(2012, Q1).adjustInto(base), expected); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_adjustInto_Temporal_null() { TEST.adjustInto((Temporal) null); } @@ -670,6 +695,7 @@ public void test_adjustInto_Temporal_null() { //----------------------------------------------------------------------- // until(Temporal,TemporalUnit) //----------------------------------------------------------------------- + @Test public void test_until_TemporalTemporalUnit_QUARTER_YEARS() { assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2011, Q4), QUARTER_YEARS), -2); assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q1), QUARTER_YEARS), -1); @@ -681,6 +707,7 @@ public void test_until_TemporalTemporalUnit_QUARTER_YEARS() { assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2013, Q3), QUARTER_YEARS), 5); } + @Test public void test_until_TemporalTemporalUnit_YEARS() { assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2010, Q2), YEARS), -2); assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2010, Q3), YEARS), -1); @@ -701,12 +728,12 @@ public void test_until_TemporalTemporalUnit_YEARS() { assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2014, Q2), YEARS), 2); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_until_TemporalTemporalUnit_nullTemporal() { YearQuarter.of(2012, Q2).until(null, QUARTER_YEARS); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_until_TemporalTemporalUnit_nullTemporalUnit() { YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q3), null); } @@ -714,12 +741,13 @@ public void test_until_TemporalTemporalUnit_nullTemporalUnit() { //----------------------------------------------------------------------- // format(DateTimeFormatter) //----------------------------------------------------------------------- + @Test public void test_format() { DateTimeFormatter f = DateTimeFormatter.ofPattern("'Q'Q uuuu"); assertEquals(YearQuarter.of(2012, Q1).format(f), "Q1 2012"); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_format_null() { TEST.format((DateTimeFormatter) null); } @@ -727,6 +755,7 @@ public void test_format_null() { //----------------------------------------------------------------------- // atDay(int) //----------------------------------------------------------------------- + @Test public void test_atDay() { for (int i = 1; i <= 90; i++) { LocalDate expected = LocalDate.of(2012, 1, 1).plusDays(i - 1); @@ -746,31 +775,32 @@ public void test_atDay() { } } + @Test public void test_atDay_Q1_91_leap() { assertEquals(YearQuarter.of(2012, Q1).atDay(91), LocalDate.of(2012, 3, 31)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_atDay_Q1_91_notLeap() { YearQuarter.of(2011, Q1).atDay(91); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_atDay_Q1_92() { YearQuarter.of(2012, Q1).atDay(92); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_atDay_Q2_92() { YearQuarter.of(2012, Q2).atDay(92); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_atDay_tooLow() { TEST.atDay(0); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_atDay_tooHigh() { TEST.atDay(93); } @@ -778,6 +808,7 @@ public void test_atDay_tooHigh() { //----------------------------------------------------------------------- // atEndOfQuarter(int) //----------------------------------------------------------------------- + @Test public void test_atEndOfQuarter() { assertEquals(YearQuarter.of(2011, Q1).atEndOfQuarter(), LocalDate.of(2011, 3, 31)); assertEquals(YearQuarter.of(2011, Q2).atEndOfQuarter(), LocalDate.of(2011, 6, 30)); @@ -793,6 +824,7 @@ public void test_atEndOfQuarter() { //----------------------------------------------------------------------- // compareTo() //----------------------------------------------------------------------- + @Test public void test_compareTo() { for (int year1 = -100; year1 < 100; year1++) { for (Quarter quarter1 : Quarter.values()) { @@ -844,7 +876,7 @@ public void test_compareTo() { } } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_compareTo_nullYearQuarter() { TEST.compareTo(null); } @@ -852,6 +884,7 @@ public void test_compareTo_nullYearQuarter() { //----------------------------------------------------------------------- // equals() / hashCode() //----------------------------------------------------------------------- + @Test public void test_equals() { for (int year1 = -100; year1 < 100; year1++) { for (Quarter quarter1 : Quarter.values()) { @@ -869,10 +902,12 @@ public void test_equals() { } } + @Test public void test_equals_nullYearQuarter() { assertEquals(TEST.equals(null), false); } + @Test public void test_equals_incorrectType() { assertEquals(TEST.equals("Incorrect type"), false); } @@ -880,18 +915,22 @@ public void test_equals_incorrectType() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- + @Test public void test_toString() { assertEquals(YearQuarter.of(2012, Q2).toString(), "2012-Q2"); } + @Test public void test_toString_bigYear() { assertEquals(YearQuarter.of(10000, Q2).toString(), "+10000-Q2"); } + @Test public void test_toString_negativeYear() { assertEquals(YearQuarter.of(-1, Q2).toString(), "-0001-Q2"); } + @Test public void test_toString_negativeBigYear() { assertEquals(YearQuarter.of(-10000, Q2).toString(), "-10000-Q2"); } diff --git a/src/test/java/org/threeten/extra/TestYearWeek.java b/src/test/java/org/threeten/extra/TestYearWeek.java index 906e48e0..69b78a16 100644 --- a/src/test/java/org/threeten/extra/TestYearWeek.java +++ b/src/test/java/org/threeten/extra/TestYearWeek.java @@ -72,9 +72,9 @@ import static java.time.temporal.IsoFields.QUARTER_OF_YEAR; import static java.time.temporal.IsoFields.WEEK_BASED_YEAR; import static java.time.temporal.IsoFields.WEEK_OF_WEEK_BASED_YEAR; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -104,17 +104,21 @@ import java.time.temporal.ValueRange; import java.util.Locale; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Test; +import org.junit.runner.RunWith; -@Test +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; + +@RunWith(DataProviderRunner.class) public class TestYearWeek { private static final YearWeek TEST_NON_LEAP = YearWeek.of(2014, 1); private static final YearWeek TEST = YearWeek.of(2015, 1); - @DataProvider(name = "sampleYearWeeks") - Object[][] provider_sampleYearWeeks() { + @DataProvider + public static Object[][] data_sampleYearWeeks() { return new Object[][]{ {2015, 1}, {2015, 2}, @@ -175,8 +179,8 @@ Object[][] provider_sampleYearWeeks() { }; } - @DataProvider(name = "53WeekYear") - Object[][] provider_53WeekYear() { + @DataProvider + public static Object[][] data_53WeekYear() { return new Object[][]{ {4}, {9}, @@ -252,8 +256,8 @@ Object[][] provider_53WeekYear() { }; } - @DataProvider(name = "sampleAtDay") - Object[][] provider_sampleAtDay() { + @DataProvider + public static Object[][] data_sampleAtDay() { return new Object[][]{ {2014, 52, MONDAY, 2014, 12, 22}, {2014, 52, TUESDAY, 2014, 12, 23}, @@ -286,6 +290,7 @@ Object[][] provider_sampleAtDay() { } //----------------------------------------------------------------------- + @Test public void test_interfaces() { assertTrue(Serializable.class.isAssignableFrom(YearWeek.class)); assertTrue(Comparable.class.isAssignableFrom(YearWeek.class)); @@ -293,6 +298,7 @@ public void test_interfaces() { assertTrue(TemporalAccessor.class.isAssignableFrom(YearWeek.class)); } + @Test public void test_serialization() throws IOException, ClassNotFoundException { YearWeek test = YearWeek.of(2015, 1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -324,7 +330,7 @@ public void test_now() { //----------------------------------------------------------------------- // now(ZoneId) //----------------------------------------------------------------------- - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void now_ZoneId_nullZoneId() { YearWeek.now((ZoneId) null); } @@ -356,7 +362,7 @@ public void now_Clock() { assertEquals(test.getWeek(), 52); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void now_Clock_nullClock() { YearWeek.now((Clock) null); } @@ -364,33 +370,35 @@ public void now_Clock_nullClock() { //----------------------------------------------------------------------- // of(int, int) //----------------------------------------------------------------------- - @Test(dataProvider = "sampleYearWeeks") + @Test + @UseDataProvider("data_sampleYearWeeks") public void test_of(int year, int week) { YearWeek yearWeek = YearWeek.of(year, week); assertEquals(yearWeek.getYear(), year); assertEquals(yearWeek.getWeek(), week); } + @Test public void test_carry() { assertTrue(YearWeek.of(2014, 53).equals(TEST)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_year_tooLow() { YearWeek.of(Integer.MIN_VALUE, 1); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_year_tooHigh() { YearWeek.of(Integer.MAX_VALUE, 1); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_invalidWeekValue() { YearWeek.of(2015, 54); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_of_invalidWeekValueZero() { YearWeek.of(2015, 0); } @@ -398,6 +406,7 @@ public void test_of_invalidWeekValueZero() { //----------------------------------------------------------------------- // isSupported(TemporalField) //----------------------------------------------------------------------- + @Test public void test_isSupported_TemporalField() { assertEquals(TEST.isSupported((TemporalField) null), false); assertEquals(TEST.isSupported(NANO_OF_SECOND), false); @@ -439,7 +448,8 @@ public void test_isSupported_TemporalField() { //----------------------------------------------------------------------- // atDay(DayOfWeek) //----------------------------------------------------------------------- - @Test(dataProvider = "sampleAtDay") + @Test + @UseDataProvider("data_sampleAtDay") public void test_atDay(int weekBasedYear, int weekOfWeekBasedYear, DayOfWeek dayOfWeek, int year, int month, int dayOfMonth) { YearWeek yearWeek = YearWeek.of(weekBasedYear, weekOfWeekBasedYear); LocalDate expected = LocalDate.of(year, month, dayOfMonth); @@ -462,7 +472,7 @@ public void test_atDay_loop20years() { } } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_atDay_null() { TEST.atDay(null); } @@ -470,7 +480,8 @@ public void test_atDay_null() { //----------------------------------------------------------------------- // is53WeekYear() //----------------------------------------------------------------------- - @Test(dataProvider = "53WeekYear") + @Test + @UseDataProvider("data_53WeekYear") public void test_is53WeekYear(int year) { YearWeek yearWeek = YearWeek.of(year, 1); assertTrue(yearWeek.is53WeekYear()); @@ -479,6 +490,7 @@ public void test_is53WeekYear(int year) { //----------------------------------------------------------------------- // compareTo() //----------------------------------------------------------------------- + @Test public void test_compareTo() { for (int year1 = -100; year1 < 100; year1++) { for (int week1 = 1; week1 < 53; week1++) { @@ -530,7 +542,7 @@ public void test_compareTo() { } } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_compareTo_nullYearWeek() { TEST.compareTo(null); } @@ -538,7 +550,8 @@ public void test_compareTo_nullYearWeek() { //----------------------------------------------------------------------- // from(TemporalAccessor) //----------------------------------------------------------------------- - @Test(dataProvider = "sampleAtDay") + @Test + @UseDataProvider("data_sampleAtDay") public void test_from(int weekBasedYear, int weekOfWeekBasedYear, DayOfWeek dayOfWeek, int year, int month, int dayOfMonth) { YearWeek expected = YearWeek.of(weekBasedYear, weekOfWeekBasedYear); LocalDate ld = LocalDate.of(year, month, dayOfMonth); @@ -547,12 +560,12 @@ public void test_from(int weekBasedYear, int weekOfWeekBasedYear, DayOfWeek dayO assertEquals(YearWeek.from(expected), expected); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_from_TemporalAccessor_noDerive() { YearWeek.from(LocalTime.NOON); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_from_TemporalAccessor_null() { YearWeek.from((TemporalAccessor) null); } @@ -560,17 +573,18 @@ public void test_from_TemporalAccessor_null() { //----------------------------------------------------------------------- // get(TemporalField) //----------------------------------------------------------------------- + @Test public void test_get() { assertEquals(TEST.get(WEEK_BASED_YEAR), 2015); assertEquals(TEST.get(WEEK_OF_WEEK_BASED_YEAR), 1); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_get_invalidField() { TEST.get(YEAR); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_get_null() { TEST.get((TemporalField) null); } @@ -578,17 +592,18 @@ public void test_get_null() { //----------------------------------------------------------------------- // getLong(TemporalField) //----------------------------------------------------------------------- + @Test public void test_getLong() { assertEquals(TEST.getLong(WEEK_BASED_YEAR), 2015L); assertEquals(TEST.getLong(WEEK_OF_WEEK_BASED_YEAR), 1L); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_getLong_invalidField() { TEST.getLong(YEAR); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_getLong_null() { TEST.getLong((TemporalField) null); } @@ -596,6 +611,7 @@ public void test_getLong_null() { //----------------------------------------------------------------------- // lengthOfYear() //----------------------------------------------------------------------- + @Test public void test_lengthOfYear() { assertEquals(YearWeek.of(2014, 1).lengthOfYear(), 364); assertEquals(YearWeek.of(2015, 1).lengthOfYear(), 371); @@ -604,6 +620,7 @@ public void test_lengthOfYear() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- + @Test public void test_toString() { assertEquals(TEST.toString(), "2015-W01"); } @@ -611,21 +628,22 @@ public void test_toString() { //----------------------------------------------------------------------- // parse(CharSequence) //----------------------------------------------------------------------- + @Test public void test_parse_CharSequence() { assertEquals(YearWeek.parse("2015-W01"), TEST); } - @Test(expectedExceptions = DateTimeParseException.class) + @Test(expected = DateTimeParseException.class) public void test_parse_CharSequenceDate_invalidYear() { YearWeek.parse("12345-W7"); } - @Test(expectedExceptions = DateTimeParseException.class) + @Test(expected = DateTimeParseException.class) public void test_parse_CharSequenceDate_invalidWeek() { YearWeek.parse("2015-W54"); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_parse_CharSequenceDate_nullCharSequence() { YearWeek.parse((CharSequence) null); } @@ -633,24 +651,25 @@ public void test_parse_CharSequenceDate_nullCharSequence() { //----------------------------------------------------------------------- // parse(CharSequence,DateTimeFormatter) //----------------------------------------------------------------------- + @Test public void test_parse_CharSequenceDateTimeFormatter() { DateTimeFormatter f = DateTimeFormatter.ofPattern("E 'W'w YYYY").withLocale(Locale.ENGLISH); assertEquals(YearWeek.parse("Mon W1 2015", f), TEST); } - @Test(expectedExceptions = DateTimeParseException.class) + @Test(expected = DateTimeParseException.class) public void test_parse_CharSequenceDateDateTimeFormatter_invalidWeek() { DateTimeFormatter f = DateTimeFormatter.ofPattern("E 'W'w YYYY").withLocale(Locale.ENGLISH); YearWeek.parse("Mon W99 2015", f); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_parse_CharSequenceDateTimeFormatter_nullCharSequence() { DateTimeFormatter f = DateTimeFormatter.ofPattern("E 'W'w YYYY").withLocale(Locale.ENGLISH); YearWeek.parse((CharSequence) null, f); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_parse_CharSequenceDateTimeFormatter_nullDateTimeFormatter() { YearWeek.parse("", (DateTimeFormatter) null); } @@ -658,6 +677,7 @@ public void test_parse_CharSequenceDateTimeFormatter_nullDateTimeFormatter() { //----------------------------------------------------------------------- // format() //----------------------------------------------------------------------- + @Test public void test_format() { DateTimeFormatter f = new DateTimeFormatterBuilder() .appendValue(WEEK_BASED_YEAR, 4) @@ -670,13 +690,14 @@ public void test_format() { //----------------------------------------------------------------------- // adjustInto() //----------------------------------------------------------------------- + @Test public void test_adjustInto() { YearWeek yw = YearWeek.of(2016, 1); LocalDate date = LocalDate.of(2015, 6, 20); assertEquals(yw.adjustInto(date), LocalDate.of(2016, 1, 9)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_adjustInto_badChronology() { YearWeek yw = YearWeek.of(2016, 1); ThaiBuddhistDate date = ThaiBuddhistDate.from(LocalDate.of(2015, 6, 20)); @@ -686,6 +707,7 @@ public void test_adjustInto_badChronology() { //----------------------------------------------------------------------- // range(TemporalField) //----------------------------------------------------------------------- + @Test public void test_range() { assertEquals(TEST_NON_LEAP.range(WEEK_BASED_YEAR), WEEK_BASED_YEAR.range()); assertEquals(TEST.range(WEEK_BASED_YEAR), WEEK_BASED_YEAR.range()); @@ -694,12 +716,12 @@ public void test_range() { assertEquals(TEST.range(WEEK_OF_WEEK_BASED_YEAR), ValueRange.of(1, 53)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_range_invalidField() { TEST.range(YEAR); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_range_null() { TEST.range((TemporalField) null); } @@ -707,25 +729,28 @@ public void test_range_null() { //----------------------------------------------------------------------- // withYear(int) //----------------------------------------------------------------------- + @Test public void test_withYear() { assertEquals(YearWeek.of(2015, 1).withYear(2014), YearWeek.of(2014, 1)); assertEquals(YearWeek.of(2015, 53).withYear(2009), YearWeek.of(2009, 53)); } + @Test public void test_withYear_sameYear() { assertEquals(YearWeek.of(2015, 1).withYear(2015), YearWeek.of(2015, 1)); } + @Test public void test_withYear_resolve() { assertEquals(YearWeek.of(2015, 53).withYear(2014), YearWeek.of(2014, 52)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_withYear_int_max() { TEST.withYear(Integer.MAX_VALUE); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_withYear_int_min() { TEST.withYear(Integer.MIN_VALUE); } @@ -733,21 +758,23 @@ public void test_withYear_int_min() { //----------------------------------------------------------------------- // withWeek(int) //----------------------------------------------------------------------- + @Test public void test_withWeek() { assertEquals(TEST.withWeek(52), YearWeek.of(2015, 52)); assertEquals(YearWeek.of(2014, 1).withWeek(53), TEST); } + @Test public void test_withWeek_sameWeek() { assertEquals(YearWeek.of(2014, 2).withWeek(2), YearWeek.of(2014, 2)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_withWeek_int_max() { TEST.withWeek(Integer.MAX_VALUE); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_withWeek_int_min() { TEST.withWeek(Integer.MIN_VALUE); } @@ -755,6 +782,7 @@ public void test_withWeek_int_min() { //----------------------------------------------------------------------- // plusYears(long) //----------------------------------------------------------------------- + @Test public void test_plusYears() { assertEquals(TEST.plusYears(-2), YearWeek.of(2013, 1)); assertEquals(TEST.plusYears(-1), YearWeek.of(2014, 1)); @@ -763,6 +791,7 @@ public void test_plusYears() { assertEquals(TEST.plusYears(2), YearWeek.of(2017, 1)); } + @Test public void test_plusYears_changeWeek() { assertEquals(YearWeek.of(2015, 53).plusYears(-1), YearWeek.of(2014, 52)); assertEquals(YearWeek.of(2015, 53).plusYears(0), YearWeek.of(2015, 53)); @@ -770,12 +799,12 @@ public void test_plusYears_changeWeek() { assertEquals(YearWeek.of(2015, 53).plusYears(5), YearWeek.of(2020, 53)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plusYears_max_long() { TEST.plusYears(Long.MAX_VALUE); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plusYears_min_long() { TEST.plusYears(Long.MIN_VALUE); } @@ -783,6 +812,7 @@ public void test_plusYears_min_long() { //----------------------------------------------------------------------- // plusWeeks(long) //----------------------------------------------------------------------- + @Test public void test_plusWeeks() { assertEquals(TEST.plusWeeks(0), TEST); assertEquals(TEST.plusWeeks(1), YearWeek.of(2015, 2)); @@ -793,6 +823,7 @@ public void test_plusWeeks() { assertEquals(TEST.plusWeeks(314), YearWeek.of(2021, 1)); } + @Test public void test_plusWeeks_negative() { assertEquals(TEST.plusWeeks(0), TEST); assertEquals(TEST.plusWeeks(-1), YearWeek.of(2014, 52)); @@ -803,12 +834,12 @@ public void test_plusWeeks_negative() { assertEquals(TEST.plusWeeks(-261), YearWeek.of(2009, 53)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plusWeeks_max_long() { TEST.plusWeeks(Long.MAX_VALUE); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plusWeeks_min_long() { TEST.plusWeeks(Long.MIN_VALUE); } @@ -816,6 +847,7 @@ public void test_plusWeeks_min_long() { //----------------------------------------------------------------------- // minusYears(long) //----------------------------------------------------------------------- + @Test public void test_minusYears() { assertEquals(TEST.minusYears(-2), YearWeek.of(2017, 1)); assertEquals(TEST.minusYears(-1), YearWeek.of(2016, 1)); @@ -824,6 +856,7 @@ public void test_minusYears() { assertEquals(TEST.minusYears(2), YearWeek.of(2013, 1)); } + @Test public void test_minusYears_changeWeek() { assertEquals(YearWeek.of(2015, 53).minusYears(-5), YearWeek.of(2020, 53)); assertEquals(YearWeek.of(2015, 53).minusYears(-1), YearWeek.of(2016, 52)); @@ -831,12 +864,12 @@ public void test_minusYears_changeWeek() { assertEquals(YearWeek.of(2015, 53).minusYears(1), YearWeek.of(2014, 52)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minusYears_max_long() { TEST.minusYears(Long.MAX_VALUE); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minusYears_min_long() { TEST.minusYears(Long.MIN_VALUE); } @@ -844,6 +877,7 @@ public void test_minusYears_min_long() { //----------------------------------------------------------------------- // minusWeeks(long) //----------------------------------------------------------------------- + @Test public void test_minusWeeks() { assertEquals(TEST.minusWeeks(0), TEST); assertEquals(TEST.minusWeeks(1), YearWeek.of(2014, 52)); @@ -854,6 +888,7 @@ public void test_minusWeeks() { assertEquals(TEST.minusWeeks(261), YearWeek.of(2009, 53)); } + @Test public void test_minusWeeks_negative() { assertEquals(TEST.minusWeeks(0), TEST); assertEquals(TEST.minusWeeks(-1), YearWeek.of(2015, 2)); @@ -864,12 +899,12 @@ public void test_minusWeeks_negative() { assertEquals(TEST.minusWeeks(-314), YearWeek.of(2021, 1)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minWeeks_max_long() { TEST.plusWeeks(Long.MAX_VALUE); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minWeeks_min_long() { TEST.plusWeeks(Long.MIN_VALUE); } @@ -891,7 +926,8 @@ public void test_query() { //----------------------------------------------------------------------- // equals() / hashCode() //----------------------------------------------------------------------- - @Test(dataProvider = "sampleYearWeeks") + @Test + @UseDataProvider("data_sampleYearWeeks") public void test_equalsAndHashCodeContract(int year, int week) { YearWeek a = YearWeek.of(year, week); YearWeek b = YearWeek.of(year, week); @@ -900,6 +936,7 @@ public void test_equalsAndHashCodeContract(int year, int week) { assertTrue(a.hashCode() == b.hashCode()); } + @Test public void test_equals() { YearWeek a = YearWeek.of(2015, 4); YearWeek b = YearWeek.of(2015, 6); @@ -912,6 +949,7 @@ public void test_equals() { assertFalse(c.equals(b)); } + @Test public void test_equals_incorrectType() { assertTrue(TEST.equals(null) == false); assertEquals(TEST.equals("Incorrect type"), false); @@ -920,8 +958,8 @@ public void test_equals_incorrectType() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider(name = "sampleToString") - Object[][] provider_sampleToString() { + @DataProvider + public static Object[][] data_sampleToString() { return new Object[][]{ {2015, 1, "2015-W01"}, {2015, 10, "2015-W10"}, @@ -931,7 +969,8 @@ Object[][] provider_sampleToString() { {-10000, 1, "-10000-W01"},}; } - @Test(dataProvider = "sampleToString") + @Test + @UseDataProvider("data_sampleToString") public void test_toString(int year, int week, String expected) { YearWeek yearWeek = YearWeek.of(year, week); String s = yearWeek.toString(); diff --git a/src/test/java/org/threeten/extra/TestYears.java b/src/test/java/org/threeten/extra/TestYears.java index 23521d4d..a342983c 100644 --- a/src/test/java/org/threeten/extra/TestYears.java +++ b/src/test/java/org/threeten/extra/TestYears.java @@ -31,9 +31,9 @@ */ package org.threeten.extra; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertSame; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -46,21 +46,27 @@ import java.time.format.DateTimeParseException; import java.time.temporal.TemporalAmount; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test class. */ -@Test +@RunWith(DataProviderRunner.class) public class TestYears { //----------------------------------------------------------------------- + @Test public void test_isSerializable() { assertTrue(Serializable.class.isAssignableFrom(Years.class)); } //----------------------------------------------------------------------- + @Test public void test_deserializationSingleton() throws Exception { Years test = Years.ZERO; ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -73,12 +79,14 @@ public void test_deserializationSingleton() throws Exception { } //----------------------------------------------------------------------- + @Test public void test_ZERO() { assertSame(Years.of(0), Years.ZERO); assertSame(Years.of(0), Years.ZERO); assertEquals(Years.ZERO.getAmount(), 0); } + @Test public void test_ONE() { assertSame(Years.of(1), Years.ONE); assertSame(Years.of(1), Years.ONE); @@ -86,6 +94,7 @@ public void test_ONE() { } //----------------------------------------------------------------------- + @Test public void test_of() { assertEquals(Years.of(1).getAmount(), 1); assertEquals(Years.of(2).getAmount(), 2); @@ -96,42 +105,48 @@ public void test_of() { } //----------------------------------------------------------------------- + @Test public void test_from_P0Y() { assertEquals(Years.from(Period.ofYears(0)), Years.of(0)); } + @Test public void test_from_P2Y() { assertEquals(Years.from(Period.ofYears(2)), Years.of(2)); } + @Test public void test_from_P24M() { assertEquals(Years.from(Period.ofMonths(24)), Years.of(2)); } + @Test public void test_from_yearsAndMonths() { assertEquals(Years.from(Period.of(3, 24, 0)), Years.of(5)); } + @Test public void test_from_decadesAndMonths() { assertEquals(Years.from(new MockDecadesMonths(2, -12)), Years.of(19)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_from_wrongUnit_remainder() { Years.from(Period.ofMonths(3)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_from_wrongUnit_noConversion() { Years.from(Period.ofDays(2)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_from_null() { Years.from((TemporalAmount) null); } //----------------------------------------------------------------------- + @Test public void test_parse_CharSequence() { assertEquals(Years.parse("P0Y"), Years.of(0)); assertEquals(Years.parse("P1Y"), Years.of(1)); @@ -142,8 +157,8 @@ public void test_parse_CharSequence() { assertEquals(Years.parse("-P-2Y"), Years.of(2)); } - @DataProvider(name = "parseInvalid") - Object[][] data_invalid() { + @DataProvider + public static Object[][] data_invalid() { return new Object[][] { {"P3M"}, {"P3W"}, @@ -159,17 +174,19 @@ Object[][] data_invalid() { }; } - @Test(expectedExceptions = DateTimeParseException.class, dataProvider = "parseInvalid") + @Test(expected = DateTimeParseException.class) + @UseDataProvider("data_invalid") public void test_parse_CharSequence_invalid(String str) { Years.parse(str); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_parse_CharSequence_null() { Years.parse((CharSequence) null); } //----------------------------------------------------------------------- + @Test public void test_plus_TemporalAmount_Years() { Years test5 = Years.of(5); assertEquals(Years.of(5), test5.plus(Years.of(0))); @@ -179,6 +196,7 @@ public void test_plus_TemporalAmount_Years() { assertEquals(Years.of(Integer.MIN_VALUE), Years.of(Integer.MIN_VALUE + 1).plus(Years.of(-1))); } + @Test public void test_plus_TemporalAmount_Period() { Years test5 = Years.of(5); assertEquals(Years.of(5), test5.plus(Period.ofYears(0))); @@ -188,32 +206,33 @@ public void test_plus_TemporalAmount_Period() { assertEquals(Years.of(Integer.MIN_VALUE), Years.of(Integer.MIN_VALUE + 1).plus(Period.ofYears(-1))); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_plus_TemporalAmount_PeriodMonths() { Years.of(1).plus(Period.ofMonths(2)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_plus_TemporalAmount_Duration() { Years.of(1).plus(Duration.ofHours(2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_TemporalAmount_overflowTooBig() { Years.of(Integer.MAX_VALUE - 1).plus(Years.of(2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_TemporalAmount_overflowTooSmall() { Years.of(Integer.MIN_VALUE + 1).plus(Years.of(-2)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_plus_TemporalAmount_null() { Years.of(Integer.MIN_VALUE + 1).plus(null); } //----------------------------------------------------------------------- + @Test public void test_plus_int() { Years test5 = Years.of(5); assertEquals(Years.of(5), test5.plus(0)); @@ -223,17 +242,18 @@ public void test_plus_int() { assertEquals(Years.of(Integer.MIN_VALUE), Years.of(Integer.MIN_VALUE + 1).plus(-1)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_int_overflowTooBig() { Years.of(Integer.MAX_VALUE - 1).plus(2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_int_overflowTooSmall() { Years.of(Integer.MIN_VALUE + 1).plus(-2); } //----------------------------------------------------------------------- + @Test public void test_minus_TemporalAmount_Years() { Years test5 = Years.of(5); assertEquals(Years.of(5), test5.minus(Years.of(0))); @@ -243,6 +263,7 @@ public void test_minus_TemporalAmount_Years() { assertEquals(Years.of(Integer.MIN_VALUE), Years.of(Integer.MIN_VALUE + 1).minus(Years.of(1))); } + @Test public void test_minus_TemporalAmount_Period() { Years test5 = Years.of(5); assertEquals(Years.of(5), test5.minus(Period.ofYears(0))); @@ -252,32 +273,33 @@ public void test_minus_TemporalAmount_Period() { assertEquals(Years.of(Integer.MIN_VALUE), Years.of(Integer.MIN_VALUE + 1).minus(Period.ofYears(1))); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_minus_TemporalAmount_PeriodMonths() { Years.of(1).minus(Period.ofMonths(2)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_minus_TemporalAmount_Duration() { Years.of(1).minus(Duration.ofHours(2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_TemporalAmount_overflowTooBig() { Years.of(Integer.MAX_VALUE - 1).minus(Years.of(-2)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_TemporalAmount_overflowTooSmall() { Years.of(Integer.MIN_VALUE + 1).minus(Years.of(2)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_minus_TemporalAmount_null() { Years.of(Integer.MIN_VALUE + 1).minus(null); } //----------------------------------------------------------------------- + @Test public void test_minus_int() { Years test5 = Years.of(5); assertEquals(Years.of(5), test5.minus(0)); @@ -287,17 +309,18 @@ public void test_minus_int() { assertEquals(Years.of(Integer.MIN_VALUE), Years.of(Integer.MIN_VALUE + 1).minus(1)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_int_overflowTooBig() { Years.of(Integer.MAX_VALUE - 1).minus(-2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_int_overflowTooSmall() { Years.of(Integer.MIN_VALUE + 1).minus(2); } //----------------------------------------------------------------------- + @Test public void test_multipliedBy() { Years test5 = Years.of(5); assertEquals(Years.of(0), test5.multipliedBy(0)); @@ -307,22 +330,24 @@ public void test_multipliedBy() { assertEquals(Years.of(-15), test5.multipliedBy(-3)); } + @Test public void test_multipliedBy_negate() { Years test5 = Years.of(5); assertEquals(Years.of(-15), test5.multipliedBy(-3)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_multipliedBy_overflowTooBig() { Years.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_multipliedBy_overflowTooSmall() { Years.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2); } //----------------------------------------------------------------------- + @Test public void test_dividedBy() { Years test12 = Years.of(12); assertEquals(Years.of(12), test12.dividedBy(1)); @@ -334,17 +359,19 @@ public void test_dividedBy() { assertEquals(Years.of(-4), test12.dividedBy(-3)); } + @Test public void test_dividedBy_negate() { Years test12 = Years.of(12); assertEquals(Years.of(-4), test12.dividedBy(-3)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_dividedBy_divideByZero() { Years.of(1).dividedBy(0); } //----------------------------------------------------------------------- + @Test public void test_negated() { assertEquals(Years.of(0), Years.of(0).negated()); assertEquals(Years.of(-12), Years.of(12).negated()); @@ -352,12 +379,13 @@ public void test_negated() { assertEquals(Years.of(-Integer.MAX_VALUE), Years.of(Integer.MAX_VALUE).negated()); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_negated_overflow() { Years.of(Integer.MIN_VALUE).negated(); } //----------------------------------------------------------------------- + @Test public void test_abs() { assertEquals(Years.of(0), Years.of(0).abs()); assertEquals(Years.of(12), Years.of(12).abs()); @@ -366,12 +394,13 @@ public void test_abs() { assertEquals(Years.of(Integer.MAX_VALUE), Years.of(-Integer.MAX_VALUE).abs()); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_abs_overflow() { Years.of(Integer.MIN_VALUE).abs(); } //----------------------------------------------------------------------- + @Test public void test_toPeriod() { for (int i = -20; i < 20; i++) { assertEquals(Years.of(i).toPeriod(), Period.ofYears(i)); @@ -379,6 +408,7 @@ public void test_toPeriod() { } //----------------------------------------------------------------------- + @Test public void test_compareTo() { Years test5 = Years.of(5); Years test6 = Years.of(6); @@ -387,13 +417,14 @@ public void test_compareTo() { assertEquals(1, test6.compareTo(test5)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_compareTo_null() { Years test5 = Years.of(5); test5.compareTo(null); } //----------------------------------------------------------------------- + @Test public void test_equals() { Years test5 = Years.of(5); Years test6 = Years.of(6); @@ -402,17 +433,20 @@ public void test_equals() { assertEquals(false, test6.equals(test5)); } + @Test public void test_equals_null() { Years test5 = Years.of(5); assertEquals(false, test5.equals(null)); } + @Test public void test_equals_otherClass() { Years test5 = Years.of(5); assertEquals(false, test5.equals("")); } //----------------------------------------------------------------------- + @Test public void test_hashCode() { Years test5 = Years.of(5); Years test6 = Years.of(6); @@ -421,6 +455,7 @@ public void test_hashCode() { } //----------------------------------------------------------------------- + @Test public void test_toString() { Years test5 = Years.of(5); assertEquals("P5Y", test5.toString()); diff --git a/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java b/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java index 64942b05..4e85f4af 100644 --- a/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java @@ -53,7 +53,7 @@ import static java.time.temporal.ChronoUnit.MONTHS; import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; -import static org.testng.Assert.assertEquals; +import static org.junit.Assert.assertEquals; import java.time.DateTimeException; import java.time.DayOfWeek; @@ -72,14 +72,18 @@ import java.util.List; import java.util.function.Predicate; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test. */ -@Test +@RunWith(DataProviderRunner.class) public class TestAccountingChronology { private static AccountingChronology INSTANCE = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST). @@ -101,8 +105,8 @@ public void test_chronology_of_name_id() { //----------------------------------------------------------------------- // creation, toLocalDate() //----------------------------------------------------------------------- - @DataProvider(name = "samples") - Object[][] data_samples() { + @DataProvider + public static Object[][] data_samples() { return new Object[][] { {INSTANCE.date(1, 1, 1), LocalDate.of(0, 9, 4)}, {INSTANCE.date(1, 1, 2), LocalDate.of(0, 9, 5)}, @@ -137,47 +141,56 @@ Object[][] data_samples() { }; } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_LocalDate_from_AccountingDate(AccountingDate accounting, LocalDate iso) { assertEquals(LocalDate.from(accounting), iso); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_AccountingDate_from_LocalDate(AccountingDate accounting, LocalDate iso) { assertEquals(AccountingDate.from(INSTANCE, iso), accounting); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_AccountingDate_chronology_dateEpochDay(AccountingDate accounting, LocalDate iso) { assertEquals(INSTANCE.dateEpochDay(iso.toEpochDay()), accounting); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_AccountingDate_toEpochDay(AccountingDate accounting, LocalDate iso) { assertEquals(accounting.toEpochDay(), iso.toEpochDay()); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_AccountingDate_until_CoptiDate(AccountingDate accounting, LocalDate iso) { assertEquals(accounting.until(accounting), INSTANCE.period(0, 0, 0)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_AccountingDate_until_LocalDate(AccountingDate accounting, LocalDate iso) { assertEquals(accounting.until(iso), INSTANCE.period(0, 0, 0)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_LocalDate_until_CoptiDate(AccountingDate accounting, LocalDate iso) { assertEquals(iso.until(accounting), Period.ZERO); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(AccountingDate accounting, LocalDate iso) { assertEquals(INSTANCE.date(iso), accounting); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_plusDays(AccountingDate accounting, LocalDate iso) { assertEquals(LocalDate.from(accounting.plus(0, DAYS)), iso); assertEquals(LocalDate.from(accounting.plus(1, DAYS)), iso.plusDays(1)); @@ -186,7 +199,8 @@ public void test_plusDays(AccountingDate accounting, LocalDate iso) { assertEquals(LocalDate.from(accounting.plus(-60, DAYS)), iso.plusDays(-60)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_minusDays(AccountingDate accounting, LocalDate iso) { assertEquals(LocalDate.from(accounting.minus(0, DAYS)), iso); assertEquals(LocalDate.from(accounting.minus(1, DAYS)), iso.minusDays(1)); @@ -195,7 +209,8 @@ public void test_minusDays(AccountingDate accounting, LocalDate iso) { assertEquals(LocalDate.from(accounting.minus(-60, DAYS)), iso.minusDays(-60)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_until_DAYS(AccountingDate accounting, LocalDate iso) { assertEquals(accounting.until(iso.plusDays(0), DAYS), 0); assertEquals(accounting.until(iso.plusDays(1), DAYS), 1); @@ -203,8 +218,8 @@ public void test_until_DAYS(AccountingDate accounting, LocalDate iso) { assertEquals(accounting.until(iso.minusDays(40), DAYS), -40); } - @DataProvider(name = "badDates") - Object[][] data_badDates() { + @DataProvider + public static Object[][] data_badDates() { return new Object[][] { {2012, 0, 0}, @@ -246,42 +261,43 @@ Object[][] data_badDates() { }; } - @Test(dataProvider = "badDates", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_badDates") public void test_badDates(int year, int month, int dom) { INSTANCE.date(year, month, dom); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_chronology_dateYearDay_badDate() { INSTANCE.dateYearDay(2001, 366); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_date_create_no_chronology() { AccountingDate.create(null, 2012, 1, 1); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_date_from_no_chronology() { AccountingDate.from(null, LocalDate.of(2012, 1, 1)); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_date_now_no_chronology() { AccountingDate.now(null); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_date_of_no_chronology() { AccountingDate.of(null, 2012, 1, 1); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_date_ofEpochDay_no_chronology() { AccountingDate.ofEpochDay(null, 0); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_date_ofYearDay_no_chronology() { AccountingDate.ofYearDay(null, 0, 1); } @@ -322,8 +338,8 @@ public void test_isLeapYear_specific() { assertEquals(INSTANCE.isLeapYear(-6), false); } - @DataProvider(name = "lengthOfMonth") - Object[][] data_lengthOfMonth() { + @DataProvider + public static Object[][] data_lengthOfMonth() { return new Object[][] { {2012, 1, 28}, {2012, 2, 28}, @@ -346,7 +362,8 @@ Object[][] data_lengthOfMonth() { }; } - @Test(dataProvider = "lengthOfMonth") + @Test + @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(INSTANCE.date(year, month, 1).lengthOfMonth(), length); } @@ -394,7 +411,7 @@ public void test_prolepticYear_specific() { assertEquals(INSTANCE.prolepticYear(AccountingEra.BCE, 4), -3); } - @Test(expectedExceptions = ClassCastException.class) + @Test(expected = ClassCastException.class) public void test_prolepticYear_badEra() { INSTANCE.prolepticYear(IsoEra.CE, 4); } @@ -405,7 +422,7 @@ public void test_Chronology_eraOf() { assertEquals(INSTANCE.eraOf(0), AccountingEra.BCE); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_Chronology_eraOf_invalid() { INSTANCE.eraOf(2); } @@ -433,8 +450,8 @@ public void test_Chronology_range() { //----------------------------------------------------------------------- // AccountingDate.range //----------------------------------------------------------------------- - @DataProvider(name = "ranges") - Object[][] data_ranges() { + @DataProvider + public static Object[][] data_ranges() { return new Object[][] { {2012, 1, 23, DAY_OF_MONTH, 1, 28}, {2012, 2, 23, DAY_OF_MONTH, 1, 28}, @@ -460,12 +477,13 @@ Object[][] data_ranges() { }; } - @Test(dataProvider = "ranges") + @Test + @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(INSTANCE.date(year, month, dom).range(field), ValueRange.of(expectedMin, expectedMax)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_range_unsupported() { INSTANCE.date(2012, 6, 28).range(MINUTE_OF_DAY); } @@ -473,8 +491,8 @@ public void test_range_unsupported() { //----------------------------------------------------------------------- // AccountingDate.getLong //----------------------------------------------------------------------- - @DataProvider(name = "getLong") - Object[][] data_getLong() { + @DataProvider + public static Object[][] data_getLong() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 5}, {2014, 5, 26, DAY_OF_MONTH, 26}, @@ -494,12 +512,13 @@ Object[][] data_getLong() { }; } - @Test(dataProvider = "getLong") + @Test + @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(INSTANCE.date(year, month, dom).getLong(field), expected); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_getLong_unsupported() { INSTANCE.date(2012, 6, 28).getLong(MINUTE_OF_DAY); } @@ -507,8 +526,8 @@ public void test_getLong_unsupported() { //----------------------------------------------------------------------- // AccountingDate.with //----------------------------------------------------------------------- - @DataProvider(name = "with") - Object[][] data_with() { + @DataProvider + public static Object[][] data_with() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 3, 2014, 5, 24}, {2014, 5, 26, DAY_OF_WEEK, 5, 2014, 5, 26}, @@ -545,14 +564,15 @@ Object[][] data_with() { }; } - @Test(dataProvider = "with") + @Test + @UseDataProvider("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(INSTANCE.date(year, month, dom).with(field, value), INSTANCE.date(expectedYear, expectedMonth, expectedDom)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_with_TemporalField_unsupported() { INSTANCE.date(2012, 6, 28).with(MINUTE_OF_DAY, 0); } @@ -584,7 +604,7 @@ public void test_adjust_toLocalDate() { assertEquals(test, INSTANCE.date(2012, 12, 5)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_adjust_toMonth() { AccountingDate accounting = INSTANCE.date(2000, 1, 4); accounting.with(Month.APRIL); @@ -610,8 +630,8 @@ public void test_LocalDateTime_adjustToAccountingDate() { //----------------------------------------------------------------------- // AccountingDate.plus //----------------------------------------------------------------------- - @DataProvider(name = "plus") - Object[][] data_plus() { + @DataProvider + public static Object[][] data_plus() { return new Object[][] { {2014, 5, 26, 0, DAYS, 2014, 5, 26}, {2014, 5, 26, 8, DAYS, 2014, 6, 6}, @@ -638,14 +658,16 @@ Object[][] data_plus() { }; } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(INSTANCE.date(year, month, dom).plus(amount, unit), INSTANCE.date(expectedYear, expectedMonth, expectedDom)); } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -653,7 +675,7 @@ public void test_minus_TemporalUnit( assertEquals(INSTANCE.date(year, month, dom).minus(amount, unit), INSTANCE.date(expectedYear, expectedMonth, expectedDom)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_plus_TemporalUnit_unsupported() { INSTANCE.date(2012, 6, 28).plus(0, MINUTES); } @@ -661,8 +683,8 @@ public void test_plus_TemporalUnit_unsupported() { //----------------------------------------------------------------------- // AccountingDate.until //----------------------------------------------------------------------- - @DataProvider(name = "until") - Object[][] data_until() { + @DataProvider + public static Object[][] data_until() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, DAYS, 0}, {2014, 5, 26, 2014, 6, 4, DAYS, 6}, @@ -690,7 +712,8 @@ Object[][] data_until() { }; } - @Test(dataProvider = "until") + @Test + @UseDataProvider("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -700,7 +723,7 @@ public void test_until_TemporalUnit( assertEquals(start.until(end, unit), expected); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_until_TemporalUnit_unsupported() { AccountingDate start = INSTANCE.date(2012, 6, 28); AccountingDate end = INSTANCE.date(2012, 7, 1); @@ -713,7 +736,7 @@ public void test_plus_Period() { assertEquals(INSTANCE.date(2014, 5, 26).plus(INSTANCE.period(0, 2, 3)), INSTANCE.date(2014, 8, 1)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_plus_Period_ISO() { assertEquals(INSTANCE.date(2014, 5, 26).plus(Period.ofMonths(2)), INSTANCE.date(2014, 7, 26)); } @@ -723,7 +746,7 @@ public void test_minus_Period() { assertEquals(INSTANCE.date(2014, 5, 26).minus(INSTANCE.period(0, 2, 3)), INSTANCE.date(2014, 3, 23)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_minus_Period_ISO() { assertEquals(INSTANCE.date(2014, 5, 26).minus(Period.ofMonths(2)), INSTANCE.date(2014, 3, 26)); } @@ -732,7 +755,7 @@ public void test_minus_Period_ISO() { // equals() //----------------------------------------------------------------------- @Test - void test_equals() { + public void test_equals() { AccountingDate a1 = INSTANCE.date(2000, 1, 3); AccountingDate a2 = INSTANCE.date(2000, 1, 3); AccountingDate b = INSTANCE.date(2000, 1, 4); @@ -761,15 +784,16 @@ void test_equals() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider(name = "toString") - Object[][] data_toString() { + @DataProvider + public static Object[][] data_toString() { return new Object[][] { {INSTANCE.date(1, 1, 1), "Accounting calendar ends on SUNDAY nearest end of AUGUST, year divided in THIRTEEN_EVEN_MONTHS_OF_4_WEEKS with leap-week in month 13 CE 1-01-01"}, {INSTANCE.date(2012, 6, 23), "Accounting calendar ends on SUNDAY nearest end of AUGUST, year divided in THIRTEEN_EVEN_MONTHS_OF_4_WEEKS with leap-week in month 13 CE 2012-06-23"}, }; } - @Test(dataProvider = "toString") + @Test + @UseDataProvider("data_toString") public void test_toString(AccountingDate accounting, String expected) { assertEquals(accounting.toString(), expected); } diff --git a/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java b/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java index 586cd081..3d56c87c 100644 --- a/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java +++ b/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java @@ -32,7 +32,7 @@ package org.threeten.extra.chrono; import static java.time.temporal.ChronoUnit.DAYS; -import static org.testng.Assert.assertEquals; +import static org.junit.Assert.assertEquals; import java.time.DateTimeException; import java.time.DayOfWeek; @@ -44,20 +44,24 @@ import java.util.function.IntFunction; import java.util.function.Predicate; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test. */ -@Test +@RunWith(DataProviderRunner.class) public class TestAccountingChronologyBuilder { //----------------------------------------------------------------------- // isLeapYear(), date(int, int, int) //----------------------------------------------------------------------- - @DataProvider(name = "yearEnding") - Object[][] data_yearEnding() { + @DataProvider + public static Object[][] data_yearEnding() { return new Object[][] { {DayOfWeek.MONDAY, Month.JANUARY}, {DayOfWeek.TUESDAY, Month.MARCH}, @@ -81,7 +85,8 @@ Object[][] data_yearEnding() { }; } - @Test(dataProvider = "yearEnding") + @Test + @UseDataProvider("data_yearEnding") public void test_isLeapYear_inLastWeekOf(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) @@ -97,11 +102,12 @@ public void test_isLeapYear_inLastWeekOf(DayOfWeek dayOfWeek, Month ending) { }; for (int year = -200; year < 600; year++) { - assertEquals(chronology.isLeapYear(year), isLeapYear.test(year), "Fails on " + year); + assertEquals(chronology.isLeapYear(year), isLeapYear.test(year)); } } - @Test(dataProvider = "yearEnding") + @Test + @UseDataProvider("data_yearEnding") public void test_isLeapYear_nearestEndOf(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) @@ -117,11 +123,12 @@ public void test_isLeapYear_nearestEndOf(DayOfWeek dayOfWeek, Month ending) { }; for (int year = -200; year < 600; year++) { - assertEquals(chronology.isLeapYear(year), isLeapYear.test(year), "Fails on " + year); + assertEquals(chronology.isLeapYear(year), isLeapYear.test(year)); } } - @Test(dataProvider = "yearEnding") + @Test + @UseDataProvider("data_yearEnding") public void test_previousLeapYears_inLastWeekOf(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) @@ -140,17 +147,18 @@ public void test_previousLeapYears_inLastWeekOf(DayOfWeek dayOfWeek, Month endin if (year != 1 && isLeapYear.test(year - 1)) { leapYears++; } - assertEquals(chronology.previousLeapYears(year), leapYears, "Fails on " + year); + assertEquals(chronology.previousLeapYears(year), leapYears); } for (int year = 1, leapYears = 0; year >= -200; year--) { if (year != 1 && isLeapYear.test(year)) { leapYears--; } - assertEquals(chronology.previousLeapYears(year), leapYears, "Fails on " + year); + assertEquals(chronology.previousLeapYears(year), leapYears); } } - @Test(dataProvider = "yearEnding") + @Test + @UseDataProvider("data_yearEnding") public void test_previousLeapYears_nearestEndOf(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) @@ -169,17 +177,18 @@ public void test_previousLeapYears_nearestEndOf(DayOfWeek dayOfWeek, Month endin if (year != 1 && isLeapYear.test(year - 1)) { leapYears++; } - assertEquals(chronology.previousLeapYears(year), leapYears, "Fails on " + year); + assertEquals(chronology.previousLeapYears(year), leapYears); } for (int year = 1, leapYears = 0; year >= -200; year--) { if (year != 1 && isLeapYear.test(year)) { leapYears--; } - assertEquals(chronology.previousLeapYears(year), leapYears, "Fails on " + year); + assertEquals(chronology.previousLeapYears(year), leapYears); } } - @Test(dataProvider = "yearEnding") + @Test + @UseDataProvider("data_yearEnding") public void test_date_int_int_int_inLastWeekOf(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) @@ -194,7 +203,8 @@ public void test_date_int_int_int_inLastWeekOf(DayOfWeek dayOfWeek, Month ending } } - @Test(dataProvider = "yearEnding") + @Test + @UseDataProvider("data_yearEnding") public void test_date_int_int_int_nearestEndOf(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) @@ -212,8 +222,8 @@ public void test_date_int_int_int_nearestEndOf(DayOfWeek dayOfWeek, Month ending //----------------------------------------------------------------------- // range(MONTH_OF_YEAR), range(DAY_OF_MONTH) //----------------------------------------------------------------------- - @DataProvider(name = "range") - Object[][] data_range() { + @DataProvider + public static Object[][] data_range() { return new Object[][] { {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, 1, ValueRange.of(1, 4, 5), ValueRange.of(1, 28, 35), ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11)}, @@ -259,7 +269,8 @@ Object[][] data_range() { }; } - @Test(dataProvider = "range") + @Test + @UseDataProvider("data_range") public void test_range(AccountingYearDivision division, int leapWeekInMonth, ValueRange expectedWeekOfMonthRange, ValueRange expectedDayOfMonthRange, ValueRange expectedMonthRange, ValueRange expectedProlepticMonthRange) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST) @@ -273,7 +284,8 @@ public void test_range(AccountingYearDivision division, int leapWeekInMonth, assertEquals(chronology.range(ChronoField.PROLEPTIC_MONTH), expectedProlepticMonthRange); } - @Test(dataProvider = "weeksInMonth") + @Test + @UseDataProvider("data_weeksInMonth") public void test_date_dayOfMonth_range(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST) .withDivision(division).leapWeekInMonth(leapWeekInMonth) @@ -287,7 +299,8 @@ public void test_date_dayOfMonth_range(AccountingYearDivision division, int[] we } } - @Test(dataProvider = "yearEnding") + @Test + @UseDataProvider("data_yearEnding") public void test_date_dayOfYear_inLastWeekOf_range(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) @@ -307,7 +320,8 @@ public void test_date_dayOfYear_inLastWeekOf_range(DayOfWeek dayOfWeek, Month en } } - @Test(dataProvider = "yearEnding") + @Test + @UseDataProvider("data_yearEnding") public void test_date_dayOfYear_nearestEndOf_range(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) @@ -331,8 +345,8 @@ public void test_date_dayOfYear_nearestEndOf_range(DayOfWeek dayOfWeek, Month en // getWeeksInMonth(month), // getWeeksAtStartOfMonth(weeks), getMonthFromElapsedWeeks(weeks) //----------------------------------------------------------------------- - @DataProvider(name = "weeksInMonth") - Object[][] data_weeksInMonth() { + @DataProvider + public static Object[][] data_weeksInMonth() { return new Object[][] { {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, new int[] {4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5}, 1}, {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, new int[] {4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5}, 2}, @@ -359,7 +373,8 @@ Object[][] data_weeksInMonth() { }; } - @Test(dataProvider = "weeksInMonth") + @Test + @UseDataProvider("data_weeksInMonth") public void test_getWeeksInMonth(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST) .withDivision(division).leapWeekInMonth(leapWeekInMonth) @@ -371,7 +386,8 @@ public void test_getWeeksInMonth(AccountingYearDivision division, int[] weeksInM } } - @Test(dataProvider = "weeksInMonth") + @Test + @UseDataProvider("data_weeksInMonth") public void test_getWeeksAtStartOf(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST) .withDivision(division).leapWeekInMonth(leapWeekInMonth) @@ -383,7 +399,8 @@ public void test_getWeeksAtStartOf(AccountingYearDivision division, int[] weeksI } } - @Test(dataProvider = "weeksInMonth") + @Test + @UseDataProvider("data_weeksInMonth") public void test_getMonthFromElapsedWeeks(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST) .withDivision(division).leapWeekInMonth(leapWeekInMonth) @@ -400,13 +417,15 @@ public void test_getMonthFromElapsedWeeks(AccountingYearDivision division, int[] } } - @Test(dataProvider = "weeksInMonth", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_weeksInMonth") public void test_negativeWeeks_getMonthFromElapsedWeekspublic(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { assertEquals(division.getMonthFromElapsedWeeks(0), 1); division.getMonthFromElapsedWeeks(-1); } - @Test(dataProvider = "weeksInMonth", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_weeksInMonth") public void test_extraWeeks_getMonthFromElapsedWeekspublic(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { int elapsedWeeks = 0; for (int month = 1; month <= weeksInMonth.length; month++) { @@ -416,7 +435,8 @@ public void test_extraWeeks_getMonthFromElapsedWeekspublic(AccountingYearDivisio division.getMonthFromElapsedWeeks(elapsedWeeks + 1); } - @Test(dataProvider = "weeksInMonth", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_weeksInMonth") public void test_extraWeeksLeap_getMonthFromElapsedWeekspublic(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { int elapsedWeeks = 1; for (int month = 1; month <= weeksInMonth.length; month++) { @@ -429,8 +449,8 @@ public void test_extraWeeksLeap_getMonthFromElapsedWeekspublic(AccountingYearDiv //----------------------------------------------------------------------- // toChronology() failures. //----------------------------------------------------------------------- - @DataProvider(name = "badChronology") - Object[][] data_badChronology() { + @DataProvider + public static Object[][] data_badChronology() { return new Object[][] { {DayOfWeek.MONDAY, Month.JANUARY, AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS, 0}, {DayOfWeek.MONDAY, Month.JANUARY, AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS, -1}, @@ -445,14 +465,16 @@ Object[][] data_badChronology() { }; } - @Test(dataProvider = "badChronology", expectedExceptions = IllegalStateException.class) + @Test(expected = IllegalStateException.class) + @UseDataProvider("data_badChronology") public void test_badChronology_nearestEndOf(DayOfWeek dayOfWeek, Month ending, AccountingYearDivision division, int leapWeekInMonth) { new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) .withDivision(division).leapWeekInMonth(leapWeekInMonth) .toChronology(); } - @Test(dataProvider = "badChronology", expectedExceptions = IllegalStateException.class) + @Test(expected = IllegalStateException.class) + @UseDataProvider("data_badChronology") public void test_badChronology_inLastWeekOf(DayOfWeek dayOfWeek, Month ending, AccountingYearDivision division, int leapWeekInMonth) { new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) .withDivision(division).leapWeekInMonth(leapWeekInMonth) diff --git a/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java b/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java index 66d0f8c3..a664d9f8 100644 --- a/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java @@ -53,7 +53,7 @@ import static java.time.temporal.ChronoUnit.MONTHS; import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; -import static org.testng.Assert.assertEquals; +import static org.junit.Assert.assertEquals; import java.time.DateTimeException; import java.time.Instant; @@ -81,14 +81,18 @@ import java.util.List; import java.util.TimeZone; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test. */ -@Test +@RunWith(DataProviderRunner.class) public class TestBritishCutoverChronology { //----------------------------------------------------------------------- @@ -106,8 +110,8 @@ public void test_chronology_of_name() { //----------------------------------------------------------------------- // creation, toLocalDate() //----------------------------------------------------------------------- - @DataProvider(name = "samples") - Object[][] data_samples() { + @DataProvider + public static Object[][] data_samples() { return new Object[][] { {BritishCutoverDate.of(1, 1, 1), LocalDate.of(0, 12, 30)}, {BritishCutoverDate.of(1, 1, 2), LocalDate.of(0, 12, 31)}, @@ -151,47 +155,56 @@ Object[][] data_samples() { }; } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_LocalDate_from_BritishCutoverDate(BritishCutoverDate cutover, LocalDate iso) { assertEquals(LocalDate.from(cutover), iso); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_BritishCutoverDate_from_LocalDate(BritishCutoverDate cutover, LocalDate iso) { assertEquals(BritishCutoverDate.from(iso), cutover); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_BritishCutoverDate_chronology_dateEpochDay(BritishCutoverDate cutover, LocalDate iso) { assertEquals(BritishCutoverChronology.INSTANCE.dateEpochDay(iso.toEpochDay()), cutover); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_BritishCutoverDate_toEpochDay(BritishCutoverDate cutover, LocalDate iso) { assertEquals(cutover.toEpochDay(), iso.toEpochDay()); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_BritishCutoverDate_until_BritishCutoverDate(BritishCutoverDate cutover, LocalDate iso) { assertEquals(cutover.until(cutover), BritishCutoverChronology.INSTANCE.period(0, 0, 0)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_BritishCutoverDate_until_LocalDate(BritishCutoverDate cutover, LocalDate iso) { assertEquals(cutover.until(iso), BritishCutoverChronology.INSTANCE.period(0, 0, 0)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_LocalDate_until_BritishCutoverDate(BritishCutoverDate cutover, LocalDate iso) { assertEquals(iso.until(cutover), Period.ZERO); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(BritishCutoverDate cutover, LocalDate iso) { assertEquals(BritishCutoverChronology.INSTANCE.date(iso), cutover); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_plusDays(BritishCutoverDate cutover, LocalDate iso) { assertEquals(LocalDate.from(cutover.plus(0, DAYS)), iso); assertEquals(LocalDate.from(cutover.plus(1, DAYS)), iso.plusDays(1)); @@ -200,7 +213,8 @@ public void test_plusDays(BritishCutoverDate cutover, LocalDate iso) { assertEquals(LocalDate.from(cutover.plus(-60, DAYS)), iso.plusDays(-60)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_minusDays(BritishCutoverDate cutover, LocalDate iso) { assertEquals(LocalDate.from(cutover.minus(0, DAYS)), iso); assertEquals(LocalDate.from(cutover.minus(1, DAYS)), iso.minusDays(1)); @@ -209,7 +223,8 @@ public void test_minusDays(BritishCutoverDate cutover, LocalDate iso) { assertEquals(LocalDate.from(cutover.minus(-60, DAYS)), iso.minusDays(-60)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_until_DAYS(BritishCutoverDate cutover, LocalDate iso) { assertEquals(cutover.until(iso.plusDays(0), DAYS), 0); assertEquals(cutover.until(iso.plusDays(1), DAYS), 1); @@ -217,8 +232,8 @@ public void test_until_DAYS(BritishCutoverDate cutover, LocalDate iso) { assertEquals(cutover.until(iso.minusDays(40), DAYS), -40); } - @DataProvider(name = "badDates") - Object[][] data_badDates() { + @DataProvider + public static Object[][] data_badDates() { return new Object[][] { {1900, 0, 0}, @@ -260,12 +275,13 @@ Object[][] data_badDates() { }; } - @Test(dataProvider = "badDates", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_badDates") public void test_badDates(int year, int month, int dom) { BritishCutoverDate.of(year, month, dom); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_Chronology_dateYearDay_badDate() { BritishCutoverChronology.INSTANCE.dateYearDay(2001, 366); } @@ -312,8 +328,8 @@ public void test_Chronology_getCutover() { //----------------------------------------------------------------------- // lengthOfMonth() //----------------------------------------------------------------------- - @DataProvider(name = "lengthOfMonth") - Object[][] data_lengthOfMonth() { + @DataProvider + public static Object[][] data_lengthOfMonth() { return new Object[][] { {1700, 1, 31}, {1700, 2, 29}, @@ -381,7 +397,8 @@ Object[][] data_lengthOfMonth() { }; } - @Test(dataProvider = "lengthOfMonth") + @Test + @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(BritishCutoverDate.of(year, month, 1).lengthOfMonth(), length); } @@ -389,8 +406,8 @@ public void test_lengthOfMonth(int year, int month, int length) { //----------------------------------------------------------------------- // lengthOfYear() //----------------------------------------------------------------------- - @DataProvider(name = "lengthOfYear") - Object[][] data_lengthOfYear() { + @DataProvider + public static Object[][] data_lengthOfYear() { return new Object[][] { {-101, 365}, {-100, 366}, @@ -421,12 +438,14 @@ Object[][] data_lengthOfYear() { }; } - @Test(dataProvider = "lengthOfYear") + @Test + @UseDataProvider("data_lengthOfYear") public void test_lengthOfYear_atStart(int year, int length) { assertEquals(BritishCutoverDate.of(year, 1, 1).lengthOfYear(), length); } - @Test(dataProvider = "lengthOfYear") + @Test + @UseDataProvider("data_lengthOfYear") public void test_lengthOfYear_atEnd(int year, int length) { assertEquals(BritishCutoverDate.of(year, 12, 31).lengthOfYear(), length); } @@ -486,7 +505,7 @@ public void test_prolepticYear_specific() { assertEquals(BritishCutoverChronology.INSTANCE.prolepticYear(JulianEra.BC, 4), -3); } - @Test(expectedExceptions = ClassCastException.class) + @Test(expected = ClassCastException.class) public void test_prolepticYear_badEra() { BritishCutoverChronology.INSTANCE.prolepticYear(IsoEra.CE, 4); } @@ -497,7 +516,7 @@ public void test_Chronology_eraOf() { assertEquals(BritishCutoverChronology.INSTANCE.eraOf(0), JulianEra.BC); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_Chronology_eraOf_invalid() { BritishCutoverChronology.INSTANCE.eraOf(2); } @@ -526,8 +545,8 @@ public void test_Chronology_range() { //----------------------------------------------------------------------- // BritishCutoverDate.range //----------------------------------------------------------------------- - @DataProvider(name = "ranges") - Object[][] data_ranges() { + @DataProvider + public static Object[][] data_ranges() { return new Object[][] { {1700, 1, 23, DAY_OF_MONTH, 1, 31}, {1700, 2, 23, DAY_OF_MONTH, 1, 29}, @@ -612,12 +631,13 @@ Object[][] data_ranges() { }; } - @Test(dataProvider = "ranges") + @Test + @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(BritishCutoverDate.of(year, month, dom).range(field), ValueRange.of(expectedMin, expectedMax)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_range_unsupported() { BritishCutoverDate.of(2012, 6, 30).range(MINUTE_OF_DAY); } @@ -625,8 +645,8 @@ public void test_range_unsupported() { //----------------------------------------------------------------------- // BritishCutoverDate.getLong //----------------------------------------------------------------------- - @DataProvider(name = "getLong") - Object[][] data_getLong() { + @DataProvider + public static Object[][] data_getLong() { return new Object[][] { {1752, 5, 26, DAY_OF_WEEK, 2}, {1752, 5, 26, DAY_OF_MONTH, 26}, @@ -673,12 +693,13 @@ Object[][] data_getLong() { }; } - @Test(dataProvider = "getLong") + @Test + @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(BritishCutoverDate.of(year, month, dom).getLong(field), expected); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_getLong_unsupported() { BritishCutoverDate.of(2012, 6, 30).getLong(MINUTE_OF_DAY); } @@ -686,8 +707,8 @@ public void test_getLong_unsupported() { //----------------------------------------------------------------------- // BritishCutoverDate.with //----------------------------------------------------------------------- - @DataProvider(name = "with") - Object[][] data_with() { + @DataProvider + public static Object[][] data_with() { return new Object[][] { {1752, 9, 2, DAY_OF_WEEK, 1, 1752, 8, 31}, {1752, 9, 2, DAY_OF_WEEK, 4, 1752, 9, 14}, @@ -784,14 +805,15 @@ Object[][] data_with() { }; } - @Test(dataProvider = "with") + @Test + @UseDataProvider("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(BritishCutoverDate.of(year, month, dom).with(field, value), BritishCutoverDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_with_TemporalField_unsupported() { BritishCutoverDate.of(2012, 6, 30).with(MINUTE_OF_DAY, 0); } @@ -799,8 +821,8 @@ public void test_with_TemporalField_unsupported() { //----------------------------------------------------------------------- // BritishCutoverDate.with(TemporalAdjuster) //----------------------------------------------------------------------- - @DataProvider(name = "withLastDayOfMonth") - Object[][] data_lastDayOfMonth() { + @DataProvider + public static Object[][] data_lastDayOfMonth() { return new Object[][] { {BritishCutoverDate.of(1752, 2, 23), BritishCutoverDate.of(1752, 2, 29)}, {BritishCutoverDate.of(1752, 6, 23), BritishCutoverDate.of(1752, 6, 30)}, @@ -811,7 +833,8 @@ Object[][] data_lastDayOfMonth() { }; } - @Test(dataProvider = "withLastDayOfMonth") + @Test + @UseDataProvider("data_lastDayOfMonth") public void test_adjust_lastDayOfMonth(BritishCutoverDate input, BritishCutoverDate expected) { BritishCutoverDate test = input.with(TemporalAdjusters.lastDayOfMonth()); assertEquals(test, expected); @@ -820,8 +843,8 @@ public void test_adjust_lastDayOfMonth(BritishCutoverDate input, BritishCutoverD //----------------------------------------------------------------------- // BritishCutoverDate.with(Local*) //----------------------------------------------------------------------- - @DataProvider(name = "withLocalDate") - Object[][] data_withLocalDate() { + @DataProvider + public static Object[][] data_withLocalDate() { return new Object[][] { {BritishCutoverDate.of(1752, 9, 2), LocalDate.of(1752, 9, 12), BritishCutoverDate.of(1752, 9, 1)}, {BritishCutoverDate.of(1752, 9, 14), LocalDate.of(1752, 9, 12), BritishCutoverDate.of(1752, 9, 1)}, @@ -831,13 +854,14 @@ Object[][] data_withLocalDate() { }; } - @Test(dataProvider = "withLocalDate") + @Test + @UseDataProvider("data_withLocalDate") public void test_adjust_LocalDate(BritishCutoverDate input, LocalDate local, BritishCutoverDate expected) { BritishCutoverDate test = input.with(local); assertEquals(test, expected); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_adjust_toMonth() { BritishCutoverDate cutover = BritishCutoverDate.of(2000, 1, 4); cutover.with(Month.APRIL); @@ -863,8 +887,8 @@ public void test_LocalDateTime_withBritishCutoverDate() { //----------------------------------------------------------------------- // BritishCutoverDate.plus //----------------------------------------------------------------------- - @DataProvider(name = "plus") - Object[][] data_plus() { + @DataProvider + public static Object[][] data_plus() { return new Object[][] { {1752, 9, 2, -1, DAYS, 1752, 9, 1, true}, {1752, 9, 2, 0, DAYS, 1752, 9, 2, true}, @@ -915,14 +939,16 @@ Object[][] data_plus() { }; } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom, boolean bidi) { assertEquals(BritishCutoverDate.of(year, month, dom).plus(amount, unit), BritishCutoverDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -932,7 +958,7 @@ public void test_minus_TemporalUnit( } } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_plus_TemporalUnit_unsupported() { BritishCutoverDate.of(2012, 6, 30).plus(0, MINUTES); } @@ -940,8 +966,8 @@ public void test_plus_TemporalUnit_unsupported() { //----------------------------------------------------------------------- // BritishCutoverDate.until //----------------------------------------------------------------------- - @DataProvider(name = "until") - Object[][] data_until() { + @DataProvider + public static Object[][] data_until() { return new Object[][] { {1752, 9, 1, 1752, 9, 2, DAYS, 1}, {1752, 9, 1, 1752, 9, 14, DAYS, 2}, @@ -993,7 +1019,8 @@ Object[][] data_until() { }; } - @Test(dataProvider = "until") + @Test + @UseDataProvider("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -1003,7 +1030,7 @@ public void test_until_TemporalUnit( assertEquals(start.until(end, unit), expected); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_until_TemporalUnit_unsupported() { BritishCutoverDate start = BritishCutoverDate.of(2012, 6, 30); BritishCutoverDate end = BritishCutoverDate.of(2012, 7, 1); @@ -1024,7 +1051,7 @@ public void test_plus_Period() { BritishCutoverDate.of(2014, 7, 29)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_plus_Period_ISO() { assertEquals( BritishCutoverDate.of(2014, 5, 26).plus(Period.ofMonths(2)), @@ -1041,7 +1068,7 @@ public void test_minus_Period() { BritishCutoverDate.of(2014, 3, 23)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_minus_Period_ISO() { assertEquals( BritishCutoverDate.of(2014, 5, 26).minus(Period.ofMonths(2)), @@ -1049,8 +1076,8 @@ public void test_minus_Period_ISO() { } //----------------------------------------------------------------------- - @DataProvider(name = "untilCLD") - Object[][] data_untilCLD() { + @DataProvider + public static Object[][] data_untilCLD() { return new Object[][] { {1752, 7, 2, 1752, 7, 1, 0, 0, -1}, {1752, 7, 2, 1752, 7, 2, 0, 0, 0}, @@ -1195,7 +1222,8 @@ Object[][] data_untilCLD() { }; } - @Test(dataProvider = "untilCLD") + @Test + @UseDataProvider("data_untilCLD") public void test_until_CLD( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -1208,7 +1236,8 @@ public void test_until_CLD( BritishCutoverChronology.INSTANCE.period(expectedYears, expectedMonths, expectedDays)); } - @Test(dataProvider = "untilCLD") + @Test + @UseDataProvider("data_untilCLD") public void test_until_CLD_plus( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -1233,7 +1262,7 @@ public void test_atTime() { assertEquals(test2, test); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_atTime_null() { BritishCutoverDate.of(2014, 5, 26).atTime(null); } @@ -1242,7 +1271,7 @@ public void test_atTime_null() { // check against GregorianCalendar //----------------------------------------------------------------------- @Test - void test_crossCheck() { + public void test_crossCheck() { BritishCutoverDate test = BritishCutoverDate.of(1700, 1, 1); BritishCutoverDate end = BritishCutoverDate.of(1800, 1, 1); Instant cutover = ZonedDateTime.of(1752, 9, 14, 0, 0, 0, 0, ZoneOffset.UTC).toInstant(); @@ -1264,7 +1293,7 @@ void test_crossCheck() { // equals() //----------------------------------------------------------------------- @Test - void test_equals() { + public void test_equals() { BritishCutoverDate a1 = BritishCutoverDate.of(2000, 1, 3); BritishCutoverDate a2 = BritishCutoverDate.of(2000, 1, 3); BritishCutoverDate b = BritishCutoverDate.of(2000, 1, 4); @@ -1286,15 +1315,16 @@ void test_equals() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider(name = "toString") - Object[][] data_toString() { + @DataProvider + public static Object[][] data_toString() { return new Object[][] { {BritishCutoverDate.of(1, 1, 1), "BritishCutover AD 1-01-01"}, {BritishCutoverDate.of(2012, 6, 23), "BritishCutover AD 2012-06-23"}, }; } - @Test(dataProvider = "toString") + @Test + @UseDataProvider("data_toString") public void test_toString(BritishCutoverDate cutover, String expected) { assertEquals(cutover.toString(), expected); } diff --git a/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java b/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java index 20c7ca13..106b2aea 100644 --- a/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java @@ -53,7 +53,7 @@ import static java.time.temporal.ChronoUnit.MONTHS; import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; -import static org.testng.Assert.assertEquals; +import static org.junit.Assert.assertEquals; import java.time.DateTimeException; import java.time.LocalDate; @@ -70,14 +70,18 @@ import java.time.temporal.WeekFields; import java.util.List; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test. */ -@Test +@RunWith(DataProviderRunner.class) public class TestCopticChronology { //----------------------------------------------------------------------- @@ -104,8 +108,8 @@ public void test_chronology_of_name_id() { //----------------------------------------------------------------------- // creation, toLocalDate() //----------------------------------------------------------------------- - @DataProvider(name = "samples") - Object[][] data_samples() { + @DataProvider + public static Object[][] data_samples() { return new Object[][] { {CopticDate.of(-1, 13, 6), LocalDate.of(283, 8, 29)}, {CopticDate.of(0, 1, 1), LocalDate.of(283, 8, 30)}, @@ -132,47 +136,56 @@ Object[][] data_samples() { }; } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_LocalDate_from_CopticDate(CopticDate coptic, LocalDate iso) { assertEquals(LocalDate.from(coptic), iso); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_CopticDate_from_LocalDate(CopticDate coptic, LocalDate iso) { assertEquals(CopticDate.from(iso), coptic); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_CopticDate_chronology_dateEpochDay(CopticDate coptic, LocalDate iso) { assertEquals(CopticChronology.INSTANCE.dateEpochDay(iso.toEpochDay()), coptic); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_CopticDate_toEpochDay(CopticDate coptic, LocalDate iso) { assertEquals(coptic.toEpochDay(), iso.toEpochDay()); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_CopticDate_until_CopticDate(CopticDate coptic, LocalDate iso) { assertEquals(coptic.until(coptic), CopticChronology.INSTANCE.period(0, 0, 0)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_CopticDate_until_LocalDate(CopticDate coptic, LocalDate iso) { assertEquals(coptic.until(iso), CopticChronology.INSTANCE.period(0, 0, 0)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_LocalDate_until_CopticDate(CopticDate coptic, LocalDate iso) { assertEquals(iso.until(coptic), Period.ZERO); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(CopticDate coptic, LocalDate iso) { assertEquals(CopticChronology.INSTANCE.date(iso), coptic); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_plusDays(CopticDate coptic, LocalDate iso) { assertEquals(LocalDate.from(coptic.plus(0, DAYS)), iso); assertEquals(LocalDate.from(coptic.plus(1, DAYS)), iso.plusDays(1)); @@ -181,7 +194,8 @@ public void test_plusDays(CopticDate coptic, LocalDate iso) { assertEquals(LocalDate.from(coptic.plus(-60, DAYS)), iso.plusDays(-60)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_minusDays(CopticDate coptic, LocalDate iso) { assertEquals(LocalDate.from(coptic.minus(0, DAYS)), iso); assertEquals(LocalDate.from(coptic.minus(1, DAYS)), iso.minusDays(1)); @@ -190,7 +204,8 @@ public void test_minusDays(CopticDate coptic, LocalDate iso) { assertEquals(LocalDate.from(coptic.minus(-60, DAYS)), iso.minusDays(-60)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_until_DAYS(CopticDate coptic, LocalDate iso) { assertEquals(coptic.until(iso.plusDays(0), DAYS), 0); assertEquals(coptic.until(iso.plusDays(1), DAYS), 1); @@ -198,8 +213,8 @@ public void test_until_DAYS(CopticDate coptic, LocalDate iso) { assertEquals(coptic.until(iso.minusDays(40), DAYS), -40); } - @DataProvider(name = "badDates") - Object[][] data_badDates() { + @DataProvider + public static Object[][] data_badDates() { return new Object[][] { {1728, 0, 0}, @@ -230,12 +245,13 @@ Object[][] data_badDates() { }; } - @Test(dataProvider = "badDates", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_badDates") public void test_badDates(int year, int month, int dom) { CopticDate.of(year, month, dom); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_chronology_dateYearDay_badDate() { CopticChronology.INSTANCE.dateYearDay(1728, 366); } @@ -271,8 +287,8 @@ public void test_isLeapYear_specific() { assertEquals(CopticChronology.INSTANCE.isLeapYear(-6), false); } - @DataProvider(name = "lengthOfMonth") - Object[][] data_lengthOfMonth() { + @DataProvider + public static Object[][] data_lengthOfMonth() { return new Object[][] { {1726, 1, 30}, {1726, 2, 30}, @@ -291,7 +307,8 @@ Object[][] data_lengthOfMonth() { }; } - @Test(dataProvider = "lengthOfMonth") + @Test + @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(CopticDate.of(year, month, 1).lengthOfMonth(), length); } @@ -345,7 +362,7 @@ public void test_Chronology_eraOf() { assertEquals(CopticChronology.INSTANCE.eraOf(0), CopticEra.BEFORE_AM); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_Chronology_eraOf_invalid() { CopticChronology.INSTANCE.eraOf(2); } @@ -372,8 +389,8 @@ public void test_Chronology_range() { //----------------------------------------------------------------------- // CopticDate.range //----------------------------------------------------------------------- - @DataProvider(name = "ranges") - Object[][] data_ranges() { + @DataProvider + public static Object[][] data_ranges() { return new Object[][] { {1727, 1, 23, DAY_OF_MONTH, 1, 30}, {1727, 2, 23, DAY_OF_MONTH, 1, 30}, @@ -401,12 +418,13 @@ Object[][] data_ranges() { }; } - @Test(dataProvider = "ranges") + @Test + @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(CopticDate.of(year, month, dom).range(field), ValueRange.of(expectedMin, expectedMax)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_range_unsupported() { CopticDate.of(1727, 6, 30).range(MINUTE_OF_DAY); } @@ -414,8 +432,8 @@ public void test_range_unsupported() { //----------------------------------------------------------------------- // CopticDate.getLong //----------------------------------------------------------------------- - @DataProvider(name = "getLong") - Object[][] data_getLong() { + @DataProvider + public static Object[][] data_getLong() { return new Object[][] { {1727, 6, 8, DAY_OF_WEEK, 2}, {1727, 6, 8, DAY_OF_MONTH, 8}, @@ -435,12 +453,13 @@ Object[][] data_getLong() { }; } - @Test(dataProvider = "getLong") + @Test + @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(CopticDate.of(year, month, dom).getLong(field), expected); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_getLong_unsupported() { CopticDate.of(1727, 6, 30).getLong(MINUTE_OF_DAY); } @@ -448,8 +467,8 @@ public void test_getLong_unsupported() { //----------------------------------------------------------------------- // CopticDate.with //----------------------------------------------------------------------- - @DataProvider(name = "with") - Object[][] data_with() { + @DataProvider + public static Object[][] data_with() { return new Object[][] { {1727, 6, 8, DAY_OF_WEEK, 4, 1727, 6, 10}, {1727, 6, 8, DAY_OF_WEEK, 2, 1727, 6, 8}, @@ -484,14 +503,15 @@ Object[][] data_with() { }; } - @Test(dataProvider = "with") + @Test + @UseDataProvider("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(CopticDate.of(year, month, dom).with(field, value), CopticDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_with_TemporalField_unsupported() { CopticDate.of(1727, 6, 30).with(MINUTE_OF_DAY, 0); } @@ -523,7 +543,7 @@ public void test_adjust_toLocalDate() { assertEquals(test, CopticDate.of(1728, 10, 29)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_adjust_toMonth() { CopticDate coptic = CopticDate.of(1726, 1, 4); coptic.with(Month.APRIL); @@ -549,8 +569,8 @@ public void test_LocalDateTime_adjustToCopticDate() { //----------------------------------------------------------------------- // CopticDate.plus //----------------------------------------------------------------------- - @DataProvider(name = "plus") - Object[][] data_plus() { + @DataProvider + public static Object[][] data_plus() { return new Object[][] { {1726, 5, 26, 0, DAYS, 1726, 5, 26}, {1726, 5, 26, 8, DAYS, 1726, 6, 4}, @@ -577,14 +597,16 @@ Object[][] data_plus() { }; } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(CopticDate.of(year, month, dom).plus(amount, unit), CopticDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -592,7 +614,7 @@ public void test_minus_TemporalUnit( assertEquals(CopticDate.of(year, month, dom).minus(amount, unit), CopticDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_plus_TemporalUnit_unsupported() { CopticDate.of(1727, 6, 30).plus(0, MINUTES); } @@ -603,7 +625,7 @@ public void test_plus_Period() { assertEquals(CopticDate.of(1727, 5, 26).plus(CopticChronology.INSTANCE.period(0, 2, 3)), CopticDate.of(1727, 7, 29)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_plus_Period_ISO() { assertEquals(CopticDate.of(1727, 5, 26).plus(Period.ofMonths(2)), CopticDate.of(1727, 7, 26)); } @@ -613,7 +635,7 @@ public void test_minus_Period() { assertEquals(CopticDate.of(1727, 5, 26).minus(CopticChronology.INSTANCE.period(0, 2, 3)), CopticDate.of(1727, 3, 23)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_minus_Period_ISO() { assertEquals(CopticDate.of(1727, 5, 26).minus(Period.ofMonths(2)), CopticDate.of(1727, 3, 26)); } @@ -621,8 +643,8 @@ public void test_minus_Period_ISO() { //----------------------------------------------------------------------- // CopticDate.until //----------------------------------------------------------------------- - @DataProvider(name = "until") - Object[][] data_until() { + @DataProvider + public static Object[][] data_until() { return new Object[][] { {1726, 5, 26, 1726, 5, 26, DAYS, 0}, {1726, 5, 26, 1726, 6, 1, DAYS, 5}, @@ -648,7 +670,8 @@ Object[][] data_until() { }; } - @Test(dataProvider = "until") + @Test + @UseDataProvider("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -658,7 +681,7 @@ public void test_until_TemporalUnit( assertEquals(start.until(end, unit), expected); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_until_TemporalUnit_unsupported() { CopticDate start = CopticDate.of(1726, 6, 30); CopticDate end = CopticDate.of(1726, 7, 1); @@ -669,7 +692,7 @@ public void test_until_TemporalUnit_unsupported() { // equals() //----------------------------------------------------------------------- @Test - void test_equals() { + public void test_equals() { CopticDate a1 = CopticDate.of(1728, 1, 3); CopticDate a2 = CopticDate.of(1728, 1, 3); CopticDate b = CopticDate.of(1728, 1, 4); @@ -691,8 +714,8 @@ void test_equals() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider(name = "toString") - Object[][] data_toString() { + @DataProvider + public static Object[][] data_toString() { return new Object[][] { {CopticDate.of(1, 1, 1), "Coptic AM 1-01-01"}, {CopticDate.of(1728, 10, 28), "Coptic AM 1728-10-28"}, @@ -702,7 +725,8 @@ Object[][] data_toString() { }; } - @Test(dataProvider = "toString") + @Test + @UseDataProvider("data_toString") public void test_toString(CopticDate coptic, String expected) { assertEquals(coptic.toString(), expected); } diff --git a/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java b/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java index 915e3bb8..a28c5f45 100644 --- a/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java @@ -54,7 +54,7 @@ import static java.time.temporal.ChronoUnit.MONTHS; import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; -import static org.testng.Assert.assertEquals; +import static org.junit.Assert.assertEquals; import java.time.DateTimeException; import java.time.LocalDate; @@ -73,14 +73,18 @@ import java.util.List; import java.util.function.Predicate; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test. */ -@Test +@RunWith(DataProviderRunner.class) public class TestDiscordianChronology { //----------------------------------------------------------------------- @@ -107,8 +111,8 @@ public void test_chronology_of_name_id() { //----------------------------------------------------------------------- // creation, toLocalDate() //----------------------------------------------------------------------- - @DataProvider(name = "samples") - Object[][] data_samples() { + @DataProvider + public static Object[][] data_samples() { return new Object[][] { {DiscordianDate.of(2, 1, 1), LocalDate.of(-1164, 1, 1)}, {DiscordianDate.of(166, 1, 1), LocalDate.of(-1000, 1, 1)}, @@ -148,47 +152,56 @@ Object[][] data_samples() { }; } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_LocalDate_from_DiscordianDate(DiscordianDate discordian, LocalDate iso) { assertEquals(LocalDate.from(discordian), iso); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_DiscordianDate_from_LocalDate(DiscordianDate discordian, LocalDate iso) { assertEquals(DiscordianDate.from(iso), discordian); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_DiscordianDate_chronology_dateEpochDay(DiscordianDate discordian, LocalDate iso) { assertEquals(DiscordianChronology.INSTANCE.dateEpochDay(iso.toEpochDay()), discordian); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_DiscordianDate_toEpochDay(DiscordianDate discordian, LocalDate iso) { assertEquals(discordian.toEpochDay(), iso.toEpochDay()); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_DiscordianDate_until_DiscordianDate(DiscordianDate discordian, LocalDate iso) { assertEquals(discordian.until(discordian), DiscordianChronology.INSTANCE.period(0, 0, 0)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_DiscordianDate_until_LocalDate(DiscordianDate discordian, LocalDate iso) { assertEquals(discordian.until(iso), DiscordianChronology.INSTANCE.period(0, 0, 0)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_LocalDate_until_DiscordianDate(DiscordianDate discordian, LocalDate iso) { assertEquals(iso.until(discordian), Period.ZERO); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(DiscordianDate discordian, LocalDate iso) { assertEquals(DiscordianChronology.INSTANCE.date(iso), discordian); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_plusDays(DiscordianDate discordian, LocalDate iso) { assertEquals(LocalDate.from(discordian.plus(0, DAYS)), iso); assertEquals(LocalDate.from(discordian.plus(1, DAYS)), iso.plusDays(1)); @@ -197,7 +210,8 @@ public void test_plusDays(DiscordianDate discordian, LocalDate iso) { assertEquals(LocalDate.from(discordian.plus(-60, DAYS)), iso.plusDays(-60)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_minusDays(DiscordianDate discordian, LocalDate iso) { assertEquals(LocalDate.from(discordian.minus(0, DAYS)), iso); assertEquals(LocalDate.from(discordian.minus(1, DAYS)), iso.minusDays(1)); @@ -206,7 +220,8 @@ public void test_minusDays(DiscordianDate discordian, LocalDate iso) { assertEquals(LocalDate.from(discordian.minus(-60, DAYS)), iso.minusDays(-60)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_until_DAYS(DiscordianDate discordian, LocalDate iso) { assertEquals(discordian.until(iso.plusDays(0), DAYS), 0); assertEquals(discordian.until(iso.plusDays(1), DAYS), 1); @@ -214,8 +229,8 @@ public void test_until_DAYS(DiscordianDate discordian, LocalDate iso) { assertEquals(discordian.until(iso.minusDays(40), DAYS), -40); } - @DataProvider(name = "badDates") - Object[][] data_badDates() { + @DataProvider + public static Object[][] data_badDates() { return new Object[][] { {1900, 0, 0}, @@ -240,12 +255,13 @@ Object[][] data_badDates() { }; } - @Test(dataProvider = "badDates", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_badDates") public void test_badDates(int year, int month, int dom) { DiscordianDate.of(year, month, dom); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_chronology_dateYearDay_badDate() { DiscordianChronology.INSTANCE.dateYearDay(2001, 366); } @@ -261,8 +277,8 @@ public void test_isLeapYear_loop() { }; for (int year = 1066; year < 1567; year++) { DiscordianDate base = DiscordianDate.of(year, 1, 1); - assertEquals(base.isLeapYear(), isLeapYear.test(year), "Mismatch on " + year); - assertEquals(DiscordianChronology.INSTANCE.isLeapYear(year), isLeapYear.test(year), "Mismatch on " + year); + assertEquals(base.isLeapYear(), isLeapYear.test(year)); + assertEquals(DiscordianChronology.INSTANCE.isLeapYear(year), isLeapYear.test(year)); } } @@ -285,8 +301,8 @@ public void test_isLeapYear_specific() { assertEquals(DiscordianChronology.INSTANCE.isLeapYear(1160), false); } - @DataProvider(name = "lengthOfMonth") - Object[][] data_lengthOfMonth() { + @DataProvider + public static Object[][] data_lengthOfMonth() { return new Object[][] { {1900, 1, 73}, {1900, 2, 73}, @@ -303,7 +319,8 @@ Object[][] data_lengthOfMonth() { }; } - @Test(dataProvider = "lengthOfMonth") + @Test + @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(DiscordianDate.of(year, month, 1).lengthOfMonth(), length); } @@ -350,7 +367,7 @@ public void test_prolepticYear_specific() { assertEquals(DiscordianChronology.INSTANCE.prolepticYear(DiscordianEra.YOLD, 1), 1); } - @Test(expectedExceptions = ClassCastException.class) + @Test(expected = ClassCastException.class) public void test_prolepticYear_badEra() { DiscordianChronology.INSTANCE.prolepticYear(IsoEra.CE, 4); } @@ -360,7 +377,7 @@ public void test_Chronology_eraOf() { assertEquals(DiscordianChronology.INSTANCE.eraOf(1), DiscordianEra.YOLD); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_Chronology_eraOf_invalid() { DiscordianChronology.INSTANCE.eraOf(2); DiscordianChronology.INSTANCE.eraOf(0); @@ -396,8 +413,8 @@ public void test_Chronology_range() { //----------------------------------------------------------------------- // DiscordianDate.range //----------------------------------------------------------------------- - @DataProvider(name = "ranges") - Object[][] data_ranges() { + @DataProvider + public static Object[][] data_ranges() { return new Object[][] { // St Tibs is in its own month, so (0 to 0) or (1 to 73) {2010, 0, 0, DAY_OF_MONTH, 0, 0}, @@ -438,12 +455,13 @@ Object[][] data_ranges() { }; } - @Test(dataProvider = "ranges") + @Test + @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(DiscordianDate.of(year, month, dom).range(field), ValueRange.of(expectedMin, expectedMax)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_range_unsupported() { DiscordianDate.of(2012, 5, 30).range(MINUTE_OF_DAY); } @@ -451,8 +469,8 @@ public void test_range_unsupported() { //----------------------------------------------------------------------- // DiscordianDate.getLong //----------------------------------------------------------------------- - @DataProvider(name = "getLong") - Object[][] data_getLong() { + @DataProvider + public static Object[][] data_getLong() { return new Object[][] { {2014, 1, 26, DAY_OF_WEEK, 1}, {2014, 1, 26, DAY_OF_MONTH, 26}, @@ -491,12 +509,13 @@ Object[][] data_getLong() { }; } - @Test(dataProvider = "getLong") + @Test + @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(DiscordianDate.of(year, month, dom).getLong(field), expected); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_getLong_unsupported() { DiscordianDate.of(2012, 1, 30).getLong(MINUTE_OF_DAY); } @@ -504,8 +523,8 @@ public void test_getLong_unsupported() { //----------------------------------------------------------------------- // DiscordianDate.with //----------------------------------------------------------------------- - @DataProvider(name = "with") - Object[][] data_with() { + @DataProvider + public static Object[][] data_with() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 1, 2014, 5, 24}, {2014, 5, 26, DAY_OF_WEEK, 3, 2014, 5, 26}, @@ -579,15 +598,16 @@ Object[][] data_with() { }; } - @Test(dataProvider = "with") + @Test + @UseDataProvider("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(DiscordianDate.of(year, month, dom).with(field, value), DiscordianDate.of(expectedYear, expectedMonth, expectedDom)); } - @DataProvider(name = "withBad") - Object[][] data_with_bad() { + @DataProvider + public static Object[][] data_with_bad() { return new Object[][] { {2013, 1, 1, DAY_OF_WEEK, 0}, {2013, 1, 1, DAY_OF_WEEK, 6}, @@ -611,12 +631,13 @@ Object[][] data_with_bad() { }; } - @Test(dataProvider = "withBad", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_with_bad") public void test_with_TemporalField_badValue(int year, int month, int dom, TemporalField field, long value) { DiscordianDate.of(year, month, dom).with(field, value); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_with_TemporalField_unsupported() { DiscordianDate.of(2012, 5, 30).with(MINUTE_OF_DAY, 0); } @@ -648,7 +669,7 @@ public void test_adjust_toLocalDate() { assertEquals(test, DiscordianDate.of(3178, 3, 41)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_adjust_toMonth() { DiscordianDate discordian = DiscordianDate.of(2000, 1, 4); discordian.with(Month.APRIL); @@ -674,8 +695,8 @@ public void test_LocalDateTime_adjustToDiscordianDate() { //----------------------------------------------------------------------- // DiscordianDate.plus //----------------------------------------------------------------------- - @DataProvider(name = "plus") - Object[][] data_plus() { + @DataProvider + public static Object[][] data_plus() { return new Object[][] { {2014, 5, 26, 0, DAYS, 2014, 5, 26}, {2014, 5, 26, 8, DAYS, 2014, 5, 34}, @@ -701,8 +722,8 @@ Object[][] data_plus() { }; } - @DataProvider(name = "plus_leap") - Object[][] data_plus_leap() { + @DataProvider + public static Object[][] data_plus_leap() { return new Object[][] { {2014, 0, 0, 0, DAYS, 2014, 0, 0}, {2014, 0, 0, 8, DAYS, 2014, 1, 67}, @@ -722,8 +743,8 @@ Object[][] data_plus_leap() { }; } - @DataProvider(name = "minus_leap") - Object[][] data_minus_leap() { + @DataProvider + public static Object[][] data_minus_leap() { return new Object[][] { {2014, 0, 0, 0, DAYS, 2014, 0, 0}, {2014, 1, 52, 8, DAYS, 2014, 0, 0}, @@ -743,21 +764,24 @@ Object[][] data_minus_leap() { }; } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(DiscordianDate.of(year, month, dom).plus(amount, unit), DiscordianDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(dataProvider = "plus_leap") + @Test + @UseDataProvider("data_plus_leap") public void test_plus_leap_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(DiscordianDate.of(year, month, dom).plus(amount, unit), DiscordianDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -765,7 +789,8 @@ public void test_minus_TemporalUnit( assertEquals(DiscordianDate.of(year, month, dom).minus(amount, unit), DiscordianDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(dataProvider = "minus_leap") + @Test + @UseDataProvider("data_minus_leap") public void test_minus_leap_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -773,7 +798,7 @@ public void test_minus_leap_TemporalUnit( assertEquals(DiscordianDate.of(year, month, dom).minus(amount, unit), DiscordianDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_plus_TemporalUnit_unsupported() { DiscordianDate.of(2012, 5, 30).plus(0, MINUTES); } @@ -781,8 +806,8 @@ public void test_plus_TemporalUnit_unsupported() { //----------------------------------------------------------------------- // DiscordianDate.until //----------------------------------------------------------------------- - @DataProvider(name = "until") - Object[][] data_until() { + @DataProvider + public static Object[][] data_until() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, DAYS, 0}, {2014, 5, 26, 2014, 5, 32, DAYS, 6}, @@ -847,8 +872,8 @@ Object[][] data_until() { }; } - @DataProvider(name = "until_period") - Object[][] data_until_period() { + @DataProvider + public static Object[][] data_until_period() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, 0, 0, 0}, {2014, 5, 26, 2014, 5, 32, 0, 0, 6}, @@ -893,7 +918,8 @@ Object[][] data_until_period() { }; } - @Test(dataProvider = "until") + @Test + @UseDataProvider("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -903,7 +929,8 @@ public void test_until_TemporalUnit( assertEquals(start.until(end, unit), expected); } - @Test(dataProvider = "until_period") + @Test + @UseDataProvider("data_until_period") public void test_until_end( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -914,7 +941,7 @@ public void test_until_end( assertEquals(start.until(end), period); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_until_TemporalUnit_unsupported() { DiscordianDate start = DiscordianDate.of(2012, 1, 30); DiscordianDate end = DiscordianDate.of(2012, 2, 1); @@ -927,7 +954,7 @@ public void test_plus_Period() { assertEquals(DiscordianDate.of(2014, 5, 26).plus(DiscordianChronology.INSTANCE.period(0, 2, 3)), DiscordianDate.of(2015, 2, 29)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_plus_Period_ISO() { assertEquals(DiscordianDate.of(2014, 5, 26).plus(Period.ofMonths(2)), DiscordianDate.of(2015, 2, 26)); } @@ -937,7 +964,7 @@ public void test_minus_Period() { assertEquals(DiscordianDate.of(2014, 5, 26).minus(DiscordianChronology.INSTANCE.period(0, 2, 3)), DiscordianDate.of(2014, 3, 23)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_minus_Period_ISO() { assertEquals(DiscordianDate.of(2014, 5, 26).minus(Period.ofMonths(2)), DiscordianDate.of(2014, 3, 26)); } @@ -946,7 +973,7 @@ public void test_minus_Period_ISO() { // equals() //----------------------------------------------------------------------- @Test - void test_equals() { + public void test_equals() { DiscordianDate a1 = DiscordianDate.of(2000, 1, 3); DiscordianDate a2 = DiscordianDate.of(2000, 1, 3); DiscordianDate b = DiscordianDate.of(2000, 1, 4); @@ -968,8 +995,8 @@ void test_equals() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider(name = "toString") - Object[][] data_toString() { + @DataProvider + public static Object[][] data_toString() { return new Object[][] { {DiscordianDate.of(1, 1, 1), "Discordian YOLD 1-1-01"}, {DiscordianDate.of(2012, 5, 23), "Discordian YOLD 2012-5-23"}, @@ -977,7 +1004,8 @@ Object[][] data_toString() { }; } - @Test(dataProvider = "toString") + @Test + @UseDataProvider("data_toString") public void test_toString(DiscordianDate discordian, String expected) { assertEquals(discordian.toString(), expected); } diff --git a/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java b/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java index e93d3822..eff4688c 100644 --- a/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java @@ -53,7 +53,7 @@ import static java.time.temporal.ChronoUnit.MONTHS; import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; -import static org.testng.Assert.assertEquals; +import static org.junit.Assert.assertEquals; import java.time.DateTimeException; import java.time.LocalDate; @@ -70,14 +70,18 @@ import java.time.temporal.WeekFields; import java.util.List; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test. */ -@Test +@RunWith(DataProviderRunner.class) public class TestEthiopicChronology { //----------------------------------------------------------------------- @@ -104,8 +108,8 @@ public void test_chronology_of_name_id() { //----------------------------------------------------------------------- // creation, toLocalDate() //----------------------------------------------------------------------- - @DataProvider(name = "samples") - Object[][] data_samples() { + @DataProvider + public static Object[][] data_samples() { return new Object[][] { {EthiopicDate.of(-1, 13, 6), LocalDate.of(7, 8, 27)}, {EthiopicDate.of(0, 1, 1), LocalDate.of(7, 8, 28)}, @@ -133,47 +137,56 @@ Object[][] data_samples() { }; } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_LocalDate_from_EthiopicDate(EthiopicDate ethiopic, LocalDate iso) { assertEquals(LocalDate.from(ethiopic), iso); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_EthiopicDate_from_LocalDate(EthiopicDate ethiopic, LocalDate iso) { assertEquals(EthiopicDate.from(iso), ethiopic); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_EthiopicDate_chronology_dateEpochDay(EthiopicDate ethiopic, LocalDate iso) { assertEquals(EthiopicChronology.INSTANCE.dateEpochDay(iso.toEpochDay()), ethiopic); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_EthiopicDate_toEpochDay(EthiopicDate ethiopic, LocalDate iso) { assertEquals(ethiopic.toEpochDay(), iso.toEpochDay()); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_EthiopicDate_until_EthiopicDate(EthiopicDate ethiopic, LocalDate iso) { assertEquals(ethiopic.until(ethiopic), EthiopicChronology.INSTANCE.period(0, 0, 0)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_EthiopicDate_until_LocalDate(EthiopicDate ethiopic, LocalDate iso) { assertEquals(ethiopic.until(iso), EthiopicChronology.INSTANCE.period(0, 0, 0)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_LocalDate_until_EthiopicDate(EthiopicDate ethiopic, LocalDate iso) { assertEquals(iso.until(ethiopic), Period.ZERO); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(EthiopicDate ethiopic, LocalDate iso) { assertEquals(EthiopicChronology.INSTANCE.date(iso), ethiopic); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_plusDays(EthiopicDate ethiopic, LocalDate iso) { assertEquals(LocalDate.from(ethiopic.plus(0, DAYS)), iso); assertEquals(LocalDate.from(ethiopic.plus(1, DAYS)), iso.plusDays(1)); @@ -182,7 +195,8 @@ public void test_plusDays(EthiopicDate ethiopic, LocalDate iso) { assertEquals(LocalDate.from(ethiopic.plus(-60, DAYS)), iso.plusDays(-60)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_minusDays(EthiopicDate ethiopic, LocalDate iso) { assertEquals(LocalDate.from(ethiopic.minus(0, DAYS)), iso); assertEquals(LocalDate.from(ethiopic.minus(1, DAYS)), iso.minusDays(1)); @@ -191,7 +205,8 @@ public void test_minusDays(EthiopicDate ethiopic, LocalDate iso) { assertEquals(LocalDate.from(ethiopic.minus(-60, DAYS)), iso.minusDays(-60)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_until_DAYS(EthiopicDate ethiopic, LocalDate iso) { assertEquals(ethiopic.until(iso.plusDays(0), DAYS), 0); assertEquals(ethiopic.until(iso.plusDays(1), DAYS), 1); @@ -199,8 +214,8 @@ public void test_until_DAYS(EthiopicDate ethiopic, LocalDate iso) { assertEquals(ethiopic.until(iso.minusDays(40), DAYS), -40); } - @DataProvider(name = "badDates") - Object[][] data_badDates() { + @DataProvider + public static Object[][] data_badDates() { return new Object[][] { {2008, 0, 0}, @@ -231,12 +246,13 @@ Object[][] data_badDates() { }; } - @Test(dataProvider = "badDates", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_badDates") public void test_badDates(int year, int month, int dom) { EthiopicDate.of(year, month, dom); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_chronology_dateYearDay_badDate() { EthiopicChronology.INSTANCE.dateYearDay(2008, 366); } @@ -272,8 +288,8 @@ public void test_isLeapYear_specific() { assertEquals(EthiopicChronology.INSTANCE.isLeapYear(-6), false); } - @DataProvider(name = "lengthOfMonth") - Object[][] data_lengthOfMonth() { + @DataProvider + public static Object[][] data_lengthOfMonth() { return new Object[][] { {2006, 1, 30}, {2006, 2, 30}, @@ -292,7 +308,8 @@ Object[][] data_lengthOfMonth() { }; } - @Test(dataProvider = "lengthOfMonth") + @Test + @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(EthiopicDate.of(year, month, 1).lengthOfMonth(), length); } @@ -346,7 +363,7 @@ public void test_Chronology_eraOf() { assertEquals(EthiopicChronology.INSTANCE.eraOf(0), EthiopicEra.BEFORE_INCARNATION); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_Chronology_eraOf_invalid() { EthiopicChronology.INSTANCE.eraOf(2); } @@ -373,8 +390,8 @@ public void test_Chronology_range() { //----------------------------------------------------------------------- // EthiopicDate.range //----------------------------------------------------------------------- - @DataProvider(name = "ranges") - Object[][] data_ranges() { + @DataProvider + public static Object[][] data_ranges() { return new Object[][] { {2007, 1, 23, DAY_OF_MONTH, 1, 30}, {2007, 2, 23, DAY_OF_MONTH, 1, 30}, @@ -402,12 +419,13 @@ Object[][] data_ranges() { }; } - @Test(dataProvider = "ranges") + @Test + @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(EthiopicDate.of(year, month, dom).range(field), ValueRange.of(expectedMin, expectedMax)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_range_unsupported() { EthiopicDate.of(2007, 6, 30).range(MINUTE_OF_DAY); } @@ -415,8 +433,8 @@ public void test_range_unsupported() { //----------------------------------------------------------------------- // EthiopicDate.getLong //----------------------------------------------------------------------- - @DataProvider(name = "getLong") - Object[][] data_getLong() { + @DataProvider + public static Object[][] data_getLong() { return new Object[][] { {2007, 6, 8, DAY_OF_WEEK, 7}, {2007, 6, 8, DAY_OF_MONTH, 8}, @@ -436,12 +454,13 @@ Object[][] data_getLong() { }; } - @Test(dataProvider = "getLong") + @Test + @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(EthiopicDate.of(year, month, dom).getLong(field), expected); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_getLong_unsupported() { EthiopicDate.of(2007, 6, 30).getLong(MINUTE_OF_DAY); } @@ -449,8 +468,8 @@ public void test_getLong_unsupported() { //----------------------------------------------------------------------- // EthiopicDate.with //----------------------------------------------------------------------- - @DataProvider(name = "with") - Object[][] data_with() { + @DataProvider + public static Object[][] data_with() { return new Object[][] { {2007, 6, 8, DAY_OF_WEEK, 3, 2007, 6, 4}, {2007, 6, 8, DAY_OF_WEEK, 7, 2007, 6, 8}, @@ -488,15 +507,16 @@ Object[][] data_with() { }; } - @Test(dataProvider = "with") + @Test + @UseDataProvider("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(EthiopicDate.of(year, month, dom).with(field, value), EthiopicDate.of(expectedYear, expectedMonth, expectedDom)); } - @DataProvider(name = "withBad") - Object[][] data_with_bad() { + @DataProvider + public static Object[][] data_with_bad() { return new Object[][] { {2007, 6, 8, DAY_OF_WEEK, 0}, {2007, 6, 8, DAY_OF_WEEK, 8}, @@ -510,12 +530,13 @@ Object[][] data_with_bad() { }; } - @Test(dataProvider = "withBad", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_with_bad") public void test_with_TemporalField_badValue(int year, int month, int dom, TemporalField field, long value) { EthiopicDate.of(year, month, dom).with(field, value); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_with_TemporalField_unsupported() { EthiopicDate.of(2006, 6, 30).with(MINUTE_OF_DAY, 0); } @@ -547,7 +568,7 @@ public void test_adjust_toLocalDate() { assertEquals(test, EthiopicDate.of(2004, 2, 5)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_adjust_toMonth() { EthiopicDate ethiopic = EthiopicDate.of(2004, 1, 4); ethiopic.with(Month.APRIL); @@ -573,8 +594,8 @@ public void test_LocalDateTime_adjustToEthiopicDate() { //----------------------------------------------------------------------- // EthiopicDate.plus //----------------------------------------------------------------------- - @DataProvider(name = "plus") - Object[][] data_plus() { + @DataProvider + public static Object[][] data_plus() { return new Object[][] { {2006, 5, 26, 0, DAYS, 2006, 5, 26}, {2006, 5, 26, 8, DAYS, 2006, 6, 4}, @@ -601,14 +622,16 @@ Object[][] data_plus() { }; } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(EthiopicDate.of(year, month, dom).plus(amount, unit), EthiopicDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -616,7 +639,7 @@ public void test_minus_TemporalUnit( assertEquals(EthiopicDate.of(year, month, dom).minus(amount, unit), EthiopicDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_plus_TemporalUnit_unsupported() { EthiopicDate.of(2006, 6, 30).plus(0, MINUTES); } @@ -627,7 +650,7 @@ public void test_plus_Period() { assertEquals(EthiopicDate.of(2006, 5, 26).plus(EthiopicChronology.INSTANCE.period(0, 2, 3)), EthiopicDate.of(2006, 7, 29)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_plus_Period_ISO() { assertEquals(EthiopicDate.of(2006, 5, 26).plus(Period.ofMonths(2)), EthiopicDate.of(2006, 7, 26)); } @@ -637,7 +660,7 @@ public void test_minus_Period() { assertEquals(EthiopicDate.of(2006, 5, 26).minus(EthiopicChronology.INSTANCE.period(0, 2, 3)), EthiopicDate.of(2006, 3, 23)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_minus_Period_ISO() { assertEquals(EthiopicDate.of(2006, 5, 26).minus(Period.ofMonths(2)), EthiopicDate.of(2006, 3, 26)); } @@ -645,8 +668,8 @@ public void test_minus_Period_ISO() { //----------------------------------------------------------------------- // EthiopicDate.until //----------------------------------------------------------------------- - @DataProvider(name = "until") - Object[][] data_until() { + @DataProvider + public static Object[][] data_until() { return new Object[][] { {2006, 5, 26, 2006, 5, 26, DAYS, 0}, {2006, 5, 26, 2006, 6, 1, DAYS, 5}, @@ -672,7 +695,8 @@ Object[][] data_until() { }; } - @Test(dataProvider = "until") + @Test + @UseDataProvider("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -682,7 +706,7 @@ public void test_until_TemporalUnit( assertEquals(start.until(end, unit), expected); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_until_TemporalUnit_unsupported() { EthiopicDate start = EthiopicDate.of(2006, 6, 30); EthiopicDate end = EthiopicDate.of(2006, 7, 1); @@ -693,7 +717,7 @@ public void test_until_TemporalUnit_unsupported() { // equals() //----------------------------------------------------------------------- @Test - void test_equals() { + public void test_equals() { EthiopicDate a1 = EthiopicDate.of(2004, 1, 3); EthiopicDate a2 = EthiopicDate.of(2004, 1, 3); EthiopicDate b = EthiopicDate.of(2004, 1, 4); @@ -715,8 +739,8 @@ void test_equals() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider(name = "toString") - Object[][] data_toString() { + @DataProvider + public static Object[][] data_toString() { return new Object[][] { {EthiopicDate.of(1, 1, 1), "Ethiopic INCARNATION 1-01-01"}, {EthiopicDate.of(2007, 10, 28), "Ethiopic INCARNATION 2007-10-28"}, @@ -726,7 +750,8 @@ Object[][] data_toString() { }; } - @Test(dataProvider = "toString") + @Test + @UseDataProvider("data_toString") public void test_toString(EthiopicDate ethiopic, String expected) { assertEquals(ethiopic.toString(), expected); } diff --git a/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java b/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java index aaf70c91..9da4e1d4 100644 --- a/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java @@ -54,40 +54,40 @@ import static java.time.temporal.ChronoUnit.MONTHS; import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.Month; import java.time.Period; - -import java.time.chrono.Chronology; import java.time.chrono.ChronoPeriod; +import java.time.chrono.Chronology; import java.time.chrono.Era; import java.time.chrono.IsoEra; - import java.time.temporal.TemporalAdjusters; import java.time.temporal.TemporalField; import java.time.temporal.TemporalUnit; import java.time.temporal.UnsupportedTemporalTypeException; import java.time.temporal.ValueRange; - import java.util.List; import java.util.function.Predicate; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test. */ -@Test @SuppressWarnings({"static-method", "javadoc"}) +@RunWith(DataProviderRunner.class) public class TestInternationalFixedChronology { //----------------------------------------------------------------------- @@ -105,8 +105,8 @@ public void test_chronology() { //----------------------------------------------------------------------- // creation, toLocalDate() //----------------------------------------------------------------------- - @DataProvider(name = "samples") - Object[][] data_samples() { + @DataProvider + public static Object[][] data_samples() { return new Object[][] { {InternationalFixedDate.of(1, 1, 1), LocalDate.of(1, 1, 1)}, {InternationalFixedDate.of(1, 1, 2), LocalDate.of(1, 1, 2)}, @@ -152,47 +152,56 @@ Object[][] data_samples() { }; } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_LocalDate_from_InternationalFixedDate(InternationalFixedDate fixed, LocalDate iso) { assertEquals(LocalDate.from(fixed), iso); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_InternationalFixedDate_from_LocalDate(InternationalFixedDate fixed, LocalDate iso) { assertEquals(InternationalFixedDate.from(iso), fixed); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_InternationalFixedDate_chronology_dateEpochDay(InternationalFixedDate fixed, LocalDate iso) { assertEquals(InternationalFixedChronology.INSTANCE.dateEpochDay(iso.toEpochDay()), fixed); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_InternationalFixedDate_toEpochDay(InternationalFixedDate fixed, LocalDate iso) { assertEquals(fixed.toEpochDay(), iso.toEpochDay()); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_InternationalFixedDate_until_InternationalFixedDate(InternationalFixedDate fixed, LocalDate iso) { assertEquals(fixed.until(fixed), InternationalFixedChronology.INSTANCE.period(0, 0, 0)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_InternationalFixedDate_until_LocalDate(InternationalFixedDate fixed, LocalDate iso) { assertEquals(fixed.until(iso), InternationalFixedChronology.INSTANCE.period(0, 0, 0)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_LocalDate_until_InternationalFixedDate(InternationalFixedDate fixed, LocalDate iso) { assertEquals(iso.until(fixed), Period.ZERO); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(InternationalFixedDate fixed, LocalDate iso) { assertEquals(InternationalFixedChronology.INSTANCE.date(iso), fixed); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_plusDays(InternationalFixedDate fixed, LocalDate iso) { assertEquals(LocalDate.from(fixed.plus(0, DAYS)), iso); assertEquals(LocalDate.from(fixed.plus(1, DAYS)), iso.plusDays(1)); @@ -203,7 +212,8 @@ public void test_plusDays(InternationalFixedDate fixed, LocalDate iso) { } } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_minusDays(InternationalFixedDate fixed, LocalDate iso) { assertEquals(LocalDate.from(fixed.minus(0, DAYS)), iso); if (LocalDate.ofYearDay(1, 35).isBefore(iso)) { @@ -215,7 +225,8 @@ public void test_minusDays(InternationalFixedDate fixed, LocalDate iso) { } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_until_DAYS(InternationalFixedDate fixed, LocalDate iso) { assertEquals(fixed.until(iso.plusDays(0), DAYS), 0); assertEquals(fixed.until(iso.plusDays(1), DAYS), 1); @@ -225,8 +236,8 @@ public void test_until_DAYS(InternationalFixedDate fixed, LocalDate iso) { } } - @DataProvider(name = "badDates") - Object[][] data_badDates() { + @DataProvider + public static Object[][] data_badDates() { return new Object[][] { {-1, 13, 28}, {-1, 13, 29}, @@ -266,13 +277,14 @@ Object[][] data_badDates() { }; } - @Test(dataProvider = "badDates", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_badDates") public void test_badDates(int year, int month, int dom) { InternationalFixedDate.of(year, month, dom); } - @DataProvider(name = "badLeapDates") - Object[][] data_badLeapDates() { + @DataProvider + public static Object[][] data_badLeapDates() { return new Object[][] { {1}, {100}, @@ -282,12 +294,13 @@ Object[][] data_badLeapDates() { }; } - @Test(dataProvider = "badLeapDates", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_badLeapDates") public void badLeapDayDates(int year) { InternationalFixedDate.of(year, 6, 29); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_chronology_dateYearDay_badDate() { InternationalFixedChronology.INSTANCE.dateYearDay(2001, 366); } @@ -303,9 +316,9 @@ public void test_isLeapYear_loop() { for (int year = 1; year < 500; year++) { InternationalFixedDate base = InternationalFixedDate.of(year, 1, 1); - assertEquals(base.isLeapYear(), isLeapYear.test(year), "Year " + year + " is failing"); + assertEquals(base.isLeapYear(), isLeapYear.test(year)); assertEquals(base.lengthOfYear(), isLeapYear.test(year) ? 366 : 365); - assertEquals(InternationalFixedChronology.INSTANCE.isLeapYear(year), isLeapYear.test(year), "Year " + year + " is failing leap-year test"); + assertEquals(InternationalFixedChronology.INSTANCE.isLeapYear(year), isLeapYear.test(year)); } } @@ -322,8 +335,8 @@ public void test_isLeapYear_specific() { //----------------------------------------------------------------------- // lengthOfMonth() //----------------------------------------------------------------------- - @DataProvider(name = "lengthOfMonth") - Object[][] data_lengthOfMonth() { + @DataProvider + public static Object[][] data_lengthOfMonth() { return new Object[][] { {1900, 1, 28, 28}, {1900, 2, 28, 28}, @@ -342,12 +355,14 @@ Object[][] data_lengthOfMonth() { }; } - @Test(dataProvider = "lengthOfMonth") + @Test + @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int day, int length) { assertEquals(InternationalFixedDate.of(year, month, day).lengthOfMonth(), length); } - @Test(dataProvider = "lengthOfMonth") + @Test + @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonthFirst(int year, int month, int day, int length) { assertEquals(InternationalFixedDate.of(year, month, 1).lengthOfMonth(), length); } @@ -398,8 +413,8 @@ public void test_prolepticYear_specific() { assertEquals(InternationalFixedChronology.INSTANCE.prolepticYear(InternationalFixedEra.CE, 1582), 1582); } - @DataProvider(name = "prolepticYearBad") - Object[][] data_prolepticYear_bad() { + @DataProvider + public static Object[][] data_prolepticYear_bad() { return new Object[][] { {-10}, {-1}, @@ -407,12 +422,13 @@ Object[][] data_prolepticYear_bad() { }; } - @Test(dataProvider = "prolepticYearBad", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_prolepticYear_bad") public void test_prolepticYearBad(int year) { InternationalFixedChronology.INSTANCE.prolepticYear(InternationalFixedEra.CE, year); } - @Test(expectedExceptions = ClassCastException.class) + @Test(expected = ClassCastException.class) public void test_prolepticYear_badEra() { InternationalFixedChronology.INSTANCE.prolepticYear(IsoEra.CE, 4); } @@ -422,7 +438,7 @@ public void test_Chronology_eraOf() { assertEquals(InternationalFixedChronology.INSTANCE.eraOf(1), InternationalFixedEra.CE); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_Chronology_eraOf_invalid() { InternationalFixedChronology.INSTANCE.eraOf(0); } @@ -457,8 +473,8 @@ public void test_Chronology_range() { //----------------------------------------------------------------------- // InternationalFixedDate.range //----------------------------------------------------------------------- - @DataProvider(name = "ranges") - Object[][] data_ranges() { + @DataProvider + public static Object[][] data_ranges() { return new Object[][] { // Leap Day and Year Day are members of months {2012, 6, 29, DAY_OF_MONTH, ValueRange.of(1, 29)}, @@ -517,12 +533,13 @@ Object[][] data_ranges() { }; } - @Test(dataProvider = "ranges") + @Test + @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, ValueRange range) { assertEquals(InternationalFixedDate.of(year, month, dom).range(field), range); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_range_unsupported() { InternationalFixedDate.of(2012, 6, 28).range(MINUTE_OF_DAY); } @@ -530,8 +547,8 @@ public void test_range_unsupported() { //----------------------------------------------------------------------- // InternationalFixedDate.getLong //----------------------------------------------------------------------- - @DataProvider(name = "getLong") - Object[][] data_getLong() { + @DataProvider + public static Object[][] data_getLong() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 5}, {2014, 5, 26, DAY_OF_MONTH, 26}, @@ -598,12 +615,13 @@ Object[][] data_getLong() { }; } - @Test(dataProvider = "getLong") + @Test + @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(InternationalFixedDate.of(year, month, dom).getLong(field), expected); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_getLong_unsupported() { InternationalFixedDate.of(2012, 6, 28).getLong(MINUTE_OF_DAY); } @@ -611,8 +629,8 @@ public void test_getLong_unsupported() { //----------------------------------------------------------------------- // InternationalFixedDate.with //----------------------------------------------------------------------- - @DataProvider(name = "with") - Object[][] data_with() { + @DataProvider + public static Object[][] data_with() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 1, 2014, 5, 22}, {2014, 5, 26, DAY_OF_WEEK, 5, 2014, 5, 26}, @@ -745,15 +763,16 @@ Object[][] data_with() { }; } - @Test(dataProvider = "with") + @Test + @UseDataProvider("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(InternationalFixedDate.of(year, month, dom).with(field, value), InternationalFixedDate.of(expectedYear, expectedMonth, expectedDom)); } - @DataProvider(name = "with_bad") - Object[][] data_with_bad() { + @DataProvider + public static Object[][] data_with_bad() { return new Object[][] { {2013, 1, 1, ALIGNED_DAY_OF_WEEK_IN_MONTH, 0}, {2013, 1, 1, ALIGNED_DAY_OF_WEEK_IN_MONTH, 8}, @@ -811,12 +830,13 @@ Object[][] data_with_bad() { }; } - @Test(dataProvider = "with_bad", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_with_bad") public void test_with_TemporalField_badValue(int year, int month, int dom, TemporalField field, long value) { InternationalFixedDate.of(year, month, dom).with(field, value); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_with_TemporalField_unsupported() { InternationalFixedDate.of(2012, 6, 28).with(MINUTE_OF_DAY, 0); } @@ -824,8 +844,8 @@ public void test_with_TemporalField_unsupported() { //----------------------------------------------------------------------- // InternationalFixedDate.with(TemporalAdjuster) //----------------------------------------------------------------------- - @DataProvider(name = "temporalAdjusters_lastDayOfMonth") - Object[][] data_temporalAdjusters_lastDayOfMonth() { + @DataProvider + public static Object[][] data_temporalAdjusters_lastDayOfMonth() { return new Object[][] { {2012, 6, 23, 2012, 6, 29}, {2012, 6, 29, 2012, 6, 29}, @@ -835,7 +855,8 @@ Object[][] data_temporalAdjusters_lastDayOfMonth() { }; } - @Test(dataProvider = "temporalAdjusters_lastDayOfMonth") + @Test + @UseDataProvider("data_temporalAdjusters_lastDayOfMonth") public void test_temporalAdjusters_LastDayOfMonth(int year, int month, int day, int expectedYear, int expectedMonth, int expectedDay) { InternationalFixedDate base = InternationalFixedDate.of(year, month, day); InternationalFixedDate expected = InternationalFixedDate.of(expectedYear, expectedMonth, expectedDay); @@ -853,7 +874,7 @@ public void test_adjust_toLocalDate() { assertEquals(test, InternationalFixedDate.of(2012, 7, 19)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_adjust_toMonth() { InternationalFixedDate fixed = InternationalFixedDate.of(2000, 1, 4); fixed.with(Month.APRIL); @@ -880,8 +901,8 @@ public void test_LocalDateTime_adjustToInternationalFixedDate() { // InternationalFixedDate.plus // InternationalFixedDate.minus //----------------------------------------------------------------------- - @DataProvider(name = "plus") - Object[][] data_plus() { + @DataProvider + public static Object[][] data_plus() { return new Object[][] { {2014, 5, 26, 0, DAYS, 2014, 5, 26}, {2014, 5, 26, 8, DAYS, 2014, 6, 6}, @@ -916,8 +937,8 @@ Object[][] data_plus() { }; } - @DataProvider(name = "plus_leap_and_year_day") - Object[][] data_plus_leap_and_year_day() { + @DataProvider + public static Object[][] data_plus_leap_and_year_day() { return new Object[][] { {2014, 13, 29, 0, DAYS, 2014, 13, 29}, {2014, 13, 29, 8, DAYS, 2015, 1, 8}, @@ -958,8 +979,8 @@ Object[][] data_plus_leap_and_year_day() { }; } - @DataProvider(name = "minus_leap_and_year_day") - Object[][] data_minus_leap_and_year_day() { + @DataProvider + public static Object[][] data_minus_leap_and_year_day() { return new Object[][] { {2014, 13, 29, 0, DAYS, 2014, 13, 29}, {2014, 13, 21, 8, DAYS, 2014, 13, 29}, @@ -1001,21 +1022,24 @@ Object[][] data_minus_leap_and_year_day() { }; } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(InternationalFixedDate.of(year, month, dom).plus(amount, unit), InternationalFixedDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(dataProvider = "plus_leap_and_year_day") + @Test + @UseDataProvider("data_plus_leap_and_year_day") public void test_plus_leap_and_year_day_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(InternationalFixedDate.of(year, month, dom).plus(amount, unit), InternationalFixedDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -1023,7 +1047,8 @@ public void test_minus_TemporalUnit( assertEquals(InternationalFixedDate.of(year, month, dom).minus(amount, unit), InternationalFixedDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(dataProvider = "minus_leap_and_year_day") + @Test + @UseDataProvider("data_minus_leap_and_year_day") public void test_minus_leap_and_year_day_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -1031,7 +1056,7 @@ public void test_minus_leap_and_year_day_TemporalUnit( assertEquals(InternationalFixedDate.of(year, month, dom).minus(amount, unit), InternationalFixedDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_plus_TemporalUnit_unsupported() { InternationalFixedDate.of(2012, 6, 28).plus(0, MINUTES); } @@ -1039,8 +1064,8 @@ public void test_plus_TemporalUnit_unsupported() { //----------------------------------------------------------------------- // InternationalFixedDate.until //----------------------------------------------------------------------- - @DataProvider(name = "until") - Object[][] data_until() { + @DataProvider + public static Object[][] data_until() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, DAYS, 0}, {2014, 5, 26, 2014, 6, 4, DAYS, 6}, @@ -1171,8 +1196,8 @@ Object[][] data_until() { }; } - @DataProvider(name = "until_period") - Object[][] data_until_period() { + @DataProvider + public static Object[][] data_until_period() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, 0, 0, 0}, {2014, 5, 26, 2014, 6, 4, 0, 0, 6}, @@ -1247,7 +1272,8 @@ Object[][] data_until_period() { }; } - @Test(dataProvider = "until") + @Test + @UseDataProvider("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -1257,7 +1283,8 @@ public void test_until_TemporalUnit( assertEquals(start.until(end, unit), expected); } - @Test(dataProvider = "until_period") + @Test + @UseDataProvider("data_until_period") public void test_until_end( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -1268,7 +1295,7 @@ public void test_until_end( assertEquals(start.until(end), period); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_until_TemporalUnit_unsupported() { InternationalFixedDate start = InternationalFixedDate.of(2012, 6, 28); InternationalFixedDate end = InternationalFixedDate.of(2012, 7, 1); @@ -1283,7 +1310,7 @@ public void test_plus_Period() { assertEquals(InternationalFixedDate.of(2014, 5, 26).plus(InternationalFixedChronology.INSTANCE.period(0, 2, 3)), InternationalFixedDate.of(2014, 8, 1)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_plus_Period_ISO() { assertEquals(InternationalFixedDate.of(2014, 5, 26).plus(Period.ofMonths(2)), InternationalFixedDate.of(2014, 7, 26)); } @@ -1293,7 +1320,7 @@ public void test_minus_Period() { assertEquals(InternationalFixedDate.of(2014, 5, 26).minus(InternationalFixedChronology.INSTANCE.period(0, 2, 3)), InternationalFixedDate.of(2014, 3, 23)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_minus_Period_ISO() { assertEquals(InternationalFixedDate.of(2014, 5, 26).minus(Period.ofMonths(2)), InternationalFixedDate.of(2014, 3, 26)); } @@ -1301,8 +1328,8 @@ public void test_minus_Period_ISO() { //----------------------------------------------------------------------- // equals() //----------------------------------------------------------------------- - @DataProvider(name = "equals") - Object[][] data_equals() { + @DataProvider + public static Object[][] data_equals() { return new Object[][] { {InternationalFixedDate.of(2000, 1, 3), InternationalFixedDate.of(2000, 1, 4), InternationalFixedDate.of(2000, 2, 3), InternationalFixedDate.of(2001, 1, 3)}, @@ -1313,8 +1340,10 @@ Object[][] data_equals() { }; } - @Test(dataProvider = "equals") - void test_equals(InternationalFixedDate a1, InternationalFixedDate b, InternationalFixedDate c, InternationalFixedDate d) { + @Test + @UseDataProvider("data_equals") + public void test_equals(InternationalFixedDate a1, InternationalFixedDate b, InternationalFixedDate c, + InternationalFixedDate d) { assertTrue(a1.equals(a1)); assertFalse(a1.equals(b)); assertFalse(a1.equals(c)); @@ -1327,8 +1356,8 @@ void test_equals(InternationalFixedDate a1, InternationalFixedDate b, Internatio //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider(name = "toString") - Object[][] data_toString() { + @DataProvider + public static Object[][] data_toString() { return new Object[][] { {InternationalFixedDate.of(1, 1, 1), "Ifc CE 1/01/01"}, {InternationalFixedDate.of(2012, 6, 23), "Ifc CE 2012/06/23"}, @@ -1339,7 +1368,8 @@ Object[][] data_toString() { }; } - @Test(dataProvider = "toString") + @Test + @UseDataProvider("data_toString") public void test_toString(InternationalFixedDate date, String expected) { assertEquals(date.toString(), expected); } diff --git a/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java b/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java index 22205e0a..7010eac2 100644 --- a/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java @@ -53,7 +53,7 @@ import static java.time.temporal.ChronoUnit.MONTHS; import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; -import static org.testng.Assert.assertEquals; +import static org.junit.Assert.assertEquals; import java.time.DateTimeException; import java.time.LocalDate; @@ -71,14 +71,18 @@ import java.time.temporal.WeekFields; import java.util.List; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test. */ -@Test +@RunWith(DataProviderRunner.class) public class TestJulianChronology { //----------------------------------------------------------------------- @@ -105,8 +109,8 @@ public void test_chronology_of_name_id() { //----------------------------------------------------------------------- // creation, toLocalDate() //----------------------------------------------------------------------- - @DataProvider(name = "samples") - Object[][] data_samples() { + @DataProvider + public static Object[][] data_samples() { return new Object[][] { {JulianDate.of(1, 1, 1), LocalDate.of(0, 12, 30)}, {JulianDate.of(1, 1, 2), LocalDate.of(0, 12, 31)}, @@ -141,47 +145,56 @@ Object[][] data_samples() { }; } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_LocalDate_from_JulianDate(JulianDate julian, LocalDate iso) { assertEquals(LocalDate.from(julian), iso); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_JulianDate_from_LocalDate(JulianDate julian, LocalDate iso) { assertEquals(JulianDate.from(iso), julian); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_JulianDate_chronology_dateEpochDay(JulianDate julian, LocalDate iso) { assertEquals(JulianChronology.INSTANCE.dateEpochDay(iso.toEpochDay()), julian); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_JulianDate_toEpochDay(JulianDate julian, LocalDate iso) { assertEquals(julian.toEpochDay(), iso.toEpochDay()); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_JulianDate_until_JulianDate(JulianDate julian, LocalDate iso) { assertEquals(julian.until(julian), JulianChronology.INSTANCE.period(0, 0, 0)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_JulianDate_until_LocalDate(JulianDate julian, LocalDate iso) { assertEquals(julian.until(iso), JulianChronology.INSTANCE.period(0, 0, 0)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_LocalDate_until_JulianDate(JulianDate julian, LocalDate iso) { assertEquals(iso.until(julian), Period.ZERO); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(JulianDate julian, LocalDate iso) { assertEquals(JulianChronology.INSTANCE.date(iso), julian); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_plusDays(JulianDate julian, LocalDate iso) { assertEquals(LocalDate.from(julian.plus(0, DAYS)), iso); assertEquals(LocalDate.from(julian.plus(1, DAYS)), iso.plusDays(1)); @@ -190,7 +203,8 @@ public void test_plusDays(JulianDate julian, LocalDate iso) { assertEquals(LocalDate.from(julian.plus(-60, DAYS)), iso.plusDays(-60)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_minusDays(JulianDate julian, LocalDate iso) { assertEquals(LocalDate.from(julian.minus(0, DAYS)), iso); assertEquals(LocalDate.from(julian.minus(1, DAYS)), iso.minusDays(1)); @@ -199,7 +213,8 @@ public void test_minusDays(JulianDate julian, LocalDate iso) { assertEquals(LocalDate.from(julian.minus(-60, DAYS)), iso.minusDays(-60)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_until_DAYS(JulianDate julian, LocalDate iso) { assertEquals(julian.until(iso.plusDays(0), DAYS), 0); assertEquals(julian.until(iso.plusDays(1), DAYS), 1); @@ -207,8 +222,8 @@ public void test_until_DAYS(JulianDate julian, LocalDate iso) { assertEquals(julian.until(iso.minusDays(40), DAYS), -40); } - @DataProvider(name = "badDates") - Object[][] data_badDates() { + @DataProvider + public static Object[][] data_badDates() { return new Object[][] { {1900, 0, 0}, @@ -250,12 +265,13 @@ Object[][] data_badDates() { }; } - @Test(dataProvider = "badDates", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_badDates") public void test_badDates(int year, int month, int dom) { JulianDate.of(year, month, dom); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_chronology_dateYearDay_badDate() { JulianChronology.INSTANCE.dateYearDay(2001, 366); } @@ -291,8 +307,8 @@ public void test_isLeapYear_specific() { assertEquals(JulianChronology.INSTANCE.isLeapYear(-6), false); } - @DataProvider(name = "lengthOfMonth") - Object[][] data_lengthOfMonth() { + @DataProvider + public static Object[][] data_lengthOfMonth() { return new Object[][] { {1900, 1, 31}, {1900, 2, 29}, @@ -316,7 +332,8 @@ Object[][] data_lengthOfMonth() { }; } - @Test(dataProvider = "lengthOfMonth") + @Test + @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(JulianDate.of(year, month, 1).lengthOfMonth(), length); } @@ -364,7 +381,7 @@ public void test_prolepticYear_specific() { assertEquals(JulianChronology.INSTANCE.prolepticYear(JulianEra.BC, 4), -3); } - @Test(expectedExceptions = ClassCastException.class) + @Test(expected = ClassCastException.class) public void test_prolepticYear_badEra() { JulianChronology.INSTANCE.prolepticYear(IsoEra.CE, 4); } @@ -375,7 +392,7 @@ public void test_Chronology_eraOf() { assertEquals(JulianChronology.INSTANCE.eraOf(0), JulianEra.BC); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_Chronology_eraOf_invalid() { JulianChronology.INSTANCE.eraOf(2); } @@ -402,8 +419,8 @@ public void test_Chronology_range() { //----------------------------------------------------------------------- // JulianDate.range //----------------------------------------------------------------------- - @DataProvider(name = "ranges") - Object[][] data_ranges() { + @DataProvider + public static Object[][] data_ranges() { return new Object[][] { {2012, 1, 23, DAY_OF_MONTH, 1, 31}, {2012, 2, 23, DAY_OF_MONTH, 1, 29}, @@ -428,12 +445,13 @@ Object[][] data_ranges() { }; } - @Test(dataProvider = "ranges") + @Test + @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(JulianDate.of(year, month, dom).range(field), ValueRange.of(expectedMin, expectedMax)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_range_unsupported() { JulianDate.of(2012, 6, 30).range(MINUTE_OF_DAY); } @@ -441,8 +459,8 @@ public void test_range_unsupported() { //----------------------------------------------------------------------- // JulianDate.getLong //----------------------------------------------------------------------- - @DataProvider(name = "getLong") - Object[][] data_getLong() { + @DataProvider + public static Object[][] data_getLong() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 7}, {2014, 5, 26, DAY_OF_MONTH, 26}, @@ -462,12 +480,13 @@ Object[][] data_getLong() { }; } - @Test(dataProvider = "getLong") + @Test + @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(JulianDate.of(year, month, dom).getLong(field), expected); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_getLong_unsupported() { JulianDate.of(2012, 6, 30).getLong(MINUTE_OF_DAY); } @@ -475,8 +494,8 @@ public void test_getLong_unsupported() { //----------------------------------------------------------------------- // JulianDate.with //----------------------------------------------------------------------- - @DataProvider(name = "with") - Object[][] data_with() { + @DataProvider + public static Object[][] data_with() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 3, 2014, 5, 22}, {2014, 5, 26, DAY_OF_WEEK, 7, 2014, 5, 26}, @@ -512,14 +531,15 @@ Object[][] data_with() { }; } - @Test(dataProvider = "with") + @Test + @UseDataProvider("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(JulianDate.of(year, month, dom).with(field, value), JulianDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_with_TemporalField_unsupported() { JulianDate.of(2012, 6, 30).with(MINUTE_OF_DAY, 0); } @@ -551,7 +571,7 @@ public void test_adjust_toLocalDate() { assertEquals(test, JulianDate.of(2012, 6, 23)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_adjust_toMonth() { JulianDate julian = JulianDate.of(2000, 1, 4); julian.with(Month.APRIL); @@ -577,8 +597,8 @@ public void test_LocalDateTime_adjustToJulianDate() { //----------------------------------------------------------------------- // JulianDate.plus //----------------------------------------------------------------------- - @DataProvider(name = "plus") - Object[][] data_plus() { + @DataProvider + public static Object[][] data_plus() { return new Object[][] { {2014, 5, 26, 0, DAYS, 2014, 5, 26}, {2014, 5, 26, 8, DAYS, 2014, 6, 3}, @@ -605,14 +625,16 @@ Object[][] data_plus() { }; } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(JulianDate.of(year, month, dom).plus(amount, unit), JulianDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -620,7 +642,7 @@ public void test_minus_TemporalUnit( assertEquals(JulianDate.of(year, month, dom).minus(amount, unit), JulianDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_plus_TemporalUnit_unsupported() { JulianDate.of(2012, 6, 30).plus(0, MINUTES); } @@ -628,8 +650,8 @@ public void test_plus_TemporalUnit_unsupported() { //----------------------------------------------------------------------- // JulianDate.until //----------------------------------------------------------------------- - @DataProvider(name = "until") - Object[][] data_until() { + @DataProvider + public static Object[][] data_until() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, DAYS, 0}, {2014, 5, 26, 2014, 6, 1, DAYS, 6}, @@ -657,7 +679,8 @@ Object[][] data_until() { }; } - @Test(dataProvider = "until") + @Test + @UseDataProvider("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -667,7 +690,7 @@ public void test_until_TemporalUnit( assertEquals(start.until(end, unit), expected); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_until_TemporalUnit_unsupported() { JulianDate start = JulianDate.of(2012, 6, 30); JulianDate end = JulianDate.of(2012, 7, 1); @@ -680,7 +703,7 @@ public void test_plus_Period() { assertEquals(JulianDate.of(2014, 5, 26).plus(JulianChronology.INSTANCE.period(0, 2, 3)), JulianDate.of(2014, 7, 29)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_plus_Period_ISO() { assertEquals(JulianDate.of(2014, 5, 26).plus(Period.ofMonths(2)), JulianDate.of(2014, 7, 26)); } @@ -690,7 +713,7 @@ public void test_minus_Period() { assertEquals(JulianDate.of(2014, 5, 26).minus(JulianChronology.INSTANCE.period(0, 2, 3)), JulianDate.of(2014, 3, 23)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_minus_Period_ISO() { assertEquals(JulianDate.of(2014, 5, 26).minus(Period.ofMonths(2)), JulianDate.of(2014, 3, 26)); } @@ -699,7 +722,7 @@ public void test_minus_Period_ISO() { // equals() //----------------------------------------------------------------------- @Test - void test_equals() { + public void test_equals() { JulianDate a1 = JulianDate.of(2000, 1, 3); JulianDate a2 = JulianDate.of(2000, 1, 3); JulianDate b = JulianDate.of(2000, 1, 4); @@ -721,15 +744,16 @@ void test_equals() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider(name = "toString") - Object[][] data_toString() { + @DataProvider + public static Object[][] data_toString() { return new Object[][] { {JulianDate.of(1, 1, 1), "Julian AD 1-01-01"}, {JulianDate.of(2012, 6, 23), "Julian AD 2012-06-23"}, }; } - @Test(dataProvider = "toString") + @Test + @UseDataProvider("data_toString") public void test_toString(JulianDate julian, String expected) { assertEquals(julian.toString(), expected); } diff --git a/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java b/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java index d15a4cdf..f8da0722 100644 --- a/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java @@ -53,7 +53,7 @@ import static java.time.temporal.ChronoUnit.MONTHS; import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; -import static org.testng.Assert.assertEquals; +import static org.junit.Assert.assertEquals; import java.time.DateTimeException; import java.time.LocalDate; @@ -73,15 +73,19 @@ import java.util.List; import java.util.function.Predicate; -import org.testng.Assert; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test. */ -@Test @SuppressWarnings({"static-method", "javadoc"}) +@RunWith(DataProviderRunner.class) public class TestPaxChronology { //----------------------------------------------------------------------- @@ -108,8 +112,8 @@ public void test_chronology_of_name_id() { //----------------------------------------------------------------------- // creation, toLocalDate() //----------------------------------------------------------------------- - @DataProvider(name = "samples") - Object[][] data_samples() { + @DataProvider + public static Object[][] data_samples() { return new Object[][] { {PaxDate.of(1, 1, 1), LocalDate.of(0, 12, 31)}, {PaxDate.of(1, 1, 2), LocalDate.of(1, 1, 1)}, @@ -173,47 +177,56 @@ Object[][] data_samples() { }; } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_LocalDate_from_PaxDate(PaxDate pax, LocalDate iso) { assertEquals(LocalDate.from(pax), iso); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_PaxDate_from_LocalDate(PaxDate pax, LocalDate iso) { assertEquals(PaxDate.from(iso), pax); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_PaxDate_chronology_dateEpochDay(PaxDate pax, LocalDate iso) { assertEquals(PaxChronology.INSTANCE.dateEpochDay(iso.toEpochDay()), pax); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_PaxDate_toEpochDay(PaxDate pax, LocalDate iso) { assertEquals(pax.toEpochDay(), iso.toEpochDay()); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_PaxDate_until_PaxDate(PaxDate pax, LocalDate iso) { assertEquals(pax.until(pax), PaxChronology.INSTANCE.period(0, 0, 0)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_PaxDate_until_LocalDate(PaxDate pax, LocalDate iso) { assertEquals(pax.until(iso), PaxChronology.INSTANCE.period(0, 0, 0)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_LocalDate_until_PaxDate(PaxDate pax, LocalDate iso) { assertEquals(iso.until(pax), Period.ZERO); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(PaxDate pax, LocalDate iso) { assertEquals(PaxChronology.INSTANCE.date(iso), pax); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_plusDays(PaxDate pax, LocalDate iso) { assertEquals(LocalDate.from(pax.plus(0, DAYS)), iso); assertEquals(LocalDate.from(pax.plus(1, DAYS)), iso.plusDays(1)); @@ -222,7 +235,8 @@ public void test_plusDays(PaxDate pax, LocalDate iso) { assertEquals(LocalDate.from(pax.plus(-60, DAYS)), iso.plusDays(-60)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_minusDays(PaxDate pax, LocalDate iso) { assertEquals(LocalDate.from(pax.minus(0, DAYS)), iso); assertEquals(LocalDate.from(pax.minus(1, DAYS)), iso.minusDays(1)); @@ -231,7 +245,8 @@ public void test_minusDays(PaxDate pax, LocalDate iso) { assertEquals(LocalDate.from(pax.minus(-60, DAYS)), iso.minusDays(-60)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_until_DAYS(PaxDate pax, LocalDate iso) { assertEquals(pax.until(iso.plusDays(0), DAYS), 0); assertEquals(pax.until(iso.plusDays(1), DAYS), 1); @@ -239,8 +254,8 @@ public void test_until_DAYS(PaxDate pax, LocalDate iso) { assertEquals(pax.until(iso.minusDays(40), DAYS), -40); } - @DataProvider(name = "badDates") - Object[][] data_badDates() { + @DataProvider + public static Object[][] data_badDates() { return new Object[][] { {1900, 0, 0}, @@ -286,12 +301,13 @@ Object[][] data_badDates() { }; } - @Test(dataProvider = "badDates", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_badDates") public void test_badDates(int year, int month, int dom) { PaxDate.of(year, month, dom); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_chronology_dateYearDay_badDate() { PaxChronology.INSTANCE.dateYearDay(2001, 365); } @@ -307,8 +323,8 @@ public void test_isLeapYear_loop() { }; for (int year = -500; year < 500; year++) { PaxDate base = PaxDate.of(year, 1, 1); - assertEquals(base.isLeapYear(), isLeapYear.test(year), "Year " + year + " is failing"); - assertEquals(PaxChronology.INSTANCE.isLeapYear(year), isLeapYear.test(year), "Year " + year + " is failing"); + assertEquals(base.isLeapYear(), isLeapYear.test(year)); + assertEquals(PaxChronology.INSTANCE.isLeapYear(year), isLeapYear.test(year)); } } @@ -336,8 +352,8 @@ public void test_isLeapYear_specific() { assertEquals(PaxChronology.INSTANCE.isLeapYear(-400), false); } - @DataProvider(name = "lengthOfMonth") - Object[][] data_lengthOfMonth() { + @DataProvider + public static Object[][] data_lengthOfMonth() { return new Object[][] { {1900, 1, 28}, {1900, 2, 28}, @@ -365,7 +381,8 @@ Object[][] data_lengthOfMonth() { }; } - @Test(dataProvider = "lengthOfMonth") + @Test + @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(PaxDate.of(year, month, 1).lengthOfMonth(), length); } @@ -413,7 +430,7 @@ public void test_prolepticYear_specific() { assertEquals(PaxChronology.INSTANCE.prolepticYear(PaxEra.BCE, 4), -3); } - @Test(expectedExceptions = ClassCastException.class) + @Test(expected = ClassCastException.class) public void test_prolepticYear_badEra() { PaxChronology.INSTANCE.prolepticYear(IsoEra.CE, 4); } @@ -424,7 +441,7 @@ public void test_Chronology_eraOf() { assertEquals(PaxChronology.INSTANCE.eraOf(0), PaxEra.BCE); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_Chronology_eraOf_invalid() { PaxChronology.INSTANCE.eraOf(2); } @@ -451,8 +468,8 @@ public void test_Chronology_range() { //----------------------------------------------------------------------- // PaxDate.range //----------------------------------------------------------------------- - @DataProvider(name = "ranges") - Object[][] data_ranges() { + @DataProvider + public static Object[][] data_ranges() { return new Object[][] { {2012, 1, 23, DAY_OF_MONTH, 1, 28}, {2012, 2, 23, DAY_OF_MONTH, 1, 28}, @@ -483,12 +500,13 @@ Object[][] data_ranges() { }; } - @Test(dataProvider = "ranges") + @Test + @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(PaxDate.of(year, month, dom).range(field), ValueRange.of(expectedMin, expectedMax)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_range_unsupported() { PaxDate.of(2012, 6, 28).range(MINUTE_OF_DAY); } @@ -496,8 +514,8 @@ public void test_range_unsupported() { //----------------------------------------------------------------------- // PaxDate.getLong //----------------------------------------------------------------------- - @DataProvider(name = "getLong") - Object[][] data_getLong() { + @DataProvider + public static Object[][] data_getLong() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 4}, {2014, 5, 26, DAY_OF_MONTH, 26}, @@ -517,12 +535,13 @@ Object[][] data_getLong() { }; } - @Test(dataProvider = "getLong") + @Test + @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(PaxDate.of(year, month, dom).getLong(field), expected); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_getLong_unsupported() { PaxDate.of(2012, 6, 28).getLong(MINUTE_OF_DAY); } @@ -530,8 +549,8 @@ public void test_getLong_unsupported() { //----------------------------------------------------------------------- // PaxDate.with //----------------------------------------------------------------------- - @DataProvider(name = "with") - Object[][] data_with() { + @DataProvider + public static Object[][] data_with() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 3, 2014, 5, 25}, {2014, 5, 26, DAY_OF_WEEK, 4, 2014, 5, 26}, @@ -567,14 +586,15 @@ Object[][] data_with() { }; } - @Test(dataProvider = "with") + @Test + @UseDataProvider("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(PaxDate.of(year, month, dom).with(field, value), PaxDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_with_TemporalField_unsupported() { PaxDate.of(2012, 6, 28).with(MINUTE_OF_DAY, 0); } @@ -606,7 +626,7 @@ public void test_adjust_toLocalDate() { assertEquals(test, PaxDate.of(2012, 7, 27)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_adjust_toMonth() { PaxDate pax = PaxDate.of(2000, 1, 4); pax.with(Month.APRIL); @@ -632,8 +652,8 @@ public void test_LocalDateTime_adjustToPaxDate() { //----------------------------------------------------------------------- // PaxDate.plus //----------------------------------------------------------------------- - @DataProvider(name = "plus") - Object[][] data_plus() { + @DataProvider + public static Object[][] data_plus() { return new Object[][] { {2014, 5, 26, 0, DAYS, 2014, 5, 26}, {2014, 5, 26, 8, DAYS, 2014, 6, 6}, @@ -670,8 +690,8 @@ Object[][] data_plus() { }; } - @DataProvider(name = "plusLeap") - Object[][] data_plus_leap() { + @DataProvider + public static Object[][] data_plus_leap() { return new Object[][] { {2012, 12, 26, 1, MONTHS, 2012, 13, 7}, {2012, 14, 26, -1, MONTHS, 2012, 13, 7}, @@ -679,8 +699,8 @@ Object[][] data_plus_leap() { }; } - @DataProvider(name = "minusLeap") - Object[][] data_minus_leap() { + @DataProvider + public static Object[][] data_minus_leap() { return new Object[][] { {2012, 13, 7, -1, MONTHS, 2012, 12, 26}, {2012, 13, 7, 1, MONTHS, 2012, 14, 26}, @@ -688,21 +708,24 @@ Object[][] data_minus_leap() { }; } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(PaxDate.of(year, month, dom).plus(amount, unit), PaxDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(dataProvider = "plusLeap") + @Test + @UseDataProvider("data_plus_leap") public void test_plus_leap_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { test_plus_TemporalUnit(year, month, dom, amount, unit, expectedYear, expectedMonth, expectedDom); } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -710,14 +733,15 @@ public void test_minus_TemporalUnit( assertEquals(PaxDate.of(year, month, dom).minus(amount, unit), PaxDate.of(expectedYear, expectedMonth, expectedDom)); } - @Test(dataProvider = "minusLeap") + @Test + @UseDataProvider("data_minus_leap") public void test_minus_leap_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { test_minus_TemporalUnit(year, month, dom, amount, unit, expectedYear, expectedMonth, expectedDom); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_plus_TemporalUnit_unsupported() { PaxDate.of(2012, 6, 10).plus(0, MINUTES); } @@ -725,8 +749,8 @@ public void test_plus_TemporalUnit_unsupported() { //----------------------------------------------------------------------- // PaxDate.until //----------------------------------------------------------------------- - @DataProvider(name = "until") - Object[][] data_until() { + @DataProvider + public static Object[][] data_until() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, DAYS, 0}, {2014, 5, 26, 2014, 6, 4, DAYS, 6}, @@ -767,8 +791,8 @@ Object[][] data_until() { }; } - @DataProvider(name = "until_period") - Object[][] data_until_period() { + @DataProvider + public static Object[][] data_until_period() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, 0, 0, 0}, {2014, 5, 26, 2014, 6, 4, 0, 0, 6}, @@ -795,7 +819,8 @@ Object[][] data_until_period() { }; } - @Test(dataProvider = "until") + @Test + @UseDataProvider("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -805,7 +830,8 @@ public void test_until_TemporalUnit( assertEquals(start.until(end, unit), expected); } - @Test(dataProvider = "until_period") + @Test + @UseDataProvider("data_until_period") public void test_until_end( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -816,7 +842,7 @@ public void test_until_end( assertEquals(start.until(end), period); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_until_TemporalUnit_unsupported() { PaxDate start = PaxDate.of(2012, 6, 28); PaxDate end = PaxDate.of(2012, 7, 1); @@ -829,7 +855,7 @@ public void test_plus_Period() { assertEquals(PaxDate.of(2014, 5, 26).plus(PaxChronology.INSTANCE.period(0, 2, 2)), PaxDate.of(2014, 7, 28)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_plus_Period_ISO() { assertEquals(PaxDate.of(2014, 5, 26).plus(Period.ofMonths(2)), PaxDate.of(2014, 7, 26)); } @@ -839,7 +865,7 @@ public void test_minus_Period() { assertEquals(PaxDate.of(2014, 5, 26).minus(PaxChronology.INSTANCE.period(0, 2, 3)), PaxDate.of(2014, 3, 23)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_minus_Period_ISO() { assertEquals(PaxDate.of(2014, 5, 26).minus(Period.ofMonths(2)), PaxDate.of(2014, 3, 26)); } @@ -848,7 +874,7 @@ public void test_minus_Period_ISO() { // equals() //----------------------------------------------------------------------- @Test - void test_equals() { + public void test_equals() { PaxDate a1 = PaxDate.of(2000, 1, 3); PaxDate a2 = PaxDate.of(2000, 1, 3); PaxDate b = PaxDate.of(2000, 1, 4); @@ -870,15 +896,16 @@ void test_equals() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider(name = "toString") - Object[][] data_toString() { + @DataProvider + public static Object[][] data_toString() { return new Object[][] { {PaxDate.of(1, 1, 1), "Pax CE 1-01-01"}, {PaxDate.of(2012, 6, 23), "Pax CE 2012-06-23"}, }; } - @Test(dataProvider = "toString") + @Test + @UseDataProvider("data_toString") public void test_toString(PaxDate pax, String expected) { assertEquals(pax.toString(), expected); } diff --git a/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java b/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java index fda786b1..ac6ac7b1 100644 --- a/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java @@ -31,67 +31,67 @@ */ package org.threeten.extra.chrono; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; + +import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH; +import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR; +import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH; +import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR; +import static java.time.temporal.ChronoField.DAY_OF_MONTH; +import static java.time.temporal.ChronoField.DAY_OF_WEEK; +import static java.time.temporal.ChronoField.DAY_OF_YEAR; +import static java.time.temporal.ChronoField.EPOCH_DAY; +import static java.time.temporal.ChronoField.ERA; +import static java.time.temporal.ChronoField.MINUTE_OF_DAY; +import static java.time.temporal.ChronoField.MONTH_OF_YEAR; +import static java.time.temporal.ChronoField.PROLEPTIC_MONTH; +import static java.time.temporal.ChronoField.YEAR; +import static java.time.temporal.ChronoField.YEAR_OF_ERA; +import static java.time.temporal.ChronoUnit.CENTURIES; +import static java.time.temporal.ChronoUnit.DAYS; +import static java.time.temporal.ChronoUnit.DECADES; +import static java.time.temporal.ChronoUnit.ERAS; +import static java.time.temporal.ChronoUnit.MILLENNIA; +import static java.time.temporal.ChronoUnit.MINUTES; +import static java.time.temporal.ChronoUnit.MONTHS; +import static java.time.temporal.ChronoUnit.WEEKS; +import static java.time.temporal.ChronoUnit.YEARS; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.Month; import java.time.Period; - -import java.time.chrono.Chronology; import java.time.chrono.ChronoPeriod; +import java.time.chrono.Chronology; import java.time.chrono.Era; import java.time.chrono.HijrahEra; import java.time.chrono.IsoEra; import java.time.chrono.JapaneseEra; import java.time.chrono.MinguoEra; import java.time.chrono.ThaiBuddhistEra; - import java.time.temporal.TemporalAdjusters; import java.time.temporal.TemporalField; import java.time.temporal.TemporalUnit; -import java.time.temporal.ValueRange; import java.time.temporal.UnsupportedTemporalTypeException; - +import java.time.temporal.ValueRange; import java.util.List; -import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH; -import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR; -import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH; -import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR; -import static java.time.temporal.ChronoField.DAY_OF_MONTH; -import static java.time.temporal.ChronoField.DAY_OF_WEEK; -import static java.time.temporal.ChronoField.DAY_OF_YEAR; -import static java.time.temporal.ChronoField.EPOCH_DAY; -import static java.time.temporal.ChronoField.ERA; -import static java.time.temporal.ChronoField.MONTH_OF_YEAR; -import static java.time.temporal.ChronoField.PROLEPTIC_MONTH; -import static java.time.temporal.ChronoField.YEAR_OF_ERA; -import static java.time.temporal.ChronoField.YEAR; -import static java.time.temporal.ChronoField.MINUTE_OF_DAY; - -import static java.time.temporal.ChronoUnit.DAYS; -import static java.time.temporal.ChronoUnit.ERAS; -import static java.time.temporal.ChronoUnit.MONTHS; -import static java.time.temporal.ChronoUnit.WEEKS; -import static java.time.temporal.ChronoUnit.YEARS; -import static java.time.temporal.ChronoUnit.DECADES; -import static java.time.temporal.ChronoUnit.CENTURIES; -import static java.time.temporal.ChronoUnit.MILLENNIA; -import static java.time.temporal.ChronoUnit.MINUTES; +import org.junit.Test; +import org.junit.runner.RunWith; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test. */ -@Test @SuppressWarnings({"static-method", "javadoc"}) +@RunWith(DataProviderRunner.class) public class TestSymmetry010Chronology { //----------------------------------------------------------------------- @@ -109,8 +109,8 @@ public void test_chronology() { //----------------------------------------------------------------------- // Symmetry010Date.of //----------------------------------------------------------------------- - @DataProvider(name = "samples") - Object[][] data_samples() { + @DataProvider + public static Object[][] data_samples() { return new Object[][] { { Symmetry010Date.of( 1, 1, 1), LocalDate.of( 1, 1, 1) }, { Symmetry010Date.of( 272, 2, 28), LocalDate.of( 272, 2, 27) }, // Constantine the Great, Roman emperor (d. 337) @@ -146,47 +146,56 @@ Object[][] data_samples() { }; } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_LocalDate_from_Symmetry010Date(Symmetry010Date sym010, LocalDate iso) { assertEquals(LocalDate.from(sym010), iso); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_Symmetry010Date_from_LocalDate(Symmetry010Date sym010, LocalDate iso) { assertEquals(Symmetry010Date.from(iso), sym010); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_Symmetry010Date_chronology_dateEpochDay(Symmetry010Date sym010, LocalDate iso) { assertEquals(Symmetry010Chronology.INSTANCE.dateEpochDay(iso.toEpochDay()), sym010); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_Symmetry010Date_toEpochDay(Symmetry010Date sym010, LocalDate iso) { assertEquals(sym010.toEpochDay(), iso.toEpochDay()); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_Symmetry010Date_until_Symmetry010Date(Symmetry010Date sym010, LocalDate iso) { assertEquals(sym010.until(sym010), Symmetry010Chronology.INSTANCE.period(0, 0, 0)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_Symmetry010Date_until_LocalDate(Symmetry010Date sym010, LocalDate iso) { assertEquals(sym010.until(iso), Symmetry010Chronology.INSTANCE.period(0, 0, 0)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(Symmetry010Date sym010, LocalDate iso) { assertEquals(Symmetry010Chronology.INSTANCE.date(iso), sym010); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_LocalDate_until_Symmetry010Date(Symmetry010Date sym010, LocalDate iso) { assertEquals(iso.until(sym010), Period.ZERO); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_plusDays(Symmetry010Date sym010, LocalDate iso) { assertEquals(LocalDate.from(sym010.plus(0, DAYS)), iso); assertEquals(LocalDate.from(sym010.plus(1, DAYS)), iso.plusDays(1)); @@ -195,7 +204,8 @@ public void test_plusDays(Symmetry010Date sym010, LocalDate iso) { assertEquals(LocalDate.from(sym010.plus(-60, DAYS)), iso.plusDays(-60)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_minusDays(Symmetry010Date sym010, LocalDate iso) { assertEquals(LocalDate.from(sym010.minus(0, DAYS)), iso); assertEquals(LocalDate.from(sym010.minus(1, DAYS)), iso.minusDays(1)); @@ -204,7 +214,8 @@ public void test_minusDays(Symmetry010Date sym010, LocalDate iso) { assertEquals(LocalDate.from(sym010.minus(-60, DAYS)), iso.minusDays(-60)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_until_DAYS(Symmetry010Date sym010, LocalDate iso) { assertEquals(sym010.until(iso.plusDays(0), DAYS), 0); assertEquals(sym010.until(iso.plusDays(1), DAYS), 1); @@ -212,8 +223,8 @@ public void test_until_DAYS(Symmetry010Date sym010, LocalDate iso) { assertEquals(sym010.until(iso.minusDays(40), DAYS), -40); } - @DataProvider(name = "badDates") - Object[][] data_badDates() { + @DataProvider + public static Object[][] data_badDates() { return new Object[][] { {-1, 13, 28}, {-1, 13, 29}, @@ -245,13 +256,14 @@ Object[][] data_badDates() { }; } - @Test(dataProvider = "badDates", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_badDates") public void test_badDates(int year, int month, int dom) { Symmetry010Date.of(year, month, dom); } - @DataProvider(name = "badLeapDates") - Object[][] data_badLeapDates() { + @DataProvider + public static Object[][] data_badLeapDates() { return new Object[][] { {1}, {100}, @@ -260,7 +272,8 @@ Object[][] data_badLeapDates() { }; } - @Test(dataProvider = "badLeapDates", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_badLeapDates") public void badLeapDayDates(int year) { Symmetry010Date.of(year, 12, 37); } @@ -281,7 +294,7 @@ public void test_isLeapYear_specific() { // Symmetry010Date.isLeapWeek //----------------------------------------------------------------------- @Test - void test_leapWeek() { + public void test_leapWeek() { assertTrue(Symmetry010Date.of (2015, 12, 31).isLeapWeek()); assertTrue(Symmetry010Date.of (2015, 12, 32).isLeapWeek()); assertTrue(Symmetry010Date.of (2015, 12, 33).isLeapWeek()); @@ -294,8 +307,8 @@ void test_leapWeek() { //----------------------------------------------------------------------- // Symmetry010Date.lengthOfMonth //----------------------------------------------------------------------- - @DataProvider(name = "lengthOfMonth") - Object[][] data_lengthOfMonth() { + @DataProvider + public static Object[][] data_lengthOfMonth() { return new Object[][] { {2000, 1, 28, 30}, {2000, 2, 28, 31}, @@ -313,12 +326,14 @@ Object[][] data_lengthOfMonth() { }; } - @Test(dataProvider = "lengthOfMonth") + @Test + @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int day, int length) { assertEquals(Symmetry010Date.of(year, month, day).lengthOfMonth(), length); } - @Test(dataProvider = "lengthOfMonth") + @Test + @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonthFirst(int year, int month, int day, int length) { assertEquals(Symmetry010Date.of(year, month, 1).lengthOfMonth(), length); } @@ -380,8 +395,8 @@ public void test_prolepticYear_specific() { assertEquals(Symmetry010Chronology.INSTANCE.prolepticYear(IsoEra.CE, 1582), 1582); } - @DataProvider(name = "prolepticYearBadEra") - Object[][] data_prolepticYear_badEra() { + @DataProvider + public static Object[][] data_prolepticYear_badEra() { return new Era[][] { { AccountingEra.BCE }, { AccountingEra.CE }, @@ -407,7 +422,8 @@ Object[][] data_prolepticYear_badEra() { }; } - @Test(dataProvider = "prolepticYearBadEra", expectedExceptions = ClassCastException.class) + @Test(expected = ClassCastException.class) + @UseDataProvider("data_prolepticYear_badEra") public void test_prolepticYear_badEra(Era era) { Symmetry010Chronology.INSTANCE.prolepticYear(era, 4); } @@ -418,7 +434,7 @@ public void test_Chronology_eraOf() { assertEquals(Symmetry010Chronology.INSTANCE.eraOf(1), IsoEra.CE); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_Chronology_eraOf_invalid() { Symmetry010Chronology.INSTANCE.eraOf(2); } @@ -454,8 +470,8 @@ public void test_Chronology_range() { //----------------------------------------------------------------------- // Symmetry010Date.range //----------------------------------------------------------------------- - @DataProvider(name = "ranges") - Object[][] data_ranges() { + @DataProvider + public static Object[][] data_ranges() { return new Object[][] { // Leap Day and Year Day are members of months {2012, 1, 23, DAY_OF_MONTH, ValueRange.of(1, 30)}, @@ -500,12 +516,13 @@ Object[][] data_ranges() { }; } - @Test(dataProvider = "ranges") + @Test + @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, ValueRange range) { assertEquals(Symmetry010Date.of(year, month, dom).range(field), range); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_range_unsupported() { Symmetry010Date.of(2012, 6, 28).range(MINUTE_OF_DAY); } @@ -513,8 +530,8 @@ public void test_range_unsupported() { //----------------------------------------------------------------------- // Symmetry010Date.getLong //----------------------------------------------------------------------- - @DataProvider(name = "getLong") - Object[][] data_getLong() { + @DataProvider + public static Object[][] data_getLong() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 2}, {2014, 5, 26, DAY_OF_MONTH, 26}, @@ -548,12 +565,13 @@ Object[][] data_getLong() { }; } - @Test(dataProvider = "getLong") + @Test + @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(Symmetry010Date.of(year, month, dom).getLong(field), expected); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_getLong_unsupported() { Symmetry010Date.of(2012, 6, 28).getLong(MINUTE_OF_DAY); } @@ -561,8 +579,8 @@ public void test_getLong_unsupported() { //----------------------------------------------------------------------- // Symmetry010Date.with //----------------------------------------------------------------------- - @DataProvider(name = "with") - Object[][] data_with() { + @DataProvider + public static Object[][] data_with() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 1, 2014, 5, 20}, {2014, 5, 26, DAY_OF_WEEK, 5, 2014, 5, 24}, @@ -637,15 +655,16 @@ Object[][] data_with() { }; } - @Test(dataProvider = "with") + @Test + @UseDataProvider("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(Symmetry010Date.of(year, month, dom).with(field, value), Symmetry010Date.of(expectedYear, expectedMonth, expectedDom)); } - @DataProvider(name = "with_bad") - Object[][] data_with_bad() { + @DataProvider + public static Object[][] data_with_bad() { return new Object[][] { {2013, 1, 1, ALIGNED_DAY_OF_WEEK_IN_MONTH, -1}, {2013, 1, 1, ALIGNED_DAY_OF_WEEK_IN_MONTH, 8}, @@ -683,12 +702,13 @@ Object[][] data_with_bad() { }; } - @Test(dataProvider = "with_bad", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_with_bad") public void test_with_TemporalField_badValue(int year, int month, int dom, TemporalField field, long value) { Symmetry010Date.of(year, month, dom).with(field, value); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_with_TemporalField_unsupported() { Symmetry010Date.of(2012, 6, 28).with(MINUTE_OF_DAY, 10); } @@ -696,8 +716,8 @@ public void test_with_TemporalField_unsupported() { //----------------------------------------------------------------------- // Symmetry010Date.with(TemporalAdjuster) //----------------------------------------------------------------------- - @DataProvider(name = "temporalAdjusters_lastDayOfMonth") - Object[][] data_temporalAdjusters_lastDayOfMonth() { + @DataProvider + public static Object[][] data_temporalAdjusters_lastDayOfMonth() { return new Object[][] { {2012, 1, 23, 2012, 1, 30}, {2012, 2, 23, 2012, 2, 31}, @@ -715,7 +735,8 @@ Object[][] data_temporalAdjusters_lastDayOfMonth() { }; } - @Test(dataProvider = "temporalAdjusters_lastDayOfMonth") + @Test + @UseDataProvider("data_temporalAdjusters_lastDayOfMonth") public void test_temporalAdjusters_LastDayOfMonth(int year, int month, int day, int expectedYear, int expectedMonth, int expectedDay) { Symmetry010Date base = Symmetry010Date.of(year, month, day); Symmetry010Date expected = Symmetry010Date.of(expectedYear, expectedMonth, expectedDay); @@ -733,7 +754,7 @@ public void test_adjust_toLocalDate() { assertEquals(test, Symmetry010Date.of(2012, 7, 5)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_adjust_toMonth() { Symmetry010Date sym010 = Symmetry010Date.of(2000, 1, 4); sym010.with(Month.APRIL); @@ -760,8 +781,8 @@ public void test_LocalDateTime_adjustToSymmetry010Date() { // Symmetry010Date.plus // Symmetry010Date.minus //----------------------------------------------------------------------- - @DataProvider(name = "plus") - Object[][] data_plus() { + @DataProvider + public static Object[][] data_plus() { return new Object[][] { {2014, 5, 26, 0, DAYS, 2014, 5, 26}, {2014, 5, 26, 8, DAYS, 2014, 6, 3}, @@ -796,8 +817,8 @@ Object[][] data_plus() { }; } - @DataProvider(name = "plus_leapWeek") - Object[][] data_plus_leapWeek() { + @DataProvider + public static Object[][] data_plus_leapWeek() { return new Object[][] { {2015, 12, 28, 0, DAYS, 2015, 12, 28}, {2015, 12, 28, 8, DAYS, 2015, 12, 36}, @@ -816,21 +837,24 @@ Object[][] data_plus_leapWeek() { }; } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(Symmetry010Date.of(year, month, dom).plus(amount, unit), Symmetry010Date.of(expectedYear, expectedMonth, expectedDom)); } - @Test(dataProvider = "plus_leapWeek") + @Test + @UseDataProvider("data_plus_leapWeek") public void test_plus_leapWeek_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(Symmetry010Date.of(year, month, dom).plus(amount, unit), Symmetry010Date.of(expectedYear, expectedMonth, expectedDom)); } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -838,7 +862,8 @@ public void test_minus_TemporalUnit( assertEquals(Symmetry010Date.of(year, month, dom).minus(amount, unit), Symmetry010Date.of(expectedYear, expectedMonth, expectedDom)); } - @Test(dataProvider = "plus_leapWeek") + @Test + @UseDataProvider("data_plus_leapWeek") public void test_minus_leapWeek_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -846,7 +871,7 @@ public void test_minus_leapWeek_TemporalUnit( assertEquals(Symmetry010Date.of(year, month, dom).minus(amount, unit), Symmetry010Date.of(expectedYear, expectedMonth, expectedDom)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_plus_TemporalUnit_unsupported() { Symmetry010Date.of(2012, 6, 28).plus(0, MINUTES); } @@ -854,8 +879,8 @@ public void test_plus_TemporalUnit_unsupported() { //----------------------------------------------------------------------- // Symmetry010Date.until //----------------------------------------------------------------------- - @DataProvider(name = "until") - Object[][] data_until() { + @DataProvider + public static Object[][] data_until() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, DAYS, 0}, {2014, 5, 26, 2014, 6, 4, DAYS, 9}, @@ -882,8 +907,8 @@ Object[][] data_until() { }; } - @DataProvider(name = "until_period") - Object[][] data_until_period() { + @DataProvider + public static Object[][] data_until_period() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, 0, 0, 0}, {2014, 5, 26, 2014, 6, 4, 0, 0, 9}, @@ -897,7 +922,8 @@ Object[][] data_until_period() { }; } - @Test(dataProvider = "until") + @Test + @UseDataProvider("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -907,7 +933,8 @@ public void test_until_TemporalUnit( assertEquals(start.until(end, unit), expected); } - @Test(dataProvider = "until_period") + @Test + @UseDataProvider("data_until_period") public void test_until_end( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -918,7 +945,7 @@ public void test_until_end( assertEquals(start.until(end), period); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_until_TemporalUnit_unsupported() { Symmetry010Date start = Symmetry010Date.of(2012, 6, 28); Symmetry010Date end = Symmetry010Date.of(2012, 7, 1); @@ -934,7 +961,7 @@ public void test_plus_Period() { Symmetry010Date.of(2014, 7, 29)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_plus_Period_ISO() { assertEquals(Symmetry010Date.of(2014, 5, 26).plus(Period.ofMonths(2)), Symmetry010Date.of(2014, 7, 26)); @@ -946,7 +973,7 @@ public void test_minus_Period() { Symmetry010Date.of(2014, 3, 23)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_minus_Period_ISO() { assertEquals(Symmetry010Date.of(2014, 5, 26).minus(Period.ofMonths(2)), Symmetry010Date.of(2014, 3, 26)); } @@ -954,8 +981,8 @@ public void test_minus_Period_ISO() { //----------------------------------------------------------------------- // Symmetry010Date.equals //----------------------------------------------------------------------- - @DataProvider(name = "equals") - Object[][] data_equals() { + @DataProvider + public static Object[][] data_equals() { return new Object[][] { {Symmetry010Date.of(2000, 1, 3), Symmetry010Date.of(2000, 1, 4), Symmetry010Date.of(2000, 2, 3), Symmetry010Date.of(2001, 1, 3)}, {Symmetry010Date.of(2000, 12, 28), Symmetry010Date.of(2000, 12, 25), Symmetry010Date.of(2001, 1, 1), Symmetry010Date.of(2001, 12, 28)}, @@ -963,8 +990,9 @@ Object[][] data_equals() { }; } - @Test(dataProvider = "equals") - void test_equals(Symmetry010Date a1, Symmetry010Date b, Symmetry010Date c, Symmetry010Date d) { + @Test + @UseDataProvider("data_equals") + public void test_equals(Symmetry010Date a1, Symmetry010Date b, Symmetry010Date c, Symmetry010Date d) { assertTrue(a1.equals(a1)); assertFalse(a1.equals(b)); assertFalse(a1.equals(c)); @@ -977,8 +1005,8 @@ void test_equals(Symmetry010Date a1, Symmetry010Date b, Symmetry010Date c, Symme //----------------------------------------------------------------------- // Symmetry010Date.toString //----------------------------------------------------------------------- - @DataProvider(name = "toString") - Object[][] data_toString() { + @DataProvider + public static Object[][] data_toString() { return new Object[][] { {Symmetry010Date.of( 1, 1, 1), "Sym010 CE 1/01/01"}, {Symmetry010Date.of(1970, 2, 31), "Sym010 CE 1970/02/31"}, @@ -987,7 +1015,8 @@ Object[][] data_toString() { }; } - @Test(dataProvider = "toString") + @Test + @UseDataProvider("data_toString") public void test_toString(Symmetry010Date date, String expected) { assertEquals(date.toString(), expected); } diff --git a/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java b/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java index bac82cf1..4ab8799e 100644 --- a/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java @@ -31,67 +31,67 @@ */ package org.threeten.extra.chrono; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; + +import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH; +import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR; +import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH; +import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR; +import static java.time.temporal.ChronoField.DAY_OF_MONTH; +import static java.time.temporal.ChronoField.DAY_OF_WEEK; +import static java.time.temporal.ChronoField.DAY_OF_YEAR; +import static java.time.temporal.ChronoField.EPOCH_DAY; +import static java.time.temporal.ChronoField.ERA; +import static java.time.temporal.ChronoField.MINUTE_OF_DAY; +import static java.time.temporal.ChronoField.MONTH_OF_YEAR; +import static java.time.temporal.ChronoField.PROLEPTIC_MONTH; +import static java.time.temporal.ChronoField.YEAR; +import static java.time.temporal.ChronoField.YEAR_OF_ERA; +import static java.time.temporal.ChronoUnit.CENTURIES; +import static java.time.temporal.ChronoUnit.DAYS; +import static java.time.temporal.ChronoUnit.DECADES; +import static java.time.temporal.ChronoUnit.ERAS; +import static java.time.temporal.ChronoUnit.MILLENNIA; +import static java.time.temporal.ChronoUnit.MINUTES; +import static java.time.temporal.ChronoUnit.MONTHS; +import static java.time.temporal.ChronoUnit.WEEKS; +import static java.time.temporal.ChronoUnit.YEARS; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.Month; import java.time.Period; - -import java.time.chrono.Chronology; import java.time.chrono.ChronoPeriod; +import java.time.chrono.Chronology; import java.time.chrono.Era; import java.time.chrono.HijrahEra; import java.time.chrono.IsoEra; import java.time.chrono.JapaneseEra; import java.time.chrono.MinguoEra; import java.time.chrono.ThaiBuddhistEra; - import java.time.temporal.TemporalAdjusters; import java.time.temporal.TemporalField; import java.time.temporal.TemporalUnit; -import java.time.temporal.ValueRange; import java.time.temporal.UnsupportedTemporalTypeException; - +import java.time.temporal.ValueRange; import java.util.List; -import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH; -import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR; -import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH; -import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR; -import static java.time.temporal.ChronoField.DAY_OF_MONTH; -import static java.time.temporal.ChronoField.DAY_OF_WEEK; -import static java.time.temporal.ChronoField.DAY_OF_YEAR; -import static java.time.temporal.ChronoField.EPOCH_DAY; -import static java.time.temporal.ChronoField.ERA; -import static java.time.temporal.ChronoField.MONTH_OF_YEAR; -import static java.time.temporal.ChronoField.PROLEPTIC_MONTH; -import static java.time.temporal.ChronoField.YEAR_OF_ERA; -import static java.time.temporal.ChronoField.YEAR; -import static java.time.temporal.ChronoField.MINUTE_OF_DAY; - -import static java.time.temporal.ChronoUnit.DAYS; -import static java.time.temporal.ChronoUnit.ERAS; -import static java.time.temporal.ChronoUnit.MONTHS; -import static java.time.temporal.ChronoUnit.WEEKS; -import static java.time.temporal.ChronoUnit.YEARS; -import static java.time.temporal.ChronoUnit.DECADES; -import static java.time.temporal.ChronoUnit.CENTURIES; -import static java.time.temporal.ChronoUnit.MILLENNIA; -import static java.time.temporal.ChronoUnit.MINUTES; +import org.junit.Test; +import org.junit.runner.RunWith; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test. */ -@Test @SuppressWarnings({"static-method", "javadoc"}) +@RunWith(DataProviderRunner.class) public class TestSymmetry454Chronology { //----------------------------------------------------------------------- @@ -109,8 +109,8 @@ public void test_chronology() { //----------------------------------------------------------------------- // Symmetry454Date.of //----------------------------------------------------------------------- - @DataProvider(name = "samples") - Object[][] data_samples() { + @DataProvider + public static Object[][] data_samples() { return new Object[][] { { Symmetry454Date.of( 1, 1, 1), LocalDate.of( 1, 1, 1) }, { Symmetry454Date.of( 272, 2, 30), LocalDate.of( 272, 2, 27) }, // Constantine the Great, Roman emperor (d. 337) @@ -146,47 +146,56 @@ Object[][] data_samples() { }; } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_LocalDate_from_Symmetry454Date(Symmetry454Date sym454, LocalDate iso) { assertEquals(LocalDate.from(sym454), iso); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_Symmetry454Date_from_LocalDate(Symmetry454Date sym454, LocalDate iso) { assertEquals(Symmetry454Date.from(iso), sym454); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_Symmetry454Date_chronology_dateEpochDay(Symmetry454Date sym454, LocalDate iso) { assertEquals(Symmetry454Chronology.INSTANCE.dateEpochDay(iso.toEpochDay()), sym454); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_Symmetry454Date_toEpochDay(Symmetry454Date sym454, LocalDate iso) { assertEquals(sym454.toEpochDay(), iso.toEpochDay()); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_Symmetry454Date_until_Symmetry454Date(Symmetry454Date sym454, LocalDate iso) { assertEquals(sym454.until(sym454), Symmetry454Chronology.INSTANCE.period(0, 0, 0)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_Symmetry454Date_until_LocalDate(Symmetry454Date sym454, LocalDate iso) { assertEquals(sym454.until(iso), Symmetry454Chronology.INSTANCE.period(0, 0, 0)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(Symmetry454Date sym454, LocalDate iso) { assertEquals(Symmetry454Chronology.INSTANCE.date(iso), sym454); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_LocalDate_until_Symmetry454Date(Symmetry454Date sym454, LocalDate iso) { assertEquals(iso.until(sym454), Period.ZERO); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_plusDays(Symmetry454Date sym454, LocalDate iso) { assertEquals(LocalDate.from(sym454.plus(0, DAYS)), iso); assertEquals(LocalDate.from(sym454.plus(1, DAYS)), iso.plusDays(1)); @@ -195,7 +204,8 @@ public void test_plusDays(Symmetry454Date sym454, LocalDate iso) { assertEquals(LocalDate.from(sym454.plus(-60, DAYS)), iso.plusDays(-60)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_minusDays(Symmetry454Date sym454, LocalDate iso) { assertEquals(LocalDate.from(sym454.minus(0, DAYS)), iso); assertEquals(LocalDate.from(sym454.minus(1, DAYS)), iso.minusDays(1)); @@ -204,7 +214,8 @@ public void test_minusDays(Symmetry454Date sym454, LocalDate iso) { assertEquals(LocalDate.from(sym454.minus(-60, DAYS)), iso.minusDays(-60)); } - @Test(dataProvider = "samples") + @Test + @UseDataProvider("data_samples") public void test_until_DAYS(Symmetry454Date sym454, LocalDate iso) { assertEquals(sym454.until(iso.plusDays(0), DAYS), 0); assertEquals(sym454.until(iso.plusDays(1), DAYS), 1); @@ -212,8 +223,8 @@ public void test_until_DAYS(Symmetry454Date sym454, LocalDate iso) { assertEquals(sym454.until(iso.minusDays(40), DAYS), -40); } - @DataProvider(name = "badDates") - Object[][] data_badDates() { + @DataProvider + public static Object[][] data_badDates() { return new Object[][] { {-1, 13, 28}, {-1, 13, 29}, @@ -245,13 +256,14 @@ Object[][] data_badDates() { }; } - @Test(dataProvider = "badDates", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_badDates") public void test_badDates(int year, int month, int dom) { Symmetry454Date.of(year, month, dom); } - @DataProvider(name = "badLeapDates") - Object[][] data_badLeapDates() { + @DataProvider + public static Object[][] data_badLeapDates() { return new Object[][] { {1}, {100}, @@ -260,12 +272,13 @@ Object[][] data_badLeapDates() { }; } - @Test(dataProvider = "badLeapDates", expectedExceptions = DateTimeException.class) - public void badLeapDayDates(int year) { + @Test(expected = DateTimeException.class) + @UseDataProvider("data_badLeapDates") + public void test_badLeapDayDates(int year) { Symmetry454Date.of(year, 12, 29); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_chronology_dateYearDay_badDate() { Symmetry454Chronology.INSTANCE.dateYearDay(2000, 365); } @@ -286,7 +299,7 @@ public void test_isLeapYear_specific() { // Symmetry454Date.isLeapWeek //----------------------------------------------------------------------- @Test - void test_leapWeek() { + public void test_leapWeek() { assertTrue(Symmetry454Date.of (2015, 12, 29).isLeapWeek()); assertTrue(Symmetry454Date.of (2015, 12, 30).isLeapWeek()); assertTrue(Symmetry454Date.of (2015, 12, 31).isLeapWeek()); @@ -299,8 +312,8 @@ void test_leapWeek() { //----------------------------------------------------------------------- // Symmetry454Date.lengthOfMonth //----------------------------------------------------------------------- - @DataProvider(name = "lengthOfMonth") - Object[][] data_lengthOfMonth() { + @DataProvider + public static Object[][] data_lengthOfMonth() { return new Object[][] { {2000, 1, 28, 28}, {2000, 2, 28, 35}, @@ -318,12 +331,14 @@ Object[][] data_lengthOfMonth() { }; } - @Test(dataProvider = "lengthOfMonth") + @Test + @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int day, int length) { assertEquals(Symmetry454Date.of(year, month, day).lengthOfMonth(), length); } - @Test(dataProvider = "lengthOfMonth") + @Test + @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonthFirst(int year, int month, int day, int length) { assertEquals(Symmetry454Date.of(year, month, 1).lengthOfMonth(), length); } @@ -386,8 +401,8 @@ public void test_prolepticYear_specific() { assertEquals(Symmetry454Chronology.INSTANCE.prolepticYear(IsoEra.CE, 1582), 1582); } - @DataProvider(name = "prolepticYearBadEra") - Object[][] data_prolepticYear_badEra() { + @DataProvider + public static Object[][] data_prolepticYear_badEra() { return new Era[][] { { AccountingEra.BCE }, { AccountingEra.CE }, @@ -413,7 +428,8 @@ Object[][] data_prolepticYear_badEra() { }; } - @Test(dataProvider = "prolepticYearBadEra", expectedExceptions = ClassCastException.class) + @Test(expected = ClassCastException.class) + @UseDataProvider("data_prolepticYear_badEra") public void test_prolepticYear_badEra(Era era) { Symmetry454Chronology.INSTANCE.prolepticYear(era, 4); } @@ -424,7 +440,7 @@ public void test_Chronology_eraOf() { assertEquals(Symmetry454Chronology.INSTANCE.eraOf(1), IsoEra.CE); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_Chronology_eraOf_invalid() { Symmetry454Chronology.INSTANCE.eraOf(2); } @@ -460,8 +476,8 @@ public void test_Chronology_range() { //----------------------------------------------------------------------- // Symmetry454Date.range //----------------------------------------------------------------------- - @DataProvider(name = "ranges") - Object[][] data_ranges() { + @DataProvider + public static Object[][] data_ranges() { return new Object[][] { // Leap Day and Year Day are members of months {2012, 1, 23, DAY_OF_MONTH, ValueRange.of(1, 28)}, @@ -506,12 +522,13 @@ Object[][] data_ranges() { }; } - @Test(dataProvider = "ranges") + @Test + @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, ValueRange range) { assertEquals(Symmetry454Date.of(year, month, dom).range(field), range); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_range_unsupported() { Symmetry454Date.of(2012, 6, 28).range(MINUTE_OF_DAY); } @@ -519,8 +536,8 @@ public void test_range_unsupported() { //----------------------------------------------------------------------- // Symmetry454Date.getLong //----------------------------------------------------------------------- - @DataProvider(name = "getLong") - Object[][] data_getLong() { + @DataProvider + public static Object[][] data_getLong() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 5}, {2014, 5, 26, DAY_OF_MONTH, 26}, @@ -554,12 +571,13 @@ Object[][] data_getLong() { }; } - @Test(dataProvider = "getLong") + @Test + @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(Symmetry454Date.of(year, month, dom).getLong(field), expected); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_getLong_unsupported() { Symmetry454Date.of(2012, 6, 28).getLong(MINUTE_OF_DAY); } @@ -567,8 +585,8 @@ public void test_getLong_unsupported() { //----------------------------------------------------------------------- // Symmetry454Date.with //----------------------------------------------------------------------- - @DataProvider(name = "with") - Object[][] data_with() { + @DataProvider + public static Object[][] data_with() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 1, 2014, 5, 22}, {2014, 5, 26, DAY_OF_WEEK, 5, 2014, 5, 26}, @@ -643,15 +661,16 @@ Object[][] data_with() { }; } - @Test(dataProvider = "with") + @Test + @UseDataProvider("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(Symmetry454Date.of(year, month, dom).with(field, value), Symmetry454Date.of(expectedYear, expectedMonth, expectedDom)); } - @DataProvider(name = "with_bad") - Object[][] data_with_bad() { + @DataProvider + public static Object[][] data_with_bad() { return new Object[][] { {2013, 1, 1, ALIGNED_DAY_OF_WEEK_IN_MONTH, -1}, {2013, 1, 1, ALIGNED_DAY_OF_WEEK_IN_MONTH, 8}, @@ -691,12 +710,13 @@ Object[][] data_with_bad() { }; } - @Test(dataProvider = "with_bad", expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) + @UseDataProvider("data_with_bad") public void test_with_TemporalField_badValue(int year, int month, int dom, TemporalField field, long value) { Symmetry454Date.of(year, month, dom).with(field, value); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_with_TemporalField_unsupported() { Symmetry454Date.of(2012, 6, 28).with(MINUTE_OF_DAY, 10); } @@ -704,8 +724,8 @@ public void test_with_TemporalField_unsupported() { //----------------------------------------------------------------------- // Symmetry454Date.with(TemporalAdjuster) //----------------------------------------------------------------------- - @DataProvider(name = "temporalAdjusters_lastDayOfMonth") - Object[][] data_temporalAdjusters_lastDayOfMonth() { + @DataProvider + public static Object[][] data_temporalAdjusters_lastDayOfMonth() { return new Object[][] { {2012, 1, 23, 2012, 1, 28}, {2012, 2, 23, 2012, 2, 35}, @@ -723,7 +743,8 @@ Object[][] data_temporalAdjusters_lastDayOfMonth() { }; } - @Test(dataProvider = "temporalAdjusters_lastDayOfMonth") + @Test + @UseDataProvider("data_temporalAdjusters_lastDayOfMonth") public void test_temporalAdjusters_LastDayOfMonth(int year, int month, int day, int expectedYear, int expectedMonth, int expectedDay) { Symmetry454Date base = Symmetry454Date.of(year, month, day); Symmetry454Date expected = Symmetry454Date.of(expectedYear, expectedMonth, expectedDay); @@ -741,7 +762,7 @@ public void test_adjust_toLocalDate() { assertEquals(test, Symmetry454Date.of(2012, 7, 5)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_adjust_toMonth() { Symmetry454Date sym454 = Symmetry454Date.of(2000, 1, 4); sym454.with(Month.APRIL); @@ -768,8 +789,8 @@ public void test_LocalDateTime_adjustToSymmetry454Date() { // Symmetry454Date.plus // Symmetry454Date.minus //----------------------------------------------------------------------- - @DataProvider(name = "plus") - Object[][] data_plus() { + @DataProvider + public static Object[][] data_plus() { return new Object[][] { {2014, 5, 26, 0, DAYS, 2014, 5, 26}, {2014, 5, 26, 8, DAYS, 2014, 5, 34}, @@ -804,8 +825,8 @@ Object[][] data_plus() { }; } - @DataProvider(name = "plus_leapWeek") - Object[][] data_plus_leapWeek() { + @DataProvider + public static Object[][] data_plus_leapWeek() { return new Object[][] { {2015, 12, 28, 0, DAYS, 2015, 12, 28}, {2015, 12, 28, 8, DAYS, 2016, 1, 1}, @@ -824,21 +845,24 @@ Object[][] data_plus_leapWeek() { }; } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(Symmetry454Date.of(year, month, dom).plus(amount, unit), Symmetry454Date.of(expectedYear, expectedMonth, expectedDom)); } - @Test(dataProvider = "plus_leapWeek") + @Test + @UseDataProvider("data_plus_leapWeek") public void test_plus_leapWeek_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(Symmetry454Date.of(year, month, dom).plus(amount, unit), Symmetry454Date.of(expectedYear, expectedMonth, expectedDom)); } - @Test(dataProvider = "plus") + @Test + @UseDataProvider("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -846,7 +870,8 @@ public void test_minus_TemporalUnit( assertEquals(Symmetry454Date.of(year, month, dom).minus(amount, unit), Symmetry454Date.of(expectedYear, expectedMonth, expectedDom)); } - @Test(dataProvider = "plus_leapWeek") + @Test + @UseDataProvider("data_plus_leapWeek") public void test_minus_leapWeek_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -854,7 +879,7 @@ public void test_minus_leapWeek_TemporalUnit( assertEquals(Symmetry454Date.of(year, month, dom).minus(amount, unit), Symmetry454Date.of(expectedYear, expectedMonth, expectedDom)); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_plus_TemporalUnit_unsupported() { Symmetry454Date.of(2012, 6, 28).plus(0, MINUTES); } @@ -862,8 +887,8 @@ public void test_plus_TemporalUnit_unsupported() { //----------------------------------------------------------------------- // Symmetry454Date.until //----------------------------------------------------------------------- - @DataProvider(name = "until") - Object[][] data_until() { + @DataProvider + public static Object[][] data_until() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, DAYS, 0}, {2014, 5, 26, 2014, 6, 4, DAYS, 13}, @@ -890,8 +915,8 @@ Object[][] data_until() { }; } - @DataProvider(name = "until_period") - Object[][] data_until_period() { + @DataProvider + public static Object[][] data_until_period() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, 0, 0, 0}, {2014, 5, 26, 2014, 6, 4, 0, 0, 13}, @@ -905,7 +930,8 @@ Object[][] data_until_period() { }; } - @Test(dataProvider = "until") + @Test + @UseDataProvider("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -915,7 +941,8 @@ public void test_until_TemporalUnit( assertEquals(start.until(end, unit), expected); } - @Test(dataProvider = "until_period") + @Test + @UseDataProvider("data_until_period") public void test_until_end( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -926,7 +953,7 @@ public void test_until_end( assertEquals(start.until(end), period); } - @Test(expectedExceptions = UnsupportedTemporalTypeException.class) + @Test(expected = UnsupportedTemporalTypeException.class) public void test_until_TemporalUnit_unsupported() { Symmetry454Date start = Symmetry454Date.of(2012, 6, 28); Symmetry454Date end = Symmetry454Date.of(2012, 7, 1); @@ -942,7 +969,7 @@ public void test_plus_Period() { Symmetry454Date.of(2014, 8, 1)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_plus_Period_ISO() { assertEquals(Symmetry454Date.of(2014, 5, 26).plus(Period.ofMonths(2)), Symmetry454Date.of(2014, 7, 26)); @@ -954,7 +981,7 @@ public void test_minus_Period() { Symmetry454Date.of(2014, 3, 23)); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void test_minus_Period_ISO() { assertEquals(Symmetry454Date.of(2014, 5, 26).minus(Period.ofMonths(2)), Symmetry454Date.of(2014, 3, 26)); } @@ -962,8 +989,8 @@ public void test_minus_Period_ISO() { //----------------------------------------------------------------------- // Symmetry454Date.equals //----------------------------------------------------------------------- - @DataProvider(name = "equals") - Object[][] data_equals() { + @DataProvider + public static Object[][] data_equals() { return new Object[][] { {Symmetry454Date.of(2000, 1, 3), Symmetry454Date.of(2000, 1, 4), Symmetry454Date.of(2000, 2, 3), Symmetry454Date.of(2001, 1, 3)}, {Symmetry454Date.of(2000, 12, 28), Symmetry454Date.of(2000, 12, 25), Symmetry454Date.of(2001, 1, 1), Symmetry454Date.of(2001, 12, 28)}, @@ -971,8 +998,9 @@ Object[][] data_equals() { }; } - @Test(dataProvider = "equals") - void test_equals(Symmetry454Date a1, Symmetry454Date b, Symmetry454Date c, Symmetry454Date d) { + @Test + @UseDataProvider("data_equals") + public void test_equals(Symmetry454Date a1, Symmetry454Date b, Symmetry454Date c, Symmetry454Date d) { assertTrue(a1.equals(a1)); assertFalse(a1.equals(b)); assertFalse(a1.equals(c)); @@ -985,8 +1013,8 @@ void test_equals(Symmetry454Date a1, Symmetry454Date b, Symmetry454Date c, Symme //----------------------------------------------------------------------- // Symmetry454Date.toString //----------------------------------------------------------------------- - @DataProvider(name = "toString") - Object[][] data_toString() { + @DataProvider + public static Object[][] data_toString() { return new Object[][] { {Symmetry454Date.of(1, 1, 1), "Sym454 CE 1/01/01"}, {Symmetry454Date.of(1970, 2, 35), "Sym454 CE 1970/02/35"}, @@ -995,7 +1023,8 @@ Object[][] data_toString() { }; } - @Test(dataProvider = "toString") + @Test + @UseDataProvider("data_toString") public void test_toString(Symmetry454Date date, String expected) { assertEquals(date.toString(), expected); } diff --git a/src/test/java/org/threeten/extra/scale/TestTaiInstant.java b/src/test/java/org/threeten/extra/scale/TestTaiInstant.java index ab270b00..9f4d5b24 100644 --- a/src/test/java/org/threeten/extra/scale/TestTaiInstant.java +++ b/src/test/java/org/threeten/extra/scale/TestTaiInstant.java @@ -31,9 +31,9 @@ */ package org.threeten.extra.scale; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -44,13 +44,17 @@ import java.time.Instant; import java.time.format.DateTimeParseException; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test TaiInstant. */ -@Test +@RunWith(DataProviderRunner.class) public class TestTaiInstant { //----------------------------------------------------------------------- @@ -106,7 +110,7 @@ public void factory_ofTaiSeconds_long_long_nanosNegativeAdjusted() { assertEquals(test.getNano(), 999999999); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void factory_ofTaiSeconds_long_long_tooBig() { TaiInstant.ofTaiSeconds(Long.MAX_VALUE, 1000000000); } @@ -121,7 +125,7 @@ public void factory_of_Instant() { assertEquals(test.getNano(), 2); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void factory_of_Instant_null() { TaiInstant.of((Instant) null); } @@ -140,7 +144,7 @@ public void factory_of_UtcInstant() { } } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void factory_of_UtcInstant_null() { TaiInstant.of((UtcInstant) null); } @@ -160,8 +164,8 @@ public void factory_parse_CharSequence() { } } - @DataProvider(name = "BadParse") - Object[][] provider_badParse() { + @DataProvider + public static Object[][] data_badParse() { return new Object[][] { {"A.123456789s(TAI)"}, {"123.12345678As(TAI)"}, @@ -172,12 +176,13 @@ Object[][] provider_badParse() { }; } - @Test(dataProvider = "BadParse", expectedExceptions = DateTimeParseException.class) + @Test(expected = DateTimeParseException.class) + @UseDataProvider("data_badParse") public void factory_parse_CharSequence_invalid(String str) { TaiInstant.parse(str); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void factory_parse_CharSequence_null() { TaiInstant.parse((String) null); } @@ -185,8 +190,8 @@ public void factory_parse_CharSequence_null() { //----------------------------------------------------------------------- // withTAISeconds() //----------------------------------------------------------------------- - @DataProvider(name = "withTAISeconds") - Object[][] provider_withTAISeconds() { + @DataProvider + public static Object[][] data_withTAISeconds() { return new Object[][] { {0L, 12345L, 1L, 1L, 12345L}, {0L, 12345L, -1L, -1L, 12345L}, @@ -197,7 +202,8 @@ Object[][] provider_withTAISeconds() { }; } - @Test(dataProvider = "withTAISeconds") + @Test + @UseDataProvider("data_withTAISeconds") public void test_withTAISeconds(long tai, long nanos, long newTai, Long expectedTai, Long expectedNanos) { TaiInstant i = TaiInstant.ofTaiSeconds(tai, nanos).withTaiSeconds(newTai); assertEquals(i.getTaiSeconds(), expectedTai.longValue()); @@ -207,8 +213,8 @@ public void test_withTAISeconds(long tai, long nanos, long newTai, Long expected //----------------------------------------------------------------------- // withNano() //----------------------------------------------------------------------- - @DataProvider(name = "withNanoOfSecond") - Object[][] provider_withNano() { + @DataProvider + public static Object[][] data_withNano() { return new Object[][] { {0L, 12345L, 1, 0L, 1L}, {7L, 12345L, 2, 7L, 2L}, @@ -219,7 +225,8 @@ Object[][] provider_withNano() { }; } - @Test(dataProvider = "withNanoOfSecond") + @Test + @UseDataProvider("data_withNano") public void test_withNano(long tai, long nanos, int newNano, Long expectedTai, Long expectedNanos) { TaiInstant i = TaiInstant.ofTaiSeconds(tai, nanos); if (expectedTai != null) { @@ -239,8 +246,8 @@ public void test_withNano(long tai, long nanos, int newNano, Long expectedTai, L //----------------------------------------------------------------------- // plus(Duration) //----------------------------------------------------------------------- - @DataProvider(name = "Plus") - Object[][] provider_plus() { + @DataProvider + public static Object[][] data_plus() { return new Object[][] { {Long.MIN_VALUE, 0, Long.MAX_VALUE, 0, -1, 0}, @@ -424,20 +431,21 @@ Object[][] provider_plus() { }; } - @Test(dataProvider = "Plus") + @Test + @UseDataProvider("data_plus") public void test_plus(long seconds, int nanos, long plusSeconds, int plusNanos, long expectedSeconds, int expectedNanoOfSecond) { TaiInstant i = TaiInstant.ofTaiSeconds(seconds, nanos).plus(Duration.ofSeconds(plusSeconds, plusNanos)); assertEquals(i.getTaiSeconds(), expectedSeconds); assertEquals(i.getNano(), expectedNanoOfSecond); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_overflowTooBig() { TaiInstant i = TaiInstant.ofTaiSeconds(Long.MAX_VALUE, 999999999); i.plus(Duration.ofSeconds(0, 1)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_overflowTooSmall() { TaiInstant i = TaiInstant.ofTaiSeconds(Long.MIN_VALUE, 0); i.plus(Duration.ofSeconds(-1, 999999999)); @@ -446,8 +454,8 @@ public void test_plus_overflowTooSmall() { //----------------------------------------------------------------------- // minus(Duration) //----------------------------------------------------------------------- - @DataProvider(name = "Minus") - Object[][] provider_minus() { + @DataProvider + public static Object[][] data_minus() { return new Object[][] { {Long.MIN_VALUE, 0, Long.MIN_VALUE + 1, 0, -1, 0}, @@ -631,20 +639,21 @@ Object[][] provider_minus() { }; } - @Test(dataProvider = "Minus") + @Test + @UseDataProvider("data_minus") public void test_minus(long seconds, int nanos, long minusSeconds, int minusNanos, long expectedSeconds, int expectedNanoOfSecond) { TaiInstant i = TaiInstant.ofTaiSeconds(seconds, nanos).minus(Duration.ofSeconds(minusSeconds, minusNanos)); assertEquals(i.getTaiSeconds(), expectedSeconds); assertEquals(i.getNano(), expectedNanoOfSecond); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_overflowTooSmall() { TaiInstant i = TaiInstant.ofTaiSeconds(Long.MIN_VALUE, 0); i.minus(Duration.ofSeconds(0, 1)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_overflowTooBig() { TaiInstant i = TaiInstant.ofTaiSeconds(Long.MAX_VALUE, 999999999); i.minus(Duration.ofSeconds(-1, 999999999)); @@ -703,7 +712,7 @@ public void test_toInstant() { for (int j = 0; j < 10; j++) { Instant expected = Instant.ofEpochSecond(-378691200L + i * 24 * 60 * 60 + j).plusNanos(2); TaiInstant test = TaiInstant.ofTaiSeconds(i * 24 * 60 * 60 + j + 10, 2); - assertEquals(test.toInstant(), expected, "Loop " + i + " " + j); + assertEquals(test.toInstant(), expected); } } } @@ -736,26 +745,26 @@ void doTest_comparisons_TaiInstant(TaiInstant... instants) { for (int j = 0; j < instants.length; j++) { TaiInstant b = instants[j]; if (i < j) { - assertEquals(a.compareTo(b) < 0, true, a + " <=> " + b); - assertEquals(a.equals(b), false, a + " <=> " + b); + assertEquals(a.compareTo(b) < 0, true); + assertEquals(a.equals(b), false); } else if (i > j) { - assertEquals(a.compareTo(b) > 0, true, a + " <=> " + b); - assertEquals(a.equals(b), false, a + " <=> " + b); + assertEquals(a.compareTo(b) > 0, true); + assertEquals(a.equals(b), false); } else { - assertEquals(a.compareTo(b), 0, a + " <=> " + b); - assertEquals(a.equals(b), true, a + " <=> " + b); + assertEquals(a.compareTo(b), 0); + assertEquals(a.equals(b), true); } } } } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_compareTo_ObjectNull() { TaiInstant a = TaiInstant.ofTaiSeconds(0L, 0); a.compareTo(null); } - @Test(expectedExceptions = ClassCastException.class) + @Test(expected = ClassCastException.class) @SuppressWarnings({"unchecked", "rawtypes"}) public void test_compareToNonTaiInstant() { Comparable c = TaiInstant.ofTaiSeconds(0L, 2); diff --git a/src/test/java/org/threeten/extra/scale/TestUtcInstant.java b/src/test/java/org/threeten/extra/scale/TestUtcInstant.java index fd4e993d..cb94cdbd 100644 --- a/src/test/java/org/threeten/extra/scale/TestUtcInstant.java +++ b/src/test/java/org/threeten/extra/scale/TestUtcInstant.java @@ -31,9 +31,9 @@ */ package org.threeten.extra.scale; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -45,13 +45,17 @@ import java.time.Instant; import java.time.format.DateTimeParseException; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test UtcInstant. */ -@Test +@RunWith(DataProviderRunner.class) public class TestUtcInstant { private static final long MJD_1972_12_30 = 41681; @@ -114,17 +118,17 @@ public void factory_ofModifiedJulianDay_long_long_endLeap() { assertEquals(t.getNanoOfDay(), NANOS_PER_LEAP_DAY - 1); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void factory_ofModifiedJulianDay_long_long_nanosNegative() { UtcInstant.ofModifiedJulianDay(MJD_1973_01_01, -1); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void factory_ofModifiedJulianDay_long_long_nanosTooBig_notLeap() { UtcInstant.ofModifiedJulianDay(MJD_1973_01_01, NANOS_PER_DAY); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void factory_ofModifiedJulianDay_long_long_nanosTooBig_leap() { UtcInstant.ofModifiedJulianDay(MJD_1972_12_31_LEAP, NANOS_PER_LEAP_DAY); } @@ -139,7 +143,7 @@ public void factory_of_Instant() { assertEquals(test.getNanoOfDay(), 2); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void factory_of_Instant_null() { UtcInstant.of((Instant) null); } @@ -158,7 +162,7 @@ public void factory_of_TaiInstant() { } } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void factory_of_TaiInstant_null() { UtcInstant.of((TaiInstant) null); } @@ -172,8 +176,8 @@ public void factory_parse_CharSequence() { assertEquals(UtcInstant.parse("1972-12-31T23:59:60Z"), UtcInstant.ofModifiedJulianDay(MJD_1972_12_31_LEAP, NANOS_PER_DAY)); } - @DataProvider(name = "BadParse") - Object[][] provider_badParse() { + @DataProvider + public static Object[][] data_badParse() { return new Object[][] { {""}, {"A"}, @@ -181,17 +185,18 @@ Object[][] provider_badParse() { }; } - @Test(dataProvider = "BadParse", expectedExceptions = DateTimeParseException.class) + @Test(expected = DateTimeParseException.class) + @UseDataProvider("data_badParse") public void factory_parse_CharSequence_invalid(String str) { UtcInstant.parse(str); } - @Test(expectedExceptions = DateTimeException.class) + @Test(expected = DateTimeException.class) public void factory_parse_CharSequence_invalidLeapSecond() { UtcInstant.parse("1972-11-11T23:59:60Z"); // leap second but not leap day } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void factory_parse_CharSequence_null() { UtcInstant.parse((String) null); } @@ -199,8 +204,8 @@ public void factory_parse_CharSequence_null() { //----------------------------------------------------------------------- // withModifiedJulianDay() //----------------------------------------------------------------------- - @DataProvider(name = "WithModifiedJulianDay") - Object[][] provider_withModifiedJulianDay() { + @DataProvider + public static Object[][] data_withModifiedJulianDay() { return new Object[][] { {0L, 12345L, 1L, 1L, 12345L}, {0L, 12345L, -1L, -1L, 12345L}, @@ -215,7 +220,8 @@ Object[][] provider_withModifiedJulianDay() { }; } - @Test(dataProvider = "WithModifiedJulianDay") + @Test + @UseDataProvider("data_withModifiedJulianDay") public void test_withModifiedJulianDay(long mjd, long nanos, long newMjd, Long expectedMjd, Long expectedNanos) { UtcInstant i = UtcInstant.ofModifiedJulianDay(mjd, nanos); if (expectedMjd != null) { @@ -235,8 +241,8 @@ public void test_withModifiedJulianDay(long mjd, long nanos, long newMjd, Long e //----------------------------------------------------------------------- // withNanoOfDay() //----------------------------------------------------------------------- - @DataProvider(name = "WithNanoOfDay") - Object[][] provider_withNanoOfDay() { + @DataProvider + public static Object[][] data_withNanoOfDay() { return new Object[][] { {0L, 12345L, 1L, 0L, 1L}, {0L, 12345L, -1L, null, null}, @@ -257,7 +263,8 @@ Object[][] provider_withNanoOfDay() { }; } - @Test(dataProvider = "WithNanoOfDay") + @Test + @UseDataProvider("data_withNanoOfDay") public void test_withNanoOfDay(long mjd, long nanos, long newNanoOfDay, Long expectedMjd, Long expectedNanos) { UtcInstant i = UtcInstant.ofModifiedJulianDay(mjd, nanos); if (expectedMjd != null) { @@ -277,8 +284,8 @@ public void test_withNanoOfDay(long mjd, long nanos, long newNanoOfDay, Long exp //----------------------------------------------------------------------- // plus(Duration) //----------------------------------------------------------------------- - @DataProvider(name = "Plus") - Object[][] provider_plus() { + @DataProvider + public static Object[][] data_plus() { return new Object[][] { {0, 0, -2 * SECS_PER_DAY, 5, -2, 5}, {0, 0, -1 * SECS_PER_DAY, 1, -1, 1}, @@ -312,20 +319,21 @@ Object[][] provider_plus() { }; } - @Test(dataProvider = "Plus") + @Test + @UseDataProvider("data_plus") public void test_plus(long mjd, long nanos, long plusSeconds, int plusNanos, long expectedMjd, long expectedNanos) { UtcInstant i = UtcInstant.ofModifiedJulianDay(mjd, nanos).plus(Duration.ofSeconds(plusSeconds, plusNanos)); assertEquals(i.getModifiedJulianDay(), expectedMjd); assertEquals(i.getNanoOfDay(), expectedNanos); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_overflowTooBig() { UtcInstant i = UtcInstant.ofModifiedJulianDay(Long.MAX_VALUE, NANOS_PER_DAY - 1); i.plus(Duration.ofNanos(1)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_plus_overflowTooSmall() { UtcInstant i = UtcInstant.ofModifiedJulianDay(Long.MIN_VALUE, 0); i.plus(Duration.ofNanos(-1)); @@ -334,8 +342,8 @@ public void test_plus_overflowTooSmall() { //----------------------------------------------------------------------- // minus(Duration) //----------------------------------------------------------------------- - @DataProvider(name = "Minus") - Object[][] provider_minus() { + @DataProvider + public static Object[][] data_minus() { return new Object[][] { {0, 0, 2 * SECS_PER_DAY, -5, -2, 5}, {0, 0, 1 * SECS_PER_DAY, -1, -1, 1}, @@ -369,20 +377,21 @@ Object[][] provider_minus() { }; } - @Test(dataProvider = "Minus") + @Test + @UseDataProvider("data_minus") public void test_minus(long mjd, long nanos, long minusSeconds, int minusNanos, long expectedMjd, long expectedNanos) { UtcInstant i = UtcInstant.ofModifiedJulianDay(mjd, nanos).minus(Duration.ofSeconds(minusSeconds, minusNanos)); assertEquals(i.getModifiedJulianDay(), expectedMjd); assertEquals(i.getNanoOfDay(), expectedNanos); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_overflowTooSmall() { UtcInstant i = UtcInstant.ofModifiedJulianDay(Long.MIN_VALUE, 0); i.minus(Duration.ofNanos(1)); } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_minus_overflowTooBig() { UtcInstant i = UtcInstant.ofModifiedJulianDay(Long.MAX_VALUE, NANOS_PER_DAY - 1); i.minus(Duration.ofNanos(-1)); @@ -433,7 +442,7 @@ public void test_toTaiInstant() { } } - @Test(expectedExceptions = ArithmeticException.class) + @Test(expected = ArithmeticException.class) public void test_toTaiInstant_maxInvalid() { UtcInstant utc = UtcInstant.ofModifiedJulianDay(Long.MAX_VALUE, 0); utc.toTaiInstant(); @@ -448,7 +457,7 @@ public void test_toInstant() { for (int j = 0; j < 10; j++) { Instant expected = Instant.ofEpochSecond(315532800 + i * SECS_PER_DAY + j).plusNanos(2); UtcInstant test = UtcInstant.ofModifiedJulianDay(44239 + i, j * NANOS_PER_SEC + 2); - assertEquals(test.toInstant(), expected, "Loop " + i + " " + j); + assertEquals(test.toInstant(), expected); } } } @@ -481,26 +490,26 @@ void doTest_comparisons_UtcInstant(UtcInstant... instants) { for (int j = 0; j < instants.length; j++) { UtcInstant b = instants[j]; if (i < j) { - assertEquals(a.compareTo(b), -1, a + " <=> " + b); - assertEquals(a.equals(b), false, a + " <=> " + b); + assertEquals(a.compareTo(b), -1); + assertEquals(a.equals(b), false); } else if (i > j) { - assertEquals(a.compareTo(b), 1, a + " <=> " + b); - assertEquals(a.equals(b), false, a + " <=> " + b); + assertEquals(a.compareTo(b), 1); + assertEquals(a.equals(b), false); } else { - assertEquals(a.compareTo(b), 0, a + " <=> " + b); - assertEquals(a.equals(b), true, a + " <=> " + b); + assertEquals(a.compareTo(b), 0); + assertEquals(a.equals(b), true); } } } } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_compareTo_ObjectNull() { UtcInstant a = UtcInstant.ofModifiedJulianDay(0L, 0); a.compareTo(null); } - @Test(expectedExceptions = ClassCastException.class) + @Test(expected = ClassCastException.class) @SuppressWarnings({"unchecked", "rawtypes"}) public void test_compareToNonUtcInstant() { Comparable c = UtcInstant.ofModifiedJulianDay(0L, 2); @@ -571,8 +580,8 @@ public void test_hashCode() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider(name = "ToString") - Object[][] provider_toString() { + @DataProvider + public static Object[][] data_toString() { return new Object[][] { {40587, 0, "1970-01-01T00:00:00Z"}, {40588, 1, "1970-01-02T00:00:00.000000001Z"}, @@ -590,12 +599,14 @@ Object[][] provider_toString() { }; } - @Test(dataProvider = "ToString") + @Test + @UseDataProvider("data_toString") public void test_toString(long mjd, long nod, String expected) { assertEquals(UtcInstant.ofModifiedJulianDay(mjd, nod).toString(), expected); } - @Test(dataProvider = "ToString") + @Test + @UseDataProvider("data_toString") public void test_toString_parse(long mjd, long nod, String str) { assertEquals(UtcInstant.parse(str), UtcInstant.ofModifiedJulianDay(mjd, nod)); } diff --git a/src/test/java/org/threeten/extra/scale/TestUtcRules.java b/src/test/java/org/threeten/extra/scale/TestUtcRules.java index 1fd325c9..70363df7 100644 --- a/src/test/java/org/threeten/extra/scale/TestUtcRules.java +++ b/src/test/java/org/threeten/extra/scale/TestUtcRules.java @@ -31,9 +31,9 @@ */ package org.threeten.extra.scale; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertSame; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -49,19 +49,23 @@ import java.time.temporal.JulianFields; import java.util.Arrays; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test SystemLeapSecondRules. */ -@Test +@RunWith(DataProviderRunner.class) public class TestUtcRules { SystemUtcRules rules; - @BeforeMethod + @Before public void setUp() throws Exception { Constructor con = SystemUtcRules.class.getDeclaredConstructor(); con.setAccessible(true); @@ -69,6 +73,7 @@ public void setUp() throws Exception { } //----------------------------------------------------------------------- + @Test public void test_interfaces() { assertTrue(Serializable.class.isAssignableFrom(Duration.class)); } @@ -76,6 +81,7 @@ public void test_interfaces() { //----------------------------------------------------------------------- // serialize //----------------------------------------------------------------------- + @Test public void test_serialization() throws Exception { SystemUtcRules test = SystemUtcRules.INSTANCE; // use real rules, not our hacked copy ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -90,6 +96,7 @@ public void test_serialization() throws Exception { //----------------------------------------------------------------------- // getName() //----------------------------------------------------------------------- + @Test public void test_getName() { assertEquals(rules.getName(), "System"); } @@ -97,8 +104,8 @@ public void test_getName() { //----------------------------------------------------------------------- // getLeapSecond() //----------------------------------------------------------------------- - @DataProvider(name = "LeapSeconds") - Object[][] leapSeconds() { + @DataProvider + public static Object[][] data_leapSeconds() { return new Object[][] { {-1, 0, 10, "1858-11-16"}, {0, 0, 10, "1858-11-17"}, @@ -230,9 +237,10 @@ Object[][] leapSeconds() { }; } - @Test(dataProvider = "LeapSeconds") + @Test + @UseDataProvider("data_leapSeconds") public void test_leapSeconds(long mjd, int adjust, int offset, String checkDate) { - assertEquals(mjd, LocalDate.parse(checkDate).getLong(JulianFields.MODIFIED_JULIAN_DAY), "Invalid test"); + assertEquals(mjd, LocalDate.parse(checkDate).getLong(JulianFields.MODIFIED_JULIAN_DAY)); assertEquals(rules.getLeapSecondAdjustment(mjd), adjust); assertEquals(rules.getTaiOffset(mjd), offset); @@ -261,6 +269,7 @@ public void test_leapSeconds(long mjd, int adjust, int offset, String checkDate) private static final long TAI_SECS_UTC2100 = (MJD_2100 - MJD_1958) * SECS_PER_DAY + CURRENT_TAI_OFFSET; private static final long TAI_SECS_UTC2100_EXTRA_NEGATIVE_LEAP = (MJD_2100 - MJD_1958) * SECS_PER_DAY + CURRENT_TAI_OFFSET - 1; + @Test public void test_convertToUtc_TaiInstant_startUtcPeriod() { TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC1980, 0); // 1980-01-01 (19 leap secs added) UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_1980, 0); @@ -276,6 +285,7 @@ public void test_convertToUtc_TaiInstant_startUtcPeriod() { } } + @Test public void test_convertToUtc_TaiInstant_furtherAfterLeap() { TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC1980 + 1, 0); // 1980-01-01 (19 leap secs added) UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_1980, NANOS_PER_SEC); @@ -283,6 +293,7 @@ public void test_convertToUtc_TaiInstant_furtherAfterLeap() { assertEquals(rules.convertToTai(expected), tai); // check reverse } + @Test public void test_convertToUtc_TaiInstant_justAfterLeap() { TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC1980, 0); // 1980-01-01 (19 leap secs added) UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_1980, 0); @@ -290,6 +301,7 @@ public void test_convertToUtc_TaiInstant_justAfterLeap() { assertEquals(rules.convertToTai(expected), tai); // check reverse } + @Test public void test_convertToUtc_TaiInstant_inLeap() { TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC1980 - 1, 0); // 1980-01-01 (1 second before 1980) UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_1980 - 1, SECS_PER_DAY * NANOS_PER_SEC); @@ -297,6 +309,7 @@ public void test_convertToUtc_TaiInstant_inLeap() { assertEquals(rules.convertToTai(expected), tai); // check reverse } + @Test public void test_convertToUtc_TaiInstant_justBeforeLeap() { TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC1980 - 2, 0); // 1980-01-01 (2 seconds before 1980) UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_1980 - 1, (SECS_PER_DAY - 1) * NANOS_PER_SEC); @@ -304,6 +317,7 @@ public void test_convertToUtc_TaiInstant_justBeforeLeap() { assertEquals(rules.convertToTai(expected), tai); // check reverse } + @Test public void test_convertToUtc_TaiInstant_1800() { TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC1800, 0); // 1800-01-01 UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_1800, 0); @@ -311,6 +325,7 @@ public void test_convertToUtc_TaiInstant_1800() { assertEquals(rules.convertToTai(expected), tai); // check reverse } + @Test public void test_convertToUtc_TaiInstant_1900() { TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC1900, 0); // 1900-01-01 UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_1900, 0); @@ -318,6 +333,7 @@ public void test_convertToUtc_TaiInstant_1900() { assertEquals(rules.convertToTai(expected), tai); // check reverse } + @Test public void test_convertToUtc_TaiInstant_1958() { TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC1958, 0); // 1958-01-01 UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_1958, 0); @@ -325,6 +341,7 @@ public void test_convertToUtc_TaiInstant_1958() { assertEquals(rules.convertToTai(expected), tai); // check reverse } + @Test public void test_convertToUtc_TaiInstant_2100() { TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC2100, 0); // 2100-01-01 UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_2100, 0); @@ -332,17 +349,18 @@ public void test_convertToUtc_TaiInstant_2100() { assertEquals(rules.convertToTai(expected), tai); // check reverse } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_convertToUtc_TaiInstant_null() { rules.convertToUtc((TaiInstant) null); } - @Test(expectedExceptions = NullPointerException.class) + @Test(expected = NullPointerException.class) public void test_convertToTai_UtcInstant_null() { rules.convertToTai((UtcInstant) null); } //------------------------------------------------------------------------- + @Test public void test_negativeLeap_justBeforeLeap() { rules.register(MJD_2100 - 1, -1); TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC2100_EXTRA_NEGATIVE_LEAP - 1, 0); // 2100-01-01 (1 second before 2100) @@ -351,6 +369,7 @@ public void test_negativeLeap_justBeforeLeap() { assertEquals(rules.convertToTai(expected), tai); // check reverse } + @Test public void test_negativeLeap_justAfterLeap() { rules.register(MJD_2100 - 1, -1); TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC2100_EXTRA_NEGATIVE_LEAP, 0); // 2100-01-01 @@ -362,6 +381,7 @@ public void test_negativeLeap_justAfterLeap() { //----------------------------------------------------------------------- // convertToUtc(Instant)/convertToInstant(UtcInstant) //----------------------------------------------------------------------- + @Test public void test_convertToInstant_justBeforeLeap() { OffsetDateTime odt = OffsetDateTime.of(1979, 12, 31, 23, 43, 21, 0, ZoneOffset.UTC); Instant instant = odt.toInstant(); @@ -370,6 +390,7 @@ public void test_convertToInstant_justBeforeLeap() { assertEquals(rules.convertToUtc(instant), utc); } + @Test public void test_convertToInstant_sls() { for (int i = 1; i < 1000; i++) { long utcNanos = (SECS_PER_DAY + 1 - 1000) * NANOS_PER_SEC + i * 1000000000L; @@ -386,6 +407,7 @@ public void test_convertToInstant_sls() { } } + @Test public void test_convertToInstant_slsMillis() { for (int i = 1; i < 1000; i++) { long utcNanos = (SECS_PER_DAY + 1 - 1000) * NANOS_PER_SEC + i * 1000000; @@ -400,6 +422,7 @@ public void test_convertToInstant_slsMillis() { } } + @Test public void test_convertToInstant_slsMicros() { for (int i = 1; i < 1000; i++) { long utcNanos = (SECS_PER_DAY + 1 - 1000) * NANOS_PER_SEC + i * 1000; @@ -414,6 +437,7 @@ public void test_convertToInstant_slsMicros() { } } + @Test public void test_convertToInstant_slsNanos() { for (int i = 1; i < 5005; i++) { long utcNanos = (SECS_PER_DAY + 1 - 1000) * NANOS_PER_SEC + i; @@ -429,6 +453,7 @@ public void test_convertToInstant_slsNanos() { } } + @Test public void test_convertToInstant_justAfterLeap() { OffsetDateTime odt = OffsetDateTime.of(1980, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC); Instant instant = odt.toInstant(); @@ -437,6 +462,7 @@ public void test_convertToInstant_justAfterLeap() { assertEquals(rules.convertToUtc(instant), utc); } + @Test public void test_convertToInstant_furtherAfterLeap() { OffsetDateTime odt = OffsetDateTime.of(1980, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC); Instant instant = odt.toInstant(); @@ -448,6 +474,7 @@ public void test_convertToInstant_furtherAfterLeap() { //----------------------------------------------------------------------- // registerLeapSecond() //----------------------------------------------------------------------- + @Test public void test_registerLeapSecond_justAfterLastDate_plusOne() { long[] dates = rules.getLeapSecondDates(); long mjd = dates[dates.length - 1] + 1; @@ -458,6 +485,7 @@ public void test_registerLeapSecond_justAfterLastDate_plusOne() { assertEquals(rules.getLeapSecondAdjustment(mjd), 1); } + @Test public void test_registerLeapSecond_justAfterLastDate_minusOne() { long[] dates = rules.getLeapSecondDates(); long mjd = dates[dates.length - 1] + 1; @@ -468,6 +496,7 @@ public void test_registerLeapSecond_justAfterLastDate_minusOne() { assertEquals(rules.getLeapSecondAdjustment(mjd), -1); } + @Test public void test_registerLeapSecond_equalLastDate_sameLeap() { long[] dates = rules.getLeapSecondDates(); long mjd = dates[dates.length - 1]; @@ -478,6 +507,7 @@ public void test_registerLeapSecond_equalLastDate_sameLeap() { assertEquals(rules.getLeapSecondAdjustment(mjd), adj); } + @Test public void test_registerLeapSecond_equalEarlierDate_sameLeap() { long[] dates = rules.getLeapSecondDates(); long mjd = dates[dates.length - 2]; @@ -488,7 +518,7 @@ public void test_registerLeapSecond_equalEarlierDate_sameLeap() { assertEquals(rules.getLeapSecondAdjustment(mjd), adj); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void test_registerLeapSecond_equalLastDate_differentLeap() { long[] dates = rules.getLeapSecondDates(); long mjd = dates[dates.length - 1]; @@ -496,7 +526,7 @@ public void test_registerLeapSecond_equalLastDate_differentLeap() { rules.register(mjd, -adj); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void test_registerLeapSecond_equalEarlierDate_differentLeap() { long[] dates = rules.getLeapSecondDates(); long mjd = dates[dates.length - 2]; @@ -504,24 +534,24 @@ public void test_registerLeapSecond_equalEarlierDate_differentLeap() { rules.register(mjd, -adj); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void test_registerLeapSecond_beforeLastDate() { long[] dates = rules.getLeapSecondDates(); long mjd = dates[dates.length - 1] - 1; rules.register(mjd, 1); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void test_registerLeapSecond_invalidAdjustment_zero() { rules.register(MJD_2100, 0); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void test_registerLeapSecond_invalidAdjustment_minusTwo() { rules.register(MJD_2100, -2); } - @Test(expectedExceptions = IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void test_registerLeapSecond_invalidAdjustment_three() { rules.register(MJD_2100, 3); } @@ -529,6 +559,7 @@ public void test_registerLeapSecond_invalidAdjustment_three() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- + @Test public void test_toString() { assertEquals(rules.toString(), "UtcRules[System]"); } From f54b1105f7c938870a91e72e3924ad81bb012d70 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 8 Jan 2018 20:09:30 +0000 Subject: [PATCH 041/279] Prepare for v1.3 --- README.md | 4 ++-- src/changes/changes.xml | 2 +- src/site/markdown/index.md | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fb72e413..e38872c0 100644 --- a/README.md +++ b/README.md @@ -17,12 +17,12 @@ Various documentation is available: ### Releases -Release 1.2 is the current release. +Release 1.3 is the current release. This release is considered stable and worthy of the 1.x tag. ThreeTen-Extra requires Java SE 8 or later and has no dependencies. -Available in the [Maven Central repository](http://search.maven.org/#artifactdetails|org.threeten|threeten-extra|1.2|jar) +Available in the [Maven Central repository](http://search.maven.org/#artifactdetails|org.threeten|threeten-extra|1.3|jar) ### Support diff --git a/src/changes/changes.xml b/src/changes/changes.xml index c4157b25..3e0eadbf 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,7 +7,7 @@ - + Support Java 9. Update and redesign build. diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index 48d33abd..9da48d2d 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -47,18 +47,18 @@ Various documentation is available: ## Releases -Release 1.2 is the current release. +Release 1.3 is the current release. This release is considered stable and worthy of the 1.x tag. ThreeTen-Extra requires Java SE 8 or later and has no [dependencies](dependencies.html). -Available in [Maven Central](http://search.maven.org/#artifactdetails%7Corg.threeten%7Cthreeten-extra%7C1.2%7Cjar). +Available in [Maven Central](http://search.maven.org/#artifactdetails%7Corg.threeten%7Cthreeten-extra%7C1.3%7Cjar). ```xml org.threeten threeten-extra - 1.2 + 1.3 ``` From b5a725ed96ac70638f3b3ab5dbb98267cb6e015a Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 8 Jan 2018 20:14:49 +0000 Subject: [PATCH 042/279] No dist files are built --- pom.xml | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/pom.xml b/pom.xml index 357213c4..d35e1dfa 100644 --- a/pom.xml +++ b/pom.xml @@ -767,28 +767,7 @@ - - - org.apache.maven.plugins - maven-assembly-plugin - - false - - src/main/assembly/dist.xml - - gnu - - - - make-assembly - install - - single - - - - - + From e869d91e85f952d888666c96bb7d5dbd7cc29ffc Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 8 Jan 2018 20:20:43 +0000 Subject: [PATCH 043/279] [maven-release-plugin] prepare release v1.3 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d35e1dfa..e1bd1c89 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.3-SNAPSHOT + 1.3 Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later http://www.threeten.org/threeten-extra @@ -84,7 +84,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git http://github.com/ThreeTen/threeten-extra - HEAD + v1.3 ThreeTen.org From c770c752543576f57474564d1a1d6a093d3b0347 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 8 Jan 2018 20:20:51 +0000 Subject: [PATCH 044/279] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e1bd1c89..ea40a57b 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.3 + 1.4-SNAPSHOT Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later http://www.threeten.org/threeten-extra @@ -84,7 +84,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git http://github.com/ThreeTen/threeten-extra - v1.3 + HEAD ThreeTen.org From 53db42711d39a44733d466f6792a73675935131b Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 8 Jan 2018 20:24:04 +0000 Subject: [PATCH 045/279] Auto-release --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ea40a57b..bba8d1c6 100644 --- a/pom.xml +++ b/pom.xml @@ -800,7 +800,7 @@ https://oss.sonatype.org/ sonatype-joda-staging Releasing ${project.groupId}:${project.artifactId}:${project.version} - false + true From 4d2b15132d4bd021778843ae8abdeb58fd151920 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 22 Jan 2018 14:31:29 +0000 Subject: [PATCH 046/279] Fix build for Java 8 Javac release flag is not correctly ignoring new overloaded methods. Add override Math class to capture all uses Fixes #91 --- src/changes/changes.xml | 7 ++ src/main/java/org/threeten/extra/Math.java | 115 ++++++++++++++++++ .../java/org/threeten/extra/chrono/Math.java | 115 ++++++++++++++++++ .../java/org/threeten/extra/scale/Math.java | 115 ++++++++++++++++++ 4 files changed, 352 insertions(+) create mode 100644 src/main/java/org/threeten/extra/Math.java create mode 100644 src/main/java/org/threeten/extra/chrono/Math.java create mode 100644 src/main/java/org/threeten/extra/scale/Math.java diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 3e0eadbf..01939dff 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,6 +7,13 @@ + + + Fix build for Java 8. + Javac release flag is not correctly ignoring new overloaded methods. + Fixes #91. + + Support Java 9. diff --git a/src/main/java/org/threeten/extra/Math.java b/src/main/java/org/threeten/extra/Math.java new file mode 100644 index 00000000..4779f1c3 --- /dev/null +++ b/src/main/java/org/threeten/extra/Math.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.extra; + +/** + * Hack to avoid problems with java release flag. + */ +final class Math { + + static long abs(long a) { + return java.lang.Math.abs(a); + } + + static int abs(int a) { + return java.lang.Math.abs(a); + } + + //----------------------------------------------------------------------- + static long min(long a, long b) { + return java.lang.Math.min(a, b); + } + + static int min(int a, int b) { + return java.lang.Math.min(a, b); + } + + //----------------------------------------------------------------------- + static long max(long a, long b) { + return java.lang.Math.max(a, b); + } + + static int max(int a, int b) { + return java.lang.Math.max(a, b); + } + + //----------------------------------------------------------------------- + static long floorDiv(long a, long b) { + return java.lang.Math.floorDiv(a, b); + } + + static int floorDiv(int a, int b) { + return java.lang.Math.floorDiv(a, b); + } + + //----------------------------------------------------------------------- + static long floorMod(long a, long b) { + return java.lang.Math.floorMod(a, b); + } + + static int floorMod(int a, int b) { + return java.lang.Math.floorMod(a, b); + } + + //----------------------------------------------------------------------- + static long multiplyExact(long a, long b) { + return java.lang.Math.multiplyExact(a, b); + } + + static int multiplyExact(int a, int b) { + return java.lang.Math.multiplyExact(a, b); + } + + //----------------------------------------------------------------------- + static long addExact(long a, long b) { + return java.lang.Math.addExact(a, b); + } + + static int addExact(int a, int b) { + return java.lang.Math.addExact(a, b); + } + + //----------------------------------------------------------------------- + static long subtractExact(long a, long b) { + return java.lang.Math.subtractExact(a, b); + } + + static int subtractExact(int a, int b) { + return java.lang.Math.subtractExact(a, b); + } + + //----------------------------------------------------------------------- + static int toIntExact(long a) { + return java.lang.Math.toIntExact(a); + } + +} diff --git a/src/main/java/org/threeten/extra/chrono/Math.java b/src/main/java/org/threeten/extra/chrono/Math.java new file mode 100644 index 00000000..69780337 --- /dev/null +++ b/src/main/java/org/threeten/extra/chrono/Math.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.extra.chrono; + +/** + * Hack to avoid problems with java release flag. + */ +final class Math { + + static long abs(long a) { + return java.lang.Math.abs(a); + } + + static int abs(int a) { + return java.lang.Math.abs(a); + } + + //----------------------------------------------------------------------- + static long min(long a, long b) { + return java.lang.Math.min(a, b); + } + + static int min(int a, int b) { + return java.lang.Math.min(a, b); + } + + //----------------------------------------------------------------------- + static long max(long a, long b) { + return java.lang.Math.max(a, b); + } + + static int max(int a, int b) { + return java.lang.Math.max(a, b); + } + + //----------------------------------------------------------------------- + static long floorDiv(long a, long b) { + return java.lang.Math.floorDiv(a, b); + } + + static int floorDiv(int a, int b) { + return java.lang.Math.floorDiv(a, b); + } + + //----------------------------------------------------------------------- + static long floorMod(long a, long b) { + return java.lang.Math.floorMod(a, b); + } + + static int floorMod(int a, int b) { + return java.lang.Math.floorMod(a, b); + } + + //----------------------------------------------------------------------- + static long multiplyExact(long a, long b) { + return java.lang.Math.multiplyExact(a, b); + } + + static int multiplyExact(int a, int b) { + return java.lang.Math.multiplyExact(a, b); + } + + //----------------------------------------------------------------------- + static long addExact(long a, long b) { + return java.lang.Math.addExact(a, b); + } + + static int addExact(int a, int b) { + return java.lang.Math.addExact(a, b); + } + + //----------------------------------------------------------------------- + static long subtractExact(long a, long b) { + return java.lang.Math.subtractExact(a, b); + } + + static int subtractExact(int a, int b) { + return java.lang.Math.subtractExact(a, b); + } + + //----------------------------------------------------------------------- + static int toIntExact(long a) { + return java.lang.Math.toIntExact(a); + } + +} diff --git a/src/main/java/org/threeten/extra/scale/Math.java b/src/main/java/org/threeten/extra/scale/Math.java new file mode 100644 index 00000000..7f007dda --- /dev/null +++ b/src/main/java/org/threeten/extra/scale/Math.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.extra.scale; + +/** + * Hack to avoid problems with java release flag. + */ +final class Math { + + static long abs(long a) { + return java.lang.Math.abs(a); + } + + static int abs(int a) { + return java.lang.Math.abs(a); + } + + //----------------------------------------------------------------------- + static long min(long a, long b) { + return java.lang.Math.min(a, b); + } + + static int min(int a, int b) { + return java.lang.Math.min(a, b); + } + + //----------------------------------------------------------------------- + static long max(long a, long b) { + return java.lang.Math.max(a, b); + } + + static int max(int a, int b) { + return java.lang.Math.max(a, b); + } + + //----------------------------------------------------------------------- + static long floorDiv(long a, long b) { + return java.lang.Math.floorDiv(a, b); + } + + static int floorDiv(int a, int b) { + return java.lang.Math.floorDiv(a, b); + } + + //----------------------------------------------------------------------- + static long floorMod(long a, long b) { + return java.lang.Math.floorMod(a, b); + } + + static int floorMod(int a, int b) { + return java.lang.Math.floorMod(a, b); + } + + //----------------------------------------------------------------------- + static long multiplyExact(long a, long b) { + return java.lang.Math.multiplyExact(a, b); + } + + static int multiplyExact(int a, int b) { + return java.lang.Math.multiplyExact(a, b); + } + + //----------------------------------------------------------------------- + static long addExact(long a, long b) { + return java.lang.Math.addExact(a, b); + } + + static int addExact(int a, int b) { + return java.lang.Math.addExact(a, b); + } + + //----------------------------------------------------------------------- + static long subtractExact(long a, long b) { + return java.lang.Math.subtractExact(a, b); + } + + static int subtractExact(int a, int b) { + return java.lang.Math.subtractExact(a, b); + } + + //----------------------------------------------------------------------- + static int toIntExact(long a) { + return java.lang.Math.toIntExact(a); + } + +} From ecd664cbc07ae0fd522262ea78867c5610320503 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 22 Jan 2018 15:23:20 +0000 Subject: [PATCH 047/279] Prepare for v1.3.1 --- README.md | 7 ++++--- src/site/markdown/index.md | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e38872c0..014f07cb 100644 --- a/README.md +++ b/README.md @@ -17,12 +17,12 @@ Various documentation is available: ### Releases -Release 1.3 is the current release. +Release 1.3.1 is the current release. This release is considered stable and worthy of the 1.x tag. ThreeTen-Extra requires Java SE 8 or later and has no dependencies. -Available in the [Maven Central repository](http://search.maven.org/#artifactdetails|org.threeten|threeten-extra|1.3|jar) +Available in the [Maven Central repository](http://search.maven.org/#artifactdetails|org.threeten|threeten-extra|1.3.1|jar) ### Support @@ -31,6 +31,7 @@ Please use GitHub [issues](https://github.com/ThreeTen/threeten-extra/issues) an ### Release process -* Update manual parts of version (README.md, index.md, changes.xml) +* Update version (README.md, index.md, changes.xml) +* Commit and push * `mvn clean release:clean release:prepare release:perform` * Website will be built and released by Travis diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index 9da48d2d..2152eb77 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -47,18 +47,18 @@ Various documentation is available: ## Releases -Release 1.3 is the current release. +Release 1.3.1 is the current release. This release is considered stable and worthy of the 1.x tag. ThreeTen-Extra requires Java SE 8 or later and has no [dependencies](dependencies.html). -Available in [Maven Central](http://search.maven.org/#artifactdetails%7Corg.threeten%7Cthreeten-extra%7C1.3%7Cjar). +Available in [Maven Central](http://search.maven.org/#artifactdetails%7Corg.threeten%7Cthreeten-extra%7C1.3.1%7Cjar). ```xml org.threeten threeten-extra - 1.3 + 1.3.1 ``` From 996a40b0687c06a968237d8a92f50293df5443f4 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 22 Jan 2018 15:59:00 +0000 Subject: [PATCH 048/279] Keep nexus staging if failure --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index bba8d1c6..c1c5dabd 100644 --- a/pom.xml +++ b/pom.xml @@ -801,6 +801,7 @@ sonatype-joda-staging Releasing ${project.groupId}:${project.artifactId}:${project.version} true + true From 256352257f4dcdb7c966cab6a51705e8e1bd4693 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 22 Jan 2018 16:00:05 +0000 Subject: [PATCH 049/279] [maven-release-plugin] prepare release v1.3.1 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c1c5dabd..9cc00895 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.4-SNAPSHOT + 1.3.1 Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later http://www.threeten.org/threeten-extra @@ -84,7 +84,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git http://github.com/ThreeTen/threeten-extra - HEAD + v1.3.1 ThreeTen.org From 8e9a26e0ec97ae1a4336b3bb745933e40a51b529 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 22 Jan 2018 16:00:22 +0000 Subject: [PATCH 050/279] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 9cc00895..c1c5dabd 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.3.1 + 1.4-SNAPSHOT Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later http://www.threeten.org/threeten-extra @@ -84,7 +84,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git http://github.com/ThreeTen/threeten-extra - v1.3.1 + HEAD ThreeTen.org From f1e7d6e00f45a78df861d12d433b7f74c4ef2518 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 22 Jan 2018 17:48:24 +0000 Subject: [PATCH 051/279] Fix build for Java 8 Actual problem was in the pom.xml --- pom.xml | 2 +- src/changes/changes.xml | 7 ++ src/main/java/org/threeten/extra/Math.java | 115 ------------------ .../java/org/threeten/extra/chrono/Math.java | 115 ------------------ .../java/org/threeten/extra/scale/Math.java | 115 ------------------ 5 files changed, 8 insertions(+), 346 deletions(-) delete mode 100644 src/main/java/org/threeten/extra/Math.java delete mode 100644 src/main/java/org/threeten/extra/chrono/Math.java delete mode 100644 src/main/java/org/threeten/extra/scale/Math.java diff --git a/pom.xml b/pom.xml index c1c5dabd..b3fb8aa9 100644 --- a/pom.xml +++ b/pom.xml @@ -677,7 +677,7 @@ 9 - ${joda.release.version} + 8 diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 01939dff..2e7a2ee0 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,6 +7,13 @@ + + + Fix build for Java 8. + Found actual issue with Javac was in the pom.xml. + See #91. + + Fix build for Java 8. diff --git a/src/main/java/org/threeten/extra/Math.java b/src/main/java/org/threeten/extra/Math.java deleted file mode 100644 index 4779f1c3..00000000 --- a/src/main/java/org/threeten/extra/Math.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of JSR-310 nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.threeten.extra; - -/** - * Hack to avoid problems with java release flag. - */ -final class Math { - - static long abs(long a) { - return java.lang.Math.abs(a); - } - - static int abs(int a) { - return java.lang.Math.abs(a); - } - - //----------------------------------------------------------------------- - static long min(long a, long b) { - return java.lang.Math.min(a, b); - } - - static int min(int a, int b) { - return java.lang.Math.min(a, b); - } - - //----------------------------------------------------------------------- - static long max(long a, long b) { - return java.lang.Math.max(a, b); - } - - static int max(int a, int b) { - return java.lang.Math.max(a, b); - } - - //----------------------------------------------------------------------- - static long floorDiv(long a, long b) { - return java.lang.Math.floorDiv(a, b); - } - - static int floorDiv(int a, int b) { - return java.lang.Math.floorDiv(a, b); - } - - //----------------------------------------------------------------------- - static long floorMod(long a, long b) { - return java.lang.Math.floorMod(a, b); - } - - static int floorMod(int a, int b) { - return java.lang.Math.floorMod(a, b); - } - - //----------------------------------------------------------------------- - static long multiplyExact(long a, long b) { - return java.lang.Math.multiplyExact(a, b); - } - - static int multiplyExact(int a, int b) { - return java.lang.Math.multiplyExact(a, b); - } - - //----------------------------------------------------------------------- - static long addExact(long a, long b) { - return java.lang.Math.addExact(a, b); - } - - static int addExact(int a, int b) { - return java.lang.Math.addExact(a, b); - } - - //----------------------------------------------------------------------- - static long subtractExact(long a, long b) { - return java.lang.Math.subtractExact(a, b); - } - - static int subtractExact(int a, int b) { - return java.lang.Math.subtractExact(a, b); - } - - //----------------------------------------------------------------------- - static int toIntExact(long a) { - return java.lang.Math.toIntExact(a); - } - -} diff --git a/src/main/java/org/threeten/extra/chrono/Math.java b/src/main/java/org/threeten/extra/chrono/Math.java deleted file mode 100644 index 69780337..00000000 --- a/src/main/java/org/threeten/extra/chrono/Math.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of JSR-310 nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.threeten.extra.chrono; - -/** - * Hack to avoid problems with java release flag. - */ -final class Math { - - static long abs(long a) { - return java.lang.Math.abs(a); - } - - static int abs(int a) { - return java.lang.Math.abs(a); - } - - //----------------------------------------------------------------------- - static long min(long a, long b) { - return java.lang.Math.min(a, b); - } - - static int min(int a, int b) { - return java.lang.Math.min(a, b); - } - - //----------------------------------------------------------------------- - static long max(long a, long b) { - return java.lang.Math.max(a, b); - } - - static int max(int a, int b) { - return java.lang.Math.max(a, b); - } - - //----------------------------------------------------------------------- - static long floorDiv(long a, long b) { - return java.lang.Math.floorDiv(a, b); - } - - static int floorDiv(int a, int b) { - return java.lang.Math.floorDiv(a, b); - } - - //----------------------------------------------------------------------- - static long floorMod(long a, long b) { - return java.lang.Math.floorMod(a, b); - } - - static int floorMod(int a, int b) { - return java.lang.Math.floorMod(a, b); - } - - //----------------------------------------------------------------------- - static long multiplyExact(long a, long b) { - return java.lang.Math.multiplyExact(a, b); - } - - static int multiplyExact(int a, int b) { - return java.lang.Math.multiplyExact(a, b); - } - - //----------------------------------------------------------------------- - static long addExact(long a, long b) { - return java.lang.Math.addExact(a, b); - } - - static int addExact(int a, int b) { - return java.lang.Math.addExact(a, b); - } - - //----------------------------------------------------------------------- - static long subtractExact(long a, long b) { - return java.lang.Math.subtractExact(a, b); - } - - static int subtractExact(int a, int b) { - return java.lang.Math.subtractExact(a, b); - } - - //----------------------------------------------------------------------- - static int toIntExact(long a) { - return java.lang.Math.toIntExact(a); - } - -} diff --git a/src/main/java/org/threeten/extra/scale/Math.java b/src/main/java/org/threeten/extra/scale/Math.java deleted file mode 100644 index 7f007dda..00000000 --- a/src/main/java/org/threeten/extra/scale/Math.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of JSR-310 nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.threeten.extra.scale; - -/** - * Hack to avoid problems with java release flag. - */ -final class Math { - - static long abs(long a) { - return java.lang.Math.abs(a); - } - - static int abs(int a) { - return java.lang.Math.abs(a); - } - - //----------------------------------------------------------------------- - static long min(long a, long b) { - return java.lang.Math.min(a, b); - } - - static int min(int a, int b) { - return java.lang.Math.min(a, b); - } - - //----------------------------------------------------------------------- - static long max(long a, long b) { - return java.lang.Math.max(a, b); - } - - static int max(int a, int b) { - return java.lang.Math.max(a, b); - } - - //----------------------------------------------------------------------- - static long floorDiv(long a, long b) { - return java.lang.Math.floorDiv(a, b); - } - - static int floorDiv(int a, int b) { - return java.lang.Math.floorDiv(a, b); - } - - //----------------------------------------------------------------------- - static long floorMod(long a, long b) { - return java.lang.Math.floorMod(a, b); - } - - static int floorMod(int a, int b) { - return java.lang.Math.floorMod(a, b); - } - - //----------------------------------------------------------------------- - static long multiplyExact(long a, long b) { - return java.lang.Math.multiplyExact(a, b); - } - - static int multiplyExact(int a, int b) { - return java.lang.Math.multiplyExact(a, b); - } - - //----------------------------------------------------------------------- - static long addExact(long a, long b) { - return java.lang.Math.addExact(a, b); - } - - static int addExact(int a, int b) { - return java.lang.Math.addExact(a, b); - } - - //----------------------------------------------------------------------- - static long subtractExact(long a, long b) { - return java.lang.Math.subtractExact(a, b); - } - - static int subtractExact(int a, int b) { - return java.lang.Math.subtractExact(a, b); - } - - //----------------------------------------------------------------------- - static int toIntExact(long a) { - return java.lang.Math.toIntExact(a); - } - -} From 4cf8149cc4f76c85dcb39b98d82aecbc0f258600 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 23 Jan 2018 10:27:39 +0000 Subject: [PATCH 052/279] Prepare for v1.3.2 --- README.md | 4 ++-- pom.xml | 2 +- src/changes/changes.xml | 2 +- src/site/markdown/index.md | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 014f07cb..b492d019 100644 --- a/README.md +++ b/README.md @@ -17,12 +17,12 @@ Various documentation is available: ### Releases -Release 1.3.1 is the current release. +Release 1.3.2 is the current release. This release is considered stable and worthy of the 1.x tag. ThreeTen-Extra requires Java SE 8 or later and has no dependencies. -Available in the [Maven Central repository](http://search.maven.org/#artifactdetails|org.threeten|threeten-extra|1.3.1|jar) +Available in the [Maven Central repository](http://search.maven.org/#artifactdetails|org.threeten|threeten-extra|1.3.2|jar) ### Support diff --git a/pom.xml b/pom.xml index b3fb8aa9..e437b49a 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.4-SNAPSHOT + 1.3.2-SNAPSHOT Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later http://www.threeten.org/threeten-extra diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 2e7a2ee0..07a58f8e 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,7 +7,7 @@ - + Fix build for Java 8. Found actual issue with Javac was in the pom.xml. diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index 2152eb77..5e8148da 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -47,18 +47,18 @@ Various documentation is available: ## Releases -Release 1.3.1 is the current release. +Release 1.3.2 is the current release. This release is considered stable and worthy of the 1.x tag. ThreeTen-Extra requires Java SE 8 or later and has no [dependencies](dependencies.html). -Available in [Maven Central](http://search.maven.org/#artifactdetails%7Corg.threeten%7Cthreeten-extra%7C1.3.1%7Cjar). +Available in [Maven Central](http://search.maven.org/#artifactdetails%7Corg.threeten%7Cthreeten-extra%7C1.3.2%7Cjar). ```xml org.threeten threeten-extra - 1.3.1 + 1.3.2 ``` From 5579d9642d7dd95ff2e1a870e7e98d8cad84b4bf Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 23 Jan 2018 10:29:11 +0000 Subject: [PATCH 053/279] [maven-release-plugin] prepare release v1.3.2 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e437b49a..ceb84d92 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.3.2-SNAPSHOT + 1.3.2 Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later http://www.threeten.org/threeten-extra @@ -84,7 +84,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git http://github.com/ThreeTen/threeten-extra - HEAD + v1.3.2 ThreeTen.org From 3211fa1ca7b308e74a3c3084e84ff9d17268cfe4 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 23 Jan 2018 10:29:20 +0000 Subject: [PATCH 054/279] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index ceb84d92..b3fb8aa9 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.3.2 + 1.4-SNAPSHOT Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later http://www.threeten.org/threeten-extra @@ -84,7 +84,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git http://github.com/ThreeTen/threeten-extra - v1.3.2 + HEAD ThreeTen.org From db8cad9203f0e62af5c89b84902ab763a5902571 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Tue, 6 Feb 2018 12:09:43 +0100 Subject: [PATCH 055/279] Align doc with code --- src/main/java/org/threeten/extra/YearWeek.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/threeten/extra/YearWeek.java b/src/main/java/org/threeten/extra/YearWeek.java index b08ec591..3377a548 100644 --- a/src/main/java/org/threeten/extra/YearWeek.java +++ b/src/main/java/org/threeten/extra/YearWeek.java @@ -189,7 +189,7 @@ public static YearWeek of(int weekBasedYear, int week) { // from IsoFields in ThreeTen-Backport private static int weekRange(int weekBasedYear) { LocalDate date = LocalDate.of(weekBasedYear, 1, 1); - // 53 weeks if standard year starts on Thursday, or Wed in a leap year + // 53 weeks if year starts on Thursday, or Wed in a leap year if (date.getDayOfWeek() == THURSDAY || (date.getDayOfWeek() == WEDNESDAY && date.isLeapYear())) { return 53; } From 1d3fddcdc03c83376034199983b7dcc3e383c0e4 Mon Sep 17 00:00:00 2001 From: Laurie Callaghan Date: Wed, 7 Feb 2018 11:52:51 +1100 Subject: [PATCH 056/279] Overrride default `Require-Capabilities` manifest entry. The default uses the build JDK. Here we set it to Java 8. Fixes issue #92 --- pom.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pom.xml b/pom.xml index b3fb8aa9..5dbc83eb 100644 --- a/pom.xml +++ b/pom.xml @@ -174,6 +174,7 @@ org.threeten.extra,org.threeten.extra.chrono,org.threeten.extra.scale + ${require.capability} @@ -852,6 +853,8 @@ src/main/checkstyle/checkstyle.xml false + + osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))" UTF-8 UTF-8 From 2a6a40666ed3cda4f4a6b07ecaffa70bd3d9311f Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Wed, 7 Mar 2018 15:09:32 +0000 Subject: [PATCH 057/279] Fix Javadoc --- src/main/java/org/threeten/extra/LocalDateRange.java | 4 ++-- .../java/org/threeten/extra/chrono/Symmetry010Chronology.java | 2 +- .../java/org/threeten/extra/chrono/Symmetry454Chronology.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/threeten/extra/LocalDateRange.java b/src/main/java/org/threeten/extra/LocalDateRange.java index 5e397bea..30673f56 100644 --- a/src/main/java/org/threeten/extra/LocalDateRange.java +++ b/src/main/java/org/threeten/extra/LocalDateRange.java @@ -295,7 +295,7 @@ public boolean isUnboundedEnd() { *

    * For example, to adjust the start to one week earlier: *

    -     *  range = range.withStart(date -> date.minus(1, ChronoUnit.WEEKS));
    +     *  range = range.withStart(date -> date.minus(1, ChronoUnit.WEEKS));
          * 
    * * @param adjuster the adjuster to use, not null @@ -315,7 +315,7 @@ public LocalDateRange withStart(TemporalAdjuster adjuster) { *

    * For example, to adjust the end to one week later: *

    -     *  range = range.withEnd(date -> date.plus(1, ChronoUnit.WEEKS));
    +     *  range = range.withEnd(date -> date.plus(1, ChronoUnit.WEEKS));
          * 
    * * @param adjuster the adjuster to use, not null diff --git a/src/main/java/org/threeten/extra/chrono/Symmetry010Chronology.java b/src/main/java/org/threeten/extra/chrono/Symmetry010Chronology.java index 7d7827c5..3db1b5e5 100644 --- a/src/main/java/org/threeten/extra/chrono/Symmetry010Chronology.java +++ b/src/main/java/org/threeten/extra/chrono/Symmetry010Chronology.java @@ -73,7 +73,7 @@ *
  • day-of-year - There are 364 days in a standard Symmetry010 year and 371 days in a leap year. * The days are numbered accordingly. *
  • leap-year - Leap years occur every 5 or 6 years, evenly spread over 293 years according the formula: - * (52 > ((52 * year + 146) % 293)). + * (52 > ((52 * year + 146) % 293)). *
  • Week day - every year and every quarter starts on a Monday. * In each quarter, the first month starts on a Monday, the second month on a Wednesday and the 3rd on a Saturday. * There are no days outside of the week or month. diff --git a/src/main/java/org/threeten/extra/chrono/Symmetry454Chronology.java b/src/main/java/org/threeten/extra/chrono/Symmetry454Chronology.java index e707d078..80f565cd 100644 --- a/src/main/java/org/threeten/extra/chrono/Symmetry454Chronology.java +++ b/src/main/java/org/threeten/extra/chrono/Symmetry454Chronology.java @@ -72,7 +72,7 @@ *
  • day-of-year - There are 364 days in a standard Symmetry454 year and 371 days in a leap year. * The days are numbered accordingly. *
  • leap-year - Leap years occur every 5 or 6 years, evenly spread over 293 years according the formula: - * (52 > ((52 * year + 146) % 293)). + * (52 > ((52 * year + 146) % 293)). *
  • Week day - every month starts on a Monday. There are no days outside of the week or month. * * From ba8287341f347a60ad96ad6a3f3e1055ab1a7278 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Wed, 7 Mar 2018 15:10:32 +0000 Subject: [PATCH 058/279] Update Maven dependencies --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 5dbc83eb..15635f36 100644 --- a/pom.xml +++ b/pom.xml @@ -826,8 +826,8 @@ 3.0.2 3.0.0-M1 2.5 - 3.5 - 3.8 + 3.5.1 + 3.9.0 2.9 2.5.3 2.4 @@ -840,7 +840,7 @@ 1.1 0.8.0 1.6.8 - 3.1.1 + 3.1.3 1.8 1.8 From 74a8511574c18e77e87c7c59cac322e428a5a0bd Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Thu, 26 Apr 2018 16:11:36 +0100 Subject: [PATCH 059/279] Document OSGi data update --- src/changes/changes.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 07a58f8e..0c705298 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,6 +7,13 @@ + + + Fix OSGi for Java 9. + Now that the build is on Java 9, the OSGi data had to be updated. + See #92, #94. + + Fix build for Java 8. From fd443af835e359db97684759fdf7531efda033db Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Thu, 26 Apr 2018 16:13:00 +0100 Subject: [PATCH 060/279] Handle config file for Java 9 Java 9 resource loading has changed --- pom.xml | 4 ++-- src/changes/changes.xml | 6 +++++ src/main/java/module-info.java | 12 ++++++++++ .../threeten/extra/scale/SystemUtcRules.java | 24 ++++++++++++++++++- .../org/threeten/extra/scale/UtcRules.java | 8 ++++--- 5 files changed, 48 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 15635f36..64d25494 100644 --- a/pom.xml +++ b/pom.xml @@ -835,8 +835,8 @@ 3.4 3.0.1 - 2.20.1 - 2.20.1 + 2.21.0 + 2.21.0 1.1 0.8.0 1.6.8 diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 0c705298..2dc6a353 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -8,6 +8,12 @@ + + Fix build for Java 9. + Resource files cannot be read from other modules in Java 9. + As such, the `LeapSeconds.txt` file has moved to be under META-INF, + `META-INF/org/threeten/extra/scale/LeapSeconds.txt`. + Fix OSGi for Java 9. Now that the build is on Java 9, the OSGi data had to be updated. diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 2e23120f..7065602a 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -44,4 +44,16 @@ exports org.threeten.extra.chrono; exports org.threeten.extra.scale; + // provide the services + provides java.time.chrono.Chronology + with org.threeten.extra.chrono.BritishCutoverChronology, + org.threeten.extra.chrono.CopticChronology, + org.threeten.extra.chrono.DiscordianChronology, + org.threeten.extra.chrono.EthiopicChronology, + org.threeten.extra.chrono.InternationalFixedChronology, + org.threeten.extra.chrono.JulianChronology, + org.threeten.extra.chrono.PaxChronology, + org.threeten.extra.chrono.Symmetry010Chronology, + org.threeten.extra.chrono.Symmetry454Chronology; + } diff --git a/src/main/java/org/threeten/extra/scale/SystemUtcRules.java b/src/main/java/org/threeten/extra/scale/SystemUtcRules.java index ecd4c1fb..f1ac8dbe 100644 --- a/src/main/java/org/threeten/extra/scale/SystemUtcRules.java +++ b/src/main/java/org/threeten/extra/scale/SystemUtcRules.java @@ -58,6 +58,10 @@ */ final class SystemUtcRules extends UtcRules implements Serializable { + /** + * The leap seconds config file. + */ + private static final String LEAP_SECONDS_TXT = "org/threeten/extra/scale/LeapSeconds.txt"; /** * Leap second file format. */ @@ -213,7 +217,17 @@ private static Data loadLeapSeconds() { Data bestData = null; URL url = null; try { - Enumeration en = Thread.currentThread().getContextClassLoader().getResources("org/threeten/extra/scale/LeapSeconds.txt"); + // this is the new location of the file, working on Java 8, Java 9 class path and Java 9 module path + Enumeration en = Thread.currentThread().getContextClassLoader().getResources("META-INF/" + LEAP_SECONDS_TXT); + while (en.hasMoreElements()) { + url = en.nextElement(); + Data candidate = loadLeapSeconds(url); + if (bestData == null || candidate.getNewestDate() > bestData.getNewestDate()) { + bestData = candidate; + } + } + // this location does not work on Java 9 module path because the resource is encapsulated + en = Thread.currentThread().getContextClassLoader().getResources(LEAP_SECONDS_TXT); while (en.hasMoreElements()) { url = en.nextElement(); Data candidate = loadLeapSeconds(url); @@ -221,6 +235,14 @@ private static Data loadLeapSeconds() { bestData = candidate; } } + // this location is the canonical one, and class-based loading works on Java 9 module path + url = SystemUtcRules.class.getResource("/" + LEAP_SECONDS_TXT); + if (url != null) { + Data candidate = loadLeapSeconds(url); + if (bestData == null || candidate.getNewestDate() > bestData.getNewestDate()) { + bestData = candidate; + } + } } catch (Exception ex) { throw new RuntimeException("Unable to load time-zone rule data: " + url, ex); } diff --git a/src/main/java/org/threeten/extra/scale/UtcRules.java b/src/main/java/org/threeten/extra/scale/UtcRules.java index a977fb71..212ffc2a 100644 --- a/src/main/java/org/threeten/extra/scale/UtcRules.java +++ b/src/main/java/org/threeten/extra/scale/UtcRules.java @@ -45,9 +45,11 @@ * These are used by default in {@code UtcInstant} and {@code TaiInstant}. * Using other rules requires manual use of this class. *

    - * The system rules can be updated using the file {@code org/threeten/extra/scale/LeapSeconds.txt}. - * You can create your own version of this file and place it on the classpath - * and it will be used. + * The system rules can be updated using a {@code LeapSeconds.txt}} file. + * You can create your own version of this file and place it in on the classpath + * and it will be used. Due to Java 9 module restrictions, the file is located + * under META-INF to avoid module encapsulation problems - + * {@code META-INF/org/threeten/extra/scale/LeapSeconds.txt}. * *

    Implementation Requirements:

    * This is an abstract class and must be implemented with care From 33cb9dbe0beeced0bc7066fed9d01c34be2ce520 Mon Sep 17 00:00:00 2001 From: perceptron8 Date: Fri, 4 May 2018 20:26:24 +0200 Subject: [PATCH 061/279] Fix assertions order --- .../java/org/threeten/extra/TestAmPm.java | 106 ++-- .../org/threeten/extra/TestDayOfMonth.java | 390 ++++++------- .../org/threeten/extra/TestDayOfYear.java | 150 ++--- .../java/org/threeten/extra/TestDays.java | 50 +- .../java/org/threeten/extra/TestHours.java | 34 +- .../java/org/threeten/extra/TestInterval.java | 346 +++++------ .../threeten/extra/TestLocalDateRange.java | 536 +++++++++--------- .../java/org/threeten/extra/TestMinutes.java | 46 +- .../java/org/threeten/extra/TestMonths.java | 50 +- .../org/threeten/extra/TestMutableClock.java | 112 ++-- .../org/threeten/extra/TestPackedFields.java | 88 +-- .../threeten/extra/TestPeriodDuration.java | 160 +++--- .../java/org/threeten/extra/TestQuarter.java | 194 +++---- .../java/org/threeten/extra/TestSeconds.java | 60 +- .../org/threeten/extra/TestTemporals.java | 60 +- .../java/org/threeten/extra/TestWeeks.java | 40 +- .../org/threeten/extra/TestYearQuarter.java | 456 +++++++-------- .../java/org/threeten/extra/TestYearWeek.java | 308 +++++----- .../java/org/threeten/extra/TestYears.java | 42 +- .../chrono/TestAccountingChronology.java | 177 +++--- .../TestAccountingChronologyBuilder.java | 58 +- .../chrono/TestBritishCutoverChronology.java | 237 ++++---- .../extra/chrono/TestCopticChronology.java | 179 +++--- .../chrono/TestDiscordianChronology.java | 197 +++---- .../extra/chrono/TestEthiopicChronology.java | 179 +++--- .../TestInternationalFixedChronology.java | 148 ++--- .../extra/chrono/TestJulianChronology.java | 179 +++--- .../extra/chrono/TestPaxChronology.java | 191 +++---- .../chrono/TestSymmetry010Chronology.java | 150 ++--- .../chrono/TestSymmetry454Chronology.java | 150 ++--- .../threeten/extra/scale/TestTaiInstant.java | 126 ++-- .../threeten/extra/scale/TestUtcInstant.java | 122 ++-- .../threeten/extra/scale/TestUtcRules.java | 108 ++-- 33 files changed, 2718 insertions(+), 2711 deletions(-) diff --git a/src/test/java/org/threeten/extra/TestAmPm.java b/src/test/java/org/threeten/extra/TestAmPm.java index 44748c41..302a0547 100644 --- a/src/test/java/org/threeten/extra/TestAmPm.java +++ b/src/test/java/org/threeten/extra/TestAmPm.java @@ -98,7 +98,7 @@ public void test_interfaces() { public void test_of_int_singleton_equals() { for (int i = 0; i <= 1; i++) { AmPm test = AmPm.of(i); - assertEquals(test.getValue(), i); + assertEquals(i, test.getValue()); } } @@ -118,10 +118,10 @@ public void test_of_int_valueTooHigh() { @Test public void test_ofHour_int_singleton() { for (int i = 0; i < 12; i++) { - assertEquals(AmPm.ofHour(i), AmPm.AM); + assertEquals(AmPm.AM, AmPm.ofHour(i)); } for (int i = 12; i < 24; i++) { - assertEquals(AmPm.ofHour(i), AmPm.PM); + assertEquals(AmPm.PM, AmPm.ofHour(i)); } } @@ -140,8 +140,8 @@ public void test_ofHour_int_valueTooHigh() { //----------------------------------------------------------------------- @Test public void test_from_TemporalAccessor() { - assertEquals(AmPm.from(LocalTime.of(8, 30)), AmPm.AM); - assertEquals(AmPm.from(LocalTime.of(17, 30)), AmPm.PM); + assertEquals(AmPm.AM, AmPm.from(LocalTime.of(8, 30))); + assertEquals(AmPm.PM, AmPm.from(LocalTime.of(17, 30))); } @Test(expected = DateTimeException.class) @@ -159,7 +159,7 @@ public void test_from_TemporalAccessor_null() { //----------------------------------------------------------------------- @Test public void test_getDisplayName() { - assertEquals(AmPm.AM.getDisplayName(TextStyle.SHORT, Locale.US), "AM"); + assertEquals("AM", AmPm.AM.getDisplayName(TextStyle.SHORT, Locale.US)); } @Test(expected = NullPointerException.class) @@ -178,37 +178,37 @@ public void test_getDisplayName_nullLocale() { @Test public void test_isSupported() { AmPm test = AmPm.AM; - assertEquals(test.isSupported(null), false); - assertEquals(test.isSupported(NANO_OF_SECOND), false); - assertEquals(test.isSupported(NANO_OF_DAY), false); - assertEquals(test.isSupported(MICRO_OF_SECOND), false); - assertEquals(test.isSupported(MICRO_OF_DAY), false); - assertEquals(test.isSupported(MILLI_OF_SECOND), false); - assertEquals(test.isSupported(MILLI_OF_DAY), false); - assertEquals(test.isSupported(SECOND_OF_MINUTE), false); - assertEquals(test.isSupported(SECOND_OF_DAY), false); - assertEquals(test.isSupported(MINUTE_OF_HOUR), false); - assertEquals(test.isSupported(MINUTE_OF_DAY), false); - assertEquals(test.isSupported(HOUR_OF_AMPM), false); - assertEquals(test.isSupported(CLOCK_HOUR_OF_AMPM), false); - assertEquals(test.isSupported(HOUR_OF_DAY), false); - assertEquals(test.isSupported(CLOCK_HOUR_OF_DAY), false); - assertEquals(test.isSupported(AMPM_OF_DAY), true); - assertEquals(test.isSupported(DAY_OF_WEEK), false); - assertEquals(test.isSupported(ALIGNED_DAY_OF_WEEK_IN_MONTH), false); - assertEquals(test.isSupported(ALIGNED_DAY_OF_WEEK_IN_YEAR), false); - assertEquals(test.isSupported(DAY_OF_MONTH), false); - assertEquals(test.isSupported(DAY_OF_YEAR), false); - assertEquals(test.isSupported(EPOCH_DAY), false); - assertEquals(test.isSupported(ALIGNED_WEEK_OF_MONTH), false); - assertEquals(test.isSupported(ALIGNED_WEEK_OF_YEAR), false); - assertEquals(test.isSupported(MONTH_OF_YEAR), false); - assertEquals(test.isSupported(PROLEPTIC_MONTH), false); - assertEquals(test.isSupported(YEAR_OF_ERA), false); - assertEquals(test.isSupported(YEAR), false); - assertEquals(test.isSupported(ERA), false); - assertEquals(test.isSupported(INSTANT_SECONDS), false); - assertEquals(test.isSupported(OFFSET_SECONDS), false); + assertEquals(false, test.isSupported(null)); + assertEquals(false, test.isSupported(NANO_OF_SECOND)); + assertEquals(false, test.isSupported(NANO_OF_DAY)); + assertEquals(false, test.isSupported(MICRO_OF_SECOND)); + assertEquals(false, test.isSupported(MICRO_OF_DAY)); + assertEquals(false, test.isSupported(MILLI_OF_SECOND)); + assertEquals(false, test.isSupported(MILLI_OF_DAY)); + assertEquals(false, test.isSupported(SECOND_OF_MINUTE)); + assertEquals(false, test.isSupported(SECOND_OF_DAY)); + assertEquals(false, test.isSupported(MINUTE_OF_HOUR)); + assertEquals(false, test.isSupported(MINUTE_OF_DAY)); + assertEquals(false, test.isSupported(HOUR_OF_AMPM)); + assertEquals(false, test.isSupported(CLOCK_HOUR_OF_AMPM)); + assertEquals(false, test.isSupported(HOUR_OF_DAY)); + assertEquals(false, test.isSupported(CLOCK_HOUR_OF_DAY)); + assertEquals(true, test.isSupported(AMPM_OF_DAY)); + assertEquals(false, test.isSupported(DAY_OF_WEEK)); + assertEquals(false, test.isSupported(ALIGNED_DAY_OF_WEEK_IN_MONTH)); + assertEquals(false, test.isSupported(ALIGNED_DAY_OF_WEEK_IN_YEAR)); + assertEquals(false, test.isSupported(DAY_OF_MONTH)); + assertEquals(false, test.isSupported(DAY_OF_YEAR)); + assertEquals(false, test.isSupported(EPOCH_DAY)); + assertEquals(false, test.isSupported(ALIGNED_WEEK_OF_MONTH)); + assertEquals(false, test.isSupported(ALIGNED_WEEK_OF_YEAR)); + assertEquals(false, test.isSupported(MONTH_OF_YEAR)); + assertEquals(false, test.isSupported(PROLEPTIC_MONTH)); + assertEquals(false, test.isSupported(YEAR_OF_ERA)); + assertEquals(false, test.isSupported(YEAR)); + assertEquals(false, test.isSupported(ERA)); + assertEquals(false, test.isSupported(INSTANT_SECONDS)); + assertEquals(false, test.isSupported(OFFSET_SECONDS)); } //----------------------------------------------------------------------- @@ -216,7 +216,7 @@ public void test_isSupported() { //----------------------------------------------------------------------- @Test public void test_range() { - assertEquals(AmPm.AM.range(AMPM_OF_DAY), AMPM_OF_DAY.range()); + assertEquals(AMPM_OF_DAY.range(), AmPm.AM.range(AMPM_OF_DAY)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -234,8 +234,8 @@ public void test_range_null() { //----------------------------------------------------------------------- @Test public void test_get() { - assertEquals(AmPm.AM.get(AMPM_OF_DAY), 0); - assertEquals(AmPm.PM.get(AMPM_OF_DAY), 1); + assertEquals(0, AmPm.AM.get(AMPM_OF_DAY)); + assertEquals(1, AmPm.PM.get(AMPM_OF_DAY)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -253,8 +253,8 @@ public void test_get_null() { //----------------------------------------------------------------------- @Test public void test_getLong() { - assertEquals(AmPm.AM.getLong(AMPM_OF_DAY), 0); - assertEquals(AmPm.PM.getLong(AMPM_OF_DAY), 1); + assertEquals(0, AmPm.AM.getLong(AMPM_OF_DAY)); + assertEquals(1, AmPm.PM.getLong(AMPM_OF_DAY)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -272,13 +272,13 @@ public void test_getLong_null() { //----------------------------------------------------------------------- @Test public void test_query() { - assertEquals(AmPm.AM.query(TemporalQueries.chronology()), null); - assertEquals(AmPm.AM.query(TemporalQueries.localDate()), null); - assertEquals(AmPm.AM.query(TemporalQueries.localTime()), null); - assertEquals(AmPm.AM.query(TemporalQueries.offset()), null); - assertEquals(AmPm.AM.query(TemporalQueries.precision()), HALF_DAYS); - assertEquals(AmPm.AM.query(TemporalQueries.zone()), null); - assertEquals(AmPm.AM.query(TemporalQueries.zoneId()), null); + assertEquals(null, AmPm.AM.query(TemporalQueries.chronology())); + assertEquals(null, AmPm.AM.query(TemporalQueries.localDate())); + assertEquals(null, AmPm.AM.query(TemporalQueries.localTime())); + assertEquals(null, AmPm.AM.query(TemporalQueries.offset())); + assertEquals(HALF_DAYS, AmPm.AM.query(TemporalQueries.precision())); + assertEquals(null, AmPm.AM.query(TemporalQueries.zone())); + assertEquals(null, AmPm.AM.query(TemporalQueries.zoneId())); } //----------------------------------------------------------------------- @@ -286,8 +286,8 @@ public void test_query() { //----------------------------------------------------------------------- @Test public void test_toString() { - assertEquals(AmPm.AM.toString(), "AM"); - assertEquals(AmPm.PM.toString(), "PM"); + assertEquals("AM", AmPm.AM.toString()); + assertEquals("PM", AmPm.PM.toString()); } //----------------------------------------------------------------------- @@ -295,8 +295,8 @@ public void test_toString() { //----------------------------------------------------------------------- @Test public void test_enum() { - assertEquals(AmPm.valueOf("AM"), AmPm.AM); - assertEquals(AmPm.values()[0], AmPm.AM); + assertEquals(AmPm.AM, AmPm.valueOf("AM")); + assertEquals(AmPm.AM, AmPm.values()[0]); } } diff --git a/src/test/java/org/threeten/extra/TestDayOfMonth.java b/src/test/java/org/threeten/extra/TestDayOfMonth.java index e3e038d0..dffb0bb2 100644 --- a/src/test/java/org/threeten/extra/TestDayOfMonth.java +++ b/src/test/java/org/threeten/extra/TestDayOfMonth.java @@ -128,7 +128,7 @@ public void test_serialization() throws IOException, ClassNotFoundException { oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertEquals(ois.readObject(), test); + assertEquals(test, ois.readObject()); } } @@ -139,8 +139,8 @@ public void test_serialization() throws IOException, ClassNotFoundException { public void test_of_int_singleton() { for (int i = 1; i <= MAX_LENGTH; i++) { DayOfMonth test = DayOfMonth.of(i); - assertEquals(test.getValue(), i); - assertEquals(DayOfMonth.of(i), test); + assertEquals(i, test.getValue()); + assertEquals(test, DayOfMonth.of(i)); } } @@ -161,51 +161,51 @@ public void test_of_int_tooHigh() { public void test_from_TemporalAccessor_notLeapYear() { LocalDate date = LocalDate.of(2007, 1, 1); for (int i = 1; i <= 31; i++) { // Jan - assertEquals(DayOfMonth.from(date).getValue(), i); + assertEquals(i, DayOfMonth.from(date).getValue()); date = date.plusDays(1); } for (int i = 1; i <= 28; i++) { // Feb - assertEquals(DayOfMonth.from(date).getValue(), i); + assertEquals(i, DayOfMonth.from(date).getValue()); date = date.plusDays(1); } for (int i = 1; i <= 31; i++) { // Mar - assertEquals(DayOfMonth.from(date).getValue(), i); + assertEquals(i, DayOfMonth.from(date).getValue()); date = date.plusDays(1); } for (int i = 1; i <= 30; i++) { // Apr - assertEquals(DayOfMonth.from(date).getValue(), i); + assertEquals(i, DayOfMonth.from(date).getValue()); date = date.plusDays(1); } for (int i = 1; i <= 31; i++) { // May - assertEquals(DayOfMonth.from(date).getValue(), i); + assertEquals(i, DayOfMonth.from(date).getValue()); date = date.plusDays(1); } for (int i = 1; i <= 30; i++) { // Jun - assertEquals(DayOfMonth.from(date).getValue(), i); + assertEquals(i, DayOfMonth.from(date).getValue()); date = date.plusDays(1); } for (int i = 1; i <= 31; i++) { // Jul - assertEquals(DayOfMonth.from(date).getValue(), i); + assertEquals(i, DayOfMonth.from(date).getValue()); date = date.plusDays(1); } for (int i = 1; i <= 31; i++) { // Aug - assertEquals(DayOfMonth.from(date).getValue(), i); + assertEquals(i, DayOfMonth.from(date).getValue()); date = date.plusDays(1); } for (int i = 1; i <= 30; i++) { // Sep - assertEquals(DayOfMonth.from(date).getValue(), i); + assertEquals(i, DayOfMonth.from(date).getValue()); date = date.plusDays(1); } for (int i = 1; i <= 31; i++) { // Oct - assertEquals(DayOfMonth.from(date).getValue(), i); + assertEquals(i, DayOfMonth.from(date).getValue()); date = date.plusDays(1); } for (int i = 1; i <= 30; i++) { // Nov - assertEquals(DayOfMonth.from(date).getValue(), i); + assertEquals(i, DayOfMonth.from(date).getValue()); date = date.plusDays(1); } for (int i = 1; i <= 31; i++) { // Dec - assertEquals(DayOfMonth.from(date).getValue(), i); + assertEquals(i, DayOfMonth.from(date).getValue()); date = date.plusDays(1); } } @@ -214,15 +214,15 @@ public void test_from_TemporalAccessor_notLeapYear() { public void test_from_TemporalAccessor_leapYear() { LocalDate date = LocalDate.of(2008, 1, 1); for (int i = 1; i <= 31; i++) { // Jan - assertEquals(DayOfMonth.from(date).getValue(), i); + assertEquals(i, DayOfMonth.from(date).getValue()); date = date.plusDays(1); } for (int i = 1; i <= 29; i++) { // Feb - assertEquals(DayOfMonth.from(date).getValue(), i); + assertEquals(i, DayOfMonth.from(date).getValue()); date = date.plusDays(1); } for (int i = 1; i <= 31; i++) { // Mar - assertEquals(DayOfMonth.from(date).getValue(), i); + assertEquals(i, DayOfMonth.from(date).getValue()); date = date.plusDays(1); } } @@ -240,7 +240,7 @@ public void test_from_TemporalAccessor_null() { @Test public void test_from_parse_CharSequence() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d"); - assertEquals(formatter.parse("3", DayOfMonth::from), DayOfMonth.of(3)); + assertEquals(DayOfMonth.of(3), formatter.parse("3", DayOfMonth::from)); } //----------------------------------------------------------------------- @@ -248,37 +248,37 @@ public void test_from_parse_CharSequence() { //----------------------------------------------------------------------- @Test public void test_isSupported() { - assertEquals(TEST.isSupported((TemporalField) null), false); - assertEquals(TEST.isSupported(NANO_OF_SECOND), false); - assertEquals(TEST.isSupported(NANO_OF_DAY), false); - assertEquals(TEST.isSupported(MICRO_OF_SECOND), false); - assertEquals(TEST.isSupported(MICRO_OF_DAY), false); - assertEquals(TEST.isSupported(MILLI_OF_SECOND), false); - assertEquals(TEST.isSupported(MILLI_OF_DAY), false); - assertEquals(TEST.isSupported(SECOND_OF_MINUTE), false); - assertEquals(TEST.isSupported(SECOND_OF_DAY), false); - assertEquals(TEST.isSupported(MINUTE_OF_HOUR), false); - assertEquals(TEST.isSupported(MINUTE_OF_DAY), false); - assertEquals(TEST.isSupported(HOUR_OF_AMPM), false); - assertEquals(TEST.isSupported(CLOCK_HOUR_OF_AMPM), false); - assertEquals(TEST.isSupported(HOUR_OF_DAY), false); - assertEquals(TEST.isSupported(CLOCK_HOUR_OF_DAY), false); - assertEquals(TEST.isSupported(AMPM_OF_DAY), false); - assertEquals(TEST.isSupported(DAY_OF_WEEK), false); - assertEquals(TEST.isSupported(ALIGNED_DAY_OF_WEEK_IN_MONTH), false); - assertEquals(TEST.isSupported(ALIGNED_DAY_OF_WEEK_IN_YEAR), false); - assertEquals(TEST.isSupported(DAY_OF_MONTH), true); - assertEquals(TEST.isSupported(DAY_OF_YEAR), false); - assertEquals(TEST.isSupported(EPOCH_DAY), false); - assertEquals(TEST.isSupported(ALIGNED_WEEK_OF_MONTH), false); - assertEquals(TEST.isSupported(ALIGNED_WEEK_OF_YEAR), false); - assertEquals(TEST.isSupported(MONTH_OF_YEAR), false); - assertEquals(TEST.isSupported(PROLEPTIC_MONTH), false); - assertEquals(TEST.isSupported(YEAR_OF_ERA), false); - assertEquals(TEST.isSupported(YEAR), false); - assertEquals(TEST.isSupported(ERA), false); - assertEquals(TEST.isSupported(INSTANT_SECONDS), false); - assertEquals(TEST.isSupported(OFFSET_SECONDS), false); + assertEquals(false, TEST.isSupported((TemporalField) null)); + assertEquals(false, TEST.isSupported(NANO_OF_SECOND)); + assertEquals(false, TEST.isSupported(NANO_OF_DAY)); + assertEquals(false, TEST.isSupported(MICRO_OF_SECOND)); + assertEquals(false, TEST.isSupported(MICRO_OF_DAY)); + assertEquals(false, TEST.isSupported(MILLI_OF_SECOND)); + assertEquals(false, TEST.isSupported(MILLI_OF_DAY)); + assertEquals(false, TEST.isSupported(SECOND_OF_MINUTE)); + assertEquals(false, TEST.isSupported(SECOND_OF_DAY)); + assertEquals(false, TEST.isSupported(MINUTE_OF_HOUR)); + assertEquals(false, TEST.isSupported(MINUTE_OF_DAY)); + assertEquals(false, TEST.isSupported(HOUR_OF_AMPM)); + assertEquals(false, TEST.isSupported(CLOCK_HOUR_OF_AMPM)); + assertEquals(false, TEST.isSupported(HOUR_OF_DAY)); + assertEquals(false, TEST.isSupported(CLOCK_HOUR_OF_DAY)); + assertEquals(false, TEST.isSupported(AMPM_OF_DAY)); + assertEquals(false, TEST.isSupported(DAY_OF_WEEK)); + assertEquals(false, TEST.isSupported(ALIGNED_DAY_OF_WEEK_IN_MONTH)); + assertEquals(false, TEST.isSupported(ALIGNED_DAY_OF_WEEK_IN_YEAR)); + assertEquals(true, TEST.isSupported(DAY_OF_MONTH)); + assertEquals(false, TEST.isSupported(DAY_OF_YEAR)); + assertEquals(false, TEST.isSupported(EPOCH_DAY)); + assertEquals(false, TEST.isSupported(ALIGNED_WEEK_OF_MONTH)); + assertEquals(false, TEST.isSupported(ALIGNED_WEEK_OF_YEAR)); + assertEquals(false, TEST.isSupported(MONTH_OF_YEAR)); + assertEquals(false, TEST.isSupported(PROLEPTIC_MONTH)); + assertEquals(false, TEST.isSupported(YEAR_OF_ERA)); + assertEquals(false, TEST.isSupported(YEAR)); + assertEquals(false, TEST.isSupported(ERA)); + assertEquals(false, TEST.isSupported(INSTANT_SECONDS)); + assertEquals(false, TEST.isSupported(OFFSET_SECONDS)); } //----------------------------------------------------------------------- @@ -286,7 +286,7 @@ public void test_isSupported() { //----------------------------------------------------------------------- @Test public void test_range() { - assertEquals(TEST.range(DAY_OF_MONTH), DAY_OF_MONTH.range()); + assertEquals(DAY_OF_MONTH.range(), TEST.range(DAY_OF_MONTH)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -304,7 +304,7 @@ public void test_range_null() { //----------------------------------------------------------------------- @Test public void test_get() { - assertEquals(TEST.get(DAY_OF_MONTH), 12); + assertEquals(12, TEST.get(DAY_OF_MONTH)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -322,7 +322,7 @@ public void test_get_null() { //----------------------------------------------------------------------- @Test public void test_getLong() { - assertEquals(TEST.getLong(DAY_OF_MONTH), 12L); + assertEquals(12L, TEST.getLong(DAY_OF_MONTH)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -341,70 +341,70 @@ public void test_getLong_null() { @Test public void test_isValidYearMonth_31() { DayOfMonth test = DayOfMonth.of(31); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 1)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 2)), false); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 3)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 4)), false); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 5)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 6)), false); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 7)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 8)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 9)), false); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 10)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 11)), false); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 12)), true); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 1))); + assertEquals(false, test.isValidYearMonth(YearMonth.of(2012, 2))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 3))); + assertEquals(false, test.isValidYearMonth(YearMonth.of(2012, 4))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 5))); + assertEquals(false, test.isValidYearMonth(YearMonth.of(2012, 6))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 7))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 8))); + assertEquals(false, test.isValidYearMonth(YearMonth.of(2012, 9))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 10))); + assertEquals(false, test.isValidYearMonth(YearMonth.of(2012, 11))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 12))); } @Test public void test_isValidYearMonth_30() { DayOfMonth test = DayOfMonth.of(30); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 1)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 2)), false); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 3)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 4)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 5)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 6)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 7)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 8)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 9)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 10)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 11)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 12)), true); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 1))); + assertEquals(false, test.isValidYearMonth(YearMonth.of(2012, 2))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 3))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 4))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 5))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 6))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 7))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 8))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 9))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 10))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 11))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 12))); } @Test public void test_isValidYearMonth_29() { DayOfMonth test = DayOfMonth.of(29); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 1)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 2)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 3)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 4)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 5)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 6)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 7)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 8)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 9)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 10)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 11)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 12)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2011, 2)), false); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 1))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 2))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 3))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 4))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 5))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 6))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 7))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 8))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 9))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 10))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 11))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 12))); + assertEquals(false, test.isValidYearMonth(YearMonth.of(2011, 2))); } @Test public void test_isValidYearMonth_28() { DayOfMonth test = DayOfMonth.of(28); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 1)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 2)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 3)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 4)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 5)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 6)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 7)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 8)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 9)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 10)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 11)), true); - assertEquals(test.isValidYearMonth(YearMonth.of(2012, 12)), true); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 1))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 2))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 3))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 4))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 5))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 6))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 7))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 8))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 9))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 10))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 11))); + assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 12))); } //----------------------------------------------------------------------- @@ -412,13 +412,13 @@ public void test_isValidYearMonth_28() { //----------------------------------------------------------------------- @Test public void test_query() { - assertEquals(TEST.query(TemporalQueries.chronology()), IsoChronology.INSTANCE); - assertEquals(TEST.query(TemporalQueries.localDate()), null); - assertEquals(TEST.query(TemporalQueries.localTime()), null); - assertEquals(TEST.query(TemporalQueries.offset()), null); - assertEquals(TEST.query(TemporalQueries.precision()), null); - assertEquals(TEST.query(TemporalQueries.zone()), null); - assertEquals(TEST.query(TemporalQueries.zoneId()), null); + assertEquals(IsoChronology.INSTANCE, TEST.query(TemporalQueries.chronology())); + assertEquals(null, TEST.query(TemporalQueries.localDate())); + assertEquals(null, TEST.query(TemporalQueries.localTime())); + assertEquals(null, TEST.query(TemporalQueries.offset())); + assertEquals(null, TEST.query(TemporalQueries.precision())); + assertEquals(null, TEST.query(TemporalQueries.zone())); + assertEquals(null, TEST.query(TemporalQueries.zoneId())); } //----------------------------------------------------------------------- @@ -430,7 +430,7 @@ public void test_adjustInto() { LocalDate expected = base; for (int i = 1; i <= MAX_LENGTH; i++) { // Jan Temporal result = DayOfMonth.of(i).adjustInto(base); - assertEquals(result, expected); + assertEquals(expected, result); expected = expected.plusDays(1); } } @@ -460,35 +460,35 @@ public void test_adjustInto_null() { @Test public void test_atMonth_Month_31() { DayOfMonth test = DayOfMonth.of(31); - assertEquals(test.atMonth(JANUARY), MonthDay.of(1, 31)); - assertEquals(test.atMonth(FEBRUARY), MonthDay.of(2, 29)); - assertEquals(test.atMonth(MARCH), MonthDay.of(3, 31)); - assertEquals(test.atMonth(APRIL), MonthDay.of(4, 30)); - assertEquals(test.atMonth(MAY), MonthDay.of(5, 31)); - assertEquals(test.atMonth(JUNE), MonthDay.of(6, 30)); - assertEquals(test.atMonth(JULY), MonthDay.of(7, 31)); - assertEquals(test.atMonth(AUGUST), MonthDay.of(8, 31)); - assertEquals(test.atMonth(SEPTEMBER), MonthDay.of(9, 30)); - assertEquals(test.atMonth(OCTOBER), MonthDay.of(10, 31)); - assertEquals(test.atMonth(NOVEMBER), MonthDay.of(11, 30)); - assertEquals(test.atMonth(DECEMBER), MonthDay.of(12, 31)); + assertEquals(MonthDay.of(1, 31), test.atMonth(JANUARY)); + assertEquals(MonthDay.of(2, 29), test.atMonth(FEBRUARY)); + assertEquals(MonthDay.of(3, 31), test.atMonth(MARCH)); + assertEquals(MonthDay.of(4, 30), test.atMonth(APRIL)); + assertEquals(MonthDay.of(5, 31), test.atMonth(MAY)); + assertEquals(MonthDay.of(6, 30), test.atMonth(JUNE)); + assertEquals(MonthDay.of(7, 31), test.atMonth(JULY)); + assertEquals(MonthDay.of(8, 31), test.atMonth(AUGUST)); + assertEquals(MonthDay.of(9, 30), test.atMonth(SEPTEMBER)); + assertEquals(MonthDay.of(10, 31), test.atMonth(OCTOBER)); + assertEquals(MonthDay.of(11, 30), test.atMonth(NOVEMBER)); + assertEquals(MonthDay.of(12, 31), test.atMonth(DECEMBER)); } @Test public void test_atMonth_Month_28() { DayOfMonth test = DayOfMonth.of(28); - assertEquals(test.atMonth(JANUARY), MonthDay.of(1, 28)); - assertEquals(test.atMonth(FEBRUARY), MonthDay.of(2, 28)); - assertEquals(test.atMonth(MARCH), MonthDay.of(3, 28)); - assertEquals(test.atMonth(APRIL), MonthDay.of(4, 28)); - assertEquals(test.atMonth(MAY), MonthDay.of(5, 28)); - assertEquals(test.atMonth(JUNE), MonthDay.of(6, 28)); - assertEquals(test.atMonth(JULY), MonthDay.of(7, 28)); - assertEquals(test.atMonth(AUGUST), MonthDay.of(8, 28)); - assertEquals(test.atMonth(SEPTEMBER), MonthDay.of(9, 28)); - assertEquals(test.atMonth(OCTOBER), MonthDay.of(10, 28)); - assertEquals(test.atMonth(NOVEMBER), MonthDay.of(11, 28)); - assertEquals(test.atMonth(DECEMBER), MonthDay.of(12, 28)); + assertEquals(MonthDay.of(1, 28), test.atMonth(JANUARY)); + assertEquals(MonthDay.of(2, 28), test.atMonth(FEBRUARY)); + assertEquals(MonthDay.of(3, 28), test.atMonth(MARCH)); + assertEquals(MonthDay.of(4, 28), test.atMonth(APRIL)); + assertEquals(MonthDay.of(5, 28), test.atMonth(MAY)); + assertEquals(MonthDay.of(6, 28), test.atMonth(JUNE)); + assertEquals(MonthDay.of(7, 28), test.atMonth(JULY)); + assertEquals(MonthDay.of(8, 28), test.atMonth(AUGUST)); + assertEquals(MonthDay.of(9, 28), test.atMonth(SEPTEMBER)); + assertEquals(MonthDay.of(10, 28), test.atMonth(OCTOBER)); + assertEquals(MonthDay.of(11, 28), test.atMonth(NOVEMBER)); + assertEquals(MonthDay.of(12, 28), test.atMonth(DECEMBER)); } @Test(expected = NullPointerException.class) @@ -502,35 +502,35 @@ public void test_atMonth_null() { @Test public void test_atMonth_int_31() { DayOfMonth test = DayOfMonth.of(31); - assertEquals(test.atMonth(1), MonthDay.of(1, 31)); - assertEquals(test.atMonth(2), MonthDay.of(2, 29)); - assertEquals(test.atMonth(3), MonthDay.of(3, 31)); - assertEquals(test.atMonth(4), MonthDay.of(4, 30)); - assertEquals(test.atMonth(5), MonthDay.of(5, 31)); - assertEquals(test.atMonth(6), MonthDay.of(6, 30)); - assertEquals(test.atMonth(7), MonthDay.of(7, 31)); - assertEquals(test.atMonth(8), MonthDay.of(8, 31)); - assertEquals(test.atMonth(9), MonthDay.of(9, 30)); - assertEquals(test.atMonth(10), MonthDay.of(10, 31)); - assertEquals(test.atMonth(11), MonthDay.of(11, 30)); - assertEquals(test.atMonth(12), MonthDay.of(12, 31)); + assertEquals(MonthDay.of(1, 31), test.atMonth(1)); + assertEquals(MonthDay.of(2, 29), test.atMonth(2)); + assertEquals(MonthDay.of(3, 31), test.atMonth(3)); + assertEquals(MonthDay.of(4, 30), test.atMonth(4)); + assertEquals(MonthDay.of(5, 31), test.atMonth(5)); + assertEquals(MonthDay.of(6, 30), test.atMonth(6)); + assertEquals(MonthDay.of(7, 31), test.atMonth(7)); + assertEquals(MonthDay.of(8, 31), test.atMonth(8)); + assertEquals(MonthDay.of(9, 30), test.atMonth(9)); + assertEquals(MonthDay.of(10, 31), test.atMonth(10)); + assertEquals(MonthDay.of(11, 30), test.atMonth(11)); + assertEquals(MonthDay.of(12, 31), test.atMonth(12)); } @Test public void test_atMonth_int_28() { DayOfMonth test = DayOfMonth.of(28); - assertEquals(test.atMonth(1), MonthDay.of(1, 28)); - assertEquals(test.atMonth(2), MonthDay.of(2, 28)); - assertEquals(test.atMonth(3), MonthDay.of(3, 28)); - assertEquals(test.atMonth(4), MonthDay.of(4, 28)); - assertEquals(test.atMonth(5), MonthDay.of(5, 28)); - assertEquals(test.atMonth(6), MonthDay.of(6, 28)); - assertEquals(test.atMonth(7), MonthDay.of(7, 28)); - assertEquals(test.atMonth(8), MonthDay.of(8, 28)); - assertEquals(test.atMonth(9), MonthDay.of(9, 28)); - assertEquals(test.atMonth(10), MonthDay.of(10, 28)); - assertEquals(test.atMonth(11), MonthDay.of(11, 28)); - assertEquals(test.atMonth(12), MonthDay.of(12, 28)); + assertEquals(MonthDay.of(1, 28), test.atMonth(1)); + assertEquals(MonthDay.of(2, 28), test.atMonth(2)); + assertEquals(MonthDay.of(3, 28), test.atMonth(3)); + assertEquals(MonthDay.of(4, 28), test.atMonth(4)); + assertEquals(MonthDay.of(5, 28), test.atMonth(5)); + assertEquals(MonthDay.of(6, 28), test.atMonth(6)); + assertEquals(MonthDay.of(7, 28), test.atMonth(7)); + assertEquals(MonthDay.of(8, 28), test.atMonth(8)); + assertEquals(MonthDay.of(9, 28), test.atMonth(9)); + assertEquals(MonthDay.of(10, 28), test.atMonth(10)); + assertEquals(MonthDay.of(11, 28), test.atMonth(11)); + assertEquals(MonthDay.of(12, 28), test.atMonth(12)); } @Test(expected = DateTimeException.class) @@ -549,36 +549,36 @@ public void test_atMonth_tooHigh() { @Test public void test_atYearMonth_31() { DayOfMonth test = DayOfMonth.of(31); - assertEquals(test.atYearMonth(YearMonth.of(2012, 1)), LocalDate.of(2012, 1, 31)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 2)), LocalDate.of(2012, 2, 29)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 3)), LocalDate.of(2012, 3, 31)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 4)), LocalDate.of(2012, 4, 30)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 5)), LocalDate.of(2012, 5, 31)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 6)), LocalDate.of(2012, 6, 30)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 7)), LocalDate.of(2012, 7, 31)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 8)), LocalDate.of(2012, 8, 31)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 9)), LocalDate.of(2012, 9, 30)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 10)), LocalDate.of(2012, 10, 31)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 11)), LocalDate.of(2012, 11, 30)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 12)), LocalDate.of(2012, 12, 31)); - assertEquals(test.atYearMonth(YearMonth.of(2011, 2)), LocalDate.of(2011, 2, 28)); + assertEquals(LocalDate.of(2012, 1, 31), test.atYearMonth(YearMonth.of(2012, 1))); + assertEquals(LocalDate.of(2012, 2, 29), test.atYearMonth(YearMonth.of(2012, 2))); + assertEquals(LocalDate.of(2012, 3, 31), test.atYearMonth(YearMonth.of(2012, 3))); + assertEquals(LocalDate.of(2012, 4, 30), test.atYearMonth(YearMonth.of(2012, 4))); + assertEquals(LocalDate.of(2012, 5, 31), test.atYearMonth(YearMonth.of(2012, 5))); + assertEquals(LocalDate.of(2012, 6, 30), test.atYearMonth(YearMonth.of(2012, 6))); + assertEquals(LocalDate.of(2012, 7, 31), test.atYearMonth(YearMonth.of(2012, 7))); + assertEquals(LocalDate.of(2012, 8, 31), test.atYearMonth(YearMonth.of(2012, 8))); + assertEquals(LocalDate.of(2012, 9, 30), test.atYearMonth(YearMonth.of(2012, 9))); + assertEquals(LocalDate.of(2012, 10, 31), test.atYearMonth(YearMonth.of(2012, 10))); + assertEquals(LocalDate.of(2012, 11, 30), test.atYearMonth(YearMonth.of(2012, 11))); + assertEquals(LocalDate.of(2012, 12, 31), test.atYearMonth(YearMonth.of(2012, 12))); + assertEquals(LocalDate.of(2011, 2, 28), test.atYearMonth(YearMonth.of(2011, 2))); } @Test public void test_atYearMonth_28() { DayOfMonth test = DayOfMonth.of(28); - assertEquals(test.atYearMonth(YearMonth.of(2012, 1)), LocalDate.of(2012, 1, 28)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 2)), LocalDate.of(2012, 2, 28)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 3)), LocalDate.of(2012, 3, 28)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 4)), LocalDate.of(2012, 4, 28)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 5)), LocalDate.of(2012, 5, 28)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 6)), LocalDate.of(2012, 6, 28)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 7)), LocalDate.of(2012, 7, 28)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 8)), LocalDate.of(2012, 8, 28)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 9)), LocalDate.of(2012, 9, 28)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 10)), LocalDate.of(2012, 10, 28)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 11)), LocalDate.of(2012, 11, 28)); - assertEquals(test.atYearMonth(YearMonth.of(2012, 12)), LocalDate.of(2012, 12, 28)); + assertEquals(LocalDate.of(2012, 1, 28), test.atYearMonth(YearMonth.of(2012, 1))); + assertEquals(LocalDate.of(2012, 2, 28), test.atYearMonth(YearMonth.of(2012, 2))); + assertEquals(LocalDate.of(2012, 3, 28), test.atYearMonth(YearMonth.of(2012, 3))); + assertEquals(LocalDate.of(2012, 4, 28), test.atYearMonth(YearMonth.of(2012, 4))); + assertEquals(LocalDate.of(2012, 5, 28), test.atYearMonth(YearMonth.of(2012, 5))); + assertEquals(LocalDate.of(2012, 6, 28), test.atYearMonth(YearMonth.of(2012, 6))); + assertEquals(LocalDate.of(2012, 7, 28), test.atYearMonth(YearMonth.of(2012, 7))); + assertEquals(LocalDate.of(2012, 8, 28), test.atYearMonth(YearMonth.of(2012, 8))); + assertEquals(LocalDate.of(2012, 9, 28), test.atYearMonth(YearMonth.of(2012, 9))); + assertEquals(LocalDate.of(2012, 10, 28), test.atYearMonth(YearMonth.of(2012, 10))); + assertEquals(LocalDate.of(2012, 11, 28), test.atYearMonth(YearMonth.of(2012, 11))); + assertEquals(LocalDate.of(2012, 12, 28), test.atYearMonth(YearMonth.of(2012, 12))); } @Test(expected = NullPointerException.class) @@ -596,14 +596,14 @@ public void test_compareTo() { for (int j = 1; j <= MAX_LENGTH; j++) { DayOfMonth b = DayOfMonth.of(j); if (i < j) { - assertEquals(a.compareTo(b) < 0, true); - assertEquals(b.compareTo(a) > 0, true); + assertEquals(true, a.compareTo(b) < 0); + assertEquals(true, b.compareTo(a) > 0); } else if (i > j) { - assertEquals(a.compareTo(b) > 0, true); - assertEquals(b.compareTo(a) < 0, true); + assertEquals(true, a.compareTo(b) > 0); + assertEquals(true, b.compareTo(a) < 0); } else { - assertEquals(a.compareTo(b), 0); - assertEquals(b.compareTo(a), 0); + assertEquals(0, a.compareTo(b)); + assertEquals(0, b.compareTo(a)); } } } @@ -625,8 +625,8 @@ public void test_equals() { DayOfMonth a = DayOfMonth.of(i); for (int j = 1; j <= MAX_LENGTH; j++) { DayOfMonth b = DayOfMonth.of(j); - assertEquals(a.equals(b), i == j); - assertEquals(a.hashCode() == b.hashCode(), i == j); + assertEquals(i == j, a.equals(b)); + assertEquals(i == j, a.hashCode() == b.hashCode()); } } } @@ -635,13 +635,13 @@ public void test_equals() { public void test_equals_nullDayOfMonth() { DayOfMonth doy = null; DayOfMonth test = DayOfMonth.of(1); - assertEquals(test.equals(doy), false); + assertEquals(false, test.equals(doy)); } @Test public void test_equals_incorrectType() { DayOfMonth test = DayOfMonth.of(1); - assertEquals(test.equals("Incorrect type"), false); + assertEquals(false, test.equals("Incorrect type")); } //----------------------------------------------------------------------- @@ -651,7 +651,7 @@ public void test_equals_incorrectType() { public void test_toString() { for (int i = 1; i <= MAX_LENGTH; i++) { DayOfMonth a = DayOfMonth.of(i); - assertEquals(a.toString(), "DayOfMonth:" + i); + assertEquals("DayOfMonth:" + i, a.toString()); } } @@ -663,7 +663,7 @@ public void test_now_clock() { for (int i = 1; i <= 31; i++) { // Jan Instant instant = LocalDate.of(2008, 1, i).atStartOfDay(PARIS).toInstant(); Clock clock = Clock.fixed(instant, PARIS); - assertEquals(DayOfMonth.now(clock).getValue(), i); + assertEquals(i, DayOfMonth.now(clock).getValue()); } } diff --git a/src/test/java/org/threeten/extra/TestDayOfYear.java b/src/test/java/org/threeten/extra/TestDayOfYear.java index 3340af52..9957a4b2 100644 --- a/src/test/java/org/threeten/extra/TestDayOfYear.java +++ b/src/test/java/org/threeten/extra/TestDayOfYear.java @@ -117,7 +117,7 @@ public void test_serialization() throws IOException, ClassNotFoundException { oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertEquals(ois.readObject(), test); + assertEquals(test, ois.readObject()); } } @@ -128,8 +128,8 @@ public void test_serialization() throws IOException, ClassNotFoundException { public void test_of_int() { for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) { DayOfYear test = DayOfYear.of(i); - assertEquals(test.getValue(), i); - assertEquals(DayOfYear.of(i), test); + assertEquals(i, test.getValue()); + assertEquals(test, DayOfYear.of(i)); } } @@ -151,11 +151,11 @@ public void test_from_TemporalAccessor_notLeapYear() { LocalDate date = LocalDate.of(2007, 1, 1); for (int i = 1; i <= STANDARD_YEAR_LENGTH; i++) { DayOfYear test = DayOfYear.from(date); - assertEquals(test.getValue(), i); + assertEquals(i, test.getValue()); date = date.plusDays(1); } DayOfYear test = DayOfYear.from(date); - assertEquals(test.getValue(), 1); + assertEquals(1, test.getValue()); } @Test @@ -163,7 +163,7 @@ public void test_from_TemporalAccessor_leapYear() { LocalDate date = LocalDate.of(2008, 1, 1); for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) { DayOfYear test = DayOfYear.from(date); - assertEquals(test.getValue(), i); + assertEquals(i, test.getValue()); date = date.plusDays(1); } } @@ -181,7 +181,7 @@ public void test_from_TemporalAccessor_null() { @Test public void test_from_parse_CharSequence() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("D"); - assertEquals(formatter.parse("76", DayOfYear::from), DayOfYear.of(76)); + assertEquals(DayOfYear.of(76), formatter.parse("76", DayOfYear::from)); } //----------------------------------------------------------------------- @@ -189,37 +189,37 @@ public void test_from_parse_CharSequence() { //----------------------------------------------------------------------- @Test public void test_isSupported() { - assertEquals(TEST.isSupported((TemporalField) null), false); - assertEquals(TEST.isSupported(NANO_OF_SECOND), false); - assertEquals(TEST.isSupported(NANO_OF_DAY), false); - assertEquals(TEST.isSupported(MICRO_OF_SECOND), false); - assertEquals(TEST.isSupported(MICRO_OF_DAY), false); - assertEquals(TEST.isSupported(MILLI_OF_SECOND), false); - assertEquals(TEST.isSupported(MILLI_OF_DAY), false); - assertEquals(TEST.isSupported(SECOND_OF_MINUTE), false); - assertEquals(TEST.isSupported(SECOND_OF_DAY), false); - assertEquals(TEST.isSupported(MINUTE_OF_HOUR), false); - assertEquals(TEST.isSupported(MINUTE_OF_DAY), false); - assertEquals(TEST.isSupported(HOUR_OF_AMPM), false); - assertEquals(TEST.isSupported(CLOCK_HOUR_OF_AMPM), false); - assertEquals(TEST.isSupported(HOUR_OF_DAY), false); - assertEquals(TEST.isSupported(CLOCK_HOUR_OF_DAY), false); - assertEquals(TEST.isSupported(AMPM_OF_DAY), false); - assertEquals(TEST.isSupported(DAY_OF_WEEK), false); - assertEquals(TEST.isSupported(ALIGNED_DAY_OF_WEEK_IN_MONTH), false); - assertEquals(TEST.isSupported(ALIGNED_DAY_OF_WEEK_IN_YEAR), false); - assertEquals(TEST.isSupported(DAY_OF_MONTH), false); - assertEquals(TEST.isSupported(DAY_OF_YEAR), true); - assertEquals(TEST.isSupported(EPOCH_DAY), false); - assertEquals(TEST.isSupported(ALIGNED_WEEK_OF_MONTH), false); - assertEquals(TEST.isSupported(ALIGNED_WEEK_OF_YEAR), false); - assertEquals(TEST.isSupported(MONTH_OF_YEAR), false); - assertEquals(TEST.isSupported(PROLEPTIC_MONTH), false); - assertEquals(TEST.isSupported(YEAR_OF_ERA), false); - assertEquals(TEST.isSupported(YEAR), false); - assertEquals(TEST.isSupported(ERA), false); - assertEquals(TEST.isSupported(INSTANT_SECONDS), false); - assertEquals(TEST.isSupported(OFFSET_SECONDS), false); + assertEquals(false, TEST.isSupported((TemporalField) null)); + assertEquals(false, TEST.isSupported(NANO_OF_SECOND)); + assertEquals(false, TEST.isSupported(NANO_OF_DAY)); + assertEquals(false, TEST.isSupported(MICRO_OF_SECOND)); + assertEquals(false, TEST.isSupported(MICRO_OF_DAY)); + assertEquals(false, TEST.isSupported(MILLI_OF_SECOND)); + assertEquals(false, TEST.isSupported(MILLI_OF_DAY)); + assertEquals(false, TEST.isSupported(SECOND_OF_MINUTE)); + assertEquals(false, TEST.isSupported(SECOND_OF_DAY)); + assertEquals(false, TEST.isSupported(MINUTE_OF_HOUR)); + assertEquals(false, TEST.isSupported(MINUTE_OF_DAY)); + assertEquals(false, TEST.isSupported(HOUR_OF_AMPM)); + assertEquals(false, TEST.isSupported(CLOCK_HOUR_OF_AMPM)); + assertEquals(false, TEST.isSupported(HOUR_OF_DAY)); + assertEquals(false, TEST.isSupported(CLOCK_HOUR_OF_DAY)); + assertEquals(false, TEST.isSupported(AMPM_OF_DAY)); + assertEquals(false, TEST.isSupported(DAY_OF_WEEK)); + assertEquals(false, TEST.isSupported(ALIGNED_DAY_OF_WEEK_IN_MONTH)); + assertEquals(false, TEST.isSupported(ALIGNED_DAY_OF_WEEK_IN_YEAR)); + assertEquals(false, TEST.isSupported(DAY_OF_MONTH)); + assertEquals(true, TEST.isSupported(DAY_OF_YEAR)); + assertEquals(false, TEST.isSupported(EPOCH_DAY)); + assertEquals(false, TEST.isSupported(ALIGNED_WEEK_OF_MONTH)); + assertEquals(false, TEST.isSupported(ALIGNED_WEEK_OF_YEAR)); + assertEquals(false, TEST.isSupported(MONTH_OF_YEAR)); + assertEquals(false, TEST.isSupported(PROLEPTIC_MONTH)); + assertEquals(false, TEST.isSupported(YEAR_OF_ERA)); + assertEquals(false, TEST.isSupported(YEAR)); + assertEquals(false, TEST.isSupported(ERA)); + assertEquals(false, TEST.isSupported(INSTANT_SECONDS)); + assertEquals(false, TEST.isSupported(OFFSET_SECONDS)); } //----------------------------------------------------------------------- @@ -227,7 +227,7 @@ public void test_isSupported() { //----------------------------------------------------------------------- @Test public void test_range() { - assertEquals(TEST.range(DAY_OF_YEAR), DAY_OF_YEAR.range()); + assertEquals(DAY_OF_YEAR.range(), TEST.range(DAY_OF_YEAR)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -245,7 +245,7 @@ public void test_range_null() { //----------------------------------------------------------------------- @Test public void test_get() { - assertEquals(TEST.get(DAY_OF_YEAR), 12); + assertEquals(12, TEST.get(DAY_OF_YEAR)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -263,7 +263,7 @@ public void test_get_null() { //----------------------------------------------------------------------- @Test public void test_getLong() { - assertEquals(TEST.getLong(DAY_OF_YEAR), 12L); + assertEquals(12L, TEST.getLong(DAY_OF_YEAR)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -282,17 +282,17 @@ public void test_getLong_null() { @Test public void test_isValidYearMonth_366() { DayOfYear test = DayOfYear.of(366); - assertEquals(test.isValidYear(2011), false); - assertEquals(test.isValidYear(2012), true); - assertEquals(test.isValidYear(2013), false); + assertEquals(false, test.isValidYear(2011)); + assertEquals(true, test.isValidYear(2012)); + assertEquals(false, test.isValidYear(2013)); } @Test public void test_isValidYearMonth_365() { DayOfYear test = DayOfYear.of(365); - assertEquals(test.isValidYear(2011), true); - assertEquals(test.isValidYear(2012), true); - assertEquals(test.isValidYear(2013), true); + assertEquals(true, test.isValidYear(2011)); + assertEquals(true, test.isValidYear(2012)); + assertEquals(true, test.isValidYear(2013)); } //----------------------------------------------------------------------- @@ -300,13 +300,13 @@ public void test_isValidYearMonth_365() { //----------------------------------------------------------------------- @Test public void test_query() { - assertEquals(TEST.query(TemporalQueries.chronology()), IsoChronology.INSTANCE); - assertEquals(TEST.query(TemporalQueries.localDate()), null); - assertEquals(TEST.query(TemporalQueries.localTime()), null); - assertEquals(TEST.query(TemporalQueries.offset()), null); - assertEquals(TEST.query(TemporalQueries.precision()), null); - assertEquals(TEST.query(TemporalQueries.zone()), null); - assertEquals(TEST.query(TemporalQueries.zoneId()), null); + assertEquals(IsoChronology.INSTANCE, TEST.query(TemporalQueries.chronology())); + assertEquals(null, TEST.query(TemporalQueries.localDate())); + assertEquals(null, TEST.query(TemporalQueries.localTime())); + assertEquals(null, TEST.query(TemporalQueries.offset())); + assertEquals(null, TEST.query(TemporalQueries.precision())); + assertEquals(null, TEST.query(TemporalQueries.zone())); + assertEquals(null, TEST.query(TemporalQueries.zoneId())); } //----------------------------------------------------------------------- @@ -318,7 +318,7 @@ public void test_adjustInto_fromStartOfYear_notLeapYear() { LocalDate expected = base; for (int i = 1; i <= STANDARD_YEAR_LENGTH; i++) { DayOfYear test = DayOfYear.of(i); - assertEquals(test.adjustInto(base), expected); + assertEquals(expected, test.adjustInto(base)); expected = expected.plusDays(1); } } @@ -329,7 +329,7 @@ public void test_adjustInto_fromEndOfYear_notLeapYear() { LocalDate expected = LocalDate.of(2007, 1, 1); for (int i = 1; i <= STANDARD_YEAR_LENGTH; i++) { DayOfYear test = DayOfYear.of(i); - assertEquals(test.adjustInto(base), expected); + assertEquals(expected, test.adjustInto(base)); expected = expected.plusDays(1); } } @@ -354,7 +354,7 @@ public void test_adjustInto_fromStartOfYear_leapYear() { LocalDate expected = base; for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) { DayOfYear test = DayOfYear.of(i); - assertEquals(test.adjustInto(base), expected); + assertEquals(expected, test.adjustInto(base)); expected = expected.plusDays(1); } } @@ -365,7 +365,7 @@ public void test_adjustInto_fromEndOfYear_leapYear() { LocalDate expected = LocalDate.of(2008, 1, 1); for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) { DayOfYear test = DayOfYear.of(i); - assertEquals(test.adjustInto(base), expected); + assertEquals(expected, test.adjustInto(base)); expected = expected.plusDays(1); } } @@ -383,7 +383,7 @@ public void test_atYear_Year_notLeapYear() { LocalDate expected = LocalDate.of(2007, 1, 1); for (int i = 1; i <= STANDARD_YEAR_LENGTH; i++) { DayOfYear test = DayOfYear.of(i); - assertEquals(test.atYear(YEAR_STANDARD), expected); + assertEquals(expected, test.atYear(YEAR_STANDARD)); expected = expected.plusDays(1); } } @@ -399,7 +399,7 @@ public void test_atYear_Year_leapYear() { LocalDate expected = LocalDate.of(2008, 1, 1); for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) { DayOfYear test = DayOfYear.of(i); - assertEquals(test.atYear(YEAR_LEAP), expected); + assertEquals(expected, test.atYear(YEAR_LEAP)); expected = expected.plusDays(1); } } @@ -417,7 +417,7 @@ public void test_atYear_int_notLeapYear() { LocalDate expected = LocalDate.of(2007, 1, 1); for (int i = 1; i <= STANDARD_YEAR_LENGTH; i++) { DayOfYear test = DayOfYear.of(i); - assertEquals(test.atYear(2007), expected); + assertEquals(expected, test.atYear(2007)); expected = expected.plusDays(1); } } @@ -433,7 +433,7 @@ public void test_atYear_int_leapYear() { LocalDate expected = LocalDate.of(2008, 1, 1); for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) { DayOfYear test = DayOfYear.of(i); - assertEquals(test.atYear(2008), expected); + assertEquals(expected, test.atYear(2008)); expected = expected.plusDays(1); } } @@ -453,14 +453,14 @@ public void test_compareTo() { for (int j = 1; j <= LEAP_YEAR_LENGTH; j++) { DayOfYear b = DayOfYear.of(j); if (i < j) { - assertEquals(a.compareTo(b) < 0, true); - assertEquals(b.compareTo(a) > 0, true); + assertEquals(true, a.compareTo(b) < 0); + assertEquals(true, b.compareTo(a) > 0); } else if (i > j) { - assertEquals(a.compareTo(b) > 0, true); - assertEquals(b.compareTo(a) < 0, true); + assertEquals(true, a.compareTo(b) > 0); + assertEquals(true, b.compareTo(a) < 0); } else { - assertEquals(a.compareTo(b), 0); - assertEquals(b.compareTo(a), 0); + assertEquals(0, a.compareTo(b)); + assertEquals(0, b.compareTo(a)); } } } @@ -482,8 +482,8 @@ public void test_equals() { DayOfYear a = DayOfYear.of(i); for (int j = 1; j <= LEAP_YEAR_LENGTH; j++) { DayOfYear b = DayOfYear.of(j); - assertEquals(a.equals(b), i == j); - assertEquals(a.hashCode() == b.hashCode(), i == j); + assertEquals(i == j, a.equals(b)); + assertEquals(i == j, a.hashCode() == b.hashCode()); } } } @@ -492,13 +492,13 @@ public void test_equals() { public void test_equals_nullDayOfYear() { DayOfYear doy = null; DayOfYear test = DayOfYear.of(1); - assertEquals(test.equals(doy), false); + assertEquals(false, test.equals(doy)); } @Test public void test_equals_incorrectType() { DayOfYear test = DayOfYear.of(1); - assertEquals(test.equals("Incorrect type"), false); + assertEquals(false, test.equals("Incorrect type")); } //----------------------------------------------------------------------- @@ -508,7 +508,7 @@ public void test_equals_incorrectType() { public void test_toString() { for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) { DayOfYear a = DayOfYear.of(i); - assertEquals(a.toString(), "DayOfYear:" + i); + assertEquals("DayOfYear:" + i, a.toString()); } } @@ -522,7 +522,7 @@ public void test_now_clock_notLeapYear() { Instant instant = date.atStartOfDay(PARIS).toInstant(); Clock clock = Clock.fixed(instant, PARIS); DayOfYear test = DayOfYear.now(clock); - assertEquals(test.getValue(), i); + assertEquals(i, test.getValue()); date = date.plusDays(1); } } @@ -534,7 +534,7 @@ public void test_now_clock_leapYear() { Instant instant = date.atStartOfDay(PARIS).toInstant(); Clock clock = Clock.fixed(instant, PARIS); DayOfYear test = DayOfYear.now(clock); - assertEquals(test.getValue(), i); + assertEquals(i, test.getValue()); date = date.plusDays(1); } } diff --git a/src/test/java/org/threeten/extra/TestDays.java b/src/test/java/org/threeten/extra/TestDays.java index abe73cc1..53ee459c 100644 --- a/src/test/java/org/threeten/extra/TestDays.java +++ b/src/test/java/org/threeten/extra/TestDays.java @@ -83,38 +83,38 @@ public void test_deserializationSingleton() throws Exception { public void test_ZERO() { assertSame(Days.of(0), Days.ZERO); assertSame(Days.of(0), Days.ZERO); - assertEquals(Days.ZERO.getAmount(), 0); + assertEquals(0, Days.ZERO.getAmount()); } @Test public void test_ONE() { assertSame(Days.of(1), Days.ONE); assertSame(Days.of(1), Days.ONE); - assertEquals(Days.ONE.getAmount(), 1); + assertEquals(1, Days.ONE.getAmount()); } //----------------------------------------------------------------------- @Test public void test_of() { - assertEquals(Days.of(0).getAmount(), 0); - assertEquals(Days.of(1).getAmount(), 1); - assertEquals(Days.of(2).getAmount(), 2); - assertEquals(Days.of(Integer.MAX_VALUE).getAmount(), Integer.MAX_VALUE); - assertEquals(Days.of(-1).getAmount(), -1); - assertEquals(Days.of(-2).getAmount(), -2); - assertEquals(Days.of(Integer.MIN_VALUE).getAmount(), Integer.MIN_VALUE); + assertEquals(0, Days.of(0).getAmount()); + assertEquals(1, Days.of(1).getAmount()); + assertEquals(2, Days.of(2).getAmount()); + assertEquals(Integer.MAX_VALUE, Days.of(Integer.MAX_VALUE).getAmount()); + assertEquals(-1, Days.of(-1).getAmount()); + assertEquals(-2, Days.of(-2).getAmount()); + assertEquals(Integer.MIN_VALUE, Days.of(Integer.MIN_VALUE).getAmount()); } //----------------------------------------------------------------------- @Test public void test_ofWeeks() { - assertEquals(Days.ofWeeks(0).getAmount(), 0); - assertEquals(Days.ofWeeks(1).getAmount(), 7); - assertEquals(Days.ofWeeks(2).getAmount(), 14); - assertEquals(Days.ofWeeks(Integer.MAX_VALUE / 7).getAmount(), (Integer.MAX_VALUE / 7) * 7); - assertEquals(Days.ofWeeks(-1).getAmount(), -7); - assertEquals(Days.ofWeeks(-2).getAmount(), -14); - assertEquals(Days.ofWeeks(Integer.MIN_VALUE / 7).getAmount(), (Integer.MIN_VALUE / 7) * 7); + assertEquals(0, Days.ofWeeks(0).getAmount()); + assertEquals(7, Days.ofWeeks(1).getAmount()); + assertEquals(14, Days.ofWeeks(2).getAmount()); + assertEquals((Integer.MAX_VALUE / 7) * 7, Days.ofWeeks(Integer.MAX_VALUE / 7).getAmount()); + assertEquals(-7, Days.ofWeeks(-1).getAmount()); + assertEquals(-14, Days.ofWeeks(-2).getAmount()); + assertEquals((Integer.MIN_VALUE / 7) * 7, Days.ofWeeks(Integer.MIN_VALUE / 7).getAmount()); } @Test(expected = ArithmeticException.class) @@ -125,27 +125,27 @@ public void test_ofWeeks_overflow() { //----------------------------------------------------------------------- @Test public void test_from_Period_P0D() { - assertEquals(Days.from(Period.ofDays(0)), Days.of(0)); + assertEquals(Days.of(0), Days.from(Period.ofDays(0))); } @Test public void test_from_Period_P2D() { - assertEquals(Days.from(Period.ofDays(2)), Days.of(2)); + assertEquals(Days.of(2), Days.from(Period.ofDays(2))); } @Test public void test_from_P2W() { - assertEquals(Days.from(new MockWeeksDays(2, 0)), Days.of(14)); + assertEquals(Days.of(14), Days.from(new MockWeeksDays(2, 0))); } @Test public void test_from_P2W3D() { - assertEquals(Days.from(new MockWeeksDays(2, 3)), Days.of(17)); + assertEquals(Days.of(17), Days.from(new MockWeeksDays(2, 3))); } @Test public void test_from_Duration() { - assertEquals(Days.from(Duration.ofDays(2)), Days.of(2)); + assertEquals(Days.of(2), Days.from(Duration.ofDays(2))); } @Test(expected = DateTimeException.class) @@ -198,19 +198,19 @@ public static Object[][] data_valid() { @Test @UseDataProvider("data_valid") public void test_parse_CharSequence_valid(String str, int expectedDays) { - assertEquals(Days.parse(str), Days.of(expectedDays)); + assertEquals(Days.of(expectedDays), Days.parse(str)); } @Test @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, int expectedDays) { - assertEquals(Days.parse("+" + str), Days.of(expectedDays)); + assertEquals(Days.of(expectedDays), Days.parse("+" + str)); } @Test @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, int expectedDays) { - assertEquals(Days.parse("-" + str), Days.of(-expectedDays)); + assertEquals(Days.of(-expectedDays), Days.parse("-" + str)); } @DataProvider @@ -462,7 +462,7 @@ public void test_abs_overflow() { @Test public void test_toPeriod() { for (int i = -20; i < 20; i++) { - assertEquals(Days.of(i).toPeriod(), Period.ofDays(i)); + assertEquals(Period.ofDays(i), Days.of(i).toPeriod()); } } diff --git a/src/test/java/org/threeten/extra/TestHours.java b/src/test/java/org/threeten/extra/TestHours.java index 7278e199..36fc1001 100644 --- a/src/test/java/org/threeten/extra/TestHours.java +++ b/src/test/java/org/threeten/extra/TestHours.java @@ -81,19 +81,19 @@ public void test_deserializationSingleton() throws Exception { public void test_ZERO() { assertSame(Hours.of(0), Hours.ZERO); assertSame(Hours.of(0), Hours.ZERO); - assertEquals(Hours.ZERO.getAmount(), 0); + assertEquals(0, Hours.ZERO.getAmount()); } //----------------------------------------------------------------------- @Test public void test_of() { - assertEquals(Hours.of(0).getAmount(), 0); - assertEquals(Hours.of(1).getAmount(), 1); - assertEquals(Hours.of(2).getAmount(), 2); - assertEquals(Hours.of(Integer.MAX_VALUE).getAmount(), Integer.MAX_VALUE); - assertEquals(Hours.of(-1).getAmount(), -1); - assertEquals(Hours.of(-2).getAmount(), -2); - assertEquals(Hours.of(Integer.MIN_VALUE).getAmount(), Integer.MIN_VALUE); + assertEquals(0, Hours.of(0).getAmount()); + assertEquals(1, Hours.of(1).getAmount()); + assertEquals(2, Hours.of(2).getAmount()); + assertEquals(Integer.MAX_VALUE, Hours.of(Integer.MAX_VALUE).getAmount()); + assertEquals(-1, Hours.of(-1).getAmount()); + assertEquals(-2, Hours.of(-2).getAmount()); + assertEquals(Integer.MIN_VALUE, Hours.of(Integer.MIN_VALUE).getAmount()); } //----------------------------------------------------------------------- @@ -126,19 +126,19 @@ public static Object[][] data_valid() { @Test @UseDataProvider("data_valid") public void test_parse_CharSequence_valid(String str, int expectedDays) { - assertEquals(Hours.parse(str), Hours.of(expectedDays)); + assertEquals(Hours.of(expectedDays), Hours.parse(str)); } @Test @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, int expectedDays) { - assertEquals(Hours.parse("+" + str), Hours.of(expectedDays)); + assertEquals(Hours.of(expectedDays), Hours.parse("+" + str)); } @Test @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, int expectedDays) { - assertEquals(Hours.parse("-" + str), Hours.of(-expectedDays)); + assertEquals(Hours.of(-expectedDays), Hours.parse("-" + str)); } @DataProvider @@ -370,24 +370,24 @@ public void test_abs_overflow() { @Test public void test_addTo() { LocalTime base = LocalTime.of(11, 30); - assertEquals(Hours.of(0).addTo(base), LocalTime.of(11, 30)); - assertEquals(Hours.of(6).addTo(base), LocalTime.of(17, 30)); + assertEquals(LocalTime.of(11, 30), Hours.of(0).addTo(base)); + assertEquals(LocalTime.of(17, 30), Hours.of(6).addTo(base)); } //----------------------------------------------------------------------- @Test public void test_subtractFrom() { LocalTime base = LocalTime.of(11, 30); - assertEquals(Hours.of(0).subtractFrom(base), LocalTime.of(11, 30)); - assertEquals(Hours.of(6).subtractFrom(base), LocalTime.of(5, 30)); + assertEquals(LocalTime.of(11, 30), Hours.of(0).subtractFrom(base)); + assertEquals(LocalTime.of(5, 30), Hours.of(6).subtractFrom(base)); } //----------------------------------------------------------------------- @SuppressWarnings("deprecation") public void test_toDuration() { for (int i = -20; i < 20; i++) { - assertEquals(Hours.of(i).toPeriod(), Duration.ofHours(i)); - assertEquals(Hours.of(i).toDuration(), Duration.ofHours(i)); + assertEquals(Duration.ofHours(i), Hours.of(i).toPeriod()); + assertEquals(Duration.ofHours(i), Hours.of(i).toDuration()); } } diff --git a/src/test/java/org/threeten/extra/TestInterval.java b/src/test/java/org/threeten/extra/TestInterval.java index d6d8a387..a4457be8 100644 --- a/src/test/java/org/threeten/extra/TestInterval.java +++ b/src/test/java/org/threeten/extra/TestInterval.java @@ -83,7 +83,7 @@ public void test_serialization() throws Exception { oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertEquals(ois.readObject(), test); + assertEquals(test, ois.readObject()); } } @@ -91,32 +91,32 @@ public void test_serialization() throws Exception { @Test public void test_ALL() { Interval test = Interval.ALL; - assertEquals(test.getStart(), Instant.MIN); - assertEquals(test.getEnd(), Instant.MAX); - assertEquals(test.isEmpty(), false); - assertEquals(test.isUnboundedStart(), true); - assertEquals(test.isUnboundedEnd(), true); + assertEquals(Instant.MIN, test.getStart()); + assertEquals(Instant.MAX, test.getEnd()); + assertEquals(false, test.isEmpty()); + assertEquals(true, test.isUnboundedStart()); + assertEquals(true, test.isUnboundedEnd()); } //----------------------------------------------------------------------- @Test public void test_of_Instant_Instant() { Interval test = Interval.of(NOW1, NOW2); - assertEquals(test.getStart(), NOW1); - assertEquals(test.getEnd(), NOW2); - assertEquals(test.isEmpty(), false); - assertEquals(test.isUnboundedStart(), false); - assertEquals(test.isUnboundedEnd(), false); + assertEquals(NOW1, test.getStart()); + assertEquals(NOW2, test.getEnd()); + assertEquals(false, test.isEmpty()); + assertEquals(false, test.isUnboundedStart()); + assertEquals(false, test.isUnboundedEnd()); } @Test public void test_of_Instant_Instant_empty() { Interval test = Interval.of(NOW1, NOW1); - assertEquals(test.getStart(), NOW1); - assertEquals(test.getEnd(), NOW1); - assertEquals(test.isEmpty(), true); - assertEquals(test.isUnboundedStart(), false); - assertEquals(test.isUnboundedEnd(), false); + assertEquals(NOW1, test.getStart()); + assertEquals(NOW1, test.getEnd()); + assertEquals(true, test.isEmpty()); + assertEquals(false, test.isUnboundedStart()); + assertEquals(false, test.isUnboundedEnd()); } @Test(expected = DateTimeException.class) @@ -138,15 +138,15 @@ public void test_of_Instant_Instant_nullEnd() { @Test public void test_of_Instant_Duration() { Interval test = Interval.of(NOW1, Duration.ofSeconds(60)); - assertEquals(test.getStart(), NOW1); - assertEquals(test.getEnd(), NOW2); + assertEquals(NOW1, test.getStart()); + assertEquals(NOW2, test.getEnd()); } @Test public void test_of_Instant_Duration_zero() { Interval test = Interval.of(NOW1, Duration.ZERO); - assertEquals(test.getStart(), NOW1); - assertEquals(test.getEnd(), NOW1); + assertEquals(NOW1, test.getStart()); + assertEquals(NOW1, test.getEnd()); } @Test(expected = DateTimeException.class) @@ -199,8 +199,8 @@ public static Object[][] data_parseValid() { @UseDataProvider("data_parseValid") public void test_parse_CharSequence(String input, Instant start, Instant end) { Interval test = Interval.parse(input); - assertEquals(test.getStart(), start); - assertEquals(test.getEnd(), end); + assertEquals(start, test.getStart()); + assertEquals(end, test.getEnd()); } @Test(expected = DateTimeException.class) @@ -223,8 +223,8 @@ public void test_parse_CharSequence_null() { public void test_withStart() { Interval base = Interval.of(NOW1, NOW3); Interval test = base.withStart(NOW2); - assertEquals(test.getStart(), NOW2); - assertEquals(test.getEnd(), NOW3); + assertEquals(NOW2, test.getStart()); + assertEquals(NOW3, test.getEnd()); } @Test(expected = DateTimeException.class) @@ -244,8 +244,8 @@ public void test_withStart_null() { public void test_withEnd() { Interval base = Interval.of(NOW1, NOW3); Interval test = base.withEnd(NOW2); - assertEquals(test.getStart(), NOW1); - assertEquals(test.getEnd(), NOW2); + assertEquals(NOW1, test.getStart()); + assertEquals(NOW2, test.getEnd()); } @Test(expected = DateTimeException.class) @@ -264,29 +264,29 @@ public void test_withEnd_null() { @Test public void test_contains_Instant() { Interval test = Interval.of(NOW1, NOW2); - assertEquals(test.contains(NOW1.minusSeconds(1)), false); - assertEquals(test.contains(NOW1), true); - assertEquals(test.contains(NOW1.plusSeconds(1)), true); - assertEquals(test.contains(NOW2.minusSeconds(1)), true); - assertEquals(test.contains(NOW2), false); + assertEquals(false, test.contains(NOW1.minusSeconds(1))); + assertEquals(true, test.contains(NOW1)); + assertEquals(true, test.contains(NOW1.plusSeconds(1))); + assertEquals(true, test.contains(NOW2.minusSeconds(1))); + assertEquals(false, test.contains(NOW2)); } @Test public void test_contains_Instant_baseEmpty() { Interval test = Interval.of(NOW1, NOW1); - assertEquals(test.contains(NOW1.minusSeconds(1)), false); - assertEquals(test.contains(NOW1), false); - assertEquals(test.contains(NOW1.plusSeconds(1)), false); + assertEquals(false, test.contains(NOW1.minusSeconds(1))); + assertEquals(false, test.contains(NOW1)); + assertEquals(false, test.contains(NOW1.plusSeconds(1))); } @Test public void test_contains_max() { Interval test = Interval.of(NOW2, Instant.MAX); - assertEquals(test.contains(Instant.MIN), false); - assertEquals(test.contains(NOW1), false); - assertEquals(test.contains(NOW2), true); - assertEquals(test.contains(NOW3), true); - assertEquals(test.contains(Instant.MAX), true); + assertEquals(false, test.contains(Instant.MIN)); + assertEquals(false, test.contains(NOW1)); + assertEquals(true, test.contains(NOW2)); + assertEquals(true, test.contains(NOW3)); + assertEquals(true, test.contains(Instant.MAX)); } @Test(expected = NullPointerException.class) @@ -300,35 +300,35 @@ public void test_contains_Instant_null() { public void test_encloses_Interval() { Interval test = Interval.of(NOW1, NOW2); // completely before - assertEquals(test.encloses(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1))), false); - assertEquals(test.encloses(Interval.of(NOW1.minusSeconds(1), NOW1)), false); + assertEquals(false, test.encloses(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1)))); + assertEquals(false, test.encloses(Interval.of(NOW1.minusSeconds(1), NOW1))); // partly before - assertEquals(test.encloses(Interval.of(NOW1.minusSeconds(1), NOW2)), false); - assertEquals(test.encloses(Interval.of(NOW1.minusSeconds(1), NOW2.minusSeconds(1))), false); + assertEquals(false, test.encloses(Interval.of(NOW1.minusSeconds(1), NOW2))); + assertEquals(false, test.encloses(Interval.of(NOW1.minusSeconds(1), NOW2.minusSeconds(1)))); // contained - assertEquals(test.encloses(Interval.of(NOW1, NOW2.minusSeconds(1))), true); - assertEquals(test.encloses(Interval.of(NOW1, NOW2)), true); - assertEquals(test.encloses(Interval.of(NOW1.plusSeconds(1), NOW2)), true); + assertEquals(true, test.encloses(Interval.of(NOW1, NOW2.minusSeconds(1)))); + assertEquals(true, test.encloses(Interval.of(NOW1, NOW2))); + assertEquals(true, test.encloses(Interval.of(NOW1.plusSeconds(1), NOW2))); // partly after - assertEquals(test.encloses(Interval.of(NOW1, NOW2.plusSeconds(1))), false); - assertEquals(test.encloses(Interval.of(NOW1.plusSeconds(1), NOW2.plusSeconds(1))), false); + assertEquals(false, test.encloses(Interval.of(NOW1, NOW2.plusSeconds(1)))); + assertEquals(false, test.encloses(Interval.of(NOW1.plusSeconds(1), NOW2.plusSeconds(1)))); // completely after - assertEquals(test.encloses(Interval.of(NOW2, NOW2.plusSeconds(1))), false); - assertEquals(test.encloses(Interval.of(NOW2.plusSeconds(1), NOW2.plusSeconds(2))), false); + assertEquals(false, test.encloses(Interval.of(NOW2, NOW2.plusSeconds(1)))); + assertEquals(false, test.encloses(Interval.of(NOW2.plusSeconds(1), NOW2.plusSeconds(2)))); } @Test public void test_encloses_Interval_empty() { Interval test = Interval.of(NOW1, NOW1); // completely before - assertEquals(test.encloses(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1))), false); + assertEquals(false, test.encloses(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1)))); // partly before - assertEquals(test.encloses(Interval.of(NOW1.minusSeconds(1), NOW1)), false); + assertEquals(false, test.encloses(Interval.of(NOW1.minusSeconds(1), NOW1))); // equal - assertEquals(test.encloses(Interval.of(NOW1, NOW1)), true); + assertEquals(true, test.encloses(Interval.of(NOW1, NOW1))); // completely after - assertEquals(test.encloses(Interval.of(NOW1, NOW1.plusSeconds(1))), false); - assertEquals(test.encloses(Interval.of(NOW1.plusSeconds(1), NOW1.plusSeconds(2))), false); + assertEquals(false, test.encloses(Interval.of(NOW1, NOW1.plusSeconds(1)))); + assertEquals(false, test.encloses(Interval.of(NOW1.plusSeconds(1), NOW1.plusSeconds(2)))); } @Test(expected = NullPointerException.class) @@ -342,34 +342,34 @@ public void test_encloses_Interval_null() { public void test_abuts_Interval() { Interval test = Interval.of(NOW1, NOW2); // completely before - assertEquals(test.abuts(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1))), false); - assertEquals(test.abuts(Interval.of(NOW1.minusSeconds(1), NOW1)), true); + assertEquals(false, test.abuts(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1)))); + assertEquals(true, test.abuts(Interval.of(NOW1.minusSeconds(1), NOW1))); // partly before - assertEquals(test.abuts(Interval.of(NOW1.minusSeconds(1), NOW2)), false); - assertEquals(test.abuts(Interval.of(NOW1.minusSeconds(1), NOW2.minusSeconds(1))), false); + assertEquals(false, test.abuts(Interval.of(NOW1.minusSeconds(1), NOW2))); + assertEquals(false, test.abuts(Interval.of(NOW1.minusSeconds(1), NOW2.minusSeconds(1)))); // contained - assertEquals(test.abuts(Interval.of(NOW1, NOW2.minusSeconds(1))), false); - assertEquals(test.abuts(Interval.of(NOW1, NOW2)), false); - assertEquals(test.abuts(Interval.of(NOW1.plusSeconds(1), NOW2)), false); + assertEquals(false, test.abuts(Interval.of(NOW1, NOW2.minusSeconds(1)))); + assertEquals(false, test.abuts(Interval.of(NOW1, NOW2))); + assertEquals(false, test.abuts(Interval.of(NOW1.plusSeconds(1), NOW2))); // partly after - assertEquals(test.abuts(Interval.of(NOW1, NOW2.plusSeconds(1))), false); - assertEquals(test.abuts(Interval.of(NOW1.plusSeconds(1), NOW2.plusSeconds(1))), false); + assertEquals(false, test.abuts(Interval.of(NOW1, NOW2.plusSeconds(1)))); + assertEquals(false, test.abuts(Interval.of(NOW1.plusSeconds(1), NOW2.plusSeconds(1)))); // completely after - assertEquals(test.abuts(Interval.of(NOW2, NOW2.plusSeconds(1))), true); - assertEquals(test.abuts(Interval.of(NOW2.plusSeconds(1), NOW2.plusSeconds(2))), false); + assertEquals(true, test.abuts(Interval.of(NOW2, NOW2.plusSeconds(1)))); + assertEquals(false, test.abuts(Interval.of(NOW2.plusSeconds(1), NOW2.plusSeconds(2)))); } @Test public void test_abuts_Interval_empty() { Interval test = Interval.of(NOW1, NOW1); // completely before - assertEquals(test.abuts(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1))), false); - assertEquals(test.abuts(Interval.of(NOW1.minusSeconds(1), NOW1)), true); + assertEquals(false, test.abuts(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1)))); + assertEquals(true, test.abuts(Interval.of(NOW1.minusSeconds(1), NOW1))); // equal - assertEquals(test.abuts(Interval.of(NOW1, NOW1)), false); + assertEquals(false, test.abuts(Interval.of(NOW1, NOW1))); // completely after - assertEquals(test.abuts(Interval.of(NOW1, NOW1.plusSeconds(1))), true); - assertEquals(test.abuts(Interval.of(NOW1.plusSeconds(1), NOW1.plusSeconds(2))), false); + assertEquals(true, test.abuts(Interval.of(NOW1, NOW1.plusSeconds(1)))); + assertEquals(false, test.abuts(Interval.of(NOW1.plusSeconds(1), NOW1.plusSeconds(2)))); } @Test(expected = NullPointerException.class) @@ -383,34 +383,34 @@ public void test_abuts_Interval_null() { public void test_isConnected_Interval() { Interval test = Interval.of(NOW1, NOW2); // completely before - assertEquals(test.isConnected(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1))), false); - assertEquals(test.isConnected(Interval.of(NOW1.minusSeconds(1), NOW1)), true); + assertEquals(false, test.isConnected(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1)))); + assertEquals(true, test.isConnected(Interval.of(NOW1.minusSeconds(1), NOW1))); // partly before - assertEquals(test.isConnected(Interval.of(NOW1.minusSeconds(1), NOW2)), true); - assertEquals(test.isConnected(Interval.of(NOW1.minusSeconds(1), NOW2.minusSeconds(1))), true); + assertEquals(true, test.isConnected(Interval.of(NOW1.minusSeconds(1), NOW2))); + assertEquals(true, test.isConnected(Interval.of(NOW1.minusSeconds(1), NOW2.minusSeconds(1)))); // contained - assertEquals(test.isConnected(Interval.of(NOW1, NOW2.minusSeconds(1))), true); - assertEquals(test.isConnected(Interval.of(NOW1, NOW2)), true); - assertEquals(test.isConnected(Interval.of(NOW1.plusSeconds(1), NOW2)), true); + assertEquals(true, test.isConnected(Interval.of(NOW1, NOW2.minusSeconds(1)))); + assertEquals(true, test.isConnected(Interval.of(NOW1, NOW2))); + assertEquals(true, test.isConnected(Interval.of(NOW1.plusSeconds(1), NOW2))); // partly after - assertEquals(test.isConnected(Interval.of(NOW1, NOW2.plusSeconds(1))), true); - assertEquals(test.isConnected(Interval.of(NOW1.plusSeconds(1), NOW2.plusSeconds(1))), true); + assertEquals(true, test.isConnected(Interval.of(NOW1, NOW2.plusSeconds(1)))); + assertEquals(true, test.isConnected(Interval.of(NOW1.plusSeconds(1), NOW2.plusSeconds(1)))); // completely after - assertEquals(test.isConnected(Interval.of(NOW2, NOW2.plusSeconds(1))), true); - assertEquals(test.isConnected(Interval.of(NOW2.plusSeconds(1), NOW2.plusSeconds(2))), false); + assertEquals(true, test.isConnected(Interval.of(NOW2, NOW2.plusSeconds(1)))); + assertEquals(false, test.isConnected(Interval.of(NOW2.plusSeconds(1), NOW2.plusSeconds(2)))); } @Test public void test_isConnected_Interval_empty() { Interval test = Interval.of(NOW1, NOW1); // completely before - assertEquals(test.isConnected(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1))), false); - assertEquals(test.isConnected(Interval.of(NOW1.minusSeconds(1), NOW1)), true); + assertEquals(false, test.isConnected(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1)))); + assertEquals(true, test.isConnected(Interval.of(NOW1.minusSeconds(1), NOW1))); // equal - assertEquals(test.isConnected(Interval.of(NOW1, NOW1)), true); + assertEquals(true, test.isConnected(Interval.of(NOW1, NOW1))); // completely after - assertEquals(test.isConnected(Interval.of(NOW1, NOW1.plusSeconds(1))), true); - assertEquals(test.isConnected(Interval.of(NOW1.plusSeconds(1), NOW1.plusSeconds(2))), false); + assertEquals(true, test.isConnected(Interval.of(NOW1, NOW1.plusSeconds(1)))); + assertEquals(false, test.isConnected(Interval.of(NOW1.plusSeconds(1), NOW1.plusSeconds(2)))); } @Test(expected = NullPointerException.class) @@ -424,34 +424,34 @@ public void test_isConnected_Interval_null() { public void test_overlaps_Interval() { Interval test = Interval.of(NOW1, NOW2); // completely before - assertEquals(test.overlaps(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1))), false); - assertEquals(test.overlaps(Interval.of(NOW1.minusSeconds(1), NOW1)), false); + assertEquals(false, test.overlaps(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1)))); + assertEquals(false, test.overlaps(Interval.of(NOW1.minusSeconds(1), NOW1))); // partly before - assertEquals(test.overlaps(Interval.of(NOW1.minusSeconds(1), NOW2)), true); - assertEquals(test.overlaps(Interval.of(NOW1.minusSeconds(1), NOW2.minusSeconds(1))), true); + assertEquals(true, test.overlaps(Interval.of(NOW1.minusSeconds(1), NOW2))); + assertEquals(true, test.overlaps(Interval.of(NOW1.minusSeconds(1), NOW2.minusSeconds(1)))); // contained - assertEquals(test.overlaps(Interval.of(NOW1, NOW2.minusSeconds(1))), true); - assertEquals(test.overlaps(Interval.of(NOW1, NOW2)), true); - assertEquals(test.overlaps(Interval.of(NOW1.plusSeconds(1), NOW2)), true); + assertEquals(true, test.overlaps(Interval.of(NOW1, NOW2.minusSeconds(1)))); + assertEquals(true, test.overlaps(Interval.of(NOW1, NOW2))); + assertEquals(true, test.overlaps(Interval.of(NOW1.plusSeconds(1), NOW2))); // partly after - assertEquals(test.overlaps(Interval.of(NOW1, NOW2.plusSeconds(1))), true); - assertEquals(test.overlaps(Interval.of(NOW1.plusSeconds(1), NOW2.plusSeconds(1))), true); + assertEquals(true, test.overlaps(Interval.of(NOW1, NOW2.plusSeconds(1)))); + assertEquals(true, test.overlaps(Interval.of(NOW1.plusSeconds(1), NOW2.plusSeconds(1)))); // completely after - assertEquals(test.overlaps(Interval.of(NOW2, NOW2.plusSeconds(1))), false); - assertEquals(test.overlaps(Interval.of(NOW2.plusSeconds(1), NOW2.plusSeconds(2))), false); + assertEquals(false, test.overlaps(Interval.of(NOW2, NOW2.plusSeconds(1)))); + assertEquals(false, test.overlaps(Interval.of(NOW2.plusSeconds(1), NOW2.plusSeconds(2)))); } @Test public void test_overlaps_Interval_empty() { Interval test = Interval.of(NOW1, NOW1); // completely before - assertEquals(test.overlaps(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1))), false); - assertEquals(test.overlaps(Interval.of(NOW1.minusSeconds(1), NOW1)), false); + assertEquals(false, test.overlaps(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1)))); + assertEquals(false, test.overlaps(Interval.of(NOW1.minusSeconds(1), NOW1))); // equal - assertEquals(test.overlaps(Interval.of(NOW1, NOW1)), true); + assertEquals(true, test.overlaps(Interval.of(NOW1, NOW1))); // completely after - assertEquals(test.overlaps(Interval.of(NOW1, NOW1.plusSeconds(1))), false); - assertEquals(test.overlaps(Interval.of(NOW1.plusSeconds(1), NOW1.plusSeconds(2))), false); + assertEquals(false, test.overlaps(Interval.of(NOW1, NOW1.plusSeconds(1)))); + assertEquals(false, test.overlaps(Interval.of(NOW1.plusSeconds(1), NOW1.plusSeconds(2)))); } @Test(expected = NullPointerException.class) @@ -486,7 +486,7 @@ public void test_intersection( Interval test2 = Interval.of(start2, end2); Interval expected = Interval.of(expStart, expEnd); assertTrue(test1.isConnected(test2)); - assertEquals(test1.intersection(test2), expected); + assertEquals(expected, test1.intersection(test2)); } @Test @@ -498,21 +498,21 @@ public void test_intersection_reverse( Interval test2 = Interval.of(start2, end2); Interval expected = Interval.of(expStart, expEnd); assertTrue(test2.isConnected(test1)); - assertEquals(test2.intersection(test1), expected); + assertEquals(expected, test2.intersection(test1)); } @Test(expected = DateTimeException.class) public void test_intersectionBad() { Interval test1 = Interval.of(NOW1, NOW2); Interval test2 = Interval.of(NOW3, NOW4); - assertEquals(test1.isConnected(test2), false); + assertEquals(false, test1.isConnected(test2)); test1.intersection(test2); } @Test public void test_intersection_same() { Interval test = Interval.of(NOW2, NOW4); - assertEquals(test.intersection(test), test); + assertEquals(test, test.intersection(test)); } //----------------------------------------------------------------------- @@ -541,8 +541,8 @@ public void test_unionAndSpan( Interval test2 = Interval.of(start2, end2); Interval expected = Interval.of(expStart, expEnd); assertTrue(test1.isConnected(test2)); - assertEquals(test1.union(test2), expected); - assertEquals(test1.span(test2), expected); + assertEquals(expected, test1.union(test2)); + assertEquals(expected, test1.span(test2)); } @Test @@ -554,8 +554,8 @@ public void test_unionAndSpan_reverse( Interval test2 = Interval.of(start2, end2); Interval expected = Interval.of(expStart, expEnd); assertTrue(test2.isConnected(test1)); - assertEquals(test2.union(test1), expected); - assertEquals(test2.span(test1), expected); + assertEquals(expected, test2.union(test1)); + assertEquals(expected, test2.span(test1)); } @Test @@ -566,8 +566,8 @@ public void test_span_enclosesInputs( Interval test1 = Interval.of(start1, end1); Interval test2 = Interval.of(start2, end2); Interval expected = Interval.of(expStart, expEnd); - assertEquals(expected.encloses(test1), true); - assertEquals(expected.encloses(test2), true); + assertEquals(true, expected.encloses(test1)); + assertEquals(true, expected.encloses(test2)); } @Test(expected = DateTimeException.class) @@ -583,52 +583,52 @@ public void test_span_disconnected() { Interval test1 = Interval.of(NOW1, NOW2); Interval test2 = Interval.of(NOW3, NOW4); assertFalse(test1.isConnected(test2)); - assertEquals(test1.span(test2), Interval.of(NOW1, NOW4)); + assertEquals(Interval.of(NOW1, NOW4), test1.span(test2)); } @Test public void test_unionAndSpan_same() { Interval test = Interval.of(NOW2, NOW4); - assertEquals(test.union(test), test); - assertEquals(test.span(test), test); + assertEquals(test, test.union(test)); + assertEquals(test, test.span(test)); } //----------------------------------------------------------------------- @Test public void test_isAfter_Instant() { Interval test = Interval.of(NOW1, NOW2); - assertEquals(test.isAfter(NOW1.minusSeconds(2)), true); - assertEquals(test.isAfter(NOW1.minusSeconds(1)), true); - assertEquals(test.isAfter(NOW1), false); - assertEquals(test.isAfter(NOW2), false); - assertEquals(test.isAfter(NOW2.plusSeconds(1)), false); + assertEquals(true, test.isAfter(NOW1.minusSeconds(2))); + assertEquals(true, test.isAfter(NOW1.minusSeconds(1))); + assertEquals(false, test.isAfter(NOW1)); + assertEquals(false, test.isAfter(NOW2)); + assertEquals(false, test.isAfter(NOW2.plusSeconds(1))); } @Test public void test_isAfter_Instant_empty() { Interval test = Interval.of(NOW1, NOW1); - assertEquals(test.isAfter(NOW1.minusSeconds(2)), true); - assertEquals(test.isAfter(NOW1.minusSeconds(1)), true); - assertEquals(test.isAfter(NOW1), false); - assertEquals(test.isAfter(NOW1.plusSeconds(1)), false); + assertEquals(true, test.isAfter(NOW1.minusSeconds(2))); + assertEquals(true, test.isAfter(NOW1.minusSeconds(1))); + assertEquals(false, test.isAfter(NOW1)); + assertEquals(false, test.isAfter(NOW1.plusSeconds(1))); } //----------------------------------------------------------------------- @Test public void test_isBefore_Instant() { Interval test = Interval.of(NOW1, NOW2); - assertEquals(test.isBefore(NOW1.minusSeconds(1)), false); - assertEquals(test.isBefore(NOW1), false); - assertEquals(test.isBefore(NOW2), true); - assertEquals(test.isBefore(NOW2.plusSeconds(1)), true); + assertEquals(false, test.isBefore(NOW1.minusSeconds(1))); + assertEquals(false, test.isBefore(NOW1)); + assertEquals(true, test.isBefore(NOW2)); + assertEquals(true, test.isBefore(NOW2.plusSeconds(1))); } @Test public void test_isBefore_Instant_empty() { Interval test = Interval.of(NOW1, NOW1); - assertEquals(test.isBefore(NOW1.minusSeconds(1)), false); - assertEquals(test.isBefore(NOW1), false); - assertEquals(test.isBefore(NOW1.plusSeconds(1)), true); + assertEquals(false, test.isBefore(NOW1.minusSeconds(1))); + assertEquals(false, test.isBefore(NOW1)); + assertEquals(true, test.isBefore(NOW1.plusSeconds(1))); } //----------------------------------------------------------------------- @@ -636,34 +636,34 @@ public void test_isBefore_Instant_empty() { public void test_isAfter_Interval() { Interval test = Interval.of(NOW1, NOW2); // completely before - assertEquals(test.isAfter(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1))), true); - assertEquals(test.isAfter(Interval.of(NOW1.minusSeconds(1), NOW1)), true); + assertEquals(true, test.isAfter(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1)))); + assertEquals(true, test.isAfter(Interval.of(NOW1.minusSeconds(1), NOW1))); // partly before - assertEquals(test.isAfter(Interval.of(NOW1.minusSeconds(1), NOW2)), false); - assertEquals(test.isAfter(Interval.of(NOW1.minusSeconds(1), NOW2.minusSeconds(1))), false); + assertEquals(false, test.isAfter(Interval.of(NOW1.minusSeconds(1), NOW2))); + assertEquals(false, test.isAfter(Interval.of(NOW1.minusSeconds(1), NOW2.minusSeconds(1)))); // contained - assertEquals(test.isAfter(Interval.of(NOW1, NOW2.minusSeconds(1))), false); - assertEquals(test.isAfter(Interval.of(NOW1, NOW2)), false); - assertEquals(test.isAfter(Interval.of(NOW1.plusSeconds(1), NOW2)), false); + assertEquals(false, test.isAfter(Interval.of(NOW1, NOW2.minusSeconds(1)))); + assertEquals(false, test.isAfter(Interval.of(NOW1, NOW2))); + assertEquals(false, test.isAfter(Interval.of(NOW1.plusSeconds(1), NOW2))); // partly after - assertEquals(test.isAfter(Interval.of(NOW1, NOW2.plusSeconds(1))), false); - assertEquals(test.isAfter(Interval.of(NOW1.plusSeconds(1), NOW2.plusSeconds(1))), false); + assertEquals(false, test.isAfter(Interval.of(NOW1, NOW2.plusSeconds(1)))); + assertEquals(false, test.isAfter(Interval.of(NOW1.plusSeconds(1), NOW2.plusSeconds(1)))); // completely after - assertEquals(test.isAfter(Interval.of(NOW2, NOW2.plusSeconds(1))), false); - assertEquals(test.isAfter(Interval.of(NOW2.plusSeconds(1), NOW2.plusSeconds(2))), false); + assertEquals(false, test.isAfter(Interval.of(NOW2, NOW2.plusSeconds(1)))); + assertEquals(false, test.isAfter(Interval.of(NOW2.plusSeconds(1), NOW2.plusSeconds(2)))); } @Test public void test_isAfter_Interval_empty() { Interval test = Interval.of(NOW1, NOW1); // completely before - assertEquals(test.isAfter(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1))), true); - assertEquals(test.isAfter(Interval.of(NOW1.minusSeconds(1), NOW1)), true); + assertEquals(true, test.isAfter(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1)))); + assertEquals(true, test.isAfter(Interval.of(NOW1.minusSeconds(1), NOW1))); // equal - assertEquals(test.isAfter(Interval.of(NOW1, NOW1)), false); + assertEquals(false, test.isAfter(Interval.of(NOW1, NOW1))); // completely after - assertEquals(test.isAfter(Interval.of(NOW1, NOW1.plusSeconds(1))), false); - assertEquals(test.isAfter(Interval.of(NOW1.plusSeconds(1), NOW1.plusSeconds(2))), false); + assertEquals(false, test.isAfter(Interval.of(NOW1, NOW1.plusSeconds(1)))); + assertEquals(false, test.isAfter(Interval.of(NOW1.plusSeconds(1), NOW1.plusSeconds(2)))); } //----------------------------------------------------------------------- @@ -671,41 +671,41 @@ public void test_isAfter_Interval_empty() { public void test_isBefore_Interval() { Interval test = Interval.of(NOW1, NOW2); // completely before - assertEquals(test.isBefore(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1))), false); - assertEquals(test.isBefore(Interval.of(NOW1.minusSeconds(1), NOW1)), false); + assertEquals(false, test.isBefore(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1)))); + assertEquals(false, test.isBefore(Interval.of(NOW1.minusSeconds(1), NOW1))); // partly before - assertEquals(test.isBefore(Interval.of(NOW1.minusSeconds(1), NOW2)), false); - assertEquals(test.isBefore(Interval.of(NOW1.minusSeconds(1), NOW2.minusSeconds(1))), false); + assertEquals(false, test.isBefore(Interval.of(NOW1.minusSeconds(1), NOW2))); + assertEquals(false, test.isBefore(Interval.of(NOW1.minusSeconds(1), NOW2.minusSeconds(1)))); // contained - assertEquals(test.isBefore(Interval.of(NOW1, NOW2.minusSeconds(1))), false); - assertEquals(test.isBefore(Interval.of(NOW1, NOW2)), false); - assertEquals(test.isBefore(Interval.of(NOW1.plusSeconds(1), NOW2)), false); + assertEquals(false, test.isBefore(Interval.of(NOW1, NOW2.minusSeconds(1)))); + assertEquals(false, test.isBefore(Interval.of(NOW1, NOW2))); + assertEquals(false, test.isBefore(Interval.of(NOW1.plusSeconds(1), NOW2))); // partly after - assertEquals(test.isBefore(Interval.of(NOW1, NOW2.plusSeconds(1))), false); - assertEquals(test.isBefore(Interval.of(NOW1.plusSeconds(1), NOW2.plusSeconds(1))), false); + assertEquals(false, test.isBefore(Interval.of(NOW1, NOW2.plusSeconds(1)))); + assertEquals(false, test.isBefore(Interval.of(NOW1.plusSeconds(1), NOW2.plusSeconds(1)))); // completely after - assertEquals(test.isBefore(Interval.of(NOW2, NOW2.plusSeconds(1))), true); - assertEquals(test.isBefore(Interval.of(NOW2.plusSeconds(1), NOW2.plusSeconds(2))), true); + assertEquals(true, test.isBefore(Interval.of(NOW2, NOW2.plusSeconds(1)))); + assertEquals(true, test.isBefore(Interval.of(NOW2.plusSeconds(1), NOW2.plusSeconds(2)))); } @Test public void test_isBefore_Interval_empty() { Interval test = Interval.of(NOW1, NOW1); // completely before - assertEquals(test.isBefore(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1))), false); - assertEquals(test.isBefore(Interval.of(NOW1.minusSeconds(1), NOW1)), false); + assertEquals(false, test.isBefore(Interval.of(NOW1.minusSeconds(2), NOW1.minusSeconds(1)))); + assertEquals(false, test.isBefore(Interval.of(NOW1.minusSeconds(1), NOW1))); // equal - assertEquals(test.isBefore(Interval.of(NOW1, NOW1)), false); + assertEquals(false, test.isBefore(Interval.of(NOW1, NOW1))); // completely after - assertEquals(test.isBefore(Interval.of(NOW1, NOW1.plusSeconds(1))), true); - assertEquals(test.isBefore(Interval.of(NOW1.plusSeconds(1), NOW1.plusSeconds(2))), true); + assertEquals(true, test.isBefore(Interval.of(NOW1, NOW1.plusSeconds(1)))); + assertEquals(true, test.isBefore(Interval.of(NOW1.plusSeconds(1), NOW1.plusSeconds(2)))); } //----------------------------------------------------------------------- @Test public void test_toDuration() { Interval test = Interval.of(NOW1, NOW2); - assertEquals(test.toDuration(), Duration.between(NOW1, NOW2)); + assertEquals(Duration.between(NOW1, NOW2), test.toDuration()); } //----------------------------------------------------------------------- @@ -715,20 +715,20 @@ public void test_equals() { Interval a2 = Interval.of(NOW1, NOW2); Interval b = Interval.of(NOW1, NOW3); Interval c = Interval.of(NOW2, NOW2); - assertEquals(a.equals(a), true); - assertEquals(a.equals(a2), true); - assertEquals(a.equals(b), false); - assertEquals(a.equals(c), false); - assertEquals(a.equals(null), false); - assertEquals(a.equals(""), false); - assertEquals(a.hashCode() == a2.hashCode(), true); + assertEquals(true, a.equals(a)); + assertEquals(true, a.equals(a2)); + assertEquals(false, a.equals(b)); + assertEquals(false, a.equals(c)); + assertEquals(false, a.equals(null)); + assertEquals(false, a.equals("")); + assertEquals(true, a.hashCode() == a2.hashCode()); } //----------------------------------------------------------------------- @Test public void test_toString() { Interval test = Interval.of(NOW1, NOW2); - assertEquals(test.toString(), NOW1 + "/" + NOW2); + assertEquals(NOW1 + "/" + NOW2, test.toString()); } } diff --git a/src/test/java/org/threeten/extra/TestLocalDateRange.java b/src/test/java/org/threeten/extra/TestLocalDateRange.java index 626cb768..fe41be36 100644 --- a/src/test/java/org/threeten/extra/TestLocalDateRange.java +++ b/src/test/java/org/threeten/extra/TestLocalDateRange.java @@ -77,86 +77,86 @@ public class TestLocalDateRange { @Test public void test_ALL() { LocalDateRange test = LocalDateRange.ALL; - assertEquals(test.getStart(), LocalDate.MIN); - assertEquals(test.getEndInclusive(), LocalDate.MAX); - assertEquals(test.getEnd(), LocalDate.MAX); - assertEquals(test.isEmpty(), false); - assertEquals(test.isUnboundedStart(), true); - assertEquals(test.isUnboundedEnd(), true); - assertEquals(test.toString(), "-999999999-01-01/+999999999-12-31"); + assertEquals(LocalDate.MIN, test.getStart()); + assertEquals(LocalDate.MAX, test.getEndInclusive()); + assertEquals(LocalDate.MAX, test.getEnd()); + assertEquals(false, test.isEmpty()); + assertEquals(true, test.isUnboundedStart()); + assertEquals(true, test.isUnboundedEnd()); + assertEquals("-999999999-01-01/+999999999-12-31", test.toString()); } //----------------------------------------------------------------------- @Test public void test_of() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); - assertEquals(test.getStart(), DATE_2012_07_28); - assertEquals(test.getEndInclusive(), DATE_2012_07_30); - assertEquals(test.getEnd(), DATE_2012_07_31); - assertEquals(test.isEmpty(), false); - assertEquals(test.isUnboundedStart(), false); - assertEquals(test.isUnboundedEnd(), false); - assertEquals(test.toString(), "2012-07-28/2012-07-31"); + assertEquals(DATE_2012_07_28, test.getStart()); + assertEquals(DATE_2012_07_30, test.getEndInclusive()); + assertEquals(DATE_2012_07_31, test.getEnd()); + assertEquals(false, test.isEmpty()); + assertEquals(false, test.isUnboundedStart()); + assertEquals(false, test.isUnboundedEnd()); + assertEquals("2012-07-28/2012-07-31", test.toString()); } @Test public void test_of_MIN() { LocalDateRange test = LocalDateRange.of(LocalDate.MIN, DATE_2012_07_31); - assertEquals(test.getStart(), LocalDate.MIN); - assertEquals(test.getEndInclusive(), DATE_2012_07_30); - assertEquals(test.getEnd(), DATE_2012_07_31); - assertEquals(test.isEmpty(), false); - assertEquals(test.isUnboundedStart(), true); - assertEquals(test.isUnboundedEnd(), false); - assertEquals(test.toString(), "-999999999-01-01/2012-07-31"); + assertEquals(LocalDate.MIN, test.getStart()); + assertEquals(DATE_2012_07_30, test.getEndInclusive()); + assertEquals(DATE_2012_07_31, test.getEnd()); + assertEquals(false, test.isEmpty()); + assertEquals(true, test.isUnboundedStart()); + assertEquals(false, test.isUnboundedEnd()); + assertEquals("-999999999-01-01/2012-07-31", test.toString()); } @Test public void test_of_MAX() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, LocalDate.MAX); - assertEquals(test.getStart(), DATE_2012_07_28); - assertEquals(test.getEndInclusive(), LocalDate.MAX); - assertEquals(test.getEnd(), LocalDate.MAX); - assertEquals(test.isEmpty(), false); - assertEquals(test.isUnboundedStart(), false); - assertEquals(test.isUnboundedEnd(), true); - assertEquals(test.toString(), "2012-07-28/+999999999-12-31"); + assertEquals(DATE_2012_07_28, test.getStart()); + assertEquals(LocalDate.MAX, test.getEndInclusive()); + assertEquals(LocalDate.MAX, test.getEnd()); + assertEquals(false, test.isEmpty()); + assertEquals(false, test.isUnboundedStart()); + assertEquals(true, test.isUnboundedEnd()); + assertEquals("2012-07-28/+999999999-12-31", test.toString()); } @Test public void test_of_MIN_MAX() { LocalDateRange test = LocalDateRange.of(LocalDate.MIN, LocalDate.MAX); - assertEquals(test.getStart(), LocalDate.MIN); - assertEquals(test.getEndInclusive(), LocalDate.MAX); - assertEquals(test.getEnd(), LocalDate.MAX); - assertEquals(test.isEmpty(), false); - assertEquals(test.isUnboundedStart(), true); - assertEquals(test.isUnboundedEnd(), true); - assertEquals(test.toString(), "-999999999-01-01/+999999999-12-31"); + assertEquals(LocalDate.MIN, test.getStart()); + assertEquals(LocalDate.MAX, test.getEndInclusive()); + assertEquals(LocalDate.MAX, test.getEnd()); + assertEquals(false, test.isEmpty()); + assertEquals(true, test.isUnboundedStart()); + assertEquals(true, test.isUnboundedEnd()); + assertEquals("-999999999-01-01/+999999999-12-31", test.toString()); } @Test public void test_of_MIN_MIN() { LocalDateRange test = LocalDateRange.of(LocalDate.MIN, LocalDate.MIN); - assertEquals(test.getStart(), LocalDate.MIN); - assertEquals(test.getEndInclusive(), LocalDate.MIN); - assertEquals(test.getEnd(), LocalDate.MIN); - assertEquals(test.isEmpty(), true); - assertEquals(test.isUnboundedStart(), true); - assertEquals(test.isUnboundedEnd(), false); - assertEquals(test.toString(), "-999999999-01-01/-999999999-01-01"); + assertEquals(LocalDate.MIN, test.getStart()); + assertEquals(LocalDate.MIN, test.getEndInclusive()); + assertEquals(LocalDate.MIN, test.getEnd()); + assertEquals(true, test.isEmpty()); + assertEquals(true, test.isUnboundedStart()); + assertEquals(false, test.isUnboundedEnd()); + assertEquals("-999999999-01-01/-999999999-01-01", test.toString()); } @Test public void test_of_empty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_30, DATE_2012_07_30); - assertEquals(test.getStart(), DATE_2012_07_30); - assertEquals(test.getEndInclusive(), DATE_2012_07_29); - assertEquals(test.getEnd(), DATE_2012_07_30); - assertEquals(test.isEmpty(), true); - assertEquals(test.isUnboundedStart(), false); - assertEquals(test.isUnboundedEnd(), false); - assertEquals(test.toString(), "2012-07-30/2012-07-30"); + assertEquals(DATE_2012_07_30, test.getStart()); + assertEquals(DATE_2012_07_29, test.getEndInclusive()); + assertEquals(DATE_2012_07_30, test.getEnd()); + assertEquals(true, test.isEmpty()); + assertEquals(false, test.isUnboundedStart()); + assertEquals(false, test.isUnboundedEnd()); + assertEquals("2012-07-30/2012-07-30", test.toString()); } @Test(expected = DateTimeException.class) @@ -168,45 +168,45 @@ public void test_of_badOrder() { @Test public void test_ofClosed() { LocalDateRange test = LocalDateRange.ofClosed(DATE_2012_07_28, DATE_2012_07_30); - assertEquals(test.getStart(), DATE_2012_07_28); - assertEquals(test.getEndInclusive(), DATE_2012_07_30); - assertEquals(test.getEnd(), DATE_2012_07_31); - assertEquals(test.isUnboundedStart(), false); - assertEquals(test.isUnboundedEnd(), false); - assertEquals(test.toString(), "2012-07-28/2012-07-31"); + assertEquals(DATE_2012_07_28, test.getStart()); + assertEquals(DATE_2012_07_30, test.getEndInclusive()); + assertEquals(DATE_2012_07_31, test.getEnd()); + assertEquals(false, test.isUnboundedStart()); + assertEquals(false, test.isUnboundedEnd()); + assertEquals("2012-07-28/2012-07-31", test.toString()); } @Test public void test_ofClosed_MIN() { LocalDateRange test = LocalDateRange.ofClosed(LocalDate.MIN, DATE_2012_07_30); - assertEquals(test.getStart(), LocalDate.MIN); - assertEquals(test.getEndInclusive(), DATE_2012_07_30); - assertEquals(test.getEnd(), DATE_2012_07_31); - assertEquals(test.isUnboundedStart(), true); - assertEquals(test.isUnboundedEnd(), false); - assertEquals(test.toString(), "-999999999-01-01/2012-07-31"); + assertEquals(LocalDate.MIN, test.getStart()); + assertEquals(DATE_2012_07_30, test.getEndInclusive()); + assertEquals(DATE_2012_07_31, test.getEnd()); + assertEquals(true, test.isUnboundedStart()); + assertEquals(false, test.isUnboundedEnd()); + assertEquals("-999999999-01-01/2012-07-31", test.toString()); } @Test public void test_ofClosed_MAX() { LocalDateRange test = LocalDateRange.ofClosed(DATE_2012_07_28, LocalDate.MAX); - assertEquals(test.getStart(), DATE_2012_07_28); - assertEquals(test.getEndInclusive(), LocalDate.MAX); - assertEquals(test.getEnd(), LocalDate.MAX); - assertEquals(test.isUnboundedStart(), false); - assertEquals(test.isUnboundedEnd(), true); - assertEquals(test.toString(), "2012-07-28/+999999999-12-31"); + assertEquals(DATE_2012_07_28, test.getStart()); + assertEquals(LocalDate.MAX, test.getEndInclusive()); + assertEquals(LocalDate.MAX, test.getEnd()); + assertEquals(false, test.isUnboundedStart()); + assertEquals(true, test.isUnboundedEnd()); + assertEquals("2012-07-28/+999999999-12-31", test.toString()); } @Test public void test_ofClosed_MIN_MAX() { LocalDateRange test = LocalDateRange.ofClosed(LocalDate.MIN, LocalDate.MAX); - assertEquals(test.getStart(), LocalDate.MIN); - assertEquals(test.getEndInclusive(), LocalDate.MAX); - assertEquals(test.getEnd(), LocalDate.MAX); - assertEquals(test.isUnboundedStart(), true); - assertEquals(test.isUnboundedEnd(), true); - assertEquals(test.toString(), "-999999999-01-01/+999999999-12-31"); + assertEquals(LocalDate.MIN, test.getStart()); + assertEquals(LocalDate.MAX, test.getEndInclusive()); + assertEquals(LocalDate.MAX, test.getEnd()); + assertEquals(true, test.isUnboundedStart()); + assertEquals(true, test.isUnboundedEnd()); + assertEquals("-999999999-01-01/+999999999-12-31", test.toString()); } @Test(expected = DateTimeException.class) @@ -218,12 +218,12 @@ public void test_ofClosed_badOrder() { @Test public void test_of_period() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, Period.ofDays(3)); - assertEquals(test.getStart(), DATE_2012_07_28); - assertEquals(test.getEndInclusive(), DATE_2012_07_30); - assertEquals(test.getEnd(), DATE_2012_07_31); - assertEquals(test.isUnboundedStart(), false); - assertEquals(test.isUnboundedEnd(), false); - assertEquals(test.toString(), "2012-07-28/2012-07-31"); + assertEquals(DATE_2012_07_28, test.getStart()); + assertEquals(DATE_2012_07_30, test.getEndInclusive()); + assertEquals(DATE_2012_07_31, test.getEnd()); + assertEquals(false, test.isUnboundedStart()); + assertEquals(false, test.isUnboundedEnd()); + assertEquals("2012-07-28/2012-07-31", test.toString()); } @Test(expected = DateTimeException.class) @@ -235,43 +235,43 @@ public void test_of_period_negative() { @Test public void test_parse_CharSequence() { LocalDateRange test = LocalDateRange.parse(DATE_2012_07_27 + "/" + DATE_2012_07_29); - assertEquals(test.getStart(), DATE_2012_07_27); - assertEquals(test.getEnd(), DATE_2012_07_29); + assertEquals(DATE_2012_07_27, test.getStart()); + assertEquals(DATE_2012_07_29, test.getEnd()); } @Test public void test_parse_CharSequence_PeriodLocalDate() { LocalDateRange test = LocalDateRange.parse("P2D/" + DATE_2012_07_29); - assertEquals(test.getStart(), DATE_2012_07_27); - assertEquals(test.getEnd(), DATE_2012_07_29); + assertEquals(DATE_2012_07_27, test.getStart()); + assertEquals(DATE_2012_07_29, test.getEnd()); } @Test public void test_parse_CharSequence_PeriodLocalDate_case() { LocalDateRange test = LocalDateRange.parse("p2d/" + DATE_2012_07_29); - assertEquals(test.getStart(), DATE_2012_07_27); - assertEquals(test.getEnd(), DATE_2012_07_29); + assertEquals(DATE_2012_07_27, test.getStart()); + assertEquals(DATE_2012_07_29, test.getEnd()); } @Test public void test_parse_CharSequence_LocalDatePeriod() { LocalDateRange test = LocalDateRange.parse(DATE_2012_07_27 + "/P2D"); - assertEquals(test.getStart(), DATE_2012_07_27); - assertEquals(test.getEnd(), DATE_2012_07_29); + assertEquals(DATE_2012_07_27, test.getStart()); + assertEquals(DATE_2012_07_29, test.getEnd()); } @Test public void test_parse_CharSequence_LocalDatePeriod_case() { LocalDateRange test = LocalDateRange.parse(DATE_2012_07_27 + "/p2d"); - assertEquals(test.getStart(), DATE_2012_07_27); - assertEquals(test.getEnd(), DATE_2012_07_29); + assertEquals(DATE_2012_07_27, test.getStart()); + assertEquals(DATE_2012_07_29, test.getEnd()); } @Test public void test_parse_CharSequence_empty() { LocalDateRange test = LocalDateRange.parse(DATE_2012_07_27 + "/" + DATE_2012_07_27); - assertEquals(test.getStart(), DATE_2012_07_27); - assertEquals(test.getEnd(), DATE_2012_07_27); + assertEquals(DATE_2012_07_27, test.getStart()); + assertEquals(DATE_2012_07_27, test.getEnd()); } @Test(expected = DateTimeException.class) @@ -303,7 +303,7 @@ public void test_serialization() throws Exception { oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertEquals(ois.readObject(), test); + assertEquals(test, ois.readObject()); } } @@ -312,36 +312,36 @@ public void test_serialization() throws Exception { public void test_withStart() { LocalDateRange base = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); LocalDateRange test = base.withStart(DATE_2012_07_27); - assertEquals(test.getStart(), DATE_2012_07_27); - assertEquals(test.getEndInclusive(), DATE_2012_07_30); - assertEquals(test.getEnd(), DATE_2012_07_31); + assertEquals(DATE_2012_07_27, test.getStart()); + assertEquals(DATE_2012_07_30, test.getEndInclusive()); + assertEquals(DATE_2012_07_31, test.getEnd()); } @Test public void test_withStart_adjuster() { LocalDateRange base = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); LocalDateRange test = base.withStart(date -> date.minus(1, ChronoUnit.WEEKS)); - assertEquals(test.getStart(), DATE_2012_07_28.minusWeeks(1)); - assertEquals(test.getEndInclusive(), DATE_2012_07_30); - assertEquals(test.getEnd(), DATE_2012_07_31); + assertEquals(DATE_2012_07_28.minusWeeks(1), test.getStart()); + assertEquals(DATE_2012_07_30, test.getEndInclusive()); + assertEquals(DATE_2012_07_31, test.getEnd()); } @Test public void test_withStart_min() { LocalDateRange base = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); LocalDateRange test = base.withStart(LocalDate.MIN); - assertEquals(test.getStart(), LocalDate.MIN); - assertEquals(test.getEndInclusive(), DATE_2012_07_30); - assertEquals(test.getEnd(), DATE_2012_07_31); + assertEquals(LocalDate.MIN, test.getStart()); + assertEquals(DATE_2012_07_30, test.getEndInclusive()); + assertEquals(DATE_2012_07_31, test.getEnd()); } @Test public void test_withStart_empty() { LocalDateRange base = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); LocalDateRange test = base.withStart(DATE_2012_07_31); - assertEquals(test.getStart(), DATE_2012_07_31); - assertEquals(test.getEndInclusive(), DATE_2012_07_30); - assertEquals(test.getEnd(), DATE_2012_07_31); + assertEquals(DATE_2012_07_31, test.getStart()); + assertEquals(DATE_2012_07_30, test.getEndInclusive()); + assertEquals(DATE_2012_07_31, test.getEnd()); } @Test(expected = DateTimeException.class) @@ -355,36 +355,36 @@ public void test_withStart_invalid() { public void test_withEnd() { LocalDateRange base = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); LocalDateRange test = base.withEnd(DATE_2012_07_30); - assertEquals(test.getStart(), DATE_2012_07_28); - assertEquals(test.getEndInclusive(), DATE_2012_07_29); - assertEquals(test.getEnd(), DATE_2012_07_30); + assertEquals(DATE_2012_07_28, test.getStart()); + assertEquals(DATE_2012_07_29, test.getEndInclusive()); + assertEquals(DATE_2012_07_30, test.getEnd()); } @Test public void test_withEnd_adjuster() { LocalDateRange base = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); LocalDateRange test = base.withEnd(date -> date.plus(1, ChronoUnit.WEEKS)); - assertEquals(test.getStart(), DATE_2012_07_28); - assertEquals(test.getEndInclusive(), DATE_2012_07_30.plusWeeks(1)); - assertEquals(test.getEnd(), DATE_2012_07_31.plusWeeks(1)); + assertEquals(DATE_2012_07_28, test.getStart()); + assertEquals(DATE_2012_07_30.plusWeeks(1), test.getEndInclusive()); + assertEquals(DATE_2012_07_31.plusWeeks(1), test.getEnd()); } @Test public void test_withEnd_max() { LocalDateRange base = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); LocalDateRange test = base.withEnd(LocalDate.MAX); - assertEquals(test.getStart(), DATE_2012_07_28); - assertEquals(test.getEndInclusive(), LocalDate.MAX); - assertEquals(test.getEnd(), LocalDate.MAX); + assertEquals(DATE_2012_07_28, test.getStart()); + assertEquals(LocalDate.MAX, test.getEndInclusive()); + assertEquals(LocalDate.MAX, test.getEnd()); } @Test public void test_withEnd_empty() { LocalDateRange base = LocalDateRange.of(DATE_2012_07_30, DATE_2012_07_31); LocalDateRange test = base.withEnd(DATE_2012_07_30); - assertEquals(test.getStart(), DATE_2012_07_30); - assertEquals(test.getEndInclusive(), DATE_2012_07_29); - assertEquals(test.getEnd(), DATE_2012_07_30); + assertEquals(DATE_2012_07_30, test.getStart()); + assertEquals(DATE_2012_07_29, test.getEndInclusive()); + assertEquals(DATE_2012_07_30, test.getEnd()); } @Test(expected = DateTimeException.class) @@ -397,37 +397,37 @@ public void test_withEnd_invalid() { @Test public void test_contains() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); - assertEquals(test.contains(LocalDate.MIN), false); - assertEquals(test.contains(DATE_2012_07_27), false); - assertEquals(test.contains(DATE_2012_07_28), true); - assertEquals(test.contains(DATE_2012_07_29), true); - assertEquals(test.contains(DATE_2012_07_30), true); - assertEquals(test.contains(DATE_2012_07_31), false); - assertEquals(test.contains(DATE_2012_08_01), false); - assertEquals(test.contains(LocalDate.MAX), false); + assertEquals(false, test.contains(LocalDate.MIN)); + assertEquals(false, test.contains(DATE_2012_07_27)); + assertEquals(true, test.contains(DATE_2012_07_28)); + assertEquals(true, test.contains(DATE_2012_07_29)); + assertEquals(true, test.contains(DATE_2012_07_30)); + assertEquals(false, test.contains(DATE_2012_07_31)); + assertEquals(false, test.contains(DATE_2012_08_01)); + assertEquals(false, test.contains(LocalDate.MAX)); } @Test public void test_contains_baseEmpty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28); - assertEquals(test.contains(LocalDate.MIN), false); - assertEquals(test.contains(DATE_2012_07_27), false); - assertEquals(test.contains(DATE_2012_07_28), false); - assertEquals(test.contains(DATE_2012_07_29), false); - assertEquals(test.contains(LocalDate.MAX), false); + assertEquals(false, test.contains(LocalDate.MIN)); + assertEquals(false, test.contains(DATE_2012_07_27)); + assertEquals(false, test.contains(DATE_2012_07_28)); + assertEquals(false, test.contains(DATE_2012_07_29)); + assertEquals(false, test.contains(LocalDate.MAX)); } @Test public void test_contains_max() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, LocalDate.MAX); - assertEquals(test.contains(LocalDate.MIN), false); - assertEquals(test.contains(DATE_2012_07_27), false); - assertEquals(test.contains(DATE_2012_07_28), true); - assertEquals(test.contains(DATE_2012_07_29), true); - assertEquals(test.contains(DATE_2012_07_30), true); - assertEquals(test.contains(DATE_2012_07_31), true); - assertEquals(test.contains(DATE_2012_08_01), true); - assertEquals(test.contains(LocalDate.MAX), true); + assertEquals(false, test.contains(LocalDate.MIN)); + assertEquals(false, test.contains(DATE_2012_07_27)); + assertEquals(true, test.contains(DATE_2012_07_28)); + assertEquals(true, test.contains(DATE_2012_07_29)); + assertEquals(true, test.contains(DATE_2012_07_30)); + assertEquals(true, test.contains(DATE_2012_07_31)); + assertEquals(true, test.contains(DATE_2012_08_01)); + assertEquals(true, test.contains(LocalDate.MAX)); } //----------------------------------------------------------------------- @@ -485,7 +485,7 @@ public static Object[][] data_queries() { public void test_encloses( LocalDate start, LocalDate end, boolean isEnclosedBy, boolean abuts, boolean isConnected, boolean overlaps) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); - assertEquals(test.encloses(LocalDateRange.of(start, end)), isEnclosedBy); + assertEquals(isEnclosedBy, test.encloses(LocalDateRange.of(start, end))); } @Test @@ -493,7 +493,7 @@ public void test_encloses( public void test_abuts( LocalDate start, LocalDate end, boolean isEnclosedBy, boolean abuts, boolean isConnected, boolean overlaps) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); - assertEquals(test.abuts(LocalDateRange.of(start, end)), abuts); + assertEquals(abuts, test.abuts(LocalDateRange.of(start, end))); } @Test @@ -501,7 +501,7 @@ public void test_abuts( public void test_isConnected( LocalDate start, LocalDate end, boolean isEnclosedBy, boolean abuts, boolean isConnected, boolean overlaps) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); - assertEquals(test.isConnected(LocalDateRange.of(start, end)), isConnected); + assertEquals(isConnected, test.isConnected(LocalDateRange.of(start, end))); } @Test @@ -509,7 +509,7 @@ public void test_isConnected( public void test_overlaps( LocalDate start, LocalDate end, boolean isEnclosedBy, boolean abuts, boolean isConnected, boolean overlaps) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); - assertEquals(test.overlaps(LocalDateRange.of(start, end)), overlaps); + assertEquals(overlaps, test.overlaps(LocalDateRange.of(start, end))); } @Test @@ -518,114 +518,114 @@ public void test_crossCheck( LocalDate start, LocalDate end, boolean isEnclosedBy, boolean abuts, boolean isConnected, boolean overlaps) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); LocalDateRange input = LocalDateRange.of(start, end); - assertEquals(test.isConnected(input), test.overlaps(input) || test.abuts(input)); - assertEquals(test.overlaps(input), test.isConnected(input) && !test.abuts(input)); + assertEquals(test.overlaps(input) || test.abuts(input), test.isConnected(input)); + assertEquals(test.isConnected(input) && !test.abuts(input), test.overlaps(input)); } @Test public void test_encloses_max() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, LocalDate.MAX); - assertEquals(test.encloses(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28)), true); - assertEquals(test.encloses(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_29)), true); - assertEquals(test.encloses(LocalDateRange.of(DATE_2012_07_28, LocalDate.MAX)), true); - assertEquals(test.encloses(LocalDateRange.of(DATE_2012_07_01, DATE_2012_07_27)), false); - assertEquals(test.encloses(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_29)), false); - assertEquals(test.encloses(LocalDateRange.of(DATE_2012_07_27, LocalDate.MAX)), false); + assertEquals(true, test.encloses(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28))); + assertEquals(true, test.encloses(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_29))); + assertEquals(true, test.encloses(LocalDateRange.of(DATE_2012_07_28, LocalDate.MAX))); + assertEquals(false, test.encloses(LocalDateRange.of(DATE_2012_07_01, DATE_2012_07_27))); + assertEquals(false, test.encloses(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_29))); + assertEquals(false, test.encloses(LocalDateRange.of(DATE_2012_07_27, LocalDate.MAX))); } @Test public void test_encloses_baseEmpty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28); - assertEquals(test.encloses(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_27)), false); - assertEquals(test.encloses(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28)), true); - assertEquals(test.encloses(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29)), false); - assertEquals(test.encloses(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_27)), false); - assertEquals(test.encloses(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_28)), false); - assertEquals(test.encloses(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_29)), false); - assertEquals(test.encloses(LocalDateRange.of(DATE_2012_07_27, LocalDate.MAX)), false); - assertEquals(test.encloses(LocalDateRange.of(DATE_2012_07_28, LocalDate.MAX)), false); + assertEquals(false, test.encloses(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_27))); + assertEquals(true, test.encloses(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28))); + assertEquals(false, test.encloses(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29))); + assertEquals(false, test.encloses(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_27))); + assertEquals(false, test.encloses(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_28))); + assertEquals(false, test.encloses(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_29))); + assertEquals(false, test.encloses(LocalDateRange.of(DATE_2012_07_27, LocalDate.MAX))); + assertEquals(false, test.encloses(LocalDateRange.of(DATE_2012_07_28, LocalDate.MAX))); } @Test public void test_encloses_baseEmptyMax() { - assertEquals(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .encloses(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX)), true); - assertEquals(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX)), false); - assertEquals(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1))), false); - assertEquals(LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1))), false); - assertEquals(LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2))), false); + assertEquals(true, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) + .encloses(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX))); + assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) + .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX))); + assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) + .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); + assertEquals(false, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) + .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); + assertEquals(false, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) + .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2)))); } @Test public void test_abuts_baseEmpty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28); - assertEquals(test.abuts(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_27)), false); - assertEquals(test.abuts(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28)), false); - assertEquals(test.abuts(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29)), false); - assertEquals(test.abuts(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_28)), true); - assertEquals(test.abuts(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_29)), true); + assertEquals(false, test.abuts(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_27))); + assertEquals(false, test.abuts(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28))); + assertEquals(false, test.abuts(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29))); + assertEquals(true, test.abuts(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_28))); + assertEquals(true, test.abuts(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_29))); } @Test public void test_abuts_baseEmptyMax() { - assertEquals(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .abuts(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX)), false); - assertEquals(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX)), true); - assertEquals(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1))), false); - assertEquals(LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1))), true); - assertEquals(LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2))), false); + assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) + .abuts(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX))); + assertEquals(true, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) + .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX))); + assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) + .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); + assertEquals(true, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) + .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); + assertEquals(false, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) + .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2)))); } @Test public void test_isConnected_baseEmpty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28); - assertEquals(test.isConnected(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_27)), false); - assertEquals(test.isConnected(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28)), true); - assertEquals(test.isConnected(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29)), false); + assertEquals(false, test.isConnected(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_27))); + assertEquals(true, test.isConnected(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28))); + assertEquals(false, test.isConnected(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29))); } @Test public void test_isConnected_baseEmptyMax() { - assertEquals(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .isConnected(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX)), true); - assertEquals(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX)), true); - assertEquals(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1))), false); - assertEquals(LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1))), true); - assertEquals(LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2))), false); + assertEquals(true, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) + .isConnected(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX))); + assertEquals(true, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) + .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX))); + assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) + .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); + assertEquals(true, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) + .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); + assertEquals(false, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) + .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2)))); } @Test public void test_overlaps_baseEmpty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28); - assertEquals(test.overlaps(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_27)), false); - assertEquals(test.overlaps(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28)), true); - assertEquals(test.overlaps(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29)), false); + assertEquals(false, test.overlaps(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_27))); + assertEquals(true, test.overlaps(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28))); + assertEquals(false, test.overlaps(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29))); } @Test public void test_overlaps_baseEmptyMax() { - assertEquals(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .overlaps(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX)), true); - assertEquals(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .overlaps(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX)), false); - assertEquals(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .overlaps(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1))), false); - assertEquals(LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .overlaps(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1))), false); - assertEquals(LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .overlaps(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2))), false); + assertEquals(true, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) + .overlaps(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX))); + assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) + .overlaps(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX))); + assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) + .overlaps(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); + assertEquals(false, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) + .overlaps(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); + assertEquals(false, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) + .overlaps(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2)))); } //----------------------------------------------------------------------- @@ -654,7 +654,7 @@ public void test_intersection( LocalDateRange test2 = LocalDateRange.of(start2, end2); LocalDateRange expected = LocalDateRange.of(expStart, expEnd); assertTrue(test1.isConnected(test2)); - assertEquals(test1.intersection(test2), expected); + assertEquals(expected, test1.intersection(test2)); } @Test @@ -666,21 +666,21 @@ public void test_intersection_reverse( LocalDateRange test2 = LocalDateRange.of(start2, end2); LocalDateRange expected = LocalDateRange.of(expStart, expEnd); assertTrue(test2.isConnected(test1)); - assertEquals(test2.intersection(test1), expected); + assertEquals(expected, test2.intersection(test1)); } @Test(expected = DateTimeException.class) public void test_intersectionBad() { LocalDateRange test1 = LocalDateRange.of(DATE_2012_07_01, DATE_2012_07_28); LocalDateRange test2 = LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_30); - assertEquals(test1.isConnected(test2), false); + assertEquals(false, test1.isConnected(test2)); test1.intersection(test2); } @Test public void test_intersection_same() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); - assertEquals(test.intersection(test), test); + assertEquals(test, test.intersection(test)); } //----------------------------------------------------------------------- @@ -709,8 +709,8 @@ public void test_unionAndSpan( LocalDateRange test2 = LocalDateRange.of(start2, end2); LocalDateRange expected = LocalDateRange.of(expStart, expEnd); assertTrue(test1.isConnected(test2)); - assertEquals(test1.union(test2), expected); - assertEquals(test1.span(test2), expected); + assertEquals(expected, test1.union(test2)); + assertEquals(expected, test1.span(test2)); } @Test @@ -722,8 +722,8 @@ public void test_unionAndSpan_reverse( LocalDateRange test2 = LocalDateRange.of(start2, end2); LocalDateRange expected = LocalDateRange.of(expStart, expEnd); assertTrue(test2.isConnected(test1)); - assertEquals(test2.union(test1), expected); - assertEquals(test2.span(test1), expected); + assertEquals(expected, test2.union(test1)); + assertEquals(expected, test2.span(test1)); } @Test @@ -734,8 +734,8 @@ public void test_span_enclosesInputs( LocalDateRange test1 = LocalDateRange.of(start1, end1); LocalDateRange test2 = LocalDateRange.of(start2, end2); LocalDateRange expected = LocalDateRange.of(expStart, expEnd); - assertEquals(expected.encloses(test1), true); - assertEquals(expected.encloses(test2), true); + assertEquals(true, expected.encloses(test1)); + assertEquals(true, expected.encloses(test2)); } @Test(expected = DateTimeException.class) @@ -751,14 +751,14 @@ public void test_span_disconnected() { LocalDateRange test1 = LocalDateRange.of(DATE_2012_07_01, DATE_2012_07_28); LocalDateRange test2 = LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_30); assertFalse(test1.isConnected(test2)); - assertEquals(test1.span(test2), LocalDateRange.of(DATE_2012_07_01, DATE_2012_07_30)); + assertEquals(LocalDateRange.of(DATE_2012_07_01, DATE_2012_07_30), test1.span(test2)); } @Test public void test_unionAndSpan_same() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); - assertEquals(test.union(test), test); - assertEquals(test.span(test), test); + assertEquals(test, test.union(test)); + assertEquals(test, test.span(test)); } //----------------------------------------------------------------------- @@ -766,10 +766,10 @@ public void test_unionAndSpan_same() { public void test_stream() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); List result = test.stream().collect(Collectors.toList()); - assertEquals(result.size(), 3); - assertEquals(result.get(0), DATE_2012_07_28); - assertEquals(result.get(1), DATE_2012_07_29); - assertEquals(result.get(2), DATE_2012_07_30); + assertEquals(3, result.size()); + assertEquals(DATE_2012_07_28, result.get(0)); + assertEquals(DATE_2012_07_29, result.get(1)); + assertEquals(DATE_2012_07_30, result.get(2)); } //----------------------------------------------------------------------- @@ -820,33 +820,33 @@ public static Object[][] data_isBefore() { @UseDataProvider("data_isBefore") public void test_isBefore_range(LocalDate start, LocalDate end, boolean before) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); - assertEquals(test.isBefore(LocalDateRange.of(start, end)), before); + assertEquals(before, test.isBefore(LocalDateRange.of(start, end))); } @Test @UseDataProvider("data_isBefore") public void test_isBefore_date(LocalDate start, LocalDate end, boolean before) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); - assertEquals(test.isBefore(start), before); + assertEquals(before, test.isBefore(start)); } @Test public void test_isBefore_range_empty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29); - assertEquals(test.isBefore(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_28)), false); - assertEquals(test.isBefore(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_29)), false); - assertEquals(test.isBefore(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29)), false); - assertEquals(test.isBefore(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_30)), true); - assertEquals(test.isBefore(LocalDateRange.of(DATE_2012_07_30, DATE_2012_07_30)), true); - assertEquals(test.isBefore(LocalDateRange.of(DATE_2012_07_30, DATE_2012_07_31)), true); + assertEquals(false, test.isBefore(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_28))); + assertEquals(false, test.isBefore(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_29))); + assertEquals(false, test.isBefore(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29))); + assertEquals(true, test.isBefore(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_30))); + assertEquals(true, test.isBefore(LocalDateRange.of(DATE_2012_07_30, DATE_2012_07_30))); + assertEquals(true, test.isBefore(LocalDateRange.of(DATE_2012_07_30, DATE_2012_07_31))); } @Test public void test_isBefore_date_empty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29); - assertEquals(test.isBefore(DATE_2012_07_28), false); - assertEquals(test.isBefore(DATE_2012_07_29), false); - assertEquals(test.isBefore(DATE_2012_07_30), true); + assertEquals(false, test.isBefore(DATE_2012_07_28)); + assertEquals(false, test.isBefore(DATE_2012_07_29)); + assertEquals(true, test.isBefore(DATE_2012_07_30)); } //----------------------------------------------------------------------- @@ -900,49 +900,49 @@ public static Object[][] data_isAfter() { @UseDataProvider("data_isAfter") public void test_isAfter_range(LocalDate start, LocalDate end, boolean before) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); - assertEquals(test.isAfter(LocalDateRange.of(start, end)), before); + assertEquals(before, test.isAfter(LocalDateRange.of(start, end))); } @Test @UseDataProvider("data_isAfter") public void test_isAfter_date(LocalDate start, LocalDate end, boolean before) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); - assertEquals(test.isAfter(end.minusDays(1)), before); + assertEquals(before, test.isAfter(end.minusDays(1))); } @Test public void test_isAfter_range_empty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29); - assertEquals(test.isAfter(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_28)), true); - assertEquals(test.isAfter(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_29)), true); - assertEquals(test.isAfter(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28)), true); - assertEquals(test.isAfter(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29)), false); - assertEquals(test.isAfter(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_30)), false); - assertEquals(test.isAfter(LocalDateRange.of(DATE_2012_07_30, DATE_2012_07_30)), false); - assertEquals(test.isAfter(LocalDateRange.of(DATE_2012_07_30, DATE_2012_07_31)), false); + assertEquals(true, test.isAfter(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_28))); + assertEquals(true, test.isAfter(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_29))); + assertEquals(true, test.isAfter(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28))); + assertEquals(false, test.isAfter(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29))); + assertEquals(false, test.isAfter(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_30))); + assertEquals(false, test.isAfter(LocalDateRange.of(DATE_2012_07_30, DATE_2012_07_30))); + assertEquals(false, test.isAfter(LocalDateRange.of(DATE_2012_07_30, DATE_2012_07_31))); } @Test public void test_isAfter_date_empty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29); - assertEquals(test.isAfter(DATE_2012_07_28), true); - assertEquals(test.isAfter(DATE_2012_07_29), false); - assertEquals(test.isAfter(DATE_2012_07_30), false); + assertEquals(true, test.isAfter(DATE_2012_07_28)); + assertEquals(false, test.isAfter(DATE_2012_07_29)); + assertEquals(false, test.isAfter(DATE_2012_07_30)); } //----------------------------------------------------------------------- @Test public void test_lengthInDays() { - assertEquals(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_29).lengthInDays(), 2); - assertEquals(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_29).lengthInDays(), 1); - assertEquals(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29).lengthInDays(), 0); + assertEquals(2, LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_29).lengthInDays()); + assertEquals(1, LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_29).lengthInDays()); + assertEquals(0, LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29).lengthInDays()); } @Test public void test_toPeriod() { - assertEquals(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_29).toPeriod(), Period.ofDays(2)); - assertEquals(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_29).toPeriod(), Period.ofDays(1)); - assertEquals(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29).toPeriod(), Period.ofDays(0)); + assertEquals(Period.ofDays(2), LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_29).toPeriod()); + assertEquals(Period.ofDays(1), LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_29).toPeriod()); + assertEquals(Period.ofDays(0), LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29).toPeriod()); } //----------------------------------------------------------------------- @@ -952,13 +952,13 @@ public void test_equals() { LocalDateRange a2 = LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_29); LocalDateRange b = LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_30); LocalDateRange c = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_29); - assertEquals(a.equals(a), true); - assertEquals(a.equals(a2), true); - assertEquals(a.equals(b), false); - assertEquals(a.equals(c), false); - assertEquals(a.equals(null), false); - assertEquals(a.equals(""), false); - assertEquals(a.hashCode() == a2.hashCode(), true); + assertEquals(true, a.equals(a)); + assertEquals(true, a.equals(a2)); + assertEquals(false, a.equals(b)); + assertEquals(false, a.equals(c)); + assertEquals(false, a.equals(null)); + assertEquals(false, a.equals("")); + assertEquals(true, a.hashCode() == a2.hashCode()); } //----------------------------------------------------------------------- @@ -995,7 +995,7 @@ public void crossCheckGuava_encloses( boolean extra = extraRange1.encloses(extraRange2); boolean guava = guavaRange1.encloses(guavaRange2); - assertEquals(extra, guava); + assertEquals(guava, extra); } @Test @@ -1008,7 +1008,7 @@ public void crossCheckGuava_isConnected( boolean extra = extraRange1.isConnected(extraRange2); boolean guava = guavaRange1.isConnected(guavaRange2); - assertEquals(extra, guava); + assertEquals(guava, extra); } @Test @@ -1032,10 +1032,10 @@ public void crossCheckGuava_intersection( // continue } if (extra == null) { - assertEquals(extra, guava); + assertEquals(guava, extra); } else if (guava != null) { - assertEquals(extra.getStart(), guava.lowerEndpoint()); - assertEquals(extra.getEnd(), guava.upperEndpoint()); + assertEquals(guava.lowerEndpoint(), extra.getStart()); + assertEquals(guava.upperEndpoint(), extra.getEnd()); } } @@ -1049,8 +1049,8 @@ public void crossCheckGuava_span( LocalDateRange extra = extraRange1.span(extraRange2); Range guava = guavaRange1.span(guavaRange2); - assertEquals(extra.getStart(), guava.lowerEndpoint()); - assertEquals(extra.getEnd(), guava.upperEndpoint()); + assertEquals(guava.lowerEndpoint(), extra.getStart()); + assertEquals(guava.upperEndpoint(), extra.getEnd()); } } diff --git a/src/test/java/org/threeten/extra/TestMinutes.java b/src/test/java/org/threeten/extra/TestMinutes.java index bdf2a322..9edc75a4 100644 --- a/src/test/java/org/threeten/extra/TestMinutes.java +++ b/src/test/java/org/threeten/extra/TestMinutes.java @@ -81,31 +81,31 @@ public void test_deserializationSingleton() throws Exception { public void test_ZERO() { assertSame(Minutes.of(0), Minutes.ZERO); assertSame(Minutes.of(0), Minutes.ZERO); - assertEquals(Minutes.ZERO.getAmount(), 0); + assertEquals(0, Minutes.ZERO.getAmount()); } //----------------------------------------------------------------------- @Test public void test_of() { - assertEquals(Minutes.of(0).getAmount(), 0); - assertEquals(Minutes.of(1).getAmount(), 1); - assertEquals(Minutes.of(2).getAmount(), 2); - assertEquals(Minutes.of(Integer.MAX_VALUE).getAmount(), Integer.MAX_VALUE); - assertEquals(Minutes.of(-1).getAmount(), -1); - assertEquals(Minutes.of(-2).getAmount(), -2); - assertEquals(Minutes.of(Integer.MIN_VALUE).getAmount(), Integer.MIN_VALUE); + assertEquals(0, Minutes.of(0).getAmount()); + assertEquals(1, Minutes.of(1).getAmount()); + assertEquals(2, Minutes.of(2).getAmount()); + assertEquals(Integer.MAX_VALUE, Minutes.of(Integer.MAX_VALUE).getAmount()); + assertEquals(-1, Minutes.of(-1).getAmount()); + assertEquals(-2, Minutes.of(-2).getAmount()); + assertEquals(Integer.MIN_VALUE, Minutes.of(Integer.MIN_VALUE).getAmount()); } //----------------------------------------------------------------------- @Test public void test_ofHours() { - assertEquals(Minutes.ofHours(0).getAmount(), 0); - assertEquals(Minutes.ofHours(1).getAmount(), 60); - assertEquals(Minutes.ofHours(2).getAmount(), 120); - assertEquals(Minutes.ofHours(Integer.MAX_VALUE / 60).getAmount(), (Integer.MAX_VALUE / 60) * 60); - assertEquals(Minutes.ofHours(-1).getAmount(), -60); - assertEquals(Minutes.ofHours(-2).getAmount(), -120); - assertEquals(Minutes.ofHours(Integer.MIN_VALUE / 60).getAmount(), (Integer.MIN_VALUE / 60) * 60); + assertEquals(0, Minutes.ofHours(0).getAmount()); + assertEquals(60, Minutes.ofHours(1).getAmount()); + assertEquals(120, Minutes.ofHours(2).getAmount()); + assertEquals((Integer.MAX_VALUE / 60) * 60, Minutes.ofHours(Integer.MAX_VALUE / 60).getAmount()); + assertEquals(-60, Minutes.ofHours(-1).getAmount()); + assertEquals(-120, Minutes.ofHours(-2).getAmount()); + assertEquals((Integer.MIN_VALUE / 60) * 60, Minutes.ofHours(Integer.MIN_VALUE / 60).getAmount()); } @Test(expected = ArithmeticException.class) @@ -160,19 +160,19 @@ public static Object[][] data_valid() { @Test @UseDataProvider("data_valid") public void test_parse_CharSequence_valid(String str, int expectedMinutes) { - assertEquals(Minutes.parse(str), Minutes.of(expectedMinutes)); + assertEquals(Minutes.of(expectedMinutes), Minutes.parse(str)); } @Test @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, int expectedMinutes) { - assertEquals(Minutes.parse("+" + str), Minutes.of(expectedMinutes)); + assertEquals(Minutes.of(expectedMinutes), Minutes.parse("+" + str)); } @Test @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, int expectedMinutes) { - assertEquals(Minutes.parse("-" + str), Minutes.of(-expectedMinutes)); + assertEquals(Minutes.of(-expectedMinutes), Minutes.parse("-" + str)); } @DataProvider @@ -386,23 +386,23 @@ public void test_abs_overflow() { @Test public void test_addTo() { LocalTime base = LocalTime.of(11, 30); - assertEquals(Minutes.of(0).addTo(base), LocalTime.of(11, 30)); - assertEquals(Minutes.of(6).addTo(base), LocalTime.of(11, 36)); + assertEquals(LocalTime.of(11, 30), Minutes.of(0).addTo(base)); + assertEquals(LocalTime.of(11, 36), Minutes.of(6).addTo(base)); } //----------------------------------------------------------------------- @Test public void test_subtractFrom() { LocalTime base = LocalTime.of(11, 30); - assertEquals(Minutes.of(0).subtractFrom(base), LocalTime.of(11, 30)); - assertEquals(Minutes.of(6).subtractFrom(base), LocalTime.of(11, 24)); + assertEquals(LocalTime.of(11, 30), Minutes.of(0).subtractFrom(base)); + assertEquals(LocalTime.of(11, 24), Minutes.of(6).subtractFrom(base)); } //----------------------------------------------------------------------- @Test public void test_toDuration() { for (int i = -20; i < 20; i++) { - assertEquals(Minutes.of(i).toDuration(), Duration.ofMinutes(i)); + assertEquals(Duration.ofMinutes(i), Minutes.of(i).toDuration()); } } diff --git a/src/test/java/org/threeten/extra/TestMonths.java b/src/test/java/org/threeten/extra/TestMonths.java index 326f2b38..2b4018ea 100644 --- a/src/test/java/org/threeten/extra/TestMonths.java +++ b/src/test/java/org/threeten/extra/TestMonths.java @@ -83,38 +83,38 @@ public void test_deserializationSingleton() throws Exception { public void test_ZERO() { assertSame(Months.of(0), Months.ZERO); assertSame(Months.of(0), Months.ZERO); - assertEquals(Months.ZERO.getAmount(), 0); + assertEquals(0, Months.ZERO.getAmount()); } @Test public void test_ONE() { assertSame(Months.of(1), Months.ONE); assertSame(Months.of(1), Months.ONE); - assertEquals(Months.ONE.getAmount(), 1); + assertEquals(1, Months.ONE.getAmount()); } //----------------------------------------------------------------------- @Test public void test_of() { - assertEquals(Months.of(0).getAmount(), 0); - assertEquals(Months.of(1).getAmount(), 1); - assertEquals(Months.of(2).getAmount(), 2); - assertEquals(Months.of(Integer.MAX_VALUE).getAmount(), Integer.MAX_VALUE); - assertEquals(Months.of(-1).getAmount(), -1); - assertEquals(Months.of(-2).getAmount(), -2); - assertEquals(Months.of(Integer.MIN_VALUE).getAmount(), Integer.MIN_VALUE); + assertEquals(0, Months.of(0).getAmount()); + assertEquals(1, Months.of(1).getAmount()); + assertEquals(2, Months.of(2).getAmount()); + assertEquals(Integer.MAX_VALUE, Months.of(Integer.MAX_VALUE).getAmount()); + assertEquals(-1, Months.of(-1).getAmount()); + assertEquals(-2, Months.of(-2).getAmount()); + assertEquals(Integer.MIN_VALUE, Months.of(Integer.MIN_VALUE).getAmount()); } //----------------------------------------------------------------------- @Test public void test_ofYears() { - assertEquals(Months.ofYears(0).getAmount(), 0); - assertEquals(Months.ofYears(1).getAmount(), 12); - assertEquals(Months.ofYears(2).getAmount(), 24); - assertEquals(Months.ofYears(Integer.MAX_VALUE / 12).getAmount(), (Integer.MAX_VALUE / 12) * 12); - assertEquals(Months.ofYears(-1).getAmount(), -12); - assertEquals(Months.ofYears(-2).getAmount(), -24); - assertEquals(Months.ofYears(Integer.MIN_VALUE / 12).getAmount(), (Integer.MIN_VALUE / 12) * 12); + assertEquals(0, Months.ofYears(0).getAmount()); + assertEquals(12, Months.ofYears(1).getAmount()); + assertEquals(24, Months.ofYears(2).getAmount()); + assertEquals((Integer.MAX_VALUE / 12) * 12, Months.ofYears(Integer.MAX_VALUE / 12).getAmount()); + assertEquals(-12, Months.ofYears(-1).getAmount()); + assertEquals(-24, Months.ofYears(-2).getAmount()); + assertEquals((Integer.MIN_VALUE / 12) * 12, Months.ofYears(Integer.MIN_VALUE / 12).getAmount()); } @Test(expected = ArithmeticException.class) @@ -125,27 +125,27 @@ public void test_ofYears_overflow() { //----------------------------------------------------------------------- @Test public void test_from_Period_P0M() { - assertEquals(Months.from(Period.ofMonths(0)), Months.of(0)); + assertEquals(Months.of(0), Months.from(Period.ofMonths(0))); } @Test public void test_from_Period_P2M() { - assertEquals(Months.from(Period.ofMonths(2)), Months.of(2)); + assertEquals(Months.of(2), Months.from(Period.ofMonths(2))); } @Test public void test_from_P2Y() { - assertEquals(Months.from(new MockYearsMonths(2, 0)), Months.of(24)); + assertEquals(Months.of(24), Months.from(new MockYearsMonths(2, 0))); } @Test public void test_from_P2Y3M() { - assertEquals(Months.from(new MockYearsMonths(2, 3)), Months.of(27)); + assertEquals(Months.of(27), Months.from(new MockYearsMonths(2, 3))); } @Test public void test_from_yearsAndMonths() { - assertEquals(Months.from(Period.of(3, 5, 0)), Months.of(41)); + assertEquals(Months.of(41), Months.from(Period.of(3, 5, 0))); } @Test(expected = DateTimeException.class) @@ -193,19 +193,19 @@ public static Object[][] data_valid() { @Test @UseDataProvider("data_valid") public void test_parse_CharSequence_valid(String str, int expectedDays) { - assertEquals(Months.parse(str), Months.of(expectedDays)); + assertEquals(Months.of(expectedDays), Months.parse(str)); } @Test @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, int expectedDays) { - assertEquals(Months.parse("+" + str), Months.of(expectedDays)); + assertEquals(Months.of(expectedDays), Months.parse("+" + str)); } @Test @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, int expectedDays) { - assertEquals(Months.parse("-" + str), Months.of(-expectedDays)); + assertEquals(Months.of(-expectedDays), Months.parse("-" + str)); } @DataProvider @@ -455,7 +455,7 @@ public void test_abs_overflow() { @Test public void test_toPeriod() { for (int i = -20; i < 20; i++) { - assertEquals(Months.of(i).toPeriod(), Period.ofMonths(i)); + assertEquals(Period.ofMonths(i), Months.of(i).toPeriod()); } } diff --git a/src/test/java/org/threeten/extra/TestMutableClock.java b/src/test/java/org/threeten/extra/TestMutableClock.java index e7861e77..81b718ab 100644 --- a/src/test/java/org/threeten/extra/TestMutableClock.java +++ b/src/test/java/org/threeten/extra/TestMutableClock.java @@ -70,23 +70,23 @@ public class TestMutableClock { @Test public void test_of() { assertEquals( - MutableClock.of(Instant.EPOCH, ZoneOffset.UTC).instant(), - Instant.EPOCH); + Instant.EPOCH, + MutableClock.of(Instant.EPOCH, ZoneOffset.UTC).instant()); assertEquals( - MutableClock.of(Instant.MIN, ZoneOffset.UTC).instant(), - Instant.MIN); + Instant.MIN, + MutableClock.of(Instant.MIN, ZoneOffset.UTC).instant()); assertEquals( - MutableClock.of(Instant.MAX, ZoneOffset.UTC).instant(), - Instant.MAX); + Instant.MAX, + MutableClock.of(Instant.MAX, ZoneOffset.UTC).instant()); assertEquals( - MutableClock.of(Instant.EPOCH, ZoneOffset.UTC).getZone(), - ZoneOffset.UTC); + ZoneOffset.UTC, + MutableClock.of(Instant.EPOCH, ZoneOffset.UTC).getZone()); assertEquals( - MutableClock.of(Instant.EPOCH, ZoneOffset.MIN).getZone(), - ZoneOffset.MIN); + ZoneOffset.MIN, + MutableClock.of(Instant.EPOCH, ZoneOffset.MIN).getZone()); assertEquals( - MutableClock.of(Instant.EPOCH, ZoneOffset.MAX).getZone(), - ZoneOffset.MAX); + ZoneOffset.MAX, + MutableClock.of(Instant.EPOCH, ZoneOffset.MAX).getZone()); } @Test(expected = NullPointerException.class) @@ -101,20 +101,20 @@ public void test_of_nullZone() { @Test public void test_epochUTC() { - assertEquals(MutableClock.epochUTC().instant(), Instant.EPOCH); - assertEquals(MutableClock.epochUTC().getZone(), ZoneOffset.UTC); + assertEquals(Instant.EPOCH, MutableClock.epochUTC().instant()); + assertEquals(ZoneOffset.UTC, MutableClock.epochUTC().getZone()); } @Test public void test_setInstant() { MutableClock clock = MutableClock.epochUTC(); - assertEquals(clock.instant(), Instant.EPOCH); + assertEquals(Instant.EPOCH, clock.instant()); clock.setInstant(Instant.MIN); - assertEquals(clock.instant(), Instant.MIN); + assertEquals(Instant.MIN, clock.instant()); clock.setInstant(Instant.MAX); - assertEquals(clock.instant(), Instant.MAX); + assertEquals(Instant.MAX, clock.instant()); clock.setInstant(Instant.EPOCH.plusSeconds(10)); - assertEquals(clock.instant(), Instant.EPOCH.plusSeconds(10)); + assertEquals(Instant.EPOCH.plusSeconds(10), clock.instant()); } @Test(expected = NullPointerException.class) @@ -132,13 +132,13 @@ public void test_add_amountOnly() { clock.add(Duration.ZERO); clock.add(Period.ZERO); assertEquals( - clock.instant(), ZonedDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC) .plusNanos(3) .plusMonths(2) .minusSeconds(5) .minusWeeks(7) - .toInstant()); + .toInstant(), + clock.instant()); } @Test(expected = NullPointerException.class) @@ -156,13 +156,13 @@ public void test_add_amountAndUnit() { clock.add(0, ChronoUnit.MILLIS); clock.add(0, ChronoUnit.YEARS); assertEquals( - clock.instant(), ZonedDateTime.ofInstant(Instant.EPOCH, ZoneOffset.UTC) .plusNanos(3) .plusMonths(2) .minusSeconds(5) .minusWeeks(7) - .toInstant()); + .toInstant(), + clock.instant()); } @Test(expected = NullPointerException.class) @@ -178,14 +178,14 @@ public void test_set_adjuster() { clock.set(TemporalAdjusters.firstDayOfNextMonth()); clock.set(TemporalAdjusters.next(DayOfWeek.WEDNESDAY)); assertEquals( - clock.instant(), LocalDateTime.of(0, 1, 2, 3, 4, 5) .with(TemporalAdjusters.firstDayOfNextMonth()) .with(TemporalAdjusters.next(DayOfWeek.WEDNESDAY)) .atZone(ZoneOffset.UTC) - .toInstant()); + .toInstant(), + clock.instant()); clock.set(Instant.EPOCH); - assertEquals(clock.instant(), Instant.EPOCH); + assertEquals(Instant.EPOCH, clock.instant()); } @Test(expected = NullPointerException.class) @@ -203,10 +203,10 @@ public void test_set_fieldAndValue() { clock.set(ChronoField.MINUTE_OF_HOUR, 4); clock.set(ChronoField.SECOND_OF_MINUTE, 5); assertEquals( - clock.instant(), LocalDateTime.of(0, 1, 2, 3, 4, 5) .atZone(ZoneOffset.UTC) - .toInstant()); + .toInstant(), + clock.instant()); } @Test(expected = NullPointerException.class) @@ -219,9 +219,9 @@ public void test_getZone() { MutableClock clock = MutableClock.epochUTC(); MutableClock withOtherZone = clock.withZone(ZoneOffset.MIN); MutableClock ofOtherZone = MutableClock.of(Instant.EPOCH, ZoneOffset.MAX); - assertEquals(clock.getZone(), ZoneOffset.UTC); - assertEquals(withOtherZone.getZone(), ZoneOffset.MIN); - assertEquals(ofOtherZone.getZone(), ZoneOffset.MAX); + assertEquals(ZoneOffset.UTC, clock.getZone()); + assertEquals(ZoneOffset.MIN, withOtherZone.getZone()); + assertEquals(ZoneOffset.MAX, ofOtherZone.getZone()); } @Test @@ -230,12 +230,12 @@ public void test_withZone() { MutableClock withOtherZone = clock.withZone(ZoneOffset.MIN); MutableClock withSameZone = withOtherZone.withZone(ZoneOffset.UTC); clock.setInstant(Instant.MIN); - assertEquals(withOtherZone.instant(), Instant.MIN); - assertEquals(withSameZone.instant(), Instant.MIN); - assertEquals(withOtherZone.getZone(), ZoneOffset.MIN); - assertEquals(withSameZone.getZone(), ZoneOffset.UTC); - assertNotEquals(withOtherZone, clock); - assertEquals(withSameZone, clock); + assertEquals(Instant.MIN, withOtherZone.instant()); + assertEquals(Instant.MIN, withSameZone.instant()); + assertEquals(ZoneOffset.MIN, withOtherZone.getZone()); + assertEquals(ZoneOffset.UTC, withSameZone.getZone()); + assertNotEquals(clock, withOtherZone); + assertEquals(clock, withSameZone); } @Test(expected = NullPointerException.class) @@ -247,12 +247,12 @@ public void test_withZone_null() { public void test_instant() { MutableClock clock = MutableClock.epochUTC(); MutableClock withOtherZone = clock.withZone(ZoneOffset.MIN); - assertEquals(clock.instant(), Instant.EPOCH); + assertEquals(Instant.EPOCH, clock.instant()); clock.add(Duration.ofSeconds(5)); - assertEquals(clock.instant(), Instant.EPOCH.plusSeconds(5)); + assertEquals(Instant.EPOCH.plusSeconds(5), clock.instant()); clock.setInstant(Instant.MIN); - assertEquals(clock.instant(), Instant.MIN); - assertEquals(withOtherZone.instant(), Instant.MIN); + assertEquals(Instant.MIN, clock.instant()); + assertEquals(Instant.MIN, withOtherZone.instant()); } @Test @@ -265,8 +265,8 @@ public void test_equals() { assertNotEquals(null, clock); assertNotEquals("", clock); assertNotEquals(withOtherZone, clock); - assertEquals(withSameZone, clock); - assertNotEquals(independent, clock); + assertEquals(clock, withSameZone); + assertNotEquals(clock, independent); } @Test @@ -274,13 +274,13 @@ public void test_hashCode_isConstant() { MutableClock clock = MutableClock.epochUTC(); int hash = clock.hashCode(); clock.add(Period.ofMonths(1)); - assertEquals(clock.hashCode(), hash); + assertEquals(hash, clock.hashCode()); clock.add(1, ChronoUnit.DAYS); - assertEquals(clock.hashCode(), hash); + assertEquals(hash, clock.hashCode()); clock.set(Year.of(2000)); - assertEquals(clock.hashCode(), hash); + assertEquals(hash, clock.hashCode()); clock.set(ChronoField.INSTANT_SECONDS, -1); - assertEquals(clock.hashCode(), hash); + assertEquals(hash, clock.hashCode()); } @Test @@ -295,16 +295,16 @@ public void test_hashCode_sameWhenSharedUpdates() { public void test_toString() { MutableClock clock = MutableClock.epochUTC(); assertEquals( - clock.toString(), - "MutableClock[1970-01-01T00:00:00Z,Z]"); + "MutableClock[1970-01-01T00:00:00Z,Z]", + clock.toString()); clock.add(Period.ofYears(30)); assertEquals( - clock.toString(), - "MutableClock[2000-01-01T00:00:00Z,Z]"); + "MutableClock[2000-01-01T00:00:00Z,Z]", + clock.toString()); MutableClock withOtherZone = clock.withZone(ZoneOffset.MIN); assertEquals( - withOtherZone.toString(), - "MutableClock[2000-01-01T00:00:00Z,-18:00]"); + "MutableClock[2000-01-01T00:00:00Z,-18:00]", + withOtherZone.toString()); } @Test @@ -321,8 +321,8 @@ public void test_serialization() throws Exception { } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { MutableClock ser = (MutableClock) ois.readObject(); - assertEquals(ser.instant(), test.instant()); - assertEquals(ser.getZone(), test.getZone()); + assertEquals(test.instant(), ser.instant()); + assertEquals(test.getZone(), ser.getZone()); // no shared updates assertNotEquals(ser, test); test.add(Duration.ofSeconds(1)); @@ -352,7 +352,7 @@ public void test_updatesAreAtomic() throws Exception { } } assertEquals( - clock.instant(), - Instant.EPOCH.plus(increment.multipliedBy(updateCount))); + Instant.EPOCH.plus(increment.multipliedBy(updateCount)), + clock.instant()); } } diff --git a/src/test/java/org/threeten/extra/TestPackedFields.java b/src/test/java/org/threeten/extra/TestPackedFields.java index 89d51116..f06023c3 100644 --- a/src/test/java/org/threeten/extra/TestPackedFields.java +++ b/src/test/java/org/threeten/extra/TestPackedFields.java @@ -57,15 +57,15 @@ public class TestPackedFields { //----------------------------------------------------------------------- @Test public void test_date_basics() { - assertEquals(PackedFields.PACKED_DATE.toString(), "PackedDate"); - assertEquals(PackedFields.PACKED_DATE.getBaseUnit(), DAYS); - assertEquals(PackedFields.PACKED_DATE.getRangeUnit(), FOREVER); - assertEquals(PackedFields.PACKED_DATE.isDateBased(), true); - assertEquals(PackedFields.PACKED_DATE.isTimeBased(), false); - assertEquals(PackedFields.PACKED_DATE.isSupportedBy(LocalDate.of(2015, 3, 12)), true); - assertEquals(PackedFields.PACKED_DATE.isSupportedBy(LocalTime.of(11, 30)), false); - assertEquals(PackedFields.PACKED_DATE.range().getMinimum(), 10000101); - assertEquals(PackedFields.PACKED_DATE.range().getMaximum(), 99991231); + assertEquals("PackedDate", PackedFields.PACKED_DATE.toString()); + assertEquals(DAYS, PackedFields.PACKED_DATE.getBaseUnit()); + assertEquals(FOREVER, PackedFields.PACKED_DATE.getRangeUnit()); + assertEquals(true, PackedFields.PACKED_DATE.isDateBased()); + assertEquals(false, PackedFields.PACKED_DATE.isTimeBased()); + assertEquals(true, PackedFields.PACKED_DATE.isSupportedBy(LocalDate.of(2015, 3, 12))); + assertEquals(false, PackedFields.PACKED_DATE.isSupportedBy(LocalTime.of(11, 30))); + assertEquals(10000101, PackedFields.PACKED_DATE.range().getMinimum()); + assertEquals(99991231, PackedFields.PACKED_DATE.range().getMaximum()); } @Test(expected = DateTimeException.class) @@ -75,9 +75,9 @@ public void test_date_rangeRefinedBy_time() { @Test public void test_date_getFrom() { - assertEquals(LocalDate.of(2015, 12, 3).get(PackedFields.PACKED_DATE), 20151203); - assertEquals(LocalDate.of(1000, 1, 1).get(PackedFields.PACKED_DATE), 10000101); - assertEquals(LocalDate.of(9999, 12, 31).get(PackedFields.PACKED_DATE), 99991231); + assertEquals(20151203, LocalDate.of(2015, 12, 3).get(PackedFields.PACKED_DATE)); + assertEquals(10000101, LocalDate.of(1000, 1, 1).get(PackedFields.PACKED_DATE)); + assertEquals(99991231, LocalDate.of(9999, 12, 31).get(PackedFields.PACKED_DATE)); } @Test(expected = DateTimeException.class) @@ -92,7 +92,7 @@ public void test_date_getFrom_rangeHigh() { @Test public void test_date_adjustInto() { - assertEquals(LocalDate.MIN.with(PackedFields.PACKED_DATE, 20151203), LocalDate.of(2015, 12, 3)); + assertEquals(LocalDate.of(2015, 12, 3), LocalDate.MIN.with(PackedFields.PACKED_DATE, 20151203)); } @Test(expected = DateTimeException.class) @@ -103,7 +103,7 @@ public void test_date_adjustInto_range() { @Test public void test_date_resolve() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_DATE).toFormatter(); - assertEquals(LocalDate.parse("20151203", f), LocalDate.of(2015, 12, 3)); + assertEquals(LocalDate.of(2015, 12, 3), LocalDate.parse("20151203", f)); } @Test(expected = DateTimeParseException.class) @@ -115,7 +115,7 @@ public void test_date_resolve_invalid_smart() { @Test public void test_date_resolve_invalid_lenient() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_DATE).toFormatter(); - assertEquals(LocalDate.parse("20151403", f.withResolverStyle(ResolverStyle.LENIENT)), LocalDate.of(2016, 2, 3)); + assertEquals(LocalDate.of(2016, 2, 3), LocalDate.parse("20151403", f.withResolverStyle(ResolverStyle.LENIENT))); } //----------------------------------------------------------------------- @@ -123,15 +123,15 @@ public void test_date_resolve_invalid_lenient() { //----------------------------------------------------------------------- @Test public void test_hourMin_basics() { - assertEquals(PackedFields.PACKED_HOUR_MIN.toString(), "PackedHourMin"); - assertEquals(PackedFields.PACKED_HOUR_MIN.getBaseUnit(), MINUTES); - assertEquals(PackedFields.PACKED_HOUR_MIN.getRangeUnit(), DAYS); - assertEquals(PackedFields.PACKED_HOUR_MIN.isDateBased(), false); - assertEquals(PackedFields.PACKED_HOUR_MIN.isTimeBased(), true); - assertEquals(PackedFields.PACKED_HOUR_MIN.isSupportedBy(LocalTime.of(11, 30)), true); - assertEquals(PackedFields.PACKED_HOUR_MIN.isSupportedBy(LocalDate.of(2015, 3, 12)), false); - assertEquals(PackedFields.PACKED_HOUR_MIN.range().getMinimum(), 0); - assertEquals(PackedFields.PACKED_HOUR_MIN.range().getMaximum(), 2359); + assertEquals("PackedHourMin", PackedFields.PACKED_HOUR_MIN.toString()); + assertEquals(MINUTES, PackedFields.PACKED_HOUR_MIN.getBaseUnit()); + assertEquals(DAYS, PackedFields.PACKED_HOUR_MIN.getRangeUnit()); + assertEquals(false, PackedFields.PACKED_HOUR_MIN.isDateBased()); + assertEquals(true, PackedFields.PACKED_HOUR_MIN.isTimeBased()); + assertEquals(true, PackedFields.PACKED_HOUR_MIN.isSupportedBy(LocalTime.of(11, 30))); + assertEquals(false, PackedFields.PACKED_HOUR_MIN.isSupportedBy(LocalDate.of(2015, 3, 12))); + assertEquals(0, PackedFields.PACKED_HOUR_MIN.range().getMinimum()); + assertEquals(2359, PackedFields.PACKED_HOUR_MIN.range().getMaximum()); } @Test(expected = DateTimeException.class) @@ -141,13 +141,13 @@ public void test_hourMin_rangeRefinedBy_time() { @Test public void test_hourMin_getFrom() { - assertEquals(LocalTime.of(11, 30).get(PackedFields.PACKED_HOUR_MIN), 1130); - assertEquals(LocalTime.of(1, 21).get(PackedFields.PACKED_HOUR_MIN), 121); + assertEquals(1130, LocalTime.of(11, 30).get(PackedFields.PACKED_HOUR_MIN)); + assertEquals(121, LocalTime.of(1, 21).get(PackedFields.PACKED_HOUR_MIN)); } @Test public void test_hourMin_adjustInto() { - assertEquals(LocalTime.MIDNIGHT.with(PackedFields.PACKED_HOUR_MIN, 1130), LocalTime.of(11, 30)); + assertEquals(LocalTime.of(11, 30), LocalTime.MIDNIGHT.with(PackedFields.PACKED_HOUR_MIN, 1130)); } @Test(expected = DateTimeException.class) @@ -158,7 +158,7 @@ public void test_hourMin_adjustInto_value() { @Test public void test_hourMin_resolve() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_HOUR_MIN).toFormatter(); - assertEquals(LocalTime.parse("1130", f), LocalTime.of(11, 30)); + assertEquals(LocalTime.of(11, 30), LocalTime.parse("1130", f)); } @Test(expected = DateTimeParseException.class) @@ -170,7 +170,7 @@ public void test_hourMin_resolve_invalid_smart() { @Test public void test_hourMin_resolve_invalid_lenient() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_HOUR_MIN).toFormatter(); - assertEquals(LocalTime.parse("1173", f.withResolverStyle(ResolverStyle.LENIENT)), LocalTime.of(12, 13)); + assertEquals(LocalTime.of(12, 13), LocalTime.parse("1173", f.withResolverStyle(ResolverStyle.LENIENT))); } //----------------------------------------------------------------------- @@ -178,15 +178,15 @@ public void test_hourMin_resolve_invalid_lenient() { //----------------------------------------------------------------------- @Test public void test_time_basics() { - assertEquals(PackedFields.PACKED_TIME.toString(), "PackedTime"); - assertEquals(PackedFields.PACKED_TIME.getBaseUnit(), SECONDS); - assertEquals(PackedFields.PACKED_TIME.getRangeUnit(), DAYS); - assertEquals(PackedFields.PACKED_TIME.isDateBased(), false); - assertEquals(PackedFields.PACKED_TIME.isTimeBased(), true); - assertEquals(PackedFields.PACKED_TIME.isSupportedBy(LocalTime.of(11, 30)), true); - assertEquals(PackedFields.PACKED_TIME.isSupportedBy(LocalDate.of(2015, 3, 12)), false); - assertEquals(PackedFields.PACKED_TIME.range().getMinimum(), 0); - assertEquals(PackedFields.PACKED_TIME.range().getMaximum(), 235959); + assertEquals("PackedTime", PackedFields.PACKED_TIME.toString()); + assertEquals(SECONDS, PackedFields.PACKED_TIME.getBaseUnit()); + assertEquals(DAYS, PackedFields.PACKED_TIME.getRangeUnit()); + assertEquals(false, PackedFields.PACKED_TIME.isDateBased()); + assertEquals(true, PackedFields.PACKED_TIME.isTimeBased()); + assertEquals(true, PackedFields.PACKED_TIME.isSupportedBy(LocalTime.of(11, 30))); + assertEquals(false, PackedFields.PACKED_TIME.isSupportedBy(LocalDate.of(2015, 3, 12))); + assertEquals(0, PackedFields.PACKED_TIME.range().getMinimum()); + assertEquals(235959, PackedFields.PACKED_TIME.range().getMaximum()); } @Test(expected = DateTimeException.class) @@ -196,14 +196,14 @@ public void test_time_rangeRefinedBy_time() { @Test public void test_time_getFrom() { - assertEquals(LocalTime.of(11, 30, 52).get(PackedFields.PACKED_TIME), 113052); - assertEquals(LocalTime.of(11, 30).get(PackedFields.PACKED_TIME), 113000); - assertEquals(LocalTime.of(1, 21).get(PackedFields.PACKED_TIME), 12100); + assertEquals(113052, LocalTime.of(11, 30, 52).get(PackedFields.PACKED_TIME)); + assertEquals(113000, LocalTime.of(11, 30).get(PackedFields.PACKED_TIME)); + assertEquals(12100, LocalTime.of(1, 21).get(PackedFields.PACKED_TIME)); } @Test public void test_time_adjustInto() { - assertEquals(LocalTime.MIDNIGHT.with(PackedFields.PACKED_TIME, 113052), LocalTime.of(11, 30, 52)); + assertEquals(LocalTime.of(11, 30, 52), LocalTime.MIDNIGHT.with(PackedFields.PACKED_TIME, 113052)); } @Test(expected = DateTimeException.class) @@ -214,7 +214,7 @@ public void test_time_adjustInto_value() { @Test public void test_time_resolve() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_TIME).toFormatter(); - assertEquals(LocalTime.parse("113052", f), LocalTime.of(11, 30, 52)); + assertEquals(LocalTime.of(11, 30, 52), LocalTime.parse("113052", f)); } @Test(expected = DateTimeParseException.class) @@ -226,7 +226,7 @@ public void test_time_resolve_invalid_smart() { @Test public void test_time_resolve_invalid_lenient() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_TIME).toFormatter(); - assertEquals(LocalTime.parse("117361", f.withResolverStyle(ResolverStyle.LENIENT)), LocalTime.of(12, 14, 1)); + assertEquals(LocalTime.of(12, 14, 1), LocalTime.parse("117361", f.withResolverStyle(ResolverStyle.LENIENT))); } } diff --git a/src/test/java/org/threeten/extra/TestPeriodDuration.java b/src/test/java/org/threeten/extra/TestPeriodDuration.java index 396b98eb..1be12870 100644 --- a/src/test/java/org/threeten/extra/TestPeriodDuration.java +++ b/src/test/java/org/threeten/extra/TestPeriodDuration.java @@ -86,25 +86,25 @@ public void test_serialization() throws Exception { oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertEquals(ois.readObject(), test); + assertEquals(test, ois.readObject()); } } //----------------------------------------------------------------------- @Test public void test_ZERO() { - assertEquals(PeriodDuration.of(Period.ZERO, Duration.ZERO), PeriodDuration.ZERO); - assertEquals(PeriodDuration.of(Period.ZERO), PeriodDuration.ZERO); - assertEquals(PeriodDuration.of(Duration.ZERO), PeriodDuration.ZERO); - assertEquals(PeriodDuration.ZERO.getPeriod(), Period.ZERO); - assertEquals(PeriodDuration.ZERO.getDuration(), Duration.ZERO); - assertEquals(PeriodDuration.ZERO.isZero(), true); - assertEquals(PeriodDuration.ZERO.getUnits(), Arrays.asList(YEARS, MONTHS, DAYS, SECONDS, NANOS)); - assertEquals(PeriodDuration.ZERO.get(YEARS), 0); - assertEquals(PeriodDuration.ZERO.get(MONTHS), 0); - assertEquals(PeriodDuration.ZERO.get(DAYS), 0); - assertEquals(PeriodDuration.ZERO.get(SECONDS), 0); - assertEquals(PeriodDuration.ZERO.get(NANOS), 0); + assertEquals(PeriodDuration.ZERO, PeriodDuration.of(Period.ZERO, Duration.ZERO)); + assertEquals(PeriodDuration.ZERO, PeriodDuration.of(Period.ZERO)); + assertEquals(PeriodDuration.ZERO, PeriodDuration.of(Duration.ZERO)); + assertEquals(Period.ZERO, PeriodDuration.ZERO.getPeriod()); + assertEquals(Duration.ZERO, PeriodDuration.ZERO.getDuration()); + assertEquals(true, PeriodDuration.ZERO.isZero()); + assertEquals(Arrays.asList(YEARS, MONTHS, DAYS, SECONDS, NANOS), PeriodDuration.ZERO.getUnits()); + assertEquals(0, PeriodDuration.ZERO.get(YEARS)); + assertEquals(0, PeriodDuration.ZERO.get(MONTHS)); + assertEquals(0, PeriodDuration.ZERO.get(DAYS)); + assertEquals(0, PeriodDuration.ZERO.get(SECONDS)); + assertEquals(0, PeriodDuration.ZERO.get(NANOS)); } @Test(expected = DateTimeException.class) @@ -116,82 +116,82 @@ public void test_ZERO_getEra() { @Test public void test_of_both() { PeriodDuration test = PeriodDuration.of(P1Y2M3D, Duration.ofSeconds(4)); - assertEquals(test.getPeriod(), P1Y2M3D); - assertEquals(test.getDuration(), Duration.ofSeconds(4)); - assertEquals(test.isZero(), false); - assertEquals(test.get(YEARS), 1); - assertEquals(test.get(MONTHS), 2); - assertEquals(test.get(DAYS), 3); - assertEquals(test.get(SECONDS), 4); - assertEquals(test.get(NANOS), 0); + assertEquals(P1Y2M3D, test.getPeriod()); + assertEquals(Duration.ofSeconds(4), test.getDuration()); + assertEquals(false, test.isZero()); + assertEquals(1, test.get(YEARS)); + assertEquals(2, test.get(MONTHS)); + assertEquals(3, test.get(DAYS)); + assertEquals(4, test.get(SECONDS)); + assertEquals(0, test.get(NANOS)); } @Test public void test_of_period() { PeriodDuration test = PeriodDuration.of(P1Y2M3D); - assertEquals(test.getPeriod(), P1Y2M3D); - assertEquals(test.getDuration(), Duration.ZERO); - assertEquals(test.isZero(), false); - assertEquals(test.get(YEARS), 1); - assertEquals(test.get(MONTHS), 2); - assertEquals(test.get(DAYS), 3); - assertEquals(test.get(SECONDS), 0); - assertEquals(test.get(NANOS), 0); + assertEquals(P1Y2M3D, test.getPeriod()); + assertEquals(Duration.ZERO, test.getDuration()); + assertEquals(false, test.isZero()); + assertEquals(1, test.get(YEARS)); + assertEquals(2, test.get(MONTHS)); + assertEquals(3, test.get(DAYS)); + assertEquals(0, test.get(SECONDS)); + assertEquals(0, test.get(NANOS)); } @Test public void test_of_duration() { PeriodDuration test = PeriodDuration.of(Duration.ofSeconds(4)); - assertEquals(test.getPeriod(), Period.ZERO); - assertEquals(test.getDuration(), Duration.ofSeconds(4)); - assertEquals(test.isZero(), false); - assertEquals(test.get(YEARS), 0); - assertEquals(test.get(MONTHS), 0); - assertEquals(test.get(DAYS), 0); - assertEquals(test.get(SECONDS), 4); - assertEquals(test.get(NANOS), 0); + assertEquals(Period.ZERO, test.getPeriod()); + assertEquals(Duration.ofSeconds(4), test.getDuration()); + assertEquals(false, test.isZero()); + assertEquals(0, test.get(YEARS)); + assertEquals(0, test.get(MONTHS)); + assertEquals(0, test.get(DAYS)); + assertEquals(4, test.get(SECONDS)); + assertEquals(0, test.get(NANOS)); } //----------------------------------------------------------------------- @Test public void test_between_dates() { PeriodDuration test = PeriodDuration.between(LocalDate.of(2012, 6, 20), LocalDate.of(2012, 8, 25)); - assertEquals(test.getPeriod(), Period.between(LocalDate.of(2012, 6, 20), LocalDate.of(2012, 8, 25))); - assertEquals(test.getDuration(), Duration.ZERO); + assertEquals(Period.between(LocalDate.of(2012, 6, 20), LocalDate.of(2012, 8, 25)), test.getPeriod()); + assertEquals(Duration.ZERO, test.getDuration()); } @Test public void test_between_times() { PeriodDuration test = PeriodDuration.between(LocalTime.of(11, 20), LocalTime.of(12, 25)); - assertEquals(test.getPeriod(), Period.ZERO); - assertEquals(test.getDuration(), Duration.between(LocalTime.of(11, 20), LocalTime.of(12, 25))); + assertEquals(Period.ZERO, test.getPeriod()); + assertEquals(Duration.between(LocalTime.of(11, 20), LocalTime.of(12, 25)), test.getDuration()); } @Test public void test_between_mixed1() { PeriodDuration test = PeriodDuration.between(LocalDate.of(2012, 6, 20), LocalTime.of(11, 25)); - assertEquals(test.getPeriod(), Period.ZERO); - assertEquals(test.getDuration(), Duration.ofHours(11).plusMinutes(25)); + assertEquals(Period.ZERO, test.getPeriod()); + assertEquals(Duration.ofHours(11).plusMinutes(25), test.getDuration()); } @Test public void test_between_mixed2() { PeriodDuration test = PeriodDuration.between(LocalDate.of(2012, 6, 20), LocalDateTime.of(2012, 7, 22, 11, 25)); - assertEquals(test.getPeriod(), Period.of(0, 1, 2)); - assertEquals(test.getDuration(), Duration.ofHours(11).plusMinutes(25)); + assertEquals(Period.of(0, 1, 2), test.getPeriod()); + assertEquals(Duration.ofHours(11).plusMinutes(25), test.getDuration()); } //----------------------------------------------------------------------- @Test public void test_from() { assertEquals(PeriodDuration.from(PeriodDuration.of(P1Y2M3D)), PeriodDuration.from(PeriodDuration.of(P1Y2M3D))); - assertEquals(PeriodDuration.from(Period.ofYears(2)), PeriodDuration.of(Period.ofYears(2))); - assertEquals(PeriodDuration.from(Duration.ofSeconds(2)), PeriodDuration.of(Duration.ofSeconds(2))); - assertEquals(PeriodDuration.from(Years.of(2)), PeriodDuration.of(Period.ofYears(2))); - assertEquals(PeriodDuration.from(Months.of(2)), PeriodDuration.of(Period.ofMonths(2))); - assertEquals(PeriodDuration.from(Weeks.of(2)), PeriodDuration.of(Period.ofWeeks(2))); - assertEquals(PeriodDuration.from(Days.of(2)), PeriodDuration.of(Period.ofDays(2))); - assertEquals(PeriodDuration.from(Hours.of(2)), PeriodDuration.of(Duration.ofHours(2))); + assertEquals(PeriodDuration.of(Period.ofYears(2)), PeriodDuration.from(Period.ofYears(2))); + assertEquals(PeriodDuration.of(Duration.ofSeconds(2)), PeriodDuration.from(Duration.ofSeconds(2))); + assertEquals(PeriodDuration.of(Period.ofYears(2)), PeriodDuration.from(Years.of(2))); + assertEquals(PeriodDuration.of(Period.ofMonths(2)), PeriodDuration.from(Months.of(2))); + assertEquals(PeriodDuration.of(Period.ofWeeks(2)), PeriodDuration.from(Weeks.of(2))); + assertEquals(PeriodDuration.of(Period.ofDays(2)), PeriodDuration.from(Days.of(2))); + assertEquals(PeriodDuration.of(Duration.ofHours(2)), PeriodDuration.from(Hours.of(2))); } //----------------------------------------------------------------------- @@ -223,19 +223,19 @@ public static Object[][] data_valid() { @Test @UseDataProvider("data_valid") public void test_parse_CharSequence_valid(String str, Period period, Duration duration) { - assertEquals(PeriodDuration.parse(str), PeriodDuration.of(period, duration)); + assertEquals(PeriodDuration.of(period, duration), PeriodDuration.parse(str)); } @Test @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, Period period, Duration duration) { - assertEquals(PeriodDuration.parse("+" + str), PeriodDuration.of(period, duration)); + assertEquals(PeriodDuration.of(period, duration), PeriodDuration.parse("+" + str)); } @Test @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, Period period, Duration duration) { - assertEquals(PeriodDuration.parse("-" + str), PeriodDuration.of(period, duration).negated()); + assertEquals(PeriodDuration.of(period, duration).negated(), PeriodDuration.parse("-" + str)); } @DataProvider @@ -271,8 +271,8 @@ public void test_parse_CharSequence_null() { @Test public void test_plus_TemporalAmount_PeriodDuration() { PeriodDuration test = PeriodDuration.of(P1Y2M3D, DUR_5); - assertEquals(test.plus(Period.of(3, 2, 1)), PeriodDuration.of(Period.of(4, 4, 4), DUR_5)); - assertEquals(test.plus(Duration.ofSeconds(4)), PeriodDuration.of(P1Y2M3D, Duration.ofSeconds(9))); + assertEquals(PeriodDuration.of(Period.of(4, 4, 4), DUR_5), test.plus(Period.of(3, 2, 1))); + assertEquals(PeriodDuration.of(P1Y2M3D, Duration.ofSeconds(9)), test.plus(Duration.ofSeconds(4))); } @Test(expected = ArithmeticException.class) @@ -294,8 +294,8 @@ public void test_plus_TemporalAmount_null() { @Test public void test_minus_TemporalAmount_PeriodDuration() { PeriodDuration test = PeriodDuration.of(P1Y2M3D, DUR_5); - assertEquals(test.minus(Period.of(1, 1, 1)), PeriodDuration.of(Period.of(0, 1, 2), DUR_5)); - assertEquals(test.minus(Duration.ofSeconds(4)), PeriodDuration.of(P1Y2M3D, Duration.ofSeconds(1))); + assertEquals(PeriodDuration.of(Period.of(0, 1, 2), DUR_5), test.minus(Period.of(1, 1, 1))); + assertEquals(PeriodDuration.of(P1Y2M3D, Duration.ofSeconds(1)), test.minus(Duration.ofSeconds(4))); } @Test(expected = ArithmeticException.class) @@ -317,10 +317,10 @@ public void test_minus_TemporalAmount_null() { @Test public void test_multipliedBy() { PeriodDuration test = PeriodDuration.of(P1Y2M3D, DUR_5); - assertEquals(test.multipliedBy(0), PeriodDuration.ZERO); - assertEquals(test.multipliedBy(1), test); - assertEquals(test.multipliedBy(5), PeriodDuration.of(Period.of(5, 10, 15), Duration.ofSeconds(25))); - assertEquals(test.multipliedBy(-3), PeriodDuration.of(Period.of(-3, -6, -9), Duration.ofSeconds(-15))); + assertEquals(PeriodDuration.ZERO, test.multipliedBy(0)); + assertEquals(test, test.multipliedBy(1)); + assertEquals(PeriodDuration.of(Period.of(5, 10, 15), Duration.ofSeconds(25)), test.multipliedBy(5)); + assertEquals(PeriodDuration.of(Period.of(-3, -6, -9), Duration.ofSeconds(-15)), test.multipliedBy(-3)); } @Test(expected = ArithmeticException.class) @@ -336,7 +336,7 @@ public void test_multipliedBy_overflowTooSmall() { //----------------------------------------------------------------------- @Test public void test_negated() { - assertEquals(PeriodDuration.of(P1Y2M3D, DUR_5).negated(), PeriodDuration.of(P1Y2M3D.negated(), DUR_5.negated())); + assertEquals(PeriodDuration.of(P1Y2M3D.negated(), DUR_5.negated()), PeriodDuration.of(P1Y2M3D, DUR_5).negated()); } @Test(expected = ArithmeticException.class) @@ -347,21 +347,21 @@ public void test_negated_overflow() { //----------------------------------------------------------------------- @Test public void test_normalizedYears() { - assertEquals(PeriodDuration.of(P1Y2M3D, DUR_5).normalizedYears(), PeriodDuration.of(P1Y2M3D.normalized(), DUR_5)); + assertEquals(PeriodDuration.of(P1Y2M3D.normalized(), DUR_5), PeriodDuration.of(P1Y2M3D, DUR_5).normalizedYears()); } //----------------------------------------------------------------------- @Test public void test_normalizedStandardDays() { assertEquals( - PeriodDuration.of(P1Y2M3D, Duration.ofHours(5)).normalizedStandardDays(), - PeriodDuration.of(P1Y2M3D, Duration.ofHours(5))); + PeriodDuration.of(P1Y2M3D, Duration.ofHours(5)), + PeriodDuration.of(P1Y2M3D, Duration.ofHours(5)).normalizedStandardDays()); assertEquals( - PeriodDuration.of(P1Y2M3D, Duration.ofHours(25)).normalizedStandardDays(), - PeriodDuration.of(P1Y2M3D.plusDays(1), Duration.ofHours(1))); + PeriodDuration.of(P1Y2M3D.plusDays(1), Duration.ofHours(1)), + PeriodDuration.of(P1Y2M3D, Duration.ofHours(25)).normalizedStandardDays()); assertEquals( - PeriodDuration.of(P1Y2M3D, Duration.ofHours(-73)).normalizedStandardDays(), - PeriodDuration.of(P1Y2M3D.plusDays(-3), Duration.ofHours(-1))); + PeriodDuration.of(P1Y2M3D.plusDays(-3), Duration.ofHours(-1)), + PeriodDuration.of(P1Y2M3D, Duration.ofHours(-73)).normalizedStandardDays()); } @Test(expected = ArithmeticException.class) @@ -373,14 +373,14 @@ public void test_normalizedStandardDaysn_overflow() { @Test public void test_addTo() { LocalDateTime base = LocalDateTime.of(2012, 6, 20, 11, 30, 0); - assertEquals(PeriodDuration.of(P1Y2M3D, DUR_5).addTo(base), LocalDateTime.of(2013, 8, 23, 11, 30, 5)); + assertEquals(LocalDateTime.of(2013, 8, 23, 11, 30, 5), PeriodDuration.of(P1Y2M3D, DUR_5).addTo(base)); } //----------------------------------------------------------------------- @Test public void test_subtractFrom() { LocalDateTime base = LocalDateTime.of(2012, 6, 20, 11, 30, 0); - assertEquals(PeriodDuration.of(P1Y2M3D, DUR_5).subtractFrom(base), LocalDateTime.of(2011, 4, 17, 11, 29, 55)); + assertEquals(LocalDateTime.of(2011, 4, 17, 11, 29, 55), PeriodDuration.of(P1Y2M3D, DUR_5).subtractFrom(base)); } //----------------------------------------------------------------------- @@ -388,21 +388,21 @@ public void test_subtractFrom() { public void test_equals() { PeriodDuration test5 = PeriodDuration.of(P1Y2M3D, DUR_5); PeriodDuration test6 = PeriodDuration.of(P1Y2M3D, DUR_6); - assertEquals(test5.equals(test5), true); - assertEquals(test5.equals(test6), false); - assertEquals(test6.equals(test5), false); + assertEquals(true, test5.equals(test5)); + assertEquals(false, test5.equals(test6)); + assertEquals(false, test6.equals(test5)); } @Test public void test_equals_null() { PeriodDuration test = PeriodDuration.of(P1Y2M3D, DUR_5); - assertEquals(test.equals(null), false); + assertEquals(false, test.equals(null)); } @Test public void test_equals_otherClass() { PeriodDuration test = PeriodDuration.of(P1Y2M3D, DUR_5); - assertEquals(test.equals(""), false); + assertEquals(false, test.equals("")); } //----------------------------------------------------------------------- @@ -410,8 +410,8 @@ public void test_equals_otherClass() { public void test_hashCode() { PeriodDuration test5 = PeriodDuration.of(P1Y2M3D, DUR_5); PeriodDuration test6 = PeriodDuration.of(P1Y2M3D, DUR_6); - assertEquals(test5.hashCode() == test5.hashCode(), true); - assertEquals(test5.hashCode() == test6.hashCode(), false); + assertEquals(true, test5.hashCode() == test5.hashCode()); + assertEquals(false, test5.hashCode() == test6.hashCode()); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestQuarter.java b/src/test/java/org/threeten/extra/TestQuarter.java index ba96bde4..f0499d51 100644 --- a/src/test/java/org/threeten/extra/TestQuarter.java +++ b/src/test/java/org/threeten/extra/TestQuarter.java @@ -110,7 +110,7 @@ public void test_interfaces() { public void test_of_int_singleton() { for (int i = 1; i <= 4; i++) { Quarter test = Quarter.of(i); - assertEquals(test.getValue(), i); + assertEquals(i, test.getValue()); } } @@ -129,18 +129,18 @@ public void test_of_int_valueTooHigh() { //----------------------------------------------------------------------- @Test public void test_ofMonth_int_singleton() { - assertEquals(Quarter.ofMonth(1), Quarter.Q1); - assertEquals(Quarter.ofMonth(2), Quarter.Q1); - assertEquals(Quarter.ofMonth(3), Quarter.Q1); - assertEquals(Quarter.ofMonth(4), Quarter.Q2); - assertEquals(Quarter.ofMonth(5), Quarter.Q2); - assertEquals(Quarter.ofMonth(6), Quarter.Q2); - assertEquals(Quarter.ofMonth(7), Quarter.Q3); - assertEquals(Quarter.ofMonth(8), Quarter.Q3); - assertEquals(Quarter.ofMonth(9), Quarter.Q3); - assertEquals(Quarter.ofMonth(10), Quarter.Q4); - assertEquals(Quarter.ofMonth(11), Quarter.Q4); - assertEquals(Quarter.ofMonth(12), Quarter.Q4); + assertEquals(Quarter.Q1, Quarter.ofMonth(1)); + assertEquals(Quarter.Q1, Quarter.ofMonth(2)); + assertEquals(Quarter.Q1, Quarter.ofMonth(3)); + assertEquals(Quarter.Q2, Quarter.ofMonth(4)); + assertEquals(Quarter.Q2, Quarter.ofMonth(5)); + assertEquals(Quarter.Q2, Quarter.ofMonth(6)); + assertEquals(Quarter.Q3, Quarter.ofMonth(7)); + assertEquals(Quarter.Q3, Quarter.ofMonth(8)); + assertEquals(Quarter.Q3, Quarter.ofMonth(9)); + assertEquals(Quarter.Q4, Quarter.ofMonth(10)); + assertEquals(Quarter.Q4, Quarter.ofMonth(11)); + assertEquals(Quarter.Q4, Quarter.ofMonth(12)); } @Test(expected = DateTimeException.class) @@ -158,24 +158,24 @@ public void test_ofMonth_int_valueTooHigh() { //----------------------------------------------------------------------- @Test public void test_from_TemporalAccessor() { - assertEquals(Quarter.from(LocalDate.of(2011, 6, 6)), Quarter.Q2); - assertEquals(Quarter.from(LocalDateTime.of(2012, 2, 3, 12, 30)), Quarter.Q1); + assertEquals(Quarter.Q2, Quarter.from(LocalDate.of(2011, 6, 6))); + assertEquals(Quarter.Q1, Quarter.from(LocalDateTime.of(2012, 2, 3, 12, 30))); } @Test public void test_from_TemporalAccessor_Month() { - assertEquals(Quarter.from(Month.JANUARY), Quarter.Q1); - assertEquals(Quarter.from(Month.FEBRUARY), Quarter.Q1); - assertEquals(Quarter.from(Month.MARCH), Quarter.Q1); - assertEquals(Quarter.from(Month.APRIL), Quarter.Q2); - assertEquals(Quarter.from(Month.MAY), Quarter.Q2); - assertEquals(Quarter.from(Month.JUNE), Quarter.Q2); - assertEquals(Quarter.from(Month.JULY), Quarter.Q3); - assertEquals(Quarter.from(Month.AUGUST), Quarter.Q3); - assertEquals(Quarter.from(Month.SEPTEMBER), Quarter.Q3); - assertEquals(Quarter.from(Month.OCTOBER), Quarter.Q4); - assertEquals(Quarter.from(Month.NOVEMBER), Quarter.Q4); - assertEquals(Quarter.from(Month.DECEMBER), Quarter.Q4); + assertEquals(Quarter.Q1, Quarter.from(Month.JANUARY)); + assertEquals(Quarter.Q1, Quarter.from(Month.FEBRUARY)); + assertEquals(Quarter.Q1, Quarter.from(Month.MARCH)); + assertEquals(Quarter.Q2, Quarter.from(Month.APRIL)); + assertEquals(Quarter.Q2, Quarter.from(Month.MAY)); + assertEquals(Quarter.Q2, Quarter.from(Month.JUNE)); + assertEquals(Quarter.Q3, Quarter.from(Month.JULY)); + assertEquals(Quarter.Q3, Quarter.from(Month.AUGUST)); + assertEquals(Quarter.Q3, Quarter.from(Month.SEPTEMBER)); + assertEquals(Quarter.Q4, Quarter.from(Month.OCTOBER)); + assertEquals(Quarter.Q4, Quarter.from(Month.NOVEMBER)); + assertEquals(Quarter.Q4, Quarter.from(Month.DECEMBER)); } @Test(expected = DateTimeException.class) @@ -191,7 +191,7 @@ public void test_from_TemporalAccessor_null() { @Test public void test_from_parse_CharSequence() { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("'Q'Q"); - assertEquals(formatter.parse("Q3", Quarter::from), Q3); + assertEquals(Q3, formatter.parse("Q3", Quarter::from)); } //----------------------------------------------------------------------- @@ -199,7 +199,7 @@ public void test_from_parse_CharSequence() { //----------------------------------------------------------------------- @Test public void test_getDisplayName() { - assertEquals(Quarter.Q1.getDisplayName(TextStyle.SHORT, Locale.US), "Q1"); + assertEquals("Q1", Quarter.Q1.getDisplayName(TextStyle.SHORT, Locale.US)); } @Test(expected = NullPointerException.class) @@ -218,38 +218,38 @@ public void test_getDisplayName_nullLocale() { @Test public void test_isSupported() { Quarter test = Quarter.Q1; - assertEquals(test.isSupported(null), false); - assertEquals(test.isSupported(NANO_OF_SECOND), false); - assertEquals(test.isSupported(NANO_OF_DAY), false); - assertEquals(test.isSupported(MICRO_OF_SECOND), false); - assertEquals(test.isSupported(MICRO_OF_DAY), false); - assertEquals(test.isSupported(MILLI_OF_SECOND), false); - assertEquals(test.isSupported(MILLI_OF_DAY), false); - assertEquals(test.isSupported(SECOND_OF_MINUTE), false); - assertEquals(test.isSupported(SECOND_OF_DAY), false); - assertEquals(test.isSupported(MINUTE_OF_HOUR), false); - assertEquals(test.isSupported(MINUTE_OF_DAY), false); - assertEquals(test.isSupported(HOUR_OF_AMPM), false); - assertEquals(test.isSupported(CLOCK_HOUR_OF_AMPM), false); - assertEquals(test.isSupported(HOUR_OF_DAY), false); - assertEquals(test.isSupported(CLOCK_HOUR_OF_DAY), false); - assertEquals(test.isSupported(AMPM_OF_DAY), false); - assertEquals(test.isSupported(DAY_OF_WEEK), false); - assertEquals(test.isSupported(ALIGNED_DAY_OF_WEEK_IN_MONTH), false); - assertEquals(test.isSupported(ALIGNED_DAY_OF_WEEK_IN_YEAR), false); - assertEquals(test.isSupported(DAY_OF_MONTH), false); - assertEquals(test.isSupported(DAY_OF_YEAR), false); - assertEquals(test.isSupported(EPOCH_DAY), false); - assertEquals(test.isSupported(ALIGNED_WEEK_OF_MONTH), false); - assertEquals(test.isSupported(ALIGNED_WEEK_OF_YEAR), false); - assertEquals(test.isSupported(MONTH_OF_YEAR), false); - assertEquals(test.isSupported(PROLEPTIC_MONTH), false); - assertEquals(test.isSupported(YEAR_OF_ERA), false); - assertEquals(test.isSupported(YEAR), false); - assertEquals(test.isSupported(ERA), false); - assertEquals(test.isSupported(INSTANT_SECONDS), false); - assertEquals(test.isSupported(OFFSET_SECONDS), false); - assertEquals(test.isSupported(QUARTER_OF_YEAR), true); + assertEquals(false, test.isSupported(null)); + assertEquals(false, test.isSupported(NANO_OF_SECOND)); + assertEquals(false, test.isSupported(NANO_OF_DAY)); + assertEquals(false, test.isSupported(MICRO_OF_SECOND)); + assertEquals(false, test.isSupported(MICRO_OF_DAY)); + assertEquals(false, test.isSupported(MILLI_OF_SECOND)); + assertEquals(false, test.isSupported(MILLI_OF_DAY)); + assertEquals(false, test.isSupported(SECOND_OF_MINUTE)); + assertEquals(false, test.isSupported(SECOND_OF_DAY)); + assertEquals(false, test.isSupported(MINUTE_OF_HOUR)); + assertEquals(false, test.isSupported(MINUTE_OF_DAY)); + assertEquals(false, test.isSupported(HOUR_OF_AMPM)); + assertEquals(false, test.isSupported(CLOCK_HOUR_OF_AMPM)); + assertEquals(false, test.isSupported(HOUR_OF_DAY)); + assertEquals(false, test.isSupported(CLOCK_HOUR_OF_DAY)); + assertEquals(false, test.isSupported(AMPM_OF_DAY)); + assertEquals(false, test.isSupported(DAY_OF_WEEK)); + assertEquals(false, test.isSupported(ALIGNED_DAY_OF_WEEK_IN_MONTH)); + assertEquals(false, test.isSupported(ALIGNED_DAY_OF_WEEK_IN_YEAR)); + assertEquals(false, test.isSupported(DAY_OF_MONTH)); + assertEquals(false, test.isSupported(DAY_OF_YEAR)); + assertEquals(false, test.isSupported(EPOCH_DAY)); + assertEquals(false, test.isSupported(ALIGNED_WEEK_OF_MONTH)); + assertEquals(false, test.isSupported(ALIGNED_WEEK_OF_YEAR)); + assertEquals(false, test.isSupported(MONTH_OF_YEAR)); + assertEquals(false, test.isSupported(PROLEPTIC_MONTH)); + assertEquals(false, test.isSupported(YEAR_OF_ERA)); + assertEquals(false, test.isSupported(YEAR)); + assertEquals(false, test.isSupported(ERA)); + assertEquals(false, test.isSupported(INSTANT_SECONDS)); + assertEquals(false, test.isSupported(OFFSET_SECONDS)); + assertEquals(true, test.isSupported(QUARTER_OF_YEAR)); } //----------------------------------------------------------------------- @@ -257,7 +257,7 @@ public void test_isSupported() { //----------------------------------------------------------------------- @Test public void test_range() { - assertEquals(Quarter.Q1.range(QUARTER_OF_YEAR), QUARTER_OF_YEAR.range()); + assertEquals(QUARTER_OF_YEAR.range(), Quarter.Q1.range(QUARTER_OF_YEAR)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -275,10 +275,10 @@ public void test_range_null() { //----------------------------------------------------------------------- @Test public void test_get() { - assertEquals(Quarter.Q1.get(QUARTER_OF_YEAR), 1); - assertEquals(Quarter.Q2.get(QUARTER_OF_YEAR), 2); - assertEquals(Quarter.Q3.get(QUARTER_OF_YEAR), 3); - assertEquals(Quarter.Q4.get(QUARTER_OF_YEAR), 4); + assertEquals(1, Quarter.Q1.get(QUARTER_OF_YEAR)); + assertEquals(2, Quarter.Q2.get(QUARTER_OF_YEAR)); + assertEquals(3, Quarter.Q3.get(QUARTER_OF_YEAR)); + assertEquals(4, Quarter.Q4.get(QUARTER_OF_YEAR)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -296,10 +296,10 @@ public void test_get_null() { //----------------------------------------------------------------------- @Test public void test_getLong() { - assertEquals(Quarter.Q1.getLong(QUARTER_OF_YEAR), 1); - assertEquals(Quarter.Q2.getLong(QUARTER_OF_YEAR), 2); - assertEquals(Quarter.Q3.getLong(QUARTER_OF_YEAR), 3); - assertEquals(Quarter.Q4.getLong(QUARTER_OF_YEAR), 4); + assertEquals(1, Quarter.Q1.getLong(QUARTER_OF_YEAR)); + assertEquals(2, Quarter.Q2.getLong(QUARTER_OF_YEAR)); + assertEquals(3, Quarter.Q3.getLong(QUARTER_OF_YEAR)); + assertEquals(4, Quarter.Q4.getLong(QUARTER_OF_YEAR)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -335,7 +335,7 @@ public static Object[][] data_plus() { @Test @UseDataProvider("data_plus") public void test_plus_long(int base, long amount, int expected) { - assertEquals(Quarter.of(base).plus(amount), Quarter.of(expected)); + assertEquals(Quarter.of(expected), Quarter.of(base).plus(amount)); } //----------------------------------------------------------------------- @@ -361,7 +361,7 @@ public static Object[][] data_minus() { @Test @UseDataProvider("data_minus") public void test_minus_long(int base, long amount, int expected) { - assertEquals(Quarter.of(base).minus(amount), Quarter.of(expected)); + assertEquals(Quarter.of(expected), Quarter.of(base).minus(amount)); } //----------------------------------------------------------------------- @@ -369,14 +369,14 @@ public void test_minus_long(int base, long amount, int expected) { //----------------------------------------------------------------------- @Test public void test_length_boolean() { - assertEquals(Quarter.Q1.length(true), 91); - assertEquals(Quarter.Q1.length(false), 90); - assertEquals(Quarter.Q2.length(true), 91); - assertEquals(Quarter.Q2.length(false), 91); - assertEquals(Quarter.Q3.length(true), 92); - assertEquals(Quarter.Q3.length(false), 92); - assertEquals(Quarter.Q4.length(true), 92); - assertEquals(Quarter.Q4.length(false), 92); + assertEquals(91, Quarter.Q1.length(true)); + assertEquals(90, Quarter.Q1.length(false)); + assertEquals(91, Quarter.Q2.length(true)); + assertEquals(91, Quarter.Q2.length(false)); + assertEquals(92, Quarter.Q3.length(true)); + assertEquals(92, Quarter.Q3.length(false)); + assertEquals(92, Quarter.Q4.length(true)); + assertEquals(92, Quarter.Q4.length(false)); } //----------------------------------------------------------------------- @@ -384,10 +384,10 @@ public void test_length_boolean() { //----------------------------------------------------------------------- @Test public void test_firstMonth() { - assertEquals(Quarter.Q1.firstMonth(), Month.JANUARY); - assertEquals(Quarter.Q2.firstMonth(), Month.APRIL); - assertEquals(Quarter.Q3.firstMonth(), Month.JULY); - assertEquals(Quarter.Q4.firstMonth(), Month.OCTOBER); + assertEquals(Month.JANUARY, Quarter.Q1.firstMonth()); + assertEquals(Month.APRIL, Quarter.Q2.firstMonth()); + assertEquals(Month.JULY, Quarter.Q3.firstMonth()); + assertEquals(Month.OCTOBER, Quarter.Q4.firstMonth()); } //----------------------------------------------------------------------- @@ -395,13 +395,13 @@ public void test_firstMonth() { //----------------------------------------------------------------------- @Test public void test_query() { - assertEquals(Quarter.Q1.query(TemporalQueries.chronology()), IsoChronology.INSTANCE); - assertEquals(Quarter.Q1.query(TemporalQueries.localDate()), null); - assertEquals(Quarter.Q1.query(TemporalQueries.localTime()), null); - assertEquals(Quarter.Q1.query(TemporalQueries.offset()), null); - assertEquals(Quarter.Q1.query(TemporalQueries.precision()), QUARTER_YEARS); - assertEquals(Quarter.Q1.query(TemporalQueries.zone()), null); - assertEquals(Quarter.Q1.query(TemporalQueries.zoneId()), null); + assertEquals(IsoChronology.INSTANCE, Quarter.Q1.query(TemporalQueries.chronology())); + assertEquals(null, Quarter.Q1.query(TemporalQueries.localDate())); + assertEquals(null, Quarter.Q1.query(TemporalQueries.localTime())); + assertEquals(null, Quarter.Q1.query(TemporalQueries.offset())); + assertEquals(QUARTER_YEARS, Quarter.Q1.query(TemporalQueries.precision())); + assertEquals(null, Quarter.Q1.query(TemporalQueries.zone())); + assertEquals(null, Quarter.Q1.query(TemporalQueries.zoneId())); } //----------------------------------------------------------------------- @@ -409,10 +409,10 @@ public void test_query() { //----------------------------------------------------------------------- @Test public void test_toString() { - assertEquals(Quarter.Q1.toString(), "Q1"); - assertEquals(Quarter.Q2.toString(), "Q2"); - assertEquals(Quarter.Q3.toString(), "Q3"); - assertEquals(Quarter.Q4.toString(), "Q4"); + assertEquals("Q1", Quarter.Q1.toString()); + assertEquals("Q2", Quarter.Q2.toString()); + assertEquals("Q3", Quarter.Q3.toString()); + assertEquals("Q4", Quarter.Q4.toString()); } //----------------------------------------------------------------------- @@ -420,8 +420,8 @@ public void test_toString() { //----------------------------------------------------------------------- @Test public void test_enum() { - assertEquals(Quarter.valueOf("Q4"), Quarter.Q4); - assertEquals(Quarter.values()[0], Quarter.Q1); + assertEquals(Quarter.Q4, Quarter.valueOf("Q4")); + assertEquals(Quarter.Q1, Quarter.values()[0]); } } diff --git a/src/test/java/org/threeten/extra/TestSeconds.java b/src/test/java/org/threeten/extra/TestSeconds.java index 0cb922d0..eba3b84c 100644 --- a/src/test/java/org/threeten/extra/TestSeconds.java +++ b/src/test/java/org/threeten/extra/TestSeconds.java @@ -81,31 +81,31 @@ public void test_deserializationSingleton() throws Exception { public void test_ZERO() { assertSame(Seconds.of(0), Seconds.ZERO); assertSame(Seconds.of(0), Seconds.ZERO); - assertEquals(Seconds.ZERO.getAmount(), 0); + assertEquals(0, Seconds.ZERO.getAmount()); } //----------------------------------------------------------------------- @Test public void test_of() { - assertEquals(Seconds.of(0).getAmount(), 0); - assertEquals(Seconds.of(1).getAmount(), 1); - assertEquals(Seconds.of(2).getAmount(), 2); - assertEquals(Seconds.of(Integer.MAX_VALUE).getAmount(), Integer.MAX_VALUE); - assertEquals(Seconds.of(-1).getAmount(), -1); - assertEquals(Seconds.of(-2).getAmount(), -2); - assertEquals(Seconds.of(Integer.MIN_VALUE).getAmount(), Integer.MIN_VALUE); + assertEquals(0, Seconds.of(0).getAmount()); + assertEquals(1, Seconds.of(1).getAmount()); + assertEquals(2, Seconds.of(2).getAmount()); + assertEquals(Integer.MAX_VALUE, Seconds.of(Integer.MAX_VALUE).getAmount()); + assertEquals(-1, Seconds.of(-1).getAmount()); + assertEquals(-2, Seconds.of(-2).getAmount()); + assertEquals(Integer.MIN_VALUE, Seconds.of(Integer.MIN_VALUE).getAmount()); } //----------------------------------------------------------------------- @Test public void test_ofHours() { - assertEquals(Seconds.ofHours(0).getAmount(), 0); - assertEquals(Seconds.ofHours(1).getAmount(), 3600); - assertEquals(Seconds.ofHours(2).getAmount(), 7200); - assertEquals(Seconds.ofHours(Integer.MAX_VALUE / 3600).getAmount(), (Integer.MAX_VALUE / 3600) * 3600); - assertEquals(Seconds.ofHours(-1).getAmount(), -3600); - assertEquals(Seconds.ofHours(-2).getAmount(), -7200); - assertEquals(Seconds.ofHours(Integer.MIN_VALUE / 3600).getAmount(), (Integer.MIN_VALUE / 3600) * 3600); + assertEquals(0, Seconds.ofHours(0).getAmount()); + assertEquals(3600, Seconds.ofHours(1).getAmount()); + assertEquals(7200, Seconds.ofHours(2).getAmount()); + assertEquals((Integer.MAX_VALUE / 3600) * 3600, Seconds.ofHours(Integer.MAX_VALUE / 3600).getAmount()); + assertEquals(-3600, Seconds.ofHours(-1).getAmount()); + assertEquals(-7200, Seconds.ofHours(-2).getAmount()); + assertEquals((Integer.MIN_VALUE / 3600) * 3600, Seconds.ofHours(Integer.MIN_VALUE / 3600).getAmount()); } @Test(expected = ArithmeticException.class) @@ -116,13 +116,13 @@ public void test_ofHours_overflow() { //----------------------------------------------------------------------- @Test public void test_ofMinutes() { - assertEquals(Seconds.ofMinutes(0).getAmount(), 0); - assertEquals(Seconds.ofMinutes(1).getAmount(), 60); - assertEquals(Seconds.ofMinutes(2).getAmount(), 120); - assertEquals(Seconds.ofMinutes(Integer.MAX_VALUE / 60).getAmount(), (Integer.MAX_VALUE / 60) * 60); - assertEquals(Seconds.ofMinutes(-1).getAmount(), -60); - assertEquals(Seconds.ofMinutes(-2).getAmount(), -120); - assertEquals(Seconds.ofMinutes(Integer.MIN_VALUE / 60).getAmount(), (Integer.MIN_VALUE / 60) * 60); + assertEquals(0, Seconds.ofMinutes(0).getAmount()); + assertEquals(60, Seconds.ofMinutes(1).getAmount()); + assertEquals(120, Seconds.ofMinutes(2).getAmount()); + assertEquals((Integer.MAX_VALUE / 60) * 60, Seconds.ofMinutes(Integer.MAX_VALUE / 60).getAmount()); + assertEquals(-60, Seconds.ofMinutes(-1).getAmount()); + assertEquals(-120, Seconds.ofMinutes(-2).getAmount()); + assertEquals((Integer.MIN_VALUE / 60) * 60, Seconds.ofMinutes(Integer.MIN_VALUE / 60).getAmount()); } @Test(expected = ArithmeticException.class) @@ -194,19 +194,19 @@ public static Object[][] data_valid() { @Test @UseDataProvider("data_valid") public void test_parse_CharSequence_valid(String str, int expectedSeconds) { - assertEquals(Seconds.parse(str), Seconds.of(expectedSeconds)); + assertEquals(Seconds.of(expectedSeconds), Seconds.parse(str)); } @Test @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, int expectedSeconds) { - assertEquals(Seconds.parse("+" + str), Seconds.of(expectedSeconds)); + assertEquals(Seconds.of(expectedSeconds), Seconds.parse("+" + str)); } @Test @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, int expectedSeconds) { - assertEquals(Seconds.parse("-" + str), Seconds.of(-expectedSeconds)); + assertEquals(Seconds.of(-expectedSeconds), Seconds.parse("-" + str)); } @DataProvider @@ -418,23 +418,23 @@ public void test_abs_overflow() { @Test public void test_addTo() { LocalTime base = LocalTime.of(11, 30); - assertEquals(Seconds.of(0).addTo(base), LocalTime.of(11, 30)); - assertEquals(Seconds.of(6).addTo(base), LocalTime.of(11, 30, 6)); + assertEquals(LocalTime.of(11, 30), Seconds.of(0).addTo(base)); + assertEquals(LocalTime.of(11, 30, 6), Seconds.of(6).addTo(base)); } //----------------------------------------------------------------------- @Test public void test_subtractFrom() { LocalTime base = LocalTime.of(11, 30); - assertEquals(Seconds.of(0).subtractFrom(base), LocalTime.of(11, 30)); - assertEquals(Seconds.of(6).subtractFrom(base), LocalTime.of(11, 29, 54)); + assertEquals(LocalTime.of(11, 30), Seconds.of(0).subtractFrom(base)); + assertEquals(LocalTime.of(11, 29, 54), Seconds.of(6).subtractFrom(base)); } //----------------------------------------------------------------------- @Test public void test_toDuration() { for (int i = -20; i < 20; i++) { - assertEquals(Seconds.of(i).toDuration(), Duration.ofSeconds(i)); + assertEquals(Duration.ofSeconds(i), Seconds.of(i).toDuration()); } } diff --git a/src/test/java/org/threeten/extra/TestTemporals.java b/src/test/java/org/threeten/extra/TestTemporals.java index 7662e528..4239ee41 100644 --- a/src/test/java/org/threeten/extra/TestTemporals.java +++ b/src/test/java/org/threeten/extra/TestTemporals.java @@ -117,7 +117,7 @@ public void test_nextWorkingDay() { switch (date.getDayOfWeek()) { case FRIDAY: case SATURDAY: - assertEquals(test.getDayOfWeek(), MONDAY); + assertEquals(MONDAY, test.getDayOfWeek()); break; default: assertEquals(date.getDayOfWeek().plus(1), test.getDayOfWeek()); @@ -127,18 +127,18 @@ public void test_nextWorkingDay() { int dayDiff = test.getDayOfYear() - date.getDayOfYear(); switch (date.getDayOfWeek()) { case FRIDAY: - assertEquals(dayDiff, 3); + assertEquals(3, dayDiff); break; case SATURDAY: - assertEquals(dayDiff, 2); + assertEquals(2, dayDiff); break; default: - assertEquals(dayDiff, 1); + assertEquals(1, dayDiff); } } else { - assertEquals(test.getYear(), 2008); - assertEquals(test.getMonth(), JANUARY); - assertEquals(test.getDayOfMonth(), 1); + assertEquals(2008, test.getYear()); + assertEquals(JANUARY, test.getMonth()); + assertEquals(1, test.getDayOfMonth()); } } } @@ -148,11 +148,11 @@ public void test_nextWorkingDay() { public void test_nextWorkingDay_yearChange() { LocalDate friday = LocalDate.of(2010, DECEMBER, 31); Temporal test = Temporals.nextWorkingDay().adjustInto(friday); - assertEquals(test, LocalDate.of(2011, JANUARY, 3)); + assertEquals(LocalDate.of(2011, JANUARY, 3), test); LocalDate saturday = LocalDate.of(2011, DECEMBER, 31); test = Temporals.nextWorkingDay().adjustInto(saturday); - assertEquals(test, LocalDate.of(2012, JANUARY, 2)); + assertEquals(LocalDate.of(2012, JANUARY, 2), test); } //----------------------------------------------------------------------- @@ -184,7 +184,7 @@ public void test_previousWorkingDay() { switch (date.getDayOfWeek()) { case MONDAY: case SUNDAY: - assertEquals(test.getDayOfWeek(), FRIDAY); + assertEquals(FRIDAY, test.getDayOfWeek()); break; default: assertEquals(date.getDayOfWeek().minus(1), test.getDayOfWeek()); @@ -194,18 +194,18 @@ public void test_previousWorkingDay() { int dayDiff = test.getDayOfYear() - date.getDayOfYear(); switch (date.getDayOfWeek()) { case MONDAY: - assertEquals(dayDiff, -3); + assertEquals(-3, dayDiff); break; case SUNDAY: - assertEquals(dayDiff, -2); + assertEquals(-2, dayDiff); break; default: - assertEquals(dayDiff, -1); + assertEquals(-1, dayDiff); } } else { - assertEquals(test.getYear(), 2006); - assertEquals(test.getMonth(), DECEMBER); - assertEquals(test.getDayOfMonth(), 29); + assertEquals(2006, test.getYear()); + assertEquals(DECEMBER, test.getMonth()); + assertEquals(29, test.getDayOfMonth()); } } } @@ -215,11 +215,11 @@ public void test_previousWorkingDay() { public void test_previousWorkingDay_yearChange() { LocalDate monday = LocalDate.of(2011, JANUARY, 3); Temporal test = Temporals.previousWorkingDay().adjustInto(monday); - assertEquals(test, LocalDate.of(2010, DECEMBER, 31)); + assertEquals(LocalDate.of(2010, DECEMBER, 31), test); LocalDate sunday = LocalDate.of(2011, JANUARY, 2); test = Temporals.previousWorkingDay().adjustInto(sunday); - assertEquals(test, LocalDate.of(2010, DECEMBER, 31)); + assertEquals(LocalDate.of(2010, DECEMBER, 31), test); } //----------------------------------------------------------------------- @@ -236,7 +236,7 @@ public static Object[][] data_parseFirstMatching() { @Test @UseDataProvider("data_parseFirstMatching") public void test_parseFirstMatching(String text, DateTimeFormatter fmt1, DateTimeFormatter fmt2) { - assertEquals(Temporals.parseFirstMatching(text, LocalDate::from, fmt1, fmt2), LocalDate.of(2016, 9, 6)); + assertEquals(LocalDate.of(2016, 9, 6), Temporals.parseFirstMatching(text, LocalDate::from, fmt1, fmt2)); } @Test(expected = DateTimeParseException.class) @@ -246,7 +246,7 @@ public void test_parseFirstMatching_zero() { @Test public void test_parseFirstMatching_one() { - assertEquals(Temporals.parseFirstMatching("2016-09-06", LocalDate::from, DateTimeFormatter.ISO_LOCAL_DATE), LocalDate.of(2016, 9, 6)); + assertEquals(LocalDate.of(2016, 9, 6), Temporals.parseFirstMatching("2016-09-06", LocalDate::from, DateTimeFormatter.ISO_LOCAL_DATE)); } @Test(expected = DateTimeParseException.class) @@ -273,7 +273,7 @@ public static Object[][] data_timeUnitConversion() { @Test @UseDataProvider("data_timeUnitConversion") public void test_timeUnit(ChronoUnit chronoUnit, TimeUnit timeUnit) { - assertEquals(Temporals.timeUnit(chronoUnit), timeUnit); + assertEquals(timeUnit, Temporals.timeUnit(chronoUnit)); } @Test(expected = IllegalArgumentException.class) @@ -289,7 +289,7 @@ public void test_timeUnit_null() { @Test @UseDataProvider("data_timeUnitConversion") public void test_chronoUnit(ChronoUnit chronoUnit, TimeUnit timeUnit) { - assertEquals(Temporals.chronoUnit(timeUnit), chronoUnit); + assertEquals(chronoUnit, Temporals.chronoUnit(timeUnit)); } @Test(expected = NullPointerException.class) @@ -453,8 +453,8 @@ public void test_convertAmount( long fromAmount, TemporalUnit fromUnit, TemporalUnit resultUnit, long resultWhole, long resultRemainder) { long[] result = Temporals.convertAmount(fromAmount, fromUnit, resultUnit); - assertEquals(result[0], resultWhole); - assertEquals(result[1], resultRemainder); + assertEquals(resultWhole, result[0]); + assertEquals(resultRemainder, result[1]); } @Test @@ -463,8 +463,8 @@ public void test_convertAmount_negative( long fromAmount, TemporalUnit fromUnit, TemporalUnit resultUnit, long resultWhole, long resultRemainder) { long[] result = Temporals.convertAmount(-fromAmount, fromUnit, resultUnit); - assertEquals(result[0], -resultWhole); - assertEquals(result[1], -resultRemainder); + assertEquals(-resultWhole, result[0]); + assertEquals(-resultRemainder, result[1]); } @Test @@ -472,8 +472,8 @@ public void test_convertAmountSameUnit_zero() { for (ChronoUnit unit : ChronoUnit.values()) { if (unit != ERAS && unit != FOREVER) { long[] result = Temporals.convertAmount(0, unit, unit); - assertEquals(result[0], 0); - assertEquals(result[1], 0); + assertEquals(0, result[0]); + assertEquals(0, result[1]); } } } @@ -483,8 +483,8 @@ public void test_convertAmountSameUnit_nonZero() { for (ChronoUnit unit : ChronoUnit.values()) { if (unit != ERAS && unit != FOREVER) { long[] result = Temporals.convertAmount(2, unit, unit); - assertEquals(result[0], 2); - assertEquals(result[1], 0); + assertEquals(2, result[0]); + assertEquals(0, result[1]); } } } diff --git a/src/test/java/org/threeten/extra/TestWeeks.java b/src/test/java/org/threeten/extra/TestWeeks.java index 962f241e..52c106c7 100644 --- a/src/test/java/org/threeten/extra/TestWeeks.java +++ b/src/test/java/org/threeten/extra/TestWeeks.java @@ -83,46 +83,46 @@ public void test_deserializationSingleton() throws Exception { public void test_ZERO() { assertSame(Weeks.of(0), Weeks.ZERO); assertSame(Weeks.of(0), Weeks.ZERO); - assertEquals(Weeks.ZERO.getAmount(), 0); + assertEquals(0, Weeks.ZERO.getAmount()); } @Test public void test_ONE() { assertSame(Weeks.of(1), Weeks.ONE); assertSame(Weeks.of(1), Weeks.ONE); - assertEquals(Weeks.ONE.getAmount(), 1); + assertEquals(1, Weeks.ONE.getAmount()); } //----------------------------------------------------------------------- @Test public void test_of() { - assertEquals(Weeks.of(1).getAmount(), 1); - assertEquals(Weeks.of(2).getAmount(), 2); - assertEquals(Weeks.of(Integer.MAX_VALUE).getAmount(), Integer.MAX_VALUE); - assertEquals(Weeks.of(-1).getAmount(), -1); - assertEquals(Weeks.of(-2).getAmount(), -2); - assertEquals(Weeks.of(Integer.MIN_VALUE).getAmount(), Integer.MIN_VALUE); + assertEquals(1, Weeks.of(1).getAmount()); + assertEquals(2, Weeks.of(2).getAmount()); + assertEquals(Integer.MAX_VALUE, Weeks.of(Integer.MAX_VALUE).getAmount()); + assertEquals(-1, Weeks.of(-1).getAmount()); + assertEquals(-2, Weeks.of(-2).getAmount()); + assertEquals(Integer.MIN_VALUE, Weeks.of(Integer.MIN_VALUE).getAmount()); } //----------------------------------------------------------------------- @Test public void test_from_P0W() { - assertEquals(Weeks.from(Period.ofWeeks(0)), Weeks.of(0)); + assertEquals(Weeks.of(0), Weeks.from(Period.ofWeeks(0))); } @Test public void test_from_P2W() { - assertEquals(Weeks.from(Period.ofWeeks(2)), Weeks.of(2)); + assertEquals(Weeks.of(2), Weeks.from(Period.ofWeeks(2))); } @Test public void test_from_P14D() { - assertEquals(Weeks.from(Period.ofDays(14)), Weeks.of(2)); + assertEquals(Weeks.of(2), Weeks.from(Period.ofDays(14))); } @Test public void test_from_Duration() { - assertEquals(Weeks.from(Duration.ofDays(14)), Weeks.of(2)); + assertEquals(Weeks.of(2), Weeks.from(Duration.ofDays(14))); } @Test(expected = DateTimeException.class) @@ -143,13 +143,13 @@ public void test_from_null() { //----------------------------------------------------------------------- @Test public void test_parse_CharSequence() { - assertEquals(Weeks.parse("P0W"), Weeks.of(0)); - assertEquals(Weeks.parse("P1W"), Weeks.of(1)); - assertEquals(Weeks.parse("P2W"), Weeks.of(2)); - assertEquals(Weeks.parse("P123456789W"), Weeks.of(123456789)); - assertEquals(Weeks.parse("P-2W"), Weeks.of(-2)); - assertEquals(Weeks.parse("-P2W"), Weeks.of(-2)); - assertEquals(Weeks.parse("-P-2W"), Weeks.of(2)); + assertEquals(Weeks.of(0), Weeks.parse("P0W")); + assertEquals(Weeks.of(1), Weeks.parse("P1W")); + assertEquals(Weeks.of(2), Weeks.parse("P2W")); + assertEquals(Weeks.of(123456789), Weeks.parse("P123456789W")); + assertEquals(Weeks.of(-2), Weeks.parse("P-2W")); + assertEquals(Weeks.of(-2), Weeks.parse("-P2W")); + assertEquals(Weeks.of(2), Weeks.parse("-P-2W")); } @DataProvider @@ -398,7 +398,7 @@ public void test_abs_overflow() { @Test public void test_toPeriod() { for (int i = -20; i < 20; i++) { - assertEquals(Weeks.of(i).toPeriod(), Period.ofWeeks(i)); + assertEquals(Period.ofWeeks(i), Weeks.of(i).toPeriod()); } } diff --git a/src/test/java/org/threeten/extra/TestYearQuarter.java b/src/test/java/org/threeten/extra/TestYearQuarter.java index 6826655e..86694d37 100644 --- a/src/test/java/org/threeten/extra/TestYearQuarter.java +++ b/src/test/java/org/threeten/extra/TestYearQuarter.java @@ -135,7 +135,7 @@ public void test_serialization() throws IOException, ClassNotFoundException { oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertEquals(ois.readObject(), test); + assertEquals(test, ois.readObject()); } } @@ -147,9 +147,9 @@ public void test_of_int_Quarter() { for (int year = -100; year <= 100; year++) { for (Quarter quarter : Quarter.values()) { YearQuarter test = YearQuarter.of(year, quarter); - assertEquals(test.getYear(), year); - assertEquals(test.getQuarterValue(), quarter.getValue()); - assertEquals(test.getQuarter(), quarter); + assertEquals(year, test.getYear()); + assertEquals(quarter.getValue(), test.getQuarterValue()); + assertEquals(quarter, test.getQuarter()); } } } @@ -177,11 +177,11 @@ public void test_of_int_int() { for (int year = -100; year <= 100; year++) { for (int quarter = 1; quarter <= 4; quarter++) { YearQuarter test = YearQuarter.of(year, quarter); - assertEquals(test.getYear(), year); - assertEquals(test.getQuarterValue(), quarter); - assertEquals(test.getQuarter(), Quarter.of(quarter)); - assertEquals(YearQuarter.of(year, quarter), test); - assertEquals(YearQuarter.of(year, quarter).hashCode(), test.hashCode()); + assertEquals(year, test.getYear()); + assertEquals(quarter, test.getQuarterValue()); + assertEquals(Quarter.of(quarter), test.getQuarter()); + assertEquals(test, YearQuarter.of(year, quarter)); + assertEquals(test.hashCode(), YearQuarter.of(year, quarter).hashCode()); } } } @@ -215,7 +215,7 @@ public void test_from_TemporalAccessor_notLeapYear() { for (int i = 1; i <= STANDARD_YEAR_LENGTH; i++) { YearQuarter test = YearQuarter.from(date); int expected = ((date.getMonthValue() - 1) / 3) + 1; - assertEquals(test, YearQuarter.of(2007, expected)); + assertEquals(YearQuarter.of(2007, expected), test); date = date.plusDays(1); } } @@ -226,7 +226,7 @@ public void test_from_TemporalAccessor_leapYear() { for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) { YearQuarter test = YearQuarter.from(date); int expected = ((date.getMonthValue() - 1) / 3) + 1; - assertEquals(test, YearQuarter.of(2008, expected)); + assertEquals(YearQuarter.of(2008, expected), test); date = date.plusDays(1); } } @@ -246,12 +246,12 @@ public void test_from_TemporalAccessor_null() { //----------------------------------------------------------------------- @Test public void test_parse_CharSequence() { - assertEquals(YearQuarter.parse("2012-Q3"), YearQuarter.of(2012, Q3)); + assertEquals(YearQuarter.of(2012, Q3), YearQuarter.parse("2012-Q3")); } @Test public void test_parse_CharSequence_caseInsensitive() { - assertEquals(YearQuarter.parse("2012-q3"), YearQuarter.of(2012, Q3)); + assertEquals(YearQuarter.of(2012, Q3), YearQuarter.parse("2012-q3")); } @Test(expected = DateTimeParseException.class) @@ -275,7 +275,7 @@ public void test_parse_CharSequenceDate_nullCharSequence() { @Test public void test_parse_CharSequenceDateTimeFormatter() { DateTimeFormatter f = DateTimeFormatter.ofPattern("'Q'Q uuuu"); - assertEquals(YearQuarter.parse("Q3 2012", f), YearQuarter.of(2012, Q3)); + assertEquals(YearQuarter.of(2012, Q3), YearQuarter.parse("Q3 2012", f)); } @Test(expected = DateTimeParseException.class) @@ -300,39 +300,39 @@ public void test_parse_CharSequenceDateTimeFormatter_nullDateTimeFormatter() { //----------------------------------------------------------------------- @Test public void test_isSupported_TemporalField() { - assertEquals(TEST.isSupported((TemporalField) null), false); - assertEquals(TEST.isSupported(NANO_OF_SECOND), false); - assertEquals(TEST.isSupported(NANO_OF_DAY), false); - assertEquals(TEST.isSupported(MICRO_OF_SECOND), false); - assertEquals(TEST.isSupported(MICRO_OF_DAY), false); - assertEquals(TEST.isSupported(MILLI_OF_SECOND), false); - assertEquals(TEST.isSupported(MILLI_OF_DAY), false); - assertEquals(TEST.isSupported(SECOND_OF_MINUTE), false); - assertEquals(TEST.isSupported(SECOND_OF_DAY), false); - assertEquals(TEST.isSupported(MINUTE_OF_HOUR), false); - assertEquals(TEST.isSupported(MINUTE_OF_DAY), false); - assertEquals(TEST.isSupported(HOUR_OF_AMPM), false); - assertEquals(TEST.isSupported(CLOCK_HOUR_OF_AMPM), false); - assertEquals(TEST.isSupported(HOUR_OF_DAY), false); - assertEquals(TEST.isSupported(CLOCK_HOUR_OF_DAY), false); - assertEquals(TEST.isSupported(AMPM_OF_DAY), false); - assertEquals(TEST.isSupported(DAY_OF_WEEK), false); - assertEquals(TEST.isSupported(ALIGNED_DAY_OF_WEEK_IN_MONTH), false); - assertEquals(TEST.isSupported(ALIGNED_DAY_OF_WEEK_IN_YEAR), false); - assertEquals(TEST.isSupported(DAY_OF_MONTH), false); - assertEquals(TEST.isSupported(DAY_OF_YEAR), false); - assertEquals(TEST.isSupported(EPOCH_DAY), false); - assertEquals(TEST.isSupported(ALIGNED_WEEK_OF_MONTH), false); - assertEquals(TEST.isSupported(ALIGNED_WEEK_OF_YEAR), false); - assertEquals(TEST.isSupported(MONTH_OF_YEAR), false); - assertEquals(TEST.isSupported(PROLEPTIC_MONTH), false); - assertEquals(TEST.isSupported(YEAR_OF_ERA), true); - assertEquals(TEST.isSupported(YEAR), true); - assertEquals(TEST.isSupported(ERA), true); - assertEquals(TEST.isSupported(INSTANT_SECONDS), false); - assertEquals(TEST.isSupported(OFFSET_SECONDS), false); - assertEquals(TEST.isSupported(QUARTER_OF_YEAR), true); - assertEquals(TEST.isSupported(DAY_OF_QUARTER), false); + assertEquals(false, TEST.isSupported((TemporalField) null)); + assertEquals(false, TEST.isSupported(NANO_OF_SECOND)); + assertEquals(false, TEST.isSupported(NANO_OF_DAY)); + assertEquals(false, TEST.isSupported(MICRO_OF_SECOND)); + assertEquals(false, TEST.isSupported(MICRO_OF_DAY)); + assertEquals(false, TEST.isSupported(MILLI_OF_SECOND)); + assertEquals(false, TEST.isSupported(MILLI_OF_DAY)); + assertEquals(false, TEST.isSupported(SECOND_OF_MINUTE)); + assertEquals(false, TEST.isSupported(SECOND_OF_DAY)); + assertEquals(false, TEST.isSupported(MINUTE_OF_HOUR)); + assertEquals(false, TEST.isSupported(MINUTE_OF_DAY)); + assertEquals(false, TEST.isSupported(HOUR_OF_AMPM)); + assertEquals(false, TEST.isSupported(CLOCK_HOUR_OF_AMPM)); + assertEquals(false, TEST.isSupported(HOUR_OF_DAY)); + assertEquals(false, TEST.isSupported(CLOCK_HOUR_OF_DAY)); + assertEquals(false, TEST.isSupported(AMPM_OF_DAY)); + assertEquals(false, TEST.isSupported(DAY_OF_WEEK)); + assertEquals(false, TEST.isSupported(ALIGNED_DAY_OF_WEEK_IN_MONTH)); + assertEquals(false, TEST.isSupported(ALIGNED_DAY_OF_WEEK_IN_YEAR)); + assertEquals(false, TEST.isSupported(DAY_OF_MONTH)); + assertEquals(false, TEST.isSupported(DAY_OF_YEAR)); + assertEquals(false, TEST.isSupported(EPOCH_DAY)); + assertEquals(false, TEST.isSupported(ALIGNED_WEEK_OF_MONTH)); + assertEquals(false, TEST.isSupported(ALIGNED_WEEK_OF_YEAR)); + assertEquals(false, TEST.isSupported(MONTH_OF_YEAR)); + assertEquals(false, TEST.isSupported(PROLEPTIC_MONTH)); + assertEquals(true, TEST.isSupported(YEAR_OF_ERA)); + assertEquals(true, TEST.isSupported(YEAR)); + assertEquals(true, TEST.isSupported(ERA)); + assertEquals(false, TEST.isSupported(INSTANT_SECONDS)); + assertEquals(false, TEST.isSupported(OFFSET_SECONDS)); + assertEquals(true, TEST.isSupported(QUARTER_OF_YEAR)); + assertEquals(false, TEST.isSupported(DAY_OF_QUARTER)); } //----------------------------------------------------------------------- @@ -340,23 +340,23 @@ public void test_isSupported_TemporalField() { //----------------------------------------------------------------------- @Test public void test_isSupported_TemporalUnit() { - assertEquals(TEST.isSupported((TemporalUnit) null), false); - assertEquals(TEST.isSupported(NANOS), false); - assertEquals(TEST.isSupported(MICROS), false); - assertEquals(TEST.isSupported(MILLIS), false); - assertEquals(TEST.isSupported(SECONDS), false); - assertEquals(TEST.isSupported(MINUTES), false); - assertEquals(TEST.isSupported(HOURS), false); - assertEquals(TEST.isSupported(DAYS), false); - assertEquals(TEST.isSupported(WEEKS), false); - assertEquals(TEST.isSupported(MONTHS), false); - assertEquals(TEST.isSupported(YEARS), true); - assertEquals(TEST.isSupported(DECADES), true); - assertEquals(TEST.isSupported(CENTURIES), true); - assertEquals(TEST.isSupported(MILLENNIA), true); - assertEquals(TEST.isSupported(ERA), true); - assertEquals(TEST.isSupported(FOREVER), false); - assertEquals(TEST.isSupported(QUARTER_YEARS), true); + assertEquals(false, TEST.isSupported((TemporalUnit) null)); + assertEquals(false, TEST.isSupported(NANOS)); + assertEquals(false, TEST.isSupported(MICROS)); + assertEquals(false, TEST.isSupported(MILLIS)); + assertEquals(false, TEST.isSupported(SECONDS)); + assertEquals(false, TEST.isSupported(MINUTES)); + assertEquals(false, TEST.isSupported(HOURS)); + assertEquals(false, TEST.isSupported(DAYS)); + assertEquals(false, TEST.isSupported(WEEKS)); + assertEquals(false, TEST.isSupported(MONTHS)); + assertEquals(true, TEST.isSupported(YEARS)); + assertEquals(true, TEST.isSupported(DECADES)); + assertEquals(true, TEST.isSupported(CENTURIES)); + assertEquals(true, TEST.isSupported(MILLENNIA)); + assertEquals(true, TEST.isSupported(ERA)); + assertEquals(false, TEST.isSupported(FOREVER)); + assertEquals(true, TEST.isSupported(QUARTER_YEARS)); } //----------------------------------------------------------------------- @@ -364,10 +364,10 @@ public void test_isSupported_TemporalUnit() { //----------------------------------------------------------------------- @Test public void test_range() { - assertEquals(TEST.range(QUARTER_OF_YEAR), QUARTER_OF_YEAR.range()); - assertEquals(TEST.range(YEAR), YEAR.range()); - assertEquals(TEST.range(YEAR_OF_ERA), ValueRange.of(1, Year.MAX_VALUE)); - assertEquals(TEST.range(ERA), ERA.range()); + assertEquals(QUARTER_OF_YEAR.range(), TEST.range(QUARTER_OF_YEAR)); + assertEquals(YEAR.range(), TEST.range(YEAR)); + assertEquals(ValueRange.of(1, Year.MAX_VALUE), TEST.range(YEAR_OF_ERA)); + assertEquals(ERA.range(), TEST.range(ERA)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -385,10 +385,10 @@ public void test_range_null() { //----------------------------------------------------------------------- @Test public void test_get() { - assertEquals(TEST.get(QUARTER_OF_YEAR), 2); - assertEquals(TEST.get(YEAR), 2012); - assertEquals(TEST.get(YEAR_OF_ERA), 2012); - assertEquals(TEST.get(ERA), 1); + assertEquals(2, TEST.get(QUARTER_OF_YEAR)); + assertEquals(2012, TEST.get(YEAR)); + assertEquals(2012, TEST.get(YEAR_OF_ERA)); + assertEquals(1, TEST.get(ERA)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -406,10 +406,10 @@ public void test_get_null() { //----------------------------------------------------------------------- @Test public void test_getLong() { - assertEquals(TEST.getLong(QUARTER_OF_YEAR), 2L); - assertEquals(TEST.getLong(YEAR), 2012L); - assertEquals(TEST.getLong(YEAR_OF_ERA), 2012L); - assertEquals(TEST.getLong(ERA), 1L); + assertEquals(2L, TEST.getLong(QUARTER_OF_YEAR)); + assertEquals(2012L, TEST.getLong(YEAR)); + assertEquals(2012L, TEST.getLong(YEAR_OF_ERA)); + assertEquals(1L, TEST.getLong(ERA)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -430,7 +430,7 @@ public void test_isLeapYear_int() { for (int year = -500; year <= 500; year++) { for (Quarter quarter : Quarter.values()) { YearQuarter test = YearQuarter.of(year, quarter); - assertEquals(test.isLeapYear(), Year.isLeap(year)); + assertEquals(Year.isLeap(year), test.isLeapYear()); } } } @@ -440,53 +440,53 @@ public void test_isLeapYear_int() { //----------------------------------------------------------------------- @Test public void test_isValidDay_int_nonLeap() { - assertEquals(YearQuarter.of(2011, Q1).isValidDay(90), true); - assertEquals(YearQuarter.of(2011, Q1).isValidDay(91), false); - assertEquals(YearQuarter.of(2011, Q1).isValidDay(92), false); + assertEquals(true, YearQuarter.of(2011, Q1).isValidDay(90)); + assertEquals(false, YearQuarter.of(2011, Q1).isValidDay(91)); + assertEquals(false, YearQuarter.of(2011, Q1).isValidDay(92)); - assertEquals(YearQuarter.of(2011, Q2).isValidDay(90), true); - assertEquals(YearQuarter.of(2011, Q2).isValidDay(91), true); - assertEquals(YearQuarter.of(2011, Q2).isValidDay(92), false); + assertEquals(true, YearQuarter.of(2011, Q2).isValidDay(90)); + assertEquals(true, YearQuarter.of(2011, Q2).isValidDay(91)); + assertEquals(false, YearQuarter.of(2011, Q2).isValidDay(92)); - assertEquals(YearQuarter.of(2011, Q3).isValidDay(90), true); - assertEquals(YearQuarter.of(2011, Q3).isValidDay(91), true); - assertEquals(YearQuarter.of(2011, Q4).isValidDay(90), true); + assertEquals(true, YearQuarter.of(2011, Q3).isValidDay(90)); + assertEquals(true, YearQuarter.of(2011, Q3).isValidDay(91)); + assertEquals(true, YearQuarter.of(2011, Q4).isValidDay(90)); - assertEquals(YearQuarter.of(2011, Q3).isValidDay(92), true); - assertEquals(YearQuarter.of(2011, Q4).isValidDay(91), true); - assertEquals(YearQuarter.of(2011, Q4).isValidDay(92), true); + assertEquals(true, YearQuarter.of(2011, Q3).isValidDay(92)); + assertEquals(true, YearQuarter.of(2011, Q4).isValidDay(91)); + assertEquals(true, YearQuarter.of(2011, Q4).isValidDay(92)); } @Test public void test_isValidDay_int_leap() { - assertEquals(YearQuarter.of(2012, Q1).isValidDay(90), true); - assertEquals(YearQuarter.of(2012, Q1).isValidDay(91), true); - assertEquals(YearQuarter.of(2012, Q1).isValidDay(92), false); + assertEquals(true, YearQuarter.of(2012, Q1).isValidDay(90)); + assertEquals(true, YearQuarter.of(2012, Q1).isValidDay(91)); + assertEquals(false, YearQuarter.of(2012, Q1).isValidDay(92)); - assertEquals(YearQuarter.of(2012, Q2).isValidDay(90), true); - assertEquals(YearQuarter.of(2012, Q2).isValidDay(91), true); - assertEquals(YearQuarter.of(2012, Q2).isValidDay(92), false); + assertEquals(true, YearQuarter.of(2012, Q2).isValidDay(90)); + assertEquals(true, YearQuarter.of(2012, Q2).isValidDay(91)); + assertEquals(false, YearQuarter.of(2012, Q2).isValidDay(92)); - assertEquals(YearQuarter.of(2012, Q3).isValidDay(90), true); - assertEquals(YearQuarter.of(2012, Q3).isValidDay(91), true); - assertEquals(YearQuarter.of(2012, Q3).isValidDay(92), true); + assertEquals(true, YearQuarter.of(2012, Q3).isValidDay(90)); + assertEquals(true, YearQuarter.of(2012, Q3).isValidDay(91)); + assertEquals(true, YearQuarter.of(2012, Q3).isValidDay(92)); - assertEquals(YearQuarter.of(2012, Q4).isValidDay(90), true); - assertEquals(YearQuarter.of(2012, Q4).isValidDay(91), true); - assertEquals(YearQuarter.of(2012, Q4).isValidDay(92), true); + assertEquals(true, YearQuarter.of(2012, Q4).isValidDay(90)); + assertEquals(true, YearQuarter.of(2012, Q4).isValidDay(91)); + assertEquals(true, YearQuarter.of(2012, Q4).isValidDay(92)); } @Test public void test_isValidDay_int_outOfRange() { - assertEquals(YearQuarter.of(2011, Q1).isValidDay(93), false); - assertEquals(YearQuarter.of(2011, Q2).isValidDay(93), false); - assertEquals(YearQuarter.of(2011, Q3).isValidDay(93), false); - assertEquals(YearQuarter.of(2011, Q4).isValidDay(93), false); + assertEquals(false, YearQuarter.of(2011, Q1).isValidDay(93)); + assertEquals(false, YearQuarter.of(2011, Q2).isValidDay(93)); + assertEquals(false, YearQuarter.of(2011, Q3).isValidDay(93)); + assertEquals(false, YearQuarter.of(2011, Q4).isValidDay(93)); - assertEquals(YearQuarter.of(2011, Q1).isValidDay(0), false); - assertEquals(YearQuarter.of(2011, Q2).isValidDay(0), false); - assertEquals(YearQuarter.of(2011, Q3).isValidDay(0), false); - assertEquals(YearQuarter.of(2011, Q4).isValidDay(0), false); + assertEquals(false, YearQuarter.of(2011, Q1).isValidDay(0)); + assertEquals(false, YearQuarter.of(2011, Q2).isValidDay(0)); + assertEquals(false, YearQuarter.of(2011, Q3).isValidDay(0)); + assertEquals(false, YearQuarter.of(2011, Q4).isValidDay(0)); } //----------------------------------------------------------------------- @@ -495,10 +495,10 @@ public void test_isValidDay_int_outOfRange() { @Test public void test_lengthOfQuarter() { for (int year = -500; year <= 500; year++) { - assertEquals(YearQuarter.of(year, Q1).lengthOfQuarter(), Year.isLeap(year) ? 91 : 90); - assertEquals(YearQuarter.of(year, Q2).lengthOfQuarter(), 91); - assertEquals(YearQuarter.of(year, Q3).lengthOfQuarter(), 92); - assertEquals(YearQuarter.of(year, Q4).lengthOfQuarter(), 92); + assertEquals(Year.isLeap(year) ? 91 : 90, YearQuarter.of(year, Q1).lengthOfQuarter()); + assertEquals(91, YearQuarter.of(year, Q2).lengthOfQuarter()); + assertEquals(92, YearQuarter.of(year, Q3).lengthOfQuarter()); + assertEquals(92, YearQuarter.of(year, Q4).lengthOfQuarter()); } } @@ -507,17 +507,17 @@ public void test_lengthOfQuarter() { //----------------------------------------------------------------------- @Test public void test_with_TemporalAdjuster_Quarter() { - assertEquals(YearQuarter.of(2007, Q2).with(Q1), YearQuarter.of(2007, Q1)); + assertEquals(YearQuarter.of(2007, Q1), YearQuarter.of(2007, Q2).with(Q1)); } @Test public void test_with_TemporalAdjuster_Year() { - assertEquals(YearQuarter.of(2007, Q2).with(Year.of(2012)), YearQuarter.of(2012, Q2)); + assertEquals(YearQuarter.of(2012, Q2), YearQuarter.of(2007, Q2).with(Year.of(2012))); } @Test public void test_with_TemporalAdjuster_YearQuarter() { - assertEquals(YearQuarter.of(2007, Q2).with(YearQuarter.of(2012, Q3)), YearQuarter.of(2012, Q3)); + assertEquals(YearQuarter.of(2012, Q3), YearQuarter.of(2007, Q2).with(YearQuarter.of(2012, Q3))); } @Test(expected = DateTimeException.class) @@ -535,7 +535,7 @@ public void test_with_TemporalAdjuster_null() { //----------------------------------------------------------------------- @Test public void test_withYear() { - assertEquals(YearQuarter.of(2007, Q2).withYear(2012), YearQuarter.of(2012, Q2)); + assertEquals(YearQuarter.of(2012, Q2), YearQuarter.of(2007, Q2).withYear(2012)); } @Test(expected = DateTimeException.class) @@ -553,7 +553,7 @@ public void test_withYear_int_quarterTooHigh() { //----------------------------------------------------------------------- @Test public void test_withQuarter_int() { - assertEquals(YearQuarter.of(2007, Q2).withQuarter(1), YearQuarter.of(2007, Q1)); + assertEquals(YearQuarter.of(2007, Q1), YearQuarter.of(2007, Q2).withQuarter(1)); } @Test(expected = DateTimeException.class) @@ -571,12 +571,12 @@ public void test_withQuarter_int_quarterTooHigh() { //----------------------------------------------------------------------- @Test public void test_plus_longTemporalUnit() { - assertEquals(YearQuarter.of(2007, Q2).plus(5, YEARS), YearQuarter.of(2012, Q2)); - assertEquals(YearQuarter.of(2007, Q2).plus(0, YEARS), YearQuarter.of(2007, Q2)); - assertEquals(YearQuarter.of(2007, Q2).plus(-5, YEARS), YearQuarter.of(2002, Q2)); - assertEquals(YearQuarter.of(2007, Q2).plus(5, QUARTER_YEARS), YearQuarter.of(2008, Q3)); - assertEquals(YearQuarter.of(2007, Q2).plus(0, QUARTER_YEARS), YearQuarter.of(2007, Q2)); - assertEquals(YearQuarter.of(2007, Q2).plus(-5, QUARTER_YEARS), YearQuarter.of(2006, Q1)); + assertEquals(YearQuarter.of(2012, Q2), YearQuarter.of(2007, Q2).plus(5, YEARS)); + assertEquals(YearQuarter.of(2007, Q2), YearQuarter.of(2007, Q2).plus(0, YEARS)); + assertEquals(YearQuarter.of(2002, Q2), YearQuarter.of(2007, Q2).plus(-5, YEARS)); + assertEquals(YearQuarter.of(2008, Q3), YearQuarter.of(2007, Q2).plus(5, QUARTER_YEARS)); + assertEquals(YearQuarter.of(2007, Q2), YearQuarter.of(2007, Q2).plus(0, QUARTER_YEARS)); + assertEquals(YearQuarter.of(2006, Q1), YearQuarter.of(2007, Q2).plus(-5, QUARTER_YEARS)); } //----------------------------------------------------------------------- @@ -584,9 +584,9 @@ public void test_plus_longTemporalUnit() { //----------------------------------------------------------------------- @Test public void test_plusYears() { - assertEquals(YearQuarter.of(2007, Q2).plusYears(5), YearQuarter.of(2012, Q2)); - assertEquals(YearQuarter.of(2007, Q2).plusYears(0), YearQuarter.of(2007, Q2)); - assertEquals(YearQuarter.of(2007, Q2).plusYears(-5), YearQuarter.of(2002, Q2)); + assertEquals(YearQuarter.of(2012, Q2), YearQuarter.of(2007, Q2).plusYears(5)); + assertEquals(YearQuarter.of(2007, Q2), YearQuarter.of(2007, Q2).plusYears(0)); + assertEquals(YearQuarter.of(2002, Q2), YearQuarter.of(2007, Q2).plusYears(-5)); } //----------------------------------------------------------------------- @@ -594,9 +594,9 @@ public void test_plusYears() { //----------------------------------------------------------------------- @Test public void test_plusQuarters() { - assertEquals(YearQuarter.of(2007, Q2).plusQuarters(5), YearQuarter.of(2008, Q3)); - assertEquals(YearQuarter.of(2007, Q2).plusQuarters(0), YearQuarter.of(2007, Q2)); - assertEquals(YearQuarter.of(2007, Q2).plusQuarters(-5), YearQuarter.of(2006, Q1)); + assertEquals(YearQuarter.of(2008, Q3), YearQuarter.of(2007, Q2).plusQuarters(5)); + assertEquals(YearQuarter.of(2007, Q2), YearQuarter.of(2007, Q2).plusQuarters(0)); + assertEquals(YearQuarter.of(2006, Q1), YearQuarter.of(2007, Q2).plusQuarters(-5)); } //----------------------------------------------------------------------- @@ -604,12 +604,12 @@ public void test_plusQuarters() { //----------------------------------------------------------------------- @Test public void test_minus_longTemporalUnit() { - assertEquals(YearQuarter.of(2007, Q2).minus(5, YEARS), YearQuarter.of(2002, Q2)); - assertEquals(YearQuarter.of(2007, Q2).minus(0, YEARS), YearQuarter.of(2007, Q2)); - assertEquals(YearQuarter.of(2007, Q2).minus(-5, YEARS), YearQuarter.of(2012, Q2)); - assertEquals(YearQuarter.of(2007, Q2).minus(5, QUARTER_YEARS), YearQuarter.of(2006, Q1)); - assertEquals(YearQuarter.of(2007, Q2).minus(0, QUARTER_YEARS), YearQuarter.of(2007, Q2)); - assertEquals(YearQuarter.of(2007, Q2).minus(-5, QUARTER_YEARS), YearQuarter.of(2008, Q3)); + assertEquals(YearQuarter.of(2002, Q2), YearQuarter.of(2007, Q2).minus(5, YEARS)); + assertEquals(YearQuarter.of(2007, Q2), YearQuarter.of(2007, Q2).minus(0, YEARS)); + assertEquals(YearQuarter.of(2012, Q2), YearQuarter.of(2007, Q2).minus(-5, YEARS)); + assertEquals(YearQuarter.of(2006, Q1), YearQuarter.of(2007, Q2).minus(5, QUARTER_YEARS)); + assertEquals(YearQuarter.of(2007, Q2), YearQuarter.of(2007, Q2).minus(0, QUARTER_YEARS)); + assertEquals(YearQuarter.of(2008, Q3), YearQuarter.of(2007, Q2).minus(-5, QUARTER_YEARS)); } //----------------------------------------------------------------------- @@ -617,9 +617,9 @@ public void test_minus_longTemporalUnit() { //----------------------------------------------------------------------- @Test public void test_minusYears() { - assertEquals(YearQuarter.of(2007, Q2).minusYears(5), YearQuarter.of(2002, Q2)); - assertEquals(YearQuarter.of(2007, Q2).minusYears(0), YearQuarter.of(2007, Q2)); - assertEquals(YearQuarter.of(2007, Q2).minusYears(-5), YearQuarter.of(2012, Q2)); + assertEquals(YearQuarter.of(2002, Q2), YearQuarter.of(2007, Q2).minusYears(5)); + assertEquals(YearQuarter.of(2007, Q2), YearQuarter.of(2007, Q2).minusYears(0)); + assertEquals(YearQuarter.of(2012, Q2), YearQuarter.of(2007, Q2).minusYears(-5)); } //----------------------------------------------------------------------- @@ -627,9 +627,9 @@ public void test_minusYears() { //----------------------------------------------------------------------- @Test public void test_minusQuarters() { - assertEquals(YearQuarter.of(2007, Q2).minusQuarters(5), YearQuarter.of(2006, Q1)); - assertEquals(YearQuarter.of(2007, Q2).minusQuarters(0), YearQuarter.of(2007, Q2)); - assertEquals(YearQuarter.of(2007, Q2).minusQuarters(-5), YearQuarter.of(2008, Q3)); + assertEquals(YearQuarter.of(2006, Q1), YearQuarter.of(2007, Q2).minusQuarters(5)); + assertEquals(YearQuarter.of(2007, Q2), YearQuarter.of(2007, Q2).minusQuarters(0)); + assertEquals(YearQuarter.of(2008, Q3), YearQuarter.of(2007, Q2).minusQuarters(-5)); } //----------------------------------------------------------------------- @@ -640,7 +640,7 @@ public void test_lengthOfYear() { for (int year = -500; year <= 500; year++) { for (Quarter quarter : Quarter.values()) { YearQuarter test = YearQuarter.of(year, quarter); - assertEquals(test.lengthOfYear(), Year.isLeap(year) ? 366 : 365); + assertEquals(Year.isLeap(year) ? 366 : 365, test.lengthOfYear()); } } } @@ -650,13 +650,13 @@ public void test_lengthOfYear() { //----------------------------------------------------------------------- @Test public void test_query() { - assertEquals(TEST.query(TemporalQueries.chronology()), IsoChronology.INSTANCE); - assertEquals(TEST.query(TemporalQueries.localDate()), null); - assertEquals(TEST.query(TemporalQueries.localTime()), null); - assertEquals(TEST.query(TemporalQueries.offset()), null); - assertEquals(TEST.query(TemporalQueries.precision()), QUARTER_YEARS); - assertEquals(TEST.query(TemporalQueries.zone()), null); - assertEquals(TEST.query(TemporalQueries.zoneId()), null); + assertEquals(IsoChronology.INSTANCE, TEST.query(TemporalQueries.chronology())); + assertEquals(null, TEST.query(TemporalQueries.localDate())); + assertEquals(null, TEST.query(TemporalQueries.localTime())); + assertEquals(null, TEST.query(TemporalQueries.offset())); + assertEquals(QUARTER_YEARS, TEST.query(TemporalQueries.precision())); + assertEquals(null, TEST.query(TemporalQueries.zone())); + assertEquals(null, TEST.query(TemporalQueries.zoneId())); } //----------------------------------------------------------------------- @@ -668,7 +668,7 @@ public void test_adjustInto_Temporal() { for (int dom = 1; dom < 28; dom++) { LocalDate base = LocalDate.of(2007, month, dom); LocalDate expected = LocalDate.of(2012, 4 + ((month - 1) % 3), dom); - assertEquals(YearQuarter.of(2012, Q2).adjustInto(base), expected); + assertEquals(expected, YearQuarter.of(2012, Q2).adjustInto(base)); } } } @@ -677,14 +677,14 @@ public void test_adjustInto_Temporal() { public void test_adjustInto_Temporal_lastValidDay_nonLeap() { LocalDate base = LocalDate.of(2007, 5, 31); LocalDate expected = LocalDate.of(2011, 2, 28); - assertEquals(YearQuarter.of(2011, Q1).adjustInto(base), expected); + assertEquals(expected, YearQuarter.of(2011, Q1).adjustInto(base)); } @Test public void test_adjustInto_Temporal_lastValidDay_leap() { LocalDate base = LocalDate.of(2007, 5, 31); LocalDate expected = LocalDate.of(2012, 2, 29); - assertEquals(YearQuarter.of(2012, Q1).adjustInto(base), expected); + assertEquals(expected, YearQuarter.of(2012, Q1).adjustInto(base)); } @Test(expected = NullPointerException.class) @@ -697,35 +697,35 @@ public void test_adjustInto_Temporal_null() { //----------------------------------------------------------------------- @Test public void test_until_TemporalTemporalUnit_QUARTER_YEARS() { - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2011, Q4), QUARTER_YEARS), -2); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q1), QUARTER_YEARS), -1); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q2), QUARTER_YEARS), 0); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q3), QUARTER_YEARS), 1); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q4), QUARTER_YEARS), 2); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2013, Q1), QUARTER_YEARS), 3); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2013, Q2), QUARTER_YEARS), 4); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2013, Q3), QUARTER_YEARS), 5); + assertEquals(-2, YearQuarter.of(2012, Q2).until(YearQuarter.of(2011, Q4), QUARTER_YEARS)); + assertEquals(-1, YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q1), QUARTER_YEARS)); + assertEquals(0, YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q2), QUARTER_YEARS)); + assertEquals(1, YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q3), QUARTER_YEARS)); + assertEquals(2, YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q4), QUARTER_YEARS)); + assertEquals(3, YearQuarter.of(2012, Q2).until(YearQuarter.of(2013, Q1), QUARTER_YEARS)); + assertEquals(4, YearQuarter.of(2012, Q2).until(YearQuarter.of(2013, Q2), QUARTER_YEARS)); + assertEquals(5, YearQuarter.of(2012, Q2).until(YearQuarter.of(2013, Q3), QUARTER_YEARS)); } @Test public void test_until_TemporalTemporalUnit_YEARS() { - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2010, Q2), YEARS), -2); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2010, Q3), YEARS), -1); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2010, Q4), YEARS), -1); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2011, Q1), YEARS), -1); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2011, Q2), YEARS), -1); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2011, Q3), YEARS), 0); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2011, Q4), YEARS), 0); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q1), YEARS), 0); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q2), YEARS), 0); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q3), YEARS), 0); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q4), YEARS), 0); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2013, Q1), YEARS), 0); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2013, Q2), YEARS), 1); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2013, Q3), YEARS), 1); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2013, Q4), YEARS), 1); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2014, Q1), YEARS), 1); - assertEquals(YearQuarter.of(2012, Q2).until(YearQuarter.of(2014, Q2), YEARS), 2); + assertEquals(-2, YearQuarter.of(2012, Q2).until(YearQuarter.of(2010, Q2), YEARS)); + assertEquals(-1, YearQuarter.of(2012, Q2).until(YearQuarter.of(2010, Q3), YEARS)); + assertEquals(-1, YearQuarter.of(2012, Q2).until(YearQuarter.of(2010, Q4), YEARS)); + assertEquals(-1, YearQuarter.of(2012, Q2).until(YearQuarter.of(2011, Q1), YEARS)); + assertEquals(-1, YearQuarter.of(2012, Q2).until(YearQuarter.of(2011, Q2), YEARS)); + assertEquals(0, YearQuarter.of(2012, Q2).until(YearQuarter.of(2011, Q3), YEARS)); + assertEquals(0, YearQuarter.of(2012, Q2).until(YearQuarter.of(2011, Q4), YEARS)); + assertEquals(0, YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q1), YEARS)); + assertEquals(0, YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q2), YEARS)); + assertEquals(0, YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q3), YEARS)); + assertEquals(0, YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q4), YEARS)); + assertEquals(0, YearQuarter.of(2012, Q2).until(YearQuarter.of(2013, Q1), YEARS)); + assertEquals(1, YearQuarter.of(2012, Q2).until(YearQuarter.of(2013, Q2), YEARS)); + assertEquals(1, YearQuarter.of(2012, Q2).until(YearQuarter.of(2013, Q3), YEARS)); + assertEquals(1, YearQuarter.of(2012, Q2).until(YearQuarter.of(2013, Q4), YEARS)); + assertEquals(1, YearQuarter.of(2012, Q2).until(YearQuarter.of(2014, Q1), YEARS)); + assertEquals(2, YearQuarter.of(2012, Q2).until(YearQuarter.of(2014, Q2), YEARS)); } @Test(expected = NullPointerException.class) @@ -744,7 +744,7 @@ public void test_until_TemporalTemporalUnit_nullTemporalUnit() { @Test public void test_format() { DateTimeFormatter f = DateTimeFormatter.ofPattern("'Q'Q uuuu"); - assertEquals(YearQuarter.of(2012, Q1).format(f), "Q1 2012"); + assertEquals("Q1 2012", YearQuarter.of(2012, Q1).format(f)); } @Test(expected = NullPointerException.class) @@ -759,25 +759,25 @@ public void test_format_null() { public void test_atDay() { for (int i = 1; i <= 90; i++) { LocalDate expected = LocalDate.of(2012, 1, 1).plusDays(i - 1); - assertEquals(YearQuarter.of(2012, Q1).atDay(i), expected); + assertEquals(expected, YearQuarter.of(2012, Q1).atDay(i)); } for (int i = 1; i <= 91; i++) { LocalDate expected = LocalDate.of(2012, 4, 1).plusDays(i - 1); - assertEquals(YearQuarter.of(2012, Q2).atDay(i), expected); + assertEquals(expected, YearQuarter.of(2012, Q2).atDay(i)); } for (int i = 1; i <= 92; i++) { LocalDate expected = LocalDate.of(2012, 7, 1).plusDays(i - 1); - assertEquals(YearQuarter.of(2012, Q3).atDay(i), expected); + assertEquals(expected, YearQuarter.of(2012, Q3).atDay(i)); } for (int i = 1; i <= 92; i++) { LocalDate expected = LocalDate.of(2012, 10, 1).plusDays(i - 1); - assertEquals(YearQuarter.of(2012, Q4).atDay(i), expected); + assertEquals(expected, YearQuarter.of(2012, Q4).atDay(i)); } } @Test public void test_atDay_Q1_91_leap() { - assertEquals(YearQuarter.of(2012, Q1).atDay(91), LocalDate.of(2012, 3, 31)); + assertEquals(LocalDate.of(2012, 3, 31), YearQuarter.of(2012, Q1).atDay(91)); } @Test(expected = DateTimeException.class) @@ -810,15 +810,15 @@ public void test_atDay_tooHigh() { //----------------------------------------------------------------------- @Test public void test_atEndOfQuarter() { - assertEquals(YearQuarter.of(2011, Q1).atEndOfQuarter(), LocalDate.of(2011, 3, 31)); - assertEquals(YearQuarter.of(2011, Q2).atEndOfQuarter(), LocalDate.of(2011, 6, 30)); - assertEquals(YearQuarter.of(2011, Q3).atEndOfQuarter(), LocalDate.of(2011, 9, 30)); - assertEquals(YearQuarter.of(2011, Q4).atEndOfQuarter(), LocalDate.of(2011, 12, 31)); + assertEquals(LocalDate.of(2011, 3, 31), YearQuarter.of(2011, Q1).atEndOfQuarter()); + assertEquals(LocalDate.of(2011, 6, 30), YearQuarter.of(2011, Q2).atEndOfQuarter()); + assertEquals(LocalDate.of(2011, 9, 30), YearQuarter.of(2011, Q3).atEndOfQuarter()); + assertEquals(LocalDate.of(2011, 12, 31), YearQuarter.of(2011, Q4).atEndOfQuarter()); - assertEquals(YearQuarter.of(2012, Q1).atEndOfQuarter(), LocalDate.of(2012, 3, 31)); - assertEquals(YearQuarter.of(2012, Q2).atEndOfQuarter(), LocalDate.of(2012, 6, 30)); - assertEquals(YearQuarter.of(2012, Q3).atEndOfQuarter(), LocalDate.of(2012, 9, 30)); - assertEquals(YearQuarter.of(2012, Q4).atEndOfQuarter(), LocalDate.of(2012, 12, 31)); + assertEquals(LocalDate.of(2012, 3, 31), YearQuarter.of(2012, Q1).atEndOfQuarter()); + assertEquals(LocalDate.of(2012, 6, 30), YearQuarter.of(2012, Q2).atEndOfQuarter()); + assertEquals(LocalDate.of(2012, 9, 30), YearQuarter.of(2012, Q3).atEndOfQuarter()); + assertEquals(LocalDate.of(2012, 12, 31), YearQuarter.of(2012, Q4).atEndOfQuarter()); } //----------------------------------------------------------------------- @@ -833,41 +833,41 @@ public void test_compareTo() { for (Quarter quarter2 : Quarter.values()) { YearQuarter b = YearQuarter.of(year2, quarter2); if (year1 < year2) { - assertEquals(a.compareTo(b) < 0, true); - assertEquals(b.compareTo(a) > 0, true); - assertEquals(a.isAfter(b), false); - assertEquals(b.isBefore(a), false); - assertEquals(b.isAfter(a), true); - assertEquals(a.isBefore(b), true); + assertEquals(true, a.compareTo(b) < 0); + assertEquals(true, b.compareTo(a) > 0); + assertEquals(false, a.isAfter(b)); + assertEquals(false, b.isBefore(a)); + assertEquals(true, b.isAfter(a)); + assertEquals(true, a.isBefore(b)); } else if (year1 > year2) { - assertEquals(a.compareTo(b) > 0, true); - assertEquals(b.compareTo(a) < 0, true); - assertEquals(a.isAfter(b), true); - assertEquals(b.isBefore(a), true); - assertEquals(b.isAfter(a), false); - assertEquals(a.isBefore(b), false); + assertEquals(true, a.compareTo(b) > 0); + assertEquals(true, b.compareTo(a) < 0); + assertEquals(true, a.isAfter(b)); + assertEquals(true, b.isBefore(a)); + assertEquals(false, b.isAfter(a)); + assertEquals(false, a.isBefore(b)); } else { if (quarter1.getValue() < quarter2.getValue()) { - assertEquals(a.compareTo(b) < 0, true); - assertEquals(b.compareTo(a) > 0, true); - assertEquals(a.isAfter(b), false); - assertEquals(b.isBefore(a), false); - assertEquals(b.isAfter(a), true); - assertEquals(a.isBefore(b), true); + assertEquals(true, a.compareTo(b) < 0); + assertEquals(true, b.compareTo(a) > 0); + assertEquals(false, a.isAfter(b)); + assertEquals(false, b.isBefore(a)); + assertEquals(true, b.isAfter(a)); + assertEquals(true, a.isBefore(b)); } else if (quarter1.getValue() > quarter2.getValue()) { - assertEquals(a.compareTo(b) > 0, true); - assertEquals(b.compareTo(a) < 0, true); - assertEquals(a.isAfter(b), true); - assertEquals(b.isBefore(a), true); - assertEquals(b.isAfter(a), false); - assertEquals(a.isBefore(b), false); + assertEquals(true, a.compareTo(b) > 0); + assertEquals(true, b.compareTo(a) < 0); + assertEquals(true, a.isAfter(b)); + assertEquals(true, b.isBefore(a)); + assertEquals(false, b.isAfter(a)); + assertEquals(false, a.isBefore(b)); } else { - assertEquals(a.compareTo(b), 0); - assertEquals(b.compareTo(a), 0); - assertEquals(a.isAfter(b), false); - assertEquals(b.isBefore(a), false); - assertEquals(b.isAfter(a), false); - assertEquals(a.isBefore(b), false); + assertEquals(0, a.compareTo(b)); + assertEquals(0, b.compareTo(a)); + assertEquals(false, a.isAfter(b)); + assertEquals(false, b.isBefore(a)); + assertEquals(false, b.isAfter(a)); + assertEquals(false, a.isBefore(b)); } } } @@ -904,12 +904,12 @@ public void test_equals() { @Test public void test_equals_nullYearQuarter() { - assertEquals(TEST.equals(null), false); + assertEquals(false, TEST.equals(null)); } @Test public void test_equals_incorrectType() { - assertEquals(TEST.equals("Incorrect type"), false); + assertEquals(false, TEST.equals("Incorrect type")); } //----------------------------------------------------------------------- @@ -917,22 +917,22 @@ public void test_equals_incorrectType() { //----------------------------------------------------------------------- @Test public void test_toString() { - assertEquals(YearQuarter.of(2012, Q2).toString(), "2012-Q2"); + assertEquals("2012-Q2", YearQuarter.of(2012, Q2).toString()); } @Test public void test_toString_bigYear() { - assertEquals(YearQuarter.of(10000, Q2).toString(), "+10000-Q2"); + assertEquals("+10000-Q2", YearQuarter.of(10000, Q2).toString()); } @Test public void test_toString_negativeYear() { - assertEquals(YearQuarter.of(-1, Q2).toString(), "-0001-Q2"); + assertEquals("-0001-Q2", YearQuarter.of(-1, Q2).toString()); } @Test public void test_toString_negativeBigYear() { - assertEquals(YearQuarter.of(-10000, Q2).toString(), "-10000-Q2"); + assertEquals("-10000-Q2", YearQuarter.of(-10000, Q2).toString()); } } diff --git a/src/test/java/org/threeten/extra/TestYearWeek.java b/src/test/java/org/threeten/extra/TestYearWeek.java index 69b78a16..eefea936 100644 --- a/src/test/java/org/threeten/extra/TestYearWeek.java +++ b/src/test/java/org/threeten/extra/TestYearWeek.java @@ -307,7 +307,7 @@ public void test_serialization() throws IOException, ClassNotFoundException { } ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream( baos.toByteArray())); - assertEquals(ois.readObject(), test); + assertEquals(test, ois.readObject()); } //----------------------------------------------------------------------- @@ -324,7 +324,7 @@ public void test_now() { expected = YearWeek.now(Clock.systemDefaultZone()); test = YearWeek.now(); } - assertEquals(test, expected); + assertEquals(expected, test); } //----------------------------------------------------------------------- @@ -347,7 +347,7 @@ public void now_ZoneId() { expected = YearWeek.now(Clock.system(zone)); test = YearWeek.now(zone); } - assertEquals(test, expected); + assertEquals(expected, test); } //----------------------------------------------------------------------- @@ -358,8 +358,8 @@ public void now_Clock() { Instant instant = LocalDateTime.of(2010, 12, 31, 0, 0).toInstant(ZoneOffset.UTC); Clock clock = Clock.fixed(instant, ZoneOffset.UTC); YearWeek test = YearWeek.now(clock); - assertEquals(test.getYear(), 2010); - assertEquals(test.getWeek(), 52); + assertEquals(2010, test.getYear()); + assertEquals(52, test.getWeek()); } @Test(expected = NullPointerException.class) @@ -374,8 +374,8 @@ public void now_Clock_nullClock() { @UseDataProvider("data_sampleYearWeeks") public void test_of(int year, int week) { YearWeek yearWeek = YearWeek.of(year, week); - assertEquals(yearWeek.getYear(), year); - assertEquals(yearWeek.getWeek(), week); + assertEquals(year, yearWeek.getYear()); + assertEquals(week, yearWeek.getWeek()); } @Test @@ -408,41 +408,41 @@ public void test_of_invalidWeekValueZero() { //----------------------------------------------------------------------- @Test public void test_isSupported_TemporalField() { - assertEquals(TEST.isSupported((TemporalField) null), false); - assertEquals(TEST.isSupported(NANO_OF_SECOND), false); - assertEquals(TEST.isSupported(NANO_OF_DAY), false); - assertEquals(TEST.isSupported(MICRO_OF_SECOND), false); - assertEquals(TEST.isSupported(MICRO_OF_DAY), false); - assertEquals(TEST.isSupported(MILLI_OF_SECOND), false); - assertEquals(TEST.isSupported(MILLI_OF_DAY), false); - assertEquals(TEST.isSupported(SECOND_OF_MINUTE), false); - assertEquals(TEST.isSupported(SECOND_OF_DAY), false); - assertEquals(TEST.isSupported(MINUTE_OF_HOUR), false); - assertEquals(TEST.isSupported(MINUTE_OF_DAY), false); - assertEquals(TEST.isSupported(HOUR_OF_AMPM), false); - assertEquals(TEST.isSupported(CLOCK_HOUR_OF_AMPM), false); - assertEquals(TEST.isSupported(HOUR_OF_DAY), false); - assertEquals(TEST.isSupported(CLOCK_HOUR_OF_DAY), false); - assertEquals(TEST.isSupported(AMPM_OF_DAY), false); - assertEquals(TEST.isSupported(DAY_OF_WEEK), false); - assertEquals(TEST.isSupported(ALIGNED_DAY_OF_WEEK_IN_MONTH), false); - assertEquals(TEST.isSupported(ALIGNED_DAY_OF_WEEK_IN_YEAR), false); - assertEquals(TEST.isSupported(DAY_OF_MONTH), false); - assertEquals(TEST.isSupported(DAY_OF_YEAR), false); - assertEquals(TEST.isSupported(EPOCH_DAY), false); - assertEquals(TEST.isSupported(ALIGNED_WEEK_OF_MONTH), false); - assertEquals(TEST.isSupported(ALIGNED_WEEK_OF_YEAR), false); - assertEquals(TEST.isSupported(MONTH_OF_YEAR), false); - assertEquals(TEST.isSupported(PROLEPTIC_MONTH), false); - assertEquals(TEST.isSupported(YEAR_OF_ERA), false); - assertEquals(TEST.isSupported(YEAR), false); - assertEquals(TEST.isSupported(ERA), false); - assertEquals(TEST.isSupported(INSTANT_SECONDS), false); - assertEquals(TEST.isSupported(OFFSET_SECONDS), false); - assertEquals(TEST.isSupported(QUARTER_OF_YEAR), false); - assertEquals(TEST.isSupported(DAY_OF_QUARTER), false); - assertEquals(TEST.isSupported(WEEK_BASED_YEAR), true); - assertEquals(TEST.isSupported(WEEK_OF_WEEK_BASED_YEAR), true); + assertEquals(false, TEST.isSupported((TemporalField) null)); + assertEquals(false, TEST.isSupported(NANO_OF_SECOND)); + assertEquals(false, TEST.isSupported(NANO_OF_DAY)); + assertEquals(false, TEST.isSupported(MICRO_OF_SECOND)); + assertEquals(false, TEST.isSupported(MICRO_OF_DAY)); + assertEquals(false, TEST.isSupported(MILLI_OF_SECOND)); + assertEquals(false, TEST.isSupported(MILLI_OF_DAY)); + assertEquals(false, TEST.isSupported(SECOND_OF_MINUTE)); + assertEquals(false, TEST.isSupported(SECOND_OF_DAY)); + assertEquals(false, TEST.isSupported(MINUTE_OF_HOUR)); + assertEquals(false, TEST.isSupported(MINUTE_OF_DAY)); + assertEquals(false, TEST.isSupported(HOUR_OF_AMPM)); + assertEquals(false, TEST.isSupported(CLOCK_HOUR_OF_AMPM)); + assertEquals(false, TEST.isSupported(HOUR_OF_DAY)); + assertEquals(false, TEST.isSupported(CLOCK_HOUR_OF_DAY)); + assertEquals(false, TEST.isSupported(AMPM_OF_DAY)); + assertEquals(false, TEST.isSupported(DAY_OF_WEEK)); + assertEquals(false, TEST.isSupported(ALIGNED_DAY_OF_WEEK_IN_MONTH)); + assertEquals(false, TEST.isSupported(ALIGNED_DAY_OF_WEEK_IN_YEAR)); + assertEquals(false, TEST.isSupported(DAY_OF_MONTH)); + assertEquals(false, TEST.isSupported(DAY_OF_YEAR)); + assertEquals(false, TEST.isSupported(EPOCH_DAY)); + assertEquals(false, TEST.isSupported(ALIGNED_WEEK_OF_MONTH)); + assertEquals(false, TEST.isSupported(ALIGNED_WEEK_OF_YEAR)); + assertEquals(false, TEST.isSupported(MONTH_OF_YEAR)); + assertEquals(false, TEST.isSupported(PROLEPTIC_MONTH)); + assertEquals(false, TEST.isSupported(YEAR_OF_ERA)); + assertEquals(false, TEST.isSupported(YEAR)); + assertEquals(false, TEST.isSupported(ERA)); + assertEquals(false, TEST.isSupported(INSTANT_SECONDS)); + assertEquals(false, TEST.isSupported(OFFSET_SECONDS)); + assertEquals(false, TEST.isSupported(QUARTER_OF_YEAR)); + assertEquals(false, TEST.isSupported(DAY_OF_QUARTER)); + assertEquals(true, TEST.isSupported(WEEK_BASED_YEAR)); + assertEquals(true, TEST.isSupported(WEEK_OF_WEEK_BASED_YEAR)); } //----------------------------------------------------------------------- @@ -454,7 +454,7 @@ public void test_atDay(int weekBasedYear, int weekOfWeekBasedYear, DayOfWeek day YearWeek yearWeek = YearWeek.of(weekBasedYear, weekOfWeekBasedYear); LocalDate expected = LocalDate.of(year, month, dayOfMonth); LocalDate actual = yearWeek.atDay(dayOfWeek); - assertEquals(actual, expected); + assertEquals(expected, actual); } @Test @@ -465,7 +465,7 @@ public void test_atDay_loop20years() { for (int j = 1; j <= 7; j++) { DayOfWeek dow = DayOfWeek.of(j); LocalDate actual = yearWeek.atDay(dow); - assertEquals(actual, expected); + assertEquals(expected, actual); expected = expected.plusDays(1); } yearWeek = yearWeek.plusWeeks(1); @@ -499,41 +499,41 @@ public void test_compareTo() { for (int week2 = 1; week2 < 53; week2++) { YearWeek b = YearWeek.of(year2, week2); if (year1 < year2) { - assertEquals(a.compareTo(b) < 0, true); - assertEquals(b.compareTo(a) > 0, true); - assertEquals(a.isAfter(b), false); - assertEquals(b.isBefore(a), false); - assertEquals(b.isAfter(a), true); - assertEquals(a.isBefore(b), true); + assertEquals(true, a.compareTo(b) < 0); + assertEquals(true, b.compareTo(a) > 0); + assertEquals(false, a.isAfter(b)); + assertEquals(false, b.isBefore(a)); + assertEquals(true, b.isAfter(a)); + assertEquals(true, a.isBefore(b)); } else if (year1 > year2) { - assertEquals(a.compareTo(b) > 0, true); - assertEquals(b.compareTo(a) < 0, true); - assertEquals(a.isAfter(b), true); - assertEquals(b.isBefore(a), true); - assertEquals(b.isAfter(a), false); - assertEquals(a.isBefore(b), false); + assertEquals(true, a.compareTo(b) > 0); + assertEquals(true, b.compareTo(a) < 0); + assertEquals(true, a.isAfter(b)); + assertEquals(true, b.isBefore(a)); + assertEquals(false, b.isAfter(a)); + assertEquals(false, a.isBefore(b)); } else { if (week1 < week2) { - assertEquals(a.compareTo(b) < 0, true); - assertEquals(b.compareTo(a) > 0, true); - assertEquals(a.isAfter(b), false); - assertEquals(b.isBefore(a), false); - assertEquals(b.isAfter(a), true); - assertEquals(a.isBefore(b), true); + assertEquals(true, a.compareTo(b) < 0); + assertEquals(true, b.compareTo(a) > 0); + assertEquals(false, a.isAfter(b)); + assertEquals(false, b.isBefore(a)); + assertEquals(true, b.isAfter(a)); + assertEquals(true, a.isBefore(b)); } else if (week1 > week2) { - assertEquals(a.compareTo(b) > 0, true); - assertEquals(b.compareTo(a) < 0, true); - assertEquals(a.isAfter(b), true); - assertEquals(b.isBefore(a), true); - assertEquals(b.isAfter(a), false); - assertEquals(a.isBefore(b), false); + assertEquals(true, a.compareTo(b) > 0); + assertEquals(true, b.compareTo(a) < 0); + assertEquals(true, a.isAfter(b)); + assertEquals(true, b.isBefore(a)); + assertEquals(false, b.isAfter(a)); + assertEquals(false, a.isBefore(b)); } else { - assertEquals(a.compareTo(b), 0); - assertEquals(b.compareTo(a), 0); - assertEquals(a.isAfter(b), false); - assertEquals(b.isBefore(a), false); - assertEquals(b.isAfter(a), false); - assertEquals(a.isBefore(b), false); + assertEquals(0, a.compareTo(b)); + assertEquals(0, b.compareTo(a)); + assertEquals(false, a.isAfter(b)); + assertEquals(false, b.isBefore(a)); + assertEquals(false, b.isAfter(a)); + assertEquals(false, a.isBefore(b)); } } } @@ -555,9 +555,9 @@ public void test_compareTo_nullYearWeek() { public void test_from(int weekBasedYear, int weekOfWeekBasedYear, DayOfWeek dayOfWeek, int year, int month, int dayOfMonth) { YearWeek expected = YearWeek.of(weekBasedYear, weekOfWeekBasedYear); LocalDate ld = LocalDate.of(year, month, dayOfMonth); - assertEquals(YearWeek.from(ld), expected); - assertEquals(YearWeek.from(ThaiBuddhistDate.from(ld)), expected); - assertEquals(YearWeek.from(expected), expected); + assertEquals(expected, YearWeek.from(ld)); + assertEquals(expected, YearWeek.from(ThaiBuddhistDate.from(ld))); + assertEquals(expected, YearWeek.from(expected)); } @Test(expected = DateTimeException.class) @@ -575,8 +575,8 @@ public void test_from_TemporalAccessor_null() { //----------------------------------------------------------------------- @Test public void test_get() { - assertEquals(TEST.get(WEEK_BASED_YEAR), 2015); - assertEquals(TEST.get(WEEK_OF_WEEK_BASED_YEAR), 1); + assertEquals(2015, TEST.get(WEEK_BASED_YEAR)); + assertEquals(1, TEST.get(WEEK_OF_WEEK_BASED_YEAR)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -594,8 +594,8 @@ public void test_get_null() { //----------------------------------------------------------------------- @Test public void test_getLong() { - assertEquals(TEST.getLong(WEEK_BASED_YEAR), 2015L); - assertEquals(TEST.getLong(WEEK_OF_WEEK_BASED_YEAR), 1L); + assertEquals(2015L, TEST.getLong(WEEK_BASED_YEAR)); + assertEquals(1L, TEST.getLong(WEEK_OF_WEEK_BASED_YEAR)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -613,8 +613,8 @@ public void test_getLong_null() { //----------------------------------------------------------------------- @Test public void test_lengthOfYear() { - assertEquals(YearWeek.of(2014, 1).lengthOfYear(), 364); - assertEquals(YearWeek.of(2015, 1).lengthOfYear(), 371); + assertEquals(364, YearWeek.of(2014, 1).lengthOfYear()); + assertEquals(371, YearWeek.of(2015, 1).lengthOfYear()); } //----------------------------------------------------------------------- @@ -622,7 +622,7 @@ public void test_lengthOfYear() { //----------------------------------------------------------------------- @Test public void test_toString() { - assertEquals(TEST.toString(), "2015-W01"); + assertEquals("2015-W01", TEST.toString()); } //----------------------------------------------------------------------- @@ -630,7 +630,7 @@ public void test_toString() { //----------------------------------------------------------------------- @Test public void test_parse_CharSequence() { - assertEquals(YearWeek.parse("2015-W01"), TEST); + assertEquals(TEST, YearWeek.parse("2015-W01")); } @Test(expected = DateTimeParseException.class) @@ -654,7 +654,7 @@ public void test_parse_CharSequenceDate_nullCharSequence() { @Test public void test_parse_CharSequenceDateTimeFormatter() { DateTimeFormatter f = DateTimeFormatter.ofPattern("E 'W'w YYYY").withLocale(Locale.ENGLISH); - assertEquals(YearWeek.parse("Mon W1 2015", f), TEST); + assertEquals(TEST, YearWeek.parse("Mon W1 2015", f)); } @Test(expected = DateTimeParseException.class) @@ -684,7 +684,7 @@ public void test_format() { .appendLiteral('-') .appendValue(WEEK_OF_WEEK_BASED_YEAR, 2) .toFormatter(); - assertEquals(TEST.format(f), "2015-01"); + assertEquals("2015-01", TEST.format(f)); } //----------------------------------------------------------------------- @@ -694,7 +694,7 @@ public void test_format() { public void test_adjustInto() { YearWeek yw = YearWeek.of(2016, 1); LocalDate date = LocalDate.of(2015, 6, 20); - assertEquals(yw.adjustInto(date), LocalDate.of(2016, 1, 9)); + assertEquals(LocalDate.of(2016, 1, 9), yw.adjustInto(date)); } @Test(expected = DateTimeException.class) @@ -709,11 +709,11 @@ public void test_adjustInto_badChronology() { //----------------------------------------------------------------------- @Test public void test_range() { - assertEquals(TEST_NON_LEAP.range(WEEK_BASED_YEAR), WEEK_BASED_YEAR.range()); - assertEquals(TEST.range(WEEK_BASED_YEAR), WEEK_BASED_YEAR.range()); + assertEquals(WEEK_BASED_YEAR.range(), TEST_NON_LEAP.range(WEEK_BASED_YEAR)); + assertEquals(WEEK_BASED_YEAR.range(), TEST.range(WEEK_BASED_YEAR)); - assertEquals(TEST_NON_LEAP.range(WEEK_OF_WEEK_BASED_YEAR), ValueRange.of(1, 52)); - assertEquals(TEST.range(WEEK_OF_WEEK_BASED_YEAR), ValueRange.of(1, 53)); + assertEquals(ValueRange.of(1, 52), TEST_NON_LEAP.range(WEEK_OF_WEEK_BASED_YEAR)); + assertEquals(ValueRange.of(1, 53), TEST.range(WEEK_OF_WEEK_BASED_YEAR)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -731,18 +731,18 @@ public void test_range_null() { //----------------------------------------------------------------------- @Test public void test_withYear() { - assertEquals(YearWeek.of(2015, 1).withYear(2014), YearWeek.of(2014, 1)); - assertEquals(YearWeek.of(2015, 53).withYear(2009), YearWeek.of(2009, 53)); + assertEquals(YearWeek.of(2014, 1), YearWeek.of(2015, 1).withYear(2014)); + assertEquals(YearWeek.of(2009, 53), YearWeek.of(2015, 53).withYear(2009)); } @Test public void test_withYear_sameYear() { - assertEquals(YearWeek.of(2015, 1).withYear(2015), YearWeek.of(2015, 1)); + assertEquals(YearWeek.of(2015, 1), YearWeek.of(2015, 1).withYear(2015)); } @Test public void test_withYear_resolve() { - assertEquals(YearWeek.of(2015, 53).withYear(2014), YearWeek.of(2014, 52)); + assertEquals(YearWeek.of(2014, 52), YearWeek.of(2015, 53).withYear(2014)); } @Test(expected = DateTimeException.class) @@ -760,13 +760,13 @@ public void test_withYear_int_min() { //----------------------------------------------------------------------- @Test public void test_withWeek() { - assertEquals(TEST.withWeek(52), YearWeek.of(2015, 52)); - assertEquals(YearWeek.of(2014, 1).withWeek(53), TEST); + assertEquals(YearWeek.of(2015, 52), TEST.withWeek(52)); + assertEquals(TEST, YearWeek.of(2014, 1).withWeek(53)); } @Test public void test_withWeek_sameWeek() { - assertEquals(YearWeek.of(2014, 2).withWeek(2), YearWeek.of(2014, 2)); + assertEquals(YearWeek.of(2014, 2), YearWeek.of(2014, 2).withWeek(2)); } @Test(expected = DateTimeException.class) @@ -784,19 +784,19 @@ public void test_withWeek_int_min() { //----------------------------------------------------------------------- @Test public void test_plusYears() { - assertEquals(TEST.plusYears(-2), YearWeek.of(2013, 1)); - assertEquals(TEST.plusYears(-1), YearWeek.of(2014, 1)); - assertEquals(TEST.plusYears(0), TEST); - assertEquals(TEST.plusYears(1), YearWeek.of(2016, 1)); - assertEquals(TEST.plusYears(2), YearWeek.of(2017, 1)); + assertEquals(YearWeek.of(2013, 1), TEST.plusYears(-2)); + assertEquals(YearWeek.of(2014, 1), TEST.plusYears(-1)); + assertEquals(TEST, TEST.plusYears(0)); + assertEquals(YearWeek.of(2016, 1), TEST.plusYears(1)); + assertEquals(YearWeek.of(2017, 1), TEST.plusYears(2)); } @Test public void test_plusYears_changeWeek() { - assertEquals(YearWeek.of(2015, 53).plusYears(-1), YearWeek.of(2014, 52)); - assertEquals(YearWeek.of(2015, 53).plusYears(0), YearWeek.of(2015, 53)); - assertEquals(YearWeek.of(2015, 53).plusYears(1), YearWeek.of(2016, 52)); - assertEquals(YearWeek.of(2015, 53).plusYears(5), YearWeek.of(2020, 53)); + assertEquals(YearWeek.of(2014, 52), YearWeek.of(2015, 53).plusYears(-1)); + assertEquals(YearWeek.of(2015, 53), YearWeek.of(2015, 53).plusYears(0)); + assertEquals(YearWeek.of(2016, 52), YearWeek.of(2015, 53).plusYears(1)); + assertEquals(YearWeek.of(2020, 53), YearWeek.of(2015, 53).plusYears(5)); } @Test(expected = ArithmeticException.class) @@ -814,24 +814,24 @@ public void test_plusYears_min_long() { //----------------------------------------------------------------------- @Test public void test_plusWeeks() { - assertEquals(TEST.plusWeeks(0), TEST); - assertEquals(TEST.plusWeeks(1), YearWeek.of(2015, 2)); - assertEquals(TEST.plusWeeks(2), YearWeek.of(2015, 3)); - assertEquals(TEST.plusWeeks(51), YearWeek.of(2015, 52)); - assertEquals(TEST.plusWeeks(52), YearWeek.of(2015, 53)); - assertEquals(TEST.plusWeeks(53), YearWeek.of(2016, 1)); - assertEquals(TEST.plusWeeks(314), YearWeek.of(2021, 1)); + assertEquals(TEST, TEST.plusWeeks(0)); + assertEquals(YearWeek.of(2015, 2), TEST.plusWeeks(1)); + assertEquals(YearWeek.of(2015, 3), TEST.plusWeeks(2)); + assertEquals(YearWeek.of(2015, 52), TEST.plusWeeks(51)); + assertEquals(YearWeek.of(2015, 53), TEST.plusWeeks(52)); + assertEquals(YearWeek.of(2016, 1), TEST.plusWeeks(53)); + assertEquals(YearWeek.of(2021, 1), TEST.plusWeeks(314)); } @Test public void test_plusWeeks_negative() { - assertEquals(TEST.plusWeeks(0), TEST); - assertEquals(TEST.plusWeeks(-1), YearWeek.of(2014, 52)); - assertEquals(TEST.plusWeeks(-2), YearWeek.of(2014, 51)); - assertEquals(TEST.plusWeeks(-51), YearWeek.of(2014, 2)); - assertEquals(TEST.plusWeeks(-52), YearWeek.of(2014, 1)); - assertEquals(TEST.plusWeeks(-53), YearWeek.of(2013, 52)); - assertEquals(TEST.plusWeeks(-261), YearWeek.of(2009, 53)); + assertEquals(TEST, TEST.plusWeeks(0)); + assertEquals(YearWeek.of(2014, 52), TEST.plusWeeks(-1)); + assertEquals(YearWeek.of(2014, 51), TEST.plusWeeks(-2)); + assertEquals(YearWeek.of(2014, 2), TEST.plusWeeks(-51)); + assertEquals(YearWeek.of(2014, 1), TEST.plusWeeks(-52)); + assertEquals(YearWeek.of(2013, 52), TEST.plusWeeks(-53)); + assertEquals(YearWeek.of(2009, 53), TEST.plusWeeks(-261)); } @Test(expected = ArithmeticException.class) @@ -849,19 +849,19 @@ public void test_plusWeeks_min_long() { //----------------------------------------------------------------------- @Test public void test_minusYears() { - assertEquals(TEST.minusYears(-2), YearWeek.of(2017, 1)); - assertEquals(TEST.minusYears(-1), YearWeek.of(2016, 1)); - assertEquals(TEST.minusYears(0), TEST); - assertEquals(TEST.minusYears(1), YearWeek.of(2014, 1)); - assertEquals(TEST.minusYears(2), YearWeek.of(2013, 1)); + assertEquals(YearWeek.of(2017, 1), TEST.minusYears(-2)); + assertEquals(YearWeek.of(2016, 1), TEST.minusYears(-1)); + assertEquals(TEST, TEST.minusYears(0)); + assertEquals(YearWeek.of(2014, 1), TEST.minusYears(1)); + assertEquals(YearWeek.of(2013, 1), TEST.minusYears(2)); } @Test public void test_minusYears_changeWeek() { - assertEquals(YearWeek.of(2015, 53).minusYears(-5), YearWeek.of(2020, 53)); - assertEquals(YearWeek.of(2015, 53).minusYears(-1), YearWeek.of(2016, 52)); - assertEquals(YearWeek.of(2015, 53).minusYears(0), YearWeek.of(2015, 53)); - assertEquals(YearWeek.of(2015, 53).minusYears(1), YearWeek.of(2014, 52)); + assertEquals(YearWeek.of(2020, 53), YearWeek.of(2015, 53).minusYears(-5)); + assertEquals(YearWeek.of(2016, 52), YearWeek.of(2015, 53).minusYears(-1)); + assertEquals(YearWeek.of(2015, 53), YearWeek.of(2015, 53).minusYears(0)); + assertEquals(YearWeek.of(2014, 52), YearWeek.of(2015, 53).minusYears(1)); } @Test(expected = ArithmeticException.class) @@ -879,24 +879,24 @@ public void test_minusYears_min_long() { //----------------------------------------------------------------------- @Test public void test_minusWeeks() { - assertEquals(TEST.minusWeeks(0), TEST); - assertEquals(TEST.minusWeeks(1), YearWeek.of(2014, 52)); - assertEquals(TEST.minusWeeks(2), YearWeek.of(2014, 51)); - assertEquals(TEST.minusWeeks(51), YearWeek.of(2014, 2)); - assertEquals(TEST.minusWeeks(52), YearWeek.of(2014, 1)); - assertEquals(TEST.minusWeeks(53), YearWeek.of(2013, 52)); - assertEquals(TEST.minusWeeks(261), YearWeek.of(2009, 53)); + assertEquals(TEST, TEST.minusWeeks(0)); + assertEquals(YearWeek.of(2014, 52), TEST.minusWeeks(1)); + assertEquals(YearWeek.of(2014, 51), TEST.minusWeeks(2)); + assertEquals(YearWeek.of(2014, 2), TEST.minusWeeks(51)); + assertEquals(YearWeek.of(2014, 1), TEST.minusWeeks(52)); + assertEquals(YearWeek.of(2013, 52), TEST.minusWeeks(53)); + assertEquals(YearWeek.of(2009, 53), TEST.minusWeeks(261)); } @Test public void test_minusWeeks_negative() { - assertEquals(TEST.minusWeeks(0), TEST); - assertEquals(TEST.minusWeeks(-1), YearWeek.of(2015, 2)); - assertEquals(TEST.minusWeeks(-2), YearWeek.of(2015, 3)); - assertEquals(TEST.minusWeeks(-51), YearWeek.of(2015, 52)); - assertEquals(TEST.minusWeeks(-52), YearWeek.of(2015, 53)); - assertEquals(TEST.minusWeeks(-53), YearWeek.of(2016, 1)); - assertEquals(TEST.minusWeeks(-314), YearWeek.of(2021, 1)); + assertEquals(TEST, TEST.minusWeeks(0)); + assertEquals(YearWeek.of(2015, 2), TEST.minusWeeks(-1)); + assertEquals(YearWeek.of(2015, 3), TEST.minusWeeks(-2)); + assertEquals(YearWeek.of(2015, 52), TEST.minusWeeks(-51)); + assertEquals(YearWeek.of(2015, 53), TEST.minusWeeks(-52)); + assertEquals(YearWeek.of(2016, 1), TEST.minusWeeks(-53)); + assertEquals(YearWeek.of(2021, 1), TEST.minusWeeks(-314)); } @Test(expected = ArithmeticException.class) @@ -914,13 +914,13 @@ public void test_minWeeks_min_long() { //----------------------------------------------------------------------- @Test public void test_query() { - assertEquals(TEST.query(TemporalQueries.chronology()), IsoChronology.INSTANCE); - assertEquals(TEST.query(TemporalQueries.localDate()), null); - assertEquals(TEST.query(TemporalQueries.localTime()), null); - assertEquals(TEST.query(TemporalQueries.offset()), null); - assertEquals(TEST.query(TemporalQueries.precision()), null); - assertEquals(TEST.query(TemporalQueries.zone()), null); - assertEquals(TEST.query(TemporalQueries.zoneId()), null); + assertEquals(IsoChronology.INSTANCE, TEST.query(TemporalQueries.chronology())); + assertEquals(null, TEST.query(TemporalQueries.localDate())); + assertEquals(null, TEST.query(TemporalQueries.localTime())); + assertEquals(null, TEST.query(TemporalQueries.offset())); + assertEquals(null, TEST.query(TemporalQueries.precision())); + assertEquals(null, TEST.query(TemporalQueries.zone())); + assertEquals(null, TEST.query(TemporalQueries.zoneId())); } //----------------------------------------------------------------------- @@ -952,7 +952,7 @@ public void test_equals() { @Test public void test_equals_incorrectType() { assertTrue(TEST.equals(null) == false); - assertEquals(TEST.equals("Incorrect type"), false); + assertEquals(false, TEST.equals("Incorrect type")); } //----------------------------------------------------------------------- @@ -974,7 +974,7 @@ public static Object[][] data_sampleToString() { public void test_toString(int year, int week, String expected) { YearWeek yearWeek = YearWeek.of(year, week); String s = yearWeek.toString(); - assertEquals(s, expected); + assertEquals(expected, s); } } diff --git a/src/test/java/org/threeten/extra/TestYears.java b/src/test/java/org/threeten/extra/TestYears.java index a342983c..50c68d68 100644 --- a/src/test/java/org/threeten/extra/TestYears.java +++ b/src/test/java/org/threeten/extra/TestYears.java @@ -83,51 +83,51 @@ public void test_deserializationSingleton() throws Exception { public void test_ZERO() { assertSame(Years.of(0), Years.ZERO); assertSame(Years.of(0), Years.ZERO); - assertEquals(Years.ZERO.getAmount(), 0); + assertEquals(0, Years.ZERO.getAmount()); } @Test public void test_ONE() { assertSame(Years.of(1), Years.ONE); assertSame(Years.of(1), Years.ONE); - assertEquals(Years.ONE.getAmount(), 1); + assertEquals(1, Years.ONE.getAmount()); } //----------------------------------------------------------------------- @Test public void test_of() { - assertEquals(Years.of(1).getAmount(), 1); - assertEquals(Years.of(2).getAmount(), 2); - assertEquals(Years.of(Integer.MAX_VALUE).getAmount(), Integer.MAX_VALUE); - assertEquals(Years.of(-1).getAmount(), -1); - assertEquals(Years.of(-2).getAmount(), -2); - assertEquals(Years.of(Integer.MIN_VALUE).getAmount(), Integer.MIN_VALUE); + assertEquals(1, Years.of(1).getAmount()); + assertEquals(2, Years.of(2).getAmount()); + assertEquals(Integer.MAX_VALUE, Years.of(Integer.MAX_VALUE).getAmount()); + assertEquals(-1, Years.of(-1).getAmount()); + assertEquals(-2, Years.of(-2).getAmount()); + assertEquals(Integer.MIN_VALUE, Years.of(Integer.MIN_VALUE).getAmount()); } //----------------------------------------------------------------------- @Test public void test_from_P0Y() { - assertEquals(Years.from(Period.ofYears(0)), Years.of(0)); + assertEquals(Years.of(0), Years.from(Period.ofYears(0))); } @Test public void test_from_P2Y() { - assertEquals(Years.from(Period.ofYears(2)), Years.of(2)); + assertEquals(Years.of(2), Years.from(Period.ofYears(2))); } @Test public void test_from_P24M() { - assertEquals(Years.from(Period.ofMonths(24)), Years.of(2)); + assertEquals(Years.of(2), Years.from(Period.ofMonths(24))); } @Test public void test_from_yearsAndMonths() { - assertEquals(Years.from(Period.of(3, 24, 0)), Years.of(5)); + assertEquals(Years.of(5), Years.from(Period.of(3, 24, 0))); } @Test public void test_from_decadesAndMonths() { - assertEquals(Years.from(new MockDecadesMonths(2, -12)), Years.of(19)); + assertEquals(Years.of(19), Years.from(new MockDecadesMonths(2, -12))); } @Test(expected = DateTimeException.class) @@ -148,13 +148,13 @@ public void test_from_null() { //----------------------------------------------------------------------- @Test public void test_parse_CharSequence() { - assertEquals(Years.parse("P0Y"), Years.of(0)); - assertEquals(Years.parse("P1Y"), Years.of(1)); - assertEquals(Years.parse("P2Y"), Years.of(2)); - assertEquals(Years.parse("P123456789Y"), Years.of(123456789)); - assertEquals(Years.parse("P-2Y"), Years.of(-2)); - assertEquals(Years.parse("-P2Y"), Years.of(-2)); - assertEquals(Years.parse("-P-2Y"), Years.of(2)); + assertEquals(Years.of(0), Years.parse("P0Y")); + assertEquals(Years.of(1), Years.parse("P1Y")); + assertEquals(Years.of(2), Years.parse("P2Y")); + assertEquals(Years.of(123456789), Years.parse("P123456789Y")); + assertEquals(Years.of(-2), Years.parse("P-2Y")); + assertEquals(Years.of(-2), Years.parse("-P2Y")); + assertEquals(Years.of(2), Years.parse("-P-2Y")); } @DataProvider @@ -403,7 +403,7 @@ public void test_abs_overflow() { @Test public void test_toPeriod() { for (int i = -20; i < 20; i++) { - assertEquals(Years.of(i).toPeriod(), Period.ofYears(i)); + assertEquals(Period.ofYears(i), Years.of(i).toPeriod()); } } diff --git a/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java b/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java index 4e85f4af..6a9928c9 100644 --- a/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java @@ -54,6 +54,7 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.time.DateTimeException; import java.time.DayOfWeek; @@ -94,12 +95,12 @@ public class TestAccountingChronology { //----------------------------------------------------------------------- @Test public void test_chronology_of_name() { - Assert.assertEquals(INSTANCE.getId(), "Accounting"); + Assert.assertEquals("Accounting", INSTANCE.getId()); } @Test public void test_chronology_of_name_id() { - Assert.assertEquals(INSTANCE.getCalendarType(), null); + Assert.assertEquals(null, INSTANCE.getCalendarType()); } //----------------------------------------------------------------------- @@ -144,78 +145,78 @@ public static Object[][] data_samples() { @Test @UseDataProvider("data_samples") public void test_LocalDate_from_AccountingDate(AccountingDate accounting, LocalDate iso) { - assertEquals(LocalDate.from(accounting), iso); + assertEquals(iso, LocalDate.from(accounting)); } @Test @UseDataProvider("data_samples") public void test_AccountingDate_from_LocalDate(AccountingDate accounting, LocalDate iso) { - assertEquals(AccountingDate.from(INSTANCE, iso), accounting); + assertEquals(accounting, AccountingDate.from(INSTANCE, iso)); } @Test @UseDataProvider("data_samples") public void test_AccountingDate_chronology_dateEpochDay(AccountingDate accounting, LocalDate iso) { - assertEquals(INSTANCE.dateEpochDay(iso.toEpochDay()), accounting); + assertEquals(accounting, INSTANCE.dateEpochDay(iso.toEpochDay())); } @Test @UseDataProvider("data_samples") public void test_AccountingDate_toEpochDay(AccountingDate accounting, LocalDate iso) { - assertEquals(accounting.toEpochDay(), iso.toEpochDay()); + assertEquals(iso.toEpochDay(), accounting.toEpochDay()); } @Test @UseDataProvider("data_samples") public void test_AccountingDate_until_CoptiDate(AccountingDate accounting, LocalDate iso) { - assertEquals(accounting.until(accounting), INSTANCE.period(0, 0, 0)); + assertEquals(INSTANCE.period(0, 0, 0), accounting.until(accounting)); } @Test @UseDataProvider("data_samples") public void test_AccountingDate_until_LocalDate(AccountingDate accounting, LocalDate iso) { - assertEquals(accounting.until(iso), INSTANCE.period(0, 0, 0)); + assertEquals(INSTANCE.period(0, 0, 0), accounting.until(iso)); } @Test @UseDataProvider("data_samples") public void test_LocalDate_until_CoptiDate(AccountingDate accounting, LocalDate iso) { - assertEquals(iso.until(accounting), Period.ZERO); + assertEquals(Period.ZERO, iso.until(accounting)); } @Test @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(AccountingDate accounting, LocalDate iso) { - assertEquals(INSTANCE.date(iso), accounting); + assertEquals(accounting, INSTANCE.date(iso)); } @Test @UseDataProvider("data_samples") public void test_plusDays(AccountingDate accounting, LocalDate iso) { - assertEquals(LocalDate.from(accounting.plus(0, DAYS)), iso); - assertEquals(LocalDate.from(accounting.plus(1, DAYS)), iso.plusDays(1)); - assertEquals(LocalDate.from(accounting.plus(35, DAYS)), iso.plusDays(35)); - assertEquals(LocalDate.from(accounting.plus(-1, DAYS)), iso.plusDays(-1)); - assertEquals(LocalDate.from(accounting.plus(-60, DAYS)), iso.plusDays(-60)); + assertEquals(iso, LocalDate.from(accounting.plus(0, DAYS))); + assertEquals(iso.plusDays(1), LocalDate.from(accounting.plus(1, DAYS))); + assertEquals(iso.plusDays(35), LocalDate.from(accounting.plus(35, DAYS))); + assertEquals(iso.plusDays(-1), LocalDate.from(accounting.plus(-1, DAYS))); + assertEquals(iso.plusDays(-60), LocalDate.from(accounting.plus(-60, DAYS))); } @Test @UseDataProvider("data_samples") public void test_minusDays(AccountingDate accounting, LocalDate iso) { - assertEquals(LocalDate.from(accounting.minus(0, DAYS)), iso); - assertEquals(LocalDate.from(accounting.minus(1, DAYS)), iso.minusDays(1)); - assertEquals(LocalDate.from(accounting.minus(35, DAYS)), iso.minusDays(35)); - assertEquals(LocalDate.from(accounting.minus(-1, DAYS)), iso.minusDays(-1)); - assertEquals(LocalDate.from(accounting.minus(-60, DAYS)), iso.minusDays(-60)); + assertEquals(iso, LocalDate.from(accounting.minus(0, DAYS))); + assertEquals(iso.minusDays(1), LocalDate.from(accounting.minus(1, DAYS))); + assertEquals(iso.minusDays(35), LocalDate.from(accounting.minus(35, DAYS))); + assertEquals(iso.minusDays(-1), LocalDate.from(accounting.minus(-1, DAYS))); + assertEquals(iso.minusDays(-60), LocalDate.from(accounting.minus(-60, DAYS))); } @Test @UseDataProvider("data_samples") public void test_until_DAYS(AccountingDate accounting, LocalDate iso) { - assertEquals(accounting.until(iso.plusDays(0), DAYS), 0); - assertEquals(accounting.until(iso.plusDays(1), DAYS), 1); - assertEquals(accounting.until(iso.plusDays(35), DAYS), 35); - assertEquals(accounting.until(iso.minusDays(40), DAYS), -40); + assertEquals(0, accounting.until(iso.plusDays(0), DAYS)); + assertEquals(1, accounting.until(iso.plusDays(1), DAYS)); + assertEquals(35, accounting.until(iso.plusDays(35), DAYS)); + assertEquals(-40, accounting.until(iso.minusDays(40), DAYS)); } @DataProvider @@ -314,28 +315,28 @@ public void test_isLeapYear_loop() { }; for (int year = -200; year < 200; year++) { AccountingDate base = INSTANCE.date(year, 1, 1); - assertEquals(base.isLeapYear(), isLeapYear.test(year)); - assertEquals(INSTANCE.isLeapYear(year), isLeapYear.test(year)); + assertEquals(isLeapYear.test(year), base.isLeapYear()); + assertEquals(isLeapYear.test(year), INSTANCE.isLeapYear(year)); } } @Test public void test_isLeapYear_specific() { - assertEquals(INSTANCE.isLeapYear(8), false); - assertEquals(INSTANCE.isLeapYear(7), false); - assertEquals(INSTANCE.isLeapYear(6), true); - assertEquals(INSTANCE.isLeapYear(5), false); - assertEquals(INSTANCE.isLeapYear(4), false); - assertEquals(INSTANCE.isLeapYear(3), false); - assertEquals(INSTANCE.isLeapYear(2), false); - assertEquals(INSTANCE.isLeapYear(1), false); - assertEquals(INSTANCE.isLeapYear(0), true); - assertEquals(INSTANCE.isLeapYear(-1), false); - assertEquals(INSTANCE.isLeapYear(-2), false); - assertEquals(INSTANCE.isLeapYear(-3), false); - assertEquals(INSTANCE.isLeapYear(-4), false); - assertEquals(INSTANCE.isLeapYear(-5), true); - assertEquals(INSTANCE.isLeapYear(-6), false); + assertEquals(false, INSTANCE.isLeapYear(8)); + assertEquals(false, INSTANCE.isLeapYear(7)); + assertEquals(true, INSTANCE.isLeapYear(6)); + assertEquals(false, INSTANCE.isLeapYear(5)); + assertEquals(false, INSTANCE.isLeapYear(4)); + assertEquals(false, INSTANCE.isLeapYear(3)); + assertEquals(false, INSTANCE.isLeapYear(2)); + assertEquals(false, INSTANCE.isLeapYear(1)); + assertEquals(true, INSTANCE.isLeapYear(0)); + assertEquals(false, INSTANCE.isLeapYear(-1)); + assertEquals(false, INSTANCE.isLeapYear(-2)); + assertEquals(false, INSTANCE.isLeapYear(-3)); + assertEquals(false, INSTANCE.isLeapYear(-4)); + assertEquals(true, INSTANCE.isLeapYear(-5)); + assertEquals(false, INSTANCE.isLeapYear(-6)); } @DataProvider @@ -365,7 +366,7 @@ public static Object[][] data_lengthOfMonth() { @Test @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { - assertEquals(INSTANCE.date(year, month, 1).lengthOfMonth(), length); + assertEquals(length, INSTANCE.date(year, month, 1).lengthOfMonth()); } //----------------------------------------------------------------------- @@ -381,7 +382,7 @@ public void test_era_loop() { int yoe = (year <= 0 ? 1 - year : year); assertEquals(yoe, base.get(YEAR_OF_ERA)); AccountingDate eraBased = INSTANCE.date(era, yoe, 1, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } } @@ -395,20 +396,20 @@ public void test_era_yearDay_loop() { int yoe = (year <= 0 ? 1 - year : year); assertEquals(yoe, base.get(YEAR_OF_ERA)); AccountingDate eraBased = INSTANCE.dateYearDay(era, yoe, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } } @Test public void test_prolepticYear_specific() { - assertEquals(INSTANCE.prolepticYear(AccountingEra.CE, 4), 4); - assertEquals(INSTANCE.prolepticYear(AccountingEra.CE, 3), 3); - assertEquals(INSTANCE.prolepticYear(AccountingEra.CE, 2), 2); - assertEquals(INSTANCE.prolepticYear(AccountingEra.CE, 1), 1); - assertEquals(INSTANCE.prolepticYear(AccountingEra.BCE, 1), 0); - assertEquals(INSTANCE.prolepticYear(AccountingEra.BCE, 2), -1); - assertEquals(INSTANCE.prolepticYear(AccountingEra.BCE, 3), -2); - assertEquals(INSTANCE.prolepticYear(AccountingEra.BCE, 4), -3); + assertEquals(4, INSTANCE.prolepticYear(AccountingEra.CE, 4)); + assertEquals(3, INSTANCE.prolepticYear(AccountingEra.CE, 3)); + assertEquals(2, INSTANCE.prolepticYear(AccountingEra.CE, 2)); + assertEquals(1, INSTANCE.prolepticYear(AccountingEra.CE, 1)); + assertEquals(0, INSTANCE.prolepticYear(AccountingEra.BCE, 1)); + assertEquals(-1, INSTANCE.prolepticYear(AccountingEra.BCE, 2)); + assertEquals(-2, INSTANCE.prolepticYear(AccountingEra.BCE, 3)); + assertEquals(-3, INSTANCE.prolepticYear(AccountingEra.BCE, 4)); } @Test(expected = ClassCastException.class) @@ -418,8 +419,8 @@ public void test_prolepticYear_badEra() { @Test public void test_Chronology_eraOf() { - assertEquals(INSTANCE.eraOf(1), AccountingEra.CE); - assertEquals(INSTANCE.eraOf(0), AccountingEra.BCE); + assertEquals(AccountingEra.CE, INSTANCE.eraOf(1)); + assertEquals(AccountingEra.BCE, INSTANCE.eraOf(0)); } @Test(expected = DateTimeException.class) @@ -430,9 +431,9 @@ public void test_Chronology_eraOf_invalid() { @Test public void test_Chronology_eras() { List eras = INSTANCE.eras(); - assertEquals(eras.size(), 2); - assertEquals(eras.contains(AccountingEra.BCE), true); - assertEquals(eras.contains(AccountingEra.CE), true); + assertEquals(2, eras.size()); + assertEquals(true, eras.contains(AccountingEra.BCE)); + assertEquals(true, eras.contains(AccountingEra.CE)); } //----------------------------------------------------------------------- @@ -440,11 +441,11 @@ public void test_Chronology_eras() { //----------------------------------------------------------------------- @Test public void test_Chronology_range() { - assertEquals(INSTANCE.range(DAY_OF_WEEK), ValueRange.of(1, 7)); - assertEquals(INSTANCE.range(DAY_OF_MONTH), ValueRange.of(1, 28, 35)); - assertEquals(INSTANCE.range(DAY_OF_YEAR), ValueRange.of(1, 364, 371)); - assertEquals(INSTANCE.range(MONTH_OF_YEAR), ValueRange.of(1, 13)); - assertEquals(INSTANCE.range(ALIGNED_WEEK_OF_YEAR), ValueRange.of(1, 52, 53)); + assertEquals(ValueRange.of(1, 7), INSTANCE.range(DAY_OF_WEEK)); + assertEquals(ValueRange.of(1, 28, 35), INSTANCE.range(DAY_OF_MONTH)); + assertEquals(ValueRange.of(1, 364, 371), INSTANCE.range(DAY_OF_YEAR)); + assertEquals(ValueRange.of(1, 13), INSTANCE.range(MONTH_OF_YEAR)); + assertEquals(ValueRange.of(1, 52, 53), INSTANCE.range(ALIGNED_WEEK_OF_YEAR)); } //----------------------------------------------------------------------- @@ -480,7 +481,7 @@ public static Object[][] data_ranges() { @Test @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { - assertEquals(INSTANCE.date(year, month, dom).range(field), ValueRange.of(expectedMin, expectedMax)); + assertEquals(ValueRange.of(expectedMin, expectedMax), INSTANCE.date(year, month, dom).range(field)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -515,7 +516,7 @@ public static Object[][] data_getLong() { @Test @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { - assertEquals(INSTANCE.date(year, month, dom).getLong(field), expected); + assertEquals(expected, INSTANCE.date(year, month, dom).getLong(field)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -569,7 +570,7 @@ public static Object[][] data_with() { public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(INSTANCE.date(year, month, dom).with(field, value), INSTANCE.date(expectedYear, expectedMonth, expectedDom)); + assertEquals(INSTANCE.date(expectedYear, expectedMonth, expectedDom), INSTANCE.date(year, month, dom).with(field, value)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -584,14 +585,14 @@ public void test_with_TemporalField_unsupported() { public void test_adjust1() { AccountingDate base = INSTANCE.date(2012, 6, 23); AccountingDate test = base.with(TemporalAdjusters.lastDayOfMonth()); - assertEquals(test, INSTANCE.date(2012, 6, 28)); + assertEquals(INSTANCE.date(2012, 6, 28), test); } @Test public void test_adjust2() { AccountingDate base = INSTANCE.date(2012, 13, 23); AccountingDate test = base.with(TemporalAdjusters.lastDayOfMonth()); - assertEquals(test, INSTANCE.date(2012, 13, 35)); + assertEquals(INSTANCE.date(2012, 13, 35), test); } //----------------------------------------------------------------------- @@ -601,7 +602,7 @@ public void test_adjust2() { public void test_adjust_toLocalDate() { AccountingDate accounting = INSTANCE.date(2000, 1, 4); AccountingDate test = accounting.with(LocalDate.of(2012, 7, 6)); - assertEquals(test, INSTANCE.date(2012, 12, 5)); + assertEquals(INSTANCE.date(2012, 12, 5), test); } @Test(expected = DateTimeException.class) @@ -617,14 +618,14 @@ public void test_adjust_toMonth() { public void test_LocalDate_adjustToAccountingDate() { AccountingDate accounting = INSTANCE.date(2012, 6, 23); LocalDate test = LocalDate.MIN.with(accounting); - assertEquals(test, LocalDate.of(2012, 2, 7)); + assertEquals(LocalDate.of(2012, 2, 7), test); } @Test public void test_LocalDateTime_adjustToAccountingDate() { AccountingDate accounting = INSTANCE.date(2012, 6, 23); LocalDateTime test = LocalDateTime.MIN.with(accounting); - assertEquals(test, LocalDateTime.of(2012, 2, 7, 0, 0)); + assertEquals(LocalDateTime.of(2012, 2, 7, 0, 0), test); } //----------------------------------------------------------------------- @@ -663,7 +664,7 @@ public static Object[][] data_plus() { public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(INSTANCE.date(year, month, dom).plus(amount, unit), INSTANCE.date(expectedYear, expectedMonth, expectedDom)); + assertEquals(INSTANCE.date(expectedYear, expectedMonth, expectedDom), INSTANCE.date(year, month, dom).plus(amount, unit)); } @Test @@ -672,7 +673,7 @@ public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, int year, int month, int dom) { - assertEquals(INSTANCE.date(year, month, dom).minus(amount, unit), INSTANCE.date(expectedYear, expectedMonth, expectedDom)); + assertEquals(INSTANCE.date(expectedYear, expectedMonth, expectedDom), INSTANCE.date(year, month, dom).minus(amount, unit)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -720,7 +721,7 @@ public void test_until_TemporalUnit( TemporalUnit unit, long expected) { AccountingDate start = INSTANCE.date(year1, month1, dom1); AccountingDate end = INSTANCE.date(year2, month2, dom2); - assertEquals(start.until(end, unit), expected); + assertEquals(expected, start.until(end, unit)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -733,22 +734,22 @@ public void test_until_TemporalUnit_unsupported() { //----------------------------------------------------------------------- @Test public void test_plus_Period() { - assertEquals(INSTANCE.date(2014, 5, 26).plus(INSTANCE.period(0, 2, 3)), INSTANCE.date(2014, 8, 1)); + assertEquals(INSTANCE.date(2014, 8, 1), INSTANCE.date(2014, 5, 26).plus(INSTANCE.period(0, 2, 3))); } @Test(expected = DateTimeException.class) public void test_plus_Period_ISO() { - assertEquals(INSTANCE.date(2014, 5, 26).plus(Period.ofMonths(2)), INSTANCE.date(2014, 7, 26)); + assertEquals(INSTANCE.date(2014, 7, 26), INSTANCE.date(2014, 5, 26).plus(Period.ofMonths(2))); } @Test public void test_minus_Period() { - assertEquals(INSTANCE.date(2014, 5, 26).minus(INSTANCE.period(0, 2, 3)), INSTANCE.date(2014, 3, 23)); + assertEquals(INSTANCE.date(2014, 3, 23), INSTANCE.date(2014, 5, 26).minus(INSTANCE.period(0, 2, 3))); } @Test(expected = DateTimeException.class) public void test_minus_Period_ISO() { - assertEquals(INSTANCE.date(2014, 5, 26).minus(Period.ofMonths(2)), INSTANCE.date(2014, 3, 26)); + assertEquals(INSTANCE.date(2014, 3, 26), INSTANCE.date(2014, 5, 26).minus(Period.ofMonths(2))); } //----------------------------------------------------------------------- @@ -767,18 +768,18 @@ public void test_equals() { .withDivision(AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS) .toChronology().date(2000, 1, 3); - assertEquals(a1.equals(a1), true); - assertEquals(a1.equals(a2), true); - assertEquals(a1.equals(b), false); - assertEquals(a1.equals(c), false); - assertEquals(a1.equals(d), false); + assertEquals(true, a1.equals(a1)); + assertEquals(true, a1.equals(a2)); + assertEquals(false, a1.equals(b)); + assertEquals(false, a1.equals(c)); + assertEquals(false, a1.equals(d)); - assertEquals(a1.equals(null), false); - assertEquals(a1.equals(""), false); - assertEquals(a1.getChronology().equals(other.getChronology()), false); - assertEquals(a1.equals(other), false); + assertEquals(false, a1.equals(null)); + assertEquals(false, a1.equals("")); + assertEquals(false, a1.getChronology().equals(other.getChronology())); + assertEquals(false, a1.equals(other)); - assertEquals(a1.hashCode(), a2.hashCode()); + assertTrue(a1.hashCode() == a1.hashCode()); } //----------------------------------------------------------------------- @@ -795,7 +796,7 @@ public static Object[][] data_toString() { @Test @UseDataProvider("data_toString") public void test_toString(AccountingDate accounting, String expected) { - assertEquals(accounting.toString(), expected); + assertEquals(expected, accounting.toString()); } } diff --git a/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java b/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java index 3d56c87c..5407fe1c 100644 --- a/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java +++ b/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java @@ -102,7 +102,7 @@ public void test_isLeapYear_inLastWeekOf(DayOfWeek dayOfWeek, Month ending) { }; for (int year = -200; year < 600; year++) { - assertEquals(chronology.isLeapYear(year), isLeapYear.test(year)); + assertEquals(isLeapYear.test(year), chronology.isLeapYear(year)); } } @@ -123,7 +123,7 @@ public void test_isLeapYear_nearestEndOf(DayOfWeek dayOfWeek, Month ending) { }; for (int year = -200; year < 600; year++) { - assertEquals(chronology.isLeapYear(year), isLeapYear.test(year)); + assertEquals(isLeapYear.test(year), chronology.isLeapYear(year)); } } @@ -147,13 +147,13 @@ public void test_previousLeapYears_inLastWeekOf(DayOfWeek dayOfWeek, Month endin if (year != 1 && isLeapYear.test(year - 1)) { leapYears++; } - assertEquals(chronology.previousLeapYears(year), leapYears); + assertEquals(leapYears, chronology.previousLeapYears(year)); } for (int year = 1, leapYears = 0; year >= -200; year--) { if (year != 1 && isLeapYear.test(year)) { leapYears--; } - assertEquals(chronology.previousLeapYears(year), leapYears); + assertEquals(leapYears, chronology.previousLeapYears(year)); } } @@ -177,13 +177,13 @@ public void test_previousLeapYears_nearestEndOf(DayOfWeek dayOfWeek, Month endin if (year != 1 && isLeapYear.test(year - 1)) { leapYears++; } - assertEquals(chronology.previousLeapYears(year), leapYears); + assertEquals(leapYears, chronology.previousLeapYears(year)); } for (int year = 1, leapYears = 0; year >= -200; year--) { if (year != 1 && isLeapYear.test(year)) { leapYears--; } - assertEquals(chronology.previousLeapYears(year), leapYears); + assertEquals(leapYears, chronology.previousLeapYears(year)); } } @@ -199,7 +199,7 @@ public void test_date_int_int_int_inLastWeekOf(DayOfWeek dayOfWeek, Month ending }; for (int year = -200; year < 600; year++) { - assertEquals(chronology.date(year, 1, 1).toEpochDay(), getYearEnd.apply(year - 1).plusDays(1).toEpochDay()); + assertEquals(getYearEnd.apply(year - 1).plusDays(1).toEpochDay(), chronology.date(year, 1, 1).toEpochDay()); } } @@ -215,7 +215,7 @@ public void test_date_int_int_int_nearestEndOf(DayOfWeek dayOfWeek, Month ending }; for (int year = -200; year < 600; year++) { - assertEquals(chronology.date(year, 1, 1).toEpochDay(), getYearEnd.apply(year - 1).plusDays(1).toEpochDay()); + assertEquals(getYearEnd.apply(year - 1).plusDays(1).toEpochDay(), chronology.date(year, 1, 1).toEpochDay()); } } @@ -277,11 +277,11 @@ public void test_range(AccountingYearDivision division, int leapWeekInMonth, .withDivision(division).leapWeekInMonth(leapWeekInMonth) .toChronology(); - assertEquals(chronology.range(ChronoField.ALIGNED_WEEK_OF_MONTH), expectedWeekOfMonthRange); - assertEquals(chronology.range(ChronoField.DAY_OF_MONTH), expectedDayOfMonthRange); - assertEquals(chronology.range(ChronoField.DAY_OF_YEAR), ValueRange.of(1, 364, 371)); - assertEquals(chronology.range(ChronoField.MONTH_OF_YEAR), expectedMonthRange); - assertEquals(chronology.range(ChronoField.PROLEPTIC_MONTH), expectedProlepticMonthRange); + assertEquals(expectedWeekOfMonthRange, chronology.range(ChronoField.ALIGNED_WEEK_OF_MONTH)); + assertEquals(expectedDayOfMonthRange, chronology.range(ChronoField.DAY_OF_MONTH)); + assertEquals(ValueRange.of(1, 364, 371), chronology.range(ChronoField.DAY_OF_YEAR)); + assertEquals(expectedMonthRange, chronology.range(ChronoField.MONTH_OF_YEAR)); + assertEquals(expectedProlepticMonthRange, chronology.range(ChronoField.PROLEPTIC_MONTH)); } @Test @@ -292,10 +292,10 @@ public void test_date_dayOfMonth_range(AccountingYearDivision division, int[] we .toChronology(); for (int month = 1; month <= weeksInMonth.length; month++) { - assertEquals(AccountingDate.of(chronology, 2011, month, 15).range(ChronoField.DAY_OF_MONTH), ValueRange.of(1, weeksInMonth[month - 1] * 7)); - assertEquals(AccountingDate.of(chronology, 2012, month, 15).range(ChronoField.DAY_OF_MONTH), ValueRange.of(1, weeksInMonth[month - 1] * 7 + (month == leapWeekInMonth ? 7 : 0))); - assertEquals(AccountingDate.of(chronology, 2011, month, 15).range(ChronoField.ALIGNED_WEEK_OF_MONTH), ValueRange.of(1, weeksInMonth[month - 1])); - assertEquals(AccountingDate.of(chronology, 2012, month, 15).range(ChronoField.ALIGNED_WEEK_OF_MONTH), ValueRange.of(1, weeksInMonth[month - 1] + (month == leapWeekInMonth ? 1 : 0))); + assertEquals(ValueRange.of(1, weeksInMonth[month - 1] * 7), AccountingDate.of(chronology, 2011, month, 15).range(ChronoField.DAY_OF_MONTH)); + assertEquals(ValueRange.of(1, weeksInMonth[month - 1] * 7 + (month == leapWeekInMonth ? 7 : 0)), AccountingDate.of(chronology, 2012, month, 15).range(ChronoField.DAY_OF_MONTH)); + assertEquals(ValueRange.of(1, weeksInMonth[month - 1]), AccountingDate.of(chronology, 2011, month, 15).range(ChronoField.ALIGNED_WEEK_OF_MONTH)); + assertEquals(ValueRange.of(1, weeksInMonth[month - 1] + (month == leapWeekInMonth ? 1 : 0)), AccountingDate.of(chronology, 2012, month, 15).range(ChronoField.ALIGNED_WEEK_OF_MONTH)); } } @@ -316,7 +316,7 @@ public void test_date_dayOfYear_inLastWeekOf_range(DayOfWeek dayOfWeek, Month en }; for (int year = 2007; year < 2015; year++) { - assertEquals(AccountingDate.of(chronology, year, 3, 5).range(ChronoField.DAY_OF_YEAR), ValueRange.of(1, isLeapYear.test(year) ? 371 : 364)); + assertEquals(ValueRange.of(1, isLeapYear.test(year) ? 371 : 364), AccountingDate.of(chronology, year, 3, 5).range(ChronoField.DAY_OF_YEAR)); } } @@ -337,7 +337,7 @@ public void test_date_dayOfYear_nearestEndOf_range(DayOfWeek dayOfWeek, Month en }; for (int year = 2007; year < 2015; year++) { - assertEquals(AccountingDate.of(chronology, year, 3, 5).range(ChronoField.DAY_OF_YEAR), ValueRange.of(1, isLeapYear.test(year) ? 371 : 364)); + assertEquals(ValueRange.of(1, isLeapYear.test(year) ? 371 : 364), AccountingDate.of(chronology, year, 3, 5).range(ChronoField.DAY_OF_YEAR)); } } @@ -381,8 +381,8 @@ public void test_getWeeksInMonth(AccountingYearDivision division, int[] weeksInM .toChronology(); for (int month = 1; month <= weeksInMonth.length; month++) { - assertEquals(chronology.getDivision().getWeeksInMonth(month), weeksInMonth[month - 1]); - assertEquals(chronology.getDivision().getWeeksInMonth(month, leapWeekInMonth), weeksInMonth[month - 1] + (month == leapWeekInMonth ? 1 : 0)); + assertEquals(weeksInMonth[month - 1], chronology.getDivision().getWeeksInMonth(month)); + assertEquals(weeksInMonth[month - 1] + (month == leapWeekInMonth ? 1 : 0), chronology.getDivision().getWeeksInMonth(month, leapWeekInMonth)); } } @@ -394,8 +394,8 @@ public void test_getWeeksAtStartOf(AccountingYearDivision division, int[] weeksI .toChronology(); for (int month = 1, elapsedWeeks = 0; month <= weeksInMonth.length; elapsedWeeks += weeksInMonth[month - 1], month++) { - assertEquals(chronology.getDivision().getWeeksAtStartOfMonth(month), elapsedWeeks); - assertEquals(chronology.getDivision().getWeeksAtStartOfMonth(month, leapWeekInMonth), elapsedWeeks + (month > leapWeekInMonth ? 1 : 0)); + assertEquals(elapsedWeeks, chronology.getDivision().getWeeksAtStartOfMonth(month)); + assertEquals(elapsedWeeks + (month > leapWeekInMonth ? 1 : 0), chronology.getDivision().getWeeksAtStartOfMonth(month, leapWeekInMonth)); } } @@ -408,10 +408,10 @@ public void test_getMonthFromElapsedWeeks(AccountingYearDivision division, int[] for (int month = 1, elapsedWeeks = 0; month <= weeksInMonth.length; elapsedWeeks += weeksInMonth[month - 1], month++) { for (int i = 0; i < weeksInMonth[month - 1]; i++) { - assertEquals(chronology.getDivision().getMonthFromElapsedWeeks(elapsedWeeks + i), month); - assertEquals(chronology.getDivision().getMonthFromElapsedWeeks(elapsedWeeks + i + (month > leapWeekInMonth ? 1 : 0), leapWeekInMonth), month); + assertEquals(month, chronology.getDivision().getMonthFromElapsedWeeks(elapsedWeeks + i)); + assertEquals(month, chronology.getDivision().getMonthFromElapsedWeeks(elapsedWeeks + i + (month > leapWeekInMonth ? 1 : 0), leapWeekInMonth)); if (month == leapWeekInMonth && i == weeksInMonth[month - 1] - 1) { - assertEquals(chronology.getDivision().getMonthFromElapsedWeeks(elapsedWeeks + i + 1, leapWeekInMonth), month); + assertEquals(month, chronology.getDivision().getMonthFromElapsedWeeks(elapsedWeeks + i + 1, leapWeekInMonth)); } } } @@ -420,7 +420,7 @@ public void test_getMonthFromElapsedWeeks(AccountingYearDivision division, int[] @Test(expected = DateTimeException.class) @UseDataProvider("data_weeksInMonth") public void test_negativeWeeks_getMonthFromElapsedWeekspublic(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { - assertEquals(division.getMonthFromElapsedWeeks(0), 1); + assertEquals(1, division.getMonthFromElapsedWeeks(0)); division.getMonthFromElapsedWeeks(-1); } @@ -431,7 +431,7 @@ public void test_extraWeeks_getMonthFromElapsedWeekspublic(AccountingYearDivisio for (int month = 1; month <= weeksInMonth.length; month++) { elapsedWeeks += weeksInMonth[month - 1]; } - assertEquals(division.getMonthFromElapsedWeeks(elapsedWeeks), weeksInMonth.length); + assertEquals(weeksInMonth.length, division.getMonthFromElapsedWeeks(elapsedWeeks)); division.getMonthFromElapsedWeeks(elapsedWeeks + 1); } @@ -442,7 +442,7 @@ public void test_extraWeeksLeap_getMonthFromElapsedWeekspublic(AccountingYearDiv for (int month = 1; month <= weeksInMonth.length; month++) { elapsedWeeks += weeksInMonth[month - 1]; } - assertEquals(division.getMonthFromElapsedWeeks(elapsedWeeks, leapWeekInMonth), weeksInMonth.length); + assertEquals(weeksInMonth.length, division.getMonthFromElapsedWeeks(elapsedWeeks, leapWeekInMonth)); division.getMonthFromElapsedWeeks(elapsedWeeks + 1, leapWeekInMonth); } diff --git a/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java b/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java index a664d9f8..ea7e7c44 100644 --- a/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java @@ -54,6 +54,7 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.time.DateTimeException; import java.time.Instant; @@ -102,9 +103,9 @@ public class TestBritishCutoverChronology { public void test_chronology_of_name() { Chronology chrono = Chronology.of("BritishCutover"); Assert.assertNotNull(chrono); - Assert.assertEquals(chrono, BritishCutoverChronology.INSTANCE); - Assert.assertEquals(chrono.getId(), "BritishCutover"); - Assert.assertEquals(chrono.getCalendarType(), null); + Assert.assertEquals(BritishCutoverChronology.INSTANCE, chrono); + Assert.assertEquals("BritishCutover", chrono.getId()); + Assert.assertEquals(null, chrono.getCalendarType()); } //----------------------------------------------------------------------- @@ -158,78 +159,78 @@ public static Object[][] data_samples() { @Test @UseDataProvider("data_samples") public void test_LocalDate_from_BritishCutoverDate(BritishCutoverDate cutover, LocalDate iso) { - assertEquals(LocalDate.from(cutover), iso); + assertEquals(iso, LocalDate.from(cutover)); } @Test @UseDataProvider("data_samples") public void test_BritishCutoverDate_from_LocalDate(BritishCutoverDate cutover, LocalDate iso) { - assertEquals(BritishCutoverDate.from(iso), cutover); + assertEquals(cutover, BritishCutoverDate.from(iso)); } @Test @UseDataProvider("data_samples") public void test_BritishCutoverDate_chronology_dateEpochDay(BritishCutoverDate cutover, LocalDate iso) { - assertEquals(BritishCutoverChronology.INSTANCE.dateEpochDay(iso.toEpochDay()), cutover); + assertEquals(cutover, BritishCutoverChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } @Test @UseDataProvider("data_samples") public void test_BritishCutoverDate_toEpochDay(BritishCutoverDate cutover, LocalDate iso) { - assertEquals(cutover.toEpochDay(), iso.toEpochDay()); + assertEquals(iso.toEpochDay(), cutover.toEpochDay()); } @Test @UseDataProvider("data_samples") public void test_BritishCutoverDate_until_BritishCutoverDate(BritishCutoverDate cutover, LocalDate iso) { - assertEquals(cutover.until(cutover), BritishCutoverChronology.INSTANCE.period(0, 0, 0)); + assertEquals(BritishCutoverChronology.INSTANCE.period(0, 0, 0), cutover.until(cutover)); } @Test @UseDataProvider("data_samples") public void test_BritishCutoverDate_until_LocalDate(BritishCutoverDate cutover, LocalDate iso) { - assertEquals(cutover.until(iso), BritishCutoverChronology.INSTANCE.period(0, 0, 0)); + assertEquals(BritishCutoverChronology.INSTANCE.period(0, 0, 0), cutover.until(iso)); } @Test @UseDataProvider("data_samples") public void test_LocalDate_until_BritishCutoverDate(BritishCutoverDate cutover, LocalDate iso) { - assertEquals(iso.until(cutover), Period.ZERO); + assertEquals(Period.ZERO, iso.until(cutover)); } @Test @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(BritishCutoverDate cutover, LocalDate iso) { - assertEquals(BritishCutoverChronology.INSTANCE.date(iso), cutover); + assertEquals(cutover, BritishCutoverChronology.INSTANCE.date(iso)); } @Test @UseDataProvider("data_samples") public void test_plusDays(BritishCutoverDate cutover, LocalDate iso) { - assertEquals(LocalDate.from(cutover.plus(0, DAYS)), iso); - assertEquals(LocalDate.from(cutover.plus(1, DAYS)), iso.plusDays(1)); - assertEquals(LocalDate.from(cutover.plus(35, DAYS)), iso.plusDays(35)); - assertEquals(LocalDate.from(cutover.plus(-1, DAYS)), iso.plusDays(-1)); - assertEquals(LocalDate.from(cutover.plus(-60, DAYS)), iso.plusDays(-60)); + assertEquals(iso, LocalDate.from(cutover.plus(0, DAYS))); + assertEquals(iso.plusDays(1), LocalDate.from(cutover.plus(1, DAYS))); + assertEquals(iso.plusDays(35), LocalDate.from(cutover.plus(35, DAYS))); + assertEquals(iso.plusDays(-1), LocalDate.from(cutover.plus(-1, DAYS))); + assertEquals(iso.plusDays(-60), LocalDate.from(cutover.plus(-60, DAYS))); } @Test @UseDataProvider("data_samples") public void test_minusDays(BritishCutoverDate cutover, LocalDate iso) { - assertEquals(LocalDate.from(cutover.minus(0, DAYS)), iso); - assertEquals(LocalDate.from(cutover.minus(1, DAYS)), iso.minusDays(1)); - assertEquals(LocalDate.from(cutover.minus(35, DAYS)), iso.minusDays(35)); - assertEquals(LocalDate.from(cutover.minus(-1, DAYS)), iso.minusDays(-1)); - assertEquals(LocalDate.from(cutover.minus(-60, DAYS)), iso.minusDays(-60)); + assertEquals(iso, LocalDate.from(cutover.minus(0, DAYS))); + assertEquals(iso.minusDays(1), LocalDate.from(cutover.minus(1, DAYS))); + assertEquals(iso.minusDays(35), LocalDate.from(cutover.minus(35, DAYS))); + assertEquals(iso.minusDays(-1), LocalDate.from(cutover.minus(-1, DAYS))); + assertEquals(iso.minusDays(-60), LocalDate.from(cutover.minus(-60, DAYS))); } @Test @UseDataProvider("data_samples") public void test_until_DAYS(BritishCutoverDate cutover, LocalDate iso) { - assertEquals(cutover.until(iso.plusDays(0), DAYS), 0); - assertEquals(cutover.until(iso.plusDays(1), DAYS), 1); - assertEquals(cutover.until(iso.plusDays(35), DAYS), 35); - assertEquals(cutover.until(iso.minusDays(40), DAYS), -40); + assertEquals(0, cutover.until(iso.plusDays(0), DAYS)); + assertEquals(1, cutover.until(iso.plusDays(1), DAYS)); + assertEquals(35, cutover.until(iso.plusDays(35), DAYS)); + assertEquals(-40, cutover.until(iso.minusDays(40), DAYS)); } @DataProvider @@ -293,28 +294,28 @@ public void test_Chronology_dateYearDay_badDate() { public void test_Chronology_isLeapYear_loop() { for (int year = -200; year < 200; year++) { BritishCutoverDate base = BritishCutoverDate.of(year, 1, 1); - assertEquals(base.isLeapYear(), (year % 4) == 0); - assertEquals(BritishCutoverChronology.INSTANCE.isLeapYear(year), (year % 4) == 0); + assertEquals((year % 4) == 0, base.isLeapYear()); + assertEquals((year % 4) == 0, BritishCutoverChronology.INSTANCE.isLeapYear(year)); } } @Test public void test_Chronology_isLeapYear_specific() { - assertEquals(BritishCutoverChronology.INSTANCE.isLeapYear(8), true); - assertEquals(BritishCutoverChronology.INSTANCE.isLeapYear(7), false); - assertEquals(BritishCutoverChronology.INSTANCE.isLeapYear(6), false); - assertEquals(BritishCutoverChronology.INSTANCE.isLeapYear(5), false); - assertEquals(BritishCutoverChronology.INSTANCE.isLeapYear(4), true); - assertEquals(BritishCutoverChronology.INSTANCE.isLeapYear(3), false); - assertEquals(BritishCutoverChronology.INSTANCE.isLeapYear(2), false); - assertEquals(BritishCutoverChronology.INSTANCE.isLeapYear(1), false); - assertEquals(BritishCutoverChronology.INSTANCE.isLeapYear(0), true); - assertEquals(BritishCutoverChronology.INSTANCE.isLeapYear(-1), false); - assertEquals(BritishCutoverChronology.INSTANCE.isLeapYear(-2), false); - assertEquals(BritishCutoverChronology.INSTANCE.isLeapYear(-3), false); - assertEquals(BritishCutoverChronology.INSTANCE.isLeapYear(-4), true); - assertEquals(BritishCutoverChronology.INSTANCE.isLeapYear(-5), false); - assertEquals(BritishCutoverChronology.INSTANCE.isLeapYear(-6), false); + assertEquals(true, BritishCutoverChronology.INSTANCE.isLeapYear(8)); + assertEquals(false, BritishCutoverChronology.INSTANCE.isLeapYear(7)); + assertEquals(false, BritishCutoverChronology.INSTANCE.isLeapYear(6)); + assertEquals(false, BritishCutoverChronology.INSTANCE.isLeapYear(5)); + assertEquals(true, BritishCutoverChronology.INSTANCE.isLeapYear(4)); + assertEquals(false, BritishCutoverChronology.INSTANCE.isLeapYear(3)); + assertEquals(false, BritishCutoverChronology.INSTANCE.isLeapYear(2)); + assertEquals(false, BritishCutoverChronology.INSTANCE.isLeapYear(1)); + assertEquals(true, BritishCutoverChronology.INSTANCE.isLeapYear(0)); + assertEquals(false, BritishCutoverChronology.INSTANCE.isLeapYear(-1)); + assertEquals(false, BritishCutoverChronology.INSTANCE.isLeapYear(-2)); + assertEquals(false, BritishCutoverChronology.INSTANCE.isLeapYear(-3)); + assertEquals(true, BritishCutoverChronology.INSTANCE.isLeapYear(-4)); + assertEquals(false, BritishCutoverChronology.INSTANCE.isLeapYear(-5)); + assertEquals(false, BritishCutoverChronology.INSTANCE.isLeapYear(-6)); } //----------------------------------------------------------------------- @@ -322,7 +323,7 @@ public void test_Chronology_isLeapYear_specific() { //----------------------------------------------------------------------- @Test public void test_Chronology_getCutover() { - assertEquals(BritishCutoverChronology.INSTANCE.getCutover(), LocalDate.of(1752, 9, 14)); + assertEquals(LocalDate.of(1752, 9, 14), BritishCutoverChronology.INSTANCE.getCutover()); } //----------------------------------------------------------------------- @@ -400,7 +401,7 @@ public static Object[][] data_lengthOfMonth() { @Test @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { - assertEquals(BritishCutoverDate.of(year, month, 1).lengthOfMonth(), length); + assertEquals(length, BritishCutoverDate.of(year, month, 1).lengthOfMonth()); } //----------------------------------------------------------------------- @@ -441,13 +442,13 @@ public static Object[][] data_lengthOfYear() { @Test @UseDataProvider("data_lengthOfYear") public void test_lengthOfYear_atStart(int year, int length) { - assertEquals(BritishCutoverDate.of(year, 1, 1).lengthOfYear(), length); + assertEquals(length, BritishCutoverDate.of(year, 1, 1).lengthOfYear()); } @Test @UseDataProvider("data_lengthOfYear") public void test_lengthOfYear_atEnd(int year, int length) { - assertEquals(BritishCutoverDate.of(year, 12, 31).lengthOfYear(), length); + assertEquals(length, BritishCutoverDate.of(year, 12, 31).lengthOfYear()); } //----------------------------------------------------------------------- @@ -463,7 +464,7 @@ public void test_era_loop() { int yoe = (year <= 0 ? 1 - year : year); assertEquals(yoe, base.get(YEAR_OF_ERA)); BritishCutoverDate eraBased = BritishCutoverChronology.INSTANCE.date(era, yoe, 1, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } } @@ -477,32 +478,32 @@ public void test_era_yearDay_loop() { int yoe = (year <= 0 ? 1 - year : year); assertEquals(yoe, base.get(YEAR_OF_ERA)); BritishCutoverDate eraBased = BritishCutoverChronology.INSTANCE.dateYearDay(era, yoe, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } } @Test public void test_era_yearDay() { - assertEquals(BritishCutoverChronology.INSTANCE.dateYearDay(1752, 1), BritishCutoverDate.of(1752, 1, 1)); - assertEquals(BritishCutoverChronology.INSTANCE.dateYearDay(1752, 244), BritishCutoverDate.of(1752, 8, 31)); - assertEquals(BritishCutoverChronology.INSTANCE.dateYearDay(1752, 246), BritishCutoverDate.of(1752, 9, 2)); - assertEquals(BritishCutoverChronology.INSTANCE.dateYearDay(1752, 247), BritishCutoverDate.of(1752, 9, 14)); - assertEquals(BritishCutoverChronology.INSTANCE.dateYearDay(1752, 257), BritishCutoverDate.of(1752, 9, 24)); - assertEquals(BritishCutoverChronology.INSTANCE.dateYearDay(1752, 258), BritishCutoverDate.of(1752, 9, 25)); - assertEquals(BritishCutoverChronology.INSTANCE.dateYearDay(1752, 355), BritishCutoverDate.of(1752, 12, 31)); - assertEquals(BritishCutoverChronology.INSTANCE.dateYearDay(2014, 1), BritishCutoverDate.of(2014, 1, 1)); + assertEquals(BritishCutoverDate.of(1752, 1, 1), BritishCutoverChronology.INSTANCE.dateYearDay(1752, 1)); + assertEquals(BritishCutoverDate.of(1752, 8, 31), BritishCutoverChronology.INSTANCE.dateYearDay(1752, 244)); + assertEquals(BritishCutoverDate.of(1752, 9, 2), BritishCutoverChronology.INSTANCE.dateYearDay(1752, 246)); + assertEquals(BritishCutoverDate.of(1752, 9, 14), BritishCutoverChronology.INSTANCE.dateYearDay(1752, 247)); + assertEquals(BritishCutoverDate.of(1752, 9, 24), BritishCutoverChronology.INSTANCE.dateYearDay(1752, 257)); + assertEquals(BritishCutoverDate.of(1752, 9, 25), BritishCutoverChronology.INSTANCE.dateYearDay(1752, 258)); + assertEquals(BritishCutoverDate.of(1752, 12, 31), BritishCutoverChronology.INSTANCE.dateYearDay(1752, 355)); + assertEquals(BritishCutoverDate.of(2014, 1, 1), BritishCutoverChronology.INSTANCE.dateYearDay(2014, 1)); } @Test public void test_prolepticYear_specific() { - assertEquals(BritishCutoverChronology.INSTANCE.prolepticYear(JulianEra.AD, 4), 4); - assertEquals(BritishCutoverChronology.INSTANCE.prolepticYear(JulianEra.AD, 3), 3); - assertEquals(BritishCutoverChronology.INSTANCE.prolepticYear(JulianEra.AD, 2), 2); - assertEquals(BritishCutoverChronology.INSTANCE.prolepticYear(JulianEra.AD, 1), 1); - assertEquals(BritishCutoverChronology.INSTANCE.prolepticYear(JulianEra.BC, 1), 0); - assertEquals(BritishCutoverChronology.INSTANCE.prolepticYear(JulianEra.BC, 2), -1); - assertEquals(BritishCutoverChronology.INSTANCE.prolepticYear(JulianEra.BC, 3), -2); - assertEquals(BritishCutoverChronology.INSTANCE.prolepticYear(JulianEra.BC, 4), -3); + assertEquals(4, BritishCutoverChronology.INSTANCE.prolepticYear(JulianEra.AD, 4)); + assertEquals(3, BritishCutoverChronology.INSTANCE.prolepticYear(JulianEra.AD, 3)); + assertEquals(2, BritishCutoverChronology.INSTANCE.prolepticYear(JulianEra.AD, 2)); + assertEquals(1, BritishCutoverChronology.INSTANCE.prolepticYear(JulianEra.AD, 1)); + assertEquals(0, BritishCutoverChronology.INSTANCE.prolepticYear(JulianEra.BC, 1)); + assertEquals(-1, BritishCutoverChronology.INSTANCE.prolepticYear(JulianEra.BC, 2)); + assertEquals(-2, BritishCutoverChronology.INSTANCE.prolepticYear(JulianEra.BC, 3)); + assertEquals(-3, BritishCutoverChronology.INSTANCE.prolepticYear(JulianEra.BC, 4)); } @Test(expected = ClassCastException.class) @@ -512,8 +513,8 @@ public void test_prolepticYear_badEra() { @Test public void test_Chronology_eraOf() { - assertEquals(BritishCutoverChronology.INSTANCE.eraOf(1), JulianEra.AD); - assertEquals(BritishCutoverChronology.INSTANCE.eraOf(0), JulianEra.BC); + assertEquals(JulianEra.AD, BritishCutoverChronology.INSTANCE.eraOf(1)); + assertEquals(JulianEra.BC, BritishCutoverChronology.INSTANCE.eraOf(0)); } @Test(expected = DateTimeException.class) @@ -524,9 +525,9 @@ public void test_Chronology_eraOf_invalid() { @Test public void test_Chronology_eras() { List eras = BritishCutoverChronology.INSTANCE.eras(); - assertEquals(eras.size(), 2); - assertEquals(eras.contains(JulianEra.BC), true); - assertEquals(eras.contains(JulianEra.AD), true); + assertEquals(2, eras.size()); + assertEquals(true, eras.contains(JulianEra.BC)); + assertEquals(true, eras.contains(JulianEra.AD)); } //----------------------------------------------------------------------- @@ -534,12 +535,12 @@ public void test_Chronology_eras() { //----------------------------------------------------------------------- @Test public void test_Chronology_range() { - assertEquals(BritishCutoverChronology.INSTANCE.range(DAY_OF_WEEK), ValueRange.of(1, 7)); - assertEquals(BritishCutoverChronology.INSTANCE.range(DAY_OF_MONTH), ValueRange.of(1, 28, 31)); - assertEquals(BritishCutoverChronology.INSTANCE.range(DAY_OF_YEAR), ValueRange.of(1, 355, 366)); - assertEquals(BritishCutoverChronology.INSTANCE.range(MONTH_OF_YEAR), ValueRange.of(1, 12)); - assertEquals(BritishCutoverChronology.INSTANCE.range(ALIGNED_WEEK_OF_MONTH), ValueRange.of(1, 3, 5)); - assertEquals(BritishCutoverChronology.INSTANCE.range(ALIGNED_WEEK_OF_YEAR), ValueRange.of(1, 51, 53)); + assertEquals(ValueRange.of(1, 7), BritishCutoverChronology.INSTANCE.range(DAY_OF_WEEK)); + assertEquals(ValueRange.of(1, 28, 31), BritishCutoverChronology.INSTANCE.range(DAY_OF_MONTH)); + assertEquals(ValueRange.of(1, 355, 366), BritishCutoverChronology.INSTANCE.range(DAY_OF_YEAR)); + assertEquals(ValueRange.of(1, 12), BritishCutoverChronology.INSTANCE.range(MONTH_OF_YEAR)); + assertEquals(ValueRange.of(1, 3, 5), BritishCutoverChronology.INSTANCE.range(ALIGNED_WEEK_OF_MONTH)); + assertEquals(ValueRange.of(1, 51, 53), BritishCutoverChronology.INSTANCE.range(ALIGNED_WEEK_OF_YEAR)); } //----------------------------------------------------------------------- @@ -634,7 +635,7 @@ public static Object[][] data_ranges() { @Test @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { - assertEquals(BritishCutoverDate.of(year, month, dom).range(field), ValueRange.of(expectedMin, expectedMax)); + assertEquals(ValueRange.of(expectedMin, expectedMax), BritishCutoverDate.of(year, month, dom).range(field)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -696,7 +697,7 @@ public static Object[][] data_getLong() { @Test @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { - assertEquals(BritishCutoverDate.of(year, month, dom).getLong(field), expected); + assertEquals(expected, BritishCutoverDate.of(year, month, dom).getLong(field)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -810,7 +811,7 @@ public static Object[][] data_with() { public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(BritishCutoverDate.of(year, month, dom).with(field, value), BritishCutoverDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(BritishCutoverDate.of(expectedYear, expectedMonth, expectedDom), BritishCutoverDate.of(year, month, dom).with(field, value)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -837,7 +838,7 @@ public static Object[][] data_lastDayOfMonth() { @UseDataProvider("data_lastDayOfMonth") public void test_adjust_lastDayOfMonth(BritishCutoverDate input, BritishCutoverDate expected) { BritishCutoverDate test = input.with(TemporalAdjusters.lastDayOfMonth()); - assertEquals(test, expected); + assertEquals(expected, test); } //----------------------------------------------------------------------- @@ -858,7 +859,7 @@ public static Object[][] data_withLocalDate() { @UseDataProvider("data_withLocalDate") public void test_adjust_LocalDate(BritishCutoverDate input, LocalDate local, BritishCutoverDate expected) { BritishCutoverDate test = input.with(local); - assertEquals(test, expected); + assertEquals(expected, test); } @Test(expected = DateTimeException.class) @@ -874,14 +875,14 @@ public void test_adjust_toMonth() { public void test_LocalDate_withBritishCutoverDate() { BritishCutoverDate cutover = BritishCutoverDate.of(2012, 6, 23); LocalDate test = LocalDate.MIN.with(cutover); - assertEquals(test, LocalDate.of(2012, 6, 23)); + assertEquals(LocalDate.of(2012, 6, 23), test); } @Test public void test_LocalDateTime_withBritishCutoverDate() { BritishCutoverDate cutover = BritishCutoverDate.of(2012, 6, 23); LocalDateTime test = LocalDateTime.MIN.with(cutover); - assertEquals(test, LocalDateTime.of(2012, 6, 23, 0, 0)); + assertEquals(LocalDateTime.of(2012, 6, 23, 0, 0), test); } //----------------------------------------------------------------------- @@ -944,7 +945,7 @@ public static Object[][] data_plus() { public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom, boolean bidi) { - assertEquals(BritishCutoverDate.of(year, month, dom).plus(amount, unit), BritishCutoverDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(BritishCutoverDate.of(expectedYear, expectedMonth, expectedDom), BritishCutoverDate.of(year, month, dom).plus(amount, unit)); } @Test @@ -954,7 +955,7 @@ public void test_minus_TemporalUnit( long amount, TemporalUnit unit, int year, int month, int dom, boolean bidi) { if (bidi) { - assertEquals(BritishCutoverDate.of(year, month, dom).minus(amount, unit), BritishCutoverDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(BritishCutoverDate.of(expectedYear, expectedMonth, expectedDom), BritishCutoverDate.of(year, month, dom).minus(amount, unit)); } } @@ -1027,7 +1028,7 @@ public void test_until_TemporalUnit( TemporalUnit unit, long expected) { BritishCutoverDate start = BritishCutoverDate.of(year1, month1, dom1); BritishCutoverDate end = BritishCutoverDate.of(year2, month2, dom2); - assertEquals(start.until(end, unit), expected); + assertEquals(expected, start.until(end, unit)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -1041,38 +1042,38 @@ public void test_until_TemporalUnit_unsupported() { @Test public void test_plus_Period() { assertEquals( - BritishCutoverDate.of(1752, 9, 2).plus(BritishCutoverChronology.INSTANCE.period(0, 1, 3)), - BritishCutoverDate.of(1752, 10, 5)); + BritishCutoverDate.of(1752, 10, 5), + BritishCutoverDate.of(1752, 9, 2).plus(BritishCutoverChronology.INSTANCE.period(0, 1, 3))); assertEquals( - BritishCutoverDate.of(1752, 8, 12).plus(BritishCutoverChronology.INSTANCE.period(0, 1, 0)), - BritishCutoverDate.of(1752, 9, 23)); + BritishCutoverDate.of(1752, 9, 23), + BritishCutoverDate.of(1752, 8, 12).plus(BritishCutoverChronology.INSTANCE.period(0, 1, 0))); assertEquals( - BritishCutoverDate.of(2014, 5, 26).plus(BritishCutoverChronology.INSTANCE.period(0, 2, 3)), - BritishCutoverDate.of(2014, 7, 29)); + BritishCutoverDate.of(2014, 7, 29), + BritishCutoverDate.of(2014, 5, 26).plus(BritishCutoverChronology.INSTANCE.period(0, 2, 3))); } @Test(expected = DateTimeException.class) public void test_plus_Period_ISO() { assertEquals( - BritishCutoverDate.of(2014, 5, 26).plus(Period.ofMonths(2)), - BritishCutoverDate.of(2014, 7, 26)); + BritishCutoverDate.of(2014, 7, 26), + BritishCutoverDate.of(2014, 5, 26).plus(Period.ofMonths(2))); } @Test public void test_minus_Period() { assertEquals( - BritishCutoverDate.of(1752, 10, 12).minus(BritishCutoverChronology.INSTANCE.period(0, 1, 0)), - BritishCutoverDate.of(1752, 9, 23)); + BritishCutoverDate.of(1752, 9, 23), + BritishCutoverDate.of(1752, 10, 12).minus(BritishCutoverChronology.INSTANCE.period(0, 1, 0))); assertEquals( - BritishCutoverDate.of(2014, 5, 26).minus(BritishCutoverChronology.INSTANCE.period(0, 2, 3)), - BritishCutoverDate.of(2014, 3, 23)); + BritishCutoverDate.of(2014, 3, 23), + BritishCutoverDate.of(2014, 5, 26).minus(BritishCutoverChronology.INSTANCE.period(0, 2, 3))); } @Test(expected = DateTimeException.class) public void test_minus_Period_ISO() { assertEquals( - BritishCutoverDate.of(2014, 5, 26).minus(Period.ofMonths(2)), - BritishCutoverDate.of(2014, 3, 26)); + BritishCutoverDate.of(2014, 3, 26), + BritishCutoverDate.of(2014, 5, 26).minus(Period.ofMonths(2))); } //----------------------------------------------------------------------- @@ -1232,8 +1233,8 @@ public void test_until_CLD( BritishCutoverDate b = BritishCutoverDate.of(year2, month2, dom2); ChronoPeriod c = a.until(b); assertEquals( - c, - BritishCutoverChronology.INSTANCE.period(expectedYears, expectedMonths, expectedDays)); + BritishCutoverChronology.INSTANCE.period(expectedYears, expectedMonths, expectedDays), + c); } @Test @@ -1245,7 +1246,7 @@ public void test_until_CLD_plus( BritishCutoverDate a = BritishCutoverDate.of(year1, month1, dom1); BritishCutoverDate b = BritishCutoverDate.of(year2, month2, dom2); ChronoPeriod c = a.until(b); - assertEquals(a.plus(c), b); + assertEquals(b, a.plus(c)); } //------------------------------------------------------------------------- @@ -1255,11 +1256,11 @@ public void test_until_CLD_plus( public void test_atTime() { BritishCutoverDate date = BritishCutoverDate.of(2014, 10, 12); ChronoLocalDateTime test = date.atTime(LocalTime.of(12, 30)); - assertEquals(test.toLocalDate(), date); - assertEquals(test.toLocalTime(), LocalTime.of(12, 30)); + assertEquals(date, test.toLocalDate()); + assertEquals(LocalTime.of(12, 30), test.toLocalTime()); ChronoLocalDateTime test2 = BritishCutoverChronology.INSTANCE.localDateTime(LocalDateTime.from(test)); - assertEquals(test2, test); + assertEquals(test, test2); } @Test(expected = NullPointerException.class) @@ -1280,10 +1281,10 @@ public void test_crossCheck() { gcal.clear(); gcal.set(1700, Calendar.JANUARY, 1); while (test.isBefore(end)) { - assertEquals(test.get(YEAR_OF_ERA), gcal.get(Calendar.YEAR)); - assertEquals(test.get(MONTH_OF_YEAR), gcal.get(Calendar.MONTH) + 1); - assertEquals(test.get(DAY_OF_MONTH), gcal.get(Calendar.DAY_OF_MONTH)); - assertEquals(LocalDate.from(test), gcal.toZonedDateTime().toLocalDate()); + assertEquals(gcal.get(Calendar.YEAR), test.get(YEAR_OF_ERA)); + assertEquals(gcal.get(Calendar.MONTH) + 1, test.get(MONTH_OF_YEAR)); + assertEquals(gcal.get(Calendar.DAY_OF_MONTH), test.get(DAY_OF_MONTH)); + assertEquals(gcal.toZonedDateTime().toLocalDate(), LocalDate.from(test)); gcal.add(Calendar.DAY_OF_MONTH, 1); test = test.plus(1, DAYS); } @@ -1300,16 +1301,16 @@ public void test_equals() { BritishCutoverDate c = BritishCutoverDate.of(2000, 2, 3); BritishCutoverDate d = BritishCutoverDate.of(2001, 1, 3); - assertEquals(a1.equals(a1), true); - assertEquals(a1.equals(a2), true); - assertEquals(a1.equals(b), false); - assertEquals(a1.equals(c), false); - assertEquals(a1.equals(d), false); + assertEquals(true, a1.equals(a1)); + assertEquals(true, a1.equals(a2)); + assertEquals(false, a1.equals(b)); + assertEquals(false, a1.equals(c)); + assertEquals(false, a1.equals(d)); - assertEquals(a1.equals(null), false); - assertEquals(a1.equals(""), false); + assertEquals(false, a1.equals(null)); + assertEquals(false, a1.equals("")); - assertEquals(a1.hashCode(), a2.hashCode()); + assertTrue(a1.hashCode() == a2.hashCode()); } //----------------------------------------------------------------------- @@ -1326,7 +1327,7 @@ public static Object[][] data_toString() { @Test @UseDataProvider("data_toString") public void test_toString(BritishCutoverDate cutover, String expected) { - assertEquals(cutover.toString(), expected); + assertEquals(expected, cutover.toString()); } } diff --git a/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java b/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java index 106b2aea..5637e6c5 100644 --- a/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java @@ -54,6 +54,7 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; @@ -91,18 +92,18 @@ public class TestCopticChronology { public void test_chronology_of_name() { Chronology chrono = Chronology.of("Coptic"); Assert.assertNotNull(chrono); - Assert.assertEquals(chrono, CopticChronology.INSTANCE); - Assert.assertEquals(chrono.getId(), "Coptic"); - Assert.assertEquals(chrono.getCalendarType(), "coptic"); + Assert.assertEquals(CopticChronology.INSTANCE, chrono); + Assert.assertEquals("Coptic", chrono.getId()); + Assert.assertEquals("coptic", chrono.getCalendarType()); } @Test public void test_chronology_of_name_id() { Chronology chrono = Chronology.of("coptic"); Assert.assertNotNull(chrono); - Assert.assertEquals(chrono, CopticChronology.INSTANCE); - Assert.assertEquals(chrono.getId(), "Coptic"); - Assert.assertEquals(chrono.getCalendarType(), "coptic"); + Assert.assertEquals(CopticChronology.INSTANCE, chrono); + Assert.assertEquals("Coptic", chrono.getId()); + Assert.assertEquals("coptic", chrono.getCalendarType()); } //----------------------------------------------------------------------- @@ -139,78 +140,78 @@ public static Object[][] data_samples() { @Test @UseDataProvider("data_samples") public void test_LocalDate_from_CopticDate(CopticDate coptic, LocalDate iso) { - assertEquals(LocalDate.from(coptic), iso); + assertEquals(iso, LocalDate.from(coptic)); } @Test @UseDataProvider("data_samples") public void test_CopticDate_from_LocalDate(CopticDate coptic, LocalDate iso) { - assertEquals(CopticDate.from(iso), coptic); + assertEquals(coptic, CopticDate.from(iso)); } @Test @UseDataProvider("data_samples") public void test_CopticDate_chronology_dateEpochDay(CopticDate coptic, LocalDate iso) { - assertEquals(CopticChronology.INSTANCE.dateEpochDay(iso.toEpochDay()), coptic); + assertEquals(coptic, CopticChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } @Test @UseDataProvider("data_samples") public void test_CopticDate_toEpochDay(CopticDate coptic, LocalDate iso) { - assertEquals(coptic.toEpochDay(), iso.toEpochDay()); + assertEquals(iso.toEpochDay(), coptic.toEpochDay()); } @Test @UseDataProvider("data_samples") public void test_CopticDate_until_CopticDate(CopticDate coptic, LocalDate iso) { - assertEquals(coptic.until(coptic), CopticChronology.INSTANCE.period(0, 0, 0)); + assertEquals(CopticChronology.INSTANCE.period(0, 0, 0), coptic.until(coptic)); } @Test @UseDataProvider("data_samples") public void test_CopticDate_until_LocalDate(CopticDate coptic, LocalDate iso) { - assertEquals(coptic.until(iso), CopticChronology.INSTANCE.period(0, 0, 0)); + assertEquals(CopticChronology.INSTANCE.period(0, 0, 0), coptic.until(iso)); } @Test @UseDataProvider("data_samples") public void test_LocalDate_until_CopticDate(CopticDate coptic, LocalDate iso) { - assertEquals(iso.until(coptic), Period.ZERO); + assertEquals(Period.ZERO, iso.until(coptic)); } @Test @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(CopticDate coptic, LocalDate iso) { - assertEquals(CopticChronology.INSTANCE.date(iso), coptic); + assertEquals(coptic, CopticChronology.INSTANCE.date(iso)); } @Test @UseDataProvider("data_samples") public void test_plusDays(CopticDate coptic, LocalDate iso) { - assertEquals(LocalDate.from(coptic.plus(0, DAYS)), iso); - assertEquals(LocalDate.from(coptic.plus(1, DAYS)), iso.plusDays(1)); - assertEquals(LocalDate.from(coptic.plus(35, DAYS)), iso.plusDays(35)); - assertEquals(LocalDate.from(coptic.plus(-1, DAYS)), iso.plusDays(-1)); - assertEquals(LocalDate.from(coptic.plus(-60, DAYS)), iso.plusDays(-60)); + assertEquals(iso, LocalDate.from(coptic.plus(0, DAYS))); + assertEquals(iso.plusDays(1), LocalDate.from(coptic.plus(1, DAYS))); + assertEquals(iso.plusDays(35), LocalDate.from(coptic.plus(35, DAYS))); + assertEquals(iso.plusDays(-1), LocalDate.from(coptic.plus(-1, DAYS))); + assertEquals(iso.plusDays(-60), LocalDate.from(coptic.plus(-60, DAYS))); } @Test @UseDataProvider("data_samples") public void test_minusDays(CopticDate coptic, LocalDate iso) { - assertEquals(LocalDate.from(coptic.minus(0, DAYS)), iso); - assertEquals(LocalDate.from(coptic.minus(1, DAYS)), iso.minusDays(1)); - assertEquals(LocalDate.from(coptic.minus(35, DAYS)), iso.minusDays(35)); - assertEquals(LocalDate.from(coptic.minus(-1, DAYS)), iso.minusDays(-1)); - assertEquals(LocalDate.from(coptic.minus(-60, DAYS)), iso.minusDays(-60)); + assertEquals(iso, LocalDate.from(coptic.minus(0, DAYS))); + assertEquals(iso.minusDays(1), LocalDate.from(coptic.minus(1, DAYS))); + assertEquals(iso.minusDays(35), LocalDate.from(coptic.minus(35, DAYS))); + assertEquals(iso.minusDays(-1), LocalDate.from(coptic.minus(-1, DAYS))); + assertEquals(iso.minusDays(-60), LocalDate.from(coptic.minus(-60, DAYS))); } @Test @UseDataProvider("data_samples") public void test_until_DAYS(CopticDate coptic, LocalDate iso) { - assertEquals(coptic.until(iso.plusDays(0), DAYS), 0); - assertEquals(coptic.until(iso.plusDays(1), DAYS), 1); - assertEquals(coptic.until(iso.plusDays(35), DAYS), 35); - assertEquals(coptic.until(iso.minusDays(40), DAYS), -40); + assertEquals(0, coptic.until(iso.plusDays(0), DAYS)); + assertEquals(1, coptic.until(iso.plusDays(1), DAYS)); + assertEquals(35, coptic.until(iso.plusDays(35), DAYS)); + assertEquals(-40, coptic.until(iso.minusDays(40), DAYS)); } @DataProvider @@ -263,28 +264,28 @@ public void test_chronology_dateYearDay_badDate() { public void test_isLeapYear_loop() { for (int year = -200; year < 200; year++) { CopticDate base = CopticDate.of(year, 1, 1); - assertEquals(base.isLeapYear(), ((year - 3) % 4) == 0); - assertEquals(CopticChronology.INSTANCE.isLeapYear(year), ((year + 400 - 3) % 4) == 0); + assertEquals(((year - 3) % 4) == 0, base.isLeapYear()); + assertEquals(((year + 400 - 3) % 4) == 0, CopticChronology.INSTANCE.isLeapYear(year)); } } @Test public void test_isLeapYear_specific() { - assertEquals(CopticChronology.INSTANCE.isLeapYear(8), false); - assertEquals(CopticChronology.INSTANCE.isLeapYear(7), true); - assertEquals(CopticChronology.INSTANCE.isLeapYear(6), false); - assertEquals(CopticChronology.INSTANCE.isLeapYear(5), false); - assertEquals(CopticChronology.INSTANCE.isLeapYear(4), false); - assertEquals(CopticChronology.INSTANCE.isLeapYear(3), true); - assertEquals(CopticChronology.INSTANCE.isLeapYear(2), false); - assertEquals(CopticChronology.INSTANCE.isLeapYear(1), false); - assertEquals(CopticChronology.INSTANCE.isLeapYear(0), false); - assertEquals(CopticChronology.INSTANCE.isLeapYear(-1), true); - assertEquals(CopticChronology.INSTANCE.isLeapYear(-2), false); - assertEquals(CopticChronology.INSTANCE.isLeapYear(-3), false); - assertEquals(CopticChronology.INSTANCE.isLeapYear(-4), false); - assertEquals(CopticChronology.INSTANCE.isLeapYear(-5), true); - assertEquals(CopticChronology.INSTANCE.isLeapYear(-6), false); + assertEquals(false, CopticChronology.INSTANCE.isLeapYear(8)); + assertEquals(true, CopticChronology.INSTANCE.isLeapYear(7)); + assertEquals(false, CopticChronology.INSTANCE.isLeapYear(6)); + assertEquals(false, CopticChronology.INSTANCE.isLeapYear(5)); + assertEquals(false, CopticChronology.INSTANCE.isLeapYear(4)); + assertEquals(true, CopticChronology.INSTANCE.isLeapYear(3)); + assertEquals(false, CopticChronology.INSTANCE.isLeapYear(2)); + assertEquals(false, CopticChronology.INSTANCE.isLeapYear(1)); + assertEquals(false, CopticChronology.INSTANCE.isLeapYear(0)); + assertEquals(true, CopticChronology.INSTANCE.isLeapYear(-1)); + assertEquals(false, CopticChronology.INSTANCE.isLeapYear(-2)); + assertEquals(false, CopticChronology.INSTANCE.isLeapYear(-3)); + assertEquals(false, CopticChronology.INSTANCE.isLeapYear(-4)); + assertEquals(true, CopticChronology.INSTANCE.isLeapYear(-5)); + assertEquals(false, CopticChronology.INSTANCE.isLeapYear(-6)); } @DataProvider @@ -310,7 +311,7 @@ public static Object[][] data_lengthOfMonth() { @Test @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { - assertEquals(CopticDate.of(year, month, 1).lengthOfMonth(), length); + assertEquals(length, CopticDate.of(year, month, 1).lengthOfMonth()); } //----------------------------------------------------------------------- @@ -326,7 +327,7 @@ public void test_era_loop() { int yoe = (year <= 0 ? 1 - year : year); assertEquals(yoe, base.get(YEAR_OF_ERA)); CopticDate eraBased = CopticChronology.INSTANCE.date(era, yoe, 1, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } } @@ -340,26 +341,26 @@ public void test_era_yearDay_loop() { int yoe = (year <= 0 ? 1 - year : year); assertEquals(yoe, base.get(YEAR_OF_ERA)); CopticDate eraBased = CopticChronology.INSTANCE.dateYearDay(era, yoe, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } } @Test public void test_prolepticYear_specific() { - assertEquals(CopticChronology.INSTANCE.prolepticYear(CopticEra.AM, 4), 4); - assertEquals(CopticChronology.INSTANCE.prolepticYear(CopticEra.AM, 3), 3); - assertEquals(CopticChronology.INSTANCE.prolepticYear(CopticEra.AM, 2), 2); - assertEquals(CopticChronology.INSTANCE.prolepticYear(CopticEra.AM, 1), 1); - assertEquals(CopticChronology.INSTANCE.prolepticYear(CopticEra.BEFORE_AM, 1), 0); - assertEquals(CopticChronology.INSTANCE.prolepticYear(CopticEra.BEFORE_AM, 2), -1); - assertEquals(CopticChronology.INSTANCE.prolepticYear(CopticEra.BEFORE_AM, 3), -2); - assertEquals(CopticChronology.INSTANCE.prolepticYear(CopticEra.BEFORE_AM, 4), -3); + assertEquals(4, CopticChronology.INSTANCE.prolepticYear(CopticEra.AM, 4)); + assertEquals(3, CopticChronology.INSTANCE.prolepticYear(CopticEra.AM, 3)); + assertEquals(2, CopticChronology.INSTANCE.prolepticYear(CopticEra.AM, 2)); + assertEquals(1, CopticChronology.INSTANCE.prolepticYear(CopticEra.AM, 1)); + assertEquals(0, CopticChronology.INSTANCE.prolepticYear(CopticEra.BEFORE_AM, 1)); + assertEquals(-1, CopticChronology.INSTANCE.prolepticYear(CopticEra.BEFORE_AM, 2)); + assertEquals(-2, CopticChronology.INSTANCE.prolepticYear(CopticEra.BEFORE_AM, 3)); + assertEquals(-3, CopticChronology.INSTANCE.prolepticYear(CopticEra.BEFORE_AM, 4)); } @Test public void test_Chronology_eraOf() { - assertEquals(CopticChronology.INSTANCE.eraOf(1), CopticEra.AM); - assertEquals(CopticChronology.INSTANCE.eraOf(0), CopticEra.BEFORE_AM); + assertEquals(CopticEra.AM, CopticChronology.INSTANCE.eraOf(1)); + assertEquals(CopticEra.BEFORE_AM, CopticChronology.INSTANCE.eraOf(0)); } @Test(expected = DateTimeException.class) @@ -370,9 +371,9 @@ public void test_Chronology_eraOf_invalid() { @Test public void test_Chronology_eras() { List eras = CopticChronology.INSTANCE.eras(); - assertEquals(eras.size(), 2); - assertEquals(eras.contains(CopticEra.BEFORE_AM), true); - assertEquals(eras.contains(CopticEra.AM), true); + assertEquals(2, eras.size()); + assertEquals(true, eras.contains(CopticEra.BEFORE_AM)); + assertEquals(true, eras.contains(CopticEra.AM)); } //----------------------------------------------------------------------- @@ -380,10 +381,10 @@ public void test_Chronology_eras() { //----------------------------------------------------------------------- @Test public void test_Chronology_range() { - assertEquals(CopticChronology.INSTANCE.range(DAY_OF_WEEK), ValueRange.of(1, 7)); - assertEquals(CopticChronology.INSTANCE.range(DAY_OF_MONTH), ValueRange.of(1, 5, 30)); - assertEquals(CopticChronology.INSTANCE.range(DAY_OF_YEAR), ValueRange.of(1, 365, 366)); - assertEquals(CopticChronology.INSTANCE.range(MONTH_OF_YEAR), ValueRange.of(1, 13)); + assertEquals(ValueRange.of(1, 7), CopticChronology.INSTANCE.range(DAY_OF_WEEK)); + assertEquals(ValueRange.of(1, 5, 30), CopticChronology.INSTANCE.range(DAY_OF_MONTH)); + assertEquals(ValueRange.of(1, 365, 366), CopticChronology.INSTANCE.range(DAY_OF_YEAR)); + assertEquals(ValueRange.of(1, 13), CopticChronology.INSTANCE.range(MONTH_OF_YEAR)); } //----------------------------------------------------------------------- @@ -421,7 +422,7 @@ public static Object[][] data_ranges() { @Test @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { - assertEquals(CopticDate.of(year, month, dom).range(field), ValueRange.of(expectedMin, expectedMax)); + assertEquals(ValueRange.of(expectedMin, expectedMax), CopticDate.of(year, month, dom).range(field)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -456,7 +457,7 @@ public static Object[][] data_getLong() { @Test @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { - assertEquals(CopticDate.of(year, month, dom).getLong(field), expected); + assertEquals(expected, CopticDate.of(year, month, dom).getLong(field)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -508,7 +509,7 @@ public static Object[][] data_with() { public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(CopticDate.of(year, month, dom).with(field, value), CopticDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(CopticDate.of(expectedYear, expectedMonth, expectedDom), CopticDate.of(year, month, dom).with(field, value)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -523,14 +524,14 @@ public void test_with_TemporalField_unsupported() { public void test_adjust1() { CopticDate base = CopticDate.of(1728, 10, 29); CopticDate test = base.with(TemporalAdjusters.lastDayOfMonth()); - assertEquals(test, CopticDate.of(1728, 10, 30)); + assertEquals(CopticDate.of(1728, 10, 30), test); } @Test public void test_adjust2() { CopticDate base = CopticDate.of(1728, 13, 2); CopticDate test = base.with(TemporalAdjusters.lastDayOfMonth()); - assertEquals(test, CopticDate.of(1728, 13, 5)); + assertEquals(CopticDate.of(1728, 13, 5), test); } //----------------------------------------------------------------------- @@ -540,7 +541,7 @@ public void test_adjust2() { public void test_adjust_toLocalDate() { CopticDate coptic = CopticDate.of(1726, 1, 4); CopticDate test = coptic.with(LocalDate.of(2012, 7, 6)); - assertEquals(test, CopticDate.of(1728, 10, 29)); + assertEquals(CopticDate.of(1728, 10, 29), test); } @Test(expected = DateTimeException.class) @@ -556,14 +557,14 @@ public void test_adjust_toMonth() { public void test_LocalDate_adjustToCopticDate() { CopticDate coptic = CopticDate.of(1728, 10, 29); LocalDate test = LocalDate.MIN.with(coptic); - assertEquals(test, LocalDate.of(2012, 7, 6)); + assertEquals(LocalDate.of(2012, 7, 6), test); } @Test public void test_LocalDateTime_adjustToCopticDate() { CopticDate coptic = CopticDate.of(1728, 10, 29); LocalDateTime test = LocalDateTime.MIN.with(coptic); - assertEquals(test, LocalDateTime.of(2012, 7, 6, 0, 0)); + assertEquals(LocalDateTime.of(2012, 7, 6, 0, 0), test); } //----------------------------------------------------------------------- @@ -602,7 +603,7 @@ public static Object[][] data_plus() { public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(CopticDate.of(year, month, dom).plus(amount, unit), CopticDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(CopticDate.of(expectedYear, expectedMonth, expectedDom), CopticDate.of(year, month, dom).plus(amount, unit)); } @Test @@ -611,7 +612,7 @@ public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, int year, int month, int dom) { - assertEquals(CopticDate.of(year, month, dom).minus(amount, unit), CopticDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(CopticDate.of(expectedYear, expectedMonth, expectedDom), CopticDate.of(year, month, dom).minus(amount, unit)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -622,22 +623,22 @@ public void test_plus_TemporalUnit_unsupported() { //----------------------------------------------------------------------- @Test public void test_plus_Period() { - assertEquals(CopticDate.of(1727, 5, 26).plus(CopticChronology.INSTANCE.period(0, 2, 3)), CopticDate.of(1727, 7, 29)); + assertEquals(CopticDate.of(1727, 7, 29), CopticDate.of(1727, 5, 26).plus(CopticChronology.INSTANCE.period(0, 2, 3))); } @Test(expected = DateTimeException.class) public void test_plus_Period_ISO() { - assertEquals(CopticDate.of(1727, 5, 26).plus(Period.ofMonths(2)), CopticDate.of(1727, 7, 26)); + assertEquals(CopticDate.of(1727, 7, 26), CopticDate.of(1727, 5, 26).plus(Period.ofMonths(2))); } @Test public void test_minus_Period() { - assertEquals(CopticDate.of(1727, 5, 26).minus(CopticChronology.INSTANCE.period(0, 2, 3)), CopticDate.of(1727, 3, 23)); + assertEquals(CopticDate.of(1727, 3, 23), CopticDate.of(1727, 5, 26).minus(CopticChronology.INSTANCE.period(0, 2, 3))); } @Test(expected = DateTimeException.class) public void test_minus_Period_ISO() { - assertEquals(CopticDate.of(1727, 5, 26).minus(Period.ofMonths(2)), CopticDate.of(1727, 3, 26)); + assertEquals(CopticDate.of(1727, 3, 26), CopticDate.of(1727, 5, 26).minus(Period.ofMonths(2))); } //----------------------------------------------------------------------- @@ -678,7 +679,7 @@ public void test_until_TemporalUnit( TemporalUnit unit, long expected) { CopticDate start = CopticDate.of(year1, month1, dom1); CopticDate end = CopticDate.of(year2, month2, dom2); - assertEquals(start.until(end, unit), expected); + assertEquals(expected, start.until(end, unit)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -699,16 +700,16 @@ public void test_equals() { CopticDate c = CopticDate.of(1728, 2, 3); CopticDate d = CopticDate.of(1729, 1, 3); - assertEquals(a1.equals(a1), true); - assertEquals(a1.equals(a2), true); - assertEquals(a1.equals(b), false); - assertEquals(a1.equals(c), false); - assertEquals(a1.equals(d), false); + assertEquals(true, a1.equals(a1)); + assertEquals(true, a1.equals(a2)); + assertEquals(false, a1.equals(b)); + assertEquals(false, a1.equals(c)); + assertEquals(false, a1.equals(d)); - assertEquals(a1.equals(null), false); - assertEquals(a1.equals(""), false); + assertEquals(false, a1.equals(null)); + assertEquals(false, a1.equals("")); - assertEquals(a1.hashCode(), a2.hashCode()); + assertTrue(a1.hashCode() == a2.hashCode()); } //----------------------------------------------------------------------- @@ -728,7 +729,7 @@ public static Object[][] data_toString() { @Test @UseDataProvider("data_toString") public void test_toString(CopticDate coptic, String expected) { - assertEquals(coptic.toString(), expected); + assertEquals(expected, coptic.toString()); } } diff --git a/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java b/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java index a28c5f45..c0906ff0 100644 --- a/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java @@ -55,6 +55,7 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; @@ -94,18 +95,18 @@ public class TestDiscordianChronology { public void test_chronology_of_name() { Chronology chrono = Chronology.of("Discordian"); Assert.assertNotNull(chrono); - Assert.assertEquals(chrono, DiscordianChronology.INSTANCE); - Assert.assertEquals(chrono.getId(), "Discordian"); - Assert.assertEquals(chrono.getCalendarType(), "discordian"); + Assert.assertEquals(DiscordianChronology.INSTANCE, chrono); + Assert.assertEquals("Discordian", chrono.getId()); + Assert.assertEquals("discordian", chrono.getCalendarType()); } @Test public void test_chronology_of_name_id() { Chronology chrono = Chronology.of("discordian"); Assert.assertNotNull(chrono); - Assert.assertEquals(chrono, DiscordianChronology.INSTANCE); - Assert.assertEquals(chrono.getId(), "Discordian"); - Assert.assertEquals(chrono.getCalendarType(), "discordian"); + Assert.assertEquals(DiscordianChronology.INSTANCE, chrono); + Assert.assertEquals("Discordian", chrono.getId()); + Assert.assertEquals("discordian", chrono.getCalendarType()); } //----------------------------------------------------------------------- @@ -155,78 +156,78 @@ public static Object[][] data_samples() { @Test @UseDataProvider("data_samples") public void test_LocalDate_from_DiscordianDate(DiscordianDate discordian, LocalDate iso) { - assertEquals(LocalDate.from(discordian), iso); + assertEquals(iso, LocalDate.from(discordian)); } @Test @UseDataProvider("data_samples") public void test_DiscordianDate_from_LocalDate(DiscordianDate discordian, LocalDate iso) { - assertEquals(DiscordianDate.from(iso), discordian); + assertEquals(discordian, DiscordianDate.from(iso)); } @Test @UseDataProvider("data_samples") public void test_DiscordianDate_chronology_dateEpochDay(DiscordianDate discordian, LocalDate iso) { - assertEquals(DiscordianChronology.INSTANCE.dateEpochDay(iso.toEpochDay()), discordian); + assertEquals(discordian, DiscordianChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } @Test @UseDataProvider("data_samples") public void test_DiscordianDate_toEpochDay(DiscordianDate discordian, LocalDate iso) { - assertEquals(discordian.toEpochDay(), iso.toEpochDay()); + assertEquals(iso.toEpochDay(), discordian.toEpochDay()); } @Test @UseDataProvider("data_samples") public void test_DiscordianDate_until_DiscordianDate(DiscordianDate discordian, LocalDate iso) { - assertEquals(discordian.until(discordian), DiscordianChronology.INSTANCE.period(0, 0, 0)); + assertEquals(DiscordianChronology.INSTANCE.period(0, 0, 0), discordian.until(discordian)); } @Test @UseDataProvider("data_samples") public void test_DiscordianDate_until_LocalDate(DiscordianDate discordian, LocalDate iso) { - assertEquals(discordian.until(iso), DiscordianChronology.INSTANCE.period(0, 0, 0)); + assertEquals(DiscordianChronology.INSTANCE.period(0, 0, 0), discordian.until(iso)); } @Test @UseDataProvider("data_samples") public void test_LocalDate_until_DiscordianDate(DiscordianDate discordian, LocalDate iso) { - assertEquals(iso.until(discordian), Period.ZERO); + assertEquals(Period.ZERO, iso.until(discordian)); } @Test @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(DiscordianDate discordian, LocalDate iso) { - assertEquals(DiscordianChronology.INSTANCE.date(iso), discordian); + assertEquals(discordian, DiscordianChronology.INSTANCE.date(iso)); } @Test @UseDataProvider("data_samples") public void test_plusDays(DiscordianDate discordian, LocalDate iso) { - assertEquals(LocalDate.from(discordian.plus(0, DAYS)), iso); - assertEquals(LocalDate.from(discordian.plus(1, DAYS)), iso.plusDays(1)); - assertEquals(LocalDate.from(discordian.plus(35, DAYS)), iso.plusDays(35)); - assertEquals(LocalDate.from(discordian.plus(-1, DAYS)), iso.plusDays(-1)); - assertEquals(LocalDate.from(discordian.plus(-60, DAYS)), iso.plusDays(-60)); + assertEquals(iso, LocalDate.from(discordian.plus(0, DAYS))); + assertEquals(iso.plusDays(1), LocalDate.from(discordian.plus(1, DAYS))); + assertEquals(iso.plusDays(35), LocalDate.from(discordian.plus(35, DAYS))); + assertEquals(iso.plusDays(-1), LocalDate.from(discordian.plus(-1, DAYS))); + assertEquals(iso.plusDays(-60), LocalDate.from(discordian.plus(-60, DAYS))); } @Test @UseDataProvider("data_samples") public void test_minusDays(DiscordianDate discordian, LocalDate iso) { - assertEquals(LocalDate.from(discordian.minus(0, DAYS)), iso); - assertEquals(LocalDate.from(discordian.minus(1, DAYS)), iso.minusDays(1)); - assertEquals(LocalDate.from(discordian.minus(35, DAYS)), iso.minusDays(35)); - assertEquals(LocalDate.from(discordian.minus(-1, DAYS)), iso.minusDays(-1)); - assertEquals(LocalDate.from(discordian.minus(-60, DAYS)), iso.minusDays(-60)); + assertEquals(iso, LocalDate.from(discordian.minus(0, DAYS))); + assertEquals(iso.minusDays(1), LocalDate.from(discordian.minus(1, DAYS))); + assertEquals(iso.minusDays(35), LocalDate.from(discordian.minus(35, DAYS))); + assertEquals(iso.minusDays(-1), LocalDate.from(discordian.minus(-1, DAYS))); + assertEquals(iso.minusDays(-60), LocalDate.from(discordian.minus(-60, DAYS))); } @Test @UseDataProvider("data_samples") public void test_until_DAYS(DiscordianDate discordian, LocalDate iso) { - assertEquals(discordian.until(iso.plusDays(0), DAYS), 0); - assertEquals(discordian.until(iso.plusDays(1), DAYS), 1); - assertEquals(discordian.until(iso.plusDays(35), DAYS), 35); - assertEquals(discordian.until(iso.minusDays(40), DAYS), -40); + assertEquals(0, discordian.until(iso.plusDays(0), DAYS)); + assertEquals(1, discordian.until(iso.plusDays(1), DAYS)); + assertEquals(35, discordian.until(iso.plusDays(35), DAYS)); + assertEquals(-40, discordian.until(iso.minusDays(40), DAYS)); } @DataProvider @@ -277,28 +278,28 @@ public void test_isLeapYear_loop() { }; for (int year = 1066; year < 1567; year++) { DiscordianDate base = DiscordianDate.of(year, 1, 1); - assertEquals(base.isLeapYear(), isLeapYear.test(year)); - assertEquals(DiscordianChronology.INSTANCE.isLeapYear(year), isLeapYear.test(year)); + assertEquals(isLeapYear.test(year), base.isLeapYear()); + assertEquals(isLeapYear.test(year), DiscordianChronology.INSTANCE.isLeapYear(year)); } } @Test public void test_isLeapYear_specific() { - assertEquals(DiscordianChronology.INSTANCE.isLeapYear(1174), true); - assertEquals(DiscordianChronology.INSTANCE.isLeapYear(1173), false); - assertEquals(DiscordianChronology.INSTANCE.isLeapYear(1172), false); - assertEquals(DiscordianChronology.INSTANCE.isLeapYear(1171), false); - assertEquals(DiscordianChronology.INSTANCE.isLeapYear(1170), true); - assertEquals(DiscordianChronology.INSTANCE.isLeapYear(1169), false); - assertEquals(DiscordianChronology.INSTANCE.isLeapYear(1168), false); - assertEquals(DiscordianChronology.INSTANCE.isLeapYear(1167), false); - assertEquals(DiscordianChronology.INSTANCE.isLeapYear(1166), true); - assertEquals(DiscordianChronology.INSTANCE.isLeapYear(1165), false); - assertEquals(DiscordianChronology.INSTANCE.isLeapYear(1164), false); - assertEquals(DiscordianChronology.INSTANCE.isLeapYear(1163), false); - assertEquals(DiscordianChronology.INSTANCE.isLeapYear(1162), true); - assertEquals(DiscordianChronology.INSTANCE.isLeapYear(1161), false); - assertEquals(DiscordianChronology.INSTANCE.isLeapYear(1160), false); + assertEquals(true, DiscordianChronology.INSTANCE.isLeapYear(1174)); + assertEquals(false, DiscordianChronology.INSTANCE.isLeapYear(1173)); + assertEquals(false, DiscordianChronology.INSTANCE.isLeapYear(1172)); + assertEquals(false, DiscordianChronology.INSTANCE.isLeapYear(1171)); + assertEquals(true, DiscordianChronology.INSTANCE.isLeapYear(1170)); + assertEquals(false, DiscordianChronology.INSTANCE.isLeapYear(1169)); + assertEquals(false, DiscordianChronology.INSTANCE.isLeapYear(1168)); + assertEquals(false, DiscordianChronology.INSTANCE.isLeapYear(1167)); + assertEquals(true, DiscordianChronology.INSTANCE.isLeapYear(1166)); + assertEquals(false, DiscordianChronology.INSTANCE.isLeapYear(1165)); + assertEquals(false, DiscordianChronology.INSTANCE.isLeapYear(1164)); + assertEquals(false, DiscordianChronology.INSTANCE.isLeapYear(1163)); + assertEquals(true, DiscordianChronology.INSTANCE.isLeapYear(1162)); + assertEquals(false, DiscordianChronology.INSTANCE.isLeapYear(1161)); + assertEquals(false, DiscordianChronology.INSTANCE.isLeapYear(1160)); } @DataProvider @@ -322,14 +323,14 @@ public static Object[][] data_lengthOfMonth() { @Test @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { - assertEquals(DiscordianDate.of(year, month, 1).lengthOfMonth(), length); + assertEquals(length, DiscordianDate.of(year, month, 1).lengthOfMonth()); } @Test public void test_lengthOfMonth_specific() { - assertEquals(DiscordianDate.of(3178, 0, 0).lengthOfMonth(), 1); - assertEquals(DiscordianDate.of(3178, 1, 1).lengthOfMonth(), 73); - assertEquals(DiscordianDate.of(3178, 1, 73).lengthOfMonth(), 73); + assertEquals(1, DiscordianDate.of(3178, 0, 0).lengthOfMonth()); + assertEquals(73, DiscordianDate.of(3178, 1, 1).lengthOfMonth()); + assertEquals(73, DiscordianDate.of(3178, 1, 73).lengthOfMonth()); } //----------------------------------------------------------------------- @@ -343,7 +344,7 @@ public void test_era_loop() { assertEquals(DiscordianEra.YOLD, base.getEra()); assertEquals(year, base.get(YEAR_OF_ERA)); DiscordianDate eraBased = DiscordianChronology.INSTANCE.date(DiscordianEra.YOLD, year, 1, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } } @@ -355,16 +356,16 @@ public void test_era_yearDay_loop() { assertEquals(DiscordianEra.YOLD, base.getEra()); assertEquals(year, base.get(YEAR_OF_ERA)); DiscordianDate eraBased = DiscordianChronology.INSTANCE.dateYearDay(DiscordianEra.YOLD, year, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } } @Test public void test_prolepticYear_specific() { - assertEquals(DiscordianChronology.INSTANCE.prolepticYear(DiscordianEra.YOLD, 4), 4); - assertEquals(DiscordianChronology.INSTANCE.prolepticYear(DiscordianEra.YOLD, 3), 3); - assertEquals(DiscordianChronology.INSTANCE.prolepticYear(DiscordianEra.YOLD, 2), 2); - assertEquals(DiscordianChronology.INSTANCE.prolepticYear(DiscordianEra.YOLD, 1), 1); + assertEquals(4, DiscordianChronology.INSTANCE.prolepticYear(DiscordianEra.YOLD, 4)); + assertEquals(3, DiscordianChronology.INSTANCE.prolepticYear(DiscordianEra.YOLD, 3)); + assertEquals(2, DiscordianChronology.INSTANCE.prolepticYear(DiscordianEra.YOLD, 2)); + assertEquals(1, DiscordianChronology.INSTANCE.prolepticYear(DiscordianEra.YOLD, 1)); } @Test(expected = ClassCastException.class) @@ -374,7 +375,7 @@ public void test_prolepticYear_badEra() { @Test public void test_Chronology_eraOf() { - assertEquals(DiscordianChronology.INSTANCE.eraOf(1), DiscordianEra.YOLD); + assertEquals(DiscordianEra.YOLD, DiscordianChronology.INSTANCE.eraOf(1)); } @Test(expected = DateTimeException.class) @@ -386,8 +387,8 @@ public void test_Chronology_eraOf_invalid() { @Test public void test_Chronology_eras() { List eras = DiscordianChronology.INSTANCE.eras(); - assertEquals(eras.size(), 1); - assertEquals(eras.contains(DiscordianEra.YOLD), true); + assertEquals(1, eras.size()); + assertEquals(true, eras.contains(DiscordianEra.YOLD)); } //----------------------------------------------------------------------- @@ -395,19 +396,19 @@ public void test_Chronology_eras() { //----------------------------------------------------------------------- @Test public void test_Chronology_range() { - assertEquals(DiscordianChronology.INSTANCE.range(ALIGNED_DAY_OF_WEEK_IN_MONTH), ValueRange.of(0, 1, 0, 5)); - assertEquals(DiscordianChronology.INSTANCE.range(ALIGNED_DAY_OF_WEEK_IN_YEAR), ValueRange.of(0, 1, 5, 5)); - assertEquals(DiscordianChronology.INSTANCE.range(ALIGNED_WEEK_OF_MONTH), ValueRange.of(0, 1, 0, 15)); - assertEquals(DiscordianChronology.INSTANCE.range(ALIGNED_WEEK_OF_YEAR), ValueRange.of(0, 1, 73, 73)); - assertEquals(DiscordianChronology.INSTANCE.range(DAY_OF_WEEK), ValueRange.of(0, 1, 0, 5)); - assertEquals(DiscordianChronology.INSTANCE.range(DAY_OF_MONTH), ValueRange.of(0, 1, 0, 73)); - assertEquals(DiscordianChronology.INSTANCE.range(DAY_OF_YEAR), ValueRange.of(1, 365, 366)); - assertEquals(DiscordianChronology.INSTANCE.range(EPOCH_DAY), ValueRange.of(-1_145_400, 999_999 * 365L + 242_499)); - assertEquals(DiscordianChronology.INSTANCE.range(ERA), ValueRange.of(1, 1)); - assertEquals(DiscordianChronology.INSTANCE.range(MONTH_OF_YEAR), ValueRange.of(0, 1, 5, 5)); - assertEquals(DiscordianChronology.INSTANCE.range(PROLEPTIC_MONTH), ValueRange.of(0, 999_999 * 5L + 5 - 1)); - assertEquals(DiscordianChronology.INSTANCE.range(YEAR), ValueRange.of(1, 999_999)); - assertEquals(DiscordianChronology.INSTANCE.range(YEAR_OF_ERA), ValueRange.of(1, 999_999)); + assertEquals(ValueRange.of(0, 1, 0, 5), DiscordianChronology.INSTANCE.range(ALIGNED_DAY_OF_WEEK_IN_MONTH)); + assertEquals(ValueRange.of(0, 1, 5, 5), DiscordianChronology.INSTANCE.range(ALIGNED_DAY_OF_WEEK_IN_YEAR)); + assertEquals(ValueRange.of(0, 1, 0, 15), DiscordianChronology.INSTANCE.range(ALIGNED_WEEK_OF_MONTH)); + assertEquals(ValueRange.of(0, 1, 73, 73), DiscordianChronology.INSTANCE.range(ALIGNED_WEEK_OF_YEAR)); + assertEquals(ValueRange.of(0, 1, 0, 5), DiscordianChronology.INSTANCE.range(DAY_OF_WEEK)); + assertEquals(ValueRange.of(0, 1, 0, 73), DiscordianChronology.INSTANCE.range(DAY_OF_MONTH)); + assertEquals(ValueRange.of(1, 365, 366), DiscordianChronology.INSTANCE.range(DAY_OF_YEAR)); + assertEquals(ValueRange.of(-1_145_400, 999_999 * 365L + 242_499), DiscordianChronology.INSTANCE.range(EPOCH_DAY)); + assertEquals(ValueRange.of(1, 1), DiscordianChronology.INSTANCE.range(ERA)); + assertEquals(ValueRange.of(0, 1, 5, 5), DiscordianChronology.INSTANCE.range(MONTH_OF_YEAR)); + assertEquals(ValueRange.of(0, 999_999 * 5L + 5 - 1), DiscordianChronology.INSTANCE.range(PROLEPTIC_MONTH)); + assertEquals(ValueRange.of(1, 999_999), DiscordianChronology.INSTANCE.range(YEAR)); + assertEquals(ValueRange.of(1, 999_999), DiscordianChronology.INSTANCE.range(YEAR_OF_ERA)); } //----------------------------------------------------------------------- @@ -458,7 +459,7 @@ public static Object[][] data_ranges() { @Test @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { - assertEquals(DiscordianDate.of(year, month, dom).range(field), ValueRange.of(expectedMin, expectedMax)); + assertEquals(ValueRange.of(expectedMin, expectedMax), DiscordianDate.of(year, month, dom).range(field)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -512,7 +513,7 @@ public static Object[][] data_getLong() { @Test @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { - assertEquals(DiscordianDate.of(year, month, dom).getLong(field), expected); + assertEquals(expected, DiscordianDate.of(year, month, dom).getLong(field)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -603,7 +604,7 @@ public static Object[][] data_with() { public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(DiscordianDate.of(year, month, dom).with(field, value), DiscordianDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(DiscordianDate.of(expectedYear, expectedMonth, expectedDom), DiscordianDate.of(year, month, dom).with(field, value)); } @DataProvider @@ -649,14 +650,14 @@ public void test_with_TemporalField_unsupported() { public void test_adjust1() { DiscordianDate base = DiscordianDate.of(2014, 0, 0); DiscordianDate test = base.with(TemporalAdjusters.lastDayOfMonth()); - assertEquals(test, DiscordianDate.of(2014, 0, 0)); + assertEquals(DiscordianDate.of(2014, 0, 0), test); } @Test public void test_adjust2() { DiscordianDate base = DiscordianDate.of(2012, 2, 23); DiscordianDate test = base.with(TemporalAdjusters.lastDayOfMonth()); - assertEquals(test, DiscordianDate.of(2012, 2, 73)); + assertEquals(DiscordianDate.of(2012, 2, 73), test); } //----------------------------------------------------------------------- @@ -666,7 +667,7 @@ public void test_adjust2() { public void test_adjust_toLocalDate() { DiscordianDate discordian = DiscordianDate.of(2000, 1, 4); DiscordianDate test = discordian.with(LocalDate.of(2012, 7, 6)); - assertEquals(test, DiscordianDate.of(3178, 3, 41)); + assertEquals(DiscordianDate.of(3178, 3, 41), test); } @Test(expected = DateTimeException.class) @@ -682,14 +683,14 @@ public void test_adjust_toMonth() { public void test_LocalDate_adjustToDiscordianDate() { DiscordianDate discordian = DiscordianDate.of(3178, 3, 41); LocalDate test = LocalDate.MIN.with(discordian); - assertEquals(test, LocalDate.of(2012, 7, 6)); + assertEquals(LocalDate.of(2012, 7, 6), test); } @Test public void test_LocalDateTime_adjustToDiscordianDate() { DiscordianDate discordian = DiscordianDate.of(3178, 3, 41); LocalDateTime test = LocalDateTime.MIN.with(discordian); - assertEquals(test, LocalDateTime.of(2012, 7, 6, 0, 0)); + assertEquals(LocalDateTime.of(2012, 7, 6, 0, 0), test); } //----------------------------------------------------------------------- @@ -769,7 +770,7 @@ public static Object[][] data_minus_leap() { public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(DiscordianDate.of(year, month, dom).plus(amount, unit), DiscordianDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(DiscordianDate.of(expectedYear, expectedMonth, expectedDom), DiscordianDate.of(year, month, dom).plus(amount, unit)); } @Test @@ -777,7 +778,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, public void test_plus_leap_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(DiscordianDate.of(year, month, dom).plus(amount, unit), DiscordianDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(DiscordianDate.of(expectedYear, expectedMonth, expectedDom), DiscordianDate.of(year, month, dom).plus(amount, unit)); } @Test @@ -786,7 +787,7 @@ public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, int year, int month, int dom) { - assertEquals(DiscordianDate.of(year, month, dom).minus(amount, unit), DiscordianDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(DiscordianDate.of(expectedYear, expectedMonth, expectedDom), DiscordianDate.of(year, month, dom).minus(amount, unit)); } @Test @@ -795,7 +796,7 @@ public void test_minus_leap_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, int year, int month, int dom) { - assertEquals(DiscordianDate.of(year, month, dom).minus(amount, unit), DiscordianDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(DiscordianDate.of(expectedYear, expectedMonth, expectedDom), DiscordianDate.of(year, month, dom).minus(amount, unit)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -926,7 +927,7 @@ public void test_until_TemporalUnit( TemporalUnit unit, long expected) { DiscordianDate start = DiscordianDate.of(year1, month1, dom1); DiscordianDate end = DiscordianDate.of(year2, month2, dom2); - assertEquals(start.until(end, unit), expected); + assertEquals(expected, start.until(end, unit)); } @Test @@ -938,7 +939,7 @@ public void test_until_end( DiscordianDate start = DiscordianDate.of(year1, month1, dom1); DiscordianDate end = DiscordianDate.of(year2, month2, dom2); ChronoPeriod period = DiscordianChronology.INSTANCE.period(yearPeriod, monthPeriod, domPeriod); - assertEquals(start.until(end), period); + assertEquals(period, start.until(end)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -951,22 +952,22 @@ public void test_until_TemporalUnit_unsupported() { //----------------------------------------------------------------------- @Test public void test_plus_Period() { - assertEquals(DiscordianDate.of(2014, 5, 26).plus(DiscordianChronology.INSTANCE.period(0, 2, 3)), DiscordianDate.of(2015, 2, 29)); + assertEquals(DiscordianDate.of(2015, 2, 29), DiscordianDate.of(2014, 5, 26).plus(DiscordianChronology.INSTANCE.period(0, 2, 3))); } @Test(expected = DateTimeException.class) public void test_plus_Period_ISO() { - assertEquals(DiscordianDate.of(2014, 5, 26).plus(Period.ofMonths(2)), DiscordianDate.of(2015, 2, 26)); + assertEquals(DiscordianDate.of(2015, 2, 26), DiscordianDate.of(2014, 5, 26).plus(Period.ofMonths(2))); } @Test public void test_minus_Period() { - assertEquals(DiscordianDate.of(2014, 5, 26).minus(DiscordianChronology.INSTANCE.period(0, 2, 3)), DiscordianDate.of(2014, 3, 23)); + assertEquals(DiscordianDate.of(2014, 3, 23), DiscordianDate.of(2014, 5, 26).minus(DiscordianChronology.INSTANCE.period(0, 2, 3))); } @Test(expected = DateTimeException.class) public void test_minus_Period_ISO() { - assertEquals(DiscordianDate.of(2014, 5, 26).minus(Period.ofMonths(2)), DiscordianDate.of(2014, 3, 26)); + assertEquals(DiscordianDate.of(2014, 3, 26), DiscordianDate.of(2014, 5, 26).minus(Period.ofMonths(2))); } //----------------------------------------------------------------------- @@ -980,16 +981,16 @@ public void test_equals() { DiscordianDate c = DiscordianDate.of(2000, 2, 3); DiscordianDate d = DiscordianDate.of(2001, 1, 3); - assertEquals(a1.equals(a1), true); - assertEquals(a1.equals(a2), true); - assertEquals(a1.equals(b), false); - assertEquals(a1.equals(c), false); - assertEquals(a1.equals(d), false); + assertEquals(true, a1.equals(a1)); + assertEquals(true, a1.equals(a2)); + assertEquals(false, a1.equals(b)); + assertEquals(false, a1.equals(c)); + assertEquals(false, a1.equals(d)); - assertEquals(a1.equals(null), false); - assertEquals(a1.equals(""), false); + assertEquals(false, a1.equals(null)); + assertEquals(false, a1.equals("")); - assertEquals(a1.hashCode(), a2.hashCode()); + assertTrue(a1.hashCode() == a2.hashCode()); } //----------------------------------------------------------------------- @@ -1007,7 +1008,7 @@ public static Object[][] data_toString() { @Test @UseDataProvider("data_toString") public void test_toString(DiscordianDate discordian, String expected) { - assertEquals(discordian.toString(), expected); + assertEquals(expected, discordian.toString()); } } diff --git a/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java b/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java index eff4688c..63167d74 100644 --- a/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java @@ -54,6 +54,7 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; @@ -91,18 +92,18 @@ public class TestEthiopicChronology { public void test_chronology_of_name() { Chronology chrono = Chronology.of("Ethiopic"); Assert.assertNotNull(chrono); - Assert.assertEquals(chrono, EthiopicChronology.INSTANCE); - Assert.assertEquals(chrono.getId(), "Ethiopic"); - Assert.assertEquals(chrono.getCalendarType(), "ethiopic"); + Assert.assertEquals(EthiopicChronology.INSTANCE, chrono); + Assert.assertEquals("Ethiopic", chrono.getId()); + Assert.assertEquals("ethiopic", chrono.getCalendarType()); } @Test public void test_chronology_of_name_id() { Chronology chrono = Chronology.of("ethiopic"); Assert.assertNotNull(chrono); - Assert.assertEquals(chrono, EthiopicChronology.INSTANCE); - Assert.assertEquals(chrono.getId(), "Ethiopic"); - Assert.assertEquals(chrono.getCalendarType(), "ethiopic"); + Assert.assertEquals(EthiopicChronology.INSTANCE, chrono); + Assert.assertEquals("Ethiopic", chrono.getId()); + Assert.assertEquals("ethiopic", chrono.getCalendarType()); } //----------------------------------------------------------------------- @@ -140,78 +141,78 @@ public static Object[][] data_samples() { @Test @UseDataProvider("data_samples") public void test_LocalDate_from_EthiopicDate(EthiopicDate ethiopic, LocalDate iso) { - assertEquals(LocalDate.from(ethiopic), iso); + assertEquals(iso, LocalDate.from(ethiopic)); } @Test @UseDataProvider("data_samples") public void test_EthiopicDate_from_LocalDate(EthiopicDate ethiopic, LocalDate iso) { - assertEquals(EthiopicDate.from(iso), ethiopic); + assertEquals(ethiopic, EthiopicDate.from(iso)); } @Test @UseDataProvider("data_samples") public void test_EthiopicDate_chronology_dateEpochDay(EthiopicDate ethiopic, LocalDate iso) { - assertEquals(EthiopicChronology.INSTANCE.dateEpochDay(iso.toEpochDay()), ethiopic); + assertEquals(ethiopic, EthiopicChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } @Test @UseDataProvider("data_samples") public void test_EthiopicDate_toEpochDay(EthiopicDate ethiopic, LocalDate iso) { - assertEquals(ethiopic.toEpochDay(), iso.toEpochDay()); + assertEquals(iso.toEpochDay(), ethiopic.toEpochDay()); } @Test @UseDataProvider("data_samples") public void test_EthiopicDate_until_EthiopicDate(EthiopicDate ethiopic, LocalDate iso) { - assertEquals(ethiopic.until(ethiopic), EthiopicChronology.INSTANCE.period(0, 0, 0)); + assertEquals(EthiopicChronology.INSTANCE.period(0, 0, 0), ethiopic.until(ethiopic)); } @Test @UseDataProvider("data_samples") public void test_EthiopicDate_until_LocalDate(EthiopicDate ethiopic, LocalDate iso) { - assertEquals(ethiopic.until(iso), EthiopicChronology.INSTANCE.period(0, 0, 0)); + assertEquals(EthiopicChronology.INSTANCE.period(0, 0, 0), ethiopic.until(iso)); } @Test @UseDataProvider("data_samples") public void test_LocalDate_until_EthiopicDate(EthiopicDate ethiopic, LocalDate iso) { - assertEquals(iso.until(ethiopic), Period.ZERO); + assertEquals(Period.ZERO, iso.until(ethiopic)); } @Test @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(EthiopicDate ethiopic, LocalDate iso) { - assertEquals(EthiopicChronology.INSTANCE.date(iso), ethiopic); + assertEquals(ethiopic, EthiopicChronology.INSTANCE.date(iso)); } @Test @UseDataProvider("data_samples") public void test_plusDays(EthiopicDate ethiopic, LocalDate iso) { - assertEquals(LocalDate.from(ethiopic.plus(0, DAYS)), iso); - assertEquals(LocalDate.from(ethiopic.plus(1, DAYS)), iso.plusDays(1)); - assertEquals(LocalDate.from(ethiopic.plus(35, DAYS)), iso.plusDays(35)); - assertEquals(LocalDate.from(ethiopic.plus(-1, DAYS)), iso.plusDays(-1)); - assertEquals(LocalDate.from(ethiopic.plus(-60, DAYS)), iso.plusDays(-60)); + assertEquals(iso, LocalDate.from(ethiopic.plus(0, DAYS))); + assertEquals(iso.plusDays(1), LocalDate.from(ethiopic.plus(1, DAYS))); + assertEquals(iso.plusDays(35), LocalDate.from(ethiopic.plus(35, DAYS))); + assertEquals(iso.plusDays(-1), LocalDate.from(ethiopic.plus(-1, DAYS))); + assertEquals(iso.plusDays(-60), LocalDate.from(ethiopic.plus(-60, DAYS))); } @Test @UseDataProvider("data_samples") public void test_minusDays(EthiopicDate ethiopic, LocalDate iso) { - assertEquals(LocalDate.from(ethiopic.minus(0, DAYS)), iso); - assertEquals(LocalDate.from(ethiopic.minus(1, DAYS)), iso.minusDays(1)); - assertEquals(LocalDate.from(ethiopic.minus(35, DAYS)), iso.minusDays(35)); - assertEquals(LocalDate.from(ethiopic.minus(-1, DAYS)), iso.minusDays(-1)); - assertEquals(LocalDate.from(ethiopic.minus(-60, DAYS)), iso.minusDays(-60)); + assertEquals(iso, LocalDate.from(ethiopic.minus(0, DAYS))); + assertEquals(iso.minusDays(1), LocalDate.from(ethiopic.minus(1, DAYS))); + assertEquals(iso.minusDays(35), LocalDate.from(ethiopic.minus(35, DAYS))); + assertEquals(iso.minusDays(-1), LocalDate.from(ethiopic.minus(-1, DAYS))); + assertEquals(iso.minusDays(-60), LocalDate.from(ethiopic.minus(-60, DAYS))); } @Test @UseDataProvider("data_samples") public void test_until_DAYS(EthiopicDate ethiopic, LocalDate iso) { - assertEquals(ethiopic.until(iso.plusDays(0), DAYS), 0); - assertEquals(ethiopic.until(iso.plusDays(1), DAYS), 1); - assertEquals(ethiopic.until(iso.plusDays(35), DAYS), 35); - assertEquals(ethiopic.until(iso.minusDays(40), DAYS), -40); + assertEquals(0, ethiopic.until(iso.plusDays(0), DAYS)); + assertEquals(1, ethiopic.until(iso.plusDays(1), DAYS)); + assertEquals(35, ethiopic.until(iso.plusDays(35), DAYS)); + assertEquals(-40, ethiopic.until(iso.minusDays(40), DAYS)); } @DataProvider @@ -264,28 +265,28 @@ public void test_chronology_dateYearDay_badDate() { public void test_isLeapYear_loop() { for (int year = -200; year < 200; year++) { EthiopicDate base = EthiopicDate.of(year, 1, 1); - assertEquals(base.isLeapYear(), ((year - 3) % 4) == 0); - assertEquals(EthiopicChronology.INSTANCE.isLeapYear(year), ((year + 400 - 3) % 4) == 0); + assertEquals(((year - 3) % 4) == 0, base.isLeapYear()); + assertEquals(((year + 400 - 3) % 4) == 0, EthiopicChronology.INSTANCE.isLeapYear(year)); } } @Test public void test_isLeapYear_specific() { - assertEquals(EthiopicChronology.INSTANCE.isLeapYear(8), false); - assertEquals(EthiopicChronology.INSTANCE.isLeapYear(7), true); - assertEquals(EthiopicChronology.INSTANCE.isLeapYear(6), false); - assertEquals(EthiopicChronology.INSTANCE.isLeapYear(5), false); - assertEquals(EthiopicChronology.INSTANCE.isLeapYear(4), false); - assertEquals(EthiopicChronology.INSTANCE.isLeapYear(3), true); - assertEquals(EthiopicChronology.INSTANCE.isLeapYear(2), false); - assertEquals(EthiopicChronology.INSTANCE.isLeapYear(1), false); - assertEquals(EthiopicChronology.INSTANCE.isLeapYear(0), false); - assertEquals(EthiopicChronology.INSTANCE.isLeapYear(-1), true); - assertEquals(EthiopicChronology.INSTANCE.isLeapYear(-2), false); - assertEquals(EthiopicChronology.INSTANCE.isLeapYear(-3), false); - assertEquals(EthiopicChronology.INSTANCE.isLeapYear(-4), false); - assertEquals(EthiopicChronology.INSTANCE.isLeapYear(-5), true); - assertEquals(EthiopicChronology.INSTANCE.isLeapYear(-6), false); + assertEquals(false, EthiopicChronology.INSTANCE.isLeapYear(8)); + assertEquals(true, EthiopicChronology.INSTANCE.isLeapYear(7)); + assertEquals(false, EthiopicChronology.INSTANCE.isLeapYear(6)); + assertEquals(false, EthiopicChronology.INSTANCE.isLeapYear(5)); + assertEquals(false, EthiopicChronology.INSTANCE.isLeapYear(4)); + assertEquals(true, EthiopicChronology.INSTANCE.isLeapYear(3)); + assertEquals(false, EthiopicChronology.INSTANCE.isLeapYear(2)); + assertEquals(false, EthiopicChronology.INSTANCE.isLeapYear(1)); + assertEquals(false, EthiopicChronology.INSTANCE.isLeapYear(0)); + assertEquals(true, EthiopicChronology.INSTANCE.isLeapYear(-1)); + assertEquals(false, EthiopicChronology.INSTANCE.isLeapYear(-2)); + assertEquals(false, EthiopicChronology.INSTANCE.isLeapYear(-3)); + assertEquals(false, EthiopicChronology.INSTANCE.isLeapYear(-4)); + assertEquals(true, EthiopicChronology.INSTANCE.isLeapYear(-5)); + assertEquals(false, EthiopicChronology.INSTANCE.isLeapYear(-6)); } @DataProvider @@ -311,7 +312,7 @@ public static Object[][] data_lengthOfMonth() { @Test @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { - assertEquals(EthiopicDate.of(year, month, 1).lengthOfMonth(), length); + assertEquals(length, EthiopicDate.of(year, month, 1).lengthOfMonth()); } //----------------------------------------------------------------------- @@ -327,7 +328,7 @@ public void test_era_loop() { int yoe = (year <= 0 ? 1 - year : year); assertEquals(yoe, base.get(YEAR_OF_ERA)); EthiopicDate eraBased = EthiopicChronology.INSTANCE.date(era, yoe, 1, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } } @@ -341,26 +342,26 @@ public void test_era_yearDay_loop() { int yoe = (year <= 0 ? 1 - year : year); assertEquals(yoe, base.get(YEAR_OF_ERA)); EthiopicDate eraBased = EthiopicChronology.INSTANCE.dateYearDay(era, yoe, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } } @Test public void test_prolepticYear_specific() { - assertEquals(EthiopicChronology.INSTANCE.prolepticYear(EthiopicEra.INCARNATION, 4), 4); - assertEquals(EthiopicChronology.INSTANCE.prolepticYear(EthiopicEra.INCARNATION, 3), 3); - assertEquals(EthiopicChronology.INSTANCE.prolepticYear(EthiopicEra.INCARNATION, 2), 2); - assertEquals(EthiopicChronology.INSTANCE.prolepticYear(EthiopicEra.INCARNATION, 1), 1); - assertEquals(EthiopicChronology.INSTANCE.prolepticYear(EthiopicEra.BEFORE_INCARNATION, 1), 0); - assertEquals(EthiopicChronology.INSTANCE.prolepticYear(EthiopicEra.BEFORE_INCARNATION, 2), -1); - assertEquals(EthiopicChronology.INSTANCE.prolepticYear(EthiopicEra.BEFORE_INCARNATION, 3), -2); - assertEquals(EthiopicChronology.INSTANCE.prolepticYear(EthiopicEra.BEFORE_INCARNATION, 4), -3); + assertEquals(4, EthiopicChronology.INSTANCE.prolepticYear(EthiopicEra.INCARNATION, 4)); + assertEquals(3, EthiopicChronology.INSTANCE.prolepticYear(EthiopicEra.INCARNATION, 3)); + assertEquals(2, EthiopicChronology.INSTANCE.prolepticYear(EthiopicEra.INCARNATION, 2)); + assertEquals(1, EthiopicChronology.INSTANCE.prolepticYear(EthiopicEra.INCARNATION, 1)); + assertEquals(0, EthiopicChronology.INSTANCE.prolepticYear(EthiopicEra.BEFORE_INCARNATION, 1)); + assertEquals(-1, EthiopicChronology.INSTANCE.prolepticYear(EthiopicEra.BEFORE_INCARNATION, 2)); + assertEquals(-2, EthiopicChronology.INSTANCE.prolepticYear(EthiopicEra.BEFORE_INCARNATION, 3)); + assertEquals(-3, EthiopicChronology.INSTANCE.prolepticYear(EthiopicEra.BEFORE_INCARNATION, 4)); } @Test public void test_Chronology_eraOf() { - assertEquals(EthiopicChronology.INSTANCE.eraOf(1), EthiopicEra.INCARNATION); - assertEquals(EthiopicChronology.INSTANCE.eraOf(0), EthiopicEra.BEFORE_INCARNATION); + assertEquals(EthiopicEra.INCARNATION, EthiopicChronology.INSTANCE.eraOf(1)); + assertEquals(EthiopicEra.BEFORE_INCARNATION, EthiopicChronology.INSTANCE.eraOf(0)); } @Test(expected = DateTimeException.class) @@ -371,9 +372,9 @@ public void test_Chronology_eraOf_invalid() { @Test public void test_Chronology_eras() { List eras = EthiopicChronology.INSTANCE.eras(); - assertEquals(eras.size(), 2); - assertEquals(eras.contains(EthiopicEra.BEFORE_INCARNATION), true); - assertEquals(eras.contains(EthiopicEra.INCARNATION), true); + assertEquals(2, eras.size()); + assertEquals(true, eras.contains(EthiopicEra.BEFORE_INCARNATION)); + assertEquals(true, eras.contains(EthiopicEra.INCARNATION)); } //----------------------------------------------------------------------- @@ -381,10 +382,10 @@ public void test_Chronology_eras() { //----------------------------------------------------------------------- @Test public void test_Chronology_range() { - assertEquals(EthiopicChronology.INSTANCE.range(DAY_OF_WEEK), ValueRange.of(1, 7)); - assertEquals(EthiopicChronology.INSTANCE.range(DAY_OF_MONTH), ValueRange.of(1, 5, 30)); - assertEquals(EthiopicChronology.INSTANCE.range(DAY_OF_YEAR), ValueRange.of(1, 365, 366)); - assertEquals(EthiopicChronology.INSTANCE.range(MONTH_OF_YEAR), ValueRange.of(1, 13)); + assertEquals(ValueRange.of(1, 7), EthiopicChronology.INSTANCE.range(DAY_OF_WEEK)); + assertEquals(ValueRange.of(1, 5, 30), EthiopicChronology.INSTANCE.range(DAY_OF_MONTH)); + assertEquals(ValueRange.of(1, 365, 366), EthiopicChronology.INSTANCE.range(DAY_OF_YEAR)); + assertEquals(ValueRange.of(1, 13), EthiopicChronology.INSTANCE.range(MONTH_OF_YEAR)); } //----------------------------------------------------------------------- @@ -422,7 +423,7 @@ public static Object[][] data_ranges() { @Test @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { - assertEquals(EthiopicDate.of(year, month, dom).range(field), ValueRange.of(expectedMin, expectedMax)); + assertEquals(ValueRange.of(expectedMin, expectedMax), EthiopicDate.of(year, month, dom).range(field)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -457,7 +458,7 @@ public static Object[][] data_getLong() { @Test @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { - assertEquals(EthiopicDate.of(year, month, dom).getLong(field), expected); + assertEquals(expected, EthiopicDate.of(year, month, dom).getLong(field)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -512,7 +513,7 @@ public static Object[][] data_with() { public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(EthiopicDate.of(year, month, dom).with(field, value), EthiopicDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(EthiopicDate.of(expectedYear, expectedMonth, expectedDom), EthiopicDate.of(year, month, dom).with(field, value)); } @DataProvider @@ -548,14 +549,14 @@ public void test_with_TemporalField_unsupported() { public void test_adjust1() { EthiopicDate base = EthiopicDate.of(2005, 10, 29); EthiopicDate test = base.with(TemporalAdjusters.lastDayOfMonth()); - assertEquals(test, EthiopicDate.of(2005, 10, 30)); + assertEquals(EthiopicDate.of(2005, 10, 30), test); } @Test public void test_adjust2() { EthiopicDate base = EthiopicDate.of(2005, 13, 2); EthiopicDate test = base.with(TemporalAdjusters.lastDayOfMonth()); - assertEquals(test, EthiopicDate.of(2005, 13, 5)); + assertEquals(EthiopicDate.of(2005, 13, 5), test); } //----------------------------------------------------------------------- @@ -565,7 +566,7 @@ public void test_adjust2() { public void test_adjust_toLocalDate() { EthiopicDate ethiopic = EthiopicDate.of(2001, 1, 4); EthiopicDate test = ethiopic.with(LocalDate.of(2011, 10, 16)); - assertEquals(test, EthiopicDate.of(2004, 2, 5)); + assertEquals(EthiopicDate.of(2004, 2, 5), test); } @Test(expected = DateTimeException.class) @@ -581,14 +582,14 @@ public void test_adjust_toMonth() { public void test_LocalDate_adjustToEthiopicDate() { EthiopicDate ethiopic = EthiopicDate.of(2004, 2, 5); LocalDate test = LocalDate.MIN.with(ethiopic); - assertEquals(test, LocalDate.of(2011, 10, 16)); + assertEquals(LocalDate.of(2011, 10, 16), test); } @Test public void test_LocalDateTime_adjustToEthiopicDate() { EthiopicDate ethiopic = EthiopicDate.of(2004, 2, 5); LocalDateTime test = LocalDateTime.MIN.with(ethiopic); - assertEquals(test, LocalDateTime.of(2011, 10, 16, 0, 0)); + assertEquals(LocalDateTime.of(2011, 10, 16, 0, 0), test); } //----------------------------------------------------------------------- @@ -627,7 +628,7 @@ public static Object[][] data_plus() { public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(EthiopicDate.of(year, month, dom).plus(amount, unit), EthiopicDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(EthiopicDate.of(expectedYear, expectedMonth, expectedDom), EthiopicDate.of(year, month, dom).plus(amount, unit)); } @Test @@ -636,7 +637,7 @@ public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, int year, int month, int dom) { - assertEquals(EthiopicDate.of(year, month, dom).minus(amount, unit), EthiopicDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(EthiopicDate.of(expectedYear, expectedMonth, expectedDom), EthiopicDate.of(year, month, dom).minus(amount, unit)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -647,22 +648,22 @@ public void test_plus_TemporalUnit_unsupported() { //----------------------------------------------------------------------- @Test public void test_plus_Period() { - assertEquals(EthiopicDate.of(2006, 5, 26).plus(EthiopicChronology.INSTANCE.period(0, 2, 3)), EthiopicDate.of(2006, 7, 29)); + assertEquals(EthiopicDate.of(2006, 7, 29), EthiopicDate.of(2006, 5, 26).plus(EthiopicChronology.INSTANCE.period(0, 2, 3))); } @Test(expected = DateTimeException.class) public void test_plus_Period_ISO() { - assertEquals(EthiopicDate.of(2006, 5, 26).plus(Period.ofMonths(2)), EthiopicDate.of(2006, 7, 26)); + assertEquals(EthiopicDate.of(2006, 7, 26), EthiopicDate.of(2006, 5, 26).plus(Period.ofMonths(2))); } @Test public void test_minus_Period() { - assertEquals(EthiopicDate.of(2006, 5, 26).minus(EthiopicChronology.INSTANCE.period(0, 2, 3)), EthiopicDate.of(2006, 3, 23)); + assertEquals(EthiopicDate.of(2006, 3, 23), EthiopicDate.of(2006, 5, 26).minus(EthiopicChronology.INSTANCE.period(0, 2, 3))); } @Test(expected = DateTimeException.class) public void test_minus_Period_ISO() { - assertEquals(EthiopicDate.of(2006, 5, 26).minus(Period.ofMonths(2)), EthiopicDate.of(2006, 3, 26)); + assertEquals(EthiopicDate.of(2006, 3, 26), EthiopicDate.of(2006, 5, 26).minus(Period.ofMonths(2))); } //----------------------------------------------------------------------- @@ -703,7 +704,7 @@ public void test_until_TemporalUnit( TemporalUnit unit, long expected) { EthiopicDate start = EthiopicDate.of(year1, month1, dom1); EthiopicDate end = EthiopicDate.of(year2, month2, dom2); - assertEquals(start.until(end, unit), expected); + assertEquals(expected, start.until(end, unit)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -724,16 +725,16 @@ public void test_equals() { EthiopicDate c = EthiopicDate.of(2004, 2, 3); EthiopicDate d = EthiopicDate.of(2005, 1, 3); - assertEquals(a1.equals(a1), true); - assertEquals(a1.equals(a2), true); - assertEquals(a1.equals(b), false); - assertEquals(a1.equals(c), false); - assertEquals(a1.equals(d), false); + assertEquals(true, a1.equals(a1)); + assertEquals(true, a1.equals(a2)); + assertEquals(false, a1.equals(b)); + assertEquals(false, a1.equals(c)); + assertEquals(false, a1.equals(d)); - assertEquals(a1.equals(null), false); - assertEquals(a1.equals(""), false); + assertEquals(false, a1.equals(null)); + assertEquals(false, a1.equals("")); - assertEquals(a1.hashCode(), a2.hashCode()); + assertTrue(a1.hashCode() == a2.hashCode()); } //----------------------------------------------------------------------- @@ -753,7 +754,7 @@ public static Object[][] data_toString() { @Test @UseDataProvider("data_toString") public void test_toString(EthiopicDate ethiopic, String expected) { - assertEquals(ethiopic.toString(), expected); + assertEquals(expected, ethiopic.toString()); } } diff --git a/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java b/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java index 9da4e1d4..6a5afb4e 100644 --- a/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java @@ -97,9 +97,9 @@ public class TestInternationalFixedChronology { public void test_chronology() { Chronology chrono = Chronology.of("Ifc"); assertNotNull(chrono); - assertEquals(chrono, InternationalFixedChronology.INSTANCE); - assertEquals(chrono.getId(), "Ifc"); - assertEquals(chrono.getCalendarType(), null); + assertEquals(InternationalFixedChronology.INSTANCE, chrono); + assertEquals("Ifc", chrono.getId()); + assertEquals(null, chrono.getCalendarType()); } //----------------------------------------------------------------------- @@ -155,84 +155,84 @@ public static Object[][] data_samples() { @Test @UseDataProvider("data_samples") public void test_LocalDate_from_InternationalFixedDate(InternationalFixedDate fixed, LocalDate iso) { - assertEquals(LocalDate.from(fixed), iso); + assertEquals(iso, LocalDate.from(fixed)); } @Test @UseDataProvider("data_samples") public void test_InternationalFixedDate_from_LocalDate(InternationalFixedDate fixed, LocalDate iso) { - assertEquals(InternationalFixedDate.from(iso), fixed); + assertEquals(fixed, InternationalFixedDate.from(iso)); } @Test @UseDataProvider("data_samples") public void test_InternationalFixedDate_chronology_dateEpochDay(InternationalFixedDate fixed, LocalDate iso) { - assertEquals(InternationalFixedChronology.INSTANCE.dateEpochDay(iso.toEpochDay()), fixed); + assertEquals(fixed, InternationalFixedChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } @Test @UseDataProvider("data_samples") public void test_InternationalFixedDate_toEpochDay(InternationalFixedDate fixed, LocalDate iso) { - assertEquals(fixed.toEpochDay(), iso.toEpochDay()); + assertEquals(iso.toEpochDay(), fixed.toEpochDay()); } @Test @UseDataProvider("data_samples") public void test_InternationalFixedDate_until_InternationalFixedDate(InternationalFixedDate fixed, LocalDate iso) { - assertEquals(fixed.until(fixed), InternationalFixedChronology.INSTANCE.period(0, 0, 0)); + assertEquals(InternationalFixedChronology.INSTANCE.period(0, 0, 0), fixed.until(fixed)); } @Test @UseDataProvider("data_samples") public void test_InternationalFixedDate_until_LocalDate(InternationalFixedDate fixed, LocalDate iso) { - assertEquals(fixed.until(iso), InternationalFixedChronology.INSTANCE.period(0, 0, 0)); + assertEquals(InternationalFixedChronology.INSTANCE.period(0, 0, 0), fixed.until(iso)); } @Test @UseDataProvider("data_samples") public void test_LocalDate_until_InternationalFixedDate(InternationalFixedDate fixed, LocalDate iso) { - assertEquals(iso.until(fixed), Period.ZERO); + assertEquals(Period.ZERO, iso.until(fixed)); } @Test @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(InternationalFixedDate fixed, LocalDate iso) { - assertEquals(InternationalFixedChronology.INSTANCE.date(iso), fixed); + assertEquals(fixed, InternationalFixedChronology.INSTANCE.date(iso)); } @Test @UseDataProvider("data_samples") public void test_plusDays(InternationalFixedDate fixed, LocalDate iso) { - assertEquals(LocalDate.from(fixed.plus(0, DAYS)), iso); - assertEquals(LocalDate.from(fixed.plus(1, DAYS)), iso.plusDays(1)); - assertEquals(LocalDate.from(fixed.plus(35, DAYS)), iso.plusDays(35)); + assertEquals(iso, LocalDate.from(fixed.plus(0, DAYS))); + assertEquals(iso.plusDays(1), LocalDate.from(fixed.plus(1, DAYS))); + assertEquals(iso.plusDays(35), LocalDate.from(fixed.plus(35, DAYS))); if (LocalDate.ofYearDay(1, 60).isBefore(iso)) { - assertEquals(LocalDate.from(fixed.plus(-1, DAYS)), iso.plusDays(-1)); - assertEquals(LocalDate.from(fixed.plus(-60, DAYS)), iso.plusDays(-60)); + assertEquals(iso.plusDays(-1), LocalDate.from(fixed.plus(-1, DAYS))); + assertEquals(iso.plusDays(-60), LocalDate.from(fixed.plus(-60, DAYS))); } } @Test @UseDataProvider("data_samples") public void test_minusDays(InternationalFixedDate fixed, LocalDate iso) { - assertEquals(LocalDate.from(fixed.minus(0, DAYS)), iso); + assertEquals(iso, LocalDate.from(fixed.minus(0, DAYS))); if (LocalDate.ofYearDay(1, 35).isBefore(iso)) { - assertEquals(LocalDate.from(fixed.minus(1, DAYS)), iso.minusDays(1)); - assertEquals(LocalDate.from(fixed.minus(35, DAYS)), iso.minusDays(35)); + assertEquals(iso.minusDays(1), LocalDate.from(fixed.minus(1, DAYS))); + assertEquals(iso.minusDays(35), LocalDate.from(fixed.minus(35, DAYS))); } - assertEquals(LocalDate.from(fixed.minus(-1, DAYS)), iso.minusDays(-1)); - assertEquals(LocalDate.from(fixed.minus(-60, DAYS)), iso.minusDays(-60)); + assertEquals(iso.minusDays(-1), LocalDate.from(fixed.minus(-1, DAYS))); + assertEquals(iso.minusDays(-60), LocalDate.from(fixed.minus(-60, DAYS))); } @Test @UseDataProvider("data_samples") public void test_until_DAYS(InternationalFixedDate fixed, LocalDate iso) { - assertEquals(fixed.until(iso.plusDays(0), DAYS), 0); - assertEquals(fixed.until(iso.plusDays(1), DAYS), 1); - assertEquals(fixed.until(iso.plusDays(35), DAYS), 35); + assertEquals(0, fixed.until(iso.plusDays(0), DAYS)); + assertEquals(1, fixed.until(iso.plusDays(1), DAYS)); + assertEquals(35, fixed.until(iso.plusDays(35), DAYS)); if (LocalDate.ofYearDay(1, 40).isBefore(iso)) { - assertEquals(fixed.until(iso.minusDays(40), DAYS), -40); + assertEquals(-40, fixed.until(iso.minusDays(40), DAYS)); } } @@ -316,9 +316,9 @@ public void test_isLeapYear_loop() { for (int year = 1; year < 500; year++) { InternationalFixedDate base = InternationalFixedDate.of(year, 1, 1); - assertEquals(base.isLeapYear(), isLeapYear.test(year)); - assertEquals(base.lengthOfYear(), isLeapYear.test(year) ? 366 : 365); - assertEquals(InternationalFixedChronology.INSTANCE.isLeapYear(year), isLeapYear.test(year)); + assertEquals(isLeapYear.test(year), base.isLeapYear()); + assertEquals(isLeapYear.test(year) ? 366 : 365, base.lengthOfYear()); + assertEquals(isLeapYear.test(year), InternationalFixedChronology.INSTANCE.isLeapYear(year)); } } @@ -358,20 +358,20 @@ public static Object[][] data_lengthOfMonth() { @Test @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int day, int length) { - assertEquals(InternationalFixedDate.of(year, month, day).lengthOfMonth(), length); + assertEquals(length, InternationalFixedDate.of(year, month, day).lengthOfMonth()); } @Test @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonthFirst(int year, int month, int day, int length) { - assertEquals(InternationalFixedDate.of(year, month, 1).lengthOfMonth(), length); + assertEquals(length, InternationalFixedDate.of(year, month, 1).lengthOfMonth()); } @Test public void test_lengthOfMonth_specific() { - assertEquals(InternationalFixedDate.of(1900, 13, 29).lengthOfMonth(), 29); - assertEquals(InternationalFixedDate.of(2000, 13, 29).lengthOfMonth(), 29); - assertEquals(InternationalFixedDate.of(2000, 6, 29).lengthOfMonth(), 29); + assertEquals(29, InternationalFixedDate.of(1900, 13, 29).lengthOfMonth()); + assertEquals(29, InternationalFixedDate.of(2000, 13, 29).lengthOfMonth()); + assertEquals(29, InternationalFixedDate.of(2000, 6, 29).lengthOfMonth()); } //----------------------------------------------------------------------- @@ -386,7 +386,7 @@ public void test_era_loop() { assertEquals(era, base.getEra()); assertEquals(year, base.get(YEAR_OF_ERA)); InternationalFixedDate eraBased = InternationalFixedChronology.INSTANCE.date(era, year, 1, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } } @@ -399,18 +399,18 @@ public void test_era_yearDay_loop() { assertEquals(era, base.getEra()); assertEquals(year, base.get(YEAR_OF_ERA)); InternationalFixedDate eraBased = InternationalFixedChronology.INSTANCE.dateYearDay(era, year, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } } @Test public void test_prolepticYear_specific() { - assertEquals(InternationalFixedChronology.INSTANCE.prolepticYear(InternationalFixedEra.CE, 4), 4); - assertEquals(InternationalFixedChronology.INSTANCE.prolepticYear(InternationalFixedEra.CE, 3), 3); - assertEquals(InternationalFixedChronology.INSTANCE.prolepticYear(InternationalFixedEra.CE, 2), 2); - assertEquals(InternationalFixedChronology.INSTANCE.prolepticYear(InternationalFixedEra.CE, 1), 1); - assertEquals(InternationalFixedChronology.INSTANCE.prolepticYear(InternationalFixedEra.CE, 2000), 2000); - assertEquals(InternationalFixedChronology.INSTANCE.prolepticYear(InternationalFixedEra.CE, 1582), 1582); + assertEquals(4, InternationalFixedChronology.INSTANCE.prolepticYear(InternationalFixedEra.CE, 4)); + assertEquals(3, InternationalFixedChronology.INSTANCE.prolepticYear(InternationalFixedEra.CE, 3)); + assertEquals(2, InternationalFixedChronology.INSTANCE.prolepticYear(InternationalFixedEra.CE, 2)); + assertEquals(1, InternationalFixedChronology.INSTANCE.prolepticYear(InternationalFixedEra.CE, 1)); + assertEquals(2000, InternationalFixedChronology.INSTANCE.prolepticYear(InternationalFixedEra.CE, 2000)); + assertEquals(1582, InternationalFixedChronology.INSTANCE.prolepticYear(InternationalFixedEra.CE, 1582)); } @DataProvider @@ -435,7 +435,7 @@ public void test_prolepticYear_badEra() { @Test public void test_Chronology_eraOf() { - assertEquals(InternationalFixedChronology.INSTANCE.eraOf(1), InternationalFixedEra.CE); + assertEquals(InternationalFixedEra.CE, InternationalFixedChronology.INSTANCE.eraOf(1)); } @Test(expected = DateTimeException.class) @@ -446,7 +446,7 @@ public void test_Chronology_eraOf_invalid() { @Test public void test_Chronology_eras() { List eras = InternationalFixedChronology.INSTANCE.eras(); - assertEquals(eras.size(), 1); + assertEquals(1, eras.size()); assertTrue(eras.contains(InternationalFixedEra.CE)); } @@ -455,19 +455,19 @@ public void test_Chronology_eras() { //----------------------------------------------------------------------- @Test public void test_Chronology_range() { - assertEquals(InternationalFixedChronology.INSTANCE.range(ALIGNED_DAY_OF_WEEK_IN_MONTH), ValueRange.of(0, 1, 0, 7)); - assertEquals(InternationalFixedChronology.INSTANCE.range(ALIGNED_DAY_OF_WEEK_IN_YEAR), ValueRange.of(0, 1, 0, 7)); - assertEquals(InternationalFixedChronology.INSTANCE.range(ALIGNED_WEEK_OF_MONTH), ValueRange.of(0, 1, 0, 4)); - assertEquals(InternationalFixedChronology.INSTANCE.range(ALIGNED_WEEK_OF_YEAR), ValueRange.of(0, 1, 0, 52)); - assertEquals(InternationalFixedChronology.INSTANCE.range(DAY_OF_WEEK), ValueRange.of(0, 1, 0, 7)); - assertEquals(InternationalFixedChronology.INSTANCE.range(DAY_OF_MONTH), ValueRange.of(1, 29)); - assertEquals(InternationalFixedChronology.INSTANCE.range(DAY_OF_YEAR), ValueRange.of(1, 365, 366)); - assertEquals(InternationalFixedChronology.INSTANCE.range(ERA), ValueRange.of(1, 1)); - assertEquals(InternationalFixedChronology.INSTANCE.range(EPOCH_DAY), ValueRange.of(-719_528, 1_000_000 * 365L + 242_499 - 719_528)); - assertEquals(InternationalFixedChronology.INSTANCE.range(MONTH_OF_YEAR), ValueRange.of(1, 13)); - assertEquals(InternationalFixedChronology.INSTANCE.range(PROLEPTIC_MONTH), ValueRange.of(13, 1_000_000 * 13L - 1)); - assertEquals(InternationalFixedChronology.INSTANCE.range(YEAR), ValueRange.of(1, 1_000_000)); - assertEquals(InternationalFixedChronology.INSTANCE.range(YEAR_OF_ERA), ValueRange.of(1, 1_000_000)); + assertEquals(ValueRange.of(0, 1, 0, 7), InternationalFixedChronology.INSTANCE.range(ALIGNED_DAY_OF_WEEK_IN_MONTH)); + assertEquals(ValueRange.of(0, 1, 0, 7), InternationalFixedChronology.INSTANCE.range(ALIGNED_DAY_OF_WEEK_IN_YEAR)); + assertEquals(ValueRange.of(0, 1, 0, 4), InternationalFixedChronology.INSTANCE.range(ALIGNED_WEEK_OF_MONTH)); + assertEquals(ValueRange.of(0, 1, 0, 52), InternationalFixedChronology.INSTANCE.range(ALIGNED_WEEK_OF_YEAR)); + assertEquals(ValueRange.of(0, 1, 0, 7), InternationalFixedChronology.INSTANCE.range(DAY_OF_WEEK)); + assertEquals(ValueRange.of(1, 29), InternationalFixedChronology.INSTANCE.range(DAY_OF_MONTH)); + assertEquals(ValueRange.of(1, 365, 366), InternationalFixedChronology.INSTANCE.range(DAY_OF_YEAR)); + assertEquals(ValueRange.of(1, 1), InternationalFixedChronology.INSTANCE.range(ERA)); + assertEquals(ValueRange.of(-719_528, 1_000_000 * 365L + 242_499 - 719_528), InternationalFixedChronology.INSTANCE.range(EPOCH_DAY)); + assertEquals(ValueRange.of(1, 13), InternationalFixedChronology.INSTANCE.range(MONTH_OF_YEAR)); + assertEquals(ValueRange.of(13, 1_000_000 * 13L - 1), InternationalFixedChronology.INSTANCE.range(PROLEPTIC_MONTH)); + assertEquals(ValueRange.of(1, 1_000_000), InternationalFixedChronology.INSTANCE.range(YEAR)); + assertEquals(ValueRange.of(1, 1_000_000), InternationalFixedChronology.INSTANCE.range(YEAR_OF_ERA)); } //----------------------------------------------------------------------- @@ -536,7 +536,7 @@ public static Object[][] data_ranges() { @Test @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, ValueRange range) { - assertEquals(InternationalFixedDate.of(year, month, dom).range(field), range); + assertEquals(range, InternationalFixedDate.of(year, month, dom).range(field)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -618,7 +618,7 @@ public static Object[][] data_getLong() { @Test @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { - assertEquals(InternationalFixedDate.of(year, month, dom).getLong(field), expected); + assertEquals(expected, InternationalFixedDate.of(year, month, dom).getLong(field)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -768,7 +768,7 @@ public static Object[][] data_with() { public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(InternationalFixedDate.of(year, month, dom).with(field, value), InternationalFixedDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(InternationalFixedDate.of(expectedYear, expectedMonth, expectedDom), InternationalFixedDate.of(year, month, dom).with(field, value)); } @DataProvider @@ -861,7 +861,7 @@ public void test_temporalAdjusters_LastDayOfMonth(int year, int month, int day, InternationalFixedDate base = InternationalFixedDate.of(year, month, day); InternationalFixedDate expected = InternationalFixedDate.of(expectedYear, expectedMonth, expectedDay); InternationalFixedDate actual = base.with(TemporalAdjusters.lastDayOfMonth()); - assertEquals(actual, expected); + assertEquals(expected, actual); } //----------------------------------------------------------------------- @@ -871,7 +871,7 @@ public void test_temporalAdjusters_LastDayOfMonth(int year, int month, int day, public void test_adjust_toLocalDate() { InternationalFixedDate fixed = InternationalFixedDate.of(2000, 1, 4); InternationalFixedDate test = fixed.with(LocalDate.of(2012, 7, 6)); - assertEquals(test, InternationalFixedDate.of(2012, 7, 19)); + assertEquals(InternationalFixedDate.of(2012, 7, 19), test); } @Test(expected = DateTimeException.class) @@ -887,14 +887,14 @@ public void test_adjust_toMonth() { public void test_LocalDate_adjustToInternationalFixedDate() { InternationalFixedDate fixed = InternationalFixedDate.of(2012, 7, 19); LocalDate test = LocalDate.MIN.with(fixed); - assertEquals(test, LocalDate.of(2012, 7, 6)); + assertEquals(LocalDate.of(2012, 7, 6), test); } @Test public void test_LocalDateTime_adjustToInternationalFixedDate() { InternationalFixedDate fixed = InternationalFixedDate.of(2012, 7, 19); LocalDateTime test = LocalDateTime.MIN.with(fixed); - assertEquals(test, LocalDateTime.of(2012, 7, 6, 0, 0)); + assertEquals(LocalDateTime.of(2012, 7, 6, 0, 0), test); } //----------------------------------------------------------------------- @@ -1027,7 +1027,7 @@ public static Object[][] data_minus_leap_and_year_day() { public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(InternationalFixedDate.of(year, month, dom).plus(amount, unit), InternationalFixedDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(InternationalFixedDate.of(expectedYear, expectedMonth, expectedDom), InternationalFixedDate.of(year, month, dom).plus(amount, unit)); } @Test @@ -1035,7 +1035,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, public void test_plus_leap_and_year_day_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(InternationalFixedDate.of(year, month, dom).plus(amount, unit), InternationalFixedDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(InternationalFixedDate.of(expectedYear, expectedMonth, expectedDom), InternationalFixedDate.of(year, month, dom).plus(amount, unit)); } @Test @@ -1044,7 +1044,7 @@ public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, int year, int month, int dom) { - assertEquals(InternationalFixedDate.of(year, month, dom).minus(amount, unit), InternationalFixedDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(InternationalFixedDate.of(expectedYear, expectedMonth, expectedDom), InternationalFixedDate.of(year, month, dom).minus(amount, unit)); } @Test @@ -1053,7 +1053,7 @@ public void test_minus_leap_and_year_day_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, int year, int month, int dom) { - assertEquals(InternationalFixedDate.of(year, month, dom).minus(amount, unit), InternationalFixedDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(InternationalFixedDate.of(expectedYear, expectedMonth, expectedDom), InternationalFixedDate.of(year, month, dom).minus(amount, unit)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -1280,7 +1280,7 @@ public void test_until_TemporalUnit( TemporalUnit unit, long expected) { InternationalFixedDate start = InternationalFixedDate.of(year1, month1, dom1); InternationalFixedDate end = InternationalFixedDate.of(year2, month2, dom2); - assertEquals(start.until(end, unit), expected); + assertEquals(expected, start.until(end, unit)); } @Test @@ -1292,7 +1292,7 @@ public void test_until_end( InternationalFixedDate start = InternationalFixedDate.of(year1, month1, dom1); InternationalFixedDate end = InternationalFixedDate.of(year2, month2, dom2); ChronoPeriod period = InternationalFixedChronology.INSTANCE.period(yearPeriod, monthPeriod, dayPeriod); - assertEquals(start.until(end), period); + assertEquals(period, start.until(end)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -1307,22 +1307,22 @@ public void test_until_TemporalUnit_unsupported() { //----------------------------------------------------------------------- @Test public void test_plus_Period() { - assertEquals(InternationalFixedDate.of(2014, 5, 26).plus(InternationalFixedChronology.INSTANCE.period(0, 2, 3)), InternationalFixedDate.of(2014, 8, 1)); + assertEquals(InternationalFixedDate.of(2014, 8, 1), InternationalFixedDate.of(2014, 5, 26).plus(InternationalFixedChronology.INSTANCE.period(0, 2, 3))); } @Test(expected = DateTimeException.class) public void test_plus_Period_ISO() { - assertEquals(InternationalFixedDate.of(2014, 5, 26).plus(Period.ofMonths(2)), InternationalFixedDate.of(2014, 7, 26)); + assertEquals(InternationalFixedDate.of(2014, 7, 26), InternationalFixedDate.of(2014, 5, 26).plus(Period.ofMonths(2))); } @Test public void test_minus_Period() { - assertEquals(InternationalFixedDate.of(2014, 5, 26).minus(InternationalFixedChronology.INSTANCE.period(0, 2, 3)), InternationalFixedDate.of(2014, 3, 23)); + assertEquals(InternationalFixedDate.of(2014, 3, 23), InternationalFixedDate.of(2014, 5, 26).minus(InternationalFixedChronology.INSTANCE.period(0, 2, 3))); } @Test(expected = DateTimeException.class) public void test_minus_Period_ISO() { - assertEquals(InternationalFixedDate.of(2014, 5, 26).minus(Period.ofMonths(2)), InternationalFixedDate.of(2014, 3, 26)); + assertEquals(InternationalFixedDate.of(2014, 3, 26), InternationalFixedDate.of(2014, 5, 26).minus(Period.ofMonths(2))); } //----------------------------------------------------------------------- @@ -1371,6 +1371,6 @@ public static Object[][] data_toString() { @Test @UseDataProvider("data_toString") public void test_toString(InternationalFixedDate date, String expected) { - assertEquals(date.toString(), expected); + assertEquals(expected, date.toString()); } } diff --git a/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java b/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java index 7010eac2..5080828d 100644 --- a/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java @@ -54,6 +54,7 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; @@ -92,18 +93,18 @@ public class TestJulianChronology { public void test_chronology_of_name() { Chronology chrono = Chronology.of("Julian"); Assert.assertNotNull(chrono); - Assert.assertEquals(chrono, JulianChronology.INSTANCE); - Assert.assertEquals(chrono.getId(), "Julian"); - Assert.assertEquals(chrono.getCalendarType(), "julian"); + Assert.assertEquals(JulianChronology.INSTANCE, chrono); + Assert.assertEquals("Julian", chrono.getId()); + Assert.assertEquals("julian", chrono.getCalendarType()); } @Test public void test_chronology_of_name_id() { Chronology chrono = Chronology.of("julian"); Assert.assertNotNull(chrono); - Assert.assertEquals(chrono, JulianChronology.INSTANCE); - Assert.assertEquals(chrono.getId(), "Julian"); - Assert.assertEquals(chrono.getCalendarType(), "julian"); + Assert.assertEquals(JulianChronology.INSTANCE, chrono); + Assert.assertEquals("Julian", chrono.getId()); + Assert.assertEquals("julian", chrono.getCalendarType()); } //----------------------------------------------------------------------- @@ -148,78 +149,78 @@ public static Object[][] data_samples() { @Test @UseDataProvider("data_samples") public void test_LocalDate_from_JulianDate(JulianDate julian, LocalDate iso) { - assertEquals(LocalDate.from(julian), iso); + assertEquals(iso, LocalDate.from(julian)); } @Test @UseDataProvider("data_samples") public void test_JulianDate_from_LocalDate(JulianDate julian, LocalDate iso) { - assertEquals(JulianDate.from(iso), julian); + assertEquals(julian, JulianDate.from(iso)); } @Test @UseDataProvider("data_samples") public void test_JulianDate_chronology_dateEpochDay(JulianDate julian, LocalDate iso) { - assertEquals(JulianChronology.INSTANCE.dateEpochDay(iso.toEpochDay()), julian); + assertEquals(julian, JulianChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } @Test @UseDataProvider("data_samples") public void test_JulianDate_toEpochDay(JulianDate julian, LocalDate iso) { - assertEquals(julian.toEpochDay(), iso.toEpochDay()); + assertEquals(iso.toEpochDay(), julian.toEpochDay()); } @Test @UseDataProvider("data_samples") public void test_JulianDate_until_JulianDate(JulianDate julian, LocalDate iso) { - assertEquals(julian.until(julian), JulianChronology.INSTANCE.period(0, 0, 0)); + assertEquals(JulianChronology.INSTANCE.period(0, 0, 0), julian.until(julian)); } @Test @UseDataProvider("data_samples") public void test_JulianDate_until_LocalDate(JulianDate julian, LocalDate iso) { - assertEquals(julian.until(iso), JulianChronology.INSTANCE.period(0, 0, 0)); + assertEquals(JulianChronology.INSTANCE.period(0, 0, 0), julian.until(iso)); } @Test @UseDataProvider("data_samples") public void test_LocalDate_until_JulianDate(JulianDate julian, LocalDate iso) { - assertEquals(iso.until(julian), Period.ZERO); + assertEquals(Period.ZERO, iso.until(julian)); } @Test @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(JulianDate julian, LocalDate iso) { - assertEquals(JulianChronology.INSTANCE.date(iso), julian); + assertEquals(julian, JulianChronology.INSTANCE.date(iso)); } @Test @UseDataProvider("data_samples") public void test_plusDays(JulianDate julian, LocalDate iso) { - assertEquals(LocalDate.from(julian.plus(0, DAYS)), iso); - assertEquals(LocalDate.from(julian.plus(1, DAYS)), iso.plusDays(1)); - assertEquals(LocalDate.from(julian.plus(35, DAYS)), iso.plusDays(35)); - assertEquals(LocalDate.from(julian.plus(-1, DAYS)), iso.plusDays(-1)); - assertEquals(LocalDate.from(julian.plus(-60, DAYS)), iso.plusDays(-60)); + assertEquals(iso, LocalDate.from(julian.plus(0, DAYS))); + assertEquals(iso.plusDays(1), LocalDate.from(julian.plus(1, DAYS))); + assertEquals(iso.plusDays(35), LocalDate.from(julian.plus(35, DAYS))); + assertEquals(iso.plusDays(-1), LocalDate.from(julian.plus(-1, DAYS))); + assertEquals(iso.plusDays(-60), LocalDate.from(julian.plus(-60, DAYS))); } @Test @UseDataProvider("data_samples") public void test_minusDays(JulianDate julian, LocalDate iso) { - assertEquals(LocalDate.from(julian.minus(0, DAYS)), iso); - assertEquals(LocalDate.from(julian.minus(1, DAYS)), iso.minusDays(1)); - assertEquals(LocalDate.from(julian.minus(35, DAYS)), iso.minusDays(35)); - assertEquals(LocalDate.from(julian.minus(-1, DAYS)), iso.minusDays(-1)); - assertEquals(LocalDate.from(julian.minus(-60, DAYS)), iso.minusDays(-60)); + assertEquals(iso, LocalDate.from(julian.minus(0, DAYS))); + assertEquals(iso.minusDays(1), LocalDate.from(julian.minus(1, DAYS))); + assertEquals(iso.minusDays(35), LocalDate.from(julian.minus(35, DAYS))); + assertEquals(iso.minusDays(-1), LocalDate.from(julian.minus(-1, DAYS))); + assertEquals(iso.minusDays(-60), LocalDate.from(julian.minus(-60, DAYS))); } @Test @UseDataProvider("data_samples") public void test_until_DAYS(JulianDate julian, LocalDate iso) { - assertEquals(julian.until(iso.plusDays(0), DAYS), 0); - assertEquals(julian.until(iso.plusDays(1), DAYS), 1); - assertEquals(julian.until(iso.plusDays(35), DAYS), 35); - assertEquals(julian.until(iso.minusDays(40), DAYS), -40); + assertEquals(0, julian.until(iso.plusDays(0), DAYS)); + assertEquals(1, julian.until(iso.plusDays(1), DAYS)); + assertEquals(35, julian.until(iso.plusDays(35), DAYS)); + assertEquals(-40, julian.until(iso.minusDays(40), DAYS)); } @DataProvider @@ -283,28 +284,28 @@ public void test_chronology_dateYearDay_badDate() { public void test_isLeapYear_loop() { for (int year = -200; year < 200; year++) { JulianDate base = JulianDate.of(year, 1, 1); - assertEquals(base.isLeapYear(), (year % 4) == 0); - assertEquals(JulianChronology.INSTANCE.isLeapYear(year), (year % 4) == 0); + assertEquals((year % 4) == 0, base.isLeapYear()); + assertEquals((year % 4) == 0, JulianChronology.INSTANCE.isLeapYear(year)); } } @Test public void test_isLeapYear_specific() { - assertEquals(JulianChronology.INSTANCE.isLeapYear(8), true); - assertEquals(JulianChronology.INSTANCE.isLeapYear(7), false); - assertEquals(JulianChronology.INSTANCE.isLeapYear(6), false); - assertEquals(JulianChronology.INSTANCE.isLeapYear(5), false); - assertEquals(JulianChronology.INSTANCE.isLeapYear(4), true); - assertEquals(JulianChronology.INSTANCE.isLeapYear(3), false); - assertEquals(JulianChronology.INSTANCE.isLeapYear(2), false); - assertEquals(JulianChronology.INSTANCE.isLeapYear(1), false); - assertEquals(JulianChronology.INSTANCE.isLeapYear(0), true); - assertEquals(JulianChronology.INSTANCE.isLeapYear(-1), false); - assertEquals(JulianChronology.INSTANCE.isLeapYear(-2), false); - assertEquals(JulianChronology.INSTANCE.isLeapYear(-3), false); - assertEquals(JulianChronology.INSTANCE.isLeapYear(-4), true); - assertEquals(JulianChronology.INSTANCE.isLeapYear(-5), false); - assertEquals(JulianChronology.INSTANCE.isLeapYear(-6), false); + assertEquals(true, JulianChronology.INSTANCE.isLeapYear(8)); + assertEquals(false, JulianChronology.INSTANCE.isLeapYear(7)); + assertEquals(false, JulianChronology.INSTANCE.isLeapYear(6)); + assertEquals(false, JulianChronology.INSTANCE.isLeapYear(5)); + assertEquals(true, JulianChronology.INSTANCE.isLeapYear(4)); + assertEquals(false, JulianChronology.INSTANCE.isLeapYear(3)); + assertEquals(false, JulianChronology.INSTANCE.isLeapYear(2)); + assertEquals(false, JulianChronology.INSTANCE.isLeapYear(1)); + assertEquals(true, JulianChronology.INSTANCE.isLeapYear(0)); + assertEquals(false, JulianChronology.INSTANCE.isLeapYear(-1)); + assertEquals(false, JulianChronology.INSTANCE.isLeapYear(-2)); + assertEquals(false, JulianChronology.INSTANCE.isLeapYear(-3)); + assertEquals(true, JulianChronology.INSTANCE.isLeapYear(-4)); + assertEquals(false, JulianChronology.INSTANCE.isLeapYear(-5)); + assertEquals(false, JulianChronology.INSTANCE.isLeapYear(-6)); } @DataProvider @@ -335,7 +336,7 @@ public static Object[][] data_lengthOfMonth() { @Test @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { - assertEquals(JulianDate.of(year, month, 1).lengthOfMonth(), length); + assertEquals(length, JulianDate.of(year, month, 1).lengthOfMonth()); } //----------------------------------------------------------------------- @@ -351,7 +352,7 @@ public void test_era_loop() { int yoe = (year <= 0 ? 1 - year : year); assertEquals(yoe, base.get(YEAR_OF_ERA)); JulianDate eraBased = JulianChronology.INSTANCE.date(era, yoe, 1, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } } @@ -365,20 +366,20 @@ public void test_era_yearDay_loop() { int yoe = (year <= 0 ? 1 - year : year); assertEquals(yoe, base.get(YEAR_OF_ERA)); JulianDate eraBased = JulianChronology.INSTANCE.dateYearDay(era, yoe, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } } @Test public void test_prolepticYear_specific() { - assertEquals(JulianChronology.INSTANCE.prolepticYear(JulianEra.AD, 4), 4); - assertEquals(JulianChronology.INSTANCE.prolepticYear(JulianEra.AD, 3), 3); - assertEquals(JulianChronology.INSTANCE.prolepticYear(JulianEra.AD, 2), 2); - assertEquals(JulianChronology.INSTANCE.prolepticYear(JulianEra.AD, 1), 1); - assertEquals(JulianChronology.INSTANCE.prolepticYear(JulianEra.BC, 1), 0); - assertEquals(JulianChronology.INSTANCE.prolepticYear(JulianEra.BC, 2), -1); - assertEquals(JulianChronology.INSTANCE.prolepticYear(JulianEra.BC, 3), -2); - assertEquals(JulianChronology.INSTANCE.prolepticYear(JulianEra.BC, 4), -3); + assertEquals(4, JulianChronology.INSTANCE.prolepticYear(JulianEra.AD, 4)); + assertEquals(3, JulianChronology.INSTANCE.prolepticYear(JulianEra.AD, 3)); + assertEquals(2, JulianChronology.INSTANCE.prolepticYear(JulianEra.AD, 2)); + assertEquals(1, JulianChronology.INSTANCE.prolepticYear(JulianEra.AD, 1)); + assertEquals(0, JulianChronology.INSTANCE.prolepticYear(JulianEra.BC, 1)); + assertEquals(-1, JulianChronology.INSTANCE.prolepticYear(JulianEra.BC, 2)); + assertEquals(-2, JulianChronology.INSTANCE.prolepticYear(JulianEra.BC, 3)); + assertEquals(-3, JulianChronology.INSTANCE.prolepticYear(JulianEra.BC, 4)); } @Test(expected = ClassCastException.class) @@ -388,8 +389,8 @@ public void test_prolepticYear_badEra() { @Test public void test_Chronology_eraOf() { - assertEquals(JulianChronology.INSTANCE.eraOf(1), JulianEra.AD); - assertEquals(JulianChronology.INSTANCE.eraOf(0), JulianEra.BC); + assertEquals(JulianEra.AD, JulianChronology.INSTANCE.eraOf(1)); + assertEquals(JulianEra.BC, JulianChronology.INSTANCE.eraOf(0)); } @Test(expected = DateTimeException.class) @@ -400,9 +401,9 @@ public void test_Chronology_eraOf_invalid() { @Test public void test_Chronology_eras() { List eras = JulianChronology.INSTANCE.eras(); - assertEquals(eras.size(), 2); - assertEquals(eras.contains(JulianEra.BC), true); - assertEquals(eras.contains(JulianEra.AD), true); + assertEquals(2, eras.size()); + assertEquals(true, eras.contains(JulianEra.BC)); + assertEquals(true, eras.contains(JulianEra.AD)); } //----------------------------------------------------------------------- @@ -410,10 +411,10 @@ public void test_Chronology_eras() { //----------------------------------------------------------------------- @Test public void test_Chronology_range() { - assertEquals(JulianChronology.INSTANCE.range(DAY_OF_WEEK), ValueRange.of(1, 7)); - assertEquals(JulianChronology.INSTANCE.range(DAY_OF_MONTH), ValueRange.of(1, 28, 31)); - assertEquals(JulianChronology.INSTANCE.range(DAY_OF_YEAR), ValueRange.of(1, 365, 366)); - assertEquals(JulianChronology.INSTANCE.range(MONTH_OF_YEAR), ValueRange.of(1, 12)); + assertEquals(ValueRange.of(1, 7), JulianChronology.INSTANCE.range(DAY_OF_WEEK)); + assertEquals(ValueRange.of(1, 28, 31), JulianChronology.INSTANCE.range(DAY_OF_MONTH)); + assertEquals(ValueRange.of(1, 365, 366), JulianChronology.INSTANCE.range(DAY_OF_YEAR)); + assertEquals(ValueRange.of(1, 12), JulianChronology.INSTANCE.range(MONTH_OF_YEAR)); } //----------------------------------------------------------------------- @@ -448,7 +449,7 @@ public static Object[][] data_ranges() { @Test @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { - assertEquals(JulianDate.of(year, month, dom).range(field), ValueRange.of(expectedMin, expectedMax)); + assertEquals(ValueRange.of(expectedMin, expectedMax), JulianDate.of(year, month, dom).range(field)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -483,7 +484,7 @@ public static Object[][] data_getLong() { @Test @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { - assertEquals(JulianDate.of(year, month, dom).getLong(field), expected); + assertEquals(expected, JulianDate.of(year, month, dom).getLong(field)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -536,7 +537,7 @@ public static Object[][] data_with() { public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(JulianDate.of(year, month, dom).with(field, value), JulianDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(JulianDate.of(expectedYear, expectedMonth, expectedDom), JulianDate.of(year, month, dom).with(field, value)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -551,14 +552,14 @@ public void test_with_TemporalField_unsupported() { public void test_adjust1() { JulianDate base = JulianDate.of(2012, 6, 23); JulianDate test = base.with(TemporalAdjusters.lastDayOfMonth()); - assertEquals(test, JulianDate.of(2012, 6, 30)); + assertEquals(JulianDate.of(2012, 6, 30), test); } @Test public void test_adjust2() { JulianDate base = JulianDate.of(2012, 2, 23); JulianDate test = base.with(TemporalAdjusters.lastDayOfMonth()); - assertEquals(test, JulianDate.of(2012, 2, 29)); + assertEquals(JulianDate.of(2012, 2, 29), test); } //----------------------------------------------------------------------- @@ -568,7 +569,7 @@ public void test_adjust2() { public void test_adjust_toLocalDate() { JulianDate julian = JulianDate.of(2000, 1, 4); JulianDate test = julian.with(LocalDate.of(2012, 7, 6)); - assertEquals(test, JulianDate.of(2012, 6, 23)); + assertEquals(JulianDate.of(2012, 6, 23), test); } @Test(expected = DateTimeException.class) @@ -584,14 +585,14 @@ public void test_adjust_toMonth() { public void test_LocalDate_adjustToJulianDate() { JulianDate julian = JulianDate.of(2012, 6, 23); LocalDate test = LocalDate.MIN.with(julian); - assertEquals(test, LocalDate.of(2012, 7, 6)); + assertEquals(LocalDate.of(2012, 7, 6), test); } @Test public void test_LocalDateTime_adjustToJulianDate() { JulianDate julian = JulianDate.of(2012, 6, 23); LocalDateTime test = LocalDateTime.MIN.with(julian); - assertEquals(test, LocalDateTime.of(2012, 7, 6, 0, 0)); + assertEquals(LocalDateTime.of(2012, 7, 6, 0, 0), test); } //----------------------------------------------------------------------- @@ -630,7 +631,7 @@ public static Object[][] data_plus() { public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(JulianDate.of(year, month, dom).plus(amount, unit), JulianDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(JulianDate.of(expectedYear, expectedMonth, expectedDom), JulianDate.of(year, month, dom).plus(amount, unit)); } @Test @@ -639,7 +640,7 @@ public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, int year, int month, int dom) { - assertEquals(JulianDate.of(year, month, dom).minus(amount, unit), JulianDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(JulianDate.of(expectedYear, expectedMonth, expectedDom), JulianDate.of(year, month, dom).minus(amount, unit)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -687,7 +688,7 @@ public void test_until_TemporalUnit( TemporalUnit unit, long expected) { JulianDate start = JulianDate.of(year1, month1, dom1); JulianDate end = JulianDate.of(year2, month2, dom2); - assertEquals(start.until(end, unit), expected); + assertEquals(expected, start.until(end, unit)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -700,22 +701,22 @@ public void test_until_TemporalUnit_unsupported() { //----------------------------------------------------------------------- @Test public void test_plus_Period() { - assertEquals(JulianDate.of(2014, 5, 26).plus(JulianChronology.INSTANCE.period(0, 2, 3)), JulianDate.of(2014, 7, 29)); + assertEquals(JulianDate.of(2014, 7, 29), JulianDate.of(2014, 5, 26).plus(JulianChronology.INSTANCE.period(0, 2, 3))); } @Test(expected = DateTimeException.class) public void test_plus_Period_ISO() { - assertEquals(JulianDate.of(2014, 5, 26).plus(Period.ofMonths(2)), JulianDate.of(2014, 7, 26)); + assertEquals(JulianDate.of(2014, 7, 26), JulianDate.of(2014, 5, 26).plus(Period.ofMonths(2))); } @Test public void test_minus_Period() { - assertEquals(JulianDate.of(2014, 5, 26).minus(JulianChronology.INSTANCE.period(0, 2, 3)), JulianDate.of(2014, 3, 23)); + assertEquals(JulianDate.of(2014, 3, 23), JulianDate.of(2014, 5, 26).minus(JulianChronology.INSTANCE.period(0, 2, 3))); } @Test(expected = DateTimeException.class) public void test_minus_Period_ISO() { - assertEquals(JulianDate.of(2014, 5, 26).minus(Period.ofMonths(2)), JulianDate.of(2014, 3, 26)); + assertEquals(JulianDate.of(2014, 3, 26), JulianDate.of(2014, 5, 26).minus(Period.ofMonths(2))); } //----------------------------------------------------------------------- @@ -729,16 +730,16 @@ public void test_equals() { JulianDate c = JulianDate.of(2000, 2, 3); JulianDate d = JulianDate.of(2001, 1, 3); - assertEquals(a1.equals(a1), true); - assertEquals(a1.equals(a2), true); - assertEquals(a1.equals(b), false); - assertEquals(a1.equals(c), false); - assertEquals(a1.equals(d), false); + assertEquals(true, a1.equals(a1)); + assertEquals(true, a1.equals(a2)); + assertEquals(false, a1.equals(b)); + assertEquals(false, a1.equals(c)); + assertEquals(false, a1.equals(d)); - assertEquals(a1.equals(null), false); - assertEquals(a1.equals(""), false); + assertEquals(false, a1.equals(null)); + assertEquals(false, a1.equals("")); - assertEquals(a1.hashCode(), a2.hashCode()); + assertTrue(a1.hashCode() == a2.hashCode()); } //----------------------------------------------------------------------- @@ -755,7 +756,7 @@ public static Object[][] data_toString() { @Test @UseDataProvider("data_toString") public void test_toString(JulianDate julian, String expected) { - assertEquals(julian.toString(), expected); + assertEquals(expected, julian.toString()); } } diff --git a/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java b/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java index f8da0722..36f4736c 100644 --- a/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java @@ -54,6 +54,7 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; @@ -95,18 +96,18 @@ public class TestPaxChronology { public void test_chronology_of_name() { Chronology chrono = Chronology.of("Pax"); Assert.assertNotNull(chrono); - Assert.assertEquals(chrono, PaxChronology.INSTANCE); - Assert.assertEquals(chrono.getId(), "Pax"); - Assert.assertEquals(chrono.getCalendarType(), "pax"); + Assert.assertEquals(PaxChronology.INSTANCE, chrono); + Assert.assertEquals("Pax", chrono.getId()); + Assert.assertEquals("pax", chrono.getCalendarType()); } @Test public void test_chronology_of_name_id() { Chronology chrono = Chronology.of("pax"); Assert.assertNotNull(chrono); - Assert.assertEquals(chrono, PaxChronology.INSTANCE); - Assert.assertEquals(chrono.getId(), "Pax"); - Assert.assertEquals(chrono.getCalendarType(), "pax"); + Assert.assertEquals(PaxChronology.INSTANCE, chrono); + Assert.assertEquals("Pax", chrono.getId()); + Assert.assertEquals("pax", chrono.getCalendarType()); } //----------------------------------------------------------------------- @@ -180,78 +181,78 @@ public static Object[][] data_samples() { @Test @UseDataProvider("data_samples") public void test_LocalDate_from_PaxDate(PaxDate pax, LocalDate iso) { - assertEquals(LocalDate.from(pax), iso); + assertEquals(iso, LocalDate.from(pax)); } @Test @UseDataProvider("data_samples") public void test_PaxDate_from_LocalDate(PaxDate pax, LocalDate iso) { - assertEquals(PaxDate.from(iso), pax); + assertEquals(pax, PaxDate.from(iso)); } @Test @UseDataProvider("data_samples") public void test_PaxDate_chronology_dateEpochDay(PaxDate pax, LocalDate iso) { - assertEquals(PaxChronology.INSTANCE.dateEpochDay(iso.toEpochDay()), pax); + assertEquals(pax, PaxChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } @Test @UseDataProvider("data_samples") public void test_PaxDate_toEpochDay(PaxDate pax, LocalDate iso) { - assertEquals(pax.toEpochDay(), iso.toEpochDay()); + assertEquals(iso.toEpochDay(), pax.toEpochDay()); } @Test @UseDataProvider("data_samples") public void test_PaxDate_until_PaxDate(PaxDate pax, LocalDate iso) { - assertEquals(pax.until(pax), PaxChronology.INSTANCE.period(0, 0, 0)); + assertEquals(PaxChronology.INSTANCE.period(0, 0, 0), pax.until(pax)); } @Test @UseDataProvider("data_samples") public void test_PaxDate_until_LocalDate(PaxDate pax, LocalDate iso) { - assertEquals(pax.until(iso), PaxChronology.INSTANCE.period(0, 0, 0)); + assertEquals(PaxChronology.INSTANCE.period(0, 0, 0), pax.until(iso)); } @Test @UseDataProvider("data_samples") public void test_LocalDate_until_PaxDate(PaxDate pax, LocalDate iso) { - assertEquals(iso.until(pax), Period.ZERO); + assertEquals(Period.ZERO, iso.until(pax)); } @Test @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(PaxDate pax, LocalDate iso) { - assertEquals(PaxChronology.INSTANCE.date(iso), pax); + assertEquals(pax, PaxChronology.INSTANCE.date(iso)); } @Test @UseDataProvider("data_samples") public void test_plusDays(PaxDate pax, LocalDate iso) { - assertEquals(LocalDate.from(pax.plus(0, DAYS)), iso); - assertEquals(LocalDate.from(pax.plus(1, DAYS)), iso.plusDays(1)); - assertEquals(LocalDate.from(pax.plus(35, DAYS)), iso.plusDays(35)); - assertEquals(LocalDate.from(pax.plus(-1, DAYS)), iso.plusDays(-1)); - assertEquals(LocalDate.from(pax.plus(-60, DAYS)), iso.plusDays(-60)); + assertEquals(iso, LocalDate.from(pax.plus(0, DAYS))); + assertEquals(iso.plusDays(1), LocalDate.from(pax.plus(1, DAYS))); + assertEquals(iso.plusDays(35), LocalDate.from(pax.plus(35, DAYS))); + assertEquals(iso.plusDays(-1), LocalDate.from(pax.plus(-1, DAYS))); + assertEquals(iso.plusDays(-60), LocalDate.from(pax.plus(-60, DAYS))); } @Test @UseDataProvider("data_samples") public void test_minusDays(PaxDate pax, LocalDate iso) { - assertEquals(LocalDate.from(pax.minus(0, DAYS)), iso); - assertEquals(LocalDate.from(pax.minus(1, DAYS)), iso.minusDays(1)); - assertEquals(LocalDate.from(pax.minus(35, DAYS)), iso.minusDays(35)); - assertEquals(LocalDate.from(pax.minus(-1, DAYS)), iso.minusDays(-1)); - assertEquals(LocalDate.from(pax.minus(-60, DAYS)), iso.minusDays(-60)); + assertEquals(iso, LocalDate.from(pax.minus(0, DAYS))); + assertEquals(iso.minusDays(1), LocalDate.from(pax.minus(1, DAYS))); + assertEquals(iso.minusDays(35), LocalDate.from(pax.minus(35, DAYS))); + assertEquals(iso.minusDays(-1), LocalDate.from(pax.minus(-1, DAYS))); + assertEquals(iso.minusDays(-60), LocalDate.from(pax.minus(-60, DAYS))); } @Test @UseDataProvider("data_samples") public void test_until_DAYS(PaxDate pax, LocalDate iso) { - assertEquals(pax.until(iso.plusDays(0), DAYS), 0); - assertEquals(pax.until(iso.plusDays(1), DAYS), 1); - assertEquals(pax.until(iso.plusDays(35), DAYS), 35); - assertEquals(pax.until(iso.minusDays(40), DAYS), -40); + assertEquals(0, pax.until(iso.plusDays(0), DAYS)); + assertEquals(1, pax.until(iso.plusDays(1), DAYS)); + assertEquals(35, pax.until(iso.plusDays(35), DAYS)); + assertEquals(-40, pax.until(iso.minusDays(40), DAYS)); } @DataProvider @@ -323,33 +324,33 @@ public void test_isLeapYear_loop() { }; for (int year = -500; year < 500; year++) { PaxDate base = PaxDate.of(year, 1, 1); - assertEquals(base.isLeapYear(), isLeapYear.test(year)); - assertEquals(PaxChronology.INSTANCE.isLeapYear(year), isLeapYear.test(year)); + assertEquals(isLeapYear.test(year), base.isLeapYear()); + assertEquals(isLeapYear.test(year), PaxChronology.INSTANCE.isLeapYear(year)); } } @Test public void test_isLeapYear_specific() { - assertEquals(PaxChronology.INSTANCE.isLeapYear(400), false); - assertEquals(PaxChronology.INSTANCE.isLeapYear(100), true); - assertEquals(PaxChronology.INSTANCE.isLeapYear(99), true); - assertEquals(PaxChronology.INSTANCE.isLeapYear(7), false); - assertEquals(PaxChronology.INSTANCE.isLeapYear(6), true); - assertEquals(PaxChronology.INSTANCE.isLeapYear(5), false); - assertEquals(PaxChronology.INSTANCE.isLeapYear(4), false); - assertEquals(PaxChronology.INSTANCE.isLeapYear(3), false); - assertEquals(PaxChronology.INSTANCE.isLeapYear(2), false); - assertEquals(PaxChronology.INSTANCE.isLeapYear(1), false); - assertEquals(PaxChronology.INSTANCE.isLeapYear(0), false); - assertEquals(PaxChronology.INSTANCE.isLeapYear(-1), false); - assertEquals(PaxChronology.INSTANCE.isLeapYear(-2), false); - assertEquals(PaxChronology.INSTANCE.isLeapYear(-3), false); - assertEquals(PaxChronology.INSTANCE.isLeapYear(-4), false); - assertEquals(PaxChronology.INSTANCE.isLeapYear(-5), false); - assertEquals(PaxChronology.INSTANCE.isLeapYear(-6), true); - assertEquals(PaxChronology.INSTANCE.isLeapYear(-99), true); - assertEquals(PaxChronology.INSTANCE.isLeapYear(-100), true); - assertEquals(PaxChronology.INSTANCE.isLeapYear(-400), false); + assertEquals(false, PaxChronology.INSTANCE.isLeapYear(400)); + assertEquals(true, PaxChronology.INSTANCE.isLeapYear(100)); + assertEquals(true, PaxChronology.INSTANCE.isLeapYear(99)); + assertEquals(false, PaxChronology.INSTANCE.isLeapYear(7)); + assertEquals(true, PaxChronology.INSTANCE.isLeapYear(6)); + assertEquals(false, PaxChronology.INSTANCE.isLeapYear(5)); + assertEquals(false, PaxChronology.INSTANCE.isLeapYear(4)); + assertEquals(false, PaxChronology.INSTANCE.isLeapYear(3)); + assertEquals(false, PaxChronology.INSTANCE.isLeapYear(2)); + assertEquals(false, PaxChronology.INSTANCE.isLeapYear(1)); + assertEquals(false, PaxChronology.INSTANCE.isLeapYear(0)); + assertEquals(false, PaxChronology.INSTANCE.isLeapYear(-1)); + assertEquals(false, PaxChronology.INSTANCE.isLeapYear(-2)); + assertEquals(false, PaxChronology.INSTANCE.isLeapYear(-3)); + assertEquals(false, PaxChronology.INSTANCE.isLeapYear(-4)); + assertEquals(false, PaxChronology.INSTANCE.isLeapYear(-5)); + assertEquals(true, PaxChronology.INSTANCE.isLeapYear(-6)); + assertEquals(true, PaxChronology.INSTANCE.isLeapYear(-99)); + assertEquals(true, PaxChronology.INSTANCE.isLeapYear(-100)); + assertEquals(false, PaxChronology.INSTANCE.isLeapYear(-400)); } @DataProvider @@ -384,7 +385,7 @@ public static Object[][] data_lengthOfMonth() { @Test @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { - assertEquals(PaxDate.of(year, month, 1).lengthOfMonth(), length); + assertEquals(length, PaxDate.of(year, month, 1).lengthOfMonth()); } //----------------------------------------------------------------------- @@ -400,7 +401,7 @@ public void test_era_loop() { int yoe = (year <= 0 ? 1 - year : year); assertEquals(yoe, base.get(YEAR_OF_ERA)); PaxDate eraBased = PaxChronology.INSTANCE.date(era, yoe, 1, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } } @@ -414,20 +415,20 @@ public void test_era_yearDay_loop() { int yoe = (year <= 0 ? 1 - year : year); assertEquals(yoe, base.get(YEAR_OF_ERA)); PaxDate eraBased = PaxChronology.INSTANCE.dateYearDay(era, yoe, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } } @Test public void test_prolepticYear_specific() { - assertEquals(PaxChronology.INSTANCE.prolepticYear(PaxEra.CE, 4), 4); - assertEquals(PaxChronology.INSTANCE.prolepticYear(PaxEra.CE, 3), 3); - assertEquals(PaxChronology.INSTANCE.prolepticYear(PaxEra.CE, 2), 2); - assertEquals(PaxChronology.INSTANCE.prolepticYear(PaxEra.CE, 1), 1); - assertEquals(PaxChronology.INSTANCE.prolepticYear(PaxEra.BCE, 1), 0); - assertEquals(PaxChronology.INSTANCE.prolepticYear(PaxEra.BCE, 2), -1); - assertEquals(PaxChronology.INSTANCE.prolepticYear(PaxEra.BCE, 3), -2); - assertEquals(PaxChronology.INSTANCE.prolepticYear(PaxEra.BCE, 4), -3); + assertEquals(4, PaxChronology.INSTANCE.prolepticYear(PaxEra.CE, 4)); + assertEquals(3, PaxChronology.INSTANCE.prolepticYear(PaxEra.CE, 3)); + assertEquals(2, PaxChronology.INSTANCE.prolepticYear(PaxEra.CE, 2)); + assertEquals(1, PaxChronology.INSTANCE.prolepticYear(PaxEra.CE, 1)); + assertEquals(0, PaxChronology.INSTANCE.prolepticYear(PaxEra.BCE, 1)); + assertEquals(-1, PaxChronology.INSTANCE.prolepticYear(PaxEra.BCE, 2)); + assertEquals(-2, PaxChronology.INSTANCE.prolepticYear(PaxEra.BCE, 3)); + assertEquals(-3, PaxChronology.INSTANCE.prolepticYear(PaxEra.BCE, 4)); } @Test(expected = ClassCastException.class) @@ -437,8 +438,8 @@ public void test_prolepticYear_badEra() { @Test public void test_Chronology_eraOf() { - assertEquals(PaxChronology.INSTANCE.eraOf(1), PaxEra.CE); - assertEquals(PaxChronology.INSTANCE.eraOf(0), PaxEra.BCE); + assertEquals(PaxEra.CE, PaxChronology.INSTANCE.eraOf(1)); + assertEquals(PaxEra.BCE, PaxChronology.INSTANCE.eraOf(0)); } @Test(expected = DateTimeException.class) @@ -449,9 +450,9 @@ public void test_Chronology_eraOf_invalid() { @Test public void test_Chronology_eras() { List eras = PaxChronology.INSTANCE.eras(); - assertEquals(eras.size(), 2); - assertEquals(eras.contains(PaxEra.BCE), true); - assertEquals(eras.contains(PaxEra.CE), true); + assertEquals(2, eras.size()); + assertEquals(true, eras.contains(PaxEra.BCE)); + assertEquals(true, eras.contains(PaxEra.CE)); } //----------------------------------------------------------------------- @@ -459,10 +460,10 @@ public void test_Chronology_eras() { //----------------------------------------------------------------------- @Test public void test_Chronology_range() { - assertEquals(PaxChronology.INSTANCE.range(DAY_OF_WEEK), ValueRange.of(1, 7)); - assertEquals(PaxChronology.INSTANCE.range(DAY_OF_MONTH), ValueRange.of(1, 7, 28)); - assertEquals(PaxChronology.INSTANCE.range(DAY_OF_YEAR), ValueRange.of(1, 364, 371)); - assertEquals(PaxChronology.INSTANCE.range(MONTH_OF_YEAR), ValueRange.of(1, 13, 14)); + assertEquals(ValueRange.of(1, 7), PaxChronology.INSTANCE.range(DAY_OF_WEEK)); + assertEquals(ValueRange.of(1, 7, 28), PaxChronology.INSTANCE.range(DAY_OF_MONTH)); + assertEquals(ValueRange.of(1, 364, 371), PaxChronology.INSTANCE.range(DAY_OF_YEAR)); + assertEquals(ValueRange.of(1, 13, 14), PaxChronology.INSTANCE.range(MONTH_OF_YEAR)); } //----------------------------------------------------------------------- @@ -503,7 +504,7 @@ public static Object[][] data_ranges() { @Test @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { - assertEquals(PaxDate.of(year, month, dom).range(field), ValueRange.of(expectedMin, expectedMax)); + assertEquals(ValueRange.of(expectedMin, expectedMax), PaxDate.of(year, month, dom).range(field)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -538,7 +539,7 @@ public static Object[][] data_getLong() { @Test @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { - assertEquals(PaxDate.of(year, month, dom).getLong(field), expected); + assertEquals(expected, PaxDate.of(year, month, dom).getLong(field)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -591,7 +592,7 @@ public static Object[][] data_with() { public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(PaxDate.of(year, month, dom).with(field, value), PaxDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(PaxDate.of(expectedYear, expectedMonth, expectedDom), PaxDate.of(year, month, dom).with(field, value)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -606,14 +607,14 @@ public void test_with_TemporalField_unsupported() { public void test_adjust1() { PaxDate base = PaxDate.of(2012, 6, 23); PaxDate test = base.with(TemporalAdjusters.lastDayOfMonth()); - assertEquals(test, PaxDate.of(2012, 6, 28)); + assertEquals(PaxDate.of(2012, 6, 28), test); } @Test public void test_adjust2() { PaxDate base = PaxDate.of(2012, 13, 2); PaxDate test = base.with(TemporalAdjusters.lastDayOfMonth()); - assertEquals(test, PaxDate.of(2012, 13, 7)); + assertEquals(PaxDate.of(2012, 13, 7), test); } //----------------------------------------------------------------------- @@ -623,7 +624,7 @@ public void test_adjust2() { public void test_adjust_toLocalDate() { PaxDate pax = PaxDate.of(2000, 1, 4); PaxDate test = pax.with(LocalDate.of(2012, 7, 6)); - assertEquals(test, PaxDate.of(2012, 7, 27)); + assertEquals(PaxDate.of(2012, 7, 27), test); } @Test(expected = DateTimeException.class) @@ -639,14 +640,14 @@ public void test_adjust_toMonth() { public void test_LocalDate_adjustToPaxDate() { PaxDate pax = PaxDate.of(2012, 6, 23); LocalDate test = LocalDate.MIN.with(pax); - assertEquals(test, LocalDate.of(2012, 6, 4)); + assertEquals(LocalDate.of(2012, 6, 4), test); } @Test public void test_LocalDateTime_adjustToPaxDate() { PaxDate pax = PaxDate.of(2012, 6, 23); LocalDateTime test = LocalDateTime.MIN.with(pax); - assertEquals(test, LocalDateTime.of(2012, 6, 4, 0, 0)); + assertEquals(LocalDateTime.of(2012, 6, 4, 0, 0), test); } //----------------------------------------------------------------------- @@ -713,7 +714,7 @@ public static Object[][] data_minus_leap() { public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(PaxDate.of(year, month, dom).plus(amount, unit), PaxDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(PaxDate.of(expectedYear, expectedMonth, expectedDom), PaxDate.of(year, month, dom).plus(amount, unit)); } @Test @@ -730,7 +731,7 @@ public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, int year, int month, int dom) { - assertEquals(PaxDate.of(year, month, dom).minus(amount, unit), PaxDate.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(PaxDate.of(expectedYear, expectedMonth, expectedDom), PaxDate.of(year, month, dom).minus(amount, unit)); } @Test @@ -827,7 +828,7 @@ public void test_until_TemporalUnit( TemporalUnit unit, long expected) { PaxDate start = PaxDate.of(year1, month1, dom1); PaxDate end = PaxDate.of(year2, month2, dom2); - assertEquals(start.until(end, unit), expected); + assertEquals(expected, start.until(end, unit)); } @Test @@ -839,7 +840,7 @@ public void test_until_end( PaxDate start = PaxDate.of(year1, month1, dom1); PaxDate end = PaxDate.of(year2, month2, dom2); ChronoPeriod period = PaxChronology.INSTANCE.period(yearPeriod, monthPeriod, dayPeriod); - assertEquals(start.until(end), period); + assertEquals(period, start.until(end)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -852,22 +853,22 @@ public void test_until_TemporalUnit_unsupported() { //----------------------------------------------------------------------- @Test public void test_plus_Period() { - assertEquals(PaxDate.of(2014, 5, 26).plus(PaxChronology.INSTANCE.period(0, 2, 2)), PaxDate.of(2014, 7, 28)); + assertEquals(PaxDate.of(2014, 7, 28), PaxDate.of(2014, 5, 26).plus(PaxChronology.INSTANCE.period(0, 2, 2))); } @Test(expected = DateTimeException.class) public void test_plus_Period_ISO() { - assertEquals(PaxDate.of(2014, 5, 26).plus(Period.ofMonths(2)), PaxDate.of(2014, 7, 26)); + assertEquals(PaxDate.of(2014, 7, 26), PaxDate.of(2014, 5, 26).plus(Period.ofMonths(2))); } @Test public void test_minus_Period() { - assertEquals(PaxDate.of(2014, 5, 26).minus(PaxChronology.INSTANCE.period(0, 2, 3)), PaxDate.of(2014, 3, 23)); + assertEquals(PaxDate.of(2014, 3, 23), PaxDate.of(2014, 5, 26).minus(PaxChronology.INSTANCE.period(0, 2, 3))); } @Test(expected = DateTimeException.class) public void test_minus_Period_ISO() { - assertEquals(PaxDate.of(2014, 5, 26).minus(Period.ofMonths(2)), PaxDate.of(2014, 3, 26)); + assertEquals(PaxDate.of(2014, 3, 26), PaxDate.of(2014, 5, 26).minus(Period.ofMonths(2))); } //----------------------------------------------------------------------- @@ -881,16 +882,16 @@ public void test_equals() { PaxDate c = PaxDate.of(2000, 2, 3); PaxDate d = PaxDate.of(2001, 1, 3); - assertEquals(a1.equals(a1), true); - assertEquals(a1.equals(a2), true); - assertEquals(a1.equals(b), false); - assertEquals(a1.equals(c), false); - assertEquals(a1.equals(d), false); + assertEquals(true, a1.equals(a1)); + assertEquals(true, a1.equals(a2)); + assertEquals(false, a1.equals(b)); + assertEquals(false, a1.equals(c)); + assertEquals(false, a1.equals(d)); - assertEquals(a1.equals(null), false); - assertEquals(a1.equals(""), false); + assertEquals(false, a1.equals(null)); + assertEquals(false, a1.equals("")); - assertEquals(a1.hashCode(), a2.hashCode()); + assertTrue(a1.hashCode() == a2.hashCode()); } //----------------------------------------------------------------------- @@ -907,7 +908,7 @@ public static Object[][] data_toString() { @Test @UseDataProvider("data_toString") public void test_toString(PaxDate pax, String expected) { - assertEquals(pax.toString(), expected); + assertEquals(expected, pax.toString()); } } diff --git a/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java b/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java index ac6ac7b1..9d1074c8 100644 --- a/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java @@ -101,9 +101,9 @@ public class TestSymmetry010Chronology { public void test_chronology() { Chronology chrono = Chronology.of("Sym010"); assertNotNull(chrono); - assertEquals(chrono, Symmetry010Chronology.INSTANCE); - assertEquals(chrono.getId(), "Sym010"); - assertEquals(chrono.getCalendarType(), null); + assertEquals(Symmetry010Chronology.INSTANCE, chrono); + assertEquals("Sym010", chrono.getId()); + assertEquals(null, chrono.getCalendarType()); } //----------------------------------------------------------------------- @@ -149,78 +149,78 @@ public static Object[][] data_samples() { @Test @UseDataProvider("data_samples") public void test_LocalDate_from_Symmetry010Date(Symmetry010Date sym010, LocalDate iso) { - assertEquals(LocalDate.from(sym010), iso); + assertEquals(iso, LocalDate.from(sym010)); } @Test @UseDataProvider("data_samples") public void test_Symmetry010Date_from_LocalDate(Symmetry010Date sym010, LocalDate iso) { - assertEquals(Symmetry010Date.from(iso), sym010); + assertEquals(sym010, Symmetry010Date.from(iso)); } @Test @UseDataProvider("data_samples") public void test_Symmetry010Date_chronology_dateEpochDay(Symmetry010Date sym010, LocalDate iso) { - assertEquals(Symmetry010Chronology.INSTANCE.dateEpochDay(iso.toEpochDay()), sym010); + assertEquals(sym010, Symmetry010Chronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } @Test @UseDataProvider("data_samples") public void test_Symmetry010Date_toEpochDay(Symmetry010Date sym010, LocalDate iso) { - assertEquals(sym010.toEpochDay(), iso.toEpochDay()); + assertEquals(iso.toEpochDay(), sym010.toEpochDay()); } @Test @UseDataProvider("data_samples") public void test_Symmetry010Date_until_Symmetry010Date(Symmetry010Date sym010, LocalDate iso) { - assertEquals(sym010.until(sym010), Symmetry010Chronology.INSTANCE.period(0, 0, 0)); + assertEquals(Symmetry010Chronology.INSTANCE.period(0, 0, 0), sym010.until(sym010)); } @Test @UseDataProvider("data_samples") public void test_Symmetry010Date_until_LocalDate(Symmetry010Date sym010, LocalDate iso) { - assertEquals(sym010.until(iso), Symmetry010Chronology.INSTANCE.period(0, 0, 0)); + assertEquals(Symmetry010Chronology.INSTANCE.period(0, 0, 0), sym010.until(iso)); } @Test @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(Symmetry010Date sym010, LocalDate iso) { - assertEquals(Symmetry010Chronology.INSTANCE.date(iso), sym010); + assertEquals(sym010, Symmetry010Chronology.INSTANCE.date(iso)); } @Test @UseDataProvider("data_samples") public void test_LocalDate_until_Symmetry010Date(Symmetry010Date sym010, LocalDate iso) { - assertEquals(iso.until(sym010), Period.ZERO); + assertEquals(Period.ZERO, iso.until(sym010)); } @Test @UseDataProvider("data_samples") public void test_plusDays(Symmetry010Date sym010, LocalDate iso) { - assertEquals(LocalDate.from(sym010.plus(0, DAYS)), iso); - assertEquals(LocalDate.from(sym010.plus(1, DAYS)), iso.plusDays(1)); - assertEquals(LocalDate.from(sym010.plus(35, DAYS)), iso.plusDays(35)); - assertEquals(LocalDate.from(sym010.plus(-1, DAYS)), iso.plusDays(-1)); - assertEquals(LocalDate.from(sym010.plus(-60, DAYS)), iso.plusDays(-60)); + assertEquals(iso, LocalDate.from(sym010.plus(0, DAYS))); + assertEquals(iso.plusDays(1), LocalDate.from(sym010.plus(1, DAYS))); + assertEquals(iso.plusDays(35), LocalDate.from(sym010.plus(35, DAYS))); + assertEquals(iso.plusDays(-1), LocalDate.from(sym010.plus(-1, DAYS))); + assertEquals(iso.plusDays(-60), LocalDate.from(sym010.plus(-60, DAYS))); } @Test @UseDataProvider("data_samples") public void test_minusDays(Symmetry010Date sym010, LocalDate iso) { - assertEquals(LocalDate.from(sym010.minus(0, DAYS)), iso); - assertEquals(LocalDate.from(sym010.minus(1, DAYS)), iso.minusDays(1)); - assertEquals(LocalDate.from(sym010.minus(35, DAYS)), iso.minusDays(35)); - assertEquals(LocalDate.from(sym010.minus(-1, DAYS)), iso.minusDays(-1)); - assertEquals(LocalDate.from(sym010.minus(-60, DAYS)), iso.minusDays(-60)); + assertEquals(iso, LocalDate.from(sym010.minus(0, DAYS))); + assertEquals(iso.minusDays(1), LocalDate.from(sym010.minus(1, DAYS))); + assertEquals(iso.minusDays(35), LocalDate.from(sym010.minus(35, DAYS))); + assertEquals(iso.minusDays(-1), LocalDate.from(sym010.minus(-1, DAYS))); + assertEquals(iso.minusDays(-60), LocalDate.from(sym010.minus(-60, DAYS))); } @Test @UseDataProvider("data_samples") public void test_until_DAYS(Symmetry010Date sym010, LocalDate iso) { - assertEquals(sym010.until(iso.plusDays(0), DAYS), 0); - assertEquals(sym010.until(iso.plusDays(1), DAYS), 1); - assertEquals(sym010.until(iso.plusDays(35), DAYS), 35); - assertEquals(sym010.until(iso.minusDays(40), DAYS), -40); + assertEquals(0, sym010.until(iso.plusDays(0), DAYS)); + assertEquals(1, sym010.until(iso.plusDays(1), DAYS)); + assertEquals(35, sym010.until(iso.plusDays(35), DAYS)); + assertEquals(-40, sym010.until(iso.minusDays(40), DAYS)); } @DataProvider @@ -329,19 +329,19 @@ public static Object[][] data_lengthOfMonth() { @Test @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int day, int length) { - assertEquals(Symmetry010Date.of(year, month, day).lengthOfMonth(), length); + assertEquals(length, Symmetry010Date.of(year, month, day).lengthOfMonth()); } @Test @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonthFirst(int year, int month, int day, int length) { - assertEquals(Symmetry010Date.of(year, month, 1).lengthOfMonth(), length); + assertEquals(length, Symmetry010Date.of(year, month, 1).lengthOfMonth()); } @Test public void test_lengthOfMonth_specific() { - assertEquals(Symmetry010Date.of(2000, 12, 1).lengthOfMonth(), 30); - assertEquals(Symmetry010Date.of(2004, 12, 1).lengthOfMonth(), 37); + assertEquals(30, Symmetry010Date.of(2000, 12, 1).lengthOfMonth()); + assertEquals(37, Symmetry010Date.of(2004, 12, 1).lengthOfMonth()); } //----------------------------------------------------------------------- @@ -358,7 +358,7 @@ public void test_era_loop() { assertEquals(era, base.getEra()); assertEquals(year, base.get(YEAR_OF_ERA)); Symmetry010Date eraBased = Symmetry010Chronology.INSTANCE.date(era, year, 1, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } for (int year = -200; year < 0; year++) { @@ -368,7 +368,7 @@ public void test_era_loop() { assertEquals(era, base.getEra()); assertEquals(1 - year, base.get(YEAR_OF_ERA)); Symmetry010Date eraBased = Symmetry010Chronology.INSTANCE.date(era, year, 1, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } } @@ -381,18 +381,18 @@ public void test_era_yearDay_loop() { assertEquals(era, base.getEra()); assertEquals(year, base.get(YEAR_OF_ERA)); Symmetry010Date eraBased = Symmetry010Chronology.INSTANCE.dateYearDay(era, year, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } } @Test public void test_prolepticYear_specific() { - assertEquals(Symmetry010Chronology.INSTANCE.prolepticYear(IsoEra.CE, 4), 4); - assertEquals(Symmetry010Chronology.INSTANCE.prolepticYear(IsoEra.CE, 3), 3); - assertEquals(Symmetry010Chronology.INSTANCE.prolepticYear(IsoEra.CE, 2), 2); - assertEquals(Symmetry010Chronology.INSTANCE.prolepticYear(IsoEra.CE, 1), 1); - assertEquals(Symmetry010Chronology.INSTANCE.prolepticYear(IsoEra.CE, 2000), 2000); - assertEquals(Symmetry010Chronology.INSTANCE.prolepticYear(IsoEra.CE, 1582), 1582); + assertEquals(4, Symmetry010Chronology.INSTANCE.prolepticYear(IsoEra.CE, 4)); + assertEquals(3, Symmetry010Chronology.INSTANCE.prolepticYear(IsoEra.CE, 3)); + assertEquals(2, Symmetry010Chronology.INSTANCE.prolepticYear(IsoEra.CE, 2)); + assertEquals(1, Symmetry010Chronology.INSTANCE.prolepticYear(IsoEra.CE, 1)); + assertEquals(2000, Symmetry010Chronology.INSTANCE.prolepticYear(IsoEra.CE, 2000)); + assertEquals(1582, Symmetry010Chronology.INSTANCE.prolepticYear(IsoEra.CE, 1582)); } @DataProvider @@ -430,8 +430,8 @@ public void test_prolepticYear_badEra(Era era) { @Test public void test_Chronology_eraOf() { - assertEquals(Symmetry010Chronology.INSTANCE.eraOf(0), IsoEra.BCE); - assertEquals(Symmetry010Chronology.INSTANCE.eraOf(1), IsoEra.CE); + assertEquals(IsoEra.BCE, Symmetry010Chronology.INSTANCE.eraOf(0)); + assertEquals(IsoEra.CE, Symmetry010Chronology.INSTANCE.eraOf(1)); } @Test(expected = DateTimeException.class) @@ -442,7 +442,7 @@ public void test_Chronology_eraOf_invalid() { @Test public void test_Chronology_eras() { List eras = Symmetry010Chronology.INSTANCE.eras(); - assertEquals(eras.size(), 2); + assertEquals(2, eras.size()); assertTrue(eras.contains(IsoEra.BCE)); assertTrue(eras.contains(IsoEra.CE)); } @@ -452,19 +452,19 @@ public void test_Chronology_eras() { //----------------------------------------------------------------------- @Test public void test_Chronology_range() { - assertEquals(Symmetry010Chronology.INSTANCE.range(ALIGNED_DAY_OF_WEEK_IN_MONTH), ValueRange.of(1, 7)); - assertEquals(Symmetry010Chronology.INSTANCE.range(ALIGNED_DAY_OF_WEEK_IN_YEAR), ValueRange.of(1, 7)); - assertEquals(Symmetry010Chronology.INSTANCE.range(ALIGNED_WEEK_OF_MONTH), ValueRange.of(1, 4, 5)); - assertEquals(Symmetry010Chronology.INSTANCE.range(ALIGNED_WEEK_OF_YEAR), ValueRange.of(1, 52, 53)); - assertEquals(Symmetry010Chronology.INSTANCE.range(DAY_OF_WEEK), ValueRange.of(1, 7)); - assertEquals(Symmetry010Chronology.INSTANCE.range(DAY_OF_MONTH), ValueRange.of(1, 30, 37)); - assertEquals(Symmetry010Chronology.INSTANCE.range(DAY_OF_YEAR), ValueRange.of(1, 364, 371)); - assertEquals(Symmetry010Chronology.INSTANCE.range(ERA), ValueRange.of(0, 1)); - assertEquals(Symmetry010Chronology.INSTANCE.range(EPOCH_DAY), ValueRange.of(-1_000_000 * 364L - 177_474 * 7 - 719_162, 1_000_000 * 364L + 177_474 * 7 - 719_162)); - assertEquals(Symmetry010Chronology.INSTANCE.range(MONTH_OF_YEAR), ValueRange.of(1, 12)); - assertEquals(Symmetry010Chronology.INSTANCE.range(PROLEPTIC_MONTH), ValueRange.of(-12_000_000L, 11_999_999L)); - assertEquals(Symmetry010Chronology.INSTANCE.range(YEAR), ValueRange.of(-1_000_000L, 1_000_000)); - assertEquals(Symmetry010Chronology.INSTANCE.range(YEAR_OF_ERA), ValueRange.of(-1_000_000, 1_000_000)); + assertEquals(ValueRange.of(1, 7), Symmetry010Chronology.INSTANCE.range(ALIGNED_DAY_OF_WEEK_IN_MONTH)); + assertEquals(ValueRange.of(1, 7), Symmetry010Chronology.INSTANCE.range(ALIGNED_DAY_OF_WEEK_IN_YEAR)); + assertEquals(ValueRange.of(1, 4, 5), Symmetry010Chronology.INSTANCE.range(ALIGNED_WEEK_OF_MONTH)); + assertEquals(ValueRange.of(1, 52, 53), Symmetry010Chronology.INSTANCE.range(ALIGNED_WEEK_OF_YEAR)); + assertEquals(ValueRange.of(1, 7), Symmetry010Chronology.INSTANCE.range(DAY_OF_WEEK)); + assertEquals(ValueRange.of(1, 30, 37), Symmetry010Chronology.INSTANCE.range(DAY_OF_MONTH)); + assertEquals(ValueRange.of(1, 364, 371), Symmetry010Chronology.INSTANCE.range(DAY_OF_YEAR)); + assertEquals(ValueRange.of(0, 1), Symmetry010Chronology.INSTANCE.range(ERA)); + assertEquals(ValueRange.of(-1_000_000 * 364L - 177_474 * 7 - 719_162, 1_000_000 * 364L + 177_474 * 7 - 719_162), Symmetry010Chronology.INSTANCE.range(EPOCH_DAY)); + assertEquals(ValueRange.of(1, 12), Symmetry010Chronology.INSTANCE.range(MONTH_OF_YEAR)); + assertEquals(ValueRange.of(-12_000_000L, 11_999_999L), Symmetry010Chronology.INSTANCE.range(PROLEPTIC_MONTH)); + assertEquals(ValueRange.of(-1_000_000L, 1_000_000), Symmetry010Chronology.INSTANCE.range(YEAR)); + assertEquals(ValueRange.of(-1_000_000, 1_000_000), Symmetry010Chronology.INSTANCE.range(YEAR_OF_ERA)); } //----------------------------------------------------------------------- @@ -519,7 +519,7 @@ public static Object[][] data_ranges() { @Test @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, ValueRange range) { - assertEquals(Symmetry010Date.of(year, month, dom).range(field), range); + assertEquals(range, Symmetry010Date.of(year, month, dom).range(field)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -568,7 +568,7 @@ public static Object[][] data_getLong() { @Test @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { - assertEquals(Symmetry010Date.of(year, month, dom).getLong(field), expected); + assertEquals(expected, Symmetry010Date.of(year, month, dom).getLong(field)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -660,7 +660,7 @@ public static Object[][] data_with() { public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(Symmetry010Date.of(year, month, dom).with(field, value), Symmetry010Date.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(Symmetry010Date.of(expectedYear, expectedMonth, expectedDom), Symmetry010Date.of(year, month, dom).with(field, value)); } @DataProvider @@ -741,7 +741,7 @@ public void test_temporalAdjusters_LastDayOfMonth(int year, int month, int day, Symmetry010Date base = Symmetry010Date.of(year, month, day); Symmetry010Date expected = Symmetry010Date.of(expectedYear, expectedMonth, expectedDay); Symmetry010Date actual = base.with(TemporalAdjusters.lastDayOfMonth()); - assertEquals(actual, expected); + assertEquals(expected, actual); } //----------------------------------------------------------------------- @@ -751,7 +751,7 @@ public void test_temporalAdjusters_LastDayOfMonth(int year, int month, int day, public void test_adjust_toLocalDate() { Symmetry010Date sym010 = Symmetry010Date.of(2000, 1, 4); Symmetry010Date test = sym010.with(LocalDate.of(2012, 7, 6)); - assertEquals(test, Symmetry010Date.of(2012, 7, 5)); + assertEquals(Symmetry010Date.of(2012, 7, 5), test); } @Test(expected = DateTimeException.class) @@ -767,14 +767,14 @@ public void test_adjust_toMonth() { public void test_LocalDate_adjustToSymmetry010Date() { Symmetry010Date sym010 = Symmetry010Date.of(2012, 7, 19); LocalDate test = LocalDate.MIN.with(sym010); - assertEquals(test, LocalDate.of(2012, 7, 20)); + assertEquals(LocalDate.of(2012, 7, 20), test); } @Test public void test_LocalDateTime_adjustToSymmetry010Date() { Symmetry010Date sym010 = Symmetry010Date.of(2012, 7, 19); LocalDateTime test = LocalDateTime.MIN.with(sym010); - assertEquals(test, LocalDateTime.of(2012, 7, 20, 0, 0)); + assertEquals(LocalDateTime.of(2012, 7, 20, 0, 0), test); } //----------------------------------------------------------------------- @@ -842,7 +842,7 @@ public static Object[][] data_plus_leapWeek() { public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(Symmetry010Date.of(year, month, dom).plus(amount, unit), Symmetry010Date.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(Symmetry010Date.of(expectedYear, expectedMonth, expectedDom), Symmetry010Date.of(year, month, dom).plus(amount, unit)); } @Test @@ -850,7 +850,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, public void test_plus_leapWeek_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(Symmetry010Date.of(year, month, dom).plus(amount, unit), Symmetry010Date.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(Symmetry010Date.of(expectedYear, expectedMonth, expectedDom), Symmetry010Date.of(year, month, dom).plus(amount, unit)); } @Test @@ -859,7 +859,7 @@ public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, int year, int month, int dom) { - assertEquals(Symmetry010Date.of(year, month, dom).minus(amount, unit), Symmetry010Date.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(Symmetry010Date.of(expectedYear, expectedMonth, expectedDom), Symmetry010Date.of(year, month, dom).minus(amount, unit)); } @Test @@ -868,7 +868,7 @@ public void test_minus_leapWeek_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, int year, int month, int dom) { - assertEquals(Symmetry010Date.of(year, month, dom).minus(amount, unit), Symmetry010Date.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(Symmetry010Date.of(expectedYear, expectedMonth, expectedDom), Symmetry010Date.of(year, month, dom).minus(amount, unit)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -930,7 +930,7 @@ public void test_until_TemporalUnit( TemporalUnit unit, long expected) { Symmetry010Date start = Symmetry010Date.of(year1, month1, dom1); Symmetry010Date end = Symmetry010Date.of(year2, month2, dom2); - assertEquals(start.until(end, unit), expected); + assertEquals(expected, start.until(end, unit)); } @Test @@ -942,7 +942,7 @@ public void test_until_end( Symmetry010Date start = Symmetry010Date.of(year1, month1, dom1); Symmetry010Date end = Symmetry010Date.of(year2, month2, dom2); ChronoPeriod period = Symmetry010Chronology.INSTANCE.period(yearPeriod, monthPeriod, dayPeriod); - assertEquals(start.until(end), period); + assertEquals(period, start.until(end)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -957,25 +957,25 @@ public void test_until_TemporalUnit_unsupported() { //----------------------------------------------------------------------- @Test public void test_plus_Period() { - assertEquals(Symmetry010Date.of(2014, 5, 21).plus(Symmetry010Chronology.INSTANCE.period(0, 2, 8)), - Symmetry010Date.of(2014, 7, 29)); + assertEquals(Symmetry010Date.of(2014, 7, 29), + Symmetry010Date.of(2014, 5, 21).plus(Symmetry010Chronology.INSTANCE.period(0, 2, 8))); } @Test(expected = DateTimeException.class) public void test_plus_Period_ISO() { - assertEquals(Symmetry010Date.of(2014, 5, 26).plus(Period.ofMonths(2)), - Symmetry010Date.of(2014, 7, 26)); + assertEquals(Symmetry010Date.of(2014, 7, 26), + Symmetry010Date.of(2014, 5, 26).plus(Period.ofMonths(2))); } @Test public void test_minus_Period() { - assertEquals(Symmetry010Date.of(2014, 5, 26).minus(Symmetry010Chronology.INSTANCE.period(0, 2, 3)), - Symmetry010Date.of(2014, 3, 23)); + assertEquals(Symmetry010Date.of(2014, 3, 23), + Symmetry010Date.of(2014, 5, 26).minus(Symmetry010Chronology.INSTANCE.period(0, 2, 3))); } @Test(expected = DateTimeException.class) public void test_minus_Period_ISO() { - assertEquals(Symmetry010Date.of(2014, 5, 26).minus(Period.ofMonths(2)), Symmetry010Date.of(2014, 3, 26)); + assertEquals(Symmetry010Date.of(2014, 3, 26), Symmetry010Date.of(2014, 5, 26).minus(Period.ofMonths(2))); } //----------------------------------------------------------------------- @@ -1018,6 +1018,6 @@ public static Object[][] data_toString() { @Test @UseDataProvider("data_toString") public void test_toString(Symmetry010Date date, String expected) { - assertEquals(date.toString(), expected); + assertEquals(expected, date.toString()); } } diff --git a/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java b/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java index 4ab8799e..3e96ed9f 100644 --- a/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java @@ -101,9 +101,9 @@ public class TestSymmetry454Chronology { public void test_chronology() { Chronology chrono = Chronology.of("Sym454"); assertNotNull(chrono); - assertEquals(chrono, Symmetry454Chronology.INSTANCE); - assertEquals(chrono.getId(), "Sym454"); - assertEquals(chrono.getCalendarType(), null); + assertEquals(Symmetry454Chronology.INSTANCE, chrono); + assertEquals("Sym454", chrono.getId()); + assertEquals(null, chrono.getCalendarType()); } //----------------------------------------------------------------------- @@ -149,78 +149,78 @@ public static Object[][] data_samples() { @Test @UseDataProvider("data_samples") public void test_LocalDate_from_Symmetry454Date(Symmetry454Date sym454, LocalDate iso) { - assertEquals(LocalDate.from(sym454), iso); + assertEquals(iso, LocalDate.from(sym454)); } @Test @UseDataProvider("data_samples") public void test_Symmetry454Date_from_LocalDate(Symmetry454Date sym454, LocalDate iso) { - assertEquals(Symmetry454Date.from(iso), sym454); + assertEquals(sym454, Symmetry454Date.from(iso)); } @Test @UseDataProvider("data_samples") public void test_Symmetry454Date_chronology_dateEpochDay(Symmetry454Date sym454, LocalDate iso) { - assertEquals(Symmetry454Chronology.INSTANCE.dateEpochDay(iso.toEpochDay()), sym454); + assertEquals(sym454, Symmetry454Chronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } @Test @UseDataProvider("data_samples") public void test_Symmetry454Date_toEpochDay(Symmetry454Date sym454, LocalDate iso) { - assertEquals(sym454.toEpochDay(), iso.toEpochDay()); + assertEquals(iso.toEpochDay(), sym454.toEpochDay()); } @Test @UseDataProvider("data_samples") public void test_Symmetry454Date_until_Symmetry454Date(Symmetry454Date sym454, LocalDate iso) { - assertEquals(sym454.until(sym454), Symmetry454Chronology.INSTANCE.period(0, 0, 0)); + assertEquals(Symmetry454Chronology.INSTANCE.period(0, 0, 0), sym454.until(sym454)); } @Test @UseDataProvider("data_samples") public void test_Symmetry454Date_until_LocalDate(Symmetry454Date sym454, LocalDate iso) { - assertEquals(sym454.until(iso), Symmetry454Chronology.INSTANCE.period(0, 0, 0)); + assertEquals(Symmetry454Chronology.INSTANCE.period(0, 0, 0), sym454.until(iso)); } @Test @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(Symmetry454Date sym454, LocalDate iso) { - assertEquals(Symmetry454Chronology.INSTANCE.date(iso), sym454); + assertEquals(sym454, Symmetry454Chronology.INSTANCE.date(iso)); } @Test @UseDataProvider("data_samples") public void test_LocalDate_until_Symmetry454Date(Symmetry454Date sym454, LocalDate iso) { - assertEquals(iso.until(sym454), Period.ZERO); + assertEquals(Period.ZERO, iso.until(sym454)); } @Test @UseDataProvider("data_samples") public void test_plusDays(Symmetry454Date sym454, LocalDate iso) { - assertEquals(LocalDate.from(sym454.plus(0, DAYS)), iso); - assertEquals(LocalDate.from(sym454.plus(1, DAYS)), iso.plusDays(1)); - assertEquals(LocalDate.from(sym454.plus(35, DAYS)), iso.plusDays(35)); - assertEquals(LocalDate.from(sym454.plus(-1, DAYS)), iso.plusDays(-1)); - assertEquals(LocalDate.from(sym454.plus(-60, DAYS)), iso.plusDays(-60)); + assertEquals(iso, LocalDate.from(sym454.plus(0, DAYS))); + assertEquals(iso.plusDays(1), LocalDate.from(sym454.plus(1, DAYS))); + assertEquals(iso.plusDays(35), LocalDate.from(sym454.plus(35, DAYS))); + assertEquals(iso.plusDays(-1), LocalDate.from(sym454.plus(-1, DAYS))); + assertEquals(iso.plusDays(-60), LocalDate.from(sym454.plus(-60, DAYS))); } @Test @UseDataProvider("data_samples") public void test_minusDays(Symmetry454Date sym454, LocalDate iso) { - assertEquals(LocalDate.from(sym454.minus(0, DAYS)), iso); - assertEquals(LocalDate.from(sym454.minus(1, DAYS)), iso.minusDays(1)); - assertEquals(LocalDate.from(sym454.minus(35, DAYS)), iso.minusDays(35)); - assertEquals(LocalDate.from(sym454.minus(-1, DAYS)), iso.minusDays(-1)); - assertEquals(LocalDate.from(sym454.minus(-60, DAYS)), iso.minusDays(-60)); + assertEquals(iso, LocalDate.from(sym454.minus(0, DAYS))); + assertEquals(iso.minusDays(1), LocalDate.from(sym454.minus(1, DAYS))); + assertEquals(iso.minusDays(35), LocalDate.from(sym454.minus(35, DAYS))); + assertEquals(iso.minusDays(-1), LocalDate.from(sym454.minus(-1, DAYS))); + assertEquals(iso.minusDays(-60), LocalDate.from(sym454.minus(-60, DAYS))); } @Test @UseDataProvider("data_samples") public void test_until_DAYS(Symmetry454Date sym454, LocalDate iso) { - assertEquals(sym454.until(iso.plusDays(0), DAYS), 0); - assertEquals(sym454.until(iso.plusDays(1), DAYS), 1); - assertEquals(sym454.until(iso.plusDays(35), DAYS), 35); - assertEquals(sym454.until(iso.minusDays(40), DAYS), -40); + assertEquals(0, sym454.until(iso.plusDays(0), DAYS)); + assertEquals(1, sym454.until(iso.plusDays(1), DAYS)); + assertEquals(35, sym454.until(iso.plusDays(35), DAYS)); + assertEquals(-40, sym454.until(iso.minusDays(40), DAYS)); } @DataProvider @@ -334,19 +334,19 @@ public static Object[][] data_lengthOfMonth() { @Test @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int day, int length) { - assertEquals(Symmetry454Date.of(year, month, day).lengthOfMonth(), length); + assertEquals(length, Symmetry454Date.of(year, month, day).lengthOfMonth()); } @Test @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonthFirst(int year, int month, int day, int length) { - assertEquals(Symmetry454Date.of(year, month, 1).lengthOfMonth(), length); + assertEquals(length, Symmetry454Date.of(year, month, 1).lengthOfMonth()); } @Test public void test_lengthOfMonth_specific() { - assertEquals(Symmetry454Date.of(2000, 12, 28).lengthOfMonth(), 28); - assertEquals(Symmetry454Date.of(2004, 12, 28).lengthOfMonth(), 35); + assertEquals(28, Symmetry454Date.of(2000, 12, 28).lengthOfMonth()); + assertEquals(35, Symmetry454Date.of(2004, 12, 28).lengthOfMonth()); } //----------------------------------------------------------------------- @@ -363,7 +363,7 @@ public void test_era_loop() { assertEquals(era, base.getEra()); assertEquals(year, base.get(YEAR_OF_ERA)); Symmetry454Date eraBased = Symmetry454Chronology.INSTANCE.date(era, year, 1, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } @@ -374,7 +374,7 @@ public void test_era_loop() { assertEquals(era, base.getEra()); assertEquals(1 - year, base.get(YEAR_OF_ERA)); Symmetry454Date eraBased = Symmetry454Chronology.INSTANCE.date(era, year, 1, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } } @@ -387,18 +387,18 @@ public void test_era_yearDay_loop() { assertEquals(era, base.getEra()); assertEquals(year, base.get(YEAR_OF_ERA)); Symmetry454Date eraBased = Symmetry454Chronology.INSTANCE.dateYearDay(era, year, 1); - assertEquals(eraBased, base); + assertEquals(base, eraBased); } } @Test public void test_prolepticYear_specific() { - assertEquals(Symmetry454Chronology.INSTANCE.prolepticYear(IsoEra.CE, 4), 4); - assertEquals(Symmetry454Chronology.INSTANCE.prolepticYear(IsoEra.CE, 3), 3); - assertEquals(Symmetry454Chronology.INSTANCE.prolepticYear(IsoEra.CE, 2), 2); - assertEquals(Symmetry454Chronology.INSTANCE.prolepticYear(IsoEra.CE, 1), 1); - assertEquals(Symmetry454Chronology.INSTANCE.prolepticYear(IsoEra.CE, 2000), 2000); - assertEquals(Symmetry454Chronology.INSTANCE.prolepticYear(IsoEra.CE, 1582), 1582); + assertEquals(4, Symmetry454Chronology.INSTANCE.prolepticYear(IsoEra.CE, 4)); + assertEquals(3, Symmetry454Chronology.INSTANCE.prolepticYear(IsoEra.CE, 3)); + assertEquals(2, Symmetry454Chronology.INSTANCE.prolepticYear(IsoEra.CE, 2)); + assertEquals(1, Symmetry454Chronology.INSTANCE.prolepticYear(IsoEra.CE, 1)); + assertEquals(2000, Symmetry454Chronology.INSTANCE.prolepticYear(IsoEra.CE, 2000)); + assertEquals(1582, Symmetry454Chronology.INSTANCE.prolepticYear(IsoEra.CE, 1582)); } @DataProvider @@ -436,8 +436,8 @@ public void test_prolepticYear_badEra(Era era) { @Test public void test_Chronology_eraOf() { - assertEquals(Symmetry454Chronology.INSTANCE.eraOf(0), IsoEra.BCE); - assertEquals(Symmetry454Chronology.INSTANCE.eraOf(1), IsoEra.CE); + assertEquals(IsoEra.BCE, Symmetry454Chronology.INSTANCE.eraOf(0)); + assertEquals(IsoEra.CE, Symmetry454Chronology.INSTANCE.eraOf(1)); } @Test(expected = DateTimeException.class) @@ -448,7 +448,7 @@ public void test_Chronology_eraOf_invalid() { @Test public void test_Chronology_eras() { List eras = Symmetry454Chronology.INSTANCE.eras(); - assertEquals(eras.size(), 2); + assertEquals(2, eras.size()); assertTrue(eras.contains(IsoEra.BCE)); assertTrue(eras.contains(IsoEra.CE)); } @@ -458,19 +458,19 @@ public void test_Chronology_eras() { //----------------------------------------------------------------------- @Test public void test_Chronology_range() { - assertEquals(Symmetry454Chronology.INSTANCE.range(ALIGNED_DAY_OF_WEEK_IN_MONTH), ValueRange.of(1, 7)); - assertEquals(Symmetry454Chronology.INSTANCE.range(ALIGNED_DAY_OF_WEEK_IN_YEAR), ValueRange.of(1, 7)); - assertEquals(Symmetry454Chronology.INSTANCE.range(ALIGNED_WEEK_OF_MONTH), ValueRange.of(1, 4, 5)); - assertEquals(Symmetry454Chronology.INSTANCE.range(ALIGNED_WEEK_OF_YEAR), ValueRange.of(1, 52, 53)); - assertEquals(Symmetry454Chronology.INSTANCE.range(DAY_OF_WEEK), ValueRange.of(1, 7)); - assertEquals(Symmetry454Chronology.INSTANCE.range(DAY_OF_MONTH), ValueRange.of(1, 28, 35)); - assertEquals(Symmetry454Chronology.INSTANCE.range(DAY_OF_YEAR), ValueRange.of(1, 364, 371)); - assertEquals(Symmetry454Chronology.INSTANCE.range(ERA), ValueRange.of(0, 1)); - assertEquals(Symmetry454Chronology.INSTANCE.range(EPOCH_DAY), ValueRange.of(-1_000_000 * 364L - 177_474 * 7 - 719_162, 1_000_000 * 364L + 177_474 * 7 - 719_162)); - assertEquals(Symmetry454Chronology.INSTANCE.range(MONTH_OF_YEAR), ValueRange.of(1, 12)); - assertEquals(Symmetry454Chronology.INSTANCE.range(PROLEPTIC_MONTH), ValueRange.of(-12_000_000L, 11_999_999L)); - assertEquals(Symmetry454Chronology.INSTANCE.range(YEAR), ValueRange.of(-1_000_000L, 1_000_000)); - assertEquals(Symmetry454Chronology.INSTANCE.range(YEAR_OF_ERA), ValueRange.of(-1_000_000, 1_000_000)); + assertEquals(ValueRange.of(1, 7), Symmetry454Chronology.INSTANCE.range(ALIGNED_DAY_OF_WEEK_IN_MONTH)); + assertEquals(ValueRange.of(1, 7), Symmetry454Chronology.INSTANCE.range(ALIGNED_DAY_OF_WEEK_IN_YEAR)); + assertEquals(ValueRange.of(1, 4, 5), Symmetry454Chronology.INSTANCE.range(ALIGNED_WEEK_OF_MONTH)); + assertEquals(ValueRange.of(1, 52, 53), Symmetry454Chronology.INSTANCE.range(ALIGNED_WEEK_OF_YEAR)); + assertEquals(ValueRange.of(1, 7), Symmetry454Chronology.INSTANCE.range(DAY_OF_WEEK)); + assertEquals(ValueRange.of(1, 28, 35), Symmetry454Chronology.INSTANCE.range(DAY_OF_MONTH)); + assertEquals(ValueRange.of(1, 364, 371), Symmetry454Chronology.INSTANCE.range(DAY_OF_YEAR)); + assertEquals(ValueRange.of(0, 1), Symmetry454Chronology.INSTANCE.range(ERA)); + assertEquals(ValueRange.of(-1_000_000 * 364L - 177_474 * 7 - 719_162, 1_000_000 * 364L + 177_474 * 7 - 719_162), Symmetry454Chronology.INSTANCE.range(EPOCH_DAY)); + assertEquals(ValueRange.of(1, 12), Symmetry454Chronology.INSTANCE.range(MONTH_OF_YEAR)); + assertEquals(ValueRange.of(-12_000_000L, 11_999_999L), Symmetry454Chronology.INSTANCE.range(PROLEPTIC_MONTH)); + assertEquals(ValueRange.of(-1_000_000L, 1_000_000), Symmetry454Chronology.INSTANCE.range(YEAR)); + assertEquals(ValueRange.of(-1_000_000, 1_000_000), Symmetry454Chronology.INSTANCE.range(YEAR_OF_ERA)); } //----------------------------------------------------------------------- @@ -525,7 +525,7 @@ public static Object[][] data_ranges() { @Test @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, ValueRange range) { - assertEquals(Symmetry454Date.of(year, month, dom).range(field), range); + assertEquals(range, Symmetry454Date.of(year, month, dom).range(field)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -574,7 +574,7 @@ public static Object[][] data_getLong() { @Test @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { - assertEquals(Symmetry454Date.of(year, month, dom).getLong(field), expected); + assertEquals(expected, Symmetry454Date.of(year, month, dom).getLong(field)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -666,7 +666,7 @@ public static Object[][] data_with() { public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(Symmetry454Date.of(year, month, dom).with(field, value), Symmetry454Date.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(Symmetry454Date.of(expectedYear, expectedMonth, expectedDom), Symmetry454Date.of(year, month, dom).with(field, value)); } @DataProvider @@ -749,7 +749,7 @@ public void test_temporalAdjusters_LastDayOfMonth(int year, int month, int day, Symmetry454Date base = Symmetry454Date.of(year, month, day); Symmetry454Date expected = Symmetry454Date.of(expectedYear, expectedMonth, expectedDay); Symmetry454Date actual = base.with(TemporalAdjusters.lastDayOfMonth()); - assertEquals(actual, expected); + assertEquals(expected, actual); } //----------------------------------------------------------------------- @@ -759,7 +759,7 @@ public void test_temporalAdjusters_LastDayOfMonth(int year, int month, int day, public void test_adjust_toLocalDate() { Symmetry454Date sym454 = Symmetry454Date.of(2000, 1, 4); Symmetry454Date test = sym454.with(LocalDate.of(2012, 7, 6)); - assertEquals(test, Symmetry454Date.of(2012, 7, 5)); + assertEquals(Symmetry454Date.of(2012, 7, 5), test); } @Test(expected = DateTimeException.class) @@ -775,14 +775,14 @@ public void test_adjust_toMonth() { public void test_LocalDate_adjustToSymmetry454Date() { Symmetry454Date sym454 = Symmetry454Date.of(2012, 7, 19); LocalDate test = LocalDate.MIN.with(sym454); - assertEquals(test, LocalDate.of(2012, 7, 20)); + assertEquals(LocalDate.of(2012, 7, 20), test); } @Test public void test_LocalDateTime_adjustToSymmetry454Date() { Symmetry454Date sym454 = Symmetry454Date.of(2012, 7, 19); LocalDateTime test = LocalDateTime.MIN.with(sym454); - assertEquals(test, LocalDateTime.of(2012, 7, 20, 0, 0)); + assertEquals(LocalDateTime.of(2012, 7, 20, 0, 0), test); } //----------------------------------------------------------------------- @@ -850,7 +850,7 @@ public static Object[][] data_plus_leapWeek() { public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(Symmetry454Date.of(year, month, dom).plus(amount, unit), Symmetry454Date.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(Symmetry454Date.of(expectedYear, expectedMonth, expectedDom), Symmetry454Date.of(year, month, dom).plus(amount, unit)); } @Test @@ -858,7 +858,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, public void test_plus_leapWeek_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { - assertEquals(Symmetry454Date.of(year, month, dom).plus(amount, unit), Symmetry454Date.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(Symmetry454Date.of(expectedYear, expectedMonth, expectedDom), Symmetry454Date.of(year, month, dom).plus(amount, unit)); } @Test @@ -867,7 +867,7 @@ public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, int year, int month, int dom) { - assertEquals(Symmetry454Date.of(year, month, dom).minus(amount, unit), Symmetry454Date.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(Symmetry454Date.of(expectedYear, expectedMonth, expectedDom), Symmetry454Date.of(year, month, dom).minus(amount, unit)); } @Test @@ -876,7 +876,7 @@ public void test_minus_leapWeek_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, int year, int month, int dom) { - assertEquals(Symmetry454Date.of(year, month, dom).minus(amount, unit), Symmetry454Date.of(expectedYear, expectedMonth, expectedDom)); + assertEquals(Symmetry454Date.of(expectedYear, expectedMonth, expectedDom), Symmetry454Date.of(year, month, dom).minus(amount, unit)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -938,7 +938,7 @@ public void test_until_TemporalUnit( TemporalUnit unit, long expected) { Symmetry454Date start = Symmetry454Date.of(year1, month1, dom1); Symmetry454Date end = Symmetry454Date.of(year2, month2, dom2); - assertEquals(start.until(end, unit), expected); + assertEquals(expected, start.until(end, unit)); } @Test @@ -950,7 +950,7 @@ public void test_until_end( Symmetry454Date start = Symmetry454Date.of(year1, month1, dom1); Symmetry454Date end = Symmetry454Date.of(year2, month2, dom2); ChronoPeriod period = Symmetry454Chronology.INSTANCE.period(yearPeriod, monthPeriod, dayPeriod); - assertEquals(start.until(end), period); + assertEquals(period, start.until(end)); } @Test(expected = UnsupportedTemporalTypeException.class) @@ -965,25 +965,25 @@ public void test_until_TemporalUnit_unsupported() { //----------------------------------------------------------------------- @Test public void test_plus_Period() { - assertEquals(Symmetry454Date.of(2014, 5, 21).plus(Symmetry454Chronology.INSTANCE.period(0, 2, 8)), - Symmetry454Date.of(2014, 8, 1)); + assertEquals(Symmetry454Date.of(2014, 8, 1), + Symmetry454Date.of(2014, 5, 21).plus(Symmetry454Chronology.INSTANCE.period(0, 2, 8))); } @Test(expected = DateTimeException.class) public void test_plus_Period_ISO() { - assertEquals(Symmetry454Date.of(2014, 5, 26).plus(Period.ofMonths(2)), - Symmetry454Date.of(2014, 7, 26)); + assertEquals(Symmetry454Date.of(2014, 7, 26), + Symmetry454Date.of(2014, 5, 26).plus(Period.ofMonths(2))); } @Test public void test_minus_Period() { - assertEquals(Symmetry454Date.of(2014, 5, 26).minus(Symmetry454Chronology.INSTANCE.period(0, 2, 3)), - Symmetry454Date.of(2014, 3, 23)); + assertEquals(Symmetry454Date.of(2014, 3, 23), + Symmetry454Date.of(2014, 5, 26).minus(Symmetry454Chronology.INSTANCE.period(0, 2, 3))); } @Test(expected = DateTimeException.class) public void test_minus_Period_ISO() { - assertEquals(Symmetry454Date.of(2014, 5, 26).minus(Period.ofMonths(2)), Symmetry454Date.of(2014, 3, 26)); + assertEquals(Symmetry454Date.of(2014, 3, 26), Symmetry454Date.of(2014, 5, 26).minus(Period.ofMonths(2))); } //----------------------------------------------------------------------- @@ -1026,6 +1026,6 @@ public static Object[][] data_toString() { @Test @UseDataProvider("data_toString") public void test_toString(Symmetry454Date date, String expected) { - assertEquals(date.toString(), expected); + assertEquals(expected, date.toString()); } } diff --git a/src/test/java/org/threeten/extra/scale/TestTaiInstant.java b/src/test/java/org/threeten/extra/scale/TestTaiInstant.java index 9f4d5b24..806bfb3f 100644 --- a/src/test/java/org/threeten/extra/scale/TestTaiInstant.java +++ b/src/test/java/org/threeten/extra/scale/TestTaiInstant.java @@ -75,7 +75,7 @@ public void test_serialization() throws Exception { oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertEquals(ois.readObject(), test); + assertEquals(test, ois.readObject()); } } @@ -87,18 +87,18 @@ public void factory_ofTaiSecondslong_long() { for (long i = -2; i <= 2; i++) { for (int j = 0; j < 10; j++) { TaiInstant t = TaiInstant.ofTaiSeconds(i, j); - assertEquals(t.getTaiSeconds(), i); - assertEquals(t.getNano(), j); + assertEquals(i, t.getTaiSeconds()); + assertEquals(j, t.getNano()); } for (int j = -10; j < 0; j++) { TaiInstant t = TaiInstant.ofTaiSeconds(i, j); - assertEquals(t.getTaiSeconds(), i - 1); - assertEquals(t.getNano(), j + 1000000000); + assertEquals(i - 1, t.getTaiSeconds()); + assertEquals(j + 1000000000, t.getNano()); } for (int j = 999999990; j < 1000000000; j++) { TaiInstant t = TaiInstant.ofTaiSeconds(i, j); - assertEquals(t.getTaiSeconds(), i); - assertEquals(t.getNano(), j); + assertEquals(i, t.getTaiSeconds()); + assertEquals(j, t.getNano()); } } } @@ -106,8 +106,8 @@ public void factory_ofTaiSecondslong_long() { @Test public void factory_ofTaiSeconds_long_long_nanosNegativeAdjusted() { TaiInstant test = TaiInstant.ofTaiSeconds(2L, -1); - assertEquals(test.getTaiSeconds(), 1); - assertEquals(test.getNano(), 999999999); + assertEquals(1, test.getTaiSeconds()); + assertEquals(999999999, test.getNano()); } @Test(expected = ArithmeticException.class) @@ -121,8 +121,8 @@ public void factory_ofTaiSeconds_long_long_tooBig() { @Test public void factory_of_Instant() { TaiInstant test = TaiInstant.of(Instant.ofEpochSecond(0, 2)); - assertEquals(test.getTaiSeconds(), (40587L - 36204) * 24 * 60 * 60 + 10); //((1970 - 1958) * 365 + 3) * 24 * 60 * 60 + 10); - assertEquals(test.getNano(), 2); + assertEquals((40587L - 36204) * 24 * 60 * 60 + 10, test.getTaiSeconds()); //((1970 - 1958) * 365 + 3) * 24 * 60 * 60 + 10); + assertEquals(2, test.getNano()); } @Test(expected = NullPointerException.class) @@ -138,8 +138,8 @@ public void factory_of_UtcInstant() { for (int i = -1000; i < 1000; i++) { for (int j = 0; j < 10; j++) { TaiInstant test = TaiInstant.of(UtcInstant.ofModifiedJulianDay(36204 + i, j * 1000000000L + 2L)); - assertEquals(test.getTaiSeconds(), i * 24 * 60 * 60 + j + 10); - assertEquals(test.getNano(), 2); + assertEquals(i * 24 * 60 * 60 + j + 10, test.getTaiSeconds()); + assertEquals(2, test.getNano()); } } } @@ -158,8 +158,8 @@ public void factory_parse_CharSequence() { for (int j = 900000000; j < 990000000; j += 10000000) { String str = i + "." + j + "s(TAI)"; TaiInstant test = TaiInstant.parse(str); - assertEquals(test.getTaiSeconds(), i); - assertEquals(test.getNano(), j); + assertEquals(i, test.getTaiSeconds()); + assertEquals(j, test.getNano()); } } } @@ -206,8 +206,8 @@ public static Object[][] data_withTAISeconds() { @UseDataProvider("data_withTAISeconds") public void test_withTAISeconds(long tai, long nanos, long newTai, Long expectedTai, Long expectedNanos) { TaiInstant i = TaiInstant.ofTaiSeconds(tai, nanos).withTaiSeconds(newTai); - assertEquals(i.getTaiSeconds(), expectedTai.longValue()); - assertEquals(i.getNano(), expectedNanos.longValue()); + assertEquals(expectedTai.longValue(), i.getTaiSeconds()); + assertEquals(expectedNanos.longValue(), i.getNano()); } //----------------------------------------------------------------------- @@ -231,8 +231,8 @@ public void test_withNano(long tai, long nanos, int newNano, Long expectedTai, L TaiInstant i = TaiInstant.ofTaiSeconds(tai, nanos); if (expectedTai != null) { i = i.withNano(newNano); - assertEquals(i.getTaiSeconds(), expectedTai.longValue()); - assertEquals(i.getNano(), expectedNanos.longValue()); + assertEquals(expectedTai.longValue(), i.getTaiSeconds()); + assertEquals(expectedNanos.longValue(), i.getNano()); } else { try { i = i.withNano(newNano); @@ -435,8 +435,8 @@ public static Object[][] data_plus() { @UseDataProvider("data_plus") public void test_plus(long seconds, int nanos, long plusSeconds, int plusNanos, long expectedSeconds, int expectedNanoOfSecond) { TaiInstant i = TaiInstant.ofTaiSeconds(seconds, nanos).plus(Duration.ofSeconds(plusSeconds, plusNanos)); - assertEquals(i.getTaiSeconds(), expectedSeconds); - assertEquals(i.getNano(), expectedNanoOfSecond); + assertEquals(expectedSeconds, i.getTaiSeconds()); + assertEquals(expectedNanoOfSecond, i.getNano()); } @Test(expected = ArithmeticException.class) @@ -643,8 +643,8 @@ public static Object[][] data_minus() { @UseDataProvider("data_minus") public void test_minus(long seconds, int nanos, long minusSeconds, int minusNanos, long expectedSeconds, int expectedNanoOfSecond) { TaiInstant i = TaiInstant.ofTaiSeconds(seconds, nanos).minus(Duration.ofSeconds(minusSeconds, minusNanos)); - assertEquals(i.getTaiSeconds(), expectedSeconds); - assertEquals(i.getNano(), expectedNanoOfSecond); + assertEquals(expectedSeconds, i.getTaiSeconds()); + assertEquals(expectedNanoOfSecond, i.getNano()); } @Test(expected = ArithmeticException.class) @@ -667,8 +667,8 @@ public void test_durationUntil_fifteenSeconds() { TaiInstant tai1 = TaiInstant.ofTaiSeconds(10, 0); TaiInstant tai2 = TaiInstant.ofTaiSeconds(25, 0); Duration test = tai1.durationUntil(tai2); - assertEquals(test.getSeconds(), 15); - assertEquals(test.getNano(), 0); + assertEquals(15, test.getSeconds()); + assertEquals(0, test.getNano()); } @Test @@ -676,8 +676,8 @@ public void test_durationUntil_twoNanos() { TaiInstant tai1 = TaiInstant.ofTaiSeconds(4, 5); TaiInstant tai2 = TaiInstant.ofTaiSeconds(4, 7); Duration test = tai1.durationUntil(tai2); - assertEquals(test.getSeconds(), 0); - assertEquals(test.getNano(), 2); + assertEquals(0, test.getSeconds()); + assertEquals(2, test.getNano()); } @Test @@ -685,8 +685,8 @@ public void test_durationUntil_twoNanosNegative() { TaiInstant tai1 = TaiInstant.ofTaiSeconds(4, 9); TaiInstant tai2 = TaiInstant.ofTaiSeconds(4, 7); Duration test = tai1.durationUntil(tai2); - assertEquals(test.getSeconds(), -1); - assertEquals(test.getNano(), 999999998); + assertEquals(-1, test.getSeconds()); + assertEquals(999999998, test.getNano()); } //----------------------------------------------------------------------- @@ -698,7 +698,7 @@ public void test_toUtcInstant() { for (int j = 0; j < 10; j++) { UtcInstant expected = UtcInstant.ofModifiedJulianDay(36204 + i, j * 1000000000L + 2L); TaiInstant test = TaiInstant.ofTaiSeconds(i * 24 * 60 * 60 + j + 10, 2); - assertEquals(test.toUtcInstant(), expected); + assertEquals(expected, test.toUtcInstant()); } } } @@ -712,7 +712,7 @@ public void test_toInstant() { for (int j = 0; j < 10; j++) { Instant expected = Instant.ofEpochSecond(-378691200L + i * 24 * 60 * 60 + j).plusNanos(2); TaiInstant test = TaiInstant.ofTaiSeconds(i * 24 * 60 * 60 + j + 10, 2); - assertEquals(test.toInstant(), expected); + assertEquals(expected, test.toInstant()); } } } @@ -745,14 +745,14 @@ void doTest_comparisons_TaiInstant(TaiInstant... instants) { for (int j = 0; j < instants.length; j++) { TaiInstant b = instants[j]; if (i < j) { - assertEquals(a.compareTo(b) < 0, true); - assertEquals(a.equals(b), false); + assertEquals(true, a.compareTo(b) < 0); + assertEquals(false, a.equals(b)); } else if (i > j) { - assertEquals(a.compareTo(b) > 0, true); - assertEquals(a.equals(b), false); + assertEquals(true, a.compareTo(b) > 0); + assertEquals(false, a.equals(b)); } else { - assertEquals(a.compareTo(b), 0); - assertEquals(a.equals(b), true); + assertEquals(0, a.compareTo(b)); + assertEquals(true, a.equals(b)); } } } @@ -781,37 +781,37 @@ public void test_equals() { TaiInstant test5n = TaiInstant.ofTaiSeconds(5L, 30); TaiInstant test6 = TaiInstant.ofTaiSeconds(6L, 20); - assertEquals(test5a.equals(test5a), true); - assertEquals(test5a.equals(test5b), true); - assertEquals(test5a.equals(test5n), false); - assertEquals(test5a.equals(test6), false); + assertEquals(true, test5a.equals(test5a)); + assertEquals(true, test5a.equals(test5b)); + assertEquals(false, test5a.equals(test5n)); + assertEquals(false, test5a.equals(test6)); - assertEquals(test5b.equals(test5a), true); - assertEquals(test5b.equals(test5b), true); - assertEquals(test5b.equals(test5n), false); - assertEquals(test5b.equals(test6), false); + assertEquals(true, test5b.equals(test5a)); + assertEquals(true, test5b.equals(test5b)); + assertEquals(false, test5b.equals(test5n)); + assertEquals(false, test5b.equals(test6)); - assertEquals(test5n.equals(test5a), false); - assertEquals(test5n.equals(test5b), false); - assertEquals(test5n.equals(test5n), true); - assertEquals(test5n.equals(test6), false); + assertEquals(false, test5n.equals(test5a)); + assertEquals(false, test5n.equals(test5b)); + assertEquals(true, test5n.equals(test5n)); + assertEquals(false, test5n.equals(test6)); - assertEquals(test6.equals(test5a), false); - assertEquals(test6.equals(test5b), false); - assertEquals(test6.equals(test5n), false); - assertEquals(test6.equals(test6), true); + assertEquals(false, test6.equals(test5a)); + assertEquals(false, test6.equals(test5b)); + assertEquals(false, test6.equals(test5n)); + assertEquals(true, test6.equals(test6)); } @Test public void test_equals_null() { TaiInstant test5 = TaiInstant.ofTaiSeconds(5L, 20); - assertEquals(test5.equals(null), false); + assertEquals(false, test5.equals(null)); } @Test public void test_equals_otherClass() { TaiInstant test5 = TaiInstant.ofTaiSeconds(5L, 20); - assertEquals(test5.equals(""), false); + assertEquals(false, test5.equals("")); } //----------------------------------------------------------------------- @@ -824,12 +824,12 @@ public void test_hashCode() { TaiInstant test5n = TaiInstant.ofTaiSeconds(5L, 30); TaiInstant test6 = TaiInstant.ofTaiSeconds(6L, 20); - assertEquals(test5a.hashCode() == test5a.hashCode(), true); - assertEquals(test5a.hashCode() == test5b.hashCode(), true); - assertEquals(test5b.hashCode() == test5b.hashCode(), true); + assertEquals(true, test5a.hashCode() == test5a.hashCode()); + assertEquals(true, test5a.hashCode() == test5b.hashCode()); + assertEquals(true, test5b.hashCode() == test5b.hashCode()); - assertEquals(test5a.hashCode() == test5n.hashCode(), false); - assertEquals(test5a.hashCode() == test6.hashCode(), false); + assertEquals(false, test5a.hashCode() == test5n.hashCode()); + assertEquals(false, test5a.hashCode() == test6.hashCode()); } //----------------------------------------------------------------------- @@ -838,19 +838,19 @@ public void test_hashCode() { @Test public void test_toString_standard() { TaiInstant t = TaiInstant.ofTaiSeconds(123L, 123456789); - assertEquals(t.toString(), "123.123456789s(TAI)"); + assertEquals("123.123456789s(TAI)", t.toString()); } @Test public void test_toString_negative() { TaiInstant t = TaiInstant.ofTaiSeconds(-123L, 123456789); - assertEquals(t.toString(), "-123.123456789s(TAI)"); + assertEquals("-123.123456789s(TAI)", t.toString()); } @Test public void test_toString_zeroDecimal() { TaiInstant t = TaiInstant.ofTaiSeconds(0L, 567); - assertEquals(t.toString(), "0.000000567s(TAI)"); + assertEquals("0.000000567s(TAI)", t.toString()); } } diff --git a/src/test/java/org/threeten/extra/scale/TestUtcInstant.java b/src/test/java/org/threeten/extra/scale/TestUtcInstant.java index cb94cdbd..6f7ec55a 100644 --- a/src/test/java/org/threeten/extra/scale/TestUtcInstant.java +++ b/src/test/java/org/threeten/extra/scale/TestUtcInstant.java @@ -85,7 +85,7 @@ public void test_serialization() throws Exception { oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertEquals(ois.readObject(), test); + assertEquals(test, ois.readObject()); } } @@ -97,9 +97,9 @@ public void factory_ofModifiedJulianDay_long_long() { for (long i = -2; i <= 2; i++) { for (int j = 0; j < 10; j++) { UtcInstant t = UtcInstant.ofModifiedJulianDay(i, j); - assertEquals(t.getModifiedJulianDay(), i); - assertEquals(t.getNanoOfDay(), j); - assertEquals(t.isLeapSecond(), false); + assertEquals(i, t.getModifiedJulianDay()); + assertEquals(j, t.getNanoOfDay()); + assertEquals(false, t.isLeapSecond()); } } } @@ -107,15 +107,15 @@ public void factory_ofModifiedJulianDay_long_long() { @Test public void factory_ofModifiedJulianDay_long_long_startLeap() { UtcInstant t = UtcInstant.ofModifiedJulianDay(MJD_1972_12_31_LEAP, NANOS_PER_DAY); - assertEquals(t.getModifiedJulianDay(), MJD_1972_12_31_LEAP); - assertEquals(t.getNanoOfDay(), NANOS_PER_DAY); + assertEquals(MJD_1972_12_31_LEAP, t.getModifiedJulianDay()); + assertEquals(NANOS_PER_DAY, t.getNanoOfDay()); } @Test public void factory_ofModifiedJulianDay_long_long_endLeap() { UtcInstant t = UtcInstant.ofModifiedJulianDay(MJD_1972_12_31_LEAP, NANOS_PER_LEAP_DAY - 1); - assertEquals(t.getModifiedJulianDay(), MJD_1972_12_31_LEAP); - assertEquals(t.getNanoOfDay(), NANOS_PER_LEAP_DAY - 1); + assertEquals(MJD_1972_12_31_LEAP, t.getModifiedJulianDay()); + assertEquals(NANOS_PER_LEAP_DAY - 1, t.getNanoOfDay()); } @Test(expected = DateTimeException.class) @@ -139,8 +139,8 @@ public void factory_ofModifiedJulianDay_long_long_nanosTooBig_leap() { @Test public void factory_of_Instant() { UtcInstant test = UtcInstant.of(Instant.ofEpochSecond(0, 2)); // 1970-01-01 - assertEquals(test.getModifiedJulianDay(), 40587); - assertEquals(test.getNanoOfDay(), 2); + assertEquals(40587, test.getModifiedJulianDay()); + assertEquals(2, test.getNanoOfDay()); } @Test(expected = NullPointerException.class) @@ -157,7 +157,7 @@ public void factory_of_TaiInstant() { for (int j = 0; j < 10; j++) { UtcInstant expected = UtcInstant.ofModifiedJulianDay(36204 + i, j * NANOS_PER_SEC + 2L); TaiInstant tai = TaiInstant.ofTaiSeconds(i * SECS_PER_DAY + j + 10, 2); - assertEquals(UtcInstant.of(tai), expected); + assertEquals(expected, UtcInstant.of(tai)); } } } @@ -172,8 +172,8 @@ public void factory_of_TaiInstant_null() { //----------------------------------------------------------------------- @Test public void factory_parse_CharSequence() { - assertEquals(UtcInstant.parse("1972-12-31T23:59:59Z"), UtcInstant.ofModifiedJulianDay(MJD_1972_12_31_LEAP, NANOS_PER_DAY - NANOS_PER_SEC)); - assertEquals(UtcInstant.parse("1972-12-31T23:59:60Z"), UtcInstant.ofModifiedJulianDay(MJD_1972_12_31_LEAP, NANOS_PER_DAY)); + assertEquals(UtcInstant.ofModifiedJulianDay(MJD_1972_12_31_LEAP, NANOS_PER_DAY - NANOS_PER_SEC), UtcInstant.parse("1972-12-31T23:59:59Z")); + assertEquals(UtcInstant.ofModifiedJulianDay(MJD_1972_12_31_LEAP, NANOS_PER_DAY), UtcInstant.parse("1972-12-31T23:59:60Z")); } @DataProvider @@ -226,8 +226,8 @@ public void test_withModifiedJulianDay(long mjd, long nanos, long newMjd, Long e UtcInstant i = UtcInstant.ofModifiedJulianDay(mjd, nanos); if (expectedMjd != null) { i = i.withModifiedJulianDay(newMjd); - assertEquals(i.getModifiedJulianDay(), expectedMjd.longValue()); - assertEquals(i.getNanoOfDay(), expectedNanos.longValue()); + assertEquals(expectedMjd.longValue(), i.getModifiedJulianDay()); + assertEquals(expectedNanos.longValue(), i.getNanoOfDay()); } else { try { i = i.withModifiedJulianDay(newMjd); @@ -269,8 +269,8 @@ public void test_withNanoOfDay(long mjd, long nanos, long newNanoOfDay, Long exp UtcInstant i = UtcInstant.ofModifiedJulianDay(mjd, nanos); if (expectedMjd != null) { i = i.withNanoOfDay(newNanoOfDay); - assertEquals(i.getModifiedJulianDay(), expectedMjd.longValue()); - assertEquals(i.getNanoOfDay(), expectedNanos.longValue()); + assertEquals(expectedMjd.longValue(), i.getModifiedJulianDay()); + assertEquals(expectedNanos.longValue(), i.getNanoOfDay()); } else { try { i = i.withNanoOfDay(newNanoOfDay); @@ -323,8 +323,8 @@ public static Object[][] data_plus() { @UseDataProvider("data_plus") public void test_plus(long mjd, long nanos, long plusSeconds, int plusNanos, long expectedMjd, long expectedNanos) { UtcInstant i = UtcInstant.ofModifiedJulianDay(mjd, nanos).plus(Duration.ofSeconds(plusSeconds, plusNanos)); - assertEquals(i.getModifiedJulianDay(), expectedMjd); - assertEquals(i.getNanoOfDay(), expectedNanos); + assertEquals(expectedMjd, i.getModifiedJulianDay()); + assertEquals(expectedNanos, i.getNanoOfDay()); } @Test(expected = ArithmeticException.class) @@ -381,8 +381,8 @@ public static Object[][] data_minus() { @UseDataProvider("data_minus") public void test_minus(long mjd, long nanos, long minusSeconds, int minusNanos, long expectedMjd, long expectedNanos) { UtcInstant i = UtcInstant.ofModifiedJulianDay(mjd, nanos).minus(Duration.ofSeconds(minusSeconds, minusNanos)); - assertEquals(i.getModifiedJulianDay(), expectedMjd); - assertEquals(i.getNanoOfDay(), expectedNanos); + assertEquals(expectedMjd, i.getModifiedJulianDay()); + assertEquals(expectedNanos, i.getNanoOfDay()); } @Test(expected = ArithmeticException.class) @@ -405,8 +405,8 @@ public void test_durationUntil_oneDayNoLeap() { UtcInstant utc1 = UtcInstant.ofModifiedJulianDay(MJD_1972_12_30, 0); UtcInstant utc2 = UtcInstant.ofModifiedJulianDay(MJD_1972_12_31_LEAP, 0); Duration test = utc1.durationUntil(utc2); - assertEquals(test.getSeconds(), 86400); - assertEquals(test.getNano(), 0); + assertEquals(86400, test.getSeconds()); + assertEquals(0, test.getNano()); } @Test @@ -414,8 +414,8 @@ public void test_durationUntil_oneDayLeap() { UtcInstant utc1 = UtcInstant.ofModifiedJulianDay(MJD_1972_12_31_LEAP, 0); UtcInstant utc2 = UtcInstant.ofModifiedJulianDay(MJD_1973_01_01, 0); Duration test = utc1.durationUntil(utc2); - assertEquals(test.getSeconds(), 86401); - assertEquals(test.getNano(), 0); + assertEquals(86401, test.getSeconds()); + assertEquals(0, test.getNano()); } @Test @@ -423,8 +423,8 @@ public void test_durationUntil_oneDayLeapNegative() { UtcInstant utc1 = UtcInstant.ofModifiedJulianDay(MJD_1973_01_01, 0); UtcInstant utc2 = UtcInstant.ofModifiedJulianDay(MJD_1972_12_31_LEAP, 0); Duration test = utc1.durationUntil(utc2); - assertEquals(test.getSeconds(), -86401); - assertEquals(test.getNano(), 0); + assertEquals(-86401, test.getSeconds()); + assertEquals(0, test.getNano()); } //----------------------------------------------------------------------- @@ -436,8 +436,8 @@ public void test_toTaiInstant() { for (int j = 0; j < 10; j++) { UtcInstant utc = UtcInstant.ofModifiedJulianDay(36204 + i, j * NANOS_PER_SEC + 2L); TaiInstant test = utc.toTaiInstant(); - assertEquals(test.getTaiSeconds(), i * SECS_PER_DAY + j + 10); - assertEquals(test.getNano(), 2); + assertEquals(i * SECS_PER_DAY + j + 10, test.getTaiSeconds()); + assertEquals(2, test.getNano()); } } } @@ -457,7 +457,7 @@ public void test_toInstant() { for (int j = 0; j < 10; j++) { Instant expected = Instant.ofEpochSecond(315532800 + i * SECS_PER_DAY + j).plusNanos(2); UtcInstant test = UtcInstant.ofModifiedJulianDay(44239 + i, j * NANOS_PER_SEC + 2); - assertEquals(test.toInstant(), expected); + assertEquals(expected, test.toInstant()); } } } @@ -490,14 +490,14 @@ void doTest_comparisons_UtcInstant(UtcInstant... instants) { for (int j = 0; j < instants.length; j++) { UtcInstant b = instants[j]; if (i < j) { - assertEquals(a.compareTo(b), -1); - assertEquals(a.equals(b), false); + assertEquals(-1, a.compareTo(b)); + assertEquals(false, a.equals(b)); } else if (i > j) { - assertEquals(a.compareTo(b), 1); - assertEquals(a.equals(b), false); + assertEquals(1, a.compareTo(b)); + assertEquals(false, a.equals(b)); } else { - assertEquals(a.compareTo(b), 0); - assertEquals(a.equals(b), true); + assertEquals(0, a.compareTo(b)); + assertEquals(true, a.equals(b)); } } } @@ -526,37 +526,37 @@ public void test_equals() { UtcInstant test5n = UtcInstant.ofModifiedJulianDay(5L, 30); UtcInstant test6 = UtcInstant.ofModifiedJulianDay(6L, 20); - assertEquals(test5a.equals(test5a), true); - assertEquals(test5a.equals(test5b), true); - assertEquals(test5a.equals(test5n), false); - assertEquals(test5a.equals(test6), false); + assertEquals(true, test5a.equals(test5a)); + assertEquals(true, test5a.equals(test5b)); + assertEquals(false, test5a.equals(test5n)); + assertEquals(false, test5a.equals(test6)); - assertEquals(test5b.equals(test5a), true); - assertEquals(test5b.equals(test5b), true); - assertEquals(test5b.equals(test5n), false); - assertEquals(test5b.equals(test6), false); + assertEquals(true, test5b.equals(test5a)); + assertEquals(true, test5b.equals(test5b)); + assertEquals(false, test5b.equals(test5n)); + assertEquals(false, test5b.equals(test6)); - assertEquals(test5n.equals(test5a), false); - assertEquals(test5n.equals(test5b), false); - assertEquals(test5n.equals(test5n), true); - assertEquals(test5n.equals(test6), false); + assertEquals(false, test5n.equals(test5a)); + assertEquals(false, test5n.equals(test5b)); + assertEquals(true, test5n.equals(test5n)); + assertEquals(false, test5n.equals(test6)); - assertEquals(test6.equals(test5a), false); - assertEquals(test6.equals(test5b), false); - assertEquals(test6.equals(test5n), false); - assertEquals(test6.equals(test6), true); + assertEquals(false, test6.equals(test5a)); + assertEquals(false, test6.equals(test5b)); + assertEquals(false, test6.equals(test5n)); + assertEquals(true, test6.equals(test6)); } @Test public void test_equals_null() { UtcInstant test5 = UtcInstant.ofModifiedJulianDay(5L, 20); - assertEquals(test5.equals(null), false); + assertEquals(false, test5.equals(null)); } @Test public void test_equals_otherClass() { UtcInstant test5 = UtcInstant.ofModifiedJulianDay(5L, 20); - assertEquals(test5.equals(""), false); + assertEquals(false, test5.equals("")); } //----------------------------------------------------------------------- @@ -569,12 +569,12 @@ public void test_hashCode() { UtcInstant test5n = UtcInstant.ofModifiedJulianDay(5L, 30); UtcInstant test6 = UtcInstant.ofModifiedJulianDay(6L, 20); - assertEquals(test5a.hashCode() == test5a.hashCode(), true); - assertEquals(test5a.hashCode() == test5b.hashCode(), true); - assertEquals(test5b.hashCode() == test5b.hashCode(), true); + assertEquals(true, test5a.hashCode() == test5a.hashCode()); + assertEquals(true, test5a.hashCode() == test5b.hashCode()); + assertEquals(true, test5b.hashCode() == test5b.hashCode()); - assertEquals(test5a.hashCode() == test5n.hashCode(), false); - assertEquals(test5a.hashCode() == test6.hashCode(), false); + assertEquals(false, test5a.hashCode() == test5n.hashCode()); + assertEquals(false, test5a.hashCode() == test6.hashCode()); } //----------------------------------------------------------------------- @@ -602,13 +602,13 @@ public static Object[][] data_toString() { @Test @UseDataProvider("data_toString") public void test_toString(long mjd, long nod, String expected) { - assertEquals(UtcInstant.ofModifiedJulianDay(mjd, nod).toString(), expected); + assertEquals(expected, UtcInstant.ofModifiedJulianDay(mjd, nod).toString()); } @Test @UseDataProvider("data_toString") public void test_toString_parse(long mjd, long nod, String str) { - assertEquals(UtcInstant.parse(str), UtcInstant.ofModifiedJulianDay(mjd, nod)); + assertEquals(UtcInstant.ofModifiedJulianDay(mjd, nod), UtcInstant.parse(str)); } } diff --git a/src/test/java/org/threeten/extra/scale/TestUtcRules.java b/src/test/java/org/threeten/extra/scale/TestUtcRules.java index 70363df7..8aac6537 100644 --- a/src/test/java/org/threeten/extra/scale/TestUtcRules.java +++ b/src/test/java/org/threeten/extra/scale/TestUtcRules.java @@ -98,7 +98,7 @@ public void test_serialization() throws Exception { //----------------------------------------------------------------------- @Test public void test_getName() { - assertEquals(rules.getName(), "System"); + assertEquals("System", rules.getName()); } //----------------------------------------------------------------------- @@ -240,14 +240,14 @@ public static Object[][] data_leapSeconds() { @Test @UseDataProvider("data_leapSeconds") public void test_leapSeconds(long mjd, int adjust, int offset, String checkDate) { - assertEquals(mjd, LocalDate.parse(checkDate).getLong(JulianFields.MODIFIED_JULIAN_DAY)); + assertEquals(LocalDate.parse(checkDate).getLong(JulianFields.MODIFIED_JULIAN_DAY), mjd); - assertEquals(rules.getLeapSecondAdjustment(mjd), adjust); - assertEquals(rules.getTaiOffset(mjd), offset); + assertEquals(adjust, rules.getLeapSecondAdjustment(mjd)); + assertEquals(offset, rules.getTaiOffset(mjd)); if (adjust != 0) { long[] leaps = rules.getLeapSecondDates(); Arrays.sort(leaps); - assertEquals(Arrays.binarySearch(leaps, mjd) >= 0, true); + assertEquals(true, Arrays.binarySearch(leaps, mjd) >= 0); } } @@ -275,13 +275,13 @@ public void test_convertToUtc_TaiInstant_startUtcPeriod() { UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_1980, 0); for (int i = -10; i < 10; i++) { Duration duration = Duration.ofNanos(i); - assertEquals(rules.convertToUtc(tai.plus(duration)), expected.plus(duration)); - assertEquals(rules.convertToTai(expected.plus(duration)), tai.plus(duration)); // check reverse + assertEquals(expected.plus(duration), rules.convertToUtc(tai.plus(duration))); + assertEquals(tai.plus(duration), rules.convertToTai(expected.plus(duration))); // check reverse } for (int i = -10; i < 10; i++) { Duration duration = Duration.ofSeconds(i); - assertEquals(rules.convertToUtc(tai.plus(duration)), expected.plus(duration)); - assertEquals(rules.convertToTai(expected.plus(duration)), tai.plus(duration)); // check reverse + assertEquals(expected.plus(duration), rules.convertToUtc(tai.plus(duration))); + assertEquals(tai.plus(duration), rules.convertToTai(expected.plus(duration))); // check reverse } } @@ -289,64 +289,64 @@ public void test_convertToUtc_TaiInstant_startUtcPeriod() { public void test_convertToUtc_TaiInstant_furtherAfterLeap() { TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC1980 + 1, 0); // 1980-01-01 (19 leap secs added) UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_1980, NANOS_PER_SEC); - assertEquals(rules.convertToUtc(tai), expected); - assertEquals(rules.convertToTai(expected), tai); // check reverse + assertEquals(expected, rules.convertToUtc(tai)); + assertEquals(tai, rules.convertToTai(expected)); // check reverse } @Test public void test_convertToUtc_TaiInstant_justAfterLeap() { TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC1980, 0); // 1980-01-01 (19 leap secs added) UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_1980, 0); - assertEquals(rules.convertToUtc(tai), expected); - assertEquals(rules.convertToTai(expected), tai); // check reverse + assertEquals(expected, rules.convertToUtc(tai)); + assertEquals(tai, rules.convertToTai(expected)); // check reverse } @Test public void test_convertToUtc_TaiInstant_inLeap() { TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC1980 - 1, 0); // 1980-01-01 (1 second before 1980) UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_1980 - 1, SECS_PER_DAY * NANOS_PER_SEC); - assertEquals(rules.convertToUtc(tai), expected); - assertEquals(rules.convertToTai(expected), tai); // check reverse + assertEquals(expected, rules.convertToUtc(tai)); + assertEquals(tai, rules.convertToTai(expected)); // check reverse } @Test public void test_convertToUtc_TaiInstant_justBeforeLeap() { TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC1980 - 2, 0); // 1980-01-01 (2 seconds before 1980) UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_1980 - 1, (SECS_PER_DAY - 1) * NANOS_PER_SEC); - assertEquals(rules.convertToUtc(tai), expected); - assertEquals(rules.convertToTai(expected), tai); // check reverse + assertEquals(expected, rules.convertToUtc(tai)); + assertEquals(tai, rules.convertToTai(expected)); // check reverse } @Test public void test_convertToUtc_TaiInstant_1800() { TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC1800, 0); // 1800-01-01 UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_1800, 0); - assertEquals(rules.convertToUtc(tai), expected); - assertEquals(rules.convertToTai(expected), tai); // check reverse + assertEquals(expected, rules.convertToUtc(tai)); + assertEquals(tai, rules.convertToTai(expected)); // check reverse } @Test public void test_convertToUtc_TaiInstant_1900() { TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC1900, 0); // 1900-01-01 UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_1900, 0); - assertEquals(rules.convertToUtc(tai), expected); - assertEquals(rules.convertToTai(expected), tai); // check reverse + assertEquals(expected, rules.convertToUtc(tai)); + assertEquals(tai, rules.convertToTai(expected)); // check reverse } @Test public void test_convertToUtc_TaiInstant_1958() { TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC1958, 0); // 1958-01-01 UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_1958, 0); - assertEquals(rules.convertToUtc(tai), expected); - assertEquals(rules.convertToTai(expected), tai); // check reverse + assertEquals(expected, rules.convertToUtc(tai)); + assertEquals(tai, rules.convertToTai(expected)); // check reverse } @Test public void test_convertToUtc_TaiInstant_2100() { TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC2100, 0); // 2100-01-01 UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_2100, 0); - assertEquals(rules.convertToUtc(tai), expected); - assertEquals(rules.convertToTai(expected), tai); // check reverse + assertEquals(expected, rules.convertToUtc(tai)); + assertEquals(tai, rules.convertToTai(expected)); // check reverse } @Test(expected = NullPointerException.class) @@ -365,8 +365,8 @@ public void test_negativeLeap_justBeforeLeap() { rules.register(MJD_2100 - 1, -1); TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC2100_EXTRA_NEGATIVE_LEAP - 1, 0); // 2100-01-01 (1 second before 2100) UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_2100 - 1, (SECS_PER_DAY - 2) * NANOS_PER_SEC); - assertEquals(rules.convertToUtc(tai), expected); - assertEquals(rules.convertToTai(expected), tai); // check reverse + assertEquals(expected, rules.convertToUtc(tai)); + assertEquals(tai, rules.convertToTai(expected)); // check reverse } @Test @@ -374,8 +374,8 @@ public void test_negativeLeap_justAfterLeap() { rules.register(MJD_2100 - 1, -1); TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC2100_EXTRA_NEGATIVE_LEAP, 0); // 2100-01-01 UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_2100, 0); - assertEquals(rules.convertToUtc(tai), expected); - assertEquals(rules.convertToTai(expected), tai); // check reverse + assertEquals(expected, rules.convertToUtc(tai)); + assertEquals(tai, rules.convertToTai(expected)); // check reverse } //----------------------------------------------------------------------- @@ -386,8 +386,8 @@ public void test_convertToInstant_justBeforeLeap() { OffsetDateTime odt = OffsetDateTime.of(1979, 12, 31, 23, 43, 21, 0, ZoneOffset.UTC); Instant instant = odt.toInstant(); UtcInstant utc = UtcInstant.ofModifiedJulianDay(MJD_1980 - 1, (SECS_PER_DAY + 1 - 1000) * NANOS_PER_SEC); - assertEquals(rules.convertToInstant(utc), instant); - assertEquals(rules.convertToUtc(instant), utc); + assertEquals(instant, rules.convertToInstant(utc)); + assertEquals(utc, rules.convertToUtc(instant)); } @Test @@ -402,8 +402,8 @@ public void test_convertToInstant_sls() { Instant instant = odt.toInstant(); UtcInstant utc = UtcInstant.ofModifiedJulianDay( MJD_1980 - 1, (SECS_PER_DAY + 1 - 1000) * NANOS_PER_SEC + i * NANOS_PER_SEC); - assertEquals(rules.convertToInstant(utc), instant); - assertEquals(rules.convertToUtc(instant), utc); + assertEquals(instant, rules.convertToInstant(utc)); + assertEquals(utc, rules.convertToUtc(instant)); } } @@ -417,8 +417,8 @@ public void test_convertToInstant_slsMillis() { Instant instant = odt.toInstant(); UtcInstant utc = UtcInstant.ofModifiedJulianDay( MJD_1980 - 1, (SECS_PER_DAY + 1 - 1000) * NANOS_PER_SEC + i * 1000000); - assertEquals(rules.convertToInstant(utc), instant); - assertEquals(rules.convertToUtc(instant), utc); + assertEquals(instant, rules.convertToInstant(utc)); + assertEquals(utc, rules.convertToUtc(instant)); } } @@ -432,8 +432,8 @@ public void test_convertToInstant_slsMicros() { Instant instant = odt.toInstant(); UtcInstant utc = UtcInstant.ofModifiedJulianDay( MJD_1980 - 1, (SECS_PER_DAY + 1 - 1000) * NANOS_PER_SEC + i * 1000); - assertEquals(rules.convertToInstant(utc), instant); - assertEquals(rules.convertToUtc(instant), utc); + assertEquals(instant, rules.convertToInstant(utc)); + assertEquals(utc, rules.convertToUtc(instant)); } } @@ -446,10 +446,10 @@ public void test_convertToInstant_slsNanos() { OffsetDateTime odt = OffsetDateTime.of(1979, 12, 31, 23, 43, 21, (int) (slsNanos % NANOS_PER_SEC), ZoneOffset.UTC); Instant instant = odt.toInstant(); UtcInstant utc = UtcInstant.ofModifiedJulianDay(MJD_1980 - 1, utcNanos); - assertEquals(rules.convertToInstant(utc), instant); + assertEquals(instant, rules.convertToInstant(utc)); // not all instants can map back to the correct UTC value long reverseUtcNanos = startSls + ((slsNanos - startSls) * 1000L) / (1000L - 1); - assertEquals(rules.convertToUtc(instant), UtcInstant.ofModifiedJulianDay(MJD_1980 - 1, reverseUtcNanos)); + assertEquals(UtcInstant.ofModifiedJulianDay(MJD_1980 - 1, reverseUtcNanos), rules.convertToUtc(instant)); } } @@ -458,8 +458,8 @@ public void test_convertToInstant_justAfterLeap() { OffsetDateTime odt = OffsetDateTime.of(1980, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC); Instant instant = odt.toInstant(); UtcInstant utc = UtcInstant.ofModifiedJulianDay(MJD_1980, 0); - assertEquals(rules.convertToInstant(utc), instant); - assertEquals(rules.convertToUtc(instant), utc); + assertEquals(instant, rules.convertToInstant(utc)); + assertEquals(utc, rules.convertToUtc(instant)); } @Test @@ -467,8 +467,8 @@ public void test_convertToInstant_furtherAfterLeap() { OffsetDateTime odt = OffsetDateTime.of(1980, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC); Instant instant = odt.toInstant(); UtcInstant utc = UtcInstant.ofModifiedJulianDay(MJD_1980, NANOS_PER_SEC); - assertEquals(rules.convertToInstant(utc), instant); - assertEquals(rules.convertToUtc(instant), utc); + assertEquals(instant, rules.convertToInstant(utc)); + assertEquals(utc, rules.convertToUtc(instant)); } //----------------------------------------------------------------------- @@ -480,9 +480,9 @@ public void test_registerLeapSecond_justAfterLastDate_plusOne() { long mjd = dates[dates.length - 1] + 1; rules.register(mjd, 1); long[] test = rules.getLeapSecondDates(); - assertEquals(test.length, dates.length + 1); - assertEquals(test[test.length - 1], mjd); - assertEquals(rules.getLeapSecondAdjustment(mjd), 1); + assertEquals(dates.length + 1, test.length); + assertEquals(mjd, test[test.length - 1]); + assertEquals(1, rules.getLeapSecondAdjustment(mjd)); } @Test @@ -491,9 +491,9 @@ public void test_registerLeapSecond_justAfterLastDate_minusOne() { long mjd = dates[dates.length - 1] + 1; rules.register(mjd, -1); long[] test = rules.getLeapSecondDates(); - assertEquals(test.length, dates.length + 1); - assertEquals(test[test.length - 1], mjd); - assertEquals(rules.getLeapSecondAdjustment(mjd), -1); + assertEquals(dates.length + 1, test.length); + assertEquals(mjd, test[test.length - 1]); + assertEquals(-1, rules.getLeapSecondAdjustment(mjd)); } @Test @@ -503,8 +503,8 @@ public void test_registerLeapSecond_equalLastDate_sameLeap() { int adj = rules.getLeapSecondAdjustment(mjd); rules.register(mjd, adj); long[] test = rules.getLeapSecondDates(); - assertEquals(Arrays.equals(test, dates), true); - assertEquals(rules.getLeapSecondAdjustment(mjd), adj); + assertEquals(true, Arrays.equals(test, dates)); + assertEquals(adj, rules.getLeapSecondAdjustment(mjd)); } @Test @@ -514,8 +514,8 @@ public void test_registerLeapSecond_equalEarlierDate_sameLeap() { int adj = rules.getLeapSecondAdjustment(mjd); rules.register(mjd, adj); long[] test = rules.getLeapSecondDates(); - assertEquals(Arrays.equals(test, dates), true); - assertEquals(rules.getLeapSecondAdjustment(mjd), adj); + assertEquals(true, Arrays.equals(test, dates)); + assertEquals(adj, rules.getLeapSecondAdjustment(mjd)); } @Test(expected = IllegalArgumentException.class) @@ -561,7 +561,7 @@ public void test_registerLeapSecond_invalidAdjustment_three() { //----------------------------------------------------------------------- @Test public void test_toString() { - assertEquals(rules.toString(), "UtcRules[System]"); + assertEquals("UtcRules[System]", rules.toString()); } } From fc6a534f6c1ebb4388dd64da86d110908fdb4854 Mon Sep 17 00:00:00 2001 From: perceptron8 Date: Fri, 4 May 2018 21:23:30 +0200 Subject: [PATCH 062/279] Fix formatting --- .../threeten/extra/TestLocalDateRange.java | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/test/java/org/threeten/extra/TestLocalDateRange.java b/src/test/java/org/threeten/extra/TestLocalDateRange.java index fe41be36..2362ef70 100644 --- a/src/test/java/org/threeten/extra/TestLocalDateRange.java +++ b/src/test/java/org/threeten/extra/TestLocalDateRange.java @@ -549,15 +549,15 @@ public void test_encloses_baseEmpty() { @Test public void test_encloses_baseEmptyMax() { assertEquals(true, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .encloses(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX))); + .encloses(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX))); assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX))); + .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX))); assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); + .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); assertEquals(false, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); + .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); assertEquals(false, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2)))); + .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2)))); } @Test @@ -573,15 +573,15 @@ public void test_abuts_baseEmpty() { @Test public void test_abuts_baseEmptyMax() { assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .abuts(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX))); + .abuts(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX))); assertEquals(true, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX))); + .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX))); assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); + .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); assertEquals(true, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); + .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); assertEquals(false, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2)))); + .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2)))); } @Test @@ -595,15 +595,15 @@ public void test_isConnected_baseEmpty() { @Test public void test_isConnected_baseEmptyMax() { assertEquals(true, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .isConnected(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX))); + .isConnected(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX))); assertEquals(true, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX))); + .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX))); assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); + .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); assertEquals(true, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); + .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); assertEquals(false, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2)))); + .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2)))); } @Test @@ -617,15 +617,15 @@ public void test_overlaps_baseEmpty() { @Test public void test_overlaps_baseEmptyMax() { assertEquals(true, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .overlaps(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX))); + .overlaps(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX))); assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .overlaps(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX))); + .overlaps(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX))); assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .overlaps(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); + .overlaps(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); assertEquals(false, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .overlaps(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); + .overlaps(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); assertEquals(false, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .overlaps(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2)))); + .overlaps(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2)))); } //----------------------------------------------------------------------- From 90c9b4bdf74ab4003372b2c1ec59b82433985c93 Mon Sep 17 00:00:00 2001 From: perceptron8 Date: Fri, 4 May 2018 21:34:39 +0200 Subject: [PATCH 063/279] Fix some singletons tests --- .../java/org/threeten/extra/TestAmPm.java | 5 ++-- .../org/threeten/extra/TestDayOfMonth.java | 3 ++- .../java/org/threeten/extra/TestDays.java | 6 ++--- .../java/org/threeten/extra/TestHours.java | 4 +-- .../java/org/threeten/extra/TestMinutes.java | 4 +-- .../java/org/threeten/extra/TestMonths.java | 6 ++--- .../java/org/threeten/extra/TestQuarter.java | 25 ++++++++++--------- .../java/org/threeten/extra/TestSeconds.java | 4 +-- .../org/threeten/extra/TestTemporals.java | 4 +-- .../java/org/threeten/extra/TestWeeks.java | 6 ++--- .../java/org/threeten/extra/TestYears.java | 6 ++--- .../threeten/extra/scale/TestUtcRules.java | 2 +- 12 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/test/java/org/threeten/extra/TestAmPm.java b/src/test/java/org/threeten/extra/TestAmPm.java index 302a0547..5357a55a 100644 --- a/src/test/java/org/threeten/extra/TestAmPm.java +++ b/src/test/java/org/threeten/extra/TestAmPm.java @@ -63,6 +63,7 @@ import static java.time.temporal.ChronoField.YEAR_OF_ERA; import static java.time.temporal.ChronoUnit.HALF_DAYS; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import java.io.Serializable; @@ -118,10 +119,10 @@ public void test_of_int_valueTooHigh() { @Test public void test_ofHour_int_singleton() { for (int i = 0; i < 12; i++) { - assertEquals(AmPm.AM, AmPm.ofHour(i)); + assertSame(AmPm.AM, AmPm.ofHour(i)); } for (int i = 12; i < 24; i++) { - assertEquals(AmPm.PM, AmPm.ofHour(i)); + assertSame(AmPm.PM, AmPm.ofHour(i)); } } diff --git a/src/test/java/org/threeten/extra/TestDayOfMonth.java b/src/test/java/org/threeten/extra/TestDayOfMonth.java index dffb0bb2..cc6fd8db 100644 --- a/src/test/java/org/threeten/extra/TestDayOfMonth.java +++ b/src/test/java/org/threeten/extra/TestDayOfMonth.java @@ -74,6 +74,7 @@ import static java.time.temporal.ChronoField.YEAR; import static java.time.temporal.ChronoField.YEAR_OF_ERA; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; @@ -140,7 +141,7 @@ public void test_of_int_singleton() { for (int i = 1; i <= MAX_LENGTH; i++) { DayOfMonth test = DayOfMonth.of(i); assertEquals(i, test.getValue()); - assertEquals(test, DayOfMonth.of(i)); + assertSame(test, DayOfMonth.of(i)); } } diff --git a/src/test/java/org/threeten/extra/TestDays.java b/src/test/java/org/threeten/extra/TestDays.java index 53ee459c..4e78461f 100644 --- a/src/test/java/org/threeten/extra/TestDays.java +++ b/src/test/java/org/threeten/extra/TestDays.java @@ -74,7 +74,7 @@ public void test_deserializationSingleton() throws Exception { oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertSame(ois.readObject(), test); + assertSame(test, ois.readObject()); } } @@ -82,14 +82,14 @@ public void test_deserializationSingleton() throws Exception { @Test public void test_ZERO() { assertSame(Days.of(0), Days.ZERO); - assertSame(Days.of(0), Days.ZERO); + assertEquals(Days.of(0), Days.ZERO); assertEquals(0, Days.ZERO.getAmount()); } @Test public void test_ONE() { assertSame(Days.of(1), Days.ONE); - assertSame(Days.of(1), Days.ONE); + assertEquals(Days.of(1), Days.ONE); assertEquals(1, Days.ONE.getAmount()); } diff --git a/src/test/java/org/threeten/extra/TestHours.java b/src/test/java/org/threeten/extra/TestHours.java index 36fc1001..8b8616bf 100644 --- a/src/test/java/org/threeten/extra/TestHours.java +++ b/src/test/java/org/threeten/extra/TestHours.java @@ -72,7 +72,7 @@ public void test_deserializationSingleton() throws Exception { oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertSame(ois.readObject(), test); + assertSame(test, ois.readObject()); } } @@ -80,7 +80,7 @@ public void test_deserializationSingleton() throws Exception { @Test public void test_ZERO() { assertSame(Hours.of(0), Hours.ZERO); - assertSame(Hours.of(0), Hours.ZERO); + assertEquals(Hours.of(0), Hours.ZERO); assertEquals(0, Hours.ZERO.getAmount()); } diff --git a/src/test/java/org/threeten/extra/TestMinutes.java b/src/test/java/org/threeten/extra/TestMinutes.java index 9edc75a4..449dfe2f 100644 --- a/src/test/java/org/threeten/extra/TestMinutes.java +++ b/src/test/java/org/threeten/extra/TestMinutes.java @@ -72,7 +72,7 @@ public void test_deserializationSingleton() throws Exception { oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertSame(ois.readObject(), test); + assertSame(test, ois.readObject()); } } @@ -80,7 +80,7 @@ public void test_deserializationSingleton() throws Exception { @Test public void test_ZERO() { assertSame(Minutes.of(0), Minutes.ZERO); - assertSame(Minutes.of(0), Minutes.ZERO); + assertEquals(Minutes.of(0), Minutes.ZERO); assertEquals(0, Minutes.ZERO.getAmount()); } diff --git a/src/test/java/org/threeten/extra/TestMonths.java b/src/test/java/org/threeten/extra/TestMonths.java index 2b4018ea..9bfbe170 100644 --- a/src/test/java/org/threeten/extra/TestMonths.java +++ b/src/test/java/org/threeten/extra/TestMonths.java @@ -74,7 +74,7 @@ public void test_deserializationSingleton() throws Exception { oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertSame(ois.readObject(), test); + assertSame(test, ois.readObject()); } } @@ -82,14 +82,14 @@ public void test_deserializationSingleton() throws Exception { @Test public void test_ZERO() { assertSame(Months.of(0), Months.ZERO); - assertSame(Months.of(0), Months.ZERO); + assertEquals(Months.of(0), Months.ZERO); assertEquals(0, Months.ZERO.getAmount()); } @Test public void test_ONE() { assertSame(Months.of(1), Months.ONE); - assertSame(Months.of(1), Months.ONE); + assertEquals(Months.of(1), Months.ONE); assertEquals(1, Months.ONE.getAmount()); } diff --git a/src/test/java/org/threeten/extra/TestQuarter.java b/src/test/java/org/threeten/extra/TestQuarter.java index f0499d51..1b8f6cd0 100644 --- a/src/test/java/org/threeten/extra/TestQuarter.java +++ b/src/test/java/org/threeten/extra/TestQuarter.java @@ -64,6 +64,7 @@ import static java.time.temporal.IsoFields.QUARTER_OF_YEAR; import static java.time.temporal.IsoFields.QUARTER_YEARS; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.threeten.extra.Quarter.Q3; @@ -129,18 +130,18 @@ public void test_of_int_valueTooHigh() { //----------------------------------------------------------------------- @Test public void test_ofMonth_int_singleton() { - assertEquals(Quarter.Q1, Quarter.ofMonth(1)); - assertEquals(Quarter.Q1, Quarter.ofMonth(2)); - assertEquals(Quarter.Q1, Quarter.ofMonth(3)); - assertEquals(Quarter.Q2, Quarter.ofMonth(4)); - assertEquals(Quarter.Q2, Quarter.ofMonth(5)); - assertEquals(Quarter.Q2, Quarter.ofMonth(6)); - assertEquals(Quarter.Q3, Quarter.ofMonth(7)); - assertEquals(Quarter.Q3, Quarter.ofMonth(8)); - assertEquals(Quarter.Q3, Quarter.ofMonth(9)); - assertEquals(Quarter.Q4, Quarter.ofMonth(10)); - assertEquals(Quarter.Q4, Quarter.ofMonth(11)); - assertEquals(Quarter.Q4, Quarter.ofMonth(12)); + assertSame(Quarter.Q1, Quarter.ofMonth(1)); + assertSame(Quarter.Q1, Quarter.ofMonth(2)); + assertSame(Quarter.Q1, Quarter.ofMonth(3)); + assertSame(Quarter.Q2, Quarter.ofMonth(4)); + assertSame(Quarter.Q2, Quarter.ofMonth(5)); + assertSame(Quarter.Q2, Quarter.ofMonth(6)); + assertSame(Quarter.Q3, Quarter.ofMonth(7)); + assertSame(Quarter.Q3, Quarter.ofMonth(8)); + assertSame(Quarter.Q3, Quarter.ofMonth(9)); + assertSame(Quarter.Q4, Quarter.ofMonth(10)); + assertSame(Quarter.Q4, Quarter.ofMonth(11)); + assertSame(Quarter.Q4, Quarter.ofMonth(12)); } @Test(expected = DateTimeException.class) diff --git a/src/test/java/org/threeten/extra/TestSeconds.java b/src/test/java/org/threeten/extra/TestSeconds.java index eba3b84c..34709110 100644 --- a/src/test/java/org/threeten/extra/TestSeconds.java +++ b/src/test/java/org/threeten/extra/TestSeconds.java @@ -72,7 +72,7 @@ public void test_deserializationSingleton() throws Exception { oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertSame(ois.readObject(), test); + assertSame(test, ois.readObject()); } } @@ -80,7 +80,7 @@ public void test_deserializationSingleton() throws Exception { @Test public void test_ZERO() { assertSame(Seconds.of(0), Seconds.ZERO); - assertSame(Seconds.of(0), Seconds.ZERO); + assertEquals(Seconds.of(0), Seconds.ZERO); assertEquals(0, Seconds.ZERO.getAmount()); } diff --git a/src/test/java/org/threeten/extra/TestTemporals.java b/src/test/java/org/threeten/extra/TestTemporals.java index 4239ee41..955b2461 100644 --- a/src/test/java/org/threeten/extra/TestTemporals.java +++ b/src/test/java/org/threeten/extra/TestTemporals.java @@ -100,7 +100,7 @@ public void test_nextWorkingDay_serialization() throws IOException, ClassNotFoun oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertSame(ois.readObject(), test); + assertSame(test, ois.readObject()); } } @@ -167,7 +167,7 @@ public void test_previousWorkingDay_serialization() throws IOException, ClassNot oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertSame(ois.readObject(), test); + assertSame(test, ois.readObject()); } } diff --git a/src/test/java/org/threeten/extra/TestWeeks.java b/src/test/java/org/threeten/extra/TestWeeks.java index 52c106c7..1cf8b15b 100644 --- a/src/test/java/org/threeten/extra/TestWeeks.java +++ b/src/test/java/org/threeten/extra/TestWeeks.java @@ -74,7 +74,7 @@ public void test_deserializationSingleton() throws Exception { oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertSame(ois.readObject(), test); + assertSame(test, ois.readObject()); } } @@ -82,14 +82,14 @@ public void test_deserializationSingleton() throws Exception { @Test public void test_ZERO() { assertSame(Weeks.of(0), Weeks.ZERO); - assertSame(Weeks.of(0), Weeks.ZERO); + assertEquals(Weeks.of(0), Weeks.ZERO); assertEquals(0, Weeks.ZERO.getAmount()); } @Test public void test_ONE() { assertSame(Weeks.of(1), Weeks.ONE); - assertSame(Weeks.of(1), Weeks.ONE); + assertEquals(Weeks.of(1), Weeks.ONE); assertEquals(1, Weeks.ONE.getAmount()); } diff --git a/src/test/java/org/threeten/extra/TestYears.java b/src/test/java/org/threeten/extra/TestYears.java index 50c68d68..facf129d 100644 --- a/src/test/java/org/threeten/extra/TestYears.java +++ b/src/test/java/org/threeten/extra/TestYears.java @@ -74,7 +74,7 @@ public void test_deserializationSingleton() throws Exception { oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertSame(ois.readObject(), test); + assertSame(test, ois.readObject()); } } @@ -82,14 +82,14 @@ public void test_deserializationSingleton() throws Exception { @Test public void test_ZERO() { assertSame(Years.of(0), Years.ZERO); - assertSame(Years.of(0), Years.ZERO); + assertEquals(Years.of(0), Years.ZERO); assertEquals(0, Years.ZERO.getAmount()); } @Test public void test_ONE() { assertSame(Years.of(1), Years.ONE); - assertSame(Years.of(1), Years.ONE); + assertEquals(Years.of(1), Years.ONE); assertEquals(1, Years.ONE.getAmount()); } diff --git a/src/test/java/org/threeten/extra/scale/TestUtcRules.java b/src/test/java/org/threeten/extra/scale/TestUtcRules.java index 8aac6537..51b23913 100644 --- a/src/test/java/org/threeten/extra/scale/TestUtcRules.java +++ b/src/test/java/org/threeten/extra/scale/TestUtcRules.java @@ -89,7 +89,7 @@ public void test_serialization() throws Exception { oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertSame(ois.readObject(), test); + assertSame(test, ois.readObject()); } } From 661e602fbdcb2deda667efbe1428ef427e6040b4 Mon Sep 17 00:00:00 2001 From: jjcard Date: Mon, 14 May 2018 20:06:34 -0700 Subject: [PATCH 064/279] add TemporalAdjsuters for previousWorkingDayOrSame and nextWorkingDayOrSame --- .../java/org/threeten/extra/Temporals.java | 56 +++++++- .../org/threeten/extra/TestTemporals.java | 129 ++++++++++++++++++ 2 files changed, 183 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/threeten/extra/Temporals.java b/src/main/java/org/threeten/extra/Temporals.java index 797ea8c2..02c2e626 100644 --- a/src/main/java/org/threeten/extra/Temporals.java +++ b/src/main/java/org/threeten/extra/Temporals.java @@ -86,7 +86,18 @@ private Temporals() { public static TemporalAdjuster nextWorkingDay() { return Adjuster.NEXT_WORKING; } - + /** + * Returns an adjuster that returns the next working day or same day if already working day, ignoring Saturday and Sunday. + *

    + * Some territories have weekends that do not consist of Saturday and Sunday. + * No implementation is supplied to support this, however an adjuster + * can be easily written to do so. + * + * @return the next working day or same adjuster, not null + */ + public static TemporalAdjuster nextWorkingDayOrSame() { + return Adjuster.NEXT_WORKING_OR_SAME; + } /** * Returns an adjuster that returns the previous working day, ignoring Saturday and Sunday. *

    @@ -99,7 +110,18 @@ public static TemporalAdjuster nextWorkingDay() { public static TemporalAdjuster previousWorkingDay() { return Adjuster.PREVIOUS_WORKING; } - + /** + * Returns an adjuster that returns the previous working day or same day if already working day, ignoring Saturday and Sunday. + *

    + * Some territories have weekends that do not consist of Saturday and Sunday. + * No implementation is supplied to support this, however an adjuster + * can be easily written to do so. + * + * @return the previous working day or same adjuster, not null + */ + public static TemporalAdjuster previousWorkingDayOrSame() { + return Adjuster.PREVIOUS_WORKING_OR_SAME; + } //----------------------------------------------------------------------- /** * Enum implementing the adjusters. @@ -135,6 +157,36 @@ public Temporal adjustInto(Temporal temporal) { } } }, + /** Next working day or same adjuster. */ + NEXT_WORKING_OR_SAME { + @Override + public Temporal adjustInto(Temporal temporal) { + int dow = temporal.get(DAY_OF_WEEK); + switch (dow) { + case 6: //Saturday + return temporal.plus(2, DAYS); + case 7: //Sunday + return temporal.plus(1, DAYS); + default: + return temporal; + } + } + }, + /** Previous working day or same adjuster. */ + PREVIOUS_WORKING_OR_SAME { + @Override + public Temporal adjustInto(Temporal temporal) { + int dow = temporal.get(DAY_OF_WEEK); + switch (dow) { + case 6: //Saturday + return temporal.minus(1, DAYS); + case 7: // Sunday + return temporal.minus(2, DAYS); + default: + return temporal; + } + } + } } //------------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestTemporals.java b/src/test/java/org/threeten/extra/TestTemporals.java index 7662e528..06ab9ff6 100644 --- a/src/test/java/org/threeten/extra/TestTemporals.java +++ b/src/test/java/org/threeten/extra/TestTemporals.java @@ -154,7 +154,71 @@ public void test_nextWorkingDay_yearChange() { test = Temporals.nextWorkingDay().adjustInto(saturday); assertEquals(test, LocalDate.of(2012, JANUARY, 2)); } + //----------------------------------------------------------------------- + // nextWorkingDayOrSame() + //----------------------------------------------------------------------- + @Test + public void test_nextWorkingDayOrSame_serialization() throws IOException, ClassNotFoundException { + TemporalAdjuster test = Temporals.nextWorkingDayOrSame(); + assertTrue(test instanceof Serializable); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertSame(ois.readObject(), test); + } + } + @Test + public void test_nextWorkingDayOrSame() { + for (Month month : Month.values()) { + for (int i = 1; i <= month.length(false); i++) { + LocalDate date = LocalDate.of(2007, month, i); + LocalDate test = (LocalDate) Temporals.nextWorkingDayOrSame().adjustInto(date); + assertFalse(test.getDayOfWeek().equals(SATURDAY)); + assertFalse(test.getDayOfWeek().equals(SUNDAY)); + + switch (date.getDayOfWeek()) { + case SATURDAY: + case SUNDAY: + assertEquals(test.getDayOfWeek(), MONDAY); + break; + default: + assertEquals(date.getDayOfWeek(), test.getDayOfWeek()); + } + + if (test.getYear() == 2007) { + int dayDiff = test.getDayOfYear() - date.getDayOfYear(); + switch (date.getDayOfWeek()) { + case SATURDAY: + assertEquals(dayDiff, 2); + break; + case SUNDAY: + assertEquals(dayDiff, 1); + break; + default: + assertEquals(dayDiff, 0); + } + } else { + assertEquals(test.getYear(), 2008); + assertEquals(test.getMonth(), JANUARY); + assertEquals(test.getDayOfMonth(), 1); + } + } + } + } + + @Test + public void test_nextWorkingDayOrSame_yearChange() { + LocalDate saturday = LocalDate.of(2016, DECEMBER, 31); + Temporal test = Temporals.nextWorkingDayOrSame().adjustInto(saturday); + assertEquals(LocalDate.of(2017, JANUARY, 2), test ); + + LocalDate sunday = LocalDate.of(2017, DECEMBER, 31); + test = Temporals.nextWorkingDayOrSame().adjustInto(sunday); + assertEquals(LocalDate.of(2018, JANUARY, 1), test); + } //----------------------------------------------------------------------- // previousWorkingDay() //----------------------------------------------------------------------- @@ -221,7 +285,72 @@ public void test_previousWorkingDay_yearChange() { test = Temporals.previousWorkingDay().adjustInto(sunday); assertEquals(test, LocalDate.of(2010, DECEMBER, 31)); } + //----------------------------------------------------------------------- + // previousWorkingDayOrSame() + //----------------------------------------------------------------------- + @Test + public void test_previousWorkingDayOrSame_serialization() throws IOException, ClassNotFoundException { + TemporalAdjuster test = Temporals.previousWorkingDayOrSame(); + assertTrue(test instanceof Serializable); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertSame(ois.readObject(), test); + } + } + + @Test + public void test_previousWorkingDayOrSame() { + for (Month month : Month.values()) { + for (int i = 1; i <= month.length(false); i++) { + LocalDate date = LocalDate.of(2007, month, i); + LocalDate test = (LocalDate) Temporals.previousWorkingDayOrSame().adjustInto(date); + assertFalse(test.getDayOfWeek().equals(SATURDAY)); + assertFalse(test.getDayOfWeek().equals(SUNDAY)); + + switch (date.getDayOfWeek()) { + case SATURDAY: + case SUNDAY: + assertEquals(test.getDayOfWeek(), FRIDAY); + break; + default: + assertEquals(date.getDayOfWeek(), test.getDayOfWeek()); + } + + if (test.getYear() == 2007) { + int dayDiff = test.getDayOfYear() - date.getDayOfYear(); + switch (date.getDayOfWeek()) { + case SATURDAY: + assertEquals(dayDiff, -1); + break; + case SUNDAY: + assertEquals(dayDiff, -2); + break; + default: + assertEquals(dayDiff, 0); + } + } else { + assertEquals(test.getYear(), 2006); + assertEquals(test.getMonth(), DECEMBER); + assertEquals(test.getDayOfMonth(), 29); + } + } + } + } + @Test + public void test_previousWorkingDayOrSame_yearChange() { + + LocalDate sunday = LocalDate.of(2011, JANUARY, 2); + Temporal test = Temporals.previousWorkingDayOrSame().adjustInto(sunday); + assertEquals(test, LocalDate.of(2010, DECEMBER, 31)); + + LocalDate saturday = LocalDate.of(2011, JANUARY, 1); + test = Temporals.previousWorkingDayOrSame().adjustInto(saturday); + assertEquals(test, LocalDate.of(2010, DECEMBER, 31)); + } //----------------------------------------------------------------------- // parseFirstMatching() //----------------------------------------------------------------------- From 655292fb31a7d38d17ca48ef6c740fdfe1afe155 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Wed, 16 May 2018 23:33:08 +0100 Subject: [PATCH 065/279] Update after merge --- pom.xml | 4 ++++ src/changes/changes.xml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/pom.xml b/pom.xml index 64d25494..2c7fcf59 100644 --- a/pom.xml +++ b/pom.xml @@ -66,6 +66,10 @@ Bjorn Raupach https://github.com/raupachz + + Michal Sobkiewicz + https://github.com/perceptron8 + Nils Sommer https://github.com/nsommer diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 2dc6a353..7d0f8456 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -19,6 +19,10 @@ Now that the build is on Java 9, the OSGi data had to be updated. See #92, #94. + + Fix test parameter order. + See #98, #99. + From ad315416100173b72b82edd5eb74c5edd58969c4 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Wed, 16 May 2018 23:33:29 +0100 Subject: [PATCH 066/279] Javadoc clarification Suggested in #100 --- src/main/java/org/threeten/extra/LocalDateRange.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/threeten/extra/LocalDateRange.java b/src/main/java/org/threeten/extra/LocalDateRange.java index 30673f56..045f3304 100644 --- a/src/main/java/org/threeten/extra/LocalDateRange.java +++ b/src/main/java/org/threeten/extra/LocalDateRange.java @@ -259,7 +259,7 @@ public LocalDate getEndInclusive() { /** * Checks if the range is empty. *

    - * An empty range occurs when the start date equals the inclusive end date. + * An empty range occurs when the start date equals the end date. * * @return true if the range is empty */ @@ -331,9 +331,9 @@ public LocalDateRange withEnd(TemporalAdjuster adjuster) { * Checks if this range contains the specified date. *

    * This checks if the specified date is within the bounds of this range. - * If this range has an unbounded start then {@code contains(LocalDate#MIN)} returns true. - * If this range has an unbounded end then {@code contains(LocalDate#MAX)} returns true. * If this range is empty then this method always returns false. + * Else if this range has an unbounded start then {@code contains(LocalDate#MIN)} returns true. + * Else if this range has an unbounded end then {@code contains(LocalDate#MAX)} returns true. * * @param date the date to check for, not null * @return true if this range contains the date From 85aa6b71253c8071f6103c3d1057f562d9295c26 Mon Sep 17 00:00:00 2001 From: jjcard Date: Wed, 16 May 2018 19:54:52 -0700 Subject: [PATCH 067/279] fix formatting as per code review --- .../java/org/threeten/extra/Temporals.java | 40 ++++++++++--------- .../org/threeten/extra/TestTemporals.java | 10 +++-- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/threeten/extra/Temporals.java b/src/main/java/org/threeten/extra/Temporals.java index 02c2e626..10ce8bc5 100644 --- a/src/main/java/org/threeten/extra/Temporals.java +++ b/src/main/java/org/threeten/extra/Temporals.java @@ -86,6 +86,7 @@ private Temporals() { public static TemporalAdjuster nextWorkingDay() { return Adjuster.NEXT_WORKING; } + /** * Returns an adjuster that returns the next working day or same day if already working day, ignoring Saturday and Sunday. *

    @@ -96,8 +97,9 @@ public static TemporalAdjuster nextWorkingDay() { * @return the next working day or same adjuster, not null */ public static TemporalAdjuster nextWorkingDayOrSame() { - return Adjuster.NEXT_WORKING_OR_SAME; + return Adjuster.NEXT_WORKING_OR_SAME; } + /** * Returns an adjuster that returns the previous working day, ignoring Saturday and Sunday. *

    @@ -110,6 +112,7 @@ public static TemporalAdjuster nextWorkingDayOrSame() { public static TemporalAdjuster previousWorkingDay() { return Adjuster.PREVIOUS_WORKING; } + /** * Returns an adjuster that returns the previous working day or same day if already working day, ignoring Saturday and Sunday. *

    @@ -120,8 +123,9 @@ public static TemporalAdjuster previousWorkingDay() { * @return the previous working day or same adjuster, not null */ public static TemporalAdjuster previousWorkingDayOrSame() { - return Adjuster.PREVIOUS_WORKING_OR_SAME; + return Adjuster.PREVIOUS_WORKING_OR_SAME; } + //----------------------------------------------------------------------- /** * Enum implementing the adjusters. @@ -159,33 +163,33 @@ public Temporal adjustInto(Temporal temporal) { }, /** Next working day or same adjuster. */ NEXT_WORKING_OR_SAME { - @Override - public Temporal adjustInto(Temporal temporal) { - int dow = temporal.get(DAY_OF_WEEK); - switch (dow) { - case 6: //Saturday - return temporal.plus(2, DAYS); - case 7: //Sunday - return temporal.plus(1, DAYS); - default: - return temporal; - } - } + @Override + public Temporal adjustInto(Temporal temporal) { + int dow = temporal.get(DAY_OF_WEEK); + switch (dow) { + case 6: // Saturday + return temporal.plus(2, DAYS); + case 7: // Sunday + return temporal.plus(1, DAYS); + default: + return temporal; + } + } }, /** Previous working day or same adjuster. */ PREVIOUS_WORKING_OR_SAME { - @Override - public Temporal adjustInto(Temporal temporal) { + @Override + public Temporal adjustInto(Temporal temporal) { int dow = temporal.get(DAY_OF_WEEK); switch (dow) { case 6: //Saturday - return temporal.minus(1, DAYS); + return temporal.minus(1, DAYS); case 7: // Sunday return temporal.minus(2, DAYS); default: return temporal; } - } + } } } diff --git a/src/test/java/org/threeten/extra/TestTemporals.java b/src/test/java/org/threeten/extra/TestTemporals.java index 06ab9ff6..8455bc40 100644 --- a/src/test/java/org/threeten/extra/TestTemporals.java +++ b/src/test/java/org/threeten/extra/TestTemporals.java @@ -154,6 +154,7 @@ public void test_nextWorkingDay_yearChange() { test = Temporals.nextWorkingDay().adjustInto(saturday); assertEquals(test, LocalDate.of(2012, JANUARY, 2)); } + //----------------------------------------------------------------------- // nextWorkingDayOrSame() //----------------------------------------------------------------------- @@ -219,6 +220,7 @@ public void test_nextWorkingDayOrSame_yearChange() { test = Temporals.nextWorkingDayOrSame().adjustInto(sunday); assertEquals(LocalDate.of(2018, JANUARY, 1), test); } + //----------------------------------------------------------------------- // previousWorkingDay() //----------------------------------------------------------------------- @@ -311,7 +313,7 @@ public void test_previousWorkingDayOrSame() { assertFalse(test.getDayOfWeek().equals(SUNDAY)); switch (date.getDayOfWeek()) { - case SATURDAY: + case SATURDAY: case SUNDAY: assertEquals(test.getDayOfWeek(), FRIDAY); break; @@ -322,9 +324,9 @@ public void test_previousWorkingDayOrSame() { if (test.getYear() == 2007) { int dayDiff = test.getDayOfYear() - date.getDayOfYear(); switch (date.getDayOfWeek()) { - case SATURDAY: - assertEquals(dayDiff, -1); - break; + case SATURDAY: + assertEquals(dayDiff, -1); + break; case SUNDAY: assertEquals(dayDiff, -2); break; From 2739eb69b022e5ec6b9322479494315eda6a0971 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Fri, 18 May 2018 19:02:29 +0100 Subject: [PATCH 068/279] Update after PR --- pom.xml | 4 ++++ src/changes/changes.xml | 4 ++++ .../java/org/threeten/extra/Temporals.java | 20 +++++++++---------- .../org/threeten/extra/TestTemporals.java | 12 ++++++----- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index 2c7fcf59..f03def1e 100644 --- a/pom.xml +++ b/pom.xml @@ -46,6 +46,10 @@ Christian Heinemann https://github.com/cheinema + + John Hill + https://github.com/jjcard + Michael Hixson https://github.com/michaelhixson diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 7d0f8456..dec4a70f 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -19,6 +19,10 @@ Now that the build is on Java 9, the OSGi data had to be updated. See #92, #94. + + Add Temporals.nextWorkingDayOrSame() and Temporals.previousWorkingDayOrSame(). + Fixes #101. + Fix test parameter order. See #98, #99. diff --git a/src/main/java/org/threeten/extra/Temporals.java b/src/main/java/org/threeten/extra/Temporals.java index 10ce8bc5..0b3f21c2 100644 --- a/src/main/java/org/threeten/extra/Temporals.java +++ b/src/main/java/org/threeten/extra/Temporals.java @@ -86,7 +86,7 @@ private Temporals() { public static TemporalAdjuster nextWorkingDay() { return Adjuster.NEXT_WORKING; } - + /** * Returns an adjuster that returns the next working day or same day if already working day, ignoring Saturday and Sunday. *

    @@ -99,7 +99,7 @@ public static TemporalAdjuster nextWorkingDay() { public static TemporalAdjuster nextWorkingDayOrSame() { return Adjuster.NEXT_WORKING_OR_SAME; } - + /** * Returns an adjuster that returns the previous working day, ignoring Saturday and Sunday. *

    @@ -112,7 +112,7 @@ public static TemporalAdjuster nextWorkingDayOrSame() { public static TemporalAdjuster previousWorkingDay() { return Adjuster.PREVIOUS_WORKING; } - + /** * Returns an adjuster that returns the previous working day or same day if already working day, ignoring Saturday and Sunday. *

    @@ -125,7 +125,7 @@ public static TemporalAdjuster previousWorkingDay() { public static TemporalAdjuster previousWorkingDayOrSame() { return Adjuster.PREVIOUS_WORKING_OR_SAME; } - + //----------------------------------------------------------------------- /** * Enum implementing the adjusters. @@ -167,12 +167,12 @@ public Temporal adjustInto(Temporal temporal) { public Temporal adjustInto(Temporal temporal) { int dow = temporal.get(DAY_OF_WEEK); switch (dow) { - case 6: // Saturday - return temporal.plus(2, DAYS); - case 7: // Sunday - return temporal.plus(1, DAYS); - default: - return temporal; + case 6: // Saturday + return temporal.plus(2, DAYS); + case 7: // Sunday + return temporal.plus(1, DAYS); + default: + return temporal; } } }, diff --git a/src/test/java/org/threeten/extra/TestTemporals.java b/src/test/java/org/threeten/extra/TestTemporals.java index 963325b0..7e697586 100644 --- a/src/test/java/org/threeten/extra/TestTemporals.java +++ b/src/test/java/org/threeten/extra/TestTemporals.java @@ -214,13 +214,13 @@ public void test_nextWorkingDayOrSame() { public void test_nextWorkingDayOrSame_yearChange() { LocalDate saturday = LocalDate.of(2016, DECEMBER, 31); Temporal test = Temporals.nextWorkingDayOrSame().adjustInto(saturday); - assertEquals(LocalDate.of(2017, JANUARY, 2), test ); - + assertEquals(LocalDate.of(2017, JANUARY, 2), test); + LocalDate sunday = LocalDate.of(2017, DECEMBER, 31); test = Temporals.nextWorkingDayOrSame().adjustInto(sunday); assertEquals(LocalDate.of(2018, JANUARY, 1), test); } - + //----------------------------------------------------------------------- // previousWorkingDay() //----------------------------------------------------------------------- @@ -287,7 +287,8 @@ public void test_previousWorkingDay_yearChange() { test = Temporals.previousWorkingDay().adjustInto(sunday); assertEquals(LocalDate.of(2010, DECEMBER, 31), test); } - //----------------------------------------------------------------------- + + //----------------------------------------------------------------------- // previousWorkingDayOrSame() //----------------------------------------------------------------------- @Test @@ -348,11 +349,12 @@ public void test_previousWorkingDayOrSame_yearChange() { LocalDate sunday = LocalDate.of(2011, JANUARY, 2); Temporal test = Temporals.previousWorkingDayOrSame().adjustInto(sunday); assertEquals(test, LocalDate.of(2010, DECEMBER, 31)); - + LocalDate saturday = LocalDate.of(2011, JANUARY, 1); test = Temporals.previousWorkingDayOrSame().adjustInto(saturday); assertEquals(test, LocalDate.of(2010, DECEMBER, 31)); } + //----------------------------------------------------------------------- // parseFirstMatching() //----------------------------------------------------------------------- From 3fbb9115352863362ede0b89c1c40d9545ace748 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Fri, 29 Jun 2018 14:59:24 +0100 Subject: [PATCH 069/279] Update checkstyle Plugin v2.17 is needed for Eclipse integration --- pom.xml | 10 +++++++++- src/main/checkstyle/checkstyle.xml | 13 ++++++------- src/main/java/org/threeten/extra/MutableClock.java | 4 ++-- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index f03def1e..2a97c79c 100644 --- a/pom.xml +++ b/pom.xml @@ -379,6 +379,13 @@ module-info.java + + + com.puppycrawl.tools + checkstyle + ${checkstyle.version} + + @@ -823,7 +830,7 @@ 3.1.0 2.12.1 - 3.0.0 + 2.17 3.0.0 3.7.0 2.8.2 @@ -859,6 +866,7 @@ true none + 8.10.1 src/main/checkstyle/checkstyle.xml false diff --git a/src/main/checkstyle/checkstyle.xml b/src/main/checkstyle/checkstyle.xml index 27af249f..27b4c24a 100644 --- a/src/main/checkstyle/checkstyle.xml +++ b/src/main/checkstyle/checkstyle.xml @@ -5,7 +5,6 @@ - @@ -118,13 +117,18 @@ + + + + + - + @@ -134,9 +138,4 @@ - - - - - diff --git a/src/main/java/org/threeten/extra/MutableClock.java b/src/main/java/org/threeten/extra/MutableClock.java index d09ecc9b..bd0b5362 100644 --- a/src/main/java/org/threeten/extra/MutableClock.java +++ b/src/main/java/org/threeten/extra/MutableClock.java @@ -115,12 +115,12 @@ public final class MutableClock /** * The mutable instant of this clock. */ - private transient final InstantHolder instantHolder; + private final transient InstantHolder instantHolder; /** * The fixed time-zone of this clock. */ - private transient final ZoneId zone; + private final transient ZoneId zone; /** * Obtains a new {@code MutableClock} set to the epoch of From d2c125dee3fbdb22681b6c7938e24c4986dc89c7 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 19 Aug 2018 12:18:45 +0100 Subject: [PATCH 070/279] Update build Update website to later Maven version Release website via a script Better userguide --- .github/website.sh | 24 +++++++ .travis.yml | 3 +- README.md | 2 +- pom.xml | 115 ++++++++++++--------------------- src/site/markdown/index.md | 2 +- src/site/markdown/userguide.md | 5 +- src/site/site.xml | 13 ++-- 7 files changed, 81 insertions(+), 83 deletions(-) create mode 100644 .github/website.sh diff --git a/.github/website.sh b/.github/website.sh new file mode 100644 index 00000000..8ed908db --- /dev/null +++ b/.github/website.sh @@ -0,0 +1,24 @@ + +echo "## setup..." +git config --global user.name "Stephen Colebourne (CI)" +git config --global user.email "scolebourne@joda.org" +cd target + +echo "## clone..." +git clone https://${GITHUB_TOKEN}@github.com/ThreeTen/threeten.github.io.git +cd jodaorg.github.io +git status + +echo "## copy..." +rm -rf threeten-extra/ +cp -R ../site threeten-extra/ + +echo "## update..." +git add -A +git status +git commit --message "Update threeten-extra from Travis: Build $TRAVIS_BUILD_NUMBER" + +echo "## push..." +git push origin master + +echo "## done" diff --git a/.travis.yml b/.travis.yml index ccd50e69..7c973a65 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ sudo: false language: java jdk: + - oraclejdk10 - oraclejdk9 - oraclejdk8 cache: @@ -12,7 +13,7 @@ install: - mvn --version script: - mvn install site -e -B - - if [[ $TRAVIS_TAG =~ ^v.*$ ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_JDK_VERSION" == "oraclejdk9" ]; then travis_wait 40 mvn clean install site-deploy -e -B --settings .github/maven-settings.xml; fi + - if [[ $TRAVIS_TAG =~ ^v.*$ ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_JDK_VERSION" == "oraclejdk10" ]; then chmod +x ./.github/website.sh; .github/website.sh; fi # secure keys for GITHUB_TOKEN env: global: diff --git a/README.md b/README.md index b492d019..2f308981 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ This release is considered stable and worthy of the 1.x tag. ThreeTen-Extra requires Java SE 8 or later and has no dependencies. -Available in the [Maven Central repository](http://search.maven.org/#artifactdetails|org.threeten|threeten-extra|1.3.2|jar) +Available in the [Maven Central repository](https://search.maven.org/search?q=g:org.threeten%20AND%20a:threeten-extra&core=gav) ### Support diff --git a/pom.xml b/pom.xml index 2a97c79c..e8a1e953 100644 --- a/pom.xml +++ b/pom.xml @@ -146,30 +146,16 @@ - - - org.apache.maven.plugins - maven-jar-plugin - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - true - true - - - - org.apache.felix maven-bundle-plugin - 2.5.4 + ${maven-bundle-plugin.version} biz.aQute.bnd biz.aQute.bndlib - 3.5.0 + ${bndlib.version} @@ -182,12 +168,26 @@ org.threeten.extra,org.threeten.extra.chrono,org.threeten.extra.scale - ${require.capability} + osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))" + + + org.apache.maven.plugins + maven-jar-plugin + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + true + true + + + + org.apache.maven.plugins @@ -216,30 +216,6 @@ - - - com.github.github - site-maven-plugin - 0.12 - - - github-site - - site - - site-deploy - - - - Create website for ${project.artifactId} v${project.version} - threeten-extra - true - github - ThreeTen - threeten.github.io - refs/heads/master - - @@ -424,14 +400,9 @@ - lt.velykis.maven.skins + org.joda.external reflow-velocity-tools - 1.1.1 - - - org.apache.velocity - velocity - 1.7 + 1.2 @@ -469,7 +440,7 @@ com.google.guava guava - 23.5-jre + 26.0-jre test @@ -493,15 +464,16 @@ org.apache.maven.plugins maven-project-info-reports-plugin - ${maven-project-info-plugin.version} + ${maven-project-info-reports-plugin.version} + ci-management dependencies dependency-info - issue-tracking - license - project-team + issue-management + licenses + team scm summary @@ -690,9 +662,6 @@ - - 9 - 8 @@ -829,33 +798,35 @@ 3.1.0 + 2.5.4 2.12.1 + 2.17 - 3.0.0 - 3.7.0 + 3.1.0 + 3.8.0 2.8.2 - 3.0.2 + 3.1.1 3.0.0-M1 1.6 2.5.2 - 3.0.2 + 3.1.0 3.0.0-M1 2.5 - 3.5.1 - 3.9.0 - 2.9 + 3.5.2 + 3.10.0 + 3.0.0 2.5.3 2.4 - 3.0.2 - - 3.4 + 3.1.0 + 3.7.1 3.0.1 - 2.21.0 - 2.21.0 + 2.22.0 + 2.22.0 1.1 - 0.8.0 + 3.5.0 + 0.8.1 1.6.8 - 3.1.3 + 3.1.6 1.8 1.8 @@ -866,11 +837,9 @@ true none - 8.10.1 + 8.12 src/main/checkstyle/checkstyle.xml false - - osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))" UTF-8 UTF-8 diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index 5e8148da..c2572903 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -52,7 +52,7 @@ This release is considered stable and worthy of the 1.x tag. ThreeTen-Extra requires Java SE 8 or later and has no [dependencies](dependencies.html). -Available in [Maven Central](http://search.maven.org/#artifactdetails%7Corg.threeten%7Cthreeten-extra%7C1.3.2%7Cjar). +Available in [Maven Central](https://search.maven.org/search?q=g:org.threeten%20AND%20a:threeten-extra&core=gav). ```xml diff --git a/src/site/markdown/userguide.md b/src/site/markdown/userguide.md index ac10a493..d41e940f 100644 --- a/src/site/markdown/userguide.md +++ b/src/site/markdown/userguide.md @@ -53,5 +53,8 @@ They were not included as they were deemed to be too specialized for the JDK. Use `TaiInstant` if you need an instant using the TAI time-scale. Use `UtcInstant` if you need an instant using the UTC time-scale. -The leap second data is provided in a text file loaded via the `ServiceLoader`. + +The leap second data is provided in a text file loaded from the classpath. Only whole leap seconds are handled, and data starts from 1972 by default. +To replace the built in leap seconds file, create a file `META-INF/org/threeten/extra/scale/LeapSeconds.txt`. +The content should have two columns as per [this format](https://github.com/ThreeTen/threeten-extra/blob/0cf61e35fc165062eb70a66b026c54c261dce46d/src/main/resources/org/threeten/extra/scale/LeapSeconds.txt). diff --git a/src/site/site.xml b/src/site/site.xml index 1cb60d32..6e67f4dc 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -5,9 +5,9 @@ UA-1425975-2 - lt.velykis.maven.skins + org.joda.external reflow-maven-skin - 1.1.1 + 1.2 @@ -59,21 +59,22 @@ - - + + ]]>

    - + - + From 009db7991c4e5cf6450581ef0966948a358a81b1 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 19 Aug 2018 12:39:21 +0100 Subject: [PATCH 071/279] Javadoc fixes --- src/main/java/org/threeten/extra/Interval.java | 2 +- .../java/org/threeten/extra/LocalDateRange.java | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/threeten/extra/Interval.java b/src/main/java/org/threeten/extra/Interval.java index 1fad1368..f2f4b52c 100644 --- a/src/main/java/org/threeten/extra/Interval.java +++ b/src/main/java/org/threeten/extra/Interval.java @@ -121,7 +121,7 @@ public static Interval of(Instant startInclusive, Duration duration) { Objects.requireNonNull(startInclusive, "startInclusive"); Objects.requireNonNull(duration, "duration"); if (duration.isNegative()) { - throw new DateTimeException("Duration must not be zero or negative"); + throw new DateTimeException("Duration must not be negative"); } return new Interval(startInclusive, startInclusive.plus(duration)); } diff --git a/src/main/java/org/threeten/extra/LocalDateRange.java b/src/main/java/org/threeten/extra/LocalDateRange.java index 045f3304..a876dc18 100644 --- a/src/main/java/org/threeten/extra/LocalDateRange.java +++ b/src/main/java/org/threeten/extra/LocalDateRange.java @@ -57,7 +57,7 @@ * between a half-open and a closed range when the end is {@link LocalDate#MAX}. *

    * Date ranges are not comparable. To compare the length of two ranges, it is - * generally recommended to compare the number of days the contain. + * generally recommended to compare the number of days they contain. * *

    Implementation Requirements:

    * This class is immutable and thread-safe. @@ -91,13 +91,12 @@ public final class LocalDateRange /** * Obtains a half-open range of dates, including the start and excluding the end. *

    - * The range includes the start date and excludes the end date, unless the end - * is {@link LocalDate#MAX}. + * The range includes the start date and excludes the end date, unless the end is {@code LocalDate.MAX}. * The end date must be equal to or after the start date. * This definition permits an empty range located at a specific date. * - * @param startInclusive the start date, inclusive, LocalDate.MIN treated as unbounded, not null - * @param endExclusive the end date, exclusive, LocalDate.MAX treated as unbounded, not null + * @param startInclusive the start date, inclusive, {@code LocalDate.MIN} treated as unbounded, not null + * @param endExclusive the end date, exclusive, {@code LocalDate.MAX} treated as unbounded, not null * @return the half-open range, not null * @throws DateTimeException if the end is before the start */ @@ -116,8 +115,8 @@ public static LocalDateRange of(LocalDate startInclusive, LocalDate endExclusive * The range includes the start date and the end date. * The end date must be equal to or after the start date. * - * @param startInclusive the inclusive start date, LocalDate.MIN treated as unbounded, not null - * @param endInclusive the inclusive end date, LocalDate.MAX treated as unbounded, not null + * @param startInclusive the inclusive start date, {@code LocalDate.MIN} treated as unbounded, not null + * @param endInclusive the inclusive end date, {@code LocalDate.MAX} treated as unbounded, not null * @return the closed range * @throws DateTimeException if the end is before the start */ @@ -125,7 +124,7 @@ public static LocalDateRange ofClosed(LocalDate startInclusive, LocalDate endInc Objects.requireNonNull(startInclusive, "startInclusive"); Objects.requireNonNull(endInclusive, "endInclusive"); if (endInclusive.isBefore(startInclusive)) { - throw new DateTimeException("Start date must on or before end date"); + throw new DateTimeException("Start date must be on or before end date"); } LocalDate end = (endInclusive.equals(LocalDate.MAX) ? LocalDate.MAX : endInclusive.plusDays(1)); return new LocalDateRange(startInclusive, end); From 09d32ffee2613355602fbabf0e414c3df1081fe0 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 19 Aug 2018 13:09:38 +0100 Subject: [PATCH 072/279] No range can be empty and unbounded Add empty factory method Add unbounded factory methods Fixes #100 --- src/changes/changes.xml | 6 + .../org/threeten/extra/LocalDateRange.java | 78 ++++++++- .../threeten/extra/TestLocalDateRange.java | 154 ++++++++++-------- 3 files changed, 164 insertions(+), 74 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index dec4a70f..00a89afc 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -8,6 +8,12 @@ + + Enhance LocalDateRange. + Add more factory methods for empty and unbounded. + Reject empty ranges that include LocalDate.MIN/LocalDate.MAX. + Fixes #100. + Fix build for Java 9. Resource files cannot be read from other modules in Java 9. diff --git a/src/main/java/org/threeten/extra/LocalDateRange.java b/src/main/java/org/threeten/extra/LocalDateRange.java index a876dc18..37728d6b 100644 --- a/src/main/java/org/threeten/extra/LocalDateRange.java +++ b/src/main/java/org/threeten/extra/LocalDateRange.java @@ -91,21 +91,20 @@ public final class LocalDateRange /** * Obtains a half-open range of dates, including the start and excluding the end. *

    - * The range includes the start date and excludes the end date, unless the end is {@code LocalDate.MAX}. + * The range includes the start date and excludes the end date, unless the end is {@code LocalDate.MAX}. * The end date must be equal to or after the start date. - * This definition permits an empty range located at a specific date. + * This definition permits an empty range located at a specific date, + * however an empty range cannot be located at {@code LocalDate.MIN} or {@code LocalDate.MAX}. * * @param startInclusive the start date, inclusive, {@code LocalDate.MIN} treated as unbounded, not null * @param endExclusive the end date, exclusive, {@code LocalDate.MAX} treated as unbounded, not null * @return the half-open range, not null - * @throws DateTimeException if the end is before the start + * @throws DateTimeException if the end is before the start, or trying to create + * an empty range at {@code LocalDate.MIN} or {@code LocalDate.MAX} */ public static LocalDateRange of(LocalDate startInclusive, LocalDate endExclusive) { Objects.requireNonNull(startInclusive, "startInclusive"); Objects.requireNonNull(endExclusive, "endExclusive"); - if (endExclusive.isBefore(startInclusive)) { - throw new DateTimeException("End date must on or after start date"); - } return new LocalDateRange(startInclusive, endExclusive); } @@ -152,6 +151,58 @@ public static LocalDateRange of(LocalDate startInclusive, Period period) { return new LocalDateRange(startInclusive, startInclusive.plus(period)); } + /** + * Obtains an empty date range located at the specified date. + *

    + * The empty range has zero length and contains no other dates or ranges. + * An empty range cannot be located at {@code LocalDate.MIN} or {@code LocalDate.MAX}. + * + * @param date the date where the empty range is located, not null + * @return the empty range, not null + * @throws DateTimeException if the date is {@code LocalDate.MIN} or {@code LocalDate.MAX} + */ + public static LocalDateRange ofEmpty(LocalDate date) { + Objects.requireNonNull(date, "date"); + return new LocalDateRange(date, date); + } + + /** + * Obtains a range that is unbounded at the start and end. + * + * @return the range, with an unbounded start and unbounded end + */ + public static LocalDateRange ofUnbounded() { + return ALL; + } + + /** + * Obtains a range up to, but not including, the specified end date. + *

    + * The range includes all dates from the unbounded start, denoted by {@code LocalDate.MIN}, to the end date. + * The end date is exclusive and cannot be {@code LocalDate.MIN}. + * + * @param endExclusive the exclusive end date, {@code LocalDate.MAX} treated as unbounded, not null + * @return the range, with an unbounded start + * @throws DateTimeException if the end date is {@code LocalDate.MIN} + */ + public static LocalDateRange ofUnboundedStart(LocalDate endExclusive) { + return LocalDateRange.of(LocalDate.MIN, endExclusive); + } + + /** + * Obtains a range from and including the specified start date. + *

    + * The range includes all dates from the start date to the unbounded end, denoted by {@code LocalDate.MAX}. + * The start date is inclusive and cannot be {@code LocalDate.MAX}. + * + * @param startInclusive the inclusive start date, {@code LocalDate.MIN} treated as unbounded, not null + * @return the range, with an unbounded end + * @throws DateTimeException if the start date is {@code LocalDate.MAX} + */ + public static LocalDateRange ofUnboundedEnd(LocalDate startInclusive) { + return LocalDateRange.of(startInclusive, LocalDate.MAX); + } + //----------------------------------------------------------------------- /** * Obtains an instance of {@code LocalDateRange} from a text string such as @@ -207,6 +258,12 @@ public static LocalDateRange parse(CharSequence text) { * @param endExclusive the end date, exclusive, validated not null */ private LocalDateRange(LocalDate startInclusive, LocalDate endExclusive) { + if (endExclusive.isBefore(startInclusive)) { + throw new DateTimeException("End date must be on or after start date"); + } + if (endExclusive.equals(LocalDate.MIN) || startInclusive.equals(LocalDate.MAX)) { + throw new DateTimeException("Empty range must not be at LocalDate.MIN or LocalDate.MAX"); + } this.start = startInclusive; this.end = endExclusive; } @@ -248,9 +305,6 @@ public LocalDate getEndInclusive() { if (isUnboundedEnd()) { return LocalDate.MAX; } - if (end.equals(LocalDate.MIN)) { - return LocalDate.MIN; - } return end.minusDays(1); } @@ -259,6 +313,8 @@ public LocalDate getEndInclusive() { * Checks if the range is empty. *

    * An empty range occurs when the start date equals the end date. + *

    + * An empty range is never unbounded. * * @return true if the range is empty */ @@ -268,6 +324,8 @@ public boolean isEmpty() { /** * Checks if the start of the range is unbounded. + *

    + * An unbounded range is never empty. * * @return true if start is unbounded */ @@ -277,6 +335,8 @@ public boolean isUnboundedStart() { /** * Checks if the end of the range is unbounded. + *

    + * An unbounded range is never empty. * * @return true if end is unbounded */ diff --git a/src/test/java/org/threeten/extra/TestLocalDateRange.java b/src/test/java/org/threeten/extra/TestLocalDateRange.java index 2362ef70..3c7fe8e0 100644 --- a/src/test/java/org/threeten/extra/TestLocalDateRange.java +++ b/src/test/java/org/threeten/extra/TestLocalDateRange.java @@ -135,16 +135,14 @@ public void test_of_MIN_MAX() { assertEquals("-999999999-01-01/+999999999-12-31", test.toString()); } - @Test + @Test(expected = DateTimeException.class) public void test_of_MIN_MIN() { - LocalDateRange test = LocalDateRange.of(LocalDate.MIN, LocalDate.MIN); - assertEquals(LocalDate.MIN, test.getStart()); - assertEquals(LocalDate.MIN, test.getEndInclusive()); - assertEquals(LocalDate.MIN, test.getEnd()); - assertEquals(true, test.isEmpty()); - assertEquals(true, test.isUnboundedStart()); - assertEquals(false, test.isUnboundedEnd()); - assertEquals("-999999999-01-01/-999999999-01-01", test.toString()); + LocalDateRange.of(LocalDate.MIN, LocalDate.MIN); + } + + @Test(expected = DateTimeException.class) + public void test_of_MAX_MAX() { + LocalDateRange.of(LocalDate.MAX, LocalDate.MAX); } @Test @@ -214,6 +212,78 @@ public void test_ofClosed_badOrder() { LocalDateRange.ofClosed(DATE_2012_07_31, DATE_2012_07_30); } + //----------------------------------------------------------------------- + @Test + public void test_ofEmpty() { + LocalDateRange test = LocalDateRange.ofEmpty(DATE_2012_07_30); + assertEquals(DATE_2012_07_30, test.getStart()); + assertEquals(DATE_2012_07_29, test.getEndInclusive()); + assertEquals(DATE_2012_07_30, test.getEnd()); + assertEquals(true, test.isEmpty()); + assertEquals(false, test.isUnboundedStart()); + assertEquals(false, test.isUnboundedEnd()); + assertEquals("2012-07-30/2012-07-30", test.toString()); + } + + @Test(expected = DateTimeException.class) + public void test_ofEmpty_MIN() { + LocalDateRange.ofEmpty(LocalDate.MIN); + } + + @Test(expected = DateTimeException.class) + public void test_ofEmpty_MAX() { + LocalDateRange.ofEmpty(LocalDate.MAX); + } + + //----------------------------------------------------------------------- + @Test + public void test_ofUnbounded() { + LocalDateRange test = LocalDateRange.ofUnbounded(); + assertEquals(LocalDate.MIN, test.getStart()); + assertEquals(LocalDate.MAX, test.getEndInclusive()); + assertEquals(LocalDate.MAX, test.getEnd()); + assertEquals(false, test.isEmpty()); + assertEquals(true, test.isUnboundedStart()); + assertEquals(true, test.isUnboundedEnd()); + assertEquals("-999999999-01-01/+999999999-12-31", test.toString()); + } + + //----------------------------------------------------------------------- + @Test + public void test_ofUnboundedStart() { + LocalDateRange test = LocalDateRange.ofUnboundedStart(DATE_2012_07_30); + assertEquals(LocalDate.MIN, test.getStart()); + assertEquals(DATE_2012_07_29, test.getEndInclusive()); + assertEquals(DATE_2012_07_30, test.getEnd()); + assertEquals(false, test.isEmpty()); + assertEquals(true, test.isUnboundedStart()); + assertEquals(false, test.isUnboundedEnd()); + assertEquals("-999999999-01-01/2012-07-30", test.toString()); + } + + @Test(expected = DateTimeException.class) + public void test_ofUnboundedStart_MIN() { + LocalDateRange.ofUnboundedStart(LocalDate.MIN); + } + + //----------------------------------------------------------------------- + @Test + public void test_ofUnboundedEnd() { + LocalDateRange test = LocalDateRange.ofUnboundedEnd(DATE_2012_07_30); + assertEquals(DATE_2012_07_30, test.getStart()); + assertEquals(LocalDate.MAX, test.getEndInclusive()); + assertEquals(LocalDate.MAX, test.getEnd()); + assertEquals(false, test.isEmpty()); + assertEquals(false, test.isUnboundedStart()); + assertEquals(true, test.isUnboundedEnd()); + assertEquals("2012-07-30/+999999999-12-31", test.toString()); + } + + @Test(expected = DateTimeException.class) + public void test_ofUnboundedEnd_MAX() { + LocalDateRange.ofUnboundedEnd(LocalDate.MAX); + } + //----------------------------------------------------------------------- @Test public void test_of_period() { @@ -231,6 +301,16 @@ public void test_of_period_negative() { LocalDateRange.of(DATE_2012_07_31, Period.ofDays(-1)); } + @Test(expected = DateTimeException.class) + public void test_of_period_atMIN() { + LocalDateRange.of(LocalDate.MIN, Period.ofDays(0)); + } + + @Test(expected = DateTimeException.class) + public void test_of_period_atMAX() { + LocalDateRange.of(LocalDate.MAX, Period.ofDays(0)); + } + //----------------------------------------------------------------------- @Test public void test_parse_CharSequence() { @@ -546,20 +626,6 @@ public void test_encloses_baseEmpty() { assertEquals(false, test.encloses(LocalDateRange.of(DATE_2012_07_28, LocalDate.MAX))); } - @Test - public void test_encloses_baseEmptyMax() { - assertEquals(true, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .encloses(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX))); - assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX))); - assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); - assertEquals(false, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); - assertEquals(false, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .encloses(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2)))); - } - @Test public void test_abuts_baseEmpty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28); @@ -570,20 +636,6 @@ public void test_abuts_baseEmpty() { assertEquals(true, test.abuts(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_29))); } - @Test - public void test_abuts_baseEmptyMax() { - assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .abuts(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX))); - assertEquals(true, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX))); - assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); - assertEquals(true, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); - assertEquals(false, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .abuts(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2)))); - } - @Test public void test_isConnected_baseEmpty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28); @@ -592,20 +644,6 @@ public void test_isConnected_baseEmpty() { assertEquals(false, test.isConnected(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29))); } - @Test - public void test_isConnected_baseEmptyMax() { - assertEquals(true, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .isConnected(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX))); - assertEquals(true, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX))); - assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); - assertEquals(true, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); - assertEquals(false, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .isConnected(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2)))); - } - @Test public void test_overlaps_baseEmpty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_28); @@ -614,20 +652,6 @@ public void test_overlaps_baseEmpty() { assertEquals(false, test.overlaps(LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29))); } - @Test - public void test_overlaps_baseEmptyMax() { - assertEquals(true, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .overlaps(LocalDateRange.of(LocalDate.MAX, LocalDate.MAX))); - assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .overlaps(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX))); - assertEquals(false, LocalDateRange.of(LocalDate.MAX, LocalDate.MAX) - .overlaps(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); - assertEquals(false, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .overlaps(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(1)))); - assertEquals(false, LocalDateRange.of(LocalDate.MAX.minusDays(1), LocalDate.MAX.minusDays(1)) - .overlaps(LocalDateRange.of(DATE_2012_07_01, LocalDate.MAX.minusDays(2)))); - } - //----------------------------------------------------------------------- @DataProvider public static Object[][] data_intersection() { From 0ab533ddc9aea8b9b6a233e64394267ccd3ade69 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 19 Aug 2018 13:48:21 +0100 Subject: [PATCH 073/279] Clearer Javadoc --- src/main/java/org/threeten/extra/LocalDateRange.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/threeten/extra/LocalDateRange.java b/src/main/java/org/threeten/extra/LocalDateRange.java index 37728d6b..d83131a0 100644 --- a/src/main/java/org/threeten/extra/LocalDateRange.java +++ b/src/main/java/org/threeten/extra/LocalDateRange.java @@ -52,9 +52,9 @@ * Internally, the class stores the start and end dates, with the start inclusive and the end exclusive. * The end date is always greater than or equal to the start date. *

    - * The constants {@link LocalDate#MIN} and {@link LocalDate#MAX} can be used + * The constants {@code LocalDate.MIN} and {@code LocalDate.MAX} can be used * to indicate an unbounded far-past or far-future. Note that there is no difference - * between a half-open and a closed range when the end is {@link LocalDate#MAX}. + * between a half-open and a closed range when the end is {@code LocalDate.MAX}. *

    * Date ranges are not comparable. To compare the length of two ranges, it is * generally recommended to compare the number of days they contain. @@ -272,7 +272,7 @@ private LocalDateRange(LocalDate startInclusive, LocalDate endExclusive) { /** * Gets the start date of this range, inclusive. *

    - * This will return {@link LocalDate#MIN} if the range is unbounded at the start. + * This will return {@code LocalDate#MIN} if the range is unbounded at the start. * In this case, the range includes all dates into the far-past. * * @return the start date @@ -284,7 +284,7 @@ public LocalDate getStart() { /** * Gets the end date of this range, exclusive. *

    - * This will return {@link LocalDate#MAX} if the range is unbounded at the end. + * This will return {@code LocalDate.MAX} if the range is unbounded at the end. * In this case, the range includes all dates into the far-future. * * @return the end date, exclusive @@ -296,7 +296,7 @@ public LocalDate getEnd() { /** * Gets the end date of this range, inclusive. *

    - * This will return {@link LocalDate#MAX} if the range is unbounded at the end. + * This will return {@code LocalDate.MAX} if the range is unbounded at the end. * In this case, the range includes all dates into the far-future. * * @return the end date, inclusive From f431b3f087f82aca273d59612e8b1a8400421fb3 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 19 Aug 2018 15:13:16 +0100 Subject: [PATCH 074/279] Block construction of certain ranges At the boundaries, some ranges don't make much sense Prevent these from being created Fixes #100 --- .../org/threeten/extra/LocalDateRange.java | 81 ++++++-- .../threeten/extra/TestLocalDateRange.java | 185 ++++++++++++++++++ 2 files changed, 250 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/threeten/extra/LocalDateRange.java b/src/main/java/org/threeten/extra/LocalDateRange.java index d83131a0..432a0623 100644 --- a/src/main/java/org/threeten/extra/LocalDateRange.java +++ b/src/main/java/org/threeten/extra/LocalDateRange.java @@ -55,6 +55,11 @@ * The constants {@code LocalDate.MIN} and {@code LocalDate.MAX} can be used * to indicate an unbounded far-past or far-future. Note that there is no difference * between a half-open and a closed range when the end is {@code LocalDate.MAX}. + * Empty ranges are allowed. + *

    + * No range can end at {@code LocalDate.MIN} or {@code LocalDate.MIN.plusDays(1)}. + * No range can start at {@code LocalDate.MAX} or {@code LocalDate.MAX.minusDays(1)}. + * No empty range can exist at {@code LocalDate.MIN} or {@code LocalDate.MAX}. *

    * Date ranges are not comparable. To compare the length of two ranges, it is * generally recommended to compare the number of days they contain. @@ -72,6 +77,14 @@ public final class LocalDateRange * A range over the whole time-line. */ public static final LocalDateRange ALL = new LocalDateRange(LocalDate.MIN, LocalDate.MAX); + /** + * The day after the MIN date. + */ + private static final LocalDate MINP1 = LocalDate.MIN.plusDays(1); + /** + * The day before the MAX date. + */ + private static final LocalDate MAXM1 = LocalDate.MAX.minusDays(1); /** * Serialization version. @@ -93,14 +106,21 @@ public final class LocalDateRange *

    * The range includes the start date and excludes the end date, unless the end is {@code LocalDate.MAX}. * The end date must be equal to or after the start date. - * This definition permits an empty range located at a specific date, - * however an empty range cannot be located at {@code LocalDate.MIN} or {@code LocalDate.MAX}. + * This definition permits an empty range located at a specific date. + *

    + * The constants {@code LocalDate.MIN} and {@code LocalDate.MAX} can be used + * to indicate an unbounded far-past or far-future. + *

    + * The start inclusive date must not be {@code LocalDate.MAX} or {@code LocalDate.MAX.minusDays(1)}. + * The end inclusive date must not be {@code LocalDate.MIN} or {@code LocalDate.MIN.plusDays(1)}. + * No empty range can exist at {@code LocalDate.MIN} or {@code LocalDate.MAX}. * - * @param startInclusive the start date, inclusive, {@code LocalDate.MIN} treated as unbounded, not null - * @param endExclusive the end date, exclusive, {@code LocalDate.MAX} treated as unbounded, not null + * @param startInclusive the inclusive start date, not null + * @param endExclusive the exclusive end date, not null * @return the half-open range, not null - * @throws DateTimeException if the end is before the start, or trying to create - * an empty range at {@code LocalDate.MIN} or {@code LocalDate.MAX} + * @throws DateTimeException if the end is before the start, + * or the start date is {@code LocalDate.MAX} or {@code LocalDate.MAX.minusDays(1)}, + * or the end date is {@code LocalDate.MIN} or {@code LocalDate.MIN.plusDays(1)} */ public static LocalDateRange of(LocalDate startInclusive, LocalDate endExclusive) { Objects.requireNonNull(startInclusive, "startInclusive"); @@ -113,11 +133,20 @@ public static LocalDateRange of(LocalDate startInclusive, LocalDate endExclusive *

    * The range includes the start date and the end date. * The end date must be equal to or after the start date. + *

    + * The constants {@code LocalDate.MIN} and {@code LocalDate.MAX} can be used + * to indicate an unbounded far-past or far-future. In addition, an end date of + * {@code LocalDate.MAX.minusDays(1)} will also create an unbounded far-future range. + *

    + * The start inclusive date must not be {@code LocalDate.MAX} or {@code LocalDate.MAX.minusDays(1)}. + * The end inclusive date must not be {@code LocalDate.MIN}. * - * @param startInclusive the inclusive start date, {@code LocalDate.MIN} treated as unbounded, not null - * @param endInclusive the inclusive end date, {@code LocalDate.MAX} treated as unbounded, not null + * @param startInclusive the inclusive start date, not null + * @param endInclusive the inclusive end date, not null * @return the closed range - * @throws DateTimeException if the end is before the start + * @throws DateTimeException if the end is before the start, + * or the start date is {@code LocalDate.MAX} or {@code LocalDate.MAX.minusDays(1)}, + * or the end date is {@code LocalDate.MIN} */ public static LocalDateRange ofClosed(LocalDate startInclusive, LocalDate endInclusive) { Objects.requireNonNull(startInclusive, "startInclusive"); @@ -134,8 +163,12 @@ public static LocalDateRange ofClosed(LocalDate startInclusive, LocalDate endInc *

    * The end date is calculated as the start plus the duration. * The period must not be negative. + *

    + * The constant {@code LocalDate.MIN} can be used to indicate an unbounded far-past. + *

    + * The period must not be zero when the start date is {@code LocalDate.MIN}. * - * @param startInclusive the start date, inclusive, not null + * @param startInclusive the inclusive start date, not null * @param period the period from the start to the end, not null * @return the range, not null * @throws DateTimeException if the end is before the start, @@ -155,11 +188,13 @@ public static LocalDateRange of(LocalDate startInclusive, Period period) { * Obtains an empty date range located at the specified date. *

    * The empty range has zero length and contains no other dates or ranges. - * An empty range cannot be located at {@code LocalDate.MIN} or {@code LocalDate.MAX}. + * An empty range cannot be located at {@code LocalDate.MIN}, {@code LocalDate.MIN.plusDays(1)}, + * {@code LocalDate.MAX} or {@code LocalDate.MAX.minusDays(1)}. * * @param date the date where the empty range is located, not null * @return the empty range, not null - * @throws DateTimeException if the date is {@code LocalDate.MIN} or {@code LocalDate.MAX} + * @throws DateTimeException if the date is {@code LocalDate.MIN}, {@code LocalDate.MIN.plusDays(1)}, + * {@code LocalDate.MAX} or {@code LocalDate.MAX.minusDays(1)} */ public static LocalDateRange ofEmpty(LocalDate date) { Objects.requireNonNull(date, "date"); @@ -179,11 +214,11 @@ public static LocalDateRange ofUnbounded() { * Obtains a range up to, but not including, the specified end date. *

    * The range includes all dates from the unbounded start, denoted by {@code LocalDate.MIN}, to the end date. - * The end date is exclusive and cannot be {@code LocalDate.MIN}. + * The end date is exclusive and cannot be {@code LocalDate.MIN} or {@code LocalDate.MIN.plusDays(1)}. * * @param endExclusive the exclusive end date, {@code LocalDate.MAX} treated as unbounded, not null * @return the range, with an unbounded start - * @throws DateTimeException if the end date is {@code LocalDate.MIN} + * @throws DateTimeException if the end date is {@code LocalDate.MIN} or {@code LocalDate.MIN.plusDays(1)} */ public static LocalDateRange ofUnboundedStart(LocalDate endExclusive) { return LocalDateRange.of(LocalDate.MIN, endExclusive); @@ -193,11 +228,11 @@ public static LocalDateRange ofUnboundedStart(LocalDate endExclusive) { * Obtains a range from and including the specified start date. *

    * The range includes all dates from the start date to the unbounded end, denoted by {@code LocalDate.MAX}. - * The start date is inclusive and cannot be {@code LocalDate.MAX}. + * The start date is inclusive and cannot be {@code LocalDate.MAX} or {@code LocalDate.MAX.minusDays(1)}. * * @param startInclusive the inclusive start date, {@code LocalDate.MIN} treated as unbounded, not null * @return the range, with an unbounded end - * @throws DateTimeException if the start date is {@code LocalDate.MAX} + * @throws DateTimeException if the start date is {@code LocalDate.MAX} or {@code LocalDate.MAX.minusDays(1)} */ public static LocalDateRange ofUnboundedEnd(LocalDate startInclusive) { return LocalDateRange.of(startInclusive, LocalDate.MAX); @@ -261,6 +296,12 @@ private LocalDateRange(LocalDate startInclusive, LocalDate endExclusive) { if (endExclusive.isBefore(startInclusive)) { throw new DateTimeException("End date must be on or after start date"); } + if (startInclusive.equals(MAXM1)) { + throw new DateTimeException("Range must not start at LocalDate.MAX.minusDays(1)"); + } + if (endExclusive.equals(MINP1)) { + throw new DateTimeException("Range must not end at LocalDate.MIN.plusDays(1)"); + } if (endExclusive.equals(LocalDate.MIN) || startInclusive.equals(LocalDate.MAX)) { throw new DateTimeException("Empty range must not be at LocalDate.MIN or LocalDate.MAX"); } @@ -274,6 +315,8 @@ private LocalDateRange(LocalDate startInclusive, LocalDate endExclusive) { *

    * This will return {@code LocalDate#MIN} if the range is unbounded at the start. * In this case, the range includes all dates into the far-past. + *

    + * This never returns {@code LocalDate.MAX} or {@code LocalDate.MAX.minusDays(1)}. * * @return the start date */ @@ -286,6 +329,8 @@ public LocalDate getStart() { *

    * This will return {@code LocalDate.MAX} if the range is unbounded at the end. * In this case, the range includes all dates into the far-future. + *

    + * This never returns {@code LocalDate.MIN} or {@code LocalDate.MIN.plusDays(1)}. * * @return the end date, exclusive */ @@ -298,6 +343,10 @@ public LocalDate getEnd() { *

    * This will return {@code LocalDate.MAX} if the range is unbounded at the end. * In this case, the range includes all dates into the far-future. + *

    + * This returns the date before the end date. + *

    + * This never returns {@code LocalDate.MIN}. * * @return the end date, inclusive */ diff --git a/src/test/java/org/threeten/extra/TestLocalDateRange.java b/src/test/java/org/threeten/extra/TestLocalDateRange.java index 3c7fe8e0..94cb217a 100644 --- a/src/test/java/org/threeten/extra/TestLocalDateRange.java +++ b/src/test/java/org/threeten/extra/TestLocalDateRange.java @@ -64,6 +64,10 @@ @RunWith(DataProviderRunner.class) public class TestLocalDateRange { + private static final LocalDate MINP1 = LocalDate.MIN.plusDays(1); + private static final LocalDate MINP2 = LocalDate.MIN.plusDays(2); + private static final LocalDate MINP3 = LocalDate.MIN.plusDays(3); + private static final LocalDate MAXM1 = LocalDate.MAX.minusDays(1); private static final LocalDate DATE_2012_07_01 = LocalDate.of(2012, 7, 1); private static final LocalDate DATE_2012_07_27 = LocalDate.of(2012, 7, 27); private static final LocalDate DATE_2012_07_28 = LocalDate.of(2012, 7, 28); @@ -96,6 +100,7 @@ public void test_of() { assertEquals(false, test.isEmpty()); assertEquals(false, test.isUnboundedStart()); assertEquals(false, test.isUnboundedEnd()); + assertEquals(3, test.lengthInDays()); assertEquals("2012-07-28/2012-07-31", test.toString()); } @@ -140,11 +145,70 @@ public void test_of_MIN_MIN() { LocalDateRange.of(LocalDate.MIN, LocalDate.MIN); } + @Test(expected = DateTimeException.class) + public void test_of_MIN_MINP1() { + LocalDateRange.of(LocalDate.MIN, MINP1); + } + + @Test(expected = DateTimeException.class) + public void test_of_MINP1_MINP1() { + LocalDateRange.of(MINP1, MINP1); + } + + @Test + public void test_of_MIN_MINP2() { + LocalDateRange test = LocalDateRange.of(LocalDate.MIN, MINP2); + assertEquals(LocalDate.MIN, test.getStart()); + assertEquals(MINP1, test.getEndInclusive()); + assertEquals(MINP2, test.getEnd()); + assertEquals(false, test.isEmpty()); + assertEquals(true, test.isUnboundedStart()); + assertEquals(false, test.isUnboundedEnd()); + assertEquals(2, test.lengthInDays()); + assertEquals("-999999999-01-01/-999999999-01-03", test.toString()); + } + + @Test + public void test_of_MINP1_MINP2() { + LocalDateRange test = LocalDateRange.of(MINP1, MINP2); + assertEquals(MINP1, test.getStart()); + assertEquals(MINP1, test.getEndInclusive()); + assertEquals(MINP2, test.getEnd()); + assertEquals(false, test.isEmpty()); + assertEquals(false, test.isUnboundedStart()); + assertEquals(false, test.isUnboundedEnd()); + assertEquals(1, test.lengthInDays()); + assertEquals("-999999999-01-02/-999999999-01-03", test.toString()); + } + + @Test + public void test_of_MINP2_MINP2() { + LocalDateRange test = LocalDateRange.of(MINP2, MINP2); + assertEquals(MINP2, test.getStart()); + assertEquals(MINP1, test.getEndInclusive()); + assertEquals(MINP2, test.getEnd()); + assertEquals(true, test.isEmpty()); + assertEquals(false, test.isUnboundedStart()); + assertEquals(false, test.isUnboundedEnd()); + assertEquals(0, test.lengthInDays()); + assertEquals("-999999999-01-03/-999999999-01-03", test.toString()); + } + @Test(expected = DateTimeException.class) public void test_of_MAX_MAX() { LocalDateRange.of(LocalDate.MAX, LocalDate.MAX); } + @Test(expected = DateTimeException.class) + public void test_of_MAXM1_MAX() { + LocalDateRange.of(MAXM1, LocalDate.MAX); + } + + @Test(expected = DateTimeException.class) + public void test_of_MAXM1_MAXM1() { + LocalDateRange.of(MAXM1, MAXM1); + } + @Test public void test_of_empty() { LocalDateRange test = LocalDateRange.of(DATE_2012_07_30, DATE_2012_07_30); @@ -154,6 +218,7 @@ public void test_of_empty() { assertEquals(true, test.isEmpty()); assertEquals(false, test.isUnboundedStart()); assertEquals(false, test.isUnboundedEnd()); + assertEquals(0, test.lengthInDays()); assertEquals("2012-07-30/2012-07-30", test.toString()); } @@ -169,8 +234,10 @@ public void test_ofClosed() { assertEquals(DATE_2012_07_28, test.getStart()); assertEquals(DATE_2012_07_30, test.getEndInclusive()); assertEquals(DATE_2012_07_31, test.getEnd()); + assertEquals(false, test.isEmpty()); assertEquals(false, test.isUnboundedStart()); assertEquals(false, test.isUnboundedEnd()); + assertEquals(3, test.lengthInDays()); assertEquals("2012-07-28/2012-07-31", test.toString()); } @@ -180,6 +247,7 @@ public void test_ofClosed_MIN() { assertEquals(LocalDate.MIN, test.getStart()); assertEquals(DATE_2012_07_30, test.getEndInclusive()); assertEquals(DATE_2012_07_31, test.getEnd()); + assertEquals(false, test.isEmpty()); assertEquals(true, test.isUnboundedStart()); assertEquals(false, test.isUnboundedEnd()); assertEquals("-999999999-01-01/2012-07-31", test.toString()); @@ -191,6 +259,7 @@ public void test_ofClosed_MAX() { assertEquals(DATE_2012_07_28, test.getStart()); assertEquals(LocalDate.MAX, test.getEndInclusive()); assertEquals(LocalDate.MAX, test.getEnd()); + assertEquals(false, test.isEmpty()); assertEquals(false, test.isUnboundedStart()); assertEquals(true, test.isUnboundedEnd()); assertEquals("2012-07-28/+999999999-12-31", test.toString()); @@ -202,11 +271,97 @@ public void test_ofClosed_MIN_MAX() { assertEquals(LocalDate.MIN, test.getStart()); assertEquals(LocalDate.MAX, test.getEndInclusive()); assertEquals(LocalDate.MAX, test.getEnd()); + assertEquals(false, test.isEmpty()); assertEquals(true, test.isUnboundedStart()); assertEquals(true, test.isUnboundedEnd()); assertEquals("-999999999-01-01/+999999999-12-31", test.toString()); } + @Test(expected = DateTimeException.class) + public void test_ofClosed_MIN_MIN() { + LocalDateRange.ofClosed(LocalDate.MIN, LocalDate.MIN); + } + + @Test + public void test_ofClosed_MIN_MINP1() { + LocalDateRange test = LocalDateRange.ofClosed(LocalDate.MIN, MINP1); + assertEquals(LocalDate.MIN, test.getStart()); + assertEquals(MINP1, test.getEndInclusive()); + assertEquals(MINP2, test.getEnd()); + assertEquals(false, test.isEmpty()); + assertEquals(true, test.isUnboundedStart()); + assertEquals(false, test.isUnboundedEnd()); + assertEquals(2, test.lengthInDays()); + assertEquals("-999999999-01-01/-999999999-01-03", test.toString()); + } + + @Test + public void test_ofClosed_MINP1_MINP1() { + LocalDateRange test = LocalDateRange.ofClosed(MINP1, MINP1); + assertEquals(MINP1, test.getStart()); + assertEquals(MINP1, test.getEndInclusive()); + assertEquals(MINP2, test.getEnd()); + assertEquals(false, test.isEmpty()); + assertEquals(false, test.isUnboundedStart()); + assertEquals(false, test.isUnboundedEnd()); + assertEquals(1, test.lengthInDays()); + assertEquals("-999999999-01-02/-999999999-01-03", test.toString()); + } + + @Test + public void test_ofClosed_MIN_MINP2() { + LocalDateRange test = LocalDateRange.ofClosed(LocalDate.MIN, MINP2); + assertEquals(LocalDate.MIN, test.getStart()); + assertEquals(MINP2, test.getEndInclusive()); + assertEquals(MINP3, test.getEnd()); + assertEquals(false, test.isEmpty()); + assertEquals(true, test.isUnboundedStart()); + assertEquals(false, test.isUnboundedEnd()); + assertEquals(3, test.lengthInDays()); + assertEquals("-999999999-01-01/-999999999-01-04", test.toString()); + } + + @Test + public void test_ofClosed_MINP1_MINP2() { + LocalDateRange test = LocalDateRange.ofClosed(MINP1, MINP2); + assertEquals(MINP1, test.getStart()); + assertEquals(MINP2, test.getEndInclusive()); + assertEquals(MINP3, test.getEnd()); + assertEquals(false, test.isEmpty()); + assertEquals(false, test.isUnboundedStart()); + assertEquals(false, test.isUnboundedEnd()); + assertEquals(2, test.lengthInDays()); + assertEquals("-999999999-01-02/-999999999-01-04", test.toString()); + } + + @Test + public void test_ofClosed_MINP2_MINP2() { + LocalDateRange test = LocalDateRange.ofClosed(MINP2, MINP2); + assertEquals(MINP2, test.getStart()); + assertEquals(MINP2, test.getEndInclusive()); + assertEquals(MINP3, test.getEnd()); + assertEquals(false, test.isEmpty()); + assertEquals(false, test.isUnboundedStart()); + assertEquals(false, test.isUnboundedEnd()); + assertEquals(1, test.lengthInDays()); + assertEquals("-999999999-01-03/-999999999-01-04", test.toString()); + } + + @Test(expected = DateTimeException.class) + public void test_ofClosed_MAX_MAX() { + LocalDateRange.ofClosed(LocalDate.MAX, LocalDate.MAX); + } + + @Test(expected = DateTimeException.class) + public void test_ofClosed_MAXM1_MAX() { + LocalDateRange.ofClosed(MAXM1, LocalDate.MAX); + } + + @Test(expected = DateTimeException.class) + public void test_ofClosed_MAXM1_MAXM1() { + LocalDateRange.ofClosed(MAXM1, MAXM1); + } + @Test(expected = DateTimeException.class) public void test_ofClosed_badOrder() { LocalDateRange.ofClosed(DATE_2012_07_31, DATE_2012_07_30); @@ -230,11 +385,21 @@ public void test_ofEmpty_MIN() { LocalDateRange.ofEmpty(LocalDate.MIN); } + @Test(expected = DateTimeException.class) + public void test_ofEmpty_MINP1() { + LocalDateRange.ofEmpty(MINP1); + } + @Test(expected = DateTimeException.class) public void test_ofEmpty_MAX() { LocalDateRange.ofEmpty(LocalDate.MAX); } + @Test(expected = DateTimeException.class) + public void test_ofEmpty_MAXM1() { + LocalDateRange.ofEmpty(MAXM1); + } + //----------------------------------------------------------------------- @Test public void test_ofUnbounded() { @@ -266,6 +431,11 @@ public void test_ofUnboundedStart_MIN() { LocalDateRange.ofUnboundedStart(LocalDate.MIN); } + @Test(expected = DateTimeException.class) + public void test_ofUnboundedStart_MINP1() { + LocalDateRange.ofUnboundedStart(MINP1); + } + //----------------------------------------------------------------------- @Test public void test_ofUnboundedEnd() { @@ -284,6 +454,11 @@ public void test_ofUnboundedEnd_MAX() { LocalDateRange.ofUnboundedEnd(LocalDate.MAX); } + @Test(expected = DateTimeException.class) + public void test_ofUnboundedEnd_MAXM1() { + LocalDateRange.ofUnboundedEnd(MAXM1); + } + //----------------------------------------------------------------------- @Test public void test_of_period() { @@ -311,6 +486,16 @@ public void test_of_period_atMAX() { LocalDateRange.of(LocalDate.MAX, Period.ofDays(0)); } + @Test(expected = DateTimeException.class) + public void test_of_period_atMAXM1_0D() { + LocalDateRange.of(MAXM1, Period.ofDays(0)); + } + + @Test(expected = DateTimeException.class) + public void test_of_period_atMAXM1_1D() { + LocalDateRange.of(MAXM1, Period.ofDays(1)); + } + //----------------------------------------------------------------------- @Test public void test_parse_CharSequence() { From 58f2cfef9e9a5f5e9d0edc91a07666669f165a34 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 19 Aug 2018 15:30:24 +0100 Subject: [PATCH 075/279] Adjust lengthInDays() and toPeriod() Handle unbounded ranges more clearly Fixes #100 --- src/changes/changes.xml | 4 ++- .../org/threeten/extra/LocalDateRange.java | 18 ++++++++++--- .../threeten/extra/TestLocalDateRange.java | 25 ++++++++++++++++--- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 00a89afc..eb7dcf30 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -11,7 +11,9 @@ Enhance LocalDateRange. Add more factory methods for empty and unbounded. - Reject empty ranges that include LocalDate.MIN/LocalDate.MAX. + Ensure that unbounded ranges are more clearly specified. + Reject certain ranges near LocalDate.MIN/LocalDate.MAX. + Alter behaviour of lengthInDays() and toPeriod(). Fixes #100. diff --git a/src/main/java/org/threeten/extra/LocalDateRange.java b/src/main/java/org/threeten/extra/LocalDateRange.java index 432a0623..d3e95832 100644 --- a/src/main/java/org/threeten/extra/LocalDateRange.java +++ b/src/main/java/org/threeten/extra/LocalDateRange.java @@ -677,23 +677,33 @@ public boolean isBefore(LocalDateRange range) { * Obtains the length of this range in days. *

    * This returns the number of days between the start and end dates. + * If the range is too large, the length will be {@code Integer.MAX_VALUE}. + * Unbounded ranges return {@code Integer.MAX_VALUE}. * - * @return the length in days - * @throws ArithmeticException if the length exceeds the capacity of an {@code int} + * @return the length in days, Integer.MAX_VALUE if unbounded or too large */ public int lengthInDays() { - return Math.toIntExact(end.toEpochDay() - start.toEpochDay()); + if (isUnboundedStart() || isUnboundedEnd()) { + return Integer.MAX_VALUE; + } + long length = end.toEpochDay() - start.toEpochDay(); + return length > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) length; } /** * Obtains the length of this range as a period. *

    * This returns the {@link Period} between the start and end dates. + * Unbounded ranges throw {@link ArithmeticException}. * * @return the period of the range - * @throws ArithmeticException if the calculation exceeds the capacity of {@code Period} + * @throws ArithmeticException if the calculation exceeds the capacity of {@code Period}, + * or the range is unbounded */ public Period toPeriod() { + if (isUnboundedStart() || isUnboundedEnd()) { + throw new ArithmeticException("Unbounded range cannot be converted to a Period"); + } return Period.between(start, end); } diff --git a/src/test/java/org/threeten/extra/TestLocalDateRange.java b/src/test/java/org/threeten/extra/TestLocalDateRange.java index 94cb217a..d643a8fd 100644 --- a/src/test/java/org/threeten/extra/TestLocalDateRange.java +++ b/src/test/java/org/threeten/extra/TestLocalDateRange.java @@ -113,6 +113,7 @@ public void test_of_MIN() { assertEquals(false, test.isEmpty()); assertEquals(true, test.isUnboundedStart()); assertEquals(false, test.isUnboundedEnd()); + assertEquals(Integer.MAX_VALUE, test.lengthInDays()); assertEquals("-999999999-01-01/2012-07-31", test.toString()); } @@ -125,6 +126,7 @@ public void test_of_MAX() { assertEquals(false, test.isEmpty()); assertEquals(false, test.isUnboundedStart()); assertEquals(true, test.isUnboundedEnd()); + assertEquals(Integer.MAX_VALUE, test.lengthInDays()); assertEquals("2012-07-28/+999999999-12-31", test.toString()); } @@ -137,6 +139,7 @@ public void test_of_MIN_MAX() { assertEquals(false, test.isEmpty()); assertEquals(true, test.isUnboundedStart()); assertEquals(true, test.isUnboundedEnd()); + assertEquals(Integer.MAX_VALUE, test.lengthInDays()); assertEquals("-999999999-01-01/+999999999-12-31", test.toString()); } @@ -164,7 +167,7 @@ public void test_of_MIN_MINP2() { assertEquals(false, test.isEmpty()); assertEquals(true, test.isUnboundedStart()); assertEquals(false, test.isUnboundedEnd()); - assertEquals(2, test.lengthInDays()); + assertEquals(Integer.MAX_VALUE, test.lengthInDays()); assertEquals("-999999999-01-01/-999999999-01-03", test.toString()); } @@ -250,6 +253,7 @@ public void test_ofClosed_MIN() { assertEquals(false, test.isEmpty()); assertEquals(true, test.isUnboundedStart()); assertEquals(false, test.isUnboundedEnd()); + assertEquals(Integer.MAX_VALUE, test.lengthInDays()); assertEquals("-999999999-01-01/2012-07-31", test.toString()); } @@ -262,6 +266,7 @@ public void test_ofClosed_MAX() { assertEquals(false, test.isEmpty()); assertEquals(false, test.isUnboundedStart()); assertEquals(true, test.isUnboundedEnd()); + assertEquals(Integer.MAX_VALUE, test.lengthInDays()); assertEquals("2012-07-28/+999999999-12-31", test.toString()); } @@ -274,6 +279,7 @@ public void test_ofClosed_MIN_MAX() { assertEquals(false, test.isEmpty()); assertEquals(true, test.isUnboundedStart()); assertEquals(true, test.isUnboundedEnd()); + assertEquals(Integer.MAX_VALUE, test.lengthInDays()); assertEquals("-999999999-01-01/+999999999-12-31", test.toString()); } @@ -291,7 +297,7 @@ public void test_ofClosed_MIN_MINP1() { assertEquals(false, test.isEmpty()); assertEquals(true, test.isUnboundedStart()); assertEquals(false, test.isUnboundedEnd()); - assertEquals(2, test.lengthInDays()); + assertEquals(Integer.MAX_VALUE, test.lengthInDays()); assertEquals("-999999999-01-01/-999999999-01-03", test.toString()); } @@ -317,7 +323,7 @@ public void test_ofClosed_MIN_MINP2() { assertEquals(false, test.isEmpty()); assertEquals(true, test.isUnboundedStart()); assertEquals(false, test.isUnboundedEnd()); - assertEquals(3, test.lengthInDays()); + assertEquals(Integer.MAX_VALUE, test.lengthInDays()); assertEquals("-999999999-01-01/-999999999-01-04", test.toString()); } @@ -1145,6 +1151,9 @@ public void test_lengthInDays() { assertEquals(2, LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_29).lengthInDays()); assertEquals(1, LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_29).lengthInDays()); assertEquals(0, LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29).lengthInDays()); + assertEquals(Integer.MAX_VALUE, LocalDateRange.of(LocalDate.MIN, DATE_2012_07_29).lengthInDays()); + assertEquals(Integer.MAX_VALUE, LocalDateRange.of(DATE_2012_07_29, LocalDate.MAX).lengthInDays()); + assertEquals(Integer.MAX_VALUE, LocalDateRange.of(MINP1, MAXM1).lengthInDays()); } @Test @@ -1154,6 +1163,16 @@ public void test_toPeriod() { assertEquals(Period.ofDays(0), LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29).toPeriod()); } + @Test(expected = ArithmeticException.class) + public void test_toPeriod_unbounded_MIN() { + LocalDateRange.of(LocalDate.MIN, DATE_2012_07_29).toPeriod(); + } + + @Test(expected = ArithmeticException.class) + public void test_toPeriod_unbounded_MAX() { + LocalDateRange.of(DATE_2012_07_29, LocalDate.MAX).toPeriod(); + } + //----------------------------------------------------------------------- @Test public void test_equals() { From 76e1e965d5e97b0bba2a56674556e19d73632901 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 19 Aug 2018 16:07:48 +0100 Subject: [PATCH 076/279] Fix website build --- .github/website.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/website.sh b/.github/website.sh index 8ed908db..ffb57f74 100644 --- a/.github/website.sh +++ b/.github/website.sh @@ -6,7 +6,7 @@ cd target echo "## clone..." git clone https://${GITHUB_TOKEN}@github.com/ThreeTen/threeten.github.io.git -cd jodaorg.github.io +cd threeten.github.io git status echo "## copy..." From a6d800842fbcbf9e54ce542f6a59a234251e6db3 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 19 Aug 2018 18:29:40 +0100 Subject: [PATCH 077/279] Fix stream() unbounded edge cases --- .../org/threeten/extra/LocalDateRange.java | 42 ++++++++++++------- .../threeten/extra/TestLocalDateRange.java | 21 ++++++++++ 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/threeten/extra/LocalDateRange.java b/src/main/java/org/threeten/extra/LocalDateRange.java index d3e95832..95526dff 100644 --- a/src/main/java/org/threeten/extra/LocalDateRange.java +++ b/src/main/java/org/threeten/extra/LocalDateRange.java @@ -37,10 +37,11 @@ import java.time.Period; import java.time.format.DateTimeParseException; import java.time.temporal.TemporalAdjuster; -import java.util.Iterator; +import java.util.Comparator; import java.util.Objects; import java.util.Spliterator; import java.util.Spliterators; +import java.util.function.Consumer; import java.util.stream.Stream; import java.util.stream.StreamSupport; @@ -166,7 +167,7 @@ public static LocalDateRange ofClosed(LocalDate startInclusive, LocalDate endInc *

    * The constant {@code LocalDate.MIN} can be used to indicate an unbounded far-past. *

    - * The period must not be zero when the start date is {@code LocalDate.MIN}. + * The period must not be zero or one day when the start date is {@code LocalDate.MIN}. * * @param startInclusive the inclusive start date, not null * @param period the period from the start to the end, not null @@ -596,25 +597,36 @@ public LocalDateRange span(LocalDateRange other) { * @return the stream of dates from the start to the end */ public Stream stream() { - Iterator it = new Iterator() { - private LocalDate current = start; + long count = end.toEpochDay() - start.toEpochDay() + (isUnboundedEnd() ? 2 : 1); + Spliterator spliterator = new Spliterators.AbstractSpliterator( + count, + Spliterator.IMMUTABLE | Spliterator.NONNULL | Spliterator.DISTINCT | Spliterator.ORDERED | + Spliterator.SORTED | Spliterator.SIZED | Spliterator.SUBSIZED) { + private LocalDate current = start; + @Override - public LocalDate next() { - LocalDate result = current; - current = current.plusDays(1); - return result; + public boolean tryAdvance(Consumer action) { + if (current != null) { + if (current.isBefore(end)) { + action.accept(current); + current = current.plusDays(1); + return true; + } + if (current.equals(LocalDate.MAX)) { + current = null; + action.accept(LocalDate.MAX); + return true; + } + } + return false; } - + @Override - public boolean hasNext() { - return current.isBefore(end); + public Comparator getComparator() { + return Comparator.naturalOrder(); } }; - long count = end.toEpochDay() - start.toEpochDay() + 1; - Spliterator spliterator = Spliterators.spliterator(it, count, - Spliterator.IMMUTABLE | Spliterator.NONNULL | Spliterator.DISTINCT | Spliterator.ORDERED | - Spliterator.SORTED | Spliterator.SIZED | Spliterator.SUBSIZED); return StreamSupport.stream(spliterator, false); } diff --git a/src/test/java/org/threeten/extra/TestLocalDateRange.java b/src/test/java/org/threeten/extra/TestLocalDateRange.java index d643a8fd..4381f939 100644 --- a/src/test/java/org/threeten/extra/TestLocalDateRange.java +++ b/src/test/java/org/threeten/extra/TestLocalDateRange.java @@ -68,6 +68,7 @@ public class TestLocalDateRange { private static final LocalDate MINP2 = LocalDate.MIN.plusDays(2); private static final LocalDate MINP3 = LocalDate.MIN.plusDays(3); private static final LocalDate MAXM1 = LocalDate.MAX.minusDays(1); + private static final LocalDate MAXM2 = LocalDate.MAX.minusDays(2); private static final LocalDate DATE_2012_07_01 = LocalDate.of(2012, 7, 1); private static final LocalDate DATE_2012_07_27 = LocalDate.of(2012, 7, 27); private static final LocalDate DATE_2012_07_28 = LocalDate.of(2012, 7, 28); @@ -987,6 +988,26 @@ public void test_stream() { assertEquals(DATE_2012_07_30, result.get(2)); } + @Test + public void test_stream_MIN_MINP3() { + LocalDateRange test = LocalDateRange.of(LocalDate.MIN, MINP3); + List result = test.stream().collect(Collectors.toList()); + assertEquals(3, result.size()); + assertEquals(LocalDate.MIN, result.get(0)); + assertEquals(MINP1, result.get(1)); + assertEquals(MINP2, result.get(2)); + } + + @Test + public void test_stream_MAXM2_MAX() { + LocalDateRange test = LocalDateRange.of(MAXM2, LocalDate.MAX); + List result = test.stream().collect(Collectors.toList()); + assertEquals(3, result.size()); + assertEquals(MAXM2, result.get(0)); + assertEquals(MAXM1, result.get(1)); + assertEquals(LocalDate.MAX, result.get(2)); + } + //----------------------------------------------------------------------- @DataProvider public static Object[][] data_isBefore() { From c1a4d7a1e5acdcfffd7ee1df062def23b7731631 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 19 Aug 2018 18:31:51 +0100 Subject: [PATCH 078/279] Fix off-by-one --- src/main/java/org/threeten/extra/LocalDateRange.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/threeten/extra/LocalDateRange.java b/src/main/java/org/threeten/extra/LocalDateRange.java index 95526dff..13175fed 100644 --- a/src/main/java/org/threeten/extra/LocalDateRange.java +++ b/src/main/java/org/threeten/extra/LocalDateRange.java @@ -597,7 +597,7 @@ public LocalDateRange span(LocalDateRange other) { * @return the stream of dates from the start to the end */ public Stream stream() { - long count = end.toEpochDay() - start.toEpochDay() + (isUnboundedEnd() ? 2 : 1); + long count = end.toEpochDay() - start.toEpochDay() + (isUnboundedEnd() ? 1 : 0); Spliterator spliterator = new Spliterators.AbstractSpliterator( count, Spliterator.IMMUTABLE | Spliterator.NONNULL | Spliterator.DISTINCT | Spliterator.ORDERED | From 087e38f976535583f4ca4c6f3c853785f90372d1 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 20 Aug 2018 10:34:18 +0100 Subject: [PATCH 079/279] Fix spliterator --- src/main/java/org/threeten/extra/LocalDateRange.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/threeten/extra/LocalDateRange.java b/src/main/java/org/threeten/extra/LocalDateRange.java index 13175fed..acef7fbb 100644 --- a/src/main/java/org/threeten/extra/LocalDateRange.java +++ b/src/main/java/org/threeten/extra/LocalDateRange.java @@ -614,8 +614,8 @@ public boolean tryAdvance(Consumer action) { return true; } if (current.equals(LocalDate.MAX)) { - current = null; action.accept(LocalDate.MAX); + current = null; return true; } } @@ -624,7 +624,7 @@ public boolean tryAdvance(Consumer action) { @Override public Comparator getComparator() { - return Comparator.naturalOrder(); + return null; } }; return StreamSupport.stream(spliterator, false); From c6cf37147e9ff5419833af504943fa77587583df Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 20 Aug 2018 14:27:15 +0100 Subject: [PATCH 080/279] Prepare for release v1.4 --- README.md | 2 +- src/changes/changes.xml | 2 +- src/site/markdown/index.md | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2f308981..ce9de077 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Various documentation is available: ### Releases -Release 1.3.2 is the current release. +Release 1.4 is the current release. This release is considered stable and worthy of the 1.x tag. ThreeTen-Extra requires Java SE 8 or later and has no dependencies. diff --git a/src/changes/changes.xml b/src/changes/changes.xml index eb7dcf30..0e31ff1b 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,7 +7,7 @@ - + Enhance LocalDateRange. Add more factory methods for empty and unbounded. diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index c2572903..b98b8341 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -47,7 +47,7 @@ Various documentation is available: ## Releases -Release 1.3.2 is the current release. +Release 1.4 is the current release. This release is considered stable and worthy of the 1.x tag. ThreeTen-Extra requires Java SE 8 or later and has no [dependencies](dependencies.html). @@ -58,7 +58,7 @@ Available in [Maven Central](https://search.maven.org/search?q=g:org.threeten%20 org.threeten threeten-extra - 1.3.2 + 1.4 ``` From 61bb775d7a52c0fabff4563b1c1fabae9737adf6 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 20 Aug 2018 14:33:48 +0100 Subject: [PATCH 081/279] [maven-release-plugin] prepare release v1.4 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e8a1e953..30f566db 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.4-SNAPSHOT + 1.4 Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later http://www.threeten.org/threeten-extra @@ -92,7 +92,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git http://github.com/ThreeTen/threeten-extra - HEAD + v1.4 ThreeTen.org From 42ff68190d8c70fd72cee77cf4dc269446122a32 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 20 Aug 2018 14:33:58 +0100 Subject: [PATCH 082/279] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 30f566db..52cb978d 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.4 + 1.4.1-SNAPSHOT Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later http://www.threeten.org/threeten-extra @@ -92,7 +92,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git http://github.com/ThreeTen/threeten-extra - v1.4 + HEAD ThreeTen.org From bb847793d5ddfbd697f3ffca9ddee4dd26791a3f Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 20 Aug 2018 15:30:13 +0100 Subject: [PATCH 083/279] Switch to HTTPS --- .travis.yml | 1 + README.md | 6 +++--- pom.xml | 14 +++++++------- .../extra/chrono/AccountingChronology.java | 4 ++-- .../org/threeten/extra/chrono/PaxChronology.java | 2 +- .../java/org/threeten/extra/chrono/PaxDate.java | 2 +- .../org/threeten/extra/chrono/Symmetry010Date.java | 4 ++-- .../org/threeten/extra/chrono/Symmetry454Date.java | 4 ++-- src/site/markdown/index.md | 2 +- src/site/site.xml | 7 ++++--- 10 files changed, 24 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7c973a65..2bd495f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ install: - mvn --version script: - mvn install site -e -B + - if [[ $TRAVIS_TAG =~ ^website.*$ ]] && [ "$TRAVIS_JDK_VERSION" == "oraclejdk10" ]; then chmod +x ./.github/website.sh; .github/website.sh; fi - if [[ $TRAVIS_TAG =~ ^v.*$ ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_JDK_VERSION" == "oraclejdk10" ]; then chmod +x ./.github/website.sh; .github/website.sh; fi # secure keys for GITHUB_TOKEN env: diff --git a/README.md b/README.md index ce9de077..836b98d7 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,9 @@ This project provides some of those additional classes as a well-tested and reli ### Documentation Various documentation is available: -* The [home page](http://www.threeten.org/threeten-extra/) -* The [user guide](http://www.threeten.org/threeten-extra/userguide.html) -* The [Javadoc](http://www.threeten.org/threeten-extra/apidocs/index.html) +* The [home page](https://www.threeten.org/threeten-extra/) +* The [user guide](https://www.threeten.org/threeten-extra/userguide.html) +* The [Javadoc](https://www.threeten.org/threeten-extra/apidocs/index.html) ### Releases diff --git a/pom.xml b/pom.xml index 52cb978d..95dff383 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ ThreeTen-Extra 1.4.1-SNAPSHOT Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later - http://www.threeten.org/threeten-extra + https://www.threeten.org/threeten-extra @@ -91,12 +91,12 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git - http://github.com/ThreeTen/threeten-extra + https://github.com/ThreeTen/threeten-extra HEAD ThreeTen.org - http://www.threeten.org + https://www.threeten.org @@ -567,17 +567,17 @@ sonatype-threeten-staging Sonatype OSS staging repository - http://oss.sonatype.org/service/local/staging/deploy/maven2/ + https://oss.sonatype.org/service/local/staging/deploy/maven2/ default false sonatype-threeten-snapshot Sonatype OSS snapshot repository - http://oss.sonatype.org/content/repositories/threeten-snapshots + https://oss.sonatype.org/content/repositories/threeten-snapshots default - http://oss.sonatype.org/content/repositories/threeten-releases + https://oss.sonatype.org/content/repositories/threeten-releases @@ -761,7 +761,7 @@ 1.1.1 Release v${project.version} - See the [change notes](http://www.threeten.org/threeten-extra/changes-report.html) for more information. + See the [change notes](https://www.threeten.org/threeten-extra/changes-report.html) for more information. v${project.version} true diff --git a/src/main/java/org/threeten/extra/chrono/AccountingChronology.java b/src/main/java/org/threeten/extra/chrono/AccountingChronology.java index 7fba51dc..31a56ce6 100644 --- a/src/main/java/org/threeten/extra/chrono/AccountingChronology.java +++ b/src/main/java/org/threeten/extra/chrono/AccountingChronology.java @@ -58,8 +58,8 @@ * An Accounting calendar system. *

    * This chronology defines the rules of a proleptic 52/53-week Accounting calendar system. - * This calendar system follows the rules as laid down in IRS Publication 538 - * and the International Financial Reporting Standards. + * This calendar system follows the rules as laid down in IRS Publication 538 + * and the International Financial Reporting Standards. * The start of the Accounting calendar will vary against the ISO calendar. * Depending on options chosen, it can start as early as {@code 0000-01-26 (ISO)} or as late as {@code 0001-01-04 (ISO)}. *

    diff --git a/src/main/java/org/threeten/extra/chrono/PaxChronology.java b/src/main/java/org/threeten/extra/chrono/PaxChronology.java index 1cc8c479..ea66e8d8 100644 --- a/src/main/java/org/threeten/extra/chrono/PaxChronology.java +++ b/src/main/java/org/threeten/extra/chrono/PaxChronology.java @@ -75,7 +75,7 @@ *

  • leap-year - Leap years occur in every year whose last two digits are divisible by {@code 6}, are {@code 99}, or are {@code 00} and the year is not divisible by 400. * *

    - * For more information, please read the Pax Calendar Wikipedia article. + * For more information, please read the Pax Calendar Wikipedia article. * *

    Implementation Requirements

    * This class is immutable and thread-safe. diff --git a/src/main/java/org/threeten/extra/chrono/PaxDate.java b/src/main/java/org/threeten/extra/chrono/PaxDate.java index 85a6c7f2..aeba69c5 100644 --- a/src/main/java/org/threeten/extra/chrono/PaxDate.java +++ b/src/main/java/org/threeten/extra/chrono/PaxDate.java @@ -72,7 +72,7 @@ * The Pax differs from the Gregorian in terms of month count and length, and the leap year rule. * Dates are aligned such that {@code 0001-01-01 (Pax)} is {@code 0000-12-31 (ISO)}. *

    - * More information is available in the Pax Calendar Wikipedia article. + * More information is available in the Pax Calendar Wikipedia article. * *

    Implementation Requirements

    * This class is immutable and thread-safe. diff --git a/src/main/java/org/threeten/extra/chrono/Symmetry010Date.java b/src/main/java/org/threeten/extra/chrono/Symmetry010Date.java index df1b1417..16a85e25 100644 --- a/src/main/java/org/threeten/extra/chrono/Symmetry010Date.java +++ b/src/main/java/org/threeten/extra/chrono/Symmetry010Date.java @@ -92,8 +92,8 @@ * The 13th day of a month is always a Saturday. *

    * More information is available on Wikipedia at - * Symmetry010 or on the calendar's - * home page. + * Symmetry010 or on the calendar's + * home page. *

    * *

    Implementation Requirements

    diff --git a/src/main/java/org/threeten/extra/chrono/Symmetry454Date.java b/src/main/java/org/threeten/extra/chrono/Symmetry454Date.java index ff6c705a..e4fa1a99 100644 --- a/src/main/java/org/threeten/extra/chrono/Symmetry454Date.java +++ b/src/main/java/org/threeten/extra/chrono/Symmetry454Date.java @@ -91,8 +91,8 @@ * The 13th day of a month is always a Saturday. *

    * More information is available on Wikipedia at - * Symmetry454 or on the calendar's - * home page. + * Symmetry454 or on the calendar's + * home page. *

    * *

    Implementation Requirements

    diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index b98b8341..a80002fe 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -6,7 +6,7 @@ Not every piece of date/time logic is destined for the JDK. Some concepts are too specialized or too bulky to make it in. This project provides some of those additional classes as a well-tested and reliable jar. -It is curated by the primary author of the Java 8 date and time library, [Stephen Colebourne](http://www.joda.org/). +It is curated by the primary author of the Java 8 date and time library, [Stephen Colebourne](https://www.joda.org/). ThreeTen-Extra is licensed under the business-friendly [BSD 3-clause license](license.html). diff --git a/src/site/site.xml b/src/site/site.xml index 6e67f4dc..e3d3784b 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -34,6 +34,7 @@ false false false + true @@ -60,7 +61,7 @@ + ]]> @@ -84,8 +85,8 @@
  • - - + + From 3806476391e554630f88d863911c6d328935ef77 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Fri, 29 Apr 2016 10:02:37 +0100 Subject: [PATCH 084/279] Add period formats Use word files from Joda-Time --- .../org/threeten/extra/AmountFormats.java | 494 ++++++++++++++++++ .../org/threeten/extra/wordbased.properties | 22 + .../threeten/extra/wordbased_cs.properties | 23 + .../threeten/extra/wordbased_da.properties | 22 + .../threeten/extra/wordbased_de.properties | 22 + .../threeten/extra/wordbased_en.properties | 0 .../threeten/extra/wordbased_es.properties | 22 + .../threeten/extra/wordbased_fr.properties | 22 + .../threeten/extra/wordbased_it.properties | 22 + .../threeten/extra/wordbased_ja.properties | 22 + .../threeten/extra/wordbased_nl.properties | 22 + .../threeten/extra/wordbased_pl.properties | 26 + .../threeten/extra/wordbased_pt.properties | 22 + .../threeten/extra/wordbased_ru.properties | 23 + .../threeten/extra/wordbased_tr.properties | 22 + .../org/threeten/extra/TestAmountFormats.java | 85 +++ 16 files changed, 871 insertions(+) create mode 100644 src/main/java/org/threeten/extra/AmountFormats.java create mode 100644 src/main/resources/org/threeten/extra/wordbased.properties create mode 100644 src/main/resources/org/threeten/extra/wordbased_cs.properties create mode 100644 src/main/resources/org/threeten/extra/wordbased_da.properties create mode 100644 src/main/resources/org/threeten/extra/wordbased_de.properties create mode 100644 src/main/resources/org/threeten/extra/wordbased_en.properties create mode 100644 src/main/resources/org/threeten/extra/wordbased_es.properties create mode 100644 src/main/resources/org/threeten/extra/wordbased_fr.properties create mode 100644 src/main/resources/org/threeten/extra/wordbased_it.properties create mode 100644 src/main/resources/org/threeten/extra/wordbased_ja.properties create mode 100644 src/main/resources/org/threeten/extra/wordbased_nl.properties create mode 100644 src/main/resources/org/threeten/extra/wordbased_pl.properties create mode 100644 src/main/resources/org/threeten/extra/wordbased_pt.properties create mode 100644 src/main/resources/org/threeten/extra/wordbased_ru.properties create mode 100644 src/main/resources/org/threeten/extra/wordbased_tr.properties create mode 100644 src/test/java/org/threeten/extra/TestAmountFormats.java diff --git a/src/main/java/org/threeten/extra/AmountFormats.java b/src/main/java/org/threeten/extra/AmountFormats.java new file mode 100644 index 00000000..8c01b1a6 --- /dev/null +++ b/src/main/java/org/threeten/extra/AmountFormats.java @@ -0,0 +1,494 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.extra; + +import java.time.Duration; +import java.time.Period; +import java.time.temporal.TemporalAmount; +import java.util.Locale; +import java.util.Objects; +import java.util.ResourceBundle; + +/** + * Provides the ability to format a temporal amount. + *

    + * This allows a {@link TemporalAmount}, such as {@link Duration} or {@link Period}, + * to be formatted. Only selected formatting options are provided. + * + *

    Implementation Requirements:

    + * This class is immutable and thread-safe. + */ +public final class AmountFormats { + + /** + * The resource bundle name. + */ + private static final String BUNDLE_NAME = "org.threeten.extra.wordbased"; + + //----------------------------------------------------------------------- + /** + * Formats a period and duration to a string in ISO-8601 format. + *

    + * To obtain the ISO-8601 format of a {@code Period} or {@code Duration} + * individually, simply call {@code toString()}. + * See also {@link PeriodDuration}. + * + * @param period the period to format + * @param duration the duration to format + * @return the ISO-8601 format for the period and duration + */ + public static String iso8601(Period period, Duration duration) { + Objects.requireNonNull(period, "period must not be null"); + Objects.requireNonNull(duration, "duration must not be null"); + if (period.isZero()) { + return duration.toString(); + } + if (duration.isZero()) { + return period.toString(); + } + return period.toString() + duration.toString().substring(1); + } + + //------------------------------------------------------------------------- + /** + * Formats a period and duration to a string in a localized word-based format. + *

    + * This calls {@link #wordBased(Period, Locale)} using the {@link Locale#getDefault() default locale}. + * + * @param period the period to format + * @return the localized word-based format for the period and duration + */ + public static String wordBased(Period period) { + Objects.requireNonNull(period, "period must not be null"); + return wordBased(period, Locale.getDefault()); + } + + /** + * Formats a period and duration to a string in a localized word-based format. + *

    + * This returns a word-based format for the period. + * The words are configured in a resource bundle text file - + * {@code org.threeten.extra.wordbased.properties} - with overrides per language. + * + * @param period the period to format + * @param locale the locale to use + * @return the localized word-based format for the period and duration + */ + public static String wordBased(Period period, Locale locale) { + Objects.requireNonNull(period, "period must not be null"); + Objects.requireNonNull(locale, "locale must not be null"); + ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale); + UnitFormat[] formats = { + new UnitFormat(" year", " years"), + new UnitFormat(" month", " months"), + new UnitFormat(" day", " days")}; + WordBased wb = new WordBased(formats, ", ", " and "); + int[] values = {period.getYears(), period.getMonths(), period.getDays()}; + return wb.format(values); + // if (bundle.containsKey("WordBased.regex.separator")) { + // return buildRegExFormatter(bundle, locale); + // } else { + // } + } + + private AmountFormats() { + } + + //------------------------------------------------------------------------- + static final class WordBased { + private final UnitFormat[] units; + private final String separator; + private final String lastSeparator; + + public WordBased(UnitFormat[] units, String separator, String lastSeparator) { + this.units = units; + this.separator = separator; + this.lastSeparator = lastSeparator; + } + + String format(int[] values) { + StringBuilder buf = new StringBuilder(32); + int nonZeroCount = 0; + for (int i = 0; i < values.length; i++) { + if (values[i] != 0) { + nonZeroCount++; + } + } + int count = 0; + for (int i = 0; i < values.length; i++) { + if (values[i] != 0 || (count == 0 && i == values.length - 1)) { + units[i].formatTo(values[i], buf); + if (count < nonZeroCount - 2) { + buf.append(separator); + } else if (count == nonZeroCount - 2) { + buf.append(lastSeparator); + } + count++; + } + } + return buf.toString(); + } + } + + static final class UnitFormat { + private final String single; + private final String plural; + + public UnitFormat(String single, String plural) { + this.single = single; + this.plural = plural; + } + + void formatTo(int value, StringBuilder buf) { + buf.append(value).append(value == 1 ? single : plural); + } + } + + // /** + // * Returns a word based formatter for the specified locale. + // *

    + // * The words are configured in a resource bundle text file - + // * {@code org.joda.time.format.messages}. + // * This can be added to via the normal classpath resource bundle mechanisms. + // *

    + // * You can add your own translation by creating messages_.properties file + // * and adding it to the {@code org.joda.time.format.messages} path. + // *

    + // * Simple example (1 -> singular suffix, not 1 -> plural suffix): + // * + // *

    +    //     * PeriodFormat.space=\ 
    +    //     * PeriodFormat.comma=,
    +    //     * PeriodFormat.commandand=,and 
    +    //     * PeriodFormat.commaspaceand=, and 
    +    //     * PeriodFormat.commaspace=, 
    +    //     * PeriodFormat.spaceandspace=\ and 
    +    //     * PeriodFormat.year=\ year
    +    //     * PeriodFormat.years=\ years
    +    //     * PeriodFormat.month=\ month
    +    //     * PeriodFormat.months=\ months
    +    //     * PeriodFormat.week=\ week
    +    //     * PeriodFormat.weeks=\ weeks
    +    //     * PeriodFormat.day=\ day
    +    //     * PeriodFormat.days=\ days
    +    //     * PeriodFormat.hour=\ hour
    +    //     * PeriodFormat.hours=\ hours
    +    //     * PeriodFormat.minute=\ minute
    +    //     * PeriodFormat.minutes=\ minutes
    +    //     * PeriodFormat.second=\ second
    +    //     * PeriodFormat.seconds=\ seconds
    +    //     * PeriodFormat.millisecond=\ millisecond
    +    //     * PeriodFormat.milliseconds=\ milliseconds
    +    //     * 
    + // * + // *

    + // * Some languages contain more than two suffixes. You can use regular expressions + // * for them. Here's an example using regular expression for English: + // * + // *

    +    //     * PeriodFormat.space=\ 
    +    //     * PeriodFormat.comma=,
    +    //     * PeriodFormat.commandand=,and 
    +    //     * PeriodFormat.commaspaceand=, and 
    +    //     * PeriodFormat.commaspace=, 
    +    //     * PeriodFormat.spaceandspace=\ and 
    +    //     * PeriodFormat.regex.separator=%
    +    //     * PeriodFormat.years.regex=1$%.*
    +    //     * PeriodFormat.years.list=\ year%\ years
    +    //     * PeriodFormat.months.regex=1$%.*
    +    //     * PeriodFormat.months.list=\ month%\ months
    +    //     * PeriodFormat.weeks.regex=1$%.*
    +    //     * PeriodFormat.weeks.list=\ week%\ weeks
    +    //     * PeriodFormat.days.regex=1$%.*
    +    //     * PeriodFormat.days.list=\ day%\ days
    +    //     * PeriodFormat.hours.regex=1$%.*
    +    //     * PeriodFormat.hours.list=\ hour%\ hours
    +    //     * PeriodFormat.minutes.regex=1$%.*
    +    //     * PeriodFormat.minutes.list=\ minute%\ minutes
    +    //     * PeriodFormat.seconds.regex=1$%.*
    +    //     * PeriodFormat.seconds.list=\ second%\ seconds
    +    //     * PeriodFormat.milliseconds.regex=1$%.*
    +    //     * PeriodFormat.milliseconds.list=\ millisecond%\ milliseconds
    +    //     * 
    + // * + // *

    + // * You can mix both approaches. Here's example for Polish ( + // * "1 year, 2 years, 5 years, 12 years, 15 years, 21 years, 22 years, 25 years" + // * translates to + // * "1 rok, 2 lata, 5 lat, 12 lat, 15 lat, 21 lat, 22 lata, 25 lat"). Notice that + // * PeriodFormat.day and PeriodFormat.days is used for day suffixes as there is no + // * need for regular expressions: + // * + // *

    +    //     * PeriodFormat.space=\ 
    +    //     * PeriodFormat.comma=,
    +    //     * PeriodFormat.commandand=,i 
    +    //     * PeriodFormat.commaspaceand=, i 
    +    //     * PeriodFormat.commaspace=, 
    +    //     * PeriodFormat.spaceandspace=\ i 
    +    //     * PeriodFormat.regex.separator=%
    +    //     * PeriodFormat.years.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
    +    //     * PeriodFormat.years.list=\ rok%\ lata%\ lat
    +    //     * PeriodFormat.months.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
    +    //     * PeriodFormat.months.list=\ miesi\u0105c%\ miesi\u0105ce%\ miesi\u0119cy
    +    //     * PeriodFormat.weeks.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
    +    //     * PeriodFormat.weeks.list=\ tydzie\u0144%\ tygodnie%\ tygodni
    +    //     * PeriodFormat.day=\ dzie\u0144
    +    //     * PeriodFormat.days=\ dni
    +    //     * PeriodFormat.hours.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
    +    //     * PeriodFormat.hours.list=\ godzina%\ godziny%\ godzin
    +    //     * PeriodFormat.minutes.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
    +    //     * PeriodFormat.minutes.list=\ minuta%\ minuty%\ minut
    +    //     * PeriodFormat.seconds.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
    +    //     * PeriodFormat.seconds.list=\ sekunda%\ sekundy%\ sekund
    +    //     * PeriodFormat.milliseconds.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
    +    //     * PeriodFormat.milliseconds.list=\ milisekunda%\ milisekundy%\ milisekund
    +    //     * 
    + // * + // *

    + // * Each PeriodFormat.<duration_field_type>.regex property stands for an array of + // * regular expressions and is followed by a property + // * PeriodFormat.<duration_field_type>.list holding an array of suffixes. + // * PeriodFormat.regex.separator is used for splitting. See + // * {@link PeriodFormatterBuilder#appendSuffix(String[], String[])} for details. + // *

    + // * Available languages are English, Danish, Dutch, French, German, Japanese, + // * Polish, Portuguese and Spanish. + // * + // * @return the formatter, not null + // * @since 2.0, regex since 2.5 + // */ + // public static PeriodFormatter wordBased(Locale locale) { + // PeriodFormatter pf = FORMATTERS.get(locale); + // if (pf == null) { + // DynamicWordBased dynamic = new DynamicWordBased(buildWordBased(locale)); + // pf = new PeriodFormatter(dynamic, dynamic, locale, null); + // PeriodFormatter existing = FORMATTERS.putIfAbsent(locale, pf); + // if (existing != null) { + // pf = existing; + // } + // } + // return pf; + // } + // + // //----------------------------------------------------------------------- + // private static PeriodFormatter buildWordBased(Locale locale) { + // ResourceBundle b = ResourceBundle.getBundle(BUNDLE_NAME, locale); + // if (containsKey(b, "PeriodFormat.regex.separator")) { + // return buildRegExFormatter(b, locale); + // } else { + // return buildNonRegExFormatter(b, locale); + // } + // } + // + // private static PeriodFormatter buildRegExFormatter(ResourceBundle b, Locale locale) { + // String[] variants = retrieveVariants(b); + // String regExSeparator = b.getString("PeriodFormat.regex.separator"); + // + // PeriodFormatterBuilder builder = new PeriodFormatterBuilder(); + // builder.appendYears(); + // if (containsKey(b, "PeriodFormat.years.regex")) { + // builder.appendSuffix( + // b.getString("PeriodFormat.years.regex").split(regExSeparator), + // b.getString("PeriodFormat.years.list").split(regExSeparator)); + // } else { + // builder.appendSuffix(b.getString("PeriodFormat.year"), b.getString("PeriodFormat.years")); + // } + // + // builder.appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants); + // builder.appendMonths(); + // if (containsKey(b, "PeriodFormat.months.regex")) { + // builder.appendSuffix( + // b.getString("PeriodFormat.months.regex").split(regExSeparator), + // b.getString("PeriodFormat.months.list").split(regExSeparator)); + // } else { + // builder.appendSuffix(b.getString("PeriodFormat.month"), b.getString("PeriodFormat.months")); + // } + // + // builder.appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants); + // builder.appendWeeks(); + // if (containsKey(b, "PeriodFormat.weeks.regex")) { + // builder.appendSuffix( + // b.getString("PeriodFormat.weeks.regex").split(regExSeparator), + // b.getString("PeriodFormat.weeks.list").split(regExSeparator)); + // } else { + // builder.appendSuffix(b.getString("PeriodFormat.week"), b.getString("PeriodFormat.weeks")); + // } + // + // builder.appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants); + // builder.appendDays(); + // if (containsKey(b, "PeriodFormat.days.regex")) { + // builder.appendSuffix( + // b.getString("PeriodFormat.days.regex").split(regExSeparator), + // b.getString("PeriodFormat.days.list").split(regExSeparator)); + // } else { + // builder.appendSuffix(b.getString("PeriodFormat.day"), b.getString("PeriodFormat.days")); + // } + // + // builder.appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants); + // builder.appendHours(); + // if (containsKey(b, "PeriodFormat.hours.regex")) { + // builder.appendSuffix( + // b.getString("PeriodFormat.hours.regex").split(regExSeparator), + // b.getString("PeriodFormat.hours.list").split(regExSeparator)); + // } else { + // builder.appendSuffix(b.getString("PeriodFormat.hour"), b.getString("PeriodFormat.hours")); + // } + // + // builder.appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants); + // builder.appendMinutes(); + // if (containsKey(b, "PeriodFormat.minutes.regex")) { + // builder.appendSuffix( + // b.getString("PeriodFormat.minutes.regex").split(regExSeparator), + // b.getString("PeriodFormat.minutes.list").split(regExSeparator)); + // } else { + // builder.appendSuffix(b.getString("PeriodFormat.minute"), b.getString("PeriodFormat.minutes")); + // } + // + // builder.appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants); + // builder.appendSeconds(); + // if (containsKey(b, "PeriodFormat.seconds.regex")) { + // builder.appendSuffix( + // b.getString("PeriodFormat.seconds.regex").split(regExSeparator), + // b.getString("PeriodFormat.seconds.list").split(regExSeparator)); + // } else { + // builder.appendSuffix(b.getString("PeriodFormat.second"), b.getString("PeriodFormat.seconds")); + // } + // + // builder.appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants); + // builder.appendMillis(); + // if (containsKey(b, "PeriodFormat.milliseconds.regex")) { + // builder.appendSuffix( + // b.getString("PeriodFormat.milliseconds.regex").split(regExSeparator), + // b.getString("PeriodFormat.milliseconds.list").split(regExSeparator)); + // } else { + // builder.appendSuffix(b.getString("PeriodFormat.millisecond"), b.getString("PeriodFormat.milliseconds")); + // } + // return builder.toFormatter().withLocale(locale); + // } + // + // private static PeriodFormatter buildNonRegExFormatter(ResourceBundle b, Locale locale) { + // String[] variants = retrieveVariants(b); + // return new PeriodFormatterBuilder() + // .appendYears() + // .appendSuffix(b.getString("PeriodFormat.year"), b.getString("PeriodFormat.years")) + // .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) + // .appendMonths() + // .appendSuffix(b.getString("PeriodFormat.month"), b.getString("PeriodFormat.months")) + // .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) + // .appendWeeks() + // .appendSuffix(b.getString("PeriodFormat.week"), b.getString("PeriodFormat.weeks")) + // .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) + // .appendDays() + // .appendSuffix(b.getString("PeriodFormat.day"), b.getString("PeriodFormat.days")) + // .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) + // .appendHours() + // .appendSuffix(b.getString("PeriodFormat.hour"), b.getString("PeriodFormat.hours")) + // .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) + // .appendMinutes() + // .appendSuffix(b.getString("PeriodFormat.minute"), b.getString("PeriodFormat.minutes")) + // .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) + // .appendSeconds() + // .appendSuffix(b.getString("PeriodFormat.second"), b.getString("PeriodFormat.seconds")) + // .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) + // .appendMillis() + // .appendSuffix(b.getString("PeriodFormat.millisecond"), b.getString("PeriodFormat.milliseconds")) + // .toFormatter().withLocale(locale); + // } + // + // private static String[] retrieveVariants(ResourceBundle b) { + // return new String[] { b.getString("PeriodFormat.space"), b.getString("PeriodFormat.comma"), + // b.getString("PeriodFormat.commandand"), b.getString("PeriodFormat.commaspaceand") }; + // } + // + // // simulate ResourceBundle.containsKey() + // private static boolean containsKey(ResourceBundle bundle, String key) { + // for (Enumeration en = bundle.getKeys(); en.hasMoreElements(); ) { + // if (en.nextElement().equals(key)) { + // return true; + // } + // } + // return false; + // } + // + // //----------------------------------------------------------------------- + // /** + // * Printer/parser that reacts to the locale and changes the word-based + // * pattern if necessary. + // */ + // static class DynamicWordBased + // implements PeriodPrinter, PeriodParser { + // + // /** The formatter with the locale selected at construction time. */ + // private final PeriodFormatter iFormatter; + // + // DynamicWordBased(PeriodFormatter formatter) { + // iFormatter = formatter; + // } + // + // public int countFieldsToPrint(ReadablePeriod period, int stopAt, Locale locale) { + // return getPrinter(locale).countFieldsToPrint(period, stopAt, locale); + // } + // + // public int calculatePrintedLength(ReadablePeriod period, Locale locale) { + // return getPrinter(locale).calculatePrintedLength(period, locale); + // } + // + // public void printTo(StringBuffer buf, ReadablePeriod period, Locale locale) { + // getPrinter(locale).printTo(buf, period, locale); + // } + // + // public void printTo(Writer out, ReadablePeriod period, Locale locale) throws IOException { + // getPrinter(locale).printTo(out, period, locale); + // } + // + // private PeriodPrinter getPrinter(Locale locale) { + // if (locale != null && !locale.equals(iFormatter.getLocale())) { + // return wordBased(locale).getPrinter(); + // } + // return iFormatter.getPrinter(); + // } + // + // public int parseInto( + // ReadWritablePeriod period, String periodStr, + // int position, Locale locale) { + // return getParser(locale).parseInto(period, periodStr, position, locale); + // } + // + // private PeriodParser getParser(Locale locale) { + // if (locale != null && !locale.equals(iFormatter.getLocale())) { + // return wordBased(locale).getParser(); + // } + // return iFormatter.getParser(); + // } + // } +} diff --git a/src/main/resources/org/threeten/extra/wordbased.properties b/src/main/resources/org/threeten/extra/wordbased.properties new file mode 100644 index 00000000..bc4624c1 --- /dev/null +++ b/src/main/resources/org/threeten/extra/wordbased.properties @@ -0,0 +1,22 @@ +WordBased.space=\ +WordBased.comma=, +WordBased.commandand=,and +WordBased.commaspaceand=, and +WordBased.commaspace=, +WordBased.spaceandspace=\ and +WordBased.year=\ year +WordBased.years=\ years +WordBased.month=\ month +WordBased.months=\ months +WordBased.week=\ week +WordBased.weeks=\ weeks +WordBased.day=\ day +WordBased.days=\ days +WordBased.hour=\ hour +WordBased.hours=\ hours +WordBased.minute=\ minute +WordBased.minutes=\ minutes +WordBased.second=\ second +WordBased.seconds=\ seconds +WordBased.millisecond=\ millisecond +WordBased.milliseconds=\ milliseconds diff --git a/src/main/resources/org/threeten/extra/wordbased_cs.properties b/src/main/resources/org/threeten/extra/wordbased_cs.properties new file mode 100644 index 00000000..548d03f3 --- /dev/null +++ b/src/main/resources/org/threeten/extra/wordbased_cs.properties @@ -0,0 +1,23 @@ +WordBased.space=\ +WordBased.comma=, +WordBased.commandand=,a +WordBased.commaspaceand=, a +WordBased.commaspace=, +WordBased.spaceandspace=\ a +WordBased.regex.separator=% +WordBased.years.regex=^1$%[0-9]*(? Date: Thu, 15 Nov 2018 11:04:09 +0000 Subject: [PATCH 085/279] Add properties key in period format method, add duration format method --- .../org/threeten/extra/AmountFormats.java | 91 ++++++++++++++++++- .../org/threeten/extra/TestAmountFormats.java | 23 +++++ 2 files changed, 110 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/threeten/extra/AmountFormats.java b/src/main/java/org/threeten/extra/AmountFormats.java index 8c01b1a6..9a75461b 100644 --- a/src/main/java/org/threeten/extra/AmountFormats.java +++ b/src/main/java/org/threeten/extra/AmountFormats.java @@ -54,6 +54,66 @@ public final class AmountFormats { */ private static final String BUNDLE_NAME = "org.threeten.extra.wordbased"; + /** + * the property file key for the separator ", " + */ + private static final String WORDBASED_COMMASPACE = "WordBased.commaspace"; + + /** + * the property file key for the separator " and " + */ + private static final String WORDBASED_SPACEANDSPACE = "WordBased.spaceandspace"; + + /** + * the property file key for the word "year" + */ + private static final String WORDBASED_YEAR = "WordBased.year"; + + /** + * the property file key for the word "years" + */ + private static final String WORDBASED_YEARS = "WordBased.years"; + + /** + * the property file key for the word "month" + */ + private static final String WORDBASED_MONTH = "WordBased.month"; + + /** + * the property file key for the word "months" + */ + private static final String WORDBASED_MONTHS = "WordBased.months"; + + /** + * the property file key for the word "day" + */ + private static final String WORDBASED_DAY = "WordBased.day"; + + /** + * the property file key for the word "days" + */ + private static final String WORDBASED_DAYS = "WordBased.days"; + + /** + * the property file key for the word "second" + */ + private static final String WORDBASED_SECOND = "WordBased.second"; + + /** + * the property file key for the word "seconds" + */ + private static final String WORDBASED_SECONDS = "WordBased.seconds"; + + /** + * the property file key for the word "millisecond" + */ + private static final String WORDBASED_MILLISECOND = "WordBased.millisecond"; + + /** + * the property file key for the word "milliseconds" + */ + private static final String WORDBASED_MILLISECONDS = "WordBased.milliseconds"; + //----------------------------------------------------------------------- /** * Formats a period and duration to a string in ISO-8601 format. @@ -108,10 +168,10 @@ public static String wordBased(Period period, Locale locale) { Objects.requireNonNull(locale, "locale must not be null"); ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale); UnitFormat[] formats = { - new UnitFormat(" year", " years"), - new UnitFormat(" month", " months"), - new UnitFormat(" day", " days")}; - WordBased wb = new WordBased(formats, ", ", " and "); + new UnitFormat(bundle.getString(WORDBASED_YEAR), bundle.getString(WORDBASED_YEARS)), + new UnitFormat(bundle.getString(WORDBASED_MONTH), bundle.getString(WORDBASED_MONTHS)), + new UnitFormat(bundle.getString(WORDBASED_DAY), bundle.getString(WORDBASED_DAYS))}; + WordBased wb = new WordBased(formats, WORDBASED_COMMASPACE, WORDBASED_SPACEANDSPACE); int[] values = {period.getYears(), period.getMonths(), period.getDays()}; return wb.format(values); // if (bundle.containsKey("WordBased.regex.separator")) { @@ -120,6 +180,29 @@ public static String wordBased(Period period, Locale locale) { // } } + /** + * Formats a duration to a string in a localized word-based format. + *

    + * This returns a word-based format for the duration. + * The words are configured in a resource bundle text file - + * {@code org.threeten.extra.wordbased.properties} - with overrides per language. + * + * @param duration the duration to format + * @param locale the locale to use + * @return the localized word-based format for the duration + */ + public static String wordBased(Duration duration, Locale locale) { + Objects.requireNonNull(duration, "duration must not be null"); + Objects.requireNonNull(locale, "locale must not be null"); + ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale); + UnitFormat[] formats = { + new UnitFormat(bundle.getString(WORDBASED_SECOND), bundle.getString(WORDBASED_SECONDS)), + new UnitFormat(bundle.getString(WORDBASED_MILLISECOND), bundle.getString(WORDBASED_MILLISECONDS))}; + WordBased wb = new WordBased(formats, WORDBASED_COMMASPACE, WORDBASED_SPACEANDSPACE); + int[] values = {(int)duration.getSeconds()}; + return wb.format(values); + } + private AmountFormats() { } diff --git a/src/test/java/org/threeten/extra/TestAmountFormats.java b/src/test/java/org/threeten/extra/TestAmountFormats.java index 7efd8238..ec6ab5f8 100644 --- a/src/test/java/org/threeten/extra/TestAmountFormats.java +++ b/src/test/java/org/threeten/extra/TestAmountFormats.java @@ -68,6 +68,14 @@ public static Object[][] data_wordBased() { {Period.ofYears(12), Locale.ROOT, "12 years"}, {Period.ofYears(-1), Locale.ROOT, "-1 years"}, + {Period.ofWeeks(0), Locale.ENGLISH, "0 days"}, + {Period.ofWeeks(1), Locale.ENGLISH, "7 days"}, + {Period.ofWeeks(4), Locale.ENGLISH, "28 days"}, + + {Period.ofMonths(0), Locale.ENGLISH, "0 days"}, + {Period.ofMonths(1), Locale.ENGLISH, "1 month"}, + {Period.ofMonths(4), Locale.ENGLISH, "4 months"}, + {Period.ofYears(0), Locale.ENGLISH, "0 days"}, {Period.ofYears(1), Locale.ENGLISH, "1 year"}, {Period.ofYears(2), Locale.ENGLISH, "2 years"}, @@ -82,4 +90,19 @@ public void test_wordBased(Period period, Locale locale, String expected) { assertEquals(AmountFormats.wordBased(period, locale), expected); } + @DataProvider + public static Object[][] duration_wordBased() { + return new Object[][] { + + {Duration.ofSeconds(100), Locale.ENGLISH, "100 seconds"}, + {Duration.ofMillis(1_000), Locale.ENGLISH, "1 second"}, + {Duration.ofMillis(3_000), Locale.ENGLISH, "3 seconds"}, + }; + } + + @Test + @UseDataProvider("duration_wordBased") + public void test_wordBased(Duration duration, Locale locale, String expected) { + assertEquals(AmountFormats.wordBased(duration, locale), expected); + } } From e90ff6692fb91ba10ae2c65acadf2a39d790b680 Mon Sep 17 00:00:00 2001 From: monicagg Date: Wed, 21 Nov 2018 15:07:49 +0000 Subject: [PATCH 086/279] First version for duration format --- .../org/threeten/extra/AmountFormats.java | 52 ++++++++++++++++--- .../org/threeten/extra/TestAmountFormats.java | 5 +- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/threeten/extra/AmountFormats.java b/src/main/java/org/threeten/extra/AmountFormats.java index 9a75461b..3e2c1b5a 100644 --- a/src/main/java/org/threeten/extra/AmountFormats.java +++ b/src/main/java/org/threeten/extra/AmountFormats.java @@ -49,11 +49,26 @@ */ public final class AmountFormats { + /** + * The number of minutes per hour. + */ + private static final int MINUTES_PER_HOUR = 60; + + /** + * The number of seconds per minute. + */ + private static final int SECONDS_PER_MINUTE = 60; + /** * The resource bundle name. */ private static final String BUNDLE_NAME = "org.threeten.extra.wordbased"; - + + /** + * the property file key for the separator " " + */ + private static final String WORDBASED_SPACE = "WordBased.space"; + /** * the property file key for the separator ", " */ @@ -94,6 +109,26 @@ public final class AmountFormats { */ private static final String WORDBASED_DAYS = "WordBased.days"; + /** + * the property file key for the word "hour" + */ + private static final String WORDBASED_HOUR = "WordBased.hour"; + + /** + * the property file key for the word "hours" + */ + private static final String WORDBASED_HOURS = "WordBased.hours"; + + /** + * the property file key for the word "minute" + */ + private static final String WORDBASED_MINUTE = "WordBased.minute"; + + /** + * the property file key for the word "minutes" + */ + private static final String WORDBASED_MINUTES = "WordBased.minutes"; + /** * the property file key for the word "second" */ @@ -171,7 +206,7 @@ public static String wordBased(Period period, Locale locale) { new UnitFormat(bundle.getString(WORDBASED_YEAR), bundle.getString(WORDBASED_YEARS)), new UnitFormat(bundle.getString(WORDBASED_MONTH), bundle.getString(WORDBASED_MONTHS)), new UnitFormat(bundle.getString(WORDBASED_DAY), bundle.getString(WORDBASED_DAYS))}; - WordBased wb = new WordBased(formats, WORDBASED_COMMASPACE, WORDBASED_SPACEANDSPACE); + WordBased wb = new WordBased(formats, bundle.getString(WORDBASED_COMMASPACE), bundle.getString(WORDBASED_SPACEANDSPACE)); int[] values = {period.getYears(), period.getMonths(), period.getDays()}; return wb.format(values); // if (bundle.containsKey("WordBased.regex.separator")) { @@ -195,11 +230,16 @@ public static String wordBased(Duration duration, Locale locale) { Objects.requireNonNull(duration, "duration must not be null"); Objects.requireNonNull(locale, "locale must not be null"); ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale); + UnitFormat[] formats = { - new UnitFormat(bundle.getString(WORDBASED_SECOND), bundle.getString(WORDBASED_SECONDS)), - new UnitFormat(bundle.getString(WORDBASED_MILLISECOND), bundle.getString(WORDBASED_MILLISECONDS))}; - WordBased wb = new WordBased(formats, WORDBASED_COMMASPACE, WORDBASED_SPACEANDSPACE); - int[] values = {(int)duration.getSeconds()}; + new UnitFormat(bundle.getString(WORDBASED_HOUR), bundle.getString(WORDBASED_HOURS)), + new UnitFormat(bundle.getString(WORDBASED_MINUTE), bundle.getString(WORDBASED_MINUTES)), + new UnitFormat(bundle.getString(WORDBASED_SECOND), bundle.getString(WORDBASED_SECONDS)) }; + WordBased wb = new WordBased(formats, bundle.getString(WORDBASED_SPACE), bundle.getString(WORDBASED_SPACE)); + long hours = duration.toHours()<0?0:duration.toHours(); + long mins = duration.toMinutes() % MINUTES_PER_HOUR; + long secs = duration.getSeconds() % SECONDS_PER_MINUTE; + int[] values = {(int)hours, (int)mins, (int)secs}; return wb.format(values); } diff --git a/src/test/java/org/threeten/extra/TestAmountFormats.java b/src/test/java/org/threeten/extra/TestAmountFormats.java index ec6ab5f8..20e79fda 100644 --- a/src/test/java/org/threeten/extra/TestAmountFormats.java +++ b/src/test/java/org/threeten/extra/TestAmountFormats.java @@ -93,8 +93,9 @@ public void test_wordBased(Period period, Locale locale, String expected) { @DataProvider public static Object[][] duration_wordBased() { return new Object[][] { - - {Duration.ofSeconds(100), Locale.ENGLISH, "100 seconds"}, + {Duration.ofMinutes(180 + 2), Locale.ENGLISH, "3 hours 2 minutes"}, + {Duration.ofSeconds(180), Locale.ENGLISH, "3 minutes"}, + {Duration.ofSeconds(100), Locale.ENGLISH, "1 minute 40 seconds"}, {Duration.ofMillis(1_000), Locale.ENGLISH, "1 second"}, {Duration.ofMillis(3_000), Locale.ENGLISH, "3 seconds"}, }; From b061c83e107ae234682b6536829e476f8bc788d0 Mon Sep 17 00:00:00 2001 From: monicagg Date: Wed, 21 Nov 2018 15:23:02 +0000 Subject: [PATCH 087/279] Add few more test cases. Add singular for a value equal with -1 --- src/main/java/org/threeten/extra/AmountFormats.java | 5 +++-- src/test/java/org/threeten/extra/TestAmountFormats.java | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/threeten/extra/AmountFormats.java b/src/main/java/org/threeten/extra/AmountFormats.java index 3e2c1b5a..1e5bfd23 100644 --- a/src/main/java/org/threeten/extra/AmountFormats.java +++ b/src/main/java/org/threeten/extra/AmountFormats.java @@ -207,7 +207,8 @@ public static String wordBased(Period period, Locale locale) { new UnitFormat(bundle.getString(WORDBASED_MONTH), bundle.getString(WORDBASED_MONTHS)), new UnitFormat(bundle.getString(WORDBASED_DAY), bundle.getString(WORDBASED_DAYS))}; WordBased wb = new WordBased(formats, bundle.getString(WORDBASED_COMMASPACE), bundle.getString(WORDBASED_SPACEANDSPACE)); - int[] values = {period.getYears(), period.getMonths(), period.getDays()}; + Period normPeriod = period.normalized(); + int[] values = {normPeriod.getYears(), normPeriod.getMonths(), normPeriod.getDays()}; return wb.format(values); // if (bundle.containsKey("WordBased.regex.separator")) { // return buildRegExFormatter(bundle, locale); @@ -292,7 +293,7 @@ public UnitFormat(String single, String plural) { } void formatTo(int value, StringBuilder buf) { - buf.append(value).append(value == 1 ? single : plural); + buf.append(value).append(value == 1 || value == -1 ? single : plural); } } diff --git a/src/test/java/org/threeten/extra/TestAmountFormats.java b/src/test/java/org/threeten/extra/TestAmountFormats.java index 20e79fda..f63aafcd 100644 --- a/src/test/java/org/threeten/extra/TestAmountFormats.java +++ b/src/test/java/org/threeten/extra/TestAmountFormats.java @@ -66,7 +66,7 @@ public static Object[][] data_wordBased() { {Period.ofYears(1), Locale.ROOT, "1 year"}, {Period.ofYears(2), Locale.ROOT, "2 years"}, {Period.ofYears(12), Locale.ROOT, "12 years"}, - {Period.ofYears(-1), Locale.ROOT, "-1 years"}, + {Period.ofYears(-1), Locale.ROOT, "-1 year"}, {Period.ofWeeks(0), Locale.ENGLISH, "0 days"}, {Period.ofWeeks(1), Locale.ENGLISH, "7 days"}, @@ -75,12 +75,13 @@ public static Object[][] data_wordBased() { {Period.ofMonths(0), Locale.ENGLISH, "0 days"}, {Period.ofMonths(1), Locale.ENGLISH, "1 month"}, {Period.ofMonths(4), Locale.ENGLISH, "4 months"}, + {Period.ofMonths(14), Locale.ENGLISH, "1 year and 2 months"}, {Period.ofYears(0), Locale.ENGLISH, "0 days"}, {Period.ofYears(1), Locale.ENGLISH, "1 year"}, {Period.ofYears(2), Locale.ENGLISH, "2 years"}, {Period.ofYears(12), Locale.ENGLISH, "12 years"}, - {Period.ofYears(-1), Locale.ENGLISH, "-1 years"}, + {Period.ofYears(-1), Locale.ENGLISH, "-1 year"}, }; } @@ -96,6 +97,9 @@ public static Object[][] duration_wordBased() { {Duration.ofMinutes(180 + 2), Locale.ENGLISH, "3 hours 2 minutes"}, {Duration.ofSeconds(180), Locale.ENGLISH, "3 minutes"}, {Duration.ofSeconds(100), Locale.ENGLISH, "1 minute 40 seconds"}, + {Duration.ofSeconds(-140), Locale.ENGLISH, "-2 minutes -20 seconds"}, + {Duration.ofSeconds(-90), Locale.ENGLISH, "-1 minute -30 seconds"}, + {Duration.ofSeconds(-40), Locale.ENGLISH, "-40 seconds"}, {Duration.ofMillis(1_000), Locale.ENGLISH, "1 second"}, {Duration.ofMillis(3_000), Locale.ENGLISH, "3 seconds"}, }; From 7e4a3eceb0e02470b6cd3b1119ea050028feac86 Mon Sep 17 00:00:00 2001 From: monicagg Date: Wed, 21 Nov 2018 15:32:50 +0000 Subject: [PATCH 088/279] Solve the negative value for hours in duration format --- src/main/java/org/threeten/extra/AmountFormats.java | 2 +- src/test/java/org/threeten/extra/TestAmountFormats.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/threeten/extra/AmountFormats.java b/src/main/java/org/threeten/extra/AmountFormats.java index 1e5bfd23..a084bb56 100644 --- a/src/main/java/org/threeten/extra/AmountFormats.java +++ b/src/main/java/org/threeten/extra/AmountFormats.java @@ -237,7 +237,7 @@ public static String wordBased(Duration duration, Locale locale) { new UnitFormat(bundle.getString(WORDBASED_MINUTE), bundle.getString(WORDBASED_MINUTES)), new UnitFormat(bundle.getString(WORDBASED_SECOND), bundle.getString(WORDBASED_SECONDS)) }; WordBased wb = new WordBased(formats, bundle.getString(WORDBASED_SPACE), bundle.getString(WORDBASED_SPACE)); - long hours = duration.toHours()<0?0:duration.toHours(); + long hours = duration.toHours(); long mins = duration.toMinutes() % MINUTES_PER_HOUR; long secs = duration.getSeconds() % SECONDS_PER_MINUTE; int[] values = {(int)hours, (int)mins, (int)secs}; diff --git a/src/test/java/org/threeten/extra/TestAmountFormats.java b/src/test/java/org/threeten/extra/TestAmountFormats.java index f63aafcd..e4dd02b6 100644 --- a/src/test/java/org/threeten/extra/TestAmountFormats.java +++ b/src/test/java/org/threeten/extra/TestAmountFormats.java @@ -95,6 +95,7 @@ public void test_wordBased(Period period, Locale locale, String expected) { public static Object[][] duration_wordBased() { return new Object[][] { {Duration.ofMinutes(180 + 2), Locale.ENGLISH, "3 hours 2 minutes"}, + {Duration.ofMinutes(-60 - 40), Locale.ENGLISH, "-1 hour -40 minutes"}, {Duration.ofSeconds(180), Locale.ENGLISH, "3 minutes"}, {Duration.ofSeconds(100), Locale.ENGLISH, "1 minute 40 seconds"}, {Duration.ofSeconds(-140), Locale.ENGLISH, "-2 minutes -20 seconds"}, From a095fdc29c0c452ce26aa8eb3cbc712ed1a2e511 Mon Sep 17 00:00:00 2001 From: monicagg Date: Tue, 27 Nov 2018 17:55:23 +0000 Subject: [PATCH 089/279] Finish format for period and duration with all units. Add Romanian wordbased file --- .../org/threeten/extra/AmountFormats.java | 37 +++++++++++++--- .../threeten/extra/wordbased_ro.properties | 22 ++++++++++ .../org/threeten/extra/TestAmountFormats.java | 44 ++++++++++++++----- 3 files changed, 85 insertions(+), 18 deletions(-) create mode 100644 src/main/resources/org/threeten/extra/wordbased_ro.properties diff --git a/src/main/java/org/threeten/extra/AmountFormats.java b/src/main/java/org/threeten/extra/AmountFormats.java index a084bb56..9a1a65dc 100644 --- a/src/main/java/org/threeten/extra/AmountFormats.java +++ b/src/main/java/org/threeten/extra/AmountFormats.java @@ -49,16 +49,22 @@ */ public final class AmountFormats { + /** + * The number of days per week. + */ + private static final int DAYS_PER_WEEK = 7; /** * The number of minutes per hour. */ private static final int MINUTES_PER_HOUR = 60; - /** * The number of seconds per minute. */ private static final int SECONDS_PER_MINUTE = 60; - + /** + * The number of nanosecond per millisecond. + */ + private static final int NANOS_PER_MILLIS = 1000_000; /** * The resource bundle name. */ @@ -99,6 +105,16 @@ public final class AmountFormats { */ private static final String WORDBASED_MONTHS = "WordBased.months"; + /** + * the property file key for the word "week" + */ + private static final String WORDBASED_WEEK = "WordBased.week"; + + /** + * the property file key for the word "weeks" + */ + private static final String WORDBASED_WEEKS = "WordBased.weeks"; + /** * the property file key for the word "day" */ @@ -205,10 +221,17 @@ public static String wordBased(Period period, Locale locale) { UnitFormat[] formats = { new UnitFormat(bundle.getString(WORDBASED_YEAR), bundle.getString(WORDBASED_YEARS)), new UnitFormat(bundle.getString(WORDBASED_MONTH), bundle.getString(WORDBASED_MONTHS)), + new UnitFormat(bundle.getString(WORDBASED_WEEK), bundle.getString(WORDBASED_WEEKS)), new UnitFormat(bundle.getString(WORDBASED_DAY), bundle.getString(WORDBASED_DAYS))}; WordBased wb = new WordBased(formats, bundle.getString(WORDBASED_COMMASPACE), bundle.getString(WORDBASED_SPACEANDSPACE)); Period normPeriod = period.normalized(); - int[] values = {normPeriod.getYears(), normPeriod.getMonths(), normPeriod.getDays()}; + int weeks = 0, days = 0; + if (normPeriod.getDays() % DAYS_PER_WEEK == 0) { + weeks = normPeriod.getDays() / DAYS_PER_WEEK; + } else { + days = normPeriod.getDays(); + } + int[] values = {normPeriod.getYears(), normPeriod.getMonths(), weeks, days}; return wb.format(values); // if (bundle.containsKey("WordBased.regex.separator")) { // return buildRegExFormatter(bundle, locale); @@ -235,12 +258,14 @@ public static String wordBased(Duration duration, Locale locale) { UnitFormat[] formats = { new UnitFormat(bundle.getString(WORDBASED_HOUR), bundle.getString(WORDBASED_HOURS)), new UnitFormat(bundle.getString(WORDBASED_MINUTE), bundle.getString(WORDBASED_MINUTES)), - new UnitFormat(bundle.getString(WORDBASED_SECOND), bundle.getString(WORDBASED_SECONDS)) }; - WordBased wb = new WordBased(formats, bundle.getString(WORDBASED_SPACE), bundle.getString(WORDBASED_SPACE)); + new UnitFormat(bundle.getString(WORDBASED_SECOND), bundle.getString(WORDBASED_SECONDS)), + new UnitFormat(bundle.getString(WORDBASED_MILLISECOND), bundle.getString(WORDBASED_MILLISECONDS))}; + WordBased wb = new WordBased(formats, bundle.getString(WORDBASED_SPACE), bundle.getString(WORDBASED_SPACEANDSPACE)); long hours = duration.toHours(); long mins = duration.toMinutes() % MINUTES_PER_HOUR; long secs = duration.getSeconds() % SECONDS_PER_MINUTE; - int[] values = {(int)hours, (int)mins, (int)secs}; + int millis = duration.getNano() / NANOS_PER_MILLIS; + int[] values = {(int)hours, (int)mins, (int)secs, millis}; return wb.format(values); } diff --git a/src/main/resources/org/threeten/extra/wordbased_ro.properties b/src/main/resources/org/threeten/extra/wordbased_ro.properties new file mode 100644 index 00000000..e9d96576 --- /dev/null +++ b/src/main/resources/org/threeten/extra/wordbased_ro.properties @@ -0,0 +1,22 @@ +WordBased.space=\ +WordBased.comma=, +WordBased.commandand=,\u0219i +WordBased.commaspaceand=, \u0219i +WordBased.commaspace=, +WordBased.spaceandspace=\ \u0219i +WordBased.year=\ an +WordBased.years=\ ani +WordBased.month=\ lun\u0103 +WordBased.months=\ luni +WordBased.week=\ s\u0103pt\u0103m\u00E2n\u0103 +WordBased.weeks=\ s\u0103pt\u0103m\u00E2ni +WordBased.day=\ zi +WordBased.days=\ zile +WordBased.hour=\ or\u0103 +WordBased.hours=\ ore +WordBased.minute=\ minut +WordBased.minutes=\ minute +WordBased.second=\ secund\u0103 +WordBased.seconds=\ secunde +WordBased.millisecond=\ milisecund\u0103 +WordBased.milliseconds=\ milisecunde diff --git a/src/test/java/org/threeten/extra/TestAmountFormats.java b/src/test/java/org/threeten/extra/TestAmountFormats.java index e4dd02b6..9c8e0e99 100644 --- a/src/test/java/org/threeten/extra/TestAmountFormats.java +++ b/src/test/java/org/threeten/extra/TestAmountFormats.java @@ -69,19 +69,29 @@ public static Object[][] data_wordBased() { {Period.ofYears(-1), Locale.ROOT, "-1 year"}, {Period.ofWeeks(0), Locale.ENGLISH, "0 days"}, - {Period.ofWeeks(1), Locale.ENGLISH, "7 days"}, - {Period.ofWeeks(4), Locale.ENGLISH, "28 days"}, + {Period.ofWeeks(1), Locale.ENGLISH, "1 week"}, + {Period.ofWeeks(4), Locale.ENGLISH, "4 weeks"}, {Period.ofMonths(0), Locale.ENGLISH, "0 days"}, {Period.ofMonths(1), Locale.ENGLISH, "1 month"}, {Period.ofMonths(4), Locale.ENGLISH, "4 months"}, {Period.ofMonths(14), Locale.ENGLISH, "1 year and 2 months"}, - {Period.ofYears(0), Locale.ENGLISH, "0 days"}, - {Period.ofYears(1), Locale.ENGLISH, "1 year"}, - {Period.ofYears(2), Locale.ENGLISH, "2 years"}, - {Period.ofYears(12), Locale.ENGLISH, "12 years"}, - {Period.ofYears(-1), Locale.ENGLISH, "-1 year"}, + {Period.ofDays(1), Locale.ENGLISH, "1 day"}, + {Period.ofDays(2), Locale.ENGLISH, "2 days"}, + {Period.ofDays(5), Locale.ENGLISH, "5 days"}, + {Period.ofDays(7), Locale.ENGLISH, "1 week"}, + {Period.ofDays(-1), Locale.ENGLISH, "-1 day"}, + + + {Period.ofDays(1), new Locale("ro"), "1 zi"}, + {Period.ofDays(2), new Locale("ro"), "2 zile"}, + {Period.ofDays(5), new Locale("ro"), "5 zile"}, + {Period.ofDays(7), new Locale("ro"), "1 săptămână"}, + {Period.ofWeeks(3), new Locale("ro"), "3 săptămâni"}, + {Period.ofMonths(14), new Locale("ro"), "1 an și 2 luni"}, + {Period.ofMonths(1), new Locale("ro"), "1 lună"}, + {Period.ofYears(2), new Locale("ro"), "2 ani"}, }; } @@ -94,15 +104,25 @@ public void test_wordBased(Period period, Locale locale, String expected) { @DataProvider public static Object[][] duration_wordBased() { return new Object[][] { - {Duration.ofMinutes(180 + 2), Locale.ENGLISH, "3 hours 2 minutes"}, - {Duration.ofMinutes(-60 - 40), Locale.ENGLISH, "-1 hour -40 minutes"}, + {Duration.ofMinutes(180 + 2), Locale.ENGLISH, "3 hours and 2 minutes"}, + {Duration.ofMinutes(-60 - 40), Locale.ENGLISH, "-1 hour and -40 minutes"}, {Duration.ofSeconds(180), Locale.ENGLISH, "3 minutes"}, - {Duration.ofSeconds(100), Locale.ENGLISH, "1 minute 40 seconds"}, - {Duration.ofSeconds(-140), Locale.ENGLISH, "-2 minutes -20 seconds"}, - {Duration.ofSeconds(-90), Locale.ENGLISH, "-1 minute -30 seconds"}, + {Duration.ofSeconds(100), Locale.ENGLISH, "1 minute and 40 seconds"}, + {Duration.ofSeconds(-140), Locale.ENGLISH, "-2 minutes and -20 seconds"}, + {Duration.ofSeconds(-90), Locale.ENGLISH, "-1 minute and -30 seconds"}, {Duration.ofSeconds(-40), Locale.ENGLISH, "-40 seconds"}, {Duration.ofMillis(1_000), Locale.ENGLISH, "1 second"}, {Duration.ofMillis(3_000), Locale.ENGLISH, "3 seconds"}, + {Duration.ofNanos(1_000_000), Locale.ENGLISH, "1 millisecond"}, + {Duration.ofNanos(1000_000_000 + 2_000_000), Locale.ENGLISH, "1 second and 2 milliseconds"}, + + {Duration.ofMinutes(60 + 1), new Locale("ro"), "1 oră și 1 minut"}, + {Duration.ofMinutes(180 + 2), new Locale("ro"), "3 ore și 2 minute"}, + {Duration.ofMinutes(-60 - 40), new Locale("ro"), "-1 oră și -40 minute"}, + {Duration.ofSeconds(-90), new Locale("ro"), "-1 minut și -30 secunde"}, + {Duration.ofNanos(1_000_000), new Locale("ro"), "1 milisecundă"}, + {Duration.ofNanos(1000_000_000 + 2_000_000), new Locale("ro"), "1 secundă și 2 milisecunde"}, + }; } From 13fdaf251fbc21df53b2b5a9c7f822ebe6cc63d1 Mon Sep 17 00:00:00 2001 From: monicagg Date: Thu, 29 Nov 2018 12:52:06 +0000 Subject: [PATCH 090/279] Add format method for both times interval, period and duration. --- .../org/threeten/extra/AmountFormats.java | 44 +++++++++++++++---- .../org/threeten/extra/TestAmountFormats.java | 23 ++++++++++ 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/threeten/extra/AmountFormats.java b/src/main/java/org/threeten/extra/AmountFormats.java index 9a1a65dc..b516c7aa 100644 --- a/src/main/java/org/threeten/extra/AmountFormats.java +++ b/src/main/java/org/threeten/extra/AmountFormats.java @@ -49,11 +49,11 @@ */ public final class AmountFormats { - /** + /** * The number of days per week. */ private static final int DAYS_PER_WEEK = 7; - /** + /** * The number of minutes per hour. */ private static final int MINUTES_PER_HOUR = 60; @@ -227,9 +227,9 @@ public static String wordBased(Period period, Locale locale) { Period normPeriod = period.normalized(); int weeks = 0, days = 0; if (normPeriod.getDays() % DAYS_PER_WEEK == 0) { - weeks = normPeriod.getDays() / DAYS_PER_WEEK; + weeks = normPeriod.getDays() / DAYS_PER_WEEK; } else { - days = normPeriod.getDays(); + days = normPeriod.getDays(); } int[] values = {normPeriod.getYears(), normPeriod.getMonths(), weeks, days}; return wb.format(values); @@ -256,19 +256,45 @@ public static String wordBased(Duration duration, Locale locale) { ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale); UnitFormat[] formats = { - new UnitFormat(bundle.getString(WORDBASED_HOUR), bundle.getString(WORDBASED_HOURS)), - new UnitFormat(bundle.getString(WORDBASED_MINUTE), bundle.getString(WORDBASED_MINUTES)), - new UnitFormat(bundle.getString(WORDBASED_SECOND), bundle.getString(WORDBASED_SECONDS)), - new UnitFormat(bundle.getString(WORDBASED_MILLISECOND), bundle.getString(WORDBASED_MILLISECONDS))}; + new UnitFormat(bundle.getString(WORDBASED_HOUR), bundle.getString(WORDBASED_HOURS)), + new UnitFormat(bundle.getString(WORDBASED_MINUTE), bundle.getString(WORDBASED_MINUTES)), + new UnitFormat(bundle.getString(WORDBASED_SECOND), bundle.getString(WORDBASED_SECONDS)), + new UnitFormat(bundle.getString(WORDBASED_MILLISECOND), bundle.getString(WORDBASED_MILLISECONDS))}; WordBased wb = new WordBased(formats, bundle.getString(WORDBASED_SPACE), bundle.getString(WORDBASED_SPACEANDSPACE)); long hours = duration.toHours(); long mins = duration.toMinutes() % MINUTES_PER_HOUR; long secs = duration.getSeconds() % SECONDS_PER_MINUTE; int millis = duration.getNano() / NANOS_PER_MILLIS; - int[] values = {(int)hours, (int)mins, (int)secs, millis}; + int[] values = {(int) hours, (int) mins, (int) secs, millis}; return wb.format(values); } + /** + * Formats a period and duration to a string in a localized word-based format. + *

    + * This returns a word-based format for the period. + * The words are configured in a resource bundle text file - + * {@code org.threeten.extra.wordbased.properties} - with overrides per language. + * + * @param period the period to format + * @param duration the duration to format + * @param locale the locale to use + * @return the localized word-based format for the period and duration + */ + public static String wordBased(Period period, Duration duration, Locale locale) { + Objects.requireNonNull(period, "period must not be null"); + Objects.requireNonNull(duration, "duration must not be null"); + Objects.requireNonNull(locale, "locale must not be null"); + if (period.isZero()) { + return wordBased(duration, locale); + } + if (duration.isZero()) { + return wordBased(period, locale); + } + ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale); + return wordBased(period, locale) + bundle.getString(WORDBASED_SPACE) + wordBased(duration, locale); + } + private AmountFormats() { } diff --git a/src/test/java/org/threeten/extra/TestAmountFormats.java b/src/test/java/org/threeten/extra/TestAmountFormats.java index 9c8e0e99..49fe5049 100644 --- a/src/test/java/org/threeten/extra/TestAmountFormats.java +++ b/src/test/java/org/threeten/extra/TestAmountFormats.java @@ -131,4 +131,27 @@ public static Object[][] duration_wordBased() { public void test_wordBased(Duration duration, Locale locale, String expected) { assertEquals(AmountFormats.wordBased(duration, locale), expected); } + + @DataProvider + public static Object[][] period_duration_wordBased() { + return new Object[][] { + {Period.ofDays(1), Duration.ofMinutes(180 + 2), Locale.ROOT, "1 day 3 hours and 2 minutes"}, + {Period.ofDays(2), Duration.ofSeconds(180), Locale.ROOT, "2 days 3 minutes"}, + {Period.ofDays(7), Duration.ofMinutes(80), Locale.ROOT, "1 week 1 hour and 20 minutes"}, + {Period.ZERO, Duration.ofMillis(1_000), Locale.ROOT, "1 second"}, + + {Period.ofMonths(0), Duration.ofSeconds(0), Locale.ENGLISH, "0 milliseconds"}, + {Period.ofMonths(0), Duration.ofHours(9), Locale.ENGLISH, "9 hours"}, + {Period.ofMonths(1), Duration.ZERO, Locale.ENGLISH, "1 month"}, + {Period.ofMonths(4), Duration.ZERO, Locale.ENGLISH, "4 months"}, + {Period.of(1, 2, 5), Duration.ofHours(4), Locale.ENGLISH, "1 year, 2 months and 5 days 4 hours"} + }; + } + + @Test + @UseDataProvider("period_duration_wordBased") + public void test_wordBased(Period period, Duration duration, Locale locale, String expected) { + assertEquals(AmountFormats.wordBased(period, duration, locale), expected); + } + } From c034e6e7c66536552fe540a4bd44edd6ae819167 Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Sun, 9 Dec 2018 15:24:56 +0000 Subject: [PATCH 091/279] Fix CI now Java 11 is out --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2bd495f9..685a3d61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ sudo: false language: java jdk: - - oraclejdk10 + - openjdk11 - oraclejdk9 - oraclejdk8 cache: @@ -13,8 +13,8 @@ install: - mvn --version script: - mvn install site -e -B - - if [[ $TRAVIS_TAG =~ ^website.*$ ]] && [ "$TRAVIS_JDK_VERSION" == "oraclejdk10" ]; then chmod +x ./.github/website.sh; .github/website.sh; fi - - if [[ $TRAVIS_TAG =~ ^v.*$ ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_JDK_VERSION" == "oraclejdk10" ]; then chmod +x ./.github/website.sh; .github/website.sh; fi + - if [[ $TRAVIS_TAG =~ ^website.*$ ]] && [ "$TRAVIS_JDK_VERSION" == "openjdk11" ]; then chmod +x ./.github/website.sh; .github/website.sh; fi + - if [[ $TRAVIS_TAG =~ ^v.*$ ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_JDK_VERSION" == "openjdk11" ]; then chmod +x ./.github/website.sh; .github/website.sh; fi # secure keys for GITHUB_TOKEN env: global: From fa46e55511a8db609acbae9db308b2e1139518a8 Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Sun, 9 Dec 2018 15:53:07 +0000 Subject: [PATCH 092/279] Update plugins for Java 11 --- pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 95dff383..2123fab8 100644 --- a/pom.xml +++ b/pom.xml @@ -798,7 +798,7 @@ 3.1.0 - 2.5.4 + 4.1.0 2.12.1 2.17 @@ -820,11 +820,11 @@ 3.1.0 3.7.1 3.0.1 - 2.22.0 - 2.22.0 + 2.22.1 + 2.22.1 1.1 - 3.5.0 - 0.8.1 + 4.1.0 + 0.8.2 1.6.8 3.1.6 From 33ce201a1ca5b08eb853f523007731820a465f2e Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Sun, 9 Dec 2018 16:02:34 +0000 Subject: [PATCH 093/279] Update plugins for Java 11 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2123fab8..6049956c 100644 --- a/pom.xml +++ b/pom.xml @@ -826,7 +826,7 @@ 4.1.0 0.8.2 1.6.8 - 3.1.6 + 3.1.9 1.8 1.8 From 18091697cc547dbdd819ea9bee0df15386f9b357 Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Sun, 9 Dec 2018 20:15:48 +0000 Subject: [PATCH 094/279] Checkstyle/formatting tweaks --- .../org/threeten/extra/AmountFormats.java | 43 ++++++------------- .../org/threeten/extra/TestAmountFormats.java | 27 ++++++------ 2 files changed, 25 insertions(+), 45 deletions(-) diff --git a/src/main/java/org/threeten/extra/AmountFormats.java b/src/main/java/org/threeten/extra/AmountFormats.java index b516c7aa..6d5a1849 100644 --- a/src/main/java/org/threeten/extra/AmountFormats.java +++ b/src/main/java/org/threeten/extra/AmountFormats.java @@ -69,102 +69,83 @@ public final class AmountFormats { * The resource bundle name. */ private static final String BUNDLE_NAME = "org.threeten.extra.wordbased"; - /** * the property file key for the separator " " */ private static final String WORDBASED_SPACE = "WordBased.space"; - /** * the property file key for the separator ", " */ private static final String WORDBASED_COMMASPACE = "WordBased.commaspace"; - /** * the property file key for the separator " and " */ private static final String WORDBASED_SPACEANDSPACE = "WordBased.spaceandspace"; - /** * the property file key for the word "year" */ private static final String WORDBASED_YEAR = "WordBased.year"; - /** * the property file key for the word "years" */ private static final String WORDBASED_YEARS = "WordBased.years"; - /** * the property file key for the word "month" */ private static final String WORDBASED_MONTH = "WordBased.month"; - /** * the property file key for the word "months" */ private static final String WORDBASED_MONTHS = "WordBased.months"; - /** * the property file key for the word "week" */ private static final String WORDBASED_WEEK = "WordBased.week"; - /** * the property file key for the word "weeks" */ private static final String WORDBASED_WEEKS = "WordBased.weeks"; - /** * the property file key for the word "day" */ private static final String WORDBASED_DAY = "WordBased.day"; - /** * the property file key for the word "days" */ private static final String WORDBASED_DAYS = "WordBased.days"; - /** * the property file key for the word "hour" */ private static final String WORDBASED_HOUR = "WordBased.hour"; - /** * the property file key for the word "hours" */ private static final String WORDBASED_HOURS = "WordBased.hours"; - /** * the property file key for the word "minute" */ - private static final String WORDBASED_MINUTE = "WordBased.minute"; - + private static final String WORDBASED_MINUTE = "WordBased.minute"; /** * the property file key for the word "minutes" */ - private static final String WORDBASED_MINUTES = "WordBased.minutes"; - + private static final String WORDBASED_MINUTES = "WordBased.minutes"; /** * the property file key for the word "second" */ private static final String WORDBASED_SECOND = "WordBased.second"; - /** * the property file key for the word "seconds" */ private static final String WORDBASED_SECONDS = "WordBased.seconds"; - /** * the property file key for the word "millisecond" */ private static final String WORDBASED_MILLISECOND = "WordBased.millisecond"; - /** * the property file key for the word "milliseconds" */ private static final String WORDBASED_MILLISECONDS = "WordBased.milliseconds"; - + //----------------------------------------------------------------------- /** * Formats a period and duration to a string in ISO-8601 format. @@ -227,9 +208,9 @@ public static String wordBased(Period period, Locale locale) { Period normPeriod = period.normalized(); int weeks = 0, days = 0; if (normPeriod.getDays() % DAYS_PER_WEEK == 0) { - weeks = normPeriod.getDays() / DAYS_PER_WEEK; + weeks = normPeriod.getDays() / DAYS_PER_WEEK; } else { - days = normPeriod.getDays(); + days = normPeriod.getDays(); } int[] values = {normPeriod.getYears(), normPeriod.getMonths(), weeks, days}; return wb.format(values); @@ -254,12 +235,12 @@ public static String wordBased(Duration duration, Locale locale) { Objects.requireNonNull(duration, "duration must not be null"); Objects.requireNonNull(locale, "locale must not be null"); ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale); - + UnitFormat[] formats = { - new UnitFormat(bundle.getString(WORDBASED_HOUR), bundle.getString(WORDBASED_HOURS)), - new UnitFormat(bundle.getString(WORDBASED_MINUTE), bundle.getString(WORDBASED_MINUTES)), - new UnitFormat(bundle.getString(WORDBASED_SECOND), bundle.getString(WORDBASED_SECONDS)), - new UnitFormat(bundle.getString(WORDBASED_MILLISECOND), bundle.getString(WORDBASED_MILLISECONDS))}; + new UnitFormat(bundle.getString(WORDBASED_HOUR), bundle.getString(WORDBASED_HOURS)), + new UnitFormat(bundle.getString(WORDBASED_MINUTE), bundle.getString(WORDBASED_MINUTES)), + new UnitFormat(bundle.getString(WORDBASED_SECOND), bundle.getString(WORDBASED_SECONDS)), + new UnitFormat(bundle.getString(WORDBASED_MILLISECOND), bundle.getString(WORDBASED_MILLISECONDS))}; WordBased wb = new WordBased(formats, bundle.getString(WORDBASED_SPACE), bundle.getString(WORDBASED_SPACEANDSPACE)); long hours = duration.toHours(); long mins = duration.toMinutes() % MINUTES_PER_HOUR; @@ -268,7 +249,7 @@ public static String wordBased(Duration duration, Locale locale) { int[] values = {(int) hours, (int) mins, (int) secs, millis}; return wb.format(values); } - + /** * Formats a period and duration to a string in a localized word-based format. *

    @@ -294,7 +275,7 @@ public static String wordBased(Period period, Duration duration, Locale locale) ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale); return wordBased(period, locale) + bundle.getString(WORDBASED_SPACE) + wordBased(duration, locale); } - + private AmountFormats() { } diff --git a/src/test/java/org/threeten/extra/TestAmountFormats.java b/src/test/java/org/threeten/extra/TestAmountFormats.java index 49fe5049..23918871 100644 --- a/src/test/java/org/threeten/extra/TestAmountFormats.java +++ b/src/test/java/org/threeten/extra/TestAmountFormats.java @@ -71,19 +71,18 @@ public static Object[][] data_wordBased() { {Period.ofWeeks(0), Locale.ENGLISH, "0 days"}, {Period.ofWeeks(1), Locale.ENGLISH, "1 week"}, {Period.ofWeeks(4), Locale.ENGLISH, "4 weeks"}, - + {Period.ofMonths(0), Locale.ENGLISH, "0 days"}, {Period.ofMonths(1), Locale.ENGLISH, "1 month"}, {Period.ofMonths(4), Locale.ENGLISH, "4 months"}, {Period.ofMonths(14), Locale.ENGLISH, "1 year and 2 months"}, - + {Period.ofDays(1), Locale.ENGLISH, "1 day"}, {Period.ofDays(2), Locale.ENGLISH, "2 days"}, {Period.ofDays(5), Locale.ENGLISH, "5 days"}, {Period.ofDays(7), Locale.ENGLISH, "1 week"}, {Period.ofDays(-1), Locale.ENGLISH, "-1 day"}, - - + {Period.ofDays(1), new Locale("ro"), "1 zi"}, {Period.ofDays(2), new Locale("ro"), "2 zile"}, {Period.ofDays(5), new Locale("ro"), "5 zile"}, @@ -104,9 +103,9 @@ public void test_wordBased(Period period, Locale locale, String expected) { @DataProvider public static Object[][] duration_wordBased() { return new Object[][] { - {Duration.ofMinutes(180 + 2), Locale.ENGLISH, "3 hours and 2 minutes"}, - {Duration.ofMinutes(-60 - 40), Locale.ENGLISH, "-1 hour and -40 minutes"}, - {Duration.ofSeconds(180), Locale.ENGLISH, "3 minutes"}, + {Duration.ofMinutes(180 + 2), Locale.ENGLISH, "3 hours and 2 minutes"}, + {Duration.ofMinutes(-60 - 40), Locale.ENGLISH, "-1 hour and -40 minutes"}, + {Duration.ofSeconds(180), Locale.ENGLISH, "3 minutes"}, {Duration.ofSeconds(100), Locale.ENGLISH, "1 minute and 40 seconds"}, {Duration.ofSeconds(-140), Locale.ENGLISH, "-2 minutes and -20 seconds"}, {Duration.ofSeconds(-90), Locale.ENGLISH, "-1 minute and -30 seconds"}, @@ -115,23 +114,23 @@ public static Object[][] duration_wordBased() { {Duration.ofMillis(3_000), Locale.ENGLISH, "3 seconds"}, {Duration.ofNanos(1_000_000), Locale.ENGLISH, "1 millisecond"}, {Duration.ofNanos(1000_000_000 + 2_000_000), Locale.ENGLISH, "1 second and 2 milliseconds"}, - + {Duration.ofMinutes(60 + 1), new Locale("ro"), "1 oră și 1 minut"}, {Duration.ofMinutes(180 + 2), new Locale("ro"), "3 ore și 2 minute"}, - {Duration.ofMinutes(-60 - 40), new Locale("ro"), "-1 oră și -40 minute"}, - {Duration.ofSeconds(-90), new Locale("ro"), "-1 minut și -30 secunde"}, + {Duration.ofMinutes(-60 - 40), new Locale("ro"), "-1 oră și -40 minute"}, + {Duration.ofSeconds(-90), new Locale("ro"), "-1 minut și -30 secunde"}, {Duration.ofNanos(1_000_000), new Locale("ro"), "1 milisecundă"}, {Duration.ofNanos(1000_000_000 + 2_000_000), new Locale("ro"), "1 secundă și 2 milisecunde"}, }; } - + @Test @UseDataProvider("duration_wordBased") public void test_wordBased(Duration duration, Locale locale, String expected) { assertEquals(AmountFormats.wordBased(duration, locale), expected); } - + @DataProvider public static Object[][] period_duration_wordBased() { return new Object[][] { @@ -147,11 +146,11 @@ public static Object[][] period_duration_wordBased() { {Period.of(1, 2, 5), Duration.ofHours(4), Locale.ENGLISH, "1 year, 2 months and 5 days 4 hours"} }; } - + @Test @UseDataProvider("period_duration_wordBased") public void test_wordBased(Period period, Duration duration, Locale locale, String expected) { assertEquals(AmountFormats.wordBased(period, duration, locale), expected); } - + } From a7416cbca1cb8b68ad6ff267608c07bc48981b45 Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Sun, 9 Dec 2018 20:15:05 +0000 Subject: [PATCH 095/279] Tidy period formatting --- .../org/threeten/extra/AmountFormats.java | 341 +----------------- 1 file changed, 4 insertions(+), 337 deletions(-) diff --git a/src/main/java/org/threeten/extra/AmountFormats.java b/src/main/java/org/threeten/extra/AmountFormats.java index 6d5a1849..3bc8845e 100644 --- a/src/main/java/org/threeten/extra/AmountFormats.java +++ b/src/main/java/org/threeten/extra/AmountFormats.java @@ -172,20 +172,7 @@ public static String iso8601(Period period, Duration duration) { //------------------------------------------------------------------------- /** - * Formats a period and duration to a string in a localized word-based format. - *

    - * This calls {@link #wordBased(Period, Locale)} using the {@link Locale#getDefault() default locale}. - * - * @param period the period to format - * @return the localized word-based format for the period and duration - */ - public static String wordBased(Period period) { - Objects.requireNonNull(period, "period must not be null"); - return wordBased(period, Locale.getDefault()); - } - - /** - * Formats a period and duration to a string in a localized word-based format. + * Formats a period to a string in a localized word-based format. *

    * This returns a word-based format for the period. * The words are configured in a resource bundle text file - @@ -193,7 +180,7 @@ public static String wordBased(Period period) { * * @param period the period to format * @param locale the locale to use - * @return the localized word-based format for the period and duration + * @return the localized word-based format for the period */ public static String wordBased(Period period, Locale locale) { Objects.requireNonNull(period, "period must not be null"); @@ -214,10 +201,6 @@ public static String wordBased(Period period, Locale locale) { } int[] values = {normPeriod.getYears(), normPeriod.getMonths(), weeks, days}; return wb.format(values); - // if (bundle.containsKey("WordBased.regex.separator")) { - // return buildRegExFormatter(bundle, locale); - // } else { - // } } /** @@ -280,6 +263,7 @@ private AmountFormats() { } //------------------------------------------------------------------------- + // data holder for word-based formats static final class WordBased { private final UnitFormat[] units; private final String separator; @@ -315,6 +299,7 @@ String format(int[] values) { } } + // data holder for single/plural formats static final class UnitFormat { private final String single; private final String plural; @@ -329,322 +314,4 @@ void formatTo(int value, StringBuilder buf) { } } - // /** - // * Returns a word based formatter for the specified locale. - // *

    - // * The words are configured in a resource bundle text file - - // * {@code org.joda.time.format.messages}. - // * This can be added to via the normal classpath resource bundle mechanisms. - // *

    - // * You can add your own translation by creating messages_.properties file - // * and adding it to the {@code org.joda.time.format.messages} path. - // *

    - // * Simple example (1 -> singular suffix, not 1 -> plural suffix): - // * - // *

    -    //     * PeriodFormat.space=\ 
    -    //     * PeriodFormat.comma=,
    -    //     * PeriodFormat.commandand=,and 
    -    //     * PeriodFormat.commaspaceand=, and 
    -    //     * PeriodFormat.commaspace=, 
    -    //     * PeriodFormat.spaceandspace=\ and 
    -    //     * PeriodFormat.year=\ year
    -    //     * PeriodFormat.years=\ years
    -    //     * PeriodFormat.month=\ month
    -    //     * PeriodFormat.months=\ months
    -    //     * PeriodFormat.week=\ week
    -    //     * PeriodFormat.weeks=\ weeks
    -    //     * PeriodFormat.day=\ day
    -    //     * PeriodFormat.days=\ days
    -    //     * PeriodFormat.hour=\ hour
    -    //     * PeriodFormat.hours=\ hours
    -    //     * PeriodFormat.minute=\ minute
    -    //     * PeriodFormat.minutes=\ minutes
    -    //     * PeriodFormat.second=\ second
    -    //     * PeriodFormat.seconds=\ seconds
    -    //     * PeriodFormat.millisecond=\ millisecond
    -    //     * PeriodFormat.milliseconds=\ milliseconds
    -    //     * 
    - // * - // *

    - // * Some languages contain more than two suffixes. You can use regular expressions - // * for them. Here's an example using regular expression for English: - // * - // *

    -    //     * PeriodFormat.space=\ 
    -    //     * PeriodFormat.comma=,
    -    //     * PeriodFormat.commandand=,and 
    -    //     * PeriodFormat.commaspaceand=, and 
    -    //     * PeriodFormat.commaspace=, 
    -    //     * PeriodFormat.spaceandspace=\ and 
    -    //     * PeriodFormat.regex.separator=%
    -    //     * PeriodFormat.years.regex=1$%.*
    -    //     * PeriodFormat.years.list=\ year%\ years
    -    //     * PeriodFormat.months.regex=1$%.*
    -    //     * PeriodFormat.months.list=\ month%\ months
    -    //     * PeriodFormat.weeks.regex=1$%.*
    -    //     * PeriodFormat.weeks.list=\ week%\ weeks
    -    //     * PeriodFormat.days.regex=1$%.*
    -    //     * PeriodFormat.days.list=\ day%\ days
    -    //     * PeriodFormat.hours.regex=1$%.*
    -    //     * PeriodFormat.hours.list=\ hour%\ hours
    -    //     * PeriodFormat.minutes.regex=1$%.*
    -    //     * PeriodFormat.minutes.list=\ minute%\ minutes
    -    //     * PeriodFormat.seconds.regex=1$%.*
    -    //     * PeriodFormat.seconds.list=\ second%\ seconds
    -    //     * PeriodFormat.milliseconds.regex=1$%.*
    -    //     * PeriodFormat.milliseconds.list=\ millisecond%\ milliseconds
    -    //     * 
    - // * - // *

    - // * You can mix both approaches. Here's example for Polish ( - // * "1 year, 2 years, 5 years, 12 years, 15 years, 21 years, 22 years, 25 years" - // * translates to - // * "1 rok, 2 lata, 5 lat, 12 lat, 15 lat, 21 lat, 22 lata, 25 lat"). Notice that - // * PeriodFormat.day and PeriodFormat.days is used for day suffixes as there is no - // * need for regular expressions: - // * - // *

    -    //     * PeriodFormat.space=\ 
    -    //     * PeriodFormat.comma=,
    -    //     * PeriodFormat.commandand=,i 
    -    //     * PeriodFormat.commaspaceand=, i 
    -    //     * PeriodFormat.commaspace=, 
    -    //     * PeriodFormat.spaceandspace=\ i 
    -    //     * PeriodFormat.regex.separator=%
    -    //     * PeriodFormat.years.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
    -    //     * PeriodFormat.years.list=\ rok%\ lata%\ lat
    -    //     * PeriodFormat.months.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
    -    //     * PeriodFormat.months.list=\ miesi\u0105c%\ miesi\u0105ce%\ miesi\u0119cy
    -    //     * PeriodFormat.weeks.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
    -    //     * PeriodFormat.weeks.list=\ tydzie\u0144%\ tygodnie%\ tygodni
    -    //     * PeriodFormat.day=\ dzie\u0144
    -    //     * PeriodFormat.days=\ dni
    -    //     * PeriodFormat.hours.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
    -    //     * PeriodFormat.hours.list=\ godzina%\ godziny%\ godzin
    -    //     * PeriodFormat.minutes.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
    -    //     * PeriodFormat.minutes.list=\ minuta%\ minuty%\ minut
    -    //     * PeriodFormat.seconds.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
    -    //     * PeriodFormat.seconds.list=\ sekunda%\ sekundy%\ sekund
    -    //     * PeriodFormat.milliseconds.regex=^1$%[0-9]*(?<!1)[2-4]$%[0-9]*
    -    //     * PeriodFormat.milliseconds.list=\ milisekunda%\ milisekundy%\ milisekund
    -    //     * 
    - // * - // *

    - // * Each PeriodFormat.<duration_field_type>.regex property stands for an array of - // * regular expressions and is followed by a property - // * PeriodFormat.<duration_field_type>.list holding an array of suffixes. - // * PeriodFormat.regex.separator is used for splitting. See - // * {@link PeriodFormatterBuilder#appendSuffix(String[], String[])} for details. - // *

    - // * Available languages are English, Danish, Dutch, French, German, Japanese, - // * Polish, Portuguese and Spanish. - // * - // * @return the formatter, not null - // * @since 2.0, regex since 2.5 - // */ - // public static PeriodFormatter wordBased(Locale locale) { - // PeriodFormatter pf = FORMATTERS.get(locale); - // if (pf == null) { - // DynamicWordBased dynamic = new DynamicWordBased(buildWordBased(locale)); - // pf = new PeriodFormatter(dynamic, dynamic, locale, null); - // PeriodFormatter existing = FORMATTERS.putIfAbsent(locale, pf); - // if (existing != null) { - // pf = existing; - // } - // } - // return pf; - // } - // - // //----------------------------------------------------------------------- - // private static PeriodFormatter buildWordBased(Locale locale) { - // ResourceBundle b = ResourceBundle.getBundle(BUNDLE_NAME, locale); - // if (containsKey(b, "PeriodFormat.regex.separator")) { - // return buildRegExFormatter(b, locale); - // } else { - // return buildNonRegExFormatter(b, locale); - // } - // } - // - // private static PeriodFormatter buildRegExFormatter(ResourceBundle b, Locale locale) { - // String[] variants = retrieveVariants(b); - // String regExSeparator = b.getString("PeriodFormat.regex.separator"); - // - // PeriodFormatterBuilder builder = new PeriodFormatterBuilder(); - // builder.appendYears(); - // if (containsKey(b, "PeriodFormat.years.regex")) { - // builder.appendSuffix( - // b.getString("PeriodFormat.years.regex").split(regExSeparator), - // b.getString("PeriodFormat.years.list").split(regExSeparator)); - // } else { - // builder.appendSuffix(b.getString("PeriodFormat.year"), b.getString("PeriodFormat.years")); - // } - // - // builder.appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants); - // builder.appendMonths(); - // if (containsKey(b, "PeriodFormat.months.regex")) { - // builder.appendSuffix( - // b.getString("PeriodFormat.months.regex").split(regExSeparator), - // b.getString("PeriodFormat.months.list").split(regExSeparator)); - // } else { - // builder.appendSuffix(b.getString("PeriodFormat.month"), b.getString("PeriodFormat.months")); - // } - // - // builder.appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants); - // builder.appendWeeks(); - // if (containsKey(b, "PeriodFormat.weeks.regex")) { - // builder.appendSuffix( - // b.getString("PeriodFormat.weeks.regex").split(regExSeparator), - // b.getString("PeriodFormat.weeks.list").split(regExSeparator)); - // } else { - // builder.appendSuffix(b.getString("PeriodFormat.week"), b.getString("PeriodFormat.weeks")); - // } - // - // builder.appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants); - // builder.appendDays(); - // if (containsKey(b, "PeriodFormat.days.regex")) { - // builder.appendSuffix( - // b.getString("PeriodFormat.days.regex").split(regExSeparator), - // b.getString("PeriodFormat.days.list").split(regExSeparator)); - // } else { - // builder.appendSuffix(b.getString("PeriodFormat.day"), b.getString("PeriodFormat.days")); - // } - // - // builder.appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants); - // builder.appendHours(); - // if (containsKey(b, "PeriodFormat.hours.regex")) { - // builder.appendSuffix( - // b.getString("PeriodFormat.hours.regex").split(regExSeparator), - // b.getString("PeriodFormat.hours.list").split(regExSeparator)); - // } else { - // builder.appendSuffix(b.getString("PeriodFormat.hour"), b.getString("PeriodFormat.hours")); - // } - // - // builder.appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants); - // builder.appendMinutes(); - // if (containsKey(b, "PeriodFormat.minutes.regex")) { - // builder.appendSuffix( - // b.getString("PeriodFormat.minutes.regex").split(regExSeparator), - // b.getString("PeriodFormat.minutes.list").split(regExSeparator)); - // } else { - // builder.appendSuffix(b.getString("PeriodFormat.minute"), b.getString("PeriodFormat.minutes")); - // } - // - // builder.appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants); - // builder.appendSeconds(); - // if (containsKey(b, "PeriodFormat.seconds.regex")) { - // builder.appendSuffix( - // b.getString("PeriodFormat.seconds.regex").split(regExSeparator), - // b.getString("PeriodFormat.seconds.list").split(regExSeparator)); - // } else { - // builder.appendSuffix(b.getString("PeriodFormat.second"), b.getString("PeriodFormat.seconds")); - // } - // - // builder.appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants); - // builder.appendMillis(); - // if (containsKey(b, "PeriodFormat.milliseconds.regex")) { - // builder.appendSuffix( - // b.getString("PeriodFormat.milliseconds.regex").split(regExSeparator), - // b.getString("PeriodFormat.milliseconds.list").split(regExSeparator)); - // } else { - // builder.appendSuffix(b.getString("PeriodFormat.millisecond"), b.getString("PeriodFormat.milliseconds")); - // } - // return builder.toFormatter().withLocale(locale); - // } - // - // private static PeriodFormatter buildNonRegExFormatter(ResourceBundle b, Locale locale) { - // String[] variants = retrieveVariants(b); - // return new PeriodFormatterBuilder() - // .appendYears() - // .appendSuffix(b.getString("PeriodFormat.year"), b.getString("PeriodFormat.years")) - // .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) - // .appendMonths() - // .appendSuffix(b.getString("PeriodFormat.month"), b.getString("PeriodFormat.months")) - // .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) - // .appendWeeks() - // .appendSuffix(b.getString("PeriodFormat.week"), b.getString("PeriodFormat.weeks")) - // .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) - // .appendDays() - // .appendSuffix(b.getString("PeriodFormat.day"), b.getString("PeriodFormat.days")) - // .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) - // .appendHours() - // .appendSuffix(b.getString("PeriodFormat.hour"), b.getString("PeriodFormat.hours")) - // .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) - // .appendMinutes() - // .appendSuffix(b.getString("PeriodFormat.minute"), b.getString("PeriodFormat.minutes")) - // .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) - // .appendSeconds() - // .appendSuffix(b.getString("PeriodFormat.second"), b.getString("PeriodFormat.seconds")) - // .appendSeparator(b.getString("PeriodFormat.commaspace"), b.getString("PeriodFormat.spaceandspace"), variants) - // .appendMillis() - // .appendSuffix(b.getString("PeriodFormat.millisecond"), b.getString("PeriodFormat.milliseconds")) - // .toFormatter().withLocale(locale); - // } - // - // private static String[] retrieveVariants(ResourceBundle b) { - // return new String[] { b.getString("PeriodFormat.space"), b.getString("PeriodFormat.comma"), - // b.getString("PeriodFormat.commandand"), b.getString("PeriodFormat.commaspaceand") }; - // } - // - // // simulate ResourceBundle.containsKey() - // private static boolean containsKey(ResourceBundle bundle, String key) { - // for (Enumeration en = bundle.getKeys(); en.hasMoreElements(); ) { - // if (en.nextElement().equals(key)) { - // return true; - // } - // } - // return false; - // } - // - // //----------------------------------------------------------------------- - // /** - // * Printer/parser that reacts to the locale and changes the word-based - // * pattern if necessary. - // */ - // static class DynamicWordBased - // implements PeriodPrinter, PeriodParser { - // - // /** The formatter with the locale selected at construction time. */ - // private final PeriodFormatter iFormatter; - // - // DynamicWordBased(PeriodFormatter formatter) { - // iFormatter = formatter; - // } - // - // public int countFieldsToPrint(ReadablePeriod period, int stopAt, Locale locale) { - // return getPrinter(locale).countFieldsToPrint(period, stopAt, locale); - // } - // - // public int calculatePrintedLength(ReadablePeriod period, Locale locale) { - // return getPrinter(locale).calculatePrintedLength(period, locale); - // } - // - // public void printTo(StringBuffer buf, ReadablePeriod period, Locale locale) { - // getPrinter(locale).printTo(buf, period, locale); - // } - // - // public void printTo(Writer out, ReadablePeriod period, Locale locale) throws IOException { - // getPrinter(locale).printTo(out, period, locale); - // } - // - // private PeriodPrinter getPrinter(Locale locale) { - // if (locale != null && !locale.equals(iFormatter.getLocale())) { - // return wordBased(locale).getPrinter(); - // } - // return iFormatter.getPrinter(); - // } - // - // public int parseInto( - // ReadWritablePeriod period, String periodStr, - // int position, Locale locale) { - // return getParser(locale).parseInto(period, periodStr, position, locale); - // } - // - // private PeriodParser getParser(Locale locale) { - // if (locale != null && !locale.equals(iFormatter.getLocale())) { - // return wordBased(locale).getParser(); - // } - // return iFormatter.getParser(); - // } - // } } From 10d108639757c4de93c28f2830c0658fc34e17cb Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Sun, 9 Dec 2018 21:55:21 +0000 Subject: [PATCH 096/279] Add complex formats Change original regex to be predicates, because the data is now closed --- .../org/threeten/extra/AmountFormats.java | 189 ++++++++++------ .../threeten/extra/wordbased_cs.properties | 33 ++- .../threeten/extra/wordbased_en.properties | 1 + .../threeten/extra/wordbased_pl.properties | 32 ++- .../threeten/extra/wordbased_ru.properties | 33 ++- .../org/threeten/extra/TestAmountFormats.java | 204 +++++++++++++++++- 6 files changed, 369 insertions(+), 123 deletions(-) diff --git a/src/main/java/org/threeten/extra/AmountFormats.java b/src/main/java/org/threeten/extra/AmountFormats.java index 3bc8845e..d8c168ad 100644 --- a/src/main/java/org/threeten/extra/AmountFormats.java +++ b/src/main/java/org/threeten/extra/AmountFormats.java @@ -37,6 +37,9 @@ import java.util.Locale; import java.util.Objects; import java.util.ResourceBundle; +import java.util.function.IntPredicate; +import java.util.regex.Pattern; +import java.util.stream.Stream; /** * Provides the ability to format a temporal amount. @@ -53,6 +56,10 @@ public final class AmountFormats { * The number of days per week. */ private static final int DAYS_PER_WEEK = 7; + /** + * The number of hours per day. + */ + private static final int HOURS_PER_DAY = 24; /** * The number of minutes per hour. */ @@ -70,81 +77,62 @@ public final class AmountFormats { */ private static final String BUNDLE_NAME = "org.threeten.extra.wordbased"; /** - * the property file key for the separator " " + * The pattern to split lists with. */ - private static final String WORDBASED_SPACE = "WordBased.space"; + private static final Pattern SPLITTER = Pattern.compile("[|][|][|]"); /** - * the property file key for the separator ", " + * The property file key for the separator ", ". */ private static final String WORDBASED_COMMASPACE = "WordBased.commaspace"; /** - * the property file key for the separator " and " + * The property file key for the separator " and ". */ private static final String WORDBASED_SPACEANDSPACE = "WordBased.spaceandspace"; /** - * the property file key for the word "year" + * The property file key for the word "year". */ private static final String WORDBASED_YEAR = "WordBased.year"; /** - * the property file key for the word "years" - */ - private static final String WORDBASED_YEARS = "WordBased.years"; - /** - * the property file key for the word "month" + * The property file key for the word "month". */ private static final String WORDBASED_MONTH = "WordBased.month"; /** - * the property file key for the word "months" - */ - private static final String WORDBASED_MONTHS = "WordBased.months"; - /** - * the property file key for the word "week" + * The property file key for the word "week". */ private static final String WORDBASED_WEEK = "WordBased.week"; /** - * the property file key for the word "weeks" - */ - private static final String WORDBASED_WEEKS = "WordBased.weeks"; - /** - * the property file key for the word "day" + * The property file key for the word "day". */ private static final String WORDBASED_DAY = "WordBased.day"; /** - * the property file key for the word "days" - */ - private static final String WORDBASED_DAYS = "WordBased.days"; - /** - * the property file key for the word "hour" + * The property file key for the word "hour". */ private static final String WORDBASED_HOUR = "WordBased.hour"; /** - * the property file key for the word "hours" - */ - private static final String WORDBASED_HOURS = "WordBased.hours"; - /** - * the property file key for the word "minute" + * The property file key for the word "minute". */ private static final String WORDBASED_MINUTE = "WordBased.minute"; /** - * the property file key for the word "minutes" - */ - private static final String WORDBASED_MINUTES = "WordBased.minutes"; - /** - * the property file key for the word "second" + * The property file key for the word "second". */ private static final String WORDBASED_SECOND = "WordBased.second"; /** - * the property file key for the word "seconds" + * The property file key for the word "millisecond". */ - private static final String WORDBASED_SECONDS = "WordBased.seconds"; + private static final String WORDBASED_MILLISECOND = "WordBased.millisecond"; /** - * the property file key for the word "millisecond" + * The predicate that matches 1 or -1. */ - private static final String WORDBASED_MILLISECOND = "WordBased.millisecond"; + private static final IntPredicate PREDICATE_1 = value -> value == 1 || value == -1; /** - * the property file key for the word "milliseconds" + * The predicate that matches numbers ending 2, 3 or 4, but not ending 12, 13 or 14. */ - private static final String WORDBASED_MILLISECONDS = "WordBased.milliseconds"; + private static final IntPredicate PREDICATE_END234_NOTTEENS = value -> { + int abs = Math.abs(value); + int last = abs % 10; + int secondLast = (abs % 100) / 10; + return (last >= 2 && last <= 4 && secondLast != 1); + }; //----------------------------------------------------------------------- /** @@ -187,11 +175,12 @@ public static String wordBased(Period period, Locale locale) { Objects.requireNonNull(locale, "locale must not be null"); ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale); UnitFormat[] formats = { - new UnitFormat(bundle.getString(WORDBASED_YEAR), bundle.getString(WORDBASED_YEARS)), - new UnitFormat(bundle.getString(WORDBASED_MONTH), bundle.getString(WORDBASED_MONTHS)), - new UnitFormat(bundle.getString(WORDBASED_WEEK), bundle.getString(WORDBASED_WEEKS)), - new UnitFormat(bundle.getString(WORDBASED_DAY), bundle.getString(WORDBASED_DAYS))}; + UnitFormat.of(bundle, WORDBASED_YEAR), + UnitFormat.of(bundle, WORDBASED_MONTH), + UnitFormat.of(bundle, WORDBASED_WEEK), + UnitFormat.of(bundle, WORDBASED_DAY)}; WordBased wb = new WordBased(formats, bundle.getString(WORDBASED_COMMASPACE), bundle.getString(WORDBASED_SPACEANDSPACE)); + Period normPeriod = period.normalized(); int weeks = 0, days = 0; if (normPeriod.getDays() % DAYS_PER_WEEK == 0) { @@ -218,13 +207,13 @@ public static String wordBased(Duration duration, Locale locale) { Objects.requireNonNull(duration, "duration must not be null"); Objects.requireNonNull(locale, "locale must not be null"); ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale); - UnitFormat[] formats = { - new UnitFormat(bundle.getString(WORDBASED_HOUR), bundle.getString(WORDBASED_HOURS)), - new UnitFormat(bundle.getString(WORDBASED_MINUTE), bundle.getString(WORDBASED_MINUTES)), - new UnitFormat(bundle.getString(WORDBASED_SECOND), bundle.getString(WORDBASED_SECONDS)), - new UnitFormat(bundle.getString(WORDBASED_MILLISECOND), bundle.getString(WORDBASED_MILLISECONDS))}; - WordBased wb = new WordBased(formats, bundle.getString(WORDBASED_SPACE), bundle.getString(WORDBASED_SPACEANDSPACE)); + UnitFormat.of(bundle, WORDBASED_HOUR), + UnitFormat.of(bundle, WORDBASED_MINUTE), + UnitFormat.of(bundle, WORDBASED_SECOND), + UnitFormat.of(bundle, WORDBASED_MILLISECOND)}; + WordBased wb = new WordBased(formats, bundle.getString(WORDBASED_COMMASPACE), bundle.getString(WORDBASED_SPACEANDSPACE)); + long hours = duration.toHours(); long mins = duration.toMinutes() % MINUTES_PER_HOUR; long secs = duration.getSeconds() % SECONDS_PER_MINUTE; @@ -249,14 +238,35 @@ public static String wordBased(Period period, Duration duration, Locale locale) Objects.requireNonNull(period, "period must not be null"); Objects.requireNonNull(duration, "duration must not be null"); Objects.requireNonNull(locale, "locale must not be null"); - if (period.isZero()) { - return wordBased(duration, locale); - } - if (duration.isZero()) { - return wordBased(period, locale); - } ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME, locale); - return wordBased(period, locale) + bundle.getString(WORDBASED_SPACE) + wordBased(duration, locale); + UnitFormat[] formats = { + UnitFormat.of(bundle, WORDBASED_YEAR), + UnitFormat.of(bundle, WORDBASED_MONTH), + UnitFormat.of(bundle, WORDBASED_WEEK), + UnitFormat.of(bundle, WORDBASED_DAY), + UnitFormat.of(bundle, WORDBASED_HOUR), + UnitFormat.of(bundle, WORDBASED_MINUTE), + UnitFormat.of(bundle, WORDBASED_SECOND), + UnitFormat.of(bundle, WORDBASED_MILLISECOND)}; + WordBased wb = new WordBased(formats, bundle.getString(WORDBASED_COMMASPACE), bundle.getString(WORDBASED_SPACEANDSPACE)); + + Period normPeriod = period.normalized(); + int weeks = 0, days = 0; + if (normPeriod.getDays() % DAYS_PER_WEEK == 0) { + weeks = normPeriod.getDays() / DAYS_PER_WEEK; + } else { + days = normPeriod.getDays(); + } + long totalHours = duration.toHours(); + days += (int) (totalHours / HOURS_PER_DAY); + int hours = (int) (totalHours % HOURS_PER_DAY); + int mins = (int) (duration.toMinutes() % MINUTES_PER_HOUR); + int secs = (int) (duration.getSeconds() % SECONDS_PER_MINUTE); + int millis = duration.getNano() / NANOS_PER_MILLIS; + int[] values = { + normPeriod.getYears(), normPeriod.getMonths(), weeks, days, + (int) hours, mins, secs, millis}; + return wb.format(values); } private AmountFormats() { @@ -300,18 +310,75 @@ String format(int[] values) { } // data holder for single/plural formats - static final class UnitFormat { + static interface UnitFormat { + + static UnitFormat of(ResourceBundle bundle, String keyStem) { + if (bundle.containsKey(keyStem + "s.predicates")) { + String predicateList = bundle.getString(keyStem + "s.predicates"); + String textList = bundle.getString(keyStem + "s.list"); + String[] regexes = SPLITTER.split(predicateList); + String[] text = SPLITTER.split(textList); + return new PredicateFormat(regexes, text); + } else { + String single = bundle.getString(keyStem); + String plural = bundle.getString(keyStem + "s"); + return new SinglePluralFormat(single, plural); + } + } + + void formatTo(int value, StringBuilder buf); + } + + // data holder for single/plural formats + static final class SinglePluralFormat implements UnitFormat { private final String single; private final String plural; - public UnitFormat(String single, String plural) { + SinglePluralFormat(String single, String plural) { this.single = single; this.plural = plural; } - void formatTo(int value, StringBuilder buf) { + @Override + public void formatTo(int value, StringBuilder buf) { buf.append(value).append(value == 1 || value == -1 ? single : plural); } } + // data holder for predicate formats + static final class PredicateFormat implements UnitFormat { + private final IntPredicate[] predicates; + private final String[] text; + + PredicateFormat(String[] predicateStrs, String[] text) { + if (predicateStrs.length + 1 != text.length) { + throw new IllegalStateException("Invalid word-based resource"); + } + this.predicates = Stream.of(predicateStrs) + .map(predicateStr -> findPredicate(predicateStr)) + .toArray(IntPredicate[]::new); + this.text = text; + } + + private IntPredicate findPredicate(String predicateStr) { + switch (predicateStr) { + case "One": return PREDICATE_1; + case "End234NotTeens": return PREDICATE_END234_NOTTEENS; + default: throw new IllegalStateException("Invalid word-based resource"); + } + } + + @Override + public void formatTo(int value, StringBuilder buf) { + for (int i = 0; i < predicates.length; i++) { + if (predicates[i].test(value)) { + buf.append(value).append(text[i]); + return; + } + } + buf.append(value).append(text[predicates.length]); + return; + } + } + } diff --git a/src/main/resources/org/threeten/extra/wordbased_cs.properties b/src/main/resources/org/threeten/extra/wordbased_cs.properties index 548d03f3..67bb462d 100644 --- a/src/main/resources/org/threeten/extra/wordbased_cs.properties +++ b/src/main/resources/org/threeten/extra/wordbased_cs.properties @@ -4,20 +4,19 @@ WordBased.commandand=,a WordBased.commaspaceand=, a WordBased.commaspace=, WordBased.spaceandspace=\ a -WordBased.regex.separator=% -WordBased.years.regex=^1$%[0-9]*(? Date: Sun, 9 Dec 2018 21:58:58 +0000 Subject: [PATCH 097/279] Recognise contribution --- pom.xml | 4 ++++ src/changes/changes.xml | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/pom.xml b/pom.xml index 6049956c..e88e2e83 100644 --- a/pom.xml +++ b/pom.xml @@ -42,6 +42,10 @@ Jim Gough https://github.com/jpgough + + Monica Guzik + https://github.com/monicagg + Christian Heinemann https://github.com/cheinema diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 0e31ff1b..249de4bc 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,6 +7,14 @@ + + + Add word-based period formatting. + Note that textual data can only be altered by PRs to ThreeTen-Extra. + Based on original code from Joda-Time. + Fixes #113, #41. + + Enhance LocalDateRange. From 3af70853e8e7d1b4412caee12f430111190e6d49 Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Sun, 9 Dec 2018 22:09:52 +0000 Subject: [PATCH 098/279] Update docs for word-based formatting --- src/site/markdown/index.md | 1 + src/site/markdown/userguide.md | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index a80002fe..98e2086c 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -31,6 +31,7 @@ The following features are included: * [Coptic](apidocs/org/threeten/extra/chrono/CopticChronology.html) calendar system * [Ethiopic](apidocs/org/threeten/extra/chrono/EthiopicChronology.html) calendar system * [Julian](apidocs/org/threeten/extra/chrono/JulianChronology.html) calendar system +* [Word-based](apidocs/org/threeten/extra/AmountFormats.html) period and duration formatting * Support for the TAI and UTC [time-scales](apidocs/org/threeten/extra/scale/package-summary.html) diff --git a/src/site/markdown/userguide.md b/src/site/markdown/userguide.md index d41e940f..734fe16b 100644 --- a/src/site/markdown/userguide.md +++ b/src/site/markdown/userguide.md @@ -23,6 +23,21 @@ These include: * [`PeriodDuration`](apidocs/org/threeten/extra/PeriodDuration.html) - combines a `Period` and a `Duration` +## Period/Duration formatting + +The JDK does not provide a mechanism to format periods or durations beyond ISO-8601. +A simple mechanism is provided here in [`AmountFormats`](apidocs/org/threeten/extra/AmountFormats.html): + +``` + Period period = Period.of(1, 6, 5); + String str = AmountFormats.wordBased(period, Locale.ENGLISH); + // output: "1 year, 6 months and 5 days" +``` + +Translations are provided for cs, da, de, en, es, fr, it, ja, nl, pl, pt, ro, ru, tr. +Feel free to raise PRs for other languages. + + ## Calendar systems The additional calendar systems operate exactly as per similar classes in Java SE 8. From 2c25ccff266f474a19a6ab6e0abc0037860d049a Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Fri, 14 Dec 2018 23:13:41 +0000 Subject: [PATCH 099/279] Tidelift commercial support and security policy --- README.md | 11 ++++++++++- pom.xml | 1 - src/changes/changes.xml | 3 +++ src/site/markdown/index.md | 15 ++++++++------- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 836b98d7..4b093a2b 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,18 @@ ThreeTen-Extra requires Java SE 8 or later and has no dependencies. Available in the [Maven Central repository](https://search.maven.org/search?q=g:org.threeten%20AND%20a:threeten-extra&core=gav) +![Tidelift dependency check](https://tidelift.com/badges/github/ThreeTen/threeten-extra) + ### Support -Please use GitHub [issues](https://github.com/ThreeTen/threeten-extra/issues) and Pull Requests for support. +Please use [Stack Overflow](https://stackoverflow.com/search?q=threeten-extra) for general usage questions. +GitHub [issues](https://github.com/ThreeTen/threeten-extra/issues) and [pull requests](https://github.com/ThreeTen/threeten-extra/pulls) +should be used when you want to help advance the project. +Commercial support is available via the +[Tidelift subscription](https://tidelift.com/subscription/pkg/maven-org-threeten-threeten-extra?utm_source=maven-org-threeten-threeten-extra&utm_medium=referral&utm_campaign=readme). + +To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). +Tidelift will coordinate the fix and disclosure. ### Release process diff --git a/pom.xml b/pom.xml index e88e2e83..c4eeca30 100644 --- a/pom.xml +++ b/pom.xml @@ -114,7 +114,6 @@ ${project.basedir} LICENSE.txt - NOTICE.txt diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 249de4bc..4aea83b3 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -14,6 +14,9 @@ Based on original code from Joda-Time. Fixes #113, #41. + + Add Tidelift commercial support and security policy. + diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index 98e2086c..3feeeb80 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -67,10 +67,11 @@ Available in [Maven Central](https://search.maven.org/search?q=g:org.threeten%20 ### Support -Support on bugs, library usage or enhancement requests is available on a best efforts basis. - -To suggest enhancements or contribute, please [fork the source code](https://github.com/ThreeTen/threeten-extra) -on GitHub and send a Pull Request. - -Alternatively, use GitHub [issues](https://github.com/ThreeTen/threeten-extra/issues). - +Please use [Stack Overflow](https://stackoverflow.com/search?q=threeten-extra) for general usage questions. +GitHub [issues](https://github.com/ThreeTen/threeten-extra/issues) and [pull requests](https://github.com/ThreeTen/threeten-extra/pulls) +should be used when you want to help advance the project. +Commercial support is available via the +[Tidelift subscription](https://tidelift.com/subscription/pkg/maven-org-threeten-threeten-extra?utm_source=maven-org-threeten-threeten-extra&utm_medium=referral&utm_campaign=website). + +To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). +Tidelift will coordinate the fix and disclosure. From f978cfaa55c999a399c70cde1f67cf4d464fb604 Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Wed, 9 Jan 2019 23:26:49 +0000 Subject: [PATCH 100/279] Update plugin versions --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c4eeca30..8cf7ab2e 100644 --- a/pom.xml +++ b/pom.xml @@ -809,11 +809,11 @@ 3.8.0 2.8.2 3.1.1 - 3.0.0-M1 + 3.0.0-M2 1.6 2.5.2 3.1.0 - 3.0.0-M1 + 3.0.1 2.5 3.5.2 3.10.0 From ea80cb4fa059bc0dd51c779b9b63e36df908c356 Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Wed, 9 Jan 2019 23:41:06 +0000 Subject: [PATCH 101/279] Fix Javadoc links --- README.md | 2 +- src/site/markdown/index.md | 36 +++++++++++++------------- src/site/markdown/userguide.md | 46 +++++++++++++++++----------------- src/site/site.xml | 2 +- 4 files changed, 43 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 4b093a2b..0fe91cde 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Various documentation is available: * The [home page](https://www.threeten.org/threeten-extra/) * The [user guide](https://www.threeten.org/threeten-extra/userguide.html) -* The [Javadoc](https://www.threeten.org/threeten-extra/apidocs/index.html) +* The [Javadoc](https://www.threeten.org/threeten-extra/apidocs/org.threeten.extra/module-summary.html) ### Releases diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index 3feeeb80..1eaecff2 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -15,24 +15,24 @@ ThreeTen-Extra is licensed under the business-friendly [BSD 3-clause license](li The following features are included: -* [`DayOfMonth`](apidocs/org/threeten/extra/DayOfMonth.html) - a day-of-month without month or year -* [`DayOfYear`](apidocs/org/threeten/extra/DayOfYear.html) - a day-of-year without year -* [`AmPm`](apidocs/org/threeten/extra/AmPm.html) - before or after midday -* [`Quarter`](apidocs/org/threeten/extra/Quarter.html) - the four quarters, Q1, Q2, Q3 and Q4 -* [`YearQuarter`](apidocs/org/threeten/extra/YearQuarter.html) - combines a year and quarter, 2014-Q4 -* [`YearWeek`](apidocs/org/threeten/extra/YearWeek.html) - combines a week-based-year and a week, 2014-W06 -* [`Days`](apidocs/org/threeten/extra/Days.html), -[`Weeks`](apidocs/org/threeten/extra/Weeks.html), -[`Months`](apidocs/org/threeten/extra/Months.html) and -[`Years`](apidocs/org/threeten/extra/Years.html) - amounts of time -* [`Interval`](apidocs/org/threeten/extra/Interval.html) - an interval between two instants -* [`PeriodDuration`](apidocs/org/threeten/extra/PeriodDuration.html) - combines `Period` and `Duration` +* [`DayOfMonth`](apidocs/org.threeten.extra/org/threeten/extra/DayOfMonth.html) - a day-of-month without month or year +* [`DayOfYear`](apidocs/org.threeten.extra/org/threeten/extra/DayOfYear.html) - a day-of-year without year +* [`AmPm`](apidocs/org.threeten.extra/org/threeten/extra/AmPm.html) - before or after midday +* [`Quarter`](apidocs/org.threeten.extra/org/threeten/extra/Quarter.html) - the four quarters, Q1, Q2, Q3 and Q4 +* [`YearQuarter`](apidocs/org.threeten.extra/org/threeten/extra/YearQuarter.html) - combines a year and quarter, 2014-Q4 +* [`YearWeek`](apidocs/org.threeten.extra/org/threeten/extra/YearWeek.html) - combines a week-based-year and a week, 2014-W06 +* [`Days`](apidocs/org.threeten.extra/org/threeten/extra/Days.html), +[`Weeks`](apidocs/org.threeten.extra/org/threeten/extra/Weeks.html), +[`Months`](apidocs/org.threeten.extra/org/threeten/extra/Months.html) and +[`Years`](apidocs/org.threeten.extra/org/threeten/extra/Years.html) - amounts of time +* [`Interval`](apidocs/org.threeten.extra/org/threeten/extra/Interval.html) - an interval between two instants +* [`PeriodDuration`](apidocs/org.threeten.extra/org/threeten/extra/PeriodDuration.html) - combines `Period` and `Duration` * Weekend adjusters -* [Coptic](apidocs/org/threeten/extra/chrono/CopticChronology.html) calendar system -* [Ethiopic](apidocs/org/threeten/extra/chrono/EthiopicChronology.html) calendar system -* [Julian](apidocs/org/threeten/extra/chrono/JulianChronology.html) calendar system -* [Word-based](apidocs/org/threeten/extra/AmountFormats.html) period and duration formatting -* Support for the TAI and UTC [time-scales](apidocs/org/threeten/extra/scale/package-summary.html) +* [Coptic](apidocs/org.threeten.extra/org/threeten/extra/chrono/CopticChronology.html) calendar system +* [Ethiopic](apidocs/org.threeten.extra/org/threeten/extra/chrono/EthiopicChronology.html) calendar system +* [Julian](apidocs/org.threeten.extra/org/threeten/extra/chrono/JulianChronology.html) calendar system +* [Word-based](apidocs/org.threeten.extra/org/threeten/extra/AmountFormats.html) period and duration formatting +* Support for the TAI and UTC [time-scales](apidocs/org.threeten.extra/org/threeten/extra/scale/package-summary.html) ## Documentation @@ -40,7 +40,7 @@ The following features are included: Various documentation is available: * The helpful [user guide](userguide.html) -* The [Javadoc](apidocs/index.html) +* The [Javadoc](apidocs/org.threeten.extra/module-summary.html) * The [change notes](changes-report.html) for each release * The [GitHub](https://github.com/ThreeTen/threeten-extra) source repository diff --git a/src/site/markdown/userguide.md b/src/site/markdown/userguide.md index 734fe16b..385cc8ac 100644 --- a/src/site/markdown/userguide.md +++ b/src/site/markdown/userguide.md @@ -9,24 +9,24 @@ ThreeTen-Extra is a small library that builds on the Java SE 8 The additional value types operate exactly as per similar classes in Java SE 8. These include: -* [`DayOfMonth`](apidocs/org/threeten/extra/DayOfMonth.html) - a day-of-month without month or year -* [`DayOfYear`](apidocs/org/threeten/extra/DayOfYear.html) - a day-of-year without year -* [`AmPm`](apidocs/org/threeten/extra/AmPm.html) - before or after midday -* [`Quarter`](apidocs/org/threeten/extra/Quarter.html) - the four quarters, Q1, Q2, Q3 and Q4 -* [`YearQuarter`](apidocs/org/threeten/extra/YearQuarter.html) - combines a year and quarter, 2014-Q4 -* [`YearWeek`](apidocs/org/threeten/extra/YearWeek.html) - combines a week-based-year and a week, 2014-W06 -* [`Days`](apidocs/org/threeten/extra/Days.html) - an amount of time measured in days -* [`Weeks`](apidocs/org/threeten/extra/Weeks.html) - an amount of time measured in weeks -* [`Months`](apidocs/org/threeten/extra/Months.html) - an amount of time measured in months -* [`Years`](apidocs/org/threeten/extra/Years.html) - an amount of time measured in years -* [`Interval`](apidocs/org/threeten/extra/Interval.html) - an interval between two instants -* [`PeriodDuration`](apidocs/org/threeten/extra/PeriodDuration.html) - combines a `Period` and a `Duration` +* [`DayOfMonth`](apidocs/org.threeten.extra/org/threeten/extra/DayOfMonth.html) - a day-of-month without month or year +* [`DayOfYear`](apidocs/org.threeten.extra/org/threeten/extra/DayOfYear.html) - a day-of-year without year +* [`AmPm`](apidocs/org.threeten.extra/org/threeten/extra/AmPm.html) - before or after midday +* [`Quarter`](apidocs/org.threeten.extra/org/threeten/extra/Quarter.html) - the four quarters, Q1, Q2, Q3 and Q4 +* [`YearQuarter`](apidocs/org.threeten.extra/org/threeten/extra/YearQuarter.html) - combines a year and quarter, 2014-Q4 +* [`YearWeek`](apidocs/org.threeten.extra/org/threeten/extra/YearWeek.html) - combines a week-based-year and a week, 2014-W06 +* [`Days`](apidocs/org.threeten.extra/org/threeten/extra/Days.html) - an amount of time measured in days +* [`Weeks`](apidocs/org.threeten.extra/org/threeten/extra/Weeks.html) - an amount of time measured in weeks +* [`Months`](apidocs/org.threeten.extra/org/threeten/extra/Months.html) - an amount of time measured in months +* [`Years`](apidocs/org.threeten.extra/org/threeten/extra/Years.html) - an amount of time measured in years +* [`Interval`](apidocs/org.threeten.extra/org/threeten/extra/Interval.html) - an interval between two instants +* [`PeriodDuration`](apidocs/org.threeten.extra/org/threeten/extra/PeriodDuration.html) - combines a `Period` and a `Duration` ## Period/Duration formatting The JDK does not provide a mechanism to format periods or durations beyond ISO-8601. -A simple mechanism is provided here in [`AmountFormats`](apidocs/org/threeten/extra/AmountFormats.html): +A simple mechanism is provided here in [`AmountFormats`](apidocs/org.threeten.extra/org/threeten/extra/AmountFormats.html): ``` Period period = Period.of(1, 6, 5); @@ -43,16 +43,16 @@ Feel free to raise PRs for other languages. The additional calendar systems operate exactly as per similar classes in Java SE 8. These include: -* [Accounting](apidocs/org/threeten/extra/chrono/AccountingChronology.html) calendar system -* [British Cutover](apidocs/org/threeten/extra/chrono/BritishCutoverChronology.html) calendar system -* [Coptic](apidocs/org/threeten/extra/chrono/CopticChronology.html) calendar system -* [Discordian](apidocs/org/threeten/extra/chrono/DiscordianChronology.html) calendar system -* [Ethiopic](apidocs/org/threeten/extra/chrono/EthiopicChronology.html) calendar system -* [International Fixed](apidocs/org/threeten/extra/chrono/InternationalFixedChronology.html) calendar system -* [Julian](apidocs/org/threeten/extra/chrono/JulianChronology.html) calendar system -* [Pax](apidocs/org/threeten/extra/chrono/PaxChronology.html) calendar system -* [Symmetry010](apidocs/org/threeten/extra/chrono/Symmetry010Chronology.html) calendar system -* [Symmetry454](apidocs/org/threeten/extra/chrono/Symmetry454Chronology.html) calendar system +* [Accounting](apidocs/org.threeten.extra/org/threeten/extra/chrono/AccountingChronology.html) calendar system +* [British Cutover](apidocs/org.threeten.extra/org/threeten/extra/chrono/BritishCutoverChronology.html) calendar system +* [Coptic](apidocs/org.threeten.extra/org/threeten/extra/chrono/CopticChronology.html) calendar system +* [Discordian](apidocs/org.threeten.extra/org/threeten/extra/chrono/DiscordianChronology.html) calendar system +* [Ethiopic](apidocs/org.threeten.extra/org/threeten/extra/chrono/EthiopicChronology.html) calendar system +* [International Fixed](apidocs/org.threeten.extra/org/threeten/extra/chrono/InternationalFixedChronology.html) calendar system +* [Julian](apidocs/org.threeten.extra/org/threeten/extra/chrono/JulianChronology.html) calendar system +* [Pax](apidocs/org.threeten.extra/org/threeten/extra/chrono/PaxChronology.html) calendar system +* [Symmetry010](apidocs/org.threeten.extra/org/threeten/extra/chrono/Symmetry010Chronology.html) calendar system +* [Symmetry454](apidocs/org.threeten.extra/org/threeten/extra/chrono/Symmetry454Chronology.html) calendar system ## Time scales diff --git a/src/site/site.xml b/src/site/site.xml index e3d3784b..fe8438a7 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -68,7 +68,7 @@

    - + From 2404279398eb4d835cd71612b3d0ef3c99d92852 Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Thu, 10 Jan 2019 00:15:37 +0000 Subject: [PATCH 102/279] Fix javadoc --- pom.xml | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/pom.xml b/pom.xml index 8cf7ab2e..bf9312de 100644 --- a/pom.xml +++ b/pom.xml @@ -622,6 +622,7 @@ org.apache.maven.plugins maven-javadoc-plugin + true module-info.java @@ -668,33 +669,6 @@ 8 - - - org.apache.maven.plugins - maven-dependency-plugin - - - copy-dependencies - compile - - copy-dependencies - - - ${project.build.directory}/dependencies - true - true - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - --module-path ${project.build.directory}/dependencies - - From 9199231f3d3924c4672f0d3288b78e718f25b8b7 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Wed, 16 Jan 2019 11:23:17 +0000 Subject: [PATCH 103/279] Update Javadoc Fix pom.xml, removing generation on Java 8 --- pom.xml | 44 ++++++------------- .../threeten/extra/chrono/package-info.java | 35 +++++++++++++++ .../java/org/threeten/extra/package-info.java | 35 +++++++++++++++ .../threeten/extra/scale/package-info.java | 35 +++++++++++++++ 4 files changed, 119 insertions(+), 30 deletions(-) create mode 100644 src/main/java/org/threeten/extra/chrono/package-info.java create mode 100644 src/main/java/org/threeten/extra/package-info.java create mode 100644 src/main/java/org/threeten/extra/scale/package-info.java diff --git a/pom.xml b/pom.xml index bf9312de..5d4b81e1 100644 --- a/pom.xml +++ b/pom.xml @@ -191,20 +191,6 @@ - - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadocs - package - - jar - - - - org.apache.maven.plugins @@ -623,9 +609,6 @@ maven-javadoc-plugin true - - module-info.java - @@ -639,6 +622,20 @@ + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadocs + package + + jar + + + + org.apache.maven.plugins @@ -671,19 +668,6 @@ - - - - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven-javadoc-plugin.version} - - --module-path ${project.build.directory}/dependencies - - - - diff --git a/src/main/java/org/threeten/extra/chrono/package-info.java b/src/main/java/org/threeten/extra/chrono/package-info.java new file mode 100644 index 00000000..46c815a7 --- /dev/null +++ b/src/main/java/org/threeten/extra/chrono/package-info.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/** + * Additional chronologies (calendar systems) that extend {@code java.time.*}. + */ +package org.threeten.extra.chrono; diff --git a/src/main/java/org/threeten/extra/package-info.java b/src/main/java/org/threeten/extra/package-info.java new file mode 100644 index 00000000..bb7d000e --- /dev/null +++ b/src/main/java/org/threeten/extra/package-info.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/** + * Value types and utilities that extend {@code java.time.*}. + */ +package org.threeten.extra; diff --git a/src/main/java/org/threeten/extra/scale/package-info.java b/src/main/java/org/threeten/extra/scale/package-info.java new file mode 100644 index 00000000..525b80bc --- /dev/null +++ b/src/main/java/org/threeten/extra/scale/package-info.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/** + * Support for time scales that extend {@code java.time.*}. + */ +package org.threeten.extra.scale; From 187a00c50ce0d604d9a9f79b61bedb4e5c36a492 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Wed, 16 Jan 2019 13:14:26 +0000 Subject: [PATCH 104/279] Try codecov.io (#118) --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 685a3d61..4effc0ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,8 @@ script: - mvn install site -e -B - if [[ $TRAVIS_TAG =~ ^website.*$ ]] && [ "$TRAVIS_JDK_VERSION" == "openjdk11" ]; then chmod +x ./.github/website.sh; .github/website.sh; fi - if [[ $TRAVIS_TAG =~ ^v.*$ ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_JDK_VERSION" == "openjdk11" ]; then chmod +x ./.github/website.sh; .github/website.sh; fi +after_success: + - bash <(curl -s https://codecov.io/bash) # secure keys for GITHUB_TOKEN env: global: From 467cd401e0a40938b0b07ae9e5717dfda1f50fda Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Wed, 16 Jan 2019 16:32:40 +0000 Subject: [PATCH 105/279] Increase test coverage and fix PMD issues (#119) Testing codecov.io usage --- src/main/java/org/threeten/extra/Days.java | 4 +- src/main/java/org/threeten/extra/Hours.java | 4 +- .../org/threeten/extra/LocalDateRange.java | 8 +- src/main/java/org/threeten/extra/Minutes.java | 2 +- src/main/java/org/threeten/extra/Months.java | 4 +- src/main/java/org/threeten/extra/Seconds.java | 2 +- src/main/java/org/threeten/extra/Weeks.java | 4 +- src/main/java/org/threeten/extra/Years.java | 4 +- .../extra/chrono/AccountingYearDivision.java | 2 +- .../org/threeten/extra/TestDayOfMonth.java | 119 +++++++++++++++++- .../org/threeten/extra/TestDayOfYear.java | 116 ++++++++++++++++- .../java/org/threeten/extra/TestDays.java | 47 ++++++- .../java/org/threeten/extra/TestMonths.java | 47 ++++++- .../java/org/threeten/extra/TestWeeks.java | 47 ++++++- .../java/org/threeten/extra/TestYears.java | 47 ++++++- 15 files changed, 432 insertions(+), 25 deletions(-) diff --git a/src/main/java/org/threeten/extra/Days.java b/src/main/java/org/threeten/extra/Days.java index e0724cad..8f341f2d 100644 --- a/src/main/java/org/threeten/extra/Days.java +++ b/src/main/java/org/threeten/extra/Days.java @@ -207,7 +207,7 @@ public static Days parse(CharSequence text) { Objects.requireNonNull(text, "text"); Matcher matcher = PATTERN.matcher(text); if (matcher.matches()) { - int negate = ("-".equals(matcher.group(1)) ? -1 : 1); + int negate = "-".equals(matcher.group(1)) ? -1 : 1; String weeksStr = matcher.group(2); String daysStr = matcher.group(3); if (weeksStr != null || daysStr != null) { @@ -281,7 +281,7 @@ private Object readResolve() { */ @Override public long get(TemporalUnit unit) { - if (unit == ChronoUnit.DAYS) { + if (unit == DAYS) { return days; } throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); diff --git a/src/main/java/org/threeten/extra/Hours.java b/src/main/java/org/threeten/extra/Hours.java index 585cc375..38cb0d82 100644 --- a/src/main/java/org/threeten/extra/Hours.java +++ b/src/main/java/org/threeten/extra/Hours.java @@ -190,7 +190,7 @@ public static Hours parse(CharSequence text) { Objects.requireNonNull(text, "text"); Matcher matcher = PATTERN.matcher(text); if (matcher.matches()) { - int negate = ("-".equals(matcher.group(1)) ? -1 : 1); + int negate = "-".equals(matcher.group(1)) ? -1 : 1; String daysStr = matcher.group(2); String hoursStr = matcher.group(3); if (daysStr != null || hoursStr != null) { @@ -281,7 +281,7 @@ public long get(TemporalUnit unit) { */ @Override public List getUnits() { - return Collections.singletonList(ChronoUnit.HOURS); + return Collections.singletonList(HOURS); } //----------------------------------------------------------------------- diff --git a/src/main/java/org/threeten/extra/LocalDateRange.java b/src/main/java/org/threeten/extra/LocalDateRange.java index acef7fbb..f5697651 100644 --- a/src/main/java/org/threeten/extra/LocalDateRange.java +++ b/src/main/java/org/threeten/extra/LocalDateRange.java @@ -74,10 +74,6 @@ public final class LocalDateRange implements Serializable { - /** - * A range over the whole time-line. - */ - public static final LocalDateRange ALL = new LocalDateRange(LocalDate.MIN, LocalDate.MAX); /** * The day after the MIN date. */ @@ -86,6 +82,10 @@ public final class LocalDateRange * The day before the MAX date. */ private static final LocalDate MAXM1 = LocalDate.MAX.minusDays(1); + /** + * A range over the whole time-line. + */ + public static final LocalDateRange ALL = new LocalDateRange(LocalDate.MIN, LocalDate.MAX); /** * Serialization version. diff --git a/src/main/java/org/threeten/extra/Minutes.java b/src/main/java/org/threeten/extra/Minutes.java index bbb93d1c..e804aaa2 100644 --- a/src/main/java/org/threeten/extra/Minutes.java +++ b/src/main/java/org/threeten/extra/Minutes.java @@ -215,7 +215,7 @@ public static Minutes parse(CharSequence text) { Objects.requireNonNull(text, "text"); Matcher matcher = PATTERN.matcher(text); if (matcher.matches()) { - int negate = ("-".equals(matcher.group(1)) ? -1 : 1); + int negate = "-".equals(matcher.group(1)) ? -1 : 1; String daysStr = matcher.group(2); String hoursStr = matcher.group(3); String minutesStr = matcher.group(4); diff --git a/src/main/java/org/threeten/extra/Months.java b/src/main/java/org/threeten/extra/Months.java index 39bd5da1..85fb1568 100644 --- a/src/main/java/org/threeten/extra/Months.java +++ b/src/main/java/org/threeten/extra/Months.java @@ -207,7 +207,7 @@ public static Months parse(CharSequence text) { Objects.requireNonNull(text, "text"); Matcher matcher = PATTERN.matcher(text); if (matcher.matches()) { - int negate = ("-".equals(matcher.group(1)) ? -1 : 1); + int negate = "-".equals(matcher.group(1)) ? -1 : 1; String weeksStr = matcher.group(2); String daysStr = matcher.group(3); if (weeksStr != null || daysStr != null) { @@ -281,7 +281,7 @@ private Object readResolve() { */ @Override public long get(TemporalUnit unit) { - if (unit == ChronoUnit.MONTHS) { + if (unit == MONTHS) { return months; } throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); diff --git a/src/main/java/org/threeten/extra/Seconds.java b/src/main/java/org/threeten/extra/Seconds.java index 95e53545..ce9ceaae 100644 --- a/src/main/java/org/threeten/extra/Seconds.java +++ b/src/main/java/org/threeten/extra/Seconds.java @@ -241,7 +241,7 @@ public static Seconds parse(CharSequence text) { Objects.requireNonNull(text, "text"); Matcher matcher = PATTERN.matcher(text); if (matcher.matches()) { - int negate = ("-".equals(matcher.group(1)) ? -1 : 1); + int negate = "-".equals(matcher.group(1)) ? -1 : 1; String daysStr = matcher.group(2); String hoursStr = matcher.group(3); String minutesStr = matcher.group(4); diff --git a/src/main/java/org/threeten/extra/Weeks.java b/src/main/java/org/threeten/extra/Weeks.java index 261a93c7..e1494e0d 100644 --- a/src/main/java/org/threeten/extra/Weeks.java +++ b/src/main/java/org/threeten/extra/Weeks.java @@ -177,7 +177,7 @@ public static Weeks parse(CharSequence text) { Objects.requireNonNull(text, "text"); Matcher matcher = PATTERN.matcher(text); if (matcher.matches()) { - int negate = ("-".equals(matcher.group(1)) ? -1 : 1); + int negate = "-".equals(matcher.group(1)) ? -1 : 1; String str = matcher.group(2); try { int val = Integer.parseInt(str); @@ -237,7 +237,7 @@ private Object readResolve() { */ @Override public long get(TemporalUnit unit) { - if (unit == ChronoUnit.WEEKS) { + if (unit == WEEKS) { return weeks; } throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); diff --git a/src/main/java/org/threeten/extra/Years.java b/src/main/java/org/threeten/extra/Years.java index 22b7a20d..a31f1531 100644 --- a/src/main/java/org/threeten/extra/Years.java +++ b/src/main/java/org/threeten/extra/Years.java @@ -177,7 +177,7 @@ public static Years parse(CharSequence text) { Objects.requireNonNull(text, "text"); Matcher matcher = PATTERN.matcher(text); if (matcher.matches()) { - int negate = ("-".equals(matcher.group(1)) ? -1 : 1); + int negate = "-".equals(matcher.group(1)) ? -1 : 1; String str = matcher.group(2); try { int val = Integer.parseInt(str); @@ -237,7 +237,7 @@ private Object readResolve() { */ @Override public long get(TemporalUnit unit) { - if (unit == ChronoUnit.YEARS) { + if (unit == YEARS) { return years; } throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); diff --git a/src/main/java/org/threeten/extra/chrono/AccountingYearDivision.java b/src/main/java/org/threeten/extra/chrono/AccountingYearDivision.java index 4688966d..f4155e06 100644 --- a/src/main/java/org/threeten/extra/chrono/AccountingYearDivision.java +++ b/src/main/java/org/threeten/extra/chrono/AccountingYearDivision.java @@ -200,7 +200,7 @@ int getMonthFromElapsedWeeks(int weeksElapsed) { */ int getMonthFromElapsedWeeks(int weeksElapsed, int leapWeekInMonth) { if (weeksElapsed < 0 || weeksElapsed >= (leapWeekInMonth == 0 ? 52 : 53)) { - throw new DateTimeException("Count of '" + elapsedWeeks + "' elapsed weeks not valid," + throw new DateTimeException("Count of '" + elapsedWeeks.length + "' elapsed weeks not valid," + " should be in the range [0, " + (leapWeekInMonth == 0 ? 52 : 53) + ")"); } leapWeekInMonth = (leapWeekInMonth == 0 ? 0 : monthsInYearRange.checkValidIntValue(leapWeekInMonth, ChronoField.MONTH_OF_YEAR)); diff --git a/src/test/java/org/threeten/extra/TestDayOfMonth.java b/src/test/java/org/threeten/extra/TestDayOfMonth.java index cc6fd8db..eed62720 100644 --- a/src/test/java/org/threeten/extra/TestDayOfMonth.java +++ b/src/test/java/org/threeten/extra/TestDayOfMonth.java @@ -74,6 +74,7 @@ import static java.time.temporal.ChronoField.YEAR; import static java.time.temporal.ChronoField.YEAR_OF_ERA; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -93,13 +94,18 @@ import java.time.YearMonth; import java.time.ZoneId; import java.time.chrono.IsoChronology; +import java.time.chrono.JapaneseDate; import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; +import java.time.temporal.IsoFields; import java.time.temporal.Temporal; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjuster; import java.time.temporal.TemporalField; import java.time.temporal.TemporalQueries; +import java.time.temporal.TemporalUnit; import java.time.temporal.UnsupportedTemporalTypeException; +import java.time.temporal.ValueRange; import org.junit.Test; @@ -112,6 +118,57 @@ public class TestDayOfMonth { private static final DayOfMonth TEST = DayOfMonth.of(12); private static final ZoneId PARIS = ZoneId.of("Europe/Paris"); + private static class TestingField implements TemporalField { + + public static final TestingField INSTANCE = new TestingField(); + + @Override + public TemporalUnit getBaseUnit() { + return ChronoUnit.DAYS; + } + + @Override + public TemporalUnit getRangeUnit() { + return ChronoUnit.MONTHS; + } + + @Override + public ValueRange range() { + return ValueRange.of(1, 28, 31); + } + + @Override + public boolean isDateBased() { + return true; + } + + @Override + public boolean isTimeBased() { + return false; + } + + @Override + public boolean isSupportedBy(TemporalAccessor temporal) { + return temporal.isSupported(DAY_OF_MONTH); + } + + @Override + public ValueRange rangeRefinedBy(TemporalAccessor temporal) { + return range(); + } + + @Override + public long getFrom(TemporalAccessor temporal) { + return temporal.getLong(DAY_OF_MONTH); + } + + @Override + @SuppressWarnings("unchecked") + public R adjustInto(R temporal, long newValue) { + return (R) temporal.with(DAY_OF_MONTH, newValue); + } + } + //----------------------------------------------------------------------- @Test public void test_interfaces() { @@ -133,6 +190,31 @@ public void test_serialization() throws IOException, ClassNotFoundException { } } + //----------------------------------------------------------------------- + // now() + //----------------------------------------------------------------------- + @Test + public void test_now() { + DayOfMonth test = DayOfMonth.now(); + if (LocalDate.now().getDayOfMonth() != test.getValue()) { + test = DayOfMonth.now(); + } + assertEquals(LocalDate.now().getDayOfMonth(), test.getValue()); + } + + //----------------------------------------------------------------------- + // now(ZoneId) + //----------------------------------------------------------------------- + @Test + public void test_now_ZoneId() { + ZoneId zone = ZoneId.of("Asia/Tokyo"); + DayOfMonth test = DayOfMonth.now(zone); + if (LocalDate.now(zone).getDayOfMonth() != test.getValue()) { + test = DayOfMonth.now(zone); + } + assertEquals(LocalDate.now(zone).getDayOfMonth(), test.getValue()); + } + //----------------------------------------------------------------------- // of(int) //----------------------------------------------------------------------- @@ -228,6 +310,18 @@ public void test_from_TemporalAccessor_leapYear() { } } + @Test + public void test_from_TemporalAccessor_DayOfMonth() { + DayOfMonth dom = DayOfMonth.of(6); + assertEquals(dom, DayOfMonth.from(dom)); + } + + @Test + public void test_from_TemporalAccessor_nonIso() { + LocalDate date = LocalDate.now(); + assertEquals(date.getDayOfMonth(), DayOfMonth.from(JapaneseDate.from(date)).getValue()); + } + @Test(expected = DateTimeException.class) public void test_from_TemporalAccessor_noDerive() { DayOfMonth.from(LocalTime.NOON); @@ -280,6 +374,8 @@ public void test_isSupported() { assertEquals(false, TEST.isSupported(ERA)); assertEquals(false, TEST.isSupported(INSTANT_SECONDS)); assertEquals(false, TEST.isSupported(OFFSET_SECONDS)); + assertEquals(false, TEST.isSupported(IsoFields.DAY_OF_QUARTER)); + assertEquals(true, TEST.isSupported(TestingField.INSTANCE)); } //----------------------------------------------------------------------- @@ -326,11 +422,21 @@ public void test_getLong() { assertEquals(12L, TEST.getLong(DAY_OF_MONTH)); } + @Test + public void test_getLong_derivedField() { + assertEquals(12L, TEST.getLong(TestingField.INSTANCE)); + } + @Test(expected = UnsupportedTemporalTypeException.class) public void test_getLong_invalidField() { TEST.getLong(MONTH_OF_YEAR); } + @Test(expected = UnsupportedTemporalTypeException.class) + public void test_getLong_invalidField2() { + TEST.getLong(IsoFields.DAY_OF_QUARTER); + } + @Test(expected = NullPointerException.class) public void test_getLong_null() { TEST.getLong((TemporalField) null); @@ -408,6 +514,11 @@ public void test_isValidYearMonth_28() { assertEquals(true, test.isValidYearMonth(YearMonth.of(2012, 12))); } + @Test + public void test_isValidYearMonth_null() { + assertFalse(TEST.isValidYearMonth((YearMonth) null)); + } + //----------------------------------------------------------------------- // query(TemporalQuery) //----------------------------------------------------------------------- @@ -450,6 +561,11 @@ public void test_adjustInto_february29_notLeapYear() { test.adjustInto(base); } + @Test(expected = DateTimeException.class) + public void test_adjustInto_nonIso() { + TEST.adjustInto(JapaneseDate.now()); + } + @Test(expected = NullPointerException.class) public void test_adjustInto_null() { TEST.adjustInto((Temporal) null); @@ -642,7 +758,8 @@ public void test_equals_nullDayOfMonth() { @Test public void test_equals_incorrectType() { DayOfMonth test = DayOfMonth.of(1); - assertEquals(false, test.equals("Incorrect type")); + Object obj = "Incorrect type"; + assertEquals(false, test.equals(obj)); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestDayOfYear.java b/src/test/java/org/threeten/extra/TestDayOfYear.java index 9957a4b2..d4818cc2 100644 --- a/src/test/java/org/threeten/extra/TestDayOfYear.java +++ b/src/test/java/org/threeten/extra/TestDayOfYear.java @@ -78,13 +78,18 @@ import java.time.Year; import java.time.ZoneId; import java.time.chrono.IsoChronology; +import java.time.chrono.JapaneseDate; import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; +import java.time.temporal.IsoFields; import java.time.temporal.Temporal; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjuster; import java.time.temporal.TemporalField; import java.time.temporal.TemporalQueries; +import java.time.temporal.TemporalUnit; import java.time.temporal.UnsupportedTemporalTypeException; +import java.time.temporal.ValueRange; import org.junit.Test; @@ -100,6 +105,57 @@ public class TestDayOfYear { private static final DayOfYear TEST = DayOfYear.of(12); private static final ZoneId PARIS = ZoneId.of("Europe/Paris"); + private static class TestingField implements TemporalField { + + public static final TestingField INSTANCE = new TestingField(); + + @Override + public TemporalUnit getBaseUnit() { + return ChronoUnit.DAYS; + } + + @Override + public TemporalUnit getRangeUnit() { + return ChronoUnit.YEARS; + } + + @Override + public ValueRange range() { + return ValueRange.of(1, 365, 366); + } + + @Override + public boolean isDateBased() { + return true; + } + + @Override + public boolean isTimeBased() { + return false; + } + + @Override + public boolean isSupportedBy(TemporalAccessor temporal) { + return temporal.isSupported(DAY_OF_YEAR); + } + + @Override + public ValueRange rangeRefinedBy(TemporalAccessor temporal) { + return range(); + } + + @Override + public long getFrom(TemporalAccessor temporal) { + return temporal.getLong(DAY_OF_YEAR); + } + + @Override + @SuppressWarnings("unchecked") + public R adjustInto(R temporal, long newValue) { + return (R) temporal.with(DAY_OF_YEAR, newValue); + } + } + //----------------------------------------------------------------------- @Test public void test_interfaces() { @@ -121,6 +177,31 @@ public void test_serialization() throws IOException, ClassNotFoundException { } } + //----------------------------------------------------------------------- + // now() + //----------------------------------------------------------------------- + @Test + public void test_now() { + DayOfYear test = DayOfYear.now(); + if (LocalDate.now().getDayOfYear() != test.getValue()) { + test = DayOfYear.now(); + } + assertEquals(LocalDate.now().getDayOfYear(), test.getValue()); + } + + //----------------------------------------------------------------------- + // now(ZoneId) + //----------------------------------------------------------------------- + @Test + public void test_now_ZoneId() { + ZoneId zone = ZoneId.of("Asia/Tokyo"); + DayOfYear test = DayOfYear.now(zone); + if (LocalDate.now(zone).getDayOfYear() != test.getValue()) { + test = DayOfYear.now(zone); + } + assertEquals(LocalDate.now(zone).getDayOfYear(), test.getValue()); + } + //----------------------------------------------------------------------- // of(int) //----------------------------------------------------------------------- @@ -168,6 +249,18 @@ public void test_from_TemporalAccessor_leapYear() { } } + @Test + public void test_from_TemporalAccessor_DayOfYear() { + DayOfYear dom = DayOfYear.of(6); + assertEquals(dom, DayOfYear.from(dom)); + } + + @Test + public void test_from_TemporalAccessor_nonIso() { + LocalDate date = LocalDate.now(); + assertEquals(date.getDayOfYear(), DayOfYear.from(JapaneseDate.from(date)).getValue()); + } + @Test(expected = DateTimeException.class) public void test_from_TemporalAccessor_noDerive() { DayOfYear.from(LocalTime.NOON); @@ -220,6 +313,7 @@ public void test_isSupported() { assertEquals(false, TEST.isSupported(ERA)); assertEquals(false, TEST.isSupported(INSTANT_SECONDS)); assertEquals(false, TEST.isSupported(OFFSET_SECONDS)); + assertEquals(true, TEST.isSupported(TestingField.INSTANCE)); } //----------------------------------------------------------------------- @@ -266,11 +360,21 @@ public void test_getLong() { assertEquals(12L, TEST.getLong(DAY_OF_YEAR)); } + @Test + public void test_getLong_derivedField() { + assertEquals(12L, TEST.getLong(TestingField.INSTANCE)); + } + @Test(expected = UnsupportedTemporalTypeException.class) public void test_getLong_invalidField() { TEST.getLong(MONTH_OF_YEAR); } + @Test(expected = UnsupportedTemporalTypeException.class) + public void test_getLong_invalidField2() { + TEST.getLong(IsoFields.DAY_OF_QUARTER); + } + @Test(expected = NullPointerException.class) public void test_getLong_null() { TEST.getLong((TemporalField) null); @@ -280,7 +384,7 @@ public void test_getLong_null() { // isValidYear(int) //----------------------------------------------------------------------- @Test - public void test_isValidYearMonth_366() { + public void test_isValidYear_366() { DayOfYear test = DayOfYear.of(366); assertEquals(false, test.isValidYear(2011)); assertEquals(true, test.isValidYear(2012)); @@ -288,7 +392,7 @@ public void test_isValidYearMonth_366() { } @Test - public void test_isValidYearMonth_365() { + public void test_isValidYear_365() { DayOfYear test = DayOfYear.of(365); assertEquals(true, test.isValidYear(2011)); assertEquals(true, test.isValidYear(2012)); @@ -370,6 +474,11 @@ public void test_adjustInto_fromEndOfYear_leapYear() { } } + @Test(expected = DateTimeException.class) + public void test_adjustInto_nonIso() { + TEST.adjustInto(JapaneseDate.now()); + } + @Test(expected = NullPointerException.class) public void test_adjustInto_null() { TEST.adjustInto((Temporal) null); @@ -498,7 +607,8 @@ public void test_equals_nullDayOfYear() { @Test public void test_equals_incorrectType() { DayOfYear test = DayOfYear.of(1); - assertEquals(false, test.equals("Incorrect type")); + Object obj = "Incorrect type"; + assertEquals(false, test.equals(obj)); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestDays.java b/src/test/java/org/threeten/extra/TestDays.java index 4e78461f..9c0e1086 100644 --- a/src/test/java/org/threeten/extra/TestDays.java +++ b/src/test/java/org/threeten/extra/TestDays.java @@ -42,8 +42,12 @@ import java.io.Serializable; import java.time.DateTimeException; import java.time.Duration; +import java.time.LocalDate; import java.time.Period; import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoUnit; +import java.time.temporal.IsoFields; +import java.time.temporal.Temporal; import java.time.temporal.TemporalAmount; import org.junit.Test; @@ -244,6 +248,33 @@ public void test_parse_CharSequence_null() { Days.parse((CharSequence) null); } + //----------------------------------------------------------------------- + @Test + public void test_get() { + assertEquals(6, Days.of(6).get(ChronoUnit.DAYS)); + } + + @Test(expected = DateTimeException.class) + public void test_get_invalidType() { + Days.of(6).get(IsoFields.QUARTER_YEARS); + } + + //----------------------------------------------------------------------- + @Test + public void test_between() { + assertEquals(Days.of(365 + 366), Days.between(LocalDate.of(2019, 1, 1), LocalDate.of(2021, 1, 1))); + } + + @Test(expected = NullPointerException.class) + public void test_between_date_null() { + Days.between(LocalDate.now(), (Temporal) null); + } + + @Test(expected = NullPointerException.class) + public void test_between_null_date() { + Days.between((Temporal) null, LocalDate.now()); + } + //----------------------------------------------------------------------- @Test public void test_plus_TemporalAmount_Days() { @@ -458,6 +489,19 @@ public void test_abs_overflow() { Days.of(Integer.MIN_VALUE).abs(); } + //----------------------------------------------------------------------- + @Test + public void test_addTo() { + assertEquals(LocalDate.of(2019, 1, 10), Days.of(0).addTo(LocalDate.of(2019, 1, 10))); + assertEquals(LocalDate.of(2019, 1, 15), Days.of(5).addTo(LocalDate.of(2019, 1, 10))); + } + + @Test + public void test_subtractFrom() { + assertEquals(LocalDate.of(2019, 1, 10), Days.of(0).subtractFrom(LocalDate.of(2019, 1, 10))); + assertEquals(LocalDate.of(2019, 1, 5), Days.of(5).subtractFrom(LocalDate.of(2019, 1, 10))); + } + //----------------------------------------------------------------------- @Test public void test_toPeriod() { @@ -501,7 +545,8 @@ public void test_equals_null() { @Test public void test_equals_otherClass() { Days test5 = Days.of(5); - assertEquals(false, test5.equals("")); + Object obj = ""; + assertEquals(false, test5.equals(obj)); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestMonths.java b/src/test/java/org/threeten/extra/TestMonths.java index 9bfbe170..64d5970d 100644 --- a/src/test/java/org/threeten/extra/TestMonths.java +++ b/src/test/java/org/threeten/extra/TestMonths.java @@ -42,8 +42,12 @@ import java.io.Serializable; import java.time.DateTimeException; import java.time.Duration; +import java.time.LocalDate; import java.time.Period; import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoUnit; +import java.time.temporal.IsoFields; +import java.time.temporal.Temporal; import java.time.temporal.TemporalAmount; import org.junit.Test; @@ -237,6 +241,33 @@ public void test_parse_CharSequence_null() { Months.parse((CharSequence) null); } + //----------------------------------------------------------------------- + @Test + public void test_between() { + assertEquals(Months.of(24), Months.between(LocalDate.of(2019, 1, 1), LocalDate.of(2021, 1, 1))); + } + + @Test(expected = NullPointerException.class) + public void test_between_date_null() { + Months.between(LocalDate.now(), (Temporal) null); + } + + @Test(expected = NullPointerException.class) + public void test_between_null_date() { + Months.between((Temporal) null, LocalDate.now()); + } + + //----------------------------------------------------------------------- + @Test + public void test_get() { + assertEquals(6, Months.of(6).get(ChronoUnit.MONTHS)); + } + + @Test(expected = DateTimeException.class) + public void test_get_invalidType() { + Months.of(6).get(IsoFields.QUARTER_YEARS); + } + //----------------------------------------------------------------------- @Test public void test_plus_TemporalAmount_Months() { @@ -451,6 +482,19 @@ public void test_abs_overflow() { Months.of(Integer.MIN_VALUE).abs(); } + //----------------------------------------------------------------------- + @Test + public void test_addTo() { + assertEquals(LocalDate.of(2019, 1, 10), Months.of(0).addTo(LocalDate.of(2019, 1, 10))); + assertEquals(LocalDate.of(2019, 6, 10), Months.of(5).addTo(LocalDate.of(2019, 1, 10))); + } + + @Test + public void test_subtractFrom() { + assertEquals(LocalDate.of(2019, 1, 10), Months.of(0).subtractFrom(LocalDate.of(2019, 1, 10))); + assertEquals(LocalDate.of(2018, 8, 10), Months.of(5).subtractFrom(LocalDate.of(2019, 1, 10))); + } + //----------------------------------------------------------------------- @Test public void test_toPeriod() { @@ -494,7 +538,8 @@ public void test_equals_null() { @Test public void test_equals_otherClass() { Months test5 = Months.of(5); - assertEquals(false, test5.equals("")); + Object obj = ""; + assertEquals(false, test5.equals(obj)); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestWeeks.java b/src/test/java/org/threeten/extra/TestWeeks.java index 1cf8b15b..ff0daced 100644 --- a/src/test/java/org/threeten/extra/TestWeeks.java +++ b/src/test/java/org/threeten/extra/TestWeeks.java @@ -42,8 +42,12 @@ import java.io.Serializable; import java.time.DateTimeException; import java.time.Duration; +import java.time.LocalDate; import java.time.Period; import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoUnit; +import java.time.temporal.IsoFields; +import java.time.temporal.Temporal; import java.time.temporal.TemporalAmount; import org.junit.Test; @@ -180,6 +184,33 @@ public void test_parse_CharSequence_null() { Weeks.parse((CharSequence) null); } + //----------------------------------------------------------------------- + @Test + public void test_between() { + assertEquals(Weeks.of(104), Weeks.between(LocalDate.of(2019, 1, 1), LocalDate.of(2021, 1, 1))); + } + + @Test(expected = NullPointerException.class) + public void test_between_date_null() { + Weeks.between(LocalDate.now(), (Temporal) null); + } + + @Test(expected = NullPointerException.class) + public void test_between_null_date() { + Weeks.between((Temporal) null, LocalDate.now()); + } + + //----------------------------------------------------------------------- + @Test + public void test_get() { + assertEquals(6, Weeks.of(6).get(ChronoUnit.WEEKS)); + } + + @Test(expected = DateTimeException.class) + public void test_get_invalidType() { + Weeks.of(6).get(IsoFields.QUARTER_YEARS); + } + //----------------------------------------------------------------------- @Test public void test_plus_TemporalAmount_Weeks() { @@ -394,6 +425,19 @@ public void test_abs_overflow() { Weeks.of(Integer.MIN_VALUE).abs(); } + //----------------------------------------------------------------------- + @Test + public void test_addTo() { + assertEquals(LocalDate.of(2019, 1, 10), Weeks.of(0).addTo(LocalDate.of(2019, 1, 10))); + assertEquals(LocalDate.of(2019, 2, 14), Weeks.of(5).addTo(LocalDate.of(2019, 1, 10))); + } + + @Test + public void test_subtractFrom() { + assertEquals(LocalDate.of(2019, 1, 10), Weeks.of(0).subtractFrom(LocalDate.of(2019, 1, 10))); + assertEquals(LocalDate.of(2018, 12, 6), Weeks.of(5).subtractFrom(LocalDate.of(2019, 1, 10))); + } + //----------------------------------------------------------------------- @Test public void test_toPeriod() { @@ -437,7 +481,8 @@ public void test_equals_null() { @Test public void test_equals_otherClass() { Weeks test5 = Weeks.of(5); - assertEquals(false, test5.equals("")); + Object obj = ""; + assertEquals(false, test5.equals(obj)); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestYears.java b/src/test/java/org/threeten/extra/TestYears.java index facf129d..e7aa85af 100644 --- a/src/test/java/org/threeten/extra/TestYears.java +++ b/src/test/java/org/threeten/extra/TestYears.java @@ -42,8 +42,12 @@ import java.io.Serializable; import java.time.DateTimeException; import java.time.Duration; +import java.time.LocalDate; import java.time.Period; import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoUnit; +import java.time.temporal.IsoFields; +import java.time.temporal.Temporal; import java.time.temporal.TemporalAmount; import org.junit.Test; @@ -185,6 +189,33 @@ public void test_parse_CharSequence_null() { Years.parse((CharSequence) null); } + //----------------------------------------------------------------------- + @Test + public void test_between() { + assertEquals(Years.of(2), Years.between(LocalDate.of(2019, 1, 1), LocalDate.of(2021, 1, 1))); + } + + @Test(expected = NullPointerException.class) + public void test_between_date_null() { + Years.between(LocalDate.now(), (Temporal) null); + } + + @Test(expected = NullPointerException.class) + public void test_between_null_date() { + Years.between((Temporal) null, LocalDate.now()); + } + + //----------------------------------------------------------------------- + @Test + public void test_get() { + assertEquals(6, Years.of(6).get(ChronoUnit.YEARS)); + } + + @Test(expected = DateTimeException.class) + public void test_get_invalidType() { + Years.of(6).get(IsoFields.QUARTER_YEARS); + } + //----------------------------------------------------------------------- @Test public void test_plus_TemporalAmount_Years() { @@ -399,6 +430,19 @@ public void test_abs_overflow() { Years.of(Integer.MIN_VALUE).abs(); } + //----------------------------------------------------------------------- + @Test + public void test_addTo() { + assertEquals(LocalDate.of(2019, 1, 10), Years.of(0).addTo(LocalDate.of(2019, 1, 10))); + assertEquals(LocalDate.of(2024, 1, 10), Years.of(5).addTo(LocalDate.of(2019, 1, 10))); + } + + @Test + public void test_subtractFrom() { + assertEquals(LocalDate.of(2019, 1, 10), Years.of(0).subtractFrom(LocalDate.of(2019, 1, 10))); + assertEquals(LocalDate.of(2014, 1, 10), Years.of(5).subtractFrom(LocalDate.of(2019, 1, 10))); + } + //----------------------------------------------------------------------- @Test public void test_toPeriod() { @@ -442,7 +486,8 @@ public void test_equals_null() { @Test public void test_equals_otherClass() { Years test5 = Years.of(5); - assertEquals(false, test5.equals("")); + Object obj = ""; + assertEquals(false, test5.equals(obj)); } //----------------------------------------------------------------------- From 3e65cc940e5bea1e7583b0b49c36e0824cd579c4 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Wed, 16 Jan 2019 21:31:13 +0000 Subject: [PATCH 106/279] Add Joda-Convert annotations (#120) New optional dependency, mandatory on Scala --- pom.xml | 37 ++++++++ src/changes/changes.xml | 4 + src/main/java/module-info.java | 3 + src/main/java/org/threeten/extra/Days.java | 5 ++ src/main/java/org/threeten/extra/Hours.java | 5 ++ .../java/org/threeten/extra/Interval.java | 5 ++ .../org/threeten/extra/LocalDateRange.java | 5 ++ src/main/java/org/threeten/extra/Minutes.java | 5 ++ src/main/java/org/threeten/extra/Months.java | 5 ++ .../org/threeten/extra/PeriodDuration.java | 5 ++ src/main/java/org/threeten/extra/Seconds.java | 5 ++ src/main/java/org/threeten/extra/Weeks.java | 5 ++ .../java/org/threeten/extra/YearQuarter.java | 5 ++ .../java/org/threeten/extra/YearWeek.java | 5 ++ src/main/java/org/threeten/extra/Years.java | 5 ++ .../org/threeten/extra/scale/TaiInstant.java | 5 ++ .../org/threeten/extra/scale/UtcInstant.java | 5 ++ .../java/org/threeten/extra/TestConvert.java | 86 +++++++++++++++++++ 18 files changed, 200 insertions(+) create mode 100644 src/test/java/org/threeten/extra/TestConvert.java diff --git a/pom.xml b/pom.xml index 5d4b81e1..a3347e7f 100644 --- a/pom.xml +++ b/pom.xml @@ -426,6 +426,13 @@ + + org.joda + joda-convert + 2.2.0 + compile + true + com.google.guava guava @@ -622,6 +629,33 @@ + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + compile + + copy-dependencies + + + ${project.build.directory}/dependencies + true + true + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + --add-modules org.joda.convert --module-path ${project.build.directory}/dependencies ${argLine} + + org.apache.maven.plugins @@ -635,6 +669,9 @@ + + --module-path ${project.build.directory}/dependencies + diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 4aea83b3..ad8e5a7f 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -14,6 +14,10 @@ Based on original code from Joda-Time. Fixes #113, #41. + + Add Joda-Convert annotations. + The additional Joda-Convert dependency is optional (except that on Scala it is apparently mandatory). + Add Tidelift commercial support and security policy. diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 7065602a..60a3e7a6 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -39,6 +39,9 @@ */ module org.threeten.extra { + // only annotations are used, thus they are optional + requires static org.joda.convert; + // export all packages exports org.threeten.extra; exports org.threeten.extra.chrono; diff --git a/src/main/java/org/threeten/extra/Days.java b/src/main/java/org/threeten/extra/Days.java index 8f341f2d..d6eb9340 100644 --- a/src/main/java/org/threeten/extra/Days.java +++ b/src/main/java/org/threeten/extra/Days.java @@ -48,6 +48,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.joda.convert.FromString; +import org.joda.convert.ToString; + /** * A day-based amount of time, such as '12 days'. *

    @@ -203,6 +206,7 @@ public static Days from(TemporalAmount amount) { * @return the parsed period, not null * @throws DateTimeParseException if the text cannot be parsed to a period */ + @FromString public static Days parse(CharSequence text) { Objects.requireNonNull(text, "text"); Matcher matcher = PATTERN.matcher(text); @@ -574,6 +578,7 @@ public int hashCode() { * @return the number of days in ISO-8601 string format */ @Override + @ToString public String toString() { return "P" + days + "D"; } diff --git a/src/main/java/org/threeten/extra/Hours.java b/src/main/java/org/threeten/extra/Hours.java index 38cb0d82..ef6734de 100644 --- a/src/main/java/org/threeten/extra/Hours.java +++ b/src/main/java/org/threeten/extra/Hours.java @@ -48,6 +48,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.joda.convert.FromString; +import org.joda.convert.ToString; + /** * A hour-based amount of time, such as '4 hours'. *

    @@ -186,6 +189,7 @@ public static Hours from(TemporalAmount amount) { * @return the parsed period, not null * @throws DateTimeParseException if the text cannot be parsed to a period */ + @FromString public static Hours parse(CharSequence text) { Objects.requireNonNull(text, "text"); Matcher matcher = PATTERN.matcher(text); @@ -570,6 +574,7 @@ public int hashCode() { * @return the number of hours in ISO-8601 string format */ @Override + @ToString public String toString() { return "PT" + hours + "H"; } diff --git a/src/main/java/org/threeten/extra/Interval.java b/src/main/java/org/threeten/extra/Interval.java index f2f4b52c..a1fb689c 100644 --- a/src/main/java/org/threeten/extra/Interval.java +++ b/src/main/java/org/threeten/extra/Interval.java @@ -43,6 +43,9 @@ import java.time.temporal.TemporalAccessor; import java.util.Objects; +import org.joda.convert.FromString; +import org.joda.convert.ToString; + /** * An immutable interval of time between two instants. *

    @@ -150,6 +153,7 @@ public static Interval of(Instant startInclusive, Duration duration) { * @return the parsed interval, not null * @throws DateTimeParseException if the text cannot be parsed */ + @FromString public static Interval parse(CharSequence text) { Objects.requireNonNull(text, "text"); for (int i = 0; i < text.length(); i++) { @@ -589,6 +593,7 @@ public int hashCode() { * @return a string representation of this instant, not null */ @Override + @ToString public String toString() { return start.toString() + '/' + end.toString(); } diff --git a/src/main/java/org/threeten/extra/LocalDateRange.java b/src/main/java/org/threeten/extra/LocalDateRange.java index f5697651..b8991df3 100644 --- a/src/main/java/org/threeten/extra/LocalDateRange.java +++ b/src/main/java/org/threeten/extra/LocalDateRange.java @@ -45,6 +45,9 @@ import java.util.stream.Stream; import java.util.stream.StreamSupport; +import org.joda.convert.FromString; +import org.joda.convert.ToString; + /** * A range of local dates. *

    @@ -258,6 +261,7 @@ public static LocalDateRange ofUnboundedEnd(LocalDate startInclusive) { * @return the parsed range, not null * @throws DateTimeParseException if the text cannot be parsed */ + @FromString public static LocalDateRange parse(CharSequence text) { Objects.requireNonNull(text, "text"); for (int i = 0; i < text.length(); i++) { @@ -761,6 +765,7 @@ public int hashCode() { * @return a string representation of this date, not null */ @Override + @ToString public String toString() { return start.toString() + '/' + end.toString(); } diff --git a/src/main/java/org/threeten/extra/Minutes.java b/src/main/java/org/threeten/extra/Minutes.java index e804aaa2..24b1ddcf 100644 --- a/src/main/java/org/threeten/extra/Minutes.java +++ b/src/main/java/org/threeten/extra/Minutes.java @@ -48,6 +48,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.joda.convert.FromString; +import org.joda.convert.ToString; + /** * A minute-based amount of time, such as '8 minutes'. *

    @@ -211,6 +214,7 @@ public static Minutes from(TemporalAmount amount) { * @return the parsed period, not null * @throws DateTimeParseException if the text cannot be parsed to a period */ + @FromString public static Minutes parse(CharSequence text) { Objects.requireNonNull(text, "text"); Matcher matcher = PATTERN.matcher(text); @@ -590,6 +594,7 @@ public int hashCode() { * @return the number of minutes in ISO-8601 string format */ @Override + @ToString public String toString() { return "PT" + minutes + "M"; } diff --git a/src/main/java/org/threeten/extra/Months.java b/src/main/java/org/threeten/extra/Months.java index 85fb1568..635f332d 100644 --- a/src/main/java/org/threeten/extra/Months.java +++ b/src/main/java/org/threeten/extra/Months.java @@ -48,6 +48,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.joda.convert.FromString; +import org.joda.convert.ToString; + /** * A month-based amount of time, such as '12 months'. *

    @@ -203,6 +206,7 @@ public static Months from(TemporalAmount amount) { * @return the parsed period, not null * @throws DateTimeParseException if the text cannot be parsed to a period */ + @FromString public static Months parse(CharSequence text) { Objects.requireNonNull(text, "text"); Matcher matcher = PATTERN.matcher(text); @@ -574,6 +578,7 @@ public int hashCode() { * @return the number of months in ISO-8601 string format */ @Override + @ToString public String toString() { return "P" + months + "M"; } diff --git a/src/main/java/org/threeten/extra/PeriodDuration.java b/src/main/java/org/threeten/extra/PeriodDuration.java index 6be9247a..136a1944 100644 --- a/src/main/java/org/threeten/extra/PeriodDuration.java +++ b/src/main/java/org/threeten/extra/PeriodDuration.java @@ -59,6 +59,9 @@ import java.util.Locale; import java.util.Objects; +import org.joda.convert.FromString; +import org.joda.convert.ToString; + /** * An amount of time in the ISO-8601 calendar system that combines a period and a duration. *

    @@ -268,6 +271,7 @@ public static PeriodDuration from(TemporalAmount amount) { * @return the parsed period, not null * @throws DateTimeParseException if the text cannot be parsed to a period */ + @FromString public static PeriodDuration parse(CharSequence text) { Objects.requireNonNull(text, "text"); String upper = text.toString().toUpperCase(Locale.ENGLISH); @@ -656,6 +660,7 @@ public int hashCode() { * @return the period in ISO-8601 string format */ @Override + @ToString public String toString() { if (period.isZero()) { return duration.toString(); diff --git a/src/main/java/org/threeten/extra/Seconds.java b/src/main/java/org/threeten/extra/Seconds.java index ce9ceaae..5eac789b 100644 --- a/src/main/java/org/threeten/extra/Seconds.java +++ b/src/main/java/org/threeten/extra/Seconds.java @@ -48,6 +48,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.joda.convert.FromString; +import org.joda.convert.ToString; + /** * A second-based amount of time, such as '8 seconds'. *

    @@ -237,6 +240,7 @@ public static Seconds from(TemporalAmount amount) { * @return the parsed period, not null * @throws DateTimeParseException if the text cannot be parsed to a period */ + @FromString public static Seconds parse(CharSequence text) { Objects.requireNonNull(text, "text"); Matcher matcher = PATTERN.matcher(text); @@ -625,6 +629,7 @@ public int hashCode() { * @return the number of seconds in ISO-8601 string format */ @Override + @ToString public String toString() { return "PT" + seconds + "S"; } diff --git a/src/main/java/org/threeten/extra/Weeks.java b/src/main/java/org/threeten/extra/Weeks.java index e1494e0d..45d01b9a 100644 --- a/src/main/java/org/threeten/extra/Weeks.java +++ b/src/main/java/org/threeten/extra/Weeks.java @@ -48,6 +48,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.joda.convert.FromString; +import org.joda.convert.ToString; + /** * A week-based amount of time, such as '12 weeks'. *

    @@ -173,6 +176,7 @@ public static Weeks from(TemporalAmount amount) { * @return the parsed period, not null * @throws DateTimeParseException if the text cannot be parsed to a period */ + @FromString public static Weeks parse(CharSequence text) { Objects.requireNonNull(text, "text"); Matcher matcher = PATTERN.matcher(text); @@ -530,6 +534,7 @@ public int hashCode() { * @return the number of weeks in ISO-8601 string format */ @Override + @ToString public String toString() { return "P" + weeks + "W"; } diff --git a/src/main/java/org/threeten/extra/YearQuarter.java b/src/main/java/org/threeten/extra/YearQuarter.java index b930c070..25ee1a46 100644 --- a/src/main/java/org/threeten/extra/YearQuarter.java +++ b/src/main/java/org/threeten/extra/YearQuarter.java @@ -72,6 +72,9 @@ import java.time.temporal.ValueRange; import java.util.Objects; +import org.joda.convert.FromString; +import org.joda.convert.ToString; + /** * A year-quarter in the ISO-8601 calendar system, such as {@code 2007-Q2}. *

    @@ -251,6 +254,7 @@ public static YearQuarter from(TemporalAccessor temporal) { * @return the parsed year-quarter, not null * @throws DateTimeParseException if the text cannot be parsed */ + @FromString public static YearQuarter parse(CharSequence text) { return parse(text, PARSER); } @@ -1222,6 +1226,7 @@ public int hashCode() { * @return a string representation of this year-quarter, not null */ @Override + @ToString public String toString() { int absYear = Math.abs(year); StringBuilder buf = new StringBuilder(10); diff --git a/src/main/java/org/threeten/extra/YearWeek.java b/src/main/java/org/threeten/extra/YearWeek.java index 3377a548..d82bf2d7 100644 --- a/src/main/java/org/threeten/extra/YearWeek.java +++ b/src/main/java/org/threeten/extra/YearWeek.java @@ -61,6 +61,9 @@ import java.time.temporal.ValueRange; import java.util.Objects; +import org.joda.convert.FromString; +import org.joda.convert.ToString; + /** * A year-week in the ISO week date system such as {@code 2015-W13} *

    @@ -248,6 +251,7 @@ public static YearWeek from(TemporalAccessor temporal) { * @return the parsed year-week, not null * @throws DateTimeParseException if the text cannot be parsed */ + @FromString public static YearWeek parse(CharSequence text) { return parse(text, PARSER); } @@ -770,6 +774,7 @@ public int hashCode() { * @return a string representation of this year-week, not null */ @Override + @ToString public String toString() { int absYear = Math.abs(year); StringBuilder buf = new StringBuilder(10); diff --git a/src/main/java/org/threeten/extra/Years.java b/src/main/java/org/threeten/extra/Years.java index a31f1531..49578850 100644 --- a/src/main/java/org/threeten/extra/Years.java +++ b/src/main/java/org/threeten/extra/Years.java @@ -48,6 +48,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.joda.convert.FromString; +import org.joda.convert.ToString; + /** * A year-based amount of time, such as '12 years'. *

    @@ -173,6 +176,7 @@ public static Years from(TemporalAmount amount) { * @return the parsed period, not null * @throws DateTimeParseException if the text cannot be parsed to a period */ + @FromString public static Years parse(CharSequence text) { Objects.requireNonNull(text, "text"); Matcher matcher = PATTERN.matcher(text); @@ -530,6 +534,7 @@ public int hashCode() { * @return the number of years in ISO-8601 string format */ @Override + @ToString public String toString() { return "P" + years + "Y"; } diff --git a/src/main/java/org/threeten/extra/scale/TaiInstant.java b/src/main/java/org/threeten/extra/scale/TaiInstant.java index e4bb7e5a..970abb8e 100644 --- a/src/main/java/org/threeten/extra/scale/TaiInstant.java +++ b/src/main/java/org/threeten/extra/scale/TaiInstant.java @@ -40,6 +40,9 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.joda.convert.FromString; +import org.joda.convert.ToString; + /** * An instantaneous point on the time-line measured in the TAI time-scale. *

    @@ -195,6 +198,7 @@ public static TaiInstant of(UtcInstant instant) { * @return the parsed instant, not null * @throws DateTimeParseException if the text cannot be parsed */ + @FromString public static TaiInstant parse(CharSequence text) { Objects.requireNonNull(text, "text"); Matcher matcher = PARSER.matcher(text); @@ -452,6 +456,7 @@ public int hashCode() { * @return a representation of this instant, not null */ @Override + @ToString public String toString() { StringBuilder buf = new StringBuilder(); buf.append(seconds); diff --git a/src/main/java/org/threeten/extra/scale/UtcInstant.java b/src/main/java/org/threeten/extra/scale/UtcInstant.java index 0607e60d..200838f2 100644 --- a/src/main/java/org/threeten/extra/scale/UtcInstant.java +++ b/src/main/java/org/threeten/extra/scale/UtcInstant.java @@ -47,6 +47,9 @@ import java.time.temporal.JulianFields; import java.time.temporal.TemporalAccessor; +import org.joda.convert.FromString; +import org.joda.convert.ToString; + /** * An instantaneous point on the time-line measured in the UTC time-scale * with leap seconds. @@ -203,6 +206,7 @@ public static UtcInstant of(TaiInstant instant) { * @throws DateTimeParseException if the text cannot be parsed * @throws DateTimeException if parsed text represents an invalid leap second */ + @FromString public static UtcInstant parse(CharSequence text) { TemporalAccessor parsed = DateTimeFormatter.ISO_INSTANT.parse(text); long epochSecond = parsed.getLong(INSTANT_SECONDS); @@ -461,6 +465,7 @@ public int hashCode() { * @return a representation of this instant, not null */ @Override + @ToString public String toString() { LocalDate date = LocalDate.MAX.with(JulianFields.MODIFIED_JULIAN_DAY, mjDay); // TODO: capacity/import issues StringBuilder buf = new StringBuilder(30); diff --git a/src/test/java/org/threeten/extra/TestConvert.java b/src/test/java/org/threeten/extra/TestConvert.java new file mode 100644 index 00000000..23aa9518 --- /dev/null +++ b/src/test/java/org/threeten/extra/TestConvert.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.extra; + +import static org.junit.Assert.assertEquals; + +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDate; +import java.time.Period; + +import org.joda.convert.StringConvert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.threeten.extra.scale.TaiInstant; +import org.threeten.extra.scale.UtcInstant; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; + +@RunWith(DataProviderRunner.class) +public class TestConvert { + + @DataProvider + public static Object[][] data_inputs() { + return new Object[][] { + {Seconds.of(23), "PT23S"}, + {Minutes.of(23), "PT23M"}, + {Hours.of(23), "PT23H"}, + {Days.of(23), "P23D"}, + {Weeks.of(23), "P23W"}, + {Months.of(23), "P23M"}, + {Years.of(23), "P23Y"}, + {YearWeek.of(2019, 3), "2019-W03"}, + {YearQuarter.of(2019, 3), "2019-Q3"}, + {PeriodDuration.of(Period.of(1, 2, 3), Duration.ofHours(6)), "P1Y2M3DT6H"}, + {Interval.of(Instant.ofEpochSecond(60), Duration.ofHours(6)), "1970-01-01T00:01:00Z/1970-01-01T06:01:00Z"}, + {LocalDateRange.of(LocalDate.of(2018, 6, 1), LocalDate.of(2018, 9, 15)), "2018-06-01/2018-09-15"}, + {TaiInstant.ofTaiSeconds(123, 456), "123.000000456s(TAI)"}, + {UtcInstant.ofModifiedJulianDay(0, 1123456789L), "1858-11-17T00:00:01.123456789Z"}, + }; + } + + @Test + @UseDataProvider("data_inputs") + public void test_convertToString(Object obj, String str) { + assertEquals(str, StringConvert.INSTANCE.convertToString(obj)); + } + + @Test + @UseDataProvider("data_inputs") + public void test_convertFromString(Object obj, String str) { + assertEquals(obj, StringConvert.INSTANCE.convertFromString(obj.getClass(), str)); + } + +} From 432c01a8cae7ca309291da788509695ca91acec3 Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Sun, 20 Jan 2019 09:15:49 +0000 Subject: [PATCH 107/279] Reformat license (no change to the legal terms) The project license is BSD 3 clause GitHub/SPDX auto license analysis did not match the license This commit simply reformats the license file so it matches There is no change in the legal terms --- LICENSE.txt | 60 ++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index fcdfc8f0..f8f6e594 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,31 +1,29 @@ -/* - * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of JSR-310 nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ +Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos. + +All rights reserved. + +* Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of JSR-310 nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. From 7b41227b7d9e8a6e4b0994d72979594f595d52ae Mon Sep 17 00:00:00 2001 From: monicagg Date: Thu, 24 Jan 2019 14:33:28 +0000 Subject: [PATCH 108/279] Add method quartersUntil for YearQuarter, including tests --- .../java/org/threeten/extra/YearQuarter.java | 20 +++++++++++ .../org/threeten/extra/TestYearQuarter.java | 35 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/src/main/java/org/threeten/extra/YearQuarter.java b/src/main/java/org/threeten/extra/YearQuarter.java index 25ee1a46..67dc8658 100644 --- a/src/main/java/org/threeten/extra/YearQuarter.java +++ b/src/main/java/org/threeten/extra/YearQuarter.java @@ -71,6 +71,8 @@ import java.time.temporal.UnsupportedTemporalTypeException; import java.time.temporal.ValueRange; import java.util.Objects; +import java.util.stream.LongStream; +import java.util.stream.Stream; import org.joda.convert.FromString; import org.joda.convert.ToString; @@ -1085,6 +1087,24 @@ public long until(Temporal endExclusive, TemporalUnit unit) { return unit.between(this, end); } + /** + * Returns a sequential ordered stream of year-quarter. The returned stream starts from this year-quarter + * (inclusive) and goes to {@code endExclusive} (exclusive) by an incremental step of 1 {@code QUARTER_YEARS}. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param endExclusive the end year-quarter, exclusive, not null + * @return a sequential {@code Stream} for the range of {@code YearQuarter} values + * @throws IllegalArgumentException if end year-quarter is before this year-quarter + */ + public Stream quartersUntil(YearQuarter endExclusive) { + if (endExclusive.isBefore(this)) { + throw new IllegalArgumentException(endExclusive + " < " + this); + } + long intervalLength = until(endExclusive, QUARTER_YEARS); + return LongStream.range(0,intervalLength).mapToObj(n -> plusQuarters(n)); + } + /** * Formats this year-quarter using the specified formatter. *

    diff --git a/src/test/java/org/threeten/extra/TestYearQuarter.java b/src/test/java/org/threeten/extra/TestYearQuarter.java index 86694d37..92accc9a 100644 --- a/src/test/java/org/threeten/extra/TestYearQuarter.java +++ b/src/test/java/org/threeten/extra/TestYearQuarter.java @@ -106,6 +106,10 @@ import java.time.temporal.TemporalUnit; import java.time.temporal.UnsupportedTemporalTypeException; import java.time.temporal.ValueRange; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.junit.Test; @@ -738,6 +742,37 @@ public void test_until_TemporalTemporalUnit_nullTemporalUnit() { YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q3), null); } + //----------------------------------------------------------------------- + // quartersUntil(YearQuarter) + //----------------------------------------------------------------------- + @Test(expected = NullPointerException.class) + public void test_quartersUntil_null() { + YearQuarter.of(2012, Q2).quartersUntil(null); + } + + @Test(expected = IllegalArgumentException.class) + public void test_quartersUntil_IllegalArgument() { + YearQuarter.of(2012, Q2).quartersUntil(YearQuarter.of(2012, Q1)); + } + + @Test + public void test_quartersUntil() { + assertEquals(2, YearQuarter.of(2012, Q2).quartersUntil(YearQuarter.of(2012, Q4)).count()); + assertEquals(10, YearQuarter.of(2012, Q2).quartersUntil(YearQuarter.of(2014, Q4)).count()); + + YearQuarter start = YearQuarter.of(2012, Q1); + YearQuarter end = YearQuarter.of(2013, Q3); + Stream stream = start.quartersUntil(end); + + List expects = Arrays.asList(YearQuarter.of(start.getYear(), Q1), + YearQuarter.of(start.getYear(), Q2), + YearQuarter.of(start.getYear(), Q3), + YearQuarter.of(start.getYear(), Q4), + YearQuarter.of(end.getYear(), Q1), + YearQuarter.of(end.getYear(), Q2)); + assertEquals(expects, stream.collect(Collectors.toList())); + } + //----------------------------------------------------------------------- // format(DateTimeFormatter) //----------------------------------------------------------------------- From 3a187e1b0339c5dfd27ebfd13ec9dbb09b62a179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Octavi=20Forn=C3=A9s?= Date: Fri, 8 Feb 2019 10:09:16 +0100 Subject: [PATCH 109/279] Addedd catalan translation --- .../threeten/extra/wordbased_ca.properties | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/resources/org/threeten/extra/wordbased_ca.properties diff --git a/src/main/resources/org/threeten/extra/wordbased_ca.properties b/src/main/resources/org/threeten/extra/wordbased_ca.properties new file mode 100644 index 00000000..fd4ef65f --- /dev/null +++ b/src/main/resources/org/threeten/extra/wordbased_ca.properties @@ -0,0 +1,22 @@ +WordBased.space=\ +WordBased.comma=, +WordBased.commandand=,i +WordBased.commaspaceand=, i +WordBased.commaspace=, +WordBased.spaceandspace=\ i +WordBased.year=\ any +WordBased.years=\ anys +WordBased.month=\ mes +WordBased.months=\ mesos +WordBased.week=\ setmana +WordBased.weeks=\ setmanes +WordBased.day=\ dia +WordBased.days=\ dies +WordBased.hour=\ hora +WordBased.hours=\ hores +WordBased.minute=\ minut +WordBased.minutes=\ minuts +WordBased.second=\ segon +WordBased.seconds=\ segons +WordBased.millisecond=\ milisegon +WordBased.milliseconds=\ milisegons From fe3db2ac60341af15ef7a4c8a520b8064066bbe9 Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Sat, 23 Feb 2019 21:59:34 +0000 Subject: [PATCH 110/279] Update after PR to add Catalan translation Fixes #123 --- pom.xml | 4 ++++ src/changes/changes.xml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/pom.xml b/pom.xml index a3347e7f..a187baa8 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,10 @@ Carlo Dapor https://github.com/catull + + Octavi Fornés + https://github.com/ofornes + Jim Gough https://github.com/jpgough diff --git a/src/changes/changes.xml b/src/changes/changes.xml index ad8e5a7f..9831e302 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -8,6 +8,10 @@ + + Add Catalan translation. + Fixes #123. + Add word-based period formatting. Note that textual data can only be altered by PRs to ThreeTen-Extra. From 65b00fa852379af5960298b938aa412835f44c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Octavi=20Forn=C3=A9s?= Date: Fri, 8 Feb 2019 10:09:16 +0100 Subject: [PATCH 111/279] Addedd catalan translation --- .../threeten/extra/wordbased_ca.properties | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/resources/org/threeten/extra/wordbased_ca.properties diff --git a/src/main/resources/org/threeten/extra/wordbased_ca.properties b/src/main/resources/org/threeten/extra/wordbased_ca.properties new file mode 100644 index 00000000..fd4ef65f --- /dev/null +++ b/src/main/resources/org/threeten/extra/wordbased_ca.properties @@ -0,0 +1,22 @@ +WordBased.space=\ +WordBased.comma=, +WordBased.commandand=,i +WordBased.commaspaceand=, i +WordBased.commaspace=, +WordBased.spaceandspace=\ i +WordBased.year=\ any +WordBased.years=\ anys +WordBased.month=\ mes +WordBased.months=\ mesos +WordBased.week=\ setmana +WordBased.weeks=\ setmanes +WordBased.day=\ dia +WordBased.days=\ dies +WordBased.hour=\ hora +WordBased.hours=\ hores +WordBased.minute=\ minut +WordBased.minutes=\ minuts +WordBased.second=\ segon +WordBased.seconds=\ segons +WordBased.millisecond=\ milisegon +WordBased.milliseconds=\ milisegons From 119c83a0874e63a98cefeaea64a2b56a70d8d58f Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Sat, 23 Feb 2019 21:59:34 +0000 Subject: [PATCH 112/279] Update after PR to add Catalan translation Fixes #123 --- pom.xml | 4 ++++ src/changes/changes.xml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/pom.xml b/pom.xml index a3347e7f..a187baa8 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,10 @@ Carlo Dapor https://github.com/catull + + Octavi Fornés + https://github.com/ofornes + Jim Gough https://github.com/jpgough diff --git a/src/changes/changes.xml b/src/changes/changes.xml index ad8e5a7f..9831e302 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -8,6 +8,10 @@ + + Add Catalan translation. + Fixes #123. + Add word-based period formatting. Note that textual data can only be altered by PRs to ThreeTen-Extra. From 9a28b48948c5eaf8c36b7ca9f9096fef53410a4c Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Sat, 23 Feb 2019 22:27:34 +0000 Subject: [PATCH 113/279] Add YearQuarter.quartersUntil(YearQuarter) Allow streaming over quarters Fixes #122 --- src/changes/changes.xml | 4 ++ .../java/org/threeten/extra/YearQuarter.java | 14 +++---- .../org/threeten/extra/TestYearQuarter.java | 37 ++++++++++--------- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 9831e302..24478ccd 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -8,6 +8,10 @@ + + Add stream-returning method YearQuarter.quartersUntil(YearQuarter). + Fixes #122. + Add Catalan translation. Fixes #123. diff --git a/src/main/java/org/threeten/extra/YearQuarter.java b/src/main/java/org/threeten/extra/YearQuarter.java index 67dc8658..625726d9 100644 --- a/src/main/java/org/threeten/extra/YearQuarter.java +++ b/src/main/java/org/threeten/extra/YearQuarter.java @@ -1089,7 +1089,7 @@ public long until(Temporal endExclusive, TemporalUnit unit) { /** * Returns a sequential ordered stream of year-quarter. The returned stream starts from this year-quarter - * (inclusive) and goes to {@code endExclusive} (exclusive) by an incremental step of 1 {@code QUARTER_YEARS}. + * (inclusive) and goes to {@code endExclusive} (exclusive) by an incremental step of 1 {@code QUARTER_YEARS}. *

    * This instance is immutable and unaffected by this method call. * @@ -1098,13 +1098,13 @@ public long until(Temporal endExclusive, TemporalUnit unit) { * @throws IllegalArgumentException if end year-quarter is before this year-quarter */ public Stream quartersUntil(YearQuarter endExclusive) { - if (endExclusive.isBefore(this)) { - throw new IllegalArgumentException(endExclusive + " < " + this); - } - long intervalLength = until(endExclusive, QUARTER_YEARS); - return LongStream.range(0,intervalLength).mapToObj(n -> plusQuarters(n)); + if (endExclusive.isBefore(this)) { + throw new IllegalArgumentException(endExclusive + " < " + this); + } + long intervalLength = until(endExclusive, QUARTER_YEARS); + return LongStream.range(0,intervalLength).mapToObj(n -> plusQuarters(n)); } - + /** * Formats this year-quarter using the specified formatter. *

    diff --git a/src/test/java/org/threeten/extra/TestYearQuarter.java b/src/test/java/org/threeten/extra/TestYearQuarter.java index 92accc9a..64f35506 100644 --- a/src/test/java/org/threeten/extra/TestYearQuarter.java +++ b/src/test/java/org/threeten/extra/TestYearQuarter.java @@ -749,30 +749,31 @@ public void test_until_TemporalTemporalUnit_nullTemporalUnit() { public void test_quartersUntil_null() { YearQuarter.of(2012, Q2).quartersUntil(null); } - + @Test(expected = IllegalArgumentException.class) public void test_quartersUntil_IllegalArgument() { YearQuarter.of(2012, Q2).quartersUntil(YearQuarter.of(2012, Q1)); } - + @Test public void test_quartersUntil() { - assertEquals(2, YearQuarter.of(2012, Q2).quartersUntil(YearQuarter.of(2012, Q4)).count()); - assertEquals(10, YearQuarter.of(2012, Q2).quartersUntil(YearQuarter.of(2014, Q4)).count()); - - YearQuarter start = YearQuarter.of(2012, Q1); - YearQuarter end = YearQuarter.of(2013, Q3); - Stream stream = start.quartersUntil(end); - - List expects = Arrays.asList(YearQuarter.of(start.getYear(), Q1), - YearQuarter.of(start.getYear(), Q2), - YearQuarter.of(start.getYear(), Q3), - YearQuarter.of(start.getYear(), Q4), - YearQuarter.of(end.getYear(), Q1), - YearQuarter.of(end.getYear(), Q2)); - assertEquals(expects, stream.collect(Collectors.toList())); - } - + assertEquals(2, YearQuarter.of(2012, Q2).quartersUntil(YearQuarter.of(2012, Q4)).count()); + assertEquals(10, YearQuarter.of(2012, Q2).quartersUntil(YearQuarter.of(2014, Q4)).count()); + + YearQuarter start = YearQuarter.of(2012, Q1); + YearQuarter end = YearQuarter.of(2013, Q3); + Stream stream = start.quartersUntil(end); + + List expects = Arrays.asList( + YearQuarter.of(start.getYear(), Q1), + YearQuarter.of(start.getYear(), Q2), + YearQuarter.of(start.getYear(), Q3), + YearQuarter.of(start.getYear(), Q4), + YearQuarter.of(end.getYear(), Q1), + YearQuarter.of(end.getYear(), Q2)); + assertEquals(expects, stream.collect(Collectors.toList())); + } + //----------------------------------------------------------------------- // format(DateTimeFormatter) //----------------------------------------------------------------------- From 7ada02d50d52b117d6e0cc1e620dc492810de9b9 Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Sun, 24 Feb 2019 11:53:54 +0000 Subject: [PATCH 114/279] Test on module-path and class-path Update pom versions --- pom.xml | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index a187baa8..13b5bdf8 100644 --- a/pom.xml +++ b/pom.xml @@ -656,9 +656,25 @@ org.apache.maven.plugins maven-surefire-plugin - - --add-modules org.joda.convert --module-path ${project.build.directory}/dependencies ${argLine} - + + + default-test + + true + --add-modules org.joda.convert --module-path ${project.build.directory}/dependencies ${argLine} + + + + test-without-modules + test + + test + + + false + + + @@ -799,36 +815,36 @@ - 3.1.0 + 3.1.1 4.1.0 2.12.1 2.17 3.1.0 3.8.0 - 2.8.2 + 3.0.0-M1 3.1.1 3.0.0-M2 1.6 - 2.5.2 - 3.1.0 + 3.0.0-M1 + 3.1.1 3.0.1 - 2.5 - 3.5.2 - 3.10.0 + 3.0.0 + 3.6.0 + 3.11.0 3.0.0 2.5.3 2.4 3.1.0 3.7.1 3.0.1 - 2.22.1 - 2.22.1 + 3.0.0-M3 + 3.0.0-M3 1.1 4.1.0 - 0.8.2 + 0.8.3 1.6.8 - 3.1.9 + 3.1.11 1.8 1.8 @@ -839,7 +855,7 @@ true none - 8.12 + 8.17 src/main/checkstyle/checkstyle.xml false From 9dd6120b73c35ece6be637ce1d431bdd2903b9ae Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Sun, 24 Feb 2019 12:47:05 +0000 Subject: [PATCH 115/279] Prepare for release v1.5.0 --- README.md | 2 +- pom.xml | 2 +- src/changes/changes.xml | 10 +++++----- src/site/markdown/index.md | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0fe91cde..50d006d7 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Various documentation is available: ### Releases -Release 1.4 is the current release. +Release 1.5.0 is the current release. This release is considered stable and worthy of the 1.x tag. ThreeTen-Extra requires Java SE 8 or later and has no dependencies. diff --git a/pom.xml b/pom.xml index 13b5bdf8..b2c239b1 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.4.1-SNAPSHOT + 1.5.0-SNAPSHOT Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later https://www.threeten.org/threeten-extra diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 24478ccd..64435e16 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,21 +7,21 @@ - + Add stream-returning method YearQuarter.quartersUntil(YearQuarter). Fixes #122. - - Add Catalan translation. - Fixes #123. - Add word-based period formatting. Note that textual data can only be altered by PRs to ThreeTen-Extra. Based on original code from Joda-Time. Fixes #113, #41. + + Add Catalan translation for word-based formatting. + Fixes #123. + Add Joda-Convert annotations. The additional Joda-Convert dependency is optional (except that on Scala it is apparently mandatory). diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index 1eaecff2..886510d7 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -48,7 +48,7 @@ Various documentation is available: ## Releases -Release 1.4 is the current release. +Release 1.5.0 is the current release. This release is considered stable and worthy of the 1.x tag. ThreeTen-Extra requires Java SE 8 or later and has no [dependencies](dependencies.html). @@ -59,7 +59,7 @@ Available in [Maven Central](https://search.maven.org/search?q=g:org.threeten%20 org.threeten threeten-extra - 1.4 + 1.5.0 ``` From b92b352ceed45194b7d2cdce0844da6c27d81ce5 Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Sun, 24 Feb 2019 12:53:53 +0000 Subject: [PATCH 116/279] [maven-release-plugin] prepare release v1.5.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b2c239b1..ad3762c6 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.5.0-SNAPSHOT + 1.5.0 Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later https://www.threeten.org/threeten-extra @@ -100,7 +100,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git https://github.com/ThreeTen/threeten-extra - HEAD + v1.5.0 ThreeTen.org From 772c1465618da0ab802733c96d3a071c8160a5b0 Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Sun, 24 Feb 2019 12:54:10 +0000 Subject: [PATCH 117/279] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index ad3762c6..70eecfc9 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.5.0 + 1.5.1-SNAPSHOT Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later https://www.threeten.org/threeten-extra @@ -100,7 +100,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git https://github.com/ThreeTen/threeten-extra - v1.5.0 + HEAD ThreeTen.org From 8fbc10c1e1c9054f1e76829d265f5ebb47ac3676 Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Sun, 24 Feb 2019 14:08:00 +0000 Subject: [PATCH 118/279] Add Catalan to languages in user guide --- src/site/markdown/userguide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/site/markdown/userguide.md b/src/site/markdown/userguide.md index 385cc8ac..a23142eb 100644 --- a/src/site/markdown/userguide.md +++ b/src/site/markdown/userguide.md @@ -34,7 +34,7 @@ A simple mechanism is provided here in [`AmountFormats`](apidocs/org.threeten.ex // output: "1 year, 6 months and 5 days" ``` -Translations are provided for cs, da, de, en, es, fr, it, ja, nl, pl, pt, ro, ru, tr. +Translations are provided for ca, cs, da, de, en, es, fr, it, ja, nl, pl, pt, ro, ru, tr. Feel free to raise PRs for other languages. From 66be11395ebb7e466f32bb21a285d8198732e8a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 25 Feb 2019 11:51:23 +0100 Subject: [PATCH 119/279] =?UTF-8?q?Add=20Norwegian=20Bokm=C3=A5l=20and=20N?= =?UTF-8?q?orwegian=20Nynorsk=20translations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../threeten/extra/wordbased_nb.properties | 22 +++++++++++++++++++ .../threeten/extra/wordbased_nn.properties | 22 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/main/resources/org/threeten/extra/wordbased_nb.properties create mode 100644 src/main/resources/org/threeten/extra/wordbased_nn.properties diff --git a/src/main/resources/org/threeten/extra/wordbased_nb.properties b/src/main/resources/org/threeten/extra/wordbased_nb.properties new file mode 100644 index 00000000..93c587e9 --- /dev/null +++ b/src/main/resources/org/threeten/extra/wordbased_nb.properties @@ -0,0 +1,22 @@ +WordBased.space=\ +WordBased.comma=, +WordBased.commandand=,og +WordBased.commaspaceand=, og +WordBased.commaspace=, +WordBased.spaceandspace=\ og +WordBased.year=\ Ã¥r +WordBased.years=\ Ã¥r +WordBased.month=\ mÃ¥ned +WordBased.months=\ mÃ¥neder +WordBased.week=\ uke +WordBased.weeks=\ uker +WordBased.day=\ dag +WordBased.days=\ dager +WordBased.hour=\ time +WordBased.hours=\ timer +WordBased.minute=\ minutt +WordBased.minutes=\ minutt +WordBased.second=\ sekund +WordBased.seconds=\ sekund +WordBased.millisecond=\ millisekund +WordBased.milliseconds=\ millisekund diff --git a/src/main/resources/org/threeten/extra/wordbased_nn.properties b/src/main/resources/org/threeten/extra/wordbased_nn.properties new file mode 100644 index 00000000..12dc8f24 --- /dev/null +++ b/src/main/resources/org/threeten/extra/wordbased_nn.properties @@ -0,0 +1,22 @@ +WordBased.space=\ +WordBased.comma=, +WordBased.commandand=,og +WordBased.commaspaceand=, og +WordBased.commaspace=, +WordBased.spaceandspace=\ og +WordBased.year=\ Ã¥r +WordBased.years=\ Ã¥r +WordBased.month=\ mÃ¥nad +WordBased.months=\ mÃ¥nader +WordBased.week=\ veke +WordBased.weeks=\ veker +WordBased.day=\ dag +WordBased.days=\ dagar +WordBased.hour=\ time +WordBased.hours=\ timar +WordBased.minute=\ minutt +WordBased.minutes=\ minutt +WordBased.second=\ sekund +WordBased.seconds=\ sekund +WordBased.millisecond=\ millisekund +WordBased.milliseconds=\ millisekund From f1aa003a27ead6976122ebdf0c79c7a838bf8db8 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 25 Feb 2019 11:47:51 +0000 Subject: [PATCH 120/279] Update users and change notes after PR --- pom.xml | 8 ++++++-- src/changes/changes.xml | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 70eecfc9..f4a0a0cf 100644 --- a/pom.xml +++ b/pom.xml @@ -75,11 +75,15 @@ https://github.com/steve-o - Bjorn Raupach + Bjørn Erik Pedersen + https://github.com/bep + + + Björn Raupach https://github.com/raupachz - Michal Sobkiewicz + MichaÅ‚ Sobkiewicz https://github.com/perceptron8 diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 64435e16..1bfe00f2 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,6 +7,12 @@ + + + Add Norwegian Bokmål and Norwegian Nynorsk translations for word-based formatting. + Fixes #125. + + Add stream-returning method YearQuarter.quartersUntil(YearQuarter). From 105add1a506ba34329ea593fa39a28251ea77643 Mon Sep 17 00:00:00 2001 From: Dimo Velev Date: Mon, 25 Feb 2019 22:03:49 +0100 Subject: [PATCH 121/279] Create wordbased_bg.properties --- .../threeten/extra/wordbased_bg.properties | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/resources/org/threeten/extra/wordbased_bg.properties diff --git a/src/main/resources/org/threeten/extra/wordbased_bg.properties b/src/main/resources/org/threeten/extra/wordbased_bg.properties new file mode 100644 index 00000000..c6b94a05 --- /dev/null +++ b/src/main/resources/org/threeten/extra/wordbased_bg.properties @@ -0,0 +1,22 @@ +WordBased.space=\ +WordBased.comma=, +WordBased.commandand=,и +WordBased.commaspaceand=, и +WordBased.commaspace=, +WordBased.spaceandspace=\ и +WordBased.year=\ година +WordBased.years=\ години +WordBased.month=\ меÑец +WordBased.months=\ меÑеца +WordBased.week=\ Ñедмица +WordBased.weeks=\ Ñедмици +WordBased.day=\ ден +WordBased.days=\ дни +WordBased.hour=\ Ñ‡Ð°Ñ +WordBased.hours=\ чаÑа +WordBased.minute=\ минута +WordBased.minutes=\ минути +WordBased.second=\ Ñекунда +WordBased.seconds=\ Ñекунди +WordBased.millisecond=\ милиÑекунда +WordBased.milliseconds=\ милиÑекунди From bc2f648305be0fb316af55f1de5c810bbb2f29c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20L=C3=B6vdahl?= Date: Mon, 25 Feb 2019 19:20:16 +0200 Subject: [PATCH 122/279] Add Swedish translation --- .../threeten/extra/wordbased_sv.properties | 22 +++++++++++++++++++ src/site/markdown/userguide.md | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/org/threeten/extra/wordbased_sv.properties diff --git a/src/main/resources/org/threeten/extra/wordbased_sv.properties b/src/main/resources/org/threeten/extra/wordbased_sv.properties new file mode 100644 index 00000000..cd0c10ee --- /dev/null +++ b/src/main/resources/org/threeten/extra/wordbased_sv.properties @@ -0,0 +1,22 @@ +WordBased.space=\ +WordBased.comma=, +WordBased.commandand=,och +WordBased.commaspaceand=, och +WordBased.commaspace=, +WordBased.spaceandspace=\ och +WordBased.year=\ Ã¥r +WordBased.years=\ Ã¥r +WordBased.month=\ mÃ¥nad +WordBased.months=\ mÃ¥nader +WordBased.week=\ vecka +WordBased.weeks=\ veckor +WordBased.day=\ dag +WordBased.days=\ dagar +WordBased.hour=\ timme +WordBased.hours=\ timmar +WordBased.minute=\ minut +WordBased.minutes=\ minuter +WordBased.second=\ sekund +WordBased.seconds=\ sekunder +WordBased.millisecond=\ millisekund +WordBased.milliseconds=\ millisekunder diff --git a/src/site/markdown/userguide.md b/src/site/markdown/userguide.md index a23142eb..2d58470a 100644 --- a/src/site/markdown/userguide.md +++ b/src/site/markdown/userguide.md @@ -34,7 +34,7 @@ A simple mechanism is provided here in [`AmountFormats`](apidocs/org.threeten.ex // output: "1 year, 6 months and 5 days" ``` -Translations are provided for ca, cs, da, de, en, es, fr, it, ja, nl, pl, pt, ro, ru, tr. +Translations are provided for ca, cs, da, de, en, es, fr, it, ja, nl, pl, pt, ro, ru, sv, tr. Feel free to raise PRs for other languages. From 45832a80dedc9c932d64df6850c3e7fc5e6ce3b0 Mon Sep 17 00:00:00 2001 From: Michel Schudel Date: Tue, 26 Feb 2019 15:09:13 +0100 Subject: [PATCH 123/279] Added support for Farsi language. Since the data providers already test the word construction, only one test data line was added to test for presence of the property file. --- .../threeten/extra/wordbased_fa.properties | 23 +++++++++++++++++++ .../org/threeten/extra/TestAmountFormats.java | 12 ++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 src/main/resources/org/threeten/extra/wordbased_fa.properties diff --git a/src/main/resources/org/threeten/extra/wordbased_fa.properties b/src/main/resources/org/threeten/extra/wordbased_fa.properties new file mode 100644 index 00000000..4edf3b06 --- /dev/null +++ b/src/main/resources/org/threeten/extra/wordbased_fa.properties @@ -0,0 +1,23 @@ +WordBased.space=\u0020 +WordBased.comma=, +WordBased.commandand=,\u0648 +WordBased.commaspaceand=, \u0648 +WordBased.commaspace=, +WordBased.spaceandspace=\ \u0648 +#In Farsi, to denote a time period or time duration is always in singular form, never plural. +WordBased.year=\ \u0633\u0627\u0644 +WordBased.years=\ \u0633\u0627\u0644 +WordBased.month=\ \u0645\u0627\u0647 +WordBased.months=\ \u0645\u0627\u0647 +WordBased.week=\ \u0647\u0641\u062A\u0647 +WordBased.weeks=\ \u0647\u0641\u062A\u0647 +WordBased.day=\ \u0631\u0648\u0632 +WordBased.days=\ \u0631\u0648\u0632 +WordBased.hour=\ \u0633\u0627\u0639\u062A +WordBased.hours=\ \u0633\u0627\u0639\u062A +WordBased.minute=\ \u062f\u0642\u06cc\u0642\u0647 +WordBased.minutes=\ \u062f\u0642\u06cc\u0642\u0647 +WordBased.second=\ \u062b\u0627\u0646\u06cc\u0647 +WordBased.seconds=\ \u062b\u0627\u0646\u06cc\u0647 +WordBased.millisecond=\ \u0645\u06cc\u0644\u06cc\u0020\u062b\u0627\u0646\u06cc\u0647 +WordBased.milliseconds=\ \u0645\u06cc\u0644\u06cc\u0020\u062b\u0627\u0646\u06cc\u0647 diff --git a/src/test/java/org/threeten/extra/TestAmountFormats.java b/src/test/java/org/threeten/extra/TestAmountFormats.java index 7ed94c4c..597532c0 100644 --- a/src/test/java/org/threeten/extra/TestAmountFormats.java +++ b/src/test/java/org/threeten/extra/TestAmountFormats.java @@ -37,13 +37,13 @@ import java.time.Period; import java.util.Locale; -import org.junit.Test; -import org.junit.runner.RunWith; - import com.tngtech.java.junit.dataprovider.DataProvider; import com.tngtech.java.junit.dataprovider.DataProviderRunner; import com.tngtech.java.junit.dataprovider.UseDataProvider; +import org.junit.Test; +import org.junit.runner.RunWith; + /** * Test AmountFormats. */ @@ -126,7 +126,10 @@ public static Object[][] duration_wordBased() { {Duration.ofNanos(1000_000_000 + 2_000_000), new Locale("ro"), "1 secundă È™i 2 milisecunde"}, {Duration.ofHours(5).plusMinutes(6).plusSeconds(7).plusNanos(8_000_000L), PL, - "5 godzin, 6 minut, 7 sekund i 8 milisekund"}, + "5 godzin, 6 minut, 7 sekund i 8 milisekund"}, + + {Duration.ofMinutes(60 + 1), new Locale("fa"), "1 \u0633\u0627\u0639\u062A \u0648 1 \u062f\u0642\u06cc\u0642\u0647"} + }; } @@ -336,5 +339,4 @@ public void test_wordBased_ru_predicate() { assertEquals("24 \u0433\u043E\u0434\u0430", AmountFormats.wordBased(Period.ofYears(2), RU)); assertEquals("25 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(15), RU)); } - } From 8e9942936913587b98cb20017f72d970e83d225b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20L=C3=B6vdahl?= Date: Mon, 25 Feb 2019 19:25:28 +0200 Subject: [PATCH 124/279] Add Finnish translation --- .../threeten/extra/wordbased_fi.properties | 22 +++++++++++++++++++ src/site/markdown/userguide.md | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/org/threeten/extra/wordbased_fi.properties diff --git a/src/main/resources/org/threeten/extra/wordbased_fi.properties b/src/main/resources/org/threeten/extra/wordbased_fi.properties new file mode 100644 index 00000000..16fd346c --- /dev/null +++ b/src/main/resources/org/threeten/extra/wordbased_fi.properties @@ -0,0 +1,22 @@ +WordBased.space=\ +WordBased.comma=, +WordBased.commandand=,ja +WordBased.commaspaceand=, ja +WordBased.commaspace=, +WordBased.spaceandspace=\ ja +WordBased.year=\ vuosi +WordBased.years=\ vuotta +WordBased.month=\ kuukausi +WordBased.months=\ kuukautta +WordBased.week=\ viikko +WordBased.weeks=\ viikkoa +WordBased.day=\ päivä +WordBased.days=\ päivää +WordBased.hour=\ tunti +WordBased.hours=\ tuntia +WordBased.minute=\ minuutti +WordBased.minutes=\ minuttia +WordBased.second=\ sekunti +WordBased.seconds=\ sekuntia +WordBased.millisecond=\ millisekunti +WordBased.milliseconds=\ millisekuntia diff --git a/src/site/markdown/userguide.md b/src/site/markdown/userguide.md index 2d58470a..16e173e5 100644 --- a/src/site/markdown/userguide.md +++ b/src/site/markdown/userguide.md @@ -34,7 +34,7 @@ A simple mechanism is provided here in [`AmountFormats`](apidocs/org.threeten.ex // output: "1 year, 6 months and 5 days" ``` -Translations are provided for ca, cs, da, de, en, es, fr, it, ja, nl, pl, pt, ro, ru, sv, tr. +Translations are provided for ca, cs, da, de, en, es, fi, fr, it, ja, nl, pl, pt, ro, ru, sv, tr. Feel free to raise PRs for other languages. From 63f784b0d4e280654d7add5b9d31e6e6bb4cf16f Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 26 Feb 2019 21:54:04 +0000 Subject: [PATCH 125/279] Update after merging PRs --- pom.xml | 12 ++++++++++++ src/changes/changes.xml | 16 ++++++++++++++++ src/site/markdown/userguide.md | 2 +- .../org/threeten/extra/TestAmountFormats.java | 12 ++++++------ 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index f4a0a0cf..7529dcf4 100644 --- a/pom.xml +++ b/pom.xml @@ -70,6 +70,10 @@ Bruno P. Kinoshita https://github.com/kinow + + Sebastian Lövdahl + https://github.com/slovdahl + Steven McCoy https://github.com/steve-o @@ -82,6 +86,10 @@ Björn Raupach https://github.com/raupachz + + Michel Schudel + https://github.com/MichelSchudel + MichaÅ‚ Sobkiewicz https://github.com/perceptron8 @@ -90,6 +98,10 @@ Nils Sommer https://github.com/nsommer + + Dimo Velev + https://github.com/dimovelev + diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 1bfe00f2..4ed5e587 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -8,6 +8,22 @@ + + Add Farsi translations for word-based formatting. + Fixes #131. + + + Add Bulgarian translations for word-based formatting. + Fixes #129. + + + Add Finnish translations for word-based formatting. + Fixes #127. + + + Add Swedish translations for word-based formatting. + Fixes #126. + Add Norwegian Bokmål and Norwegian Nynorsk translations for word-based formatting. Fixes #125. diff --git a/src/site/markdown/userguide.md b/src/site/markdown/userguide.md index 16e173e5..3594b625 100644 --- a/src/site/markdown/userguide.md +++ b/src/site/markdown/userguide.md @@ -34,7 +34,7 @@ A simple mechanism is provided here in [`AmountFormats`](apidocs/org.threeten.ex // output: "1 year, 6 months and 5 days" ``` -Translations are provided for ca, cs, da, de, en, es, fi, fr, it, ja, nl, pl, pt, ro, ru, sv, tr. +Translations are provided for bg, ca, cs, da, de, en, es, fa, fi, fr, it, ja, nb, nl, nn, pl, pt, ro, ru, sv, tr. Feel free to raise PRs for other languages. diff --git a/src/test/java/org/threeten/extra/TestAmountFormats.java b/src/test/java/org/threeten/extra/TestAmountFormats.java index 597532c0..7252c35b 100644 --- a/src/test/java/org/threeten/extra/TestAmountFormats.java +++ b/src/test/java/org/threeten/extra/TestAmountFormats.java @@ -37,13 +37,13 @@ import java.time.Period; import java.util.Locale; +import org.junit.Test; +import org.junit.runner.RunWith; + import com.tngtech.java.junit.dataprovider.DataProvider; import com.tngtech.java.junit.dataprovider.DataProviderRunner; import com.tngtech.java.junit.dataprovider.UseDataProvider; -import org.junit.Test; -import org.junit.runner.RunWith; - /** * Test AmountFormats. */ @@ -126,10 +126,10 @@ public static Object[][] duration_wordBased() { {Duration.ofNanos(1000_000_000 + 2_000_000), new Locale("ro"), "1 secundă È™i 2 milisecunde"}, {Duration.ofHours(5).plusMinutes(6).plusSeconds(7).plusNanos(8_000_000L), PL, - "5 godzin, 6 minut, 7 sekund i 8 milisekund"}, - - {Duration.ofMinutes(60 + 1), new Locale("fa"), "1 \u0633\u0627\u0639\u062A \u0648 1 \u062f\u0642\u06cc\u0642\u0647"} + "5 godzin, 6 minut, 7 sekund i 8 milisekund"}, + {Duration.ofMinutes(60 + 1), new Locale("fa"), + "1 \u0633\u0627\u0639\u062A \u0648 1 \u062f\u0642\u06cc\u0642\u0647"} }; } From e1c5e79ac96d95875e01f1cedc1f7aa74f35e1e3 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 26 Feb 2019 22:03:31 +0000 Subject: [PATCH 126/279] Add related projects page --- src/site/markdown/index.md | 1 + src/site/markdown/related.md | 10 ++++++++++ src/site/markdown/userguide.md | 5 +++++ 3 files changed, 16 insertions(+) create mode 100644 src/site/markdown/related.md diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index 886510d7..ba072641 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -40,6 +40,7 @@ The following features are included: Various documentation is available: * The helpful [user guide](userguide.html) +* The list of [related projects](related.html) * The [Javadoc](apidocs/org.threeten.extra/module-summary.html) * The [change notes](changes-report.html) for each release * The [GitHub](https://github.com/ThreeTen/threeten-extra) source repository diff --git a/src/site/markdown/related.md b/src/site/markdown/related.md new file mode 100644 index 00000000..15247e37 --- /dev/null +++ b/src/site/markdown/related.md @@ -0,0 +1,10 @@ +## Related projects + +Here are links to a number of projects related to **JSR-310** or **ThreeTen-Extra**. +These projects are independent - no guarantees of quality are given! + +* [JAXB adapters](https://github.com/jaxb-java-time-adapters/jaxb-java-time-adapters) - Integration with JAXB +* [ObjectLab Holiday calculation](http://objectlabkit.sourceforge.net/) - Support for working and non-working days, plus how to calculate and resolve holidays, from a finance industry perspective. + +If your open source library provides a value added feature on top of JSR-310 or ThreeTen-Extra, +then let us know! Just send a pull request to edit this page. diff --git a/src/site/markdown/userguide.md b/src/site/markdown/userguide.md index 3594b625..09d90b87 100644 --- a/src/site/markdown/userguide.md +++ b/src/site/markdown/userguide.md @@ -73,3 +73,8 @@ The leap second data is provided in a text file loaded from the classpath. Only whole leap seconds are handled, and data starts from 1972 by default. To replace the built in leap seconds file, create a file `META-INF/org/threeten/extra/scale/LeapSeconds.txt`. The content should have two columns as per [this format](https://github.com/ThreeTen/threeten-extra/blob/0cf61e35fc165062eb70a66b026c54c261dce46d/src/main/resources/org/threeten/extra/scale/LeapSeconds.txt). + + +## Related projects + +See also the list of [related projects](related.html). From 950ee788fb3a8fbdcc86be0de07c8098baf27a82 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Thu, 28 Feb 2019 17:57:17 +0000 Subject: [PATCH 127/279] Update related projects --- src/site/markdown/related.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/site/markdown/related.md b/src/site/markdown/related.md index 15247e37..ba5d3d21 100644 --- a/src/site/markdown/related.md +++ b/src/site/markdown/related.md @@ -3,7 +3,8 @@ Here are links to a number of projects related to **JSR-310** or **ThreeTen-Extra**. These projects are independent - no guarantees of quality are given! -* [JAXB adapters](https://github.com/jaxb-java-time-adapters/jaxb-java-time-adapters) - Integration with JAXB +* [JPA adapters](https://github.com/marschall/threeten-jpa) - Integration with JPA +* [JAXB adapters](https://github.com/threeten-jaxb/threeten-jaxb) - Integration with JAXB * [ObjectLab Holiday calculation](http://objectlabkit.sourceforge.net/) - Support for working and non-working days, plus how to calculate and resolve holidays, from a finance industry perspective. If your open source library provides a value added feature on top of JSR-310 or ThreeTen-Extra, From abf0dc5b649b53d3996b6c95eab7d60e121c9b63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Octavi=20Forn=C3=A9s?= Date: Mon, 4 Mar 2019 12:58:47 +0100 Subject: [PATCH 128/279] Amended translation of Catalan language --- src/main/resources/org/threeten/extra/wordbased_ca.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/org/threeten/extra/wordbased_ca.properties b/src/main/resources/org/threeten/extra/wordbased_ca.properties index fd4ef65f..381b7475 100644 --- a/src/main/resources/org/threeten/extra/wordbased_ca.properties +++ b/src/main/resources/org/threeten/extra/wordbased_ca.properties @@ -18,5 +18,5 @@ WordBased.minute=\ minut WordBased.minutes=\ minuts WordBased.second=\ segon WordBased.seconds=\ segons -WordBased.millisecond=\ milisegon -WordBased.milliseconds=\ milisegons +WordBased.millisecond=\ mil·lisegon +WordBased.milliseconds=\ mil·lisegons From a0517faf077114bd65ab27f1b24177d6e45bf186 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Fri, 22 Mar 2019 16:25:23 +0000 Subject: [PATCH 129/279] Update checkstyle version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7529dcf4..3463107d 100644 --- a/pom.xml +++ b/pom.xml @@ -871,7 +871,7 @@ true none - 8.17 + 8.18 src/main/checkstyle/checkstyle.xml false From dc239048b88947c7c8eb8a6ed4adf5d3a742e4c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Raupach?= Date: Thu, 28 Mar 2019 09:10:35 +0100 Subject: [PATCH 130/279] Fixed erroneous method signature and documentation of method `minus` in several classes. * Days * Hours * Minutes * Months * Seconds * Weeks * Years --- src/main/java/org/threeten/extra/Days.java | 6 +++--- src/main/java/org/threeten/extra/Hours.java | 6 +++--- src/main/java/org/threeten/extra/Minutes.java | 6 +++--- src/main/java/org/threeten/extra/Months.java | 6 +++--- src/main/java/org/threeten/extra/Seconds.java | 6 +++--- src/main/java/org/threeten/extra/Weeks.java | 6 +++--- src/main/java/org/threeten/extra/Years.java | 6 +++--- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/org/threeten/extra/Days.java b/src/main/java/org/threeten/extra/Days.java index d6eb9340..0b6cc2af 100644 --- a/src/main/java/org/threeten/extra/Days.java +++ b/src/main/java/org/threeten/extra/Days.java @@ -357,13 +357,13 @@ public Days plus(int days) { *

    * This instance is immutable and unaffected by this method call. * - * @param amountToAdd the amount to add, not null + * @param amountToSubtract the amount to subtract, not null * @return a {@code Days} based on this instance with the requested amount subtracted, not null * @throws DateTimeException if the specified amount contains an invalid unit * @throws ArithmeticException if numeric overflow occurs */ - public Days minus(TemporalAmount amountToAdd) { - return minus(Days.from(amountToAdd).getAmount()); + public Days minus(TemporalAmount amountToSubtract) { + return minus(Days.from(amountToSubtract).getAmount()); } /** diff --git a/src/main/java/org/threeten/extra/Hours.java b/src/main/java/org/threeten/extra/Hours.java index ef6734de..24f15938 100644 --- a/src/main/java/org/threeten/extra/Hours.java +++ b/src/main/java/org/threeten/extra/Hours.java @@ -339,13 +339,13 @@ public Hours plus(int hours) { *

    * This instance is immutable and unaffected by this method call. * - * @param amountToAdd the amount to add, not null + * @param amountToSubtract the amount to subtract, not null * @return a {@code Hours} based on this instance with the requested amount subtracted, not null * @throws DateTimeException if the specified amount contains an invalid unit * @throws ArithmeticException if numeric overflow occurs */ - public Hours minus(TemporalAmount amountToAdd) { - return minus(Hours.from(amountToAdd).getAmount()); + public Hours minus(TemporalAmount amountToSubtract) { + return minus(Hours.from(amountToSubtract).getAmount()); } /** diff --git a/src/main/java/org/threeten/extra/Minutes.java b/src/main/java/org/threeten/extra/Minutes.java index 24b1ddcf..5e4cb2f8 100644 --- a/src/main/java/org/threeten/extra/Minutes.java +++ b/src/main/java/org/threeten/extra/Minutes.java @@ -373,13 +373,13 @@ public Minutes plus(int minutes) { *

    * This instance is immutable and unaffected by this method call. * - * @param amountToAdd the amount to add, not null + * @param amountToSubtract the amount to subtract, not null * @return a {@code Minutes} based on this instance with the requested amount subtracted, not null * @throws DateTimeException if the specified amount contains an invalid unit * @throws ArithmeticException if numeric overflow occurs */ - public Minutes minus(TemporalAmount amountToAdd) { - return minus(Minutes.from(amountToAdd).getAmount()); + public Minutes minus(TemporalAmount amountToSubtract) { + return minus(Minutes.from(amountToSubtract).getAmount()); } /** diff --git a/src/main/java/org/threeten/extra/Months.java b/src/main/java/org/threeten/extra/Months.java index 635f332d..d3219113 100644 --- a/src/main/java/org/threeten/extra/Months.java +++ b/src/main/java/org/threeten/extra/Months.java @@ -357,13 +357,13 @@ public Months plus(int months) { *

    * This instance is immutable and unaffected by this method call. * - * @param amountToAdd the amount to add, not null + * @param amountToSubtract the amount to subtract, not null * @return a {@code Months} based on this instance with the requested amount subtracted, not null * @throws DateTimeException if the specified amount contains an invalid unit * @throws ArithmeticException if numeric overflow occurs */ - public Months minus(TemporalAmount amountToAdd) { - return minus(Months.from(amountToAdd).getAmount()); + public Months minus(TemporalAmount amountToSubtract) { + return minus(Months.from(amountToSubtract).getAmount()); } /** diff --git a/src/main/java/org/threeten/extra/Seconds.java b/src/main/java/org/threeten/extra/Seconds.java index 5eac789b..9e00c453 100644 --- a/src/main/java/org/threeten/extra/Seconds.java +++ b/src/main/java/org/threeten/extra/Seconds.java @@ -408,13 +408,13 @@ public Seconds plus(int seconds) { *

    * This instance is immutable and unaffected by this method call. * - * @param amountToAdd the amount to add, not null + * @param amountToSubtract the amount to subtract, not null * @return a {@code Seconds} based on this instance with the requested amount subtracted, not null * @throws DateTimeException if the specified amount contains an invalid unit * @throws ArithmeticException if numeric overflow occurs */ - public Seconds minus(TemporalAmount amountToAdd) { - return minus(Seconds.from(amountToAdd).getAmount()); + public Seconds minus(TemporalAmount amountToSubtract) { + return minus(Seconds.from(amountToSubtract).getAmount()); } /** diff --git a/src/main/java/org/threeten/extra/Weeks.java b/src/main/java/org/threeten/extra/Weeks.java index 45d01b9a..27b88468 100644 --- a/src/main/java/org/threeten/extra/Weeks.java +++ b/src/main/java/org/threeten/extra/Weeks.java @@ -313,13 +313,13 @@ public Weeks plus(int weeks) { *

    * This instance is immutable and unaffected by this method call. * - * @param amountToAdd the amount to add, not null + * @param amountToSubtract the amount to subtract, not null * @return a {@code Weeks} based on this instance with the requested amount subtracted, not null * @throws DateTimeException if the specified amount contains an invalid unit * @throws ArithmeticException if numeric overflow occurs */ - public Weeks minus(TemporalAmount amountToAdd) { - return minus(Weeks.from(amountToAdd).getAmount()); + public Weeks minus(TemporalAmount amountToSubtract) { + return minus(Weeks.from(amountToSubtract).getAmount()); } /** diff --git a/src/main/java/org/threeten/extra/Years.java b/src/main/java/org/threeten/extra/Years.java index 49578850..edc3cfc1 100644 --- a/src/main/java/org/threeten/extra/Years.java +++ b/src/main/java/org/threeten/extra/Years.java @@ -313,13 +313,13 @@ public Years plus(int years) { *

    * This instance is immutable and unaffected by this method call. * - * @param amountToAdd the amount to add, not null + * @param amountToSubtract the amount to subtract, not null * @return a {@code Years} based on this instance with the requested amount subtracted, not null * @throws DateTimeException if the specified amount contains an invalid unit * @throws ArithmeticException if numeric overflow occurs */ - public Years minus(TemporalAmount amountToAdd) { - return minus(Years.from(amountToAdd).getAmount()); + public Years minus(TemporalAmount amountToSubtract) { + return minus(Years.from(amountToSubtract).getAmount()); } /** From 506312f0818f18030b9102f62fb2260a74262d2a Mon Sep 17 00:00:00 2001 From: Nick Glorioso Date: Thu, 11 Apr 2019 15:16:48 -0400 Subject: [PATCH 131/279] Add missing @Test annotations, fixing or ignoring failing tests --- .../org/threeten/extra/TestAmountFormats.java | 24 +++++++++++-------- .../java/org/threeten/extra/TestHours.java | 1 + 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/test/java/org/threeten/extra/TestAmountFormats.java b/src/test/java/org/threeten/extra/TestAmountFormats.java index 7252c35b..eb29152a 100644 --- a/src/test/java/org/threeten/extra/TestAmountFormats.java +++ b/src/test/java/org/threeten/extra/TestAmountFormats.java @@ -37,6 +37,7 @@ import java.time.Period; import java.util.Locale; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -167,11 +168,15 @@ public void test_wordBased(Period period, Duration duration, Locale locale, Stri } //----------------------------------------------------------------------- + @Test + @Ignore // Currently failing: says 29 hours, not 1 day and 5 hours public void test_wordBased_pl_formatStandard() { Duration p = Duration.ofDays(1).plusHours(5).plusMinutes(6).plusSeconds(7).plusNanos(8_000_000L); assertEquals("1 dzie\u0144, 5 godzin, 6 minut, 7 sekund i 8 milisekund", AmountFormats.wordBased(p, PL)); } + @Test + @Ignore // Currently failing: 12 months becomes 1 year public void test_wordBased_pl_predicatex() { assertEquals("1 rok", AmountFormats.wordBased(Period.ofYears(1), PL)); assertEquals("2 lata", AmountFormats.wordBased(Period.ofYears(2), PL)); @@ -322,21 +327,20 @@ public void test_wordBased_pl_predicatex() { assertEquals("2225 milisekund", AmountFormats.wordBased(Duration.ofMillis(2225), PL)); } + @Test public void test_wordBased_ru_predicate() { assertEquals("1 \u0433\u043E\u0434", AmountFormats.wordBased(Period.ofYears(1), RU)); assertEquals("2 \u0433\u043E\u0434\u0430", AmountFormats.wordBased(Period.ofYears(2), RU)); - assertEquals("3 \u0433\u043E\u0434\u0430", AmountFormats.wordBased(Period.ofYears(2), RU)); - assertEquals("4 \u0433\u043E\u0434\u0430", AmountFormats.wordBased(Period.ofYears(2), RU)); + assertEquals("3 \u0433\u043E\u0434\u0430", AmountFormats.wordBased(Period.ofYears(3), RU)); + assertEquals("4 \u0433\u043E\u0434\u0430", AmountFormats.wordBased(Period.ofYears(4), RU)); assertEquals("5 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(5), RU)); - assertEquals("11 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(12), RU)); + assertEquals("11 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(11), RU)); assertEquals("12 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(12), RU)); - assertEquals("13 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(12), RU)); - assertEquals("14 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(12), RU)); + assertEquals("13 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(13), RU)); + assertEquals("14 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(14), RU)); assertEquals("15 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(15), RU)); - assertEquals("21 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(15), RU)); - assertEquals("22 \u0433\u043E\u0434\u0430", AmountFormats.wordBased(Period.ofYears(2), RU)); - assertEquals("23 \u0433\u043E\u0434\u0430", AmountFormats.wordBased(Period.ofYears(2), RU)); - assertEquals("24 \u0433\u043E\u0434\u0430", AmountFormats.wordBased(Period.ofYears(2), RU)); - assertEquals("25 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(15), RU)); + assertEquals("21 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(21), RU)); + assertEquals("24 \u0433\u043E\u0434\u0430", AmountFormats.wordBased(Period.ofYears(24), RU)); + assertEquals("25 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(25), RU)); } } diff --git a/src/test/java/org/threeten/extra/TestHours.java b/src/test/java/org/threeten/extra/TestHours.java index 8b8616bf..448a32c0 100644 --- a/src/test/java/org/threeten/extra/TestHours.java +++ b/src/test/java/org/threeten/extra/TestHours.java @@ -384,6 +384,7 @@ public void test_subtractFrom() { //----------------------------------------------------------------------- @SuppressWarnings("deprecation") + @Test public void test_toDuration() { for (int i = -20; i < 20; i++) { assertEquals(Duration.ofHours(i), Hours.of(i).toPeriod()); From 0bab2b6714cd3cd07c0df793d7717ceaf63e61e0 Mon Sep 17 00:00:00 2001 From: Nick Glorioso Date: Tue, 16 Apr 2019 10:49:06 -0400 Subject: [PATCH 132/279] Add more test cases for Russian AmountFormats --- src/test/java/org/threeten/extra/TestAmountFormats.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/org/threeten/extra/TestAmountFormats.java b/src/test/java/org/threeten/extra/TestAmountFormats.java index eb29152a..9a4bdf4e 100644 --- a/src/test/java/org/threeten/extra/TestAmountFormats.java +++ b/src/test/java/org/threeten/extra/TestAmountFormats.java @@ -340,7 +340,10 @@ public void test_wordBased_ru_predicate() { assertEquals("14 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(14), RU)); assertEquals("15 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(15), RU)); assertEquals("21 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(21), RU)); + assertEquals("22 \u0433\u043E\u0434\u0430", AmountFormats.wordBased(Period.ofYears(22), RU)); assertEquals("24 \u0433\u043E\u0434\u0430", AmountFormats.wordBased(Period.ofYears(24), RU)); assertEquals("25 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(25), RU)); + assertEquals("31 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(31), RU)); + assertEquals("32 \u0433\u043E\u0434\u0430", AmountFormats.wordBased(Period.ofYears(32), RU)); } } From f6bdf75b62c4f649cdefb31240bbbb20bbf49ab6 Mon Sep 17 00:00:00 2001 From: Nick Glorioso Date: Tue, 16 Apr 2019 14:03:08 -0400 Subject: [PATCH 133/279] Fix minor typos in javadoc and exception text --- src/main/java/org/threeten/extra/Interval.java | 2 +- src/main/java/org/threeten/extra/LocalDateRange.java | 2 +- .../java/org/threeten/extra/chrono/AccountingChronology.java | 2 +- src/main/java/org/threeten/extra/chrono/DiscordianDate.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/threeten/extra/Interval.java b/src/main/java/org/threeten/extra/Interval.java index a1fb689c..0aaf9dbd 100644 --- a/src/main/java/org/threeten/extra/Interval.java +++ b/src/main/java/org/threeten/extra/Interval.java @@ -389,7 +389,7 @@ public boolean isConnected(Interval other) { /** * Checks if this interval overlaps the specified interval. *

    - * The result is true if the the two intervals share some part of the time-line. + * The result is true if the two intervals share some part of the time-line. * An empty interval overlaps itself. *

    * This is equivalent to {@code (isConnected(other) && !abuts(other))}. diff --git a/src/main/java/org/threeten/extra/LocalDateRange.java b/src/main/java/org/threeten/extra/LocalDateRange.java index b8991df3..5e168552 100644 --- a/src/main/java/org/threeten/extra/LocalDateRange.java +++ b/src/main/java/org/threeten/extra/LocalDateRange.java @@ -503,7 +503,7 @@ public boolean isConnected(LocalDateRange other) { /** * Checks if this range overlaps the specified range. *

    - * The result is true if the the two ranges share some part of the time-line. + * The result is true if the two ranges share some part of the time-line. * An empty range overlaps itself. *

    * This is equivalent to {@code (isConnected(other) && !abuts(other))}. diff --git a/src/main/java/org/threeten/extra/chrono/AccountingChronology.java b/src/main/java/org/threeten/extra/chrono/AccountingChronology.java index 31a56ce6..d9985772 100644 --- a/src/main/java/org/threeten/extra/chrono/AccountingChronology.java +++ b/src/main/java/org/threeten/extra/chrono/AccountingChronology.java @@ -170,7 +170,7 @@ static AccountingChronology create(DayOfWeek endsOn, Month end, boolean inLastWe + " not set."); } if (!division.getMonthsInYearRange().isValidValue(leapWeekInMonth)) { - throw new IllegalStateException("Leap week cannot not be placed in non-existant month " + leapWeekInMonth + throw new IllegalStateException("Leap week cannot not be placed in non-existent month " + leapWeekInMonth + ", range is [" + division.getMonthsInYearRange() + "]."); } diff --git a/src/main/java/org/threeten/extra/chrono/DiscordianDate.java b/src/main/java/org/threeten/extra/chrono/DiscordianDate.java index 8fb8a949..925bc452 100644 --- a/src/main/java/org/threeten/extra/chrono/DiscordianDate.java +++ b/src/main/java/org/threeten/extra/chrono/DiscordianDate.java @@ -326,7 +326,7 @@ static DiscordianDate create(int prolepticYear, int month, int dayOfMonth) { if (month == 0 || dayOfMonth == 0) { if (month != 0 || dayOfMonth != 0) { - throw new DateTimeException("Invalid date '" + month + " " + dayOfMonth + "' as St. Tib's Day is the only special day inserted in a nonexistant month."); + throw new DateTimeException("Invalid date '" + month + " " + dayOfMonth + "' as St. Tib's Day is the only special day inserted in a nonexistent month."); } else if (!DiscordianChronology.INSTANCE.isLeapYear(prolepticYear)) { throw new DateTimeException("Invalid date 'St. Tibs Day' as '" + prolepticYear + "' is not a leap year"); } From 5ea3f272d8c61c87f51ab9533420da59be1d101c Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Wed, 17 Apr 2019 09:24:33 +0100 Subject: [PATCH 134/279] Correct spelling --- src/main/java/org/threeten/extra/chrono/DiscordianDate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/threeten/extra/chrono/DiscordianDate.java b/src/main/java/org/threeten/extra/chrono/DiscordianDate.java index 925bc452..4023fc35 100644 --- a/src/main/java/org/threeten/extra/chrono/DiscordianDate.java +++ b/src/main/java/org/threeten/extra/chrono/DiscordianDate.java @@ -326,7 +326,7 @@ static DiscordianDate create(int prolepticYear, int month, int dayOfMonth) { if (month == 0 || dayOfMonth == 0) { if (month != 0 || dayOfMonth != 0) { - throw new DateTimeException("Invalid date '" + month + " " + dayOfMonth + "' as St. Tib's Day is the only special day inserted in a nonexistent month."); + throw new DateTimeException("Invalid date '" + month + " " + dayOfMonth + "' as St. Tib's Day is the only special day inserted in a non-existent month."); } else if (!DiscordianChronology.INSTANCE.isLeapYear(prolepticYear)) { throw new DateTimeException("Invalid date 'St. Tibs Day' as '" + prolepticYear + "' is not a leap year"); } From cf9828ec8a237bc83fb74729348dbb479ea61d95 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Wed, 17 Apr 2019 09:43:46 +0100 Subject: [PATCH 135/279] Update after PR --- pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pom.xml b/pom.xml index 3463107d..50a18008 100644 --- a/pom.xml +++ b/pom.xml @@ -42,6 +42,10 @@ Octavi Fornés https://github.com/ofornes + + Nick Glorioso + https://github.com/nglorioso + Jim Gough https://github.com/jpgough From 0c8ae25f28cf52453634e28eda9e40a81212fa04 Mon Sep 17 00:00:00 2001 From: Nick Glorioso Date: Tue, 16 Apr 2019 14:03:08 -0400 Subject: [PATCH 136/279] Fix minor typos in javadoc and exception text --- src/main/java/org/threeten/extra/Interval.java | 2 +- src/main/java/org/threeten/extra/LocalDateRange.java | 2 +- .../java/org/threeten/extra/chrono/AccountingChronology.java | 2 +- src/main/java/org/threeten/extra/chrono/DiscordianDate.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/threeten/extra/Interval.java b/src/main/java/org/threeten/extra/Interval.java index a1fb689c..0aaf9dbd 100644 --- a/src/main/java/org/threeten/extra/Interval.java +++ b/src/main/java/org/threeten/extra/Interval.java @@ -389,7 +389,7 @@ public boolean isConnected(Interval other) { /** * Checks if this interval overlaps the specified interval. *

    - * The result is true if the the two intervals share some part of the time-line. + * The result is true if the two intervals share some part of the time-line. * An empty interval overlaps itself. *

    * This is equivalent to {@code (isConnected(other) && !abuts(other))}. diff --git a/src/main/java/org/threeten/extra/LocalDateRange.java b/src/main/java/org/threeten/extra/LocalDateRange.java index b8991df3..5e168552 100644 --- a/src/main/java/org/threeten/extra/LocalDateRange.java +++ b/src/main/java/org/threeten/extra/LocalDateRange.java @@ -503,7 +503,7 @@ public boolean isConnected(LocalDateRange other) { /** * Checks if this range overlaps the specified range. *

    - * The result is true if the the two ranges share some part of the time-line. + * The result is true if the two ranges share some part of the time-line. * An empty range overlaps itself. *

    * This is equivalent to {@code (isConnected(other) && !abuts(other))}. diff --git a/src/main/java/org/threeten/extra/chrono/AccountingChronology.java b/src/main/java/org/threeten/extra/chrono/AccountingChronology.java index 31a56ce6..d9985772 100644 --- a/src/main/java/org/threeten/extra/chrono/AccountingChronology.java +++ b/src/main/java/org/threeten/extra/chrono/AccountingChronology.java @@ -170,7 +170,7 @@ static AccountingChronology create(DayOfWeek endsOn, Month end, boolean inLastWe + " not set."); } if (!division.getMonthsInYearRange().isValidValue(leapWeekInMonth)) { - throw new IllegalStateException("Leap week cannot not be placed in non-existant month " + leapWeekInMonth + throw new IllegalStateException("Leap week cannot not be placed in non-existent month " + leapWeekInMonth + ", range is [" + division.getMonthsInYearRange() + "]."); } diff --git a/src/main/java/org/threeten/extra/chrono/DiscordianDate.java b/src/main/java/org/threeten/extra/chrono/DiscordianDate.java index 8fb8a949..925bc452 100644 --- a/src/main/java/org/threeten/extra/chrono/DiscordianDate.java +++ b/src/main/java/org/threeten/extra/chrono/DiscordianDate.java @@ -326,7 +326,7 @@ static DiscordianDate create(int prolepticYear, int month, int dayOfMonth) { if (month == 0 || dayOfMonth == 0) { if (month != 0 || dayOfMonth != 0) { - throw new DateTimeException("Invalid date '" + month + " " + dayOfMonth + "' as St. Tib's Day is the only special day inserted in a nonexistant month."); + throw new DateTimeException("Invalid date '" + month + " " + dayOfMonth + "' as St. Tib's Day is the only special day inserted in a nonexistent month."); } else if (!DiscordianChronology.INSTANCE.isLeapYear(prolepticYear)) { throw new DateTimeException("Invalid date 'St. Tibs Day' as '" + prolepticYear + "' is not a leap year"); } From 6ce1e8140941d8b2dc8dabad6bbeb1612c674ce6 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Wed, 17 Apr 2019 09:24:33 +0100 Subject: [PATCH 137/279] Correct spelling --- src/main/java/org/threeten/extra/chrono/DiscordianDate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/threeten/extra/chrono/DiscordianDate.java b/src/main/java/org/threeten/extra/chrono/DiscordianDate.java index 925bc452..4023fc35 100644 --- a/src/main/java/org/threeten/extra/chrono/DiscordianDate.java +++ b/src/main/java/org/threeten/extra/chrono/DiscordianDate.java @@ -326,7 +326,7 @@ static DiscordianDate create(int prolepticYear, int month, int dayOfMonth) { if (month == 0 || dayOfMonth == 0) { if (month != 0 || dayOfMonth != 0) { - throw new DateTimeException("Invalid date '" + month + " " + dayOfMonth + "' as St. Tib's Day is the only special day inserted in a nonexistent month."); + throw new DateTimeException("Invalid date '" + month + " " + dayOfMonth + "' as St. Tib's Day is the only special day inserted in a non-existent month."); } else if (!DiscordianChronology.INSTANCE.isLeapYear(prolepticYear)) { throw new DateTimeException("Invalid date 'St. Tibs Day' as '" + prolepticYear + "' is not a leap year"); } From d92bd8cfa0fea22bd51d0c977d9f4dd87cd9cf1c Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Wed, 17 Apr 2019 09:43:46 +0100 Subject: [PATCH 138/279] Update after PR --- pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pom.xml b/pom.xml index 3463107d..50a18008 100644 --- a/pom.xml +++ b/pom.xml @@ -42,6 +42,10 @@ Octavi Fornés https://github.com/ofornes + + Nick Glorioso + https://github.com/nglorioso + Jim Gough https://github.com/jpgough From e94ecd3592ef70e54d6eea21095239ea9ffbab78 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 29 Apr 2019 17:05:53 +0100 Subject: [PATCH 139/279] Enhance test coverage Some tests were not correctly annotated --- .../org/threeten/extra/AmountFormats.java | 17 +++-- .../org/threeten/extra/TestAmountFormats.java | 74 ++++--------------- 2 files changed, 25 insertions(+), 66 deletions(-) diff --git a/src/main/java/org/threeten/extra/AmountFormats.java b/src/main/java/org/threeten/extra/AmountFormats.java index d8c168ad..3632faf6 100644 --- a/src/main/java/org/threeten/extra/AmountFormats.java +++ b/src/main/java/org/threeten/extra/AmountFormats.java @@ -163,6 +163,7 @@ public static String iso8601(Period period, Duration duration) { * Formats a period to a string in a localized word-based format. *

    * This returns a word-based format for the period. + * The year and month are printed as supplied unless the signs differ, in which case they are normalized. * The words are configured in a resource bundle text file - * {@code org.threeten.extra.wordbased.properties} - with overrides per language. * @@ -180,8 +181,8 @@ public static String wordBased(Period period, Locale locale) { UnitFormat.of(bundle, WORDBASED_WEEK), UnitFormat.of(bundle, WORDBASED_DAY)}; WordBased wb = new WordBased(formats, bundle.getString(WORDBASED_COMMASPACE), bundle.getString(WORDBASED_SPACEANDSPACE)); - - Period normPeriod = period.normalized(); + + Period normPeriod = oppositeSigns(period.getMonths(), period.getYears()) ? period.normalized() : period; int weeks = 0, days = 0; if (normPeriod.getDays() % DAYS_PER_WEEK == 0) { weeks = normPeriod.getDays() / DAYS_PER_WEEK; @@ -213,7 +214,7 @@ public static String wordBased(Duration duration, Locale locale) { UnitFormat.of(bundle, WORDBASED_SECOND), UnitFormat.of(bundle, WORDBASED_MILLISECOND)}; WordBased wb = new WordBased(formats, bundle.getString(WORDBASED_COMMASPACE), bundle.getString(WORDBASED_SPACEANDSPACE)); - + long hours = duration.toHours(); long mins = duration.toMinutes() % MINUTES_PER_HOUR; long secs = duration.getSeconds() % SECONDS_PER_MINUTE; @@ -226,6 +227,7 @@ public static String wordBased(Duration duration, Locale locale) { * Formats a period and duration to a string in a localized word-based format. *

    * This returns a word-based format for the period. + * The year and month are printed as supplied unless the signs differ, in which case they are normalized. * The words are configured in a resource bundle text file - * {@code org.threeten.extra.wordbased.properties} - with overrides per language. * @@ -249,8 +251,8 @@ public static String wordBased(Period period, Duration duration, Locale locale) UnitFormat.of(bundle, WORDBASED_SECOND), UnitFormat.of(bundle, WORDBASED_MILLISECOND)}; WordBased wb = new WordBased(formats, bundle.getString(WORDBASED_COMMASPACE), bundle.getString(WORDBASED_SPACEANDSPACE)); - - Period normPeriod = period.normalized(); + + Period normPeriod = oppositeSigns(period.getMonths(), period.getYears()) ? period.normalized() : period; int weeks = 0, days = 0; if (normPeriod.getDays() % DAYS_PER_WEEK == 0) { weeks = normPeriod.getDays() / DAYS_PER_WEEK; @@ -269,6 +271,11 @@ public static String wordBased(Period period, Duration duration, Locale locale) return wb.format(values); } + // are the signs opposite + private static boolean oppositeSigns(int a, int b) { + return a < 0 ? (b >= 0) : (b < 0); + } + private AmountFormats() { } diff --git a/src/test/java/org/threeten/extra/TestAmountFormats.java b/src/test/java/org/threeten/extra/TestAmountFormats.java index 9a4bdf4e..7542bfd1 100644 --- a/src/test/java/org/threeten/extra/TestAmountFormats.java +++ b/src/test/java/org/threeten/extra/TestAmountFormats.java @@ -37,7 +37,6 @@ import java.time.Period; import java.util.Locale; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; @@ -79,7 +78,9 @@ public static Object[][] data_wordBased() { {Period.ofMonths(0), Locale.ENGLISH, "0 days"}, {Period.ofMonths(1), Locale.ENGLISH, "1 month"}, {Period.ofMonths(4), Locale.ENGLISH, "4 months"}, - {Period.ofMonths(14), Locale.ENGLISH, "1 year and 2 months"}, + {Period.ofMonths(14), Locale.ENGLISH, "14 months"}, + {Period.ofMonths(14).normalized(), Locale.ENGLISH, "1 year and 2 months"}, + {Period.ofYears(2).plusMonths(-10).normalized(), Locale.ENGLISH, "1 year and 2 months"}, {Period.ofDays(1), Locale.ENGLISH, "1 day"}, {Period.ofDays(2), Locale.ENGLISH, "2 days"}, @@ -92,7 +93,7 @@ public static Object[][] data_wordBased() { {Period.ofDays(5), new Locale("ro"), "5 zile"}, {Period.ofDays(7), new Locale("ro"), "1 săptămână"}, {Period.ofWeeks(3), new Locale("ro"), "3 săptămâni"}, - {Period.ofMonths(14), new Locale("ro"), "1 an și 2 luni"}, + {Period.ofMonths(14).normalized(), new Locale("ro"), "1 an și 2 luni"}, {Period.ofMonths(1), new Locale("ro"), "1 lună"}, {Period.ofYears(2), new Locale("ro"), "2 ani"}, }; @@ -169,14 +170,13 @@ public void test_wordBased(Period period, Duration duration, Locale locale, Stri //----------------------------------------------------------------------- @Test - @Ignore // Currently failing: says 29 hours, not 1 day and 5 hours public void test_wordBased_pl_formatStandard() { - Duration p = Duration.ofDays(1).plusHours(5).plusMinutes(6).plusSeconds(7).plusNanos(8_000_000L); - assertEquals("1 dzie\u0144, 5 godzin, 6 minut, 7 sekund i 8 milisekund", AmountFormats.wordBased(p, PL)); + Period p = Period.ofDays(1); + Duration d = Duration.ofHours(5).plusMinutes(6).plusSeconds(7).plusNanos(8_000_000L); + assertEquals("1 dzie\u0144, 5 godzin, 6 minut, 7 sekund i 8 milisekund", AmountFormats.wordBased(p, d, PL)); } @Test - @Ignore // Currently failing: 12 months becomes 1 year public void test_wordBased_pl_predicatex() { assertEquals("1 rok", AmountFormats.wordBased(Period.ofYears(1), PL)); assertEquals("2 lata", AmountFormats.wordBased(Period.ofYears(2), PL)); @@ -271,60 +271,12 @@ public void test_wordBased_pl_predicatex() { assertEquals("5 minut", AmountFormats.wordBased(Duration.ofMinutes(5), PL)); assertEquals("12 minut", AmountFormats.wordBased(Duration.ofMinutes(12), PL)); assertEquals("15 minut", AmountFormats.wordBased(Duration.ofMinutes(15), PL)); - assertEquals("1112 minut", AmountFormats.wordBased(Duration.ofMinutes(1112), PL)); - assertEquals("1115 minut", AmountFormats.wordBased(Duration.ofMinutes(1115), PL)); - assertEquals("2112 minut", AmountFormats.wordBased(Duration.ofMinutes(2112), PL)); - assertEquals("2115 minut", AmountFormats.wordBased(Duration.ofMinutes(2115), PL)); - assertEquals("2212 minut", AmountFormats.wordBased(Duration.ofMinutes(2212), PL)); - assertEquals("2215 minut", AmountFormats.wordBased(Duration.ofMinutes(2215), PL)); - assertEquals("22 minuty", AmountFormats.wordBased(Duration.ofMinutes(22), PL)); - assertEquals("25 minut", AmountFormats.wordBased(Duration.ofMinutes(25), PL)); - assertEquals("1122 minuty", AmountFormats.wordBased(Duration.ofMinutes(1122), PL)); - assertEquals("1125 minut", AmountFormats.wordBased(Duration.ofMinutes(1125), PL)); - assertEquals("2122 minuty", AmountFormats.wordBased(Duration.ofMinutes(2122), PL)); - assertEquals("2125 minut", AmountFormats.wordBased(Duration.ofMinutes(2125), PL)); - assertEquals("2222 minuty", AmountFormats.wordBased(Duration.ofMinutes(2222), PL)); - assertEquals("2225 minut", AmountFormats.wordBased(Duration.ofMinutes(2225), PL)); - - assertEquals("1 sekunda", AmountFormats.wordBased(Duration.ofSeconds(1), PL)); - assertEquals("2 sekundy", AmountFormats.wordBased(Duration.ofSeconds(2), PL)); - assertEquals("5 sekund", AmountFormats.wordBased(Duration.ofSeconds(5), PL)); - assertEquals("12 sekund", AmountFormats.wordBased(Duration.ofSeconds(12), PL)); - assertEquals("15 sekund", AmountFormats.wordBased(Duration.ofSeconds(15), PL)); - assertEquals("1112 sekund", AmountFormats.wordBased(Duration.ofSeconds(1112), PL)); - assertEquals("1115 sekund", AmountFormats.wordBased(Duration.ofSeconds(1115), PL)); - assertEquals("2112 sekund", AmountFormats.wordBased(Duration.ofSeconds(2112), PL)); - assertEquals("2115 sekund", AmountFormats.wordBased(Duration.ofSeconds(2115), PL)); - assertEquals("2212 sekund", AmountFormats.wordBased(Duration.ofSeconds(2212), PL)); - assertEquals("2215 sekund", AmountFormats.wordBased(Duration.ofSeconds(2215), PL)); - assertEquals("22 sekundy", AmountFormats.wordBased(Duration.ofSeconds(22), PL)); - assertEquals("25 sekund", AmountFormats.wordBased(Duration.ofSeconds(25), PL)); - assertEquals("1122 sekundy", AmountFormats.wordBased(Duration.ofSeconds(1122), PL)); - assertEquals("1125 sekund", AmountFormats.wordBased(Duration.ofSeconds(1125), PL)); - assertEquals("2122 sekundy", AmountFormats.wordBased(Duration.ofSeconds(2122), PL)); - assertEquals("2125 sekund", AmountFormats.wordBased(Duration.ofSeconds(2125), PL)); - assertEquals("2222 sekundy", AmountFormats.wordBased(Duration.ofSeconds(2222), PL)); - assertEquals("2225 sekund", AmountFormats.wordBased(Duration.ofSeconds(2225), PL)); - - assertEquals("1 milisekunda", AmountFormats.wordBased(Duration.ofMillis(1), PL)); - assertEquals("2 milisekundy", AmountFormats.wordBased(Duration.ofMillis(2), PL)); - assertEquals("5 milisekund", AmountFormats.wordBased(Duration.ofMillis(5), PL)); - assertEquals("12 milisekund", AmountFormats.wordBased(Duration.ofMillis(12), PL)); - assertEquals("15 milisekund", AmountFormats.wordBased(Duration.ofMillis(15), PL)); - assertEquals("1112 milisekund", AmountFormats.wordBased(Duration.ofMillis(1112), PL)); - assertEquals("1115 milisekund", AmountFormats.wordBased(Duration.ofMillis(1115), PL)); - assertEquals("2112 milisekund", AmountFormats.wordBased(Duration.ofMillis(2112), PL)); - assertEquals("2115 milisekund", AmountFormats.wordBased(Duration.ofMillis(2115), PL)); - assertEquals("2212 milisekund", AmountFormats.wordBased(Duration.ofMillis(2212), PL)); - assertEquals("2215 milisekund", AmountFormats.wordBased(Duration.ofMillis(2215), PL)); - assertEquals("22 milisekundy", AmountFormats.wordBased(Duration.ofMillis(22), PL)); - assertEquals("25 milisekund", AmountFormats.wordBased(Duration.ofMillis(25), PL)); - assertEquals("1122 milisekundy", AmountFormats.wordBased(Duration.ofMillis(1122), PL)); - assertEquals("1125 milisekund", AmountFormats.wordBased(Duration.ofMillis(1125), PL)); - assertEquals("2122 milisekundy", AmountFormats.wordBased(Duration.ofMillis(2122), PL)); - assertEquals("2125 milisekund", AmountFormats.wordBased(Duration.ofMillis(2125), PL)); - assertEquals("2222 milisekundy", AmountFormats.wordBased(Duration.ofMillis(2222), PL)); - assertEquals("2225 milisekund", AmountFormats.wordBased(Duration.ofMillis(2225), PL)); + assertEquals("18 godzin i 32 minuty", AmountFormats.wordBased(Duration.ofMinutes(1112), PL)); + assertEquals("18 godzin i 35 minut", AmountFormats.wordBased(Duration.ofMinutes(1115), PL)); + assertEquals("35 godzin i 12 minut", AmountFormats.wordBased(Duration.ofMinutes(2112), PL)); + assertEquals("35 godzin i 15 minut", AmountFormats.wordBased(Duration.ofMinutes(2115), PL)); + assertEquals("36 godzin i 52 minuty", AmountFormats.wordBased(Duration.ofMinutes(2212), PL)); + assertEquals("36 godzin i 55 minut", AmountFormats.wordBased(Duration.ofMinutes(2215), PL)); } @Test From 0491eae686bb694f9cd1c373b73946629ad4ab72 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Fri, 24 May 2019 10:02:03 +0100 Subject: [PATCH 140/279] Add sponsorship information --- .github/FUNDING.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..a7e0ee6f --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,7 @@ +open_collective: joda +tidelift: maven/org.threeten:threeten-extra + +# github: [jodastephen] +# patreon: # Replace with a single Patreon username +# ko_fi: # Replace with a single Ko-fi username +# custom: # Replace with a single custom sponsorship URL From 3e3002a9ae53d69dc43965a86bd3a6aa68edb4b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Mon, 1 Apr 2019 21:44:34 +0200 Subject: [PATCH 141/279] Add OffsetDate.java From: https://github.com/ThreeTen/threetenbp/blob/e25d72b8591b6a1bf73cf048e2a4d1aeabe040eb/src/main/java/org/threeten/bp/OffsetDate.java --- .../java/org/threeten/extra/OffsetDate.java | 1317 +++++++++++++++++ 1 file changed, 1317 insertions(+) create mode 100644 src/main/java/org/threeten/extra/OffsetDate.java diff --git a/src/main/java/org/threeten/extra/OffsetDate.java b/src/main/java/org/threeten/extra/OffsetDate.java new file mode 100644 index 00000000..3eb0eb04 --- /dev/null +++ b/src/main/java/org/threeten/extra/OffsetDate.java @@ -0,0 +1,1317 @@ +/* + * Copyright (c) 2007-2013, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.bp; + +import static org.threeten.bp.LocalTime.SECONDS_PER_DAY; +import static org.threeten.bp.temporal.ChronoField.EPOCH_DAY; +import static org.threeten.bp.temporal.ChronoField.OFFSET_SECONDS; +import static org.threeten.bp.temporal.ChronoUnit.DAYS; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.io.InvalidObjectException; +import java.io.ObjectStreamException; +import java.io.Serializable; +import java.util.Objects; + +import org.threeten.bp.format.DateTimeFormatter; +import org.threeten.bp.format.DateTimeFormatters; +import org.threeten.bp.format.DateTimeParseException; +import org.threeten.bp.jdk8.DefaultInterfaceTemporalAccessor; +import org.threeten.bp.jdk8.Jdk8Methods; +import org.threeten.bp.temporal.ChronoField; +import org.threeten.bp.temporal.ChronoUnit; +import org.threeten.bp.temporal.ISOChrono; +import org.threeten.bp.temporal.Temporal; +import org.threeten.bp.temporal.TemporalAccessor; +import org.threeten.bp.temporal.TemporalAdder; +import org.threeten.bp.temporal.TemporalAdjuster; +import org.threeten.bp.temporal.TemporalAdjusters; +import org.threeten.bp.temporal.TemporalField; +import org.threeten.bp.temporal.TemporalQueries; +import org.threeten.bp.temporal.TemporalQuery; +import org.threeten.bp.temporal.TemporalSubtractor; +import org.threeten.bp.temporal.TemporalUnit; +import org.threeten.bp.temporal.ValueRange; +import org.threeten.bp.zone.ZoneRules; + +/** + * A date with an offset from UTC/Greenwich in the ISO-8601 calendar system, + * such as {@code 2007-12-03+01:00}. + *

    + * {@code OffsetDate} is an immutable date-time object that represents a date, often viewed + * as year-month-day-offset. This object can also access other date fields such as + * day-of-year, day-of-week and week-of-year. + *

    + * This class does not store or represent a time. + * For example, the value "2nd October 2007 +02:00" can be stored + * in an {@code OffsetDate}. + * + *

    Specification for implementors

    + * This class is immutable and thread-safe. + */ +public final class OffsetDate + extends DefaultInterfaceTemporalAccessor + implements Temporal, TemporalAdjuster, Comparable, Serializable { + + /** + * The minimum supported {@code OffsetDate}, '-999999999-01-01+18:00'. + * This is the minimum local date in the maximum offset + * (larger offsets are earlier on the time-line). + * This combines {@link LocalDate#MIN} and {@link ZoneOffset#MAX}. + * This could be used by an application as a "far past" date. + */ + public static final OffsetDate MIN = LocalDate.MIN.atOffset(ZoneOffset.MAX); + /** + * The maximum supported {@code OffsetDate}, '+999999999-12-31-18:00'. + * This is the maximum local date in the minimum offset + * (larger negative offsets are later on the time-line). + * This combines {@link LocalDate#MAX} and {@link ZoneOffset#MIN}. + * This could be used by an application as a "far future" date. + */ + public static final OffsetDate MAX = LocalDate.MAX.atOffset(ZoneOffset.MIN); + + /** + * Serialization version. + */ + private static final long serialVersionUID = -4382054179074397774L; + + /** + * The local date. + */ + private final LocalDate date; + /** + * The offset from UTC/Greenwich. + */ + private final ZoneOffset offset; + + //----------------------------------------------------------------------- + /** + * Obtains the current date from the system clock in the default time-zone. + *

    + * This will query the {@link Clock#systemDefaultZone() system clock} in the default + * time-zone to obtain the current date. + * The offset will be calculated from the time-zone in the clock. + *

    + * Using this method will prevent the ability to use an alternate clock for testing + * because the clock is hard-coded. + * + * @return the current date using the system clock, not null + */ + public static OffsetDate now() { + return now(Clock.systemDefaultZone()); + } + + /** + * Obtains the current date from the system clock in the specified time-zone. + *

    + * This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date. + * Specifying the time-zone avoids dependence on the default time-zone. + * The offset will be calculated from the specified time-zone. + *

    + * Using this method will prevent the ability to use an alternate clock for testing + * because the clock is hard-coded. + * + * @param zone the zone ID to use, not null + * @return the current date using the system clock, not null + */ + public static OffsetDate now(ZoneId zone) { + return now(Clock.system(zone)); + } + + /** + * Obtains the current date from the specified clock. + *

    + * This will query the specified clock to obtain the current date - today. + * The offset will be calculated from the time-zone in the clock. + *

    + * Using this method allows the use of an alternate clock for testing. + * The alternate clock may be introduced using {@link Clock dependency injection}. + * + * @param clock the clock to use, not null + * @return the current date, not null + */ + public static OffsetDate now(Clock clock) { + Objects.requireNonNull(clock, "clock"); + final Instant now = clock.instant(); // called once + return ofInstant(now, clock.getZone().getRules().getOffset(now)); + } + + //----------------------------------------------------------------------- + /** + * Obtains an instance of {@code OffsetDate} from a local date and an offset. + * + * @param date the local date, not null + * @param offset the zone offset, not null + * @return the offset date, not null + */ + public static OffsetDate of(LocalDate date, ZoneOffset offset) { + return new OffsetDate(date, offset); + } + + //----------------------------------------------------------------------- + /** + * Obtains an instance of {@code OffsetDate} from an {@code Instant} and zone ID. + *

    + * This creates an offset date with the same instant as midnight at the + * start of day of the instant specified. + * Finding the offset from UTC/Greenwich is simple as there is only one valid + * offset for each instant. + * + * @param instant the instant to create the time from, not null + * @param zone the time-zone, which may be an offset, not null + * @return the offset time, not null + */ + public static OffsetDate ofInstant(Instant instant, ZoneId zone) { + Objects.requireNonNull(instant, "instant"); + Objects.requireNonNull(zone, "zone"); + ZoneRules rules = zone.getRules(); + ZoneOffset offset = rules.getOffset(instant); + long epochSec = instant.getEpochSecond() + offset.getTotalSeconds(); // overflow caught later + long epochDay = Jdk8Methods.floorDiv(epochSec, SECONDS_PER_DAY); + LocalDate date = LocalDate.ofEpochDay(epochDay); + return new OffsetDate(date, offset); + } + + //----------------------------------------------------------------------- + /** + * Obtains an instance of {@code OffsetDate} from a temporal object. + *

    + * A {@code TemporalAccessor} represents some form of date and time information. + * This factory converts the arbitrary temporal object to an instance of {@code OffsetDate}. + *

    + * The conversion extracts and combines {@code LocalDate} and {@code ZoneOffset}. + *

    + * This method matches the signature of the functional interface {@link TemporalQuery} + * allowing it to be used in queries via method reference, {@code OffsetDate::from}. + * + * @param temporal the temporal object to convert, not null + * @return the offset date, not null + * @throws DateTimeException if unable to convert to an {@code OffsetDate} + */ + public static OffsetDate from(TemporalAccessor temporal) { + if (temporal instanceof OffsetDate) { + return (OffsetDate) temporal; + } + try { + LocalDate date = LocalDate.from(temporal); + ZoneOffset offset = ZoneOffset.from(temporal); + return new OffsetDate(date, offset); + } catch (DateTimeException ex) { + throw new DateTimeException("Unable to obtain OffsetDate from TemporalAccessor: " + temporal.getClass(), ex); + } + } + + //----------------------------------------------------------------------- + /** + * Obtains an instance of {@code OffsetDate} from a text string such as {@code 2007-12-03+01:00}. + *

    + * The string must represent a valid date and is parsed using + * {@link org.threeten.bp.format.DateTimeFormatters#isoOffsetDate()}. + * + * @param text the text to parse such as "2007-12-03+01:00", not null + * @return the parsed offset date, not null + * @throws DateTimeParseException if the text cannot be parsed + */ + public static OffsetDate parse(CharSequence text) { + return parse(text, DateTimeFormatters.isoOffsetDate()); + } + + /** + * Obtains an instance of {@code OffsetDate} from a text string using a specific formatter. + *

    + * The text is parsed using the formatter, returning a date. + * + * @param text the text to parse, not null + * @param formatter the formatter to use, not null + * @return the parsed offset date, not null + * @throws DateTimeParseException if the text cannot be parsed + */ + public static OffsetDate parse(CharSequence text, DateTimeFormatter formatter) { + Objects.requireNonNull(formatter, "formatter"); + return formatter.parse(text, OffsetDate.class); + } + + //----------------------------------------------------------------------- + /** + * Constructor. + * + * @param date the local date, not null + * @param offset the zone offset, not null + */ + private OffsetDate(LocalDate date, ZoneOffset offset) { + this.date = Objects.requireNonNull(date, "date"); + this.offset = Objects.requireNonNull(offset, "offset"); + } + + /** + * Returns a new date based on this one, returning {@code this} where possible. + * + * @param date the date to create with, not null + * @param offset the zone offset to create with, not null + */ + private OffsetDate with(LocalDate date, ZoneOffset offset) { + if (this.date == date && this.offset.equals(offset)) { + return this; + } + return new OffsetDate(date, offset); + } + + //----------------------------------------------------------------------- + /** + * Checks if the specified field is supported. + *

    + * This checks if this date can be queried for the specified field. + * If false, then calling the {@link #range(TemporalField) range} and + * {@link #get(TemporalField) get} methods will throw an exception. + *

    + * If the field is a {@link ChronoField} then the query is implemented here. + * The {@link #isSupported(TemporalField) supported fields} will return valid + * values based on this date-time. + * The supported fields are: + *

      + *
    • {@code DAY_OF_WEEK} + *
    • {@code ALIGNED_DAY_OF_WEEK_IN_MONTH} + *
    • {@code ALIGNED_DAY_OF_WEEK_IN_YEAR} + *
    • {@code DAY_OF_MONTH} + *
    • {@code DAY_OF_YEAR} + *
    • {@code EPOCH_DAY} + *
    • {@code ALIGNED_WEEK_OF_MONTH} + *
    • {@code ALIGNED_WEEK_OF_YEAR} + *
    • {@code MONTH_OF_YEAR} + *
    • {@code EPOCH_MONTH} + *
    • {@code YEAR_OF_ERA} + *
    • {@code YEAR} + *
    • {@code ERA} + *
    • {@code OFFSET_SECONDS} + *
    + * All other {@code ChronoField} instances will return false. + *

    + * If the field is not a {@code ChronoField}, then the result of this method + * is obtained by invoking {@code TemporalField.doIsSupported(TemporalAccessor)} + * passing {@code this} as the argument. + * Whether the field is supported is determined by the field. + * + * @param field the field to check, null returns false + * @return true if the field is supported on this date, false if not + */ + @Override + public boolean isSupported(TemporalField field) { + if (field instanceof ChronoField) { + return ((ChronoField) field).isDateField() || field == OFFSET_SECONDS; + } + return field != null && field.doIsSupported(this); + } + + /** + * Gets the range of valid values for the specified field. + *

    + * The range object expresses the minimum and maximum valid values for a field. + * This date is used to enhance the accuracy of the returned range. + * If it is not possible to return the range, because the field is not supported + * or for some other reason, an exception is thrown. + *

    + * If the field is a {@link ChronoField} then the query is implemented here. + * The {@link #isSupported(TemporalField) supported fields} will return + * appropriate range instances. + * All other {@code ChronoField} instances will throw a {@code DateTimeException}. + *

    + * If the field is not a {@code ChronoField}, then the result of this method + * is obtained by invoking {@code TemporalField.doRange(TemporalAccessor)} + * passing {@code this} as the argument. + * Whether the range can be obtained is determined by the field. + * + * @param field the field to query the range for, not null + * @return the range of valid values for the field, not null + * @throws DateTimeException if the range for the field cannot be obtained + */ + @Override + public ValueRange range(TemporalField field) { + if (field instanceof ChronoField) { + if (field == OFFSET_SECONDS) { + return field.range(); + } + return date.range(field); + } + return field.doRange(this); + } + + /** + * Gets the value of the specified field from this date as an {@code int}. + *

    + * This queries this date for the value for the specified field. + * The returned value will always be within the valid range of values for the field. + * If it is not possible to return the value, because the field is not supported + * or for some other reason, an exception is thrown. + *

    + * If the field is a {@link ChronoField} then the query is implemented here. + * The {@link #isSupported(TemporalField) supported fields} will return valid + * values based on this date, except {@code EPOCH_DAY} and {@code EPOCH_MONTH} + * which are too large to fit in an {@code int} and throw a {@code DateTimeException}. + * All other {@code ChronoField} instances will throw a {@code DateTimeException}. + *

    + * If the field is not a {@code ChronoField}, then the result of this method + * is obtained by invoking {@code TemporalField.doGet(TemporalAccessor)} + * passing {@code this} as the argument. Whether the value can be obtained, + * and what the value represents, is determined by the field. + * + * @param field the field to get, not null + * @return the value for the field + * @throws DateTimeException if a value for the field cannot be obtained + * @throws ArithmeticException if numeric overflow occurs + */ + @Override // override for Javadoc + public int get(TemporalField field) { + return super.get(field); + } + + /** + * Gets the value of the specified field from this date as a {@code long}. + *

    + * This queries this date for the value for the specified field. + * If it is not possible to return the value, because the field is not supported + * or for some other reason, an exception is thrown. + *

    + * If the field is a {@link ChronoField} then the query is implemented here. + * The {@link #isSupported(TemporalField) supported fields} will return valid + * values based on this date. + * All other {@code ChronoField} instances will throw a {@code DateTimeException}. + *

    + * If the field is not a {@code ChronoField}, then the result of this method + * is obtained by invoking {@code TemporalField.doGet(TemporalAccessor)} + * passing {@code this} as the argument. Whether the value can be obtained, + * and what the value represents, is determined by the field. + * + * @param field the field to get, not null + * @return the value for the field + * @throws DateTimeException if a value for the field cannot be obtained + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public long getLong(TemporalField field) { + if (field instanceof ChronoField) { + if (field == OFFSET_SECONDS) { + return getOffset().getTotalSeconds(); + } + return date.getLong(field); + } + return field.doGet(this); + } + + //----------------------------------------------------------------------- + /** + * Gets the zone offset, such as '+01:00'. + *

    + * This is the offset of the local date from UTC/Greenwich. + * + * @return the zone offset, not null + */ + public ZoneOffset getOffset() { + return offset; + } + + /** + * Returns a copy of this {@code OffsetDate} with the specified offset. + *

    + * This method returns an object with the same {@code LocalDate} and the specified {@code ZoneOffset}. + * No calculation is needed or performed. + * For example, if this time represents {@code 2007-12-03+02:00} and the offset specified is + * {@code +03:00}, then this method will return {@code 2007-12-03+03:00}. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param offset the zone offset to change to, not null + * @return an {@code OffsetDate} based on this date with the requested offset, not null + */ + public OffsetDate withOffset(ZoneOffset offset) { + Objects.requireNonNull(offset, "offset"); + return with(date, offset); + } + + //----------------------------------------------------------------------- + /** + * Gets the {@code LocalDate} part of this date-time. + *

    + * This returns a {@code LocalDate} with the same year, month and day + * as this date-time. + * + * @return the date part of this date-time, not null + */ + public LocalDate getDate() { + return date; + } + + //----------------------------------------------------------------------- + /** + * Gets the year field. + *

    + * This method returns the primitive {@code int} value for the year. + *

    + * The year returned by this method is proleptic as per {@code get(YEAR)}. + * To obtain the year-of-era, use {@code get(YEAR_OF_ERA}. + * + * @return the year, from MIN_YEAR to MAX_YEAR + */ + public int getYear() { + return date.getYear(); + } + + /** + * Gets the month-of-year field from 1 to 12. + *

    + * This method returns the month as an {@code int} from 1 to 12. + * Application code is frequently clearer if the enum {@link Month} + * is used by calling {@link #getMonth()}. + * + * @return the month-of-year, from 1 to 12 + * @see #getMonth() + */ + public int getMonthValue() { + return date.getMonthValue(); + } + + /** + * Gets the month-of-year field using the {@code Month} enum. + *

    + * This method returns the enum {@link Month} for the month. + * This avoids confusion as to what {@code int} values mean. + * If you need access to the primitive {@code int} value then the enum + * provides the {@link Month#getValue() int value}. + * + * @return the month-of-year, not null + * @see #getMonthValue() + */ + public Month getMonth() { + return date.getMonth(); + } + + /** + * Gets the day-of-month field. + *

    + * This method returns the primitive {@code int} value for the day-of-month. + * + * @return the day-of-month, from 1 to 31 + */ + public int getDayOfMonth() { + return date.getDayOfMonth(); + } + + /** + * Gets the day-of-year field. + *

    + * This method returns the primitive {@code int} value for the day-of-year. + * + * @return the day-of-year, from 1 to 365, or 366 in a leap year + */ + public int getDayOfYear() { + return date.getDayOfYear(); + } + + /** + * Gets the day-of-week field, which is an enum {@code DayOfWeek}. + *

    + * This method returns the enum {@link DayOfWeek} for the day-of-week. + * This avoids confusion as to what {@code int} values mean. + * If you need access to the primitive {@code int} value then the enum + * provides the {@link DayOfWeek#getValue() int value}. + *

    + * Additional information can be obtained from the {@code DayOfWeek}. + * This includes textual names of the values. + * + * @return the day-of-week, not null + */ + public DayOfWeek getDayOfWeek() { + return date.getDayOfWeek(); + } + + //----------------------------------------------------------------------- + /** + * Returns an adjusted copy of this date. + *

    + * This returns a new {@code OffsetDate}, based on this one, with the date adjusted. + * The adjustment takes place using the specified adjuster strategy object. + * Read the documentation of the adjuster to understand what adjustment will be made. + *

    + * A simple adjuster might simply set the one of the fields, such as the year field. + * A more complex adjuster might set the date to the last day of the month. + * A selection of common adjustments is provided in {@link TemporalAdjusters}. + * These include finding the "last day of the month" and "next Wednesday". + * Key date-time classes also implement the {@code TemporalAdjuster} interface, + * such as {@link Month} and {@link MonthDay MonthDay}. + * The adjuster is responsible for handling special cases, such as the varying + * lengths of month and leap years. + *

    + * For example this code returns a date on the last day of July: + *

    +     *  import static org.threeten.bp.Month.*;
    +     *  import static org.threeten.bp.temporal.Adjusters.*;
    +     *
    +     *  result = offsetDate.with(JULY).with(lastDayOfMonth());
    +     * 
    + *

    + * The classes {@link LocalDate} and {@link ZoneOffset} implement {@code TemporalAdjuster}, + * thus this method can be used to change the date or offset: + *

    +     *  result = offsetDate.with(date);
    +     *  result = offsetDate.with(offset);
    +     * 
    + *

    + * The result of this method is obtained by invoking the + * {@link TemporalAdjuster#adjustInto(Temporal)} method on the + * specified adjuster passing {@code this} as the argument. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param adjuster the adjuster to use, not null + * @return an {@code OffsetDate} based on {@code this} with the adjustment made, not null + * @throws DateTimeException if the adjustment cannot be made + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public OffsetDate with(TemporalAdjuster adjuster) { + // optimizations + if (adjuster instanceof LocalDate) { + return with((LocalDate) adjuster, offset); + } else if (adjuster instanceof ZoneOffset) { + return with(date, (ZoneOffset) adjuster); + } else if (adjuster instanceof OffsetDate) { + return (OffsetDate) adjuster; + } + return (OffsetDate) adjuster.adjustInto(this); + } + + /** + * Returns a copy of this date with the specified field set to a new value. + *

    + * This returns a new {@code OffsetDate}, based on this one, with the value + * for the specified field changed. + * This can be used to change any supported field, such as the year, month or day-of-month. + * If it is not possible to set the value, because the field is not supported or for + * some other reason, an exception is thrown. + *

    + * In some cases, changing the specified field can cause the resulting date to become invalid, + * such as changing the month from 31st January to February would make the day-of-month invalid. + * In cases like this, the field is responsible for resolving the date. Typically it will choose + * the previous valid date, which would be the last valid day of February in this example. + *

    + * If the field is a {@link ChronoField} then the adjustment is implemented here. + *

    + * The {@code OFFSET_SECONDS} field will return a date with the specified offset. + * The local date is unaltered. If the new offset value is outside the valid range + * then a {@code DateTimeException} will be thrown. + *

    + * The other {@link #isSupported(TemporalField) supported fields} will behave as per + * the matching method on {@link LocalDate#with(TemporalField, long)} LocalDate}. + * In this case, the offset is not part of the calculation and will be unchanged. + *

    + * All other {@code ChronoField} instances will throw a {@code DateTimeException}. + *

    + * If the field is not a {@code ChronoField}, then the result of this method + * is obtained by invoking {@code TemporalField.doWith(Temporal, long)} + * passing {@code this} as the argument. In this case, the field determines + * whether and how to adjust the instant. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param field the field to set in the result, not null + * @param newValue the new value of the field in the result + * @return an {@code OffsetDate} based on {@code this} with the specified field set, not null + * @throws DateTimeException if the field cannot be set + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public OffsetDate with(TemporalField field, long newValue) { + if (field instanceof ChronoField) { + if (field == OFFSET_SECONDS) { + ChronoField f = (ChronoField) field; + return with(date, ZoneOffset.ofTotalSeconds(f.checkValidIntValue(newValue))); + } + return with(date.with(field, newValue), offset); + } + return field.doWith(this, newValue); + } + + //----------------------------------------------------------------------- + /** + * Returns a copy of this {@code OffsetDate} with the year altered. + * The offset does not affect the calculation and will be the same in the result. + * If the day-of-month is invalid for the year, it will be changed to the last valid day of the month. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param year the year to set in the result, from MIN_YEAR to MAX_YEAR + * @return an {@code OffsetDate} based on this date with the requested year, not null + * @throws DateTimeException if the year value is invalid + */ + public OffsetDate withYear(int year) { + return with(date.withYear(year), offset); + } + + /** + * Returns a copy of this {@code OffsetDate} with the month-of-year altered. + * The offset does not affect the calculation and will be the same in the result. + * If the day-of-month is invalid for the year, it will be changed to the last valid day of the month. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param month the month-of-year to set in the result, from 1 (January) to 12 (December) + * @return an {@code OffsetDate} based on this date with the requested month, not null + * @throws DateTimeException if the month-of-year value is invalid + */ + public OffsetDate withMonth(int month) { + return with(date.withMonth(month), offset); + } + + /** + * Returns a copy of this {@code OffsetDate} with the day-of-month altered. + * If the resulting date is invalid, an exception is thrown. + * The offset does not affect the calculation and will be the same in the result. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param dayOfMonth the day-of-month to set in the result, from 1 to 28-31 + * @return an {@code OffsetDate} based on this date with the requested day, not null + * @throws DateTimeException if the day-of-month value is invalid + * @throws DateTimeException if the day-of-month is invalid for the month-year + */ + public OffsetDate withDayOfMonth(int dayOfMonth) { + return with(date.withDayOfMonth(dayOfMonth), offset); + } + + /** + * Returns a copy of this {@code OffsetDate} with the day-of-year altered. + * If the resulting date is invalid, an exception is thrown. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param dayOfYear the day-of-year to set in the result, from 1 to 365-366 + * @return an {@code OffsetDate} based on this date with the requested day, not null + * @throws DateTimeException if the day-of-year value is invalid + * @throws DateTimeException if the day-of-year is invalid for the year + */ + public OffsetDate withDayOfYear(int dayOfYear) { + return with(date.withDayOfYear(dayOfYear), offset); + } + + //----------------------------------------------------------------------- + /** + * Returns a copy of this date with the specified period added. + *

    + * This method returns a new date based on this date with the specified period added. + * The adder is typically {@link Period} but may be any other type implementing + * the {@link TemporalAdder} interface. + * The calculation is delegated to the specified adjuster, which typically calls + * back to {@link #plus(long, TemporalUnit)}. + * The offset is not part of the calculation and will be unchanged in the result. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param adder the adder to use, not null + * @return an {@code OffsetDate} based on this date with the addition made, not null + * @throws DateTimeException if the addition cannot be made + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public OffsetDate plus(TemporalAdder adder) { + return (OffsetDate) adder.addTo(this); + } + + /** + * Returns a copy of this date with the specified period added. + *

    + * This method returns a new date based on this date with the specified period added. + * This can be used to add any period that is defined by a unit, for example to add years, months or days. + * The unit is responsible for the details of the calculation, including the resolution + * of any edge cases in the calculation. + * The offset is not part of the calculation and will be unchanged in the result. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param amountToAdd the amount of the unit to add to the result, may be negative + * @param unit the unit of the period to add, not null + * @return an {@code OffsetDate} based on this date with the specified period added, not null + * @throws DateTimeException if the unit cannot be added to this type + */ + @Override + public OffsetDate plus(long amountToAdd, TemporalUnit unit) { + if (unit instanceof ChronoUnit) { + return with(date.plus(amountToAdd, unit), offset); + } + return unit.doPlus(this, amountToAdd); + } + + //----------------------------------------------------------------------- + /** + * Returns a copy of this {@code OffsetDate} with the specified period in years added. + *

    + * This method adds the specified amount to the years field in three steps: + *

      + *
    1. Add the input years to the year field
    2. + *
    3. Check if the resulting date would be invalid
    4. + *
    5. Adjust the day-of-month to the last valid day if necessary
    6. + *
    + *

    + * For example, 2008-02-29 (leap year) plus one year would result in the + * invalid date 2009-02-29 (standard year). Instead of returning an invalid + * result, the last valid day of the month, 2009-02-28, is selected instead. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param years the years to add, may be negative + * @return an {@code OffsetDate} based on this date with the years added, not null + * @throws DateTimeException if the result exceeds the supported date range + */ + public OffsetDate plusYears(long years) { + return with(date.plusYears(years), offset); + } + + /** + * Returns a copy of this {@code OffsetDate} with the specified period in months added. + *

    + * This method adds the specified amount to the months field in three steps: + *

      + *
    1. Add the input months to the month-of-year field
    2. + *
    3. Check if the resulting date would be invalid
    4. + *
    5. Adjust the day-of-month to the last valid day if necessary
    6. + *
    + *

    + * For example, 2007-03-31 plus one month would result in the invalid date + * 2007-04-31. Instead of returning an invalid result, the last valid day + * of the month, 2007-04-30, is selected instead. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param months the months to add, may be negative + * @return an {@code OffsetDate} based on this date with the months added, not null + * @throws DateTimeException if the result exceeds the supported date range + */ + public OffsetDate plusMonths(long months) { + return with(date.plusMonths(months), offset); + } + + /** + * Returns a copy of this {@code OffsetDate} with the specified period in weeks added. + *

    + * This method adds the specified amount in weeks to the days field incrementing + * the month and year fields as necessary to ensure the result remains valid. + * The result is only invalid if the maximum/minimum year is exceeded. + *

    + * For example, 2008-12-31 plus one week would result in 2009-01-07. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param weeks the weeks to add, may be negative + * @return an {@code OffsetDate} based on this date with the weeks added, not null + * @throws DateTimeException if the result exceeds the supported date range + */ + public OffsetDate plusWeeks(long weeks) { + return with(date.plusWeeks(weeks), offset); + } + + /** + * Returns a copy of this {@code OffsetDate} with the specified period in days added. + *

    + * This method adds the specified amount to the days field incrementing the + * month and year fields as necessary to ensure the result remains valid. + * The result is only invalid if the maximum/minimum year is exceeded. + *

    + * For example, 2008-12-31 plus one day would result in 2009-01-01. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param days the days to add, may be negative + * @return an {@code OffsetDate} based on this date with the days added, not null + * @throws DateTimeException if the result exceeds the supported date range + */ + public OffsetDate plusDays(long days) { + return with(date.plusDays(days), offset); + } + + //----------------------------------------------------------------------- + /** + * Returns a copy of this date with the specified period subtracted. + *

    + * This method returns a new date based on this date with the specified period subtracted. + * The subtractor is typically {@link Period} but may be any other type implementing + * the {@link TemporalSubtractor} interface. + * The calculation is delegated to the specified adjuster, which typically calls + * back to {@link #minus(long, TemporalUnit)}. + * The offset is not part of the calculation and will be unchanged in the result. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param subtractor the subtractor to use, not null + * @return an {@code OffsetDate} based on this date with the subtraction made, not null + * @throws DateTimeException if the subtraction cannot be made + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public OffsetDate minus(TemporalSubtractor subtractor) { + return (OffsetDate) subtractor.subtractFrom(this); + } + + /** + * Returns a copy of this date with the specified period subtracted. + *

    + * This method returns a new date based on this date with the specified period subtracted. + * This can be used to subtract any period that is defined by a unit, for example to subtract years, months or days. + * The unit is responsible for the details of the calculation, including the resolution + * of any edge cases in the calculation. + * The offset is not part of the calculation and will be unchanged in the result. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param amountToSubtract the amount of the unit to subtract from the result, may be negative + * @param unit the unit of the period to subtract, not null + * @return an {@code OffsetDate} based on this date with the specified period subtracted, not null + * @throws DateTimeException if the unit cannot be added to this type + */ + @Override + public OffsetDate minus(long amountToSubtract, TemporalUnit unit) { + return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit)); + } + + //----------------------------------------------------------------------- + /** + * Returns a copy of this {@code OffsetDate} with the specified period in years subtracted. + *

    + * This method subtracts the specified amount from the years field in three steps: + *

      + *
    1. Subtract the input years to the year field
    2. + *
    3. Check if the resulting date would be invalid
    4. + *
    5. Adjust the day-of-month to the last valid day if necessary
    6. + *
    + *

    + * For example, 2008-02-29 (leap year) minus one year would result in the + * invalid date 2007-02-29 (standard year). Instead of returning an invalid + * result, the last valid day of the month, 2007-02-28, is selected instead. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param years the years to subtract, may be negative + * @return an {@code OffsetDate} based on this date with the years subtracted, not null + * @throws DateTimeException if the result exceeds the supported date range + */ + public OffsetDate minusYears(long years) { + return with(date.minusYears(years), offset); + } + + /** + * Returns a copy of this {@code OffsetDate} with the specified period in months subtracted. + *

    + * This method subtracts the specified amount from the months field in three steps: + *

      + *
    1. Subtract the input months to the month-of-year field
    2. + *
    3. Check if the resulting date would be invalid
    4. + *
    5. Adjust the day-of-month to the last valid day if necessary
    6. + *
    + *

    + * For example, 2007-03-31 minus one month would result in the invalid date + * 2007-02-31. Instead of returning an invalid result, the last valid day + * of the month, 2007-02-28, is selected instead. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param months the months to subtract, may be negative + * @return an {@code OffsetDate} based on this date with the months subtracted, not null + * @throws DateTimeException if the result exceeds the supported date range + */ + public OffsetDate minusMonths(long months) { + return with(date.minusMonths(months), offset); + } + + /** + * Returns a copy of this {@code OffsetDate} with the specified period in weeks subtracted. + *

    + * This method subtracts the specified amount in weeks from the days field decrementing + * the month and year fields as necessary to ensure the result remains valid. + * The result is only invalid if the maximum/minimum year is exceeded. + *

    + * For example, 2009-01-07 minus one week would result in 2008-12-31. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param weeks the weeks to subtract, may be negative + * @return an {@code OffsetDate} based on this date with the weeks subtracted, not null + * @throws DateTimeException if the result exceeds the supported date range + */ + public OffsetDate minusWeeks(long weeks) { + return with(date.minusWeeks(weeks), offset); + } + + /** + * Returns a copy of this {@code OffsetDate} with the specified number of days subtracted. + *

    + * This method subtracts the specified amount from the days field decrementing the + * month and year fields as necessary to ensure the result remains valid. + * The result is only invalid if the maximum/minimum year is exceeded. + *

    + * For example, 2009-01-01 minus one day would result in 2008-12-31. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param days the days to subtract, may be negative + * @return an {@code OffsetDate} based on this date with the days subtracted, not null + * @throws DateTimeException if the result exceeds the supported date range + */ + public OffsetDate minusDays(long days) { + return with(date.minusDays(days), offset); + } + + //----------------------------------------------------------------------- + /** + * Queries this date using the specified query. + *

    + * This queries this date using the specified query strategy object. + * The {@code TemporalQuery} object defines the logic to be used to + * obtain the result. Read the documentation of the query to understand + * what the result of this method will be. + *

    + * The result of this method is obtained by invoking the + * {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the + * specified query passing {@code this} as the argument. + * + * @param the type of the result + * @param query the query to invoke, not null + * @return the query result, null may be returned (defined by the query) + * @throws DateTimeException if unable to query (defined by the query) + * @throws ArithmeticException if numeric overflow occurs (defined by the query) + */ + @SuppressWarnings("unchecked") + @Override + public R query(TemporalQuery query) { + if (query == TemporalQueries.chrono()) { + return (R) ISOChrono.INSTANCE; + } else if (query == TemporalQueries.precision()) { + return (R) DAYS; + } else if (query == TemporalQueries.offset() || query == TemporalQueries.zone()) { + return (R) getOffset(); + } + return super.query(query); + } + + /** + * Adjusts the specified temporal object to have the same offset and date + * as this object. + *

    + * This returns a temporal object of the same observable type as the input + * with the offset and date changed to be the same as this. + *

    + * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)} + * twice, passing {@link ChronoField#OFFSET_SECONDS} and + * {@link ChronoField#EPOCH_DAY} as the fields. + *

    + * In most cases, it is clearer to reverse the calling pattern by using + * {@link Temporal#with(TemporalAdjuster)}: + *

    +     *   // these two lines are equivalent, but the second approach is recommended
    +     *   temporal = thisOffsetDate.adjustInto(temporal);
    +     *   temporal = temporal.with(thisOffsetDate);
    +     * 
    + *

    + * This instance is immutable and unaffected by this method call. + * + * @param temporal the target object to be adjusted, not null + * @return the adjusted object, not null + * @throws DateTimeException if unable to make the adjustment + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public Temporal adjustInto(Temporal temporal) { + return temporal + .with(OFFSET_SECONDS, getOffset().getTotalSeconds()) + .with(EPOCH_DAY, getDate().toEpochDay()); + } + + /** + * Calculates the period between this date and another date in + * terms of the specified unit. + *

    + * This calculates the period between two dates in terms of a single unit. + * The start and end points are {@code this} and the specified date. + * The result will be negative if the end is before the start. + * For example, the period in days between two dates can be calculated + * using {@code startDate.periodUntil(endDate, DAYS)}. + *

    + * The {@code Temporal} passed to this method must be an {@code OffsetDate}. + * If the offset differs between the two times, then the specified + * end time is normalized to have the same offset as this time. + *

    + * The calculation returns a whole number, representing the number of + * complete units between the two dates. + * For example, the period in months between 2012-06-15Z and 2012-08-14Z + * will only be one month as it is one day short of two months. + *

    + * This method operates in association with {@link TemporalUnit#between}. + * The result of this method is a {@code long} representing the amount of + * the specified unit. By contrast, the result of {@code between} is an + * object that can be used directly in addition/subtraction: + *

    +     *   long period = start.periodUntil(end, MONTHS);   // this method
    +     *   dateTime.plus(MONTHS.between(start, end));      // use in plus/minus
    +     * 
    + *

    + * The calculation is implemented in this method for {@link ChronoUnit}. + * The units {@code DAYS}, {@code WEEKS}, {@code MONTHS}, {@code YEARS}, + * {@code DECADES}, {@code CENTURIES}, {@code MILLENNIA} and {@code ERAS} + * are supported. Other {@code ChronoUnit} values will throw an exception. + *

    + * If the unit is not a {@code ChronoUnit}, then the result of this method + * is obtained by invoking {@code TemporalUnit.between(Temporal, Temporal)} + * passing {@code this} as the first argument and the input temporal as + * the second argument. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param endDate the end date, which must be an {@code OffsetDate}, not null + * @param unit the unit to measure the period in, not null + * @return the amount of the period between this date and the end date + * @throws DateTimeException if the period cannot be calculated + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public long periodUntil(Temporal endDate, TemporalUnit unit) { + if (endDate instanceof OffsetDate == false) { + Objects.requireNonNull(endDate, "endDate"); + throw new DateTimeException("Unable to calculate period between objects of two different types"); + } + if (unit instanceof ChronoUnit) { + OffsetDate end = (OffsetDate) endDate; + long offsetDiff = end.offset.getTotalSeconds() - offset.getTotalSeconds(); + LocalDate endLocal = end.date.plusDays(Jdk8Methods.floorDiv(-offsetDiff, SECONDS_PER_DAY)); + return date.periodUntil(endLocal, unit); + } + return unit.between(this, endDate).getAmount(); + } + + //----------------------------------------------------------------------- + /** + * Returns an offset date-time formed from this date at the specified time. + *

    + * This combines this date with the specified time to form an {@code OffsetDateTime}. + * All possible combinations of date and time are valid. + *

    + * This instance is immutable and unaffected by this method call. + * + * @param time the time to combine with, not null + * @return the offset date-time formed from this date and the specified time, not null + */ + public OffsetDateTime atTime(LocalTime time) { + return OffsetDateTime.of(date, time, offset); + } + + //----------------------------------------------------------------------- + /** + * Converts this date to midnight at the start of day in epoch seconds. + * + * @return the epoch seconds value + */ + private long toEpochSecond() { + long epochDay = date.toEpochDay(); + long secs = epochDay * SECONDS_PER_DAY; + return secs - offset.getTotalSeconds(); + } + + //----------------------------------------------------------------------- + /** + * Compares this {@code OffsetDate} to another date. + *

    + * The comparison is based first on the UTC equivalent instant, then on the local date. + * It is "consistent with equals", as defined by {@link Comparable}. + *

    + * For example, the following is the comparator order: + *

      + *
    1. 2008-06-29-11:00
    2. + *
    3. 2008-06-29-12:00
    4. + *
    5. 2008-06-30+12:00
    6. + *
    7. 2008-06-29-13:00
    8. + *
    + * Values #2 and #3 represent the same instant on the time-line. + * When two values represent the same instant, the local date is compared + * to distinguish them. This step is needed to make the ordering + * consistent with {@code equals()}. + *

    + * To compare the underlying local date of two {@code TemporalAccessor} instances, + * use {@link ChronoField#EPOCH_DAY} as a comparator. + * + * @param other the other date to compare to, not null + * @return the comparator value, negative if less, positive if greater + */ + @Override + public int compareTo(OffsetDate other) { + if (offset.equals(other.offset)) { + return date.compareTo(other.date); + } + int compare = Long.compare(toEpochSecond(), other.toEpochSecond()); + if (compare == 0) { + compare = date.compareTo(other.date); + } + return compare; + } + + //----------------------------------------------------------------------- + /** + * Checks if the instant of midnight at the start of this {@code OffsetDate} + * is after midnight at the start of the specified date. + *

    + * This method differs from the comparison in {@link #compareTo} in that it + * only compares the instant of the date. This is equivalent to using + * {@code date1.toEpochSecond().isAfter(date2.toEpochSecond())}. + * + * @param other the other date to compare to, not null + * @return true if this is after the instant of the specified date + */ + public boolean isAfter(OffsetDate other) { + return toEpochSecond() > other.toEpochSecond(); + } + + /** + * Checks if the instant of midnight at the start of this {@code OffsetDate} + * is before midnight at the start of the specified date. + *

    + * This method differs from the comparison in {@link #compareTo} in that it + * only compares the instant of the date. This is equivalent to using + * {@code date1.toEpochSecond().isBefore(date2.toEpochSecond())}. + * + * @param other the other date to compare to, not null + * @return true if this is before the instant of the specified date + */ + public boolean isBefore(OffsetDate other) { + return toEpochSecond() < other.toEpochSecond(); + } + + /** + * Checks if the instant of midnight at the start of this {@code OffsetDate} + * equals midnight at the start of the specified date. + *

    + * This method differs from the comparison in {@link #compareTo} and {@link #equals} + * in that it only compares the instant of the date. This is equivalent to using + * {@code date1.toEpochSecond().equals(date2.toEpochSecond())}. + * + * @param other the other date to compare to, not null + * @return true if the instant equals the instant of the specified date + */ + public boolean isEqual(OffsetDate other) { + return toEpochSecond() == other.toEpochSecond(); + } + + //----------------------------------------------------------------------- + /** + * Checks if this date is equal to another date. + *

    + * The comparison is based on the local-date and the offset. + * To compare for the same instant on the time-line, use {@link #isEqual(OffsetDate)}. + *

    + * Only objects of type {@code OffsetDate} are compared, other types return false. + * To compare the underlying local date of two {@code TemporalAccessor} instances, + * use {@link ChronoField#EPOCH_DAY} as a comparator. + * + * @param obj the object to check, null returns false + * @return true if this is equal to the other date + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof OffsetDate) { + OffsetDate other = (OffsetDate) obj; + return date.equals(other.date) && offset.equals(other.offset); + } + return false; + } + + /** + * A hash code for this date. + * + * @return a suitable hash code + */ + @Override + public int hashCode() { + return date.hashCode() ^ offset.hashCode(); + } + + //----------------------------------------------------------------------- + /** + * Outputs this date as a {@code String}, such as {@code 2007-12-03+01:00}. + *

    + * The output will be in the ISO-8601 format {@code yyyy-MM-ddXXXXX}. + * + * @return a string representation of this date, not null + */ + @Override + public String toString() { + return date.toString() + offset.toString(); + } + + /** + * Outputs this date as a {@code String} using the formatter. + *

    + * This date will be passed to the formatter + * {@link DateTimeFormatter#print(TemporalAccessor) print method}. + * + * @param formatter the formatter to use, not null + * @return the formatted date string, not null + * @throws DateTimeException if an error occurs during printing + */ + public String toString(DateTimeFormatter formatter) { + Objects.requireNonNull(formatter, "formatter"); + return formatter.print(this); + } + + //----------------------------------------------------------------------- + private Object writeReplace() { + return new Ser(Ser.OFFSET_DATE_TYPE, this); + } + + /** + * Defend against malicious streams. + * @return never + * @throws InvalidObjectException always + */ + private Object readResolve() throws ObjectStreamException { + throw new InvalidObjectException("Deserialization via serialization delegate"); + } + + void writeExternal(DataOutput out) throws IOException { + date.writeExternal(out); + offset.writeExternal(out); + } + + static OffsetDate readExternal(DataInput in) throws IOException { + LocalDate date = LocalDate.readExternal(in); + ZoneOffset offset = ZoneOffset.readExternal(in); + return OffsetDate.of(date, offset); + } + +} From 86aab0e650c77a8110ea4f3cdf17560ea0778221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Mon, 1 Apr 2019 23:37:46 +0200 Subject: [PATCH 142/279] Fix OffsetDate compilation --- .../java/org/threeten/extra/OffsetDate.java | 190 ++++++++++-------- 1 file changed, 103 insertions(+), 87 deletions(-) diff --git a/src/main/java/org/threeten/extra/OffsetDate.java b/src/main/java/org/threeten/extra/OffsetDate.java index 3eb0eb04..2e79f1f9 100644 --- a/src/main/java/org/threeten/extra/OffsetDate.java +++ b/src/main/java/org/threeten/extra/OffsetDate.java @@ -29,42 +29,43 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.threeten.bp; +package org.threeten.extra; -import static org.threeten.bp.LocalTime.SECONDS_PER_DAY; -import static org.threeten.bp.temporal.ChronoField.EPOCH_DAY; -import static org.threeten.bp.temporal.ChronoField.OFFSET_SECONDS; -import static org.threeten.bp.temporal.ChronoUnit.DAYS; +import static java.time.temporal.ChronoField.EPOCH_DAY; +import static java.time.temporal.ChronoField.OFFSET_SECONDS; +import static java.time.temporal.ChronoUnit.DAYS; -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.io.InvalidObjectException; -import java.io.ObjectStreamException; import java.io.Serializable; +import java.time.Clock; +import java.time.DateTimeException; +import java.time.DayOfWeek; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.Month; +import java.time.MonthDay; +import java.time.OffsetDateTime; +import java.time.Period; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.chrono.IsoChronology; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoField; +import java.time.temporal.ChronoUnit; +import java.time.temporal.Temporal; +import java.time.temporal.TemporalAccessor; +import java.time.temporal.TemporalAdjuster; +import java.time.temporal.TemporalAdjusters; +import java.time.temporal.TemporalAmount; +import java.time.temporal.TemporalField; +import java.time.temporal.TemporalQueries; +import java.time.temporal.TemporalQuery; +import java.time.temporal.TemporalUnit; +import java.time.temporal.ValueRange; +import java.time.zone.ZoneRules; import java.util.Objects; -import org.threeten.bp.format.DateTimeFormatter; -import org.threeten.bp.format.DateTimeFormatters; -import org.threeten.bp.format.DateTimeParseException; -import org.threeten.bp.jdk8.DefaultInterfaceTemporalAccessor; -import org.threeten.bp.jdk8.Jdk8Methods; -import org.threeten.bp.temporal.ChronoField; -import org.threeten.bp.temporal.ChronoUnit; -import org.threeten.bp.temporal.ISOChrono; -import org.threeten.bp.temporal.Temporal; -import org.threeten.bp.temporal.TemporalAccessor; -import org.threeten.bp.temporal.TemporalAdder; -import org.threeten.bp.temporal.TemporalAdjuster; -import org.threeten.bp.temporal.TemporalAdjusters; -import org.threeten.bp.temporal.TemporalField; -import org.threeten.bp.temporal.TemporalQueries; -import org.threeten.bp.temporal.TemporalQuery; -import org.threeten.bp.temporal.TemporalSubtractor; -import org.threeten.bp.temporal.TemporalUnit; -import org.threeten.bp.temporal.ValueRange; -import org.threeten.bp.zone.ZoneRules; - /** * A date with an offset from UTC/Greenwich in the ISO-8601 calendar system, * such as {@code 2007-12-03+01:00}. @@ -81,7 +82,6 @@ * This class is immutable and thread-safe. */ public final class OffsetDate - extends DefaultInterfaceTemporalAccessor implements Temporal, TemporalAdjuster, Comparable, Serializable { /** @@ -91,7 +91,7 @@ public final class OffsetDate * This combines {@link LocalDate#MIN} and {@link ZoneOffset#MAX}. * This could be used by an application as a "far past" date. */ - public static final OffsetDate MIN = LocalDate.MIN.atOffset(ZoneOffset.MAX); + public static final OffsetDate MIN = new OffsetDate(LocalDate.MIN, ZoneOffset.MAX); /** * The maximum supported {@code OffsetDate}, '+999999999-12-31-18:00'. * This is the maximum local date in the minimum offset @@ -99,13 +99,18 @@ public final class OffsetDate * This combines {@link LocalDate#MAX} and {@link ZoneOffset#MIN}. * This could be used by an application as a "far future" date. */ - public static final OffsetDate MAX = LocalDate.MAX.atOffset(ZoneOffset.MIN); + public static final OffsetDate MAX = new OffsetDate(LocalDate.MAX, ZoneOffset.MIN); /** * Serialization version. */ private static final long serialVersionUID = -4382054179074397774L; + /** + * The number of seconds per day. + */ + private static final long SECONDS_PER_DAY = 86400; + /** * The local date. */ @@ -198,7 +203,7 @@ public static OffsetDate ofInstant(Instant instant, ZoneId zone) { ZoneRules rules = zone.getRules(); ZoneOffset offset = rules.getOffset(instant); long epochSec = instant.getEpochSecond() + offset.getTotalSeconds(); // overflow caught later - long epochDay = Jdk8Methods.floorDiv(epochSec, SECONDS_PER_DAY); + long epochDay = Math.floorDiv(epochSec, SECONDS_PER_DAY); LocalDate date = LocalDate.ofEpochDay(epochDay); return new OffsetDate(date, offset); } @@ -237,14 +242,14 @@ public static OffsetDate from(TemporalAccessor temporal) { * Obtains an instance of {@code OffsetDate} from a text string such as {@code 2007-12-03+01:00}. *

    * The string must represent a valid date and is parsed using - * {@link org.threeten.bp.format.DateTimeFormatters#isoOffsetDate()}. + * {@link DateTimeFormatter#ISO_OFFSET_DATE}. * * @param text the text to parse such as "2007-12-03+01:00", not null * @return the parsed offset date, not null * @throws DateTimeParseException if the text cannot be parsed */ public static OffsetDate parse(CharSequence text) { - return parse(text, DateTimeFormatters.isoOffsetDate()); + return parse(text, DateTimeFormatter.ISO_OFFSET_DATE); } /** @@ -259,7 +264,7 @@ public static OffsetDate parse(CharSequence text) { */ public static OffsetDate parse(CharSequence text, DateTimeFormatter formatter) { Objects.requireNonNull(formatter, "formatter"); - return formatter.parse(text, OffsetDate.class); + return formatter.parse(text, OffsetDate::from); } //----------------------------------------------------------------------- @@ -328,9 +333,45 @@ private OffsetDate with(LocalDate date, ZoneOffset offset) { @Override public boolean isSupported(TemporalField field) { if (field instanceof ChronoField) { - return ((ChronoField) field).isDateField() || field == OFFSET_SECONDS; + return ((ChronoField) field).isDateBased() || field == OFFSET_SECONDS; } - return field != null && field.doIsSupported(this); + return field != null && field.isSupportedBy(this); + } + + /** + * Checks if the specified unit is supported. + *

    + * This checks if the specified unit can be added to, or subtracted from, this date. + * If false, then calling the {@link #plus(long, TemporalUnit)} and + * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. + *

    + * If the unit is a {@link ChronoUnit} then the query is implemented here. + * The supported units are: + *

      + *
    • {@code DAYS} + *
    • {@code WEEKS} + *
    • {@code MONTHS} + *
    • {@code YEARS} + *
    • {@code DECADES} + *
    • {@code CENTURIES} + *
    • {@code MILLENNIA} + *
    • {@code ERAS} + *
    + * All other {@code ChronoUnit} instances will return false. + *

    + * If the unit is not a {@code ChronoUnit}, then the result of this method + * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} + * passing {@code this} as the argument. + * Whether the unit is supported is determined by the unit. + * + * @param unit the unit to check, null returns false + * @return true if the unit can be added/subtracted, false if not + */ + public boolean isSupported(TemporalUnit unit) { + if (unit instanceof ChronoUnit) { + return ((ChronoUnit) unit).isDateBased(); + } + return unit != null && unit.isSupportedBy(this); } /** @@ -363,7 +404,7 @@ public ValueRange range(TemporalField field) { } return date.range(field); } - return field.doRange(this); + return field.rangeRefinedBy(this); } /** @@ -392,7 +433,7 @@ public ValueRange range(TemporalField field) { */ @Override // override for Javadoc public int get(TemporalField field) { - return super.get(field); + return Temporal.super.get(field); } /** @@ -425,7 +466,7 @@ public long getLong(TemporalField field) { } return date.getLong(field); } - return field.doGet(this); + return field.getFrom(this); } //----------------------------------------------------------------------- @@ -658,7 +699,7 @@ public OffsetDate with(TemporalField field, long newValue) { } return with(date.with(field, newValue), offset); } - return field.doWith(this, newValue); + return field.adjustInto(this, newValue); } //----------------------------------------------------------------------- @@ -729,21 +770,21 @@ public OffsetDate withDayOfYear(int dayOfYear) { *

    * This method returns a new date based on this date with the specified period added. * The adder is typically {@link Period} but may be any other type implementing - * the {@link TemporalAdder} interface. + * the {@link TemporalAmount} interface. * The calculation is delegated to the specified adjuster, which typically calls * back to {@link #plus(long, TemporalUnit)}. * The offset is not part of the calculation and will be unchanged in the result. *

    * This instance is immutable and unaffected by this method call. * - * @param adder the adder to use, not null + * @param amountToAdd the adder to use, not null * @return an {@code OffsetDate} based on this date with the addition made, not null * @throws DateTimeException if the addition cannot be made * @throws ArithmeticException if numeric overflow occurs */ @Override - public OffsetDate plus(TemporalAdder adder) { - return (OffsetDate) adder.addTo(this); + public OffsetDate plus(TemporalAmount amountToAdd) { + return (OffsetDate) amountToAdd.addTo(this); } /** @@ -767,7 +808,7 @@ public OffsetDate plus(long amountToAdd, TemporalUnit unit) { if (unit instanceof ChronoUnit) { return with(date.plus(amountToAdd, unit), offset); } - return unit.doPlus(this, amountToAdd); + return unit.addTo(this, amountToAdd); } //----------------------------------------------------------------------- @@ -863,21 +904,21 @@ public OffsetDate plusDays(long days) { *

    * This method returns a new date based on this date with the specified period subtracted. * The subtractor is typically {@link Period} but may be any other type implementing - * the {@link TemporalSubtractor} interface. + * the {@link TemporalAmount} interface. * The calculation is delegated to the specified adjuster, which typically calls * back to {@link #minus(long, TemporalUnit)}. * The offset is not part of the calculation and will be unchanged in the result. *

    * This instance is immutable and unaffected by this method call. * - * @param subtractor the subtractor to use, not null + * @param amountToSubtract the subtractor to use, not null * @return an {@code OffsetDate} based on this date with the subtraction made, not null * @throws DateTimeException if the subtraction cannot be made * @throws ArithmeticException if numeric overflow occurs */ @Override - public OffsetDate minus(TemporalSubtractor subtractor) { - return (OffsetDate) subtractor.subtractFrom(this); + public OffsetDate minus(TemporalAmount amountToSubtract) { + return (OffsetDate) amountToSubtract.subtractFrom(this); } /** @@ -1010,14 +1051,14 @@ public OffsetDate minusDays(long days) { @SuppressWarnings("unchecked") @Override public R query(TemporalQuery query) { - if (query == TemporalQueries.chrono()) { - return (R) ISOChrono.INSTANCE; + if (query == TemporalQueries.chronology()) { + return (R) IsoChronology.INSTANCE; } else if (query == TemporalQueries.precision()) { return (R) DAYS; } else if (query == TemporalQueries.offset() || query == TemporalQueries.zone()) { return (R) getOffset(); } - return super.query(query); + return Temporal.super.query(query); } /** @@ -1100,7 +1141,7 @@ public Temporal adjustInto(Temporal temporal) { * @throws ArithmeticException if numeric overflow occurs */ @Override - public long periodUntil(Temporal endDate, TemporalUnit unit) { + public long until(Temporal endDate, TemporalUnit unit) { if (endDate instanceof OffsetDate == false) { Objects.requireNonNull(endDate, "endDate"); throw new DateTimeException("Unable to calculate period between objects of two different types"); @@ -1108,10 +1149,10 @@ public long periodUntil(Temporal endDate, TemporalUnit unit) { if (unit instanceof ChronoUnit) { OffsetDate end = (OffsetDate) endDate; long offsetDiff = end.offset.getTotalSeconds() - offset.getTotalSeconds(); - LocalDate endLocal = end.date.plusDays(Jdk8Methods.floorDiv(-offsetDiff, SECONDS_PER_DAY)); - return date.periodUntil(endLocal, unit); + LocalDate endLocal = end.date.plusDays(Math.floorDiv(-offsetDiff, SECONDS_PER_DAY)); + return date.until(endLocal, unit); } - return unit.between(this, endDate).getAmount(); + return unit.between(this, endDate); } //----------------------------------------------------------------------- @@ -1278,7 +1319,7 @@ public String toString() { * Outputs this date as a {@code String} using the formatter. *

    * This date will be passed to the formatter - * {@link DateTimeFormatter#print(TemporalAccessor) print method}. + * {@link DateTimeFormatter#format(TemporalAccessor) print method}. * * @param formatter the formatter to use, not null * @return the formatted date string, not null @@ -1286,32 +1327,7 @@ public String toString() { */ public String toString(DateTimeFormatter formatter) { Objects.requireNonNull(formatter, "formatter"); - return formatter.print(this); - } - - //----------------------------------------------------------------------- - private Object writeReplace() { - return new Ser(Ser.OFFSET_DATE_TYPE, this); - } - - /** - * Defend against malicious streams. - * @return never - * @throws InvalidObjectException always - */ - private Object readResolve() throws ObjectStreamException { - throw new InvalidObjectException("Deserialization via serialization delegate"); - } - - void writeExternal(DataOutput out) throws IOException { - date.writeExternal(out); - offset.writeExternal(out); - } - - static OffsetDate readExternal(DataInput in) throws IOException { - LocalDate date = LocalDate.readExternal(in); - ZoneOffset offset = ZoneOffset.readExternal(in); - return OffsetDate.of(date, offset); + return formatter.format(this); } } From c47d7f30393216b6e911b03bd522ecde059cf158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 3 Apr 2019 17:17:52 +0200 Subject: [PATCH 143/279] Add TestOffsetDate https://github.com/ThreeTen/threetenbp/blob/e25d72b8591b6a1bf73cf048e2a4d1aeabe040eb/src/test/java/org/threeten/bp/TestOffsetDate.java https://github.com/ThreeTen/threetenbp/blob/e3c78d0d882414cec46f73c80a3b1a1a045ee792/src/test/java/org/threeten/bp/AbstractDateTimeTest.java https://github.com/ThreeTen/threetenbp/blob/9cb200214d8a5daf4f0f55de921484b77d08c103/src/test/java/org/threeten/bp/AbstractTest.java https://github.com/ThreeTen/threetenbp/blob/9cb200214d8a5daf4f0f55de921484b77d08c103/src/test/java/org/threeten/bp/MockSimplePeriod.java --- .../threeten/extra/AbstractDateTimeTest.java | 234 ++ .../java/org/threeten/extra/AbstractTest.java | 210 ++ .../org/threeten/extra/MockSimplePeriod.java | 159 ++ .../org/threeten/extra/TestOffsetDate.java | 1882 +++++++++++++++++ 4 files changed, 2485 insertions(+) create mode 100644 src/test/java/org/threeten/extra/AbstractDateTimeTest.java create mode 100644 src/test/java/org/threeten/extra/AbstractTest.java create mode 100644 src/test/java/org/threeten/extra/MockSimplePeriod.java create mode 100644 src/test/java/org/threeten/extra/TestOffsetDate.java diff --git a/src/test/java/org/threeten/extra/AbstractDateTimeTest.java b/src/test/java/org/threeten/extra/AbstractDateTimeTest.java new file mode 100644 index 00000000..acf0764d --- /dev/null +++ b/src/test/java/org/threeten/extra/AbstractDateTimeTest.java @@ -0,0 +1,234 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.bp; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.fail; + +import java.util.List; + +import org.testng.annotations.Test; +import org.threeten.bp.temporal.TemporalAccessor; +import org.threeten.bp.temporal.TemporalField; +import org.threeten.bp.temporal.TemporalQuery; + +/** + * Base test class for {@code DateTime}. + */ +public abstract class AbstractDateTimeTest extends AbstractTest { + + /** + * Sample {@code DateTime} objects. + * @return the objects, not null + */ + protected abstract List samples(); + + /** + * List of valid supported fields. + * @return the fields, not null + */ + protected abstract List validFields(); + + /** + * List of invalid unsupported fields. + * @return the fields, not null + */ + protected abstract List invalidFields(); + + //----------------------------------------------------------------------- + // isSupported(DateTimeField) + //----------------------------------------------------------------------- + @Test + public void basicTest_isSupported_DateTimeField_supported() { + for (TemporalAccessor sample : samples()) { + for (TemporalField field : validFields()) { + assertEquals(sample.isSupported(field), true, "Failed on " + sample + " " + field); + } + } + } + + @Test + public void basicTest_isSupported_DateTimeField_unsupported() { + for (TemporalAccessor sample : samples()) { + for (TemporalField field : invalidFields()) { + assertEquals(sample.isSupported(field), false, "Failed on " + sample + " " + field); + } + } + } + + @Test + public void basicTest_isSupported_DateTimeField_null() { + for (TemporalAccessor sample : samples()) { + assertEquals(sample.isSupported(null), false, "Failed on " + sample); + } + } + + //----------------------------------------------------------------------- + // range(DateTimeField) + //----------------------------------------------------------------------- +// TODO needs implementations of week fields +// @Test +// public void basicTest_range_DateTimeField_supported() { +// for (DateTimeAccessor sample : samples()) { +// for (DateTimeField field : validFields()) { +// sample.range(field); // no exception +// } +// } +// } + + @Test + public void basicTest_range_DateTimeField_unsupported() { + for (TemporalAccessor sample : samples()) { + for (TemporalField field : invalidFields()) { + try { + sample.range(field); + fail("Failed on " + sample + " " + field); + } catch (DateTimeException ex) { + // expected + } + } + } + } + + @Test + public void basicTest_range_DateTimeField_null() { + for (TemporalAccessor sample : samples()) { + try { + sample.range(null); + fail("Failed on " + sample); + } catch (NullPointerException ex) { + // expected + } + } + } + + //----------------------------------------------------------------------- + // get(DateTimeField) + //----------------------------------------------------------------------- +// TODO needs implementations of week fields +// @Test +// public void basicTest_get_DateTimeField_supported() { +// for (DateTimeAccessor sample : samples()) { +// for (DateTimeField field : validFields()) { +// if (sample.range(field).isIntValue()) { +// sample.get(field); // no exception +// } else { +// try { +// sample.get(field); +// fail("Failed on " + sample + " " + field); +// } catch (DateTimeException ex) { +// // expected +// } +// } +// } +// } +// } + + @Test + public void basicTest_get_DateTimeField_unsupported() { + for (TemporalAccessor sample : samples()) { + for (TemporalField field : invalidFields()) { + try { + sample.get(field); + fail("Failed on " + sample + " " + field); + } catch (DateTimeException ex) { + // expected + } + } + } + } + + @Test + public void basicTest_get_DateTimeField_null() { + for (TemporalAccessor sample : samples()) { + try { + sample.get(null); + fail("Failed on " + sample); + } catch (NullPointerException ex) { + // expected + } + } + } + + //----------------------------------------------------------------------- + // getLong(DateTimeField) + //----------------------------------------------------------------------- +// TODO needs implementations of week fields +// @Test +// public void basicTest_getLong_DateTimeField_supported() { +// for (DateTimeAccessor sample : samples()) { +// for (DateTimeField field : validFields()) { +// sample.getLong(field); // no exception +// } +// } +// } + + @Test + public void basicTest_getLong_DateTimeField_unsupported() { + for (TemporalAccessor sample : samples()) { + for (TemporalField field : invalidFields()) { + try { + sample.getLong(field); + fail("Failed on " + sample + " " + field); + } catch (DateTimeException ex) { + // expected + } + } + } + } + + @Test + public void basicTest_getLong_DateTimeField_null() { + for (TemporalAccessor sample : samples()) { + try { + sample.getLong(null); + fail("Failed on " + sample); + } catch (NullPointerException ex) { + // expected + } + } + } + + //----------------------------------------------------------------------- + @Test + public void basicTest_query() { + for (TemporalAccessor sample : samples()) { + assertEquals(sample.query(new TemporalQuery() { + @Override + public String queryFrom(TemporalAccessor dateTime) { + return "foo"; + } + }), "foo"); + } + } + +} diff --git a/src/test/java/org/threeten/extra/AbstractTest.java b/src/test/java/org/threeten/extra/AbstractTest.java new file mode 100644 index 00000000..2d11a93b --- /dev/null +++ b/src/test/java/org/threeten/extra/AbstractTest.java @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.bp; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertSame; +import static org.testng.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.ObjectStreamConstants; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; + +/** + * Base test class. + */ +public abstract class AbstractTest { + + private static final String SERIALISATION_DATA_FOLDER = "src/test/resources/"; + + protected static boolean isIsoLeap(long year) { + if (year % 4 != 0) { + return false; + } + if (year % 100 == 0 && year % 400 != 0) { + return false; + } + return true; + } + + protected static void assertSerializable(Object o) throws IOException, ClassNotFoundException { + Object deserialisedObject = writeThenRead(o); + assertEquals(deserialisedObject, o); + } + + protected static void assertSerializableAndSame(Object o) throws IOException, ClassNotFoundException { + Object deserialisedObject = writeThenRead(o); + assertSame(deserialisedObject, o); + } + + protected static Object writeThenRead(Object o) throws IOException, ClassNotFoundException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = null; + try { + oos = new ObjectOutputStream(baos); + oos.writeObject(o); + } finally { + if (oos != null) { + oos.close(); + } + } + + ObjectInputStream ois = null; + try { + ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); + return ois.readObject(); + } finally { + if (ois != null) { + ois.close(); + } + } + } + + protected static void assertEqualsSerialisedForm(Object objectSerialised) throws IOException, ClassNotFoundException { + assertEqualsSerialisedForm(objectSerialised, objectSerialised.getClass()); + } + + protected static void assertEqualsSerialisedForm(Object objectSerialised, Class cls) throws IOException, ClassNotFoundException { + String className = cls.getSimpleName(); +// try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(SERIALISATION_DATA_FOLDER + className + ".bin"))) { +// out.writeObject(objectSerialised); +// } + + ObjectInputStream in = null; + try { + in = new ObjectInputStream(new FileInputStream(SERIALISATION_DATA_FOLDER + className + ".bin")); + Object objectFromFile = in.readObject(); + assertEquals(objectFromFile, objectSerialised); + } finally { + if (in != null) { + in.close(); + } + } + } + + protected static void assertImmutable(Class cls) { + assertTrue(Modifier.isPublic(cls.getModifiers())); + assertTrue(Modifier.isFinal(cls.getModifiers())); + Field[] fields = cls.getDeclaredFields(); + for (Field field : fields) { + if (field.getName().contains("$") == false) { + if (Modifier.isStatic(field.getModifiers())) { + assertTrue(Modifier.isFinal(field.getModifiers()), "Field:" + field.getName()); + } else { + assertTrue(Modifier.isPrivate(field.getModifiers()), "Field:" + field.getName()); + assertTrue(Modifier.isFinal(field.getModifiers()), "Field:" + field.getName()); + } + } + } + Constructor[] cons = cls.getDeclaredConstructors(); + for (Constructor con : cons) { + assertTrue(Modifier.isPrivate(con.getModifiers())); + } + } + + protected static void assertSerializedBySer(Object object, byte[] expectedBytes, byte[]... matches) throws Exception { + String serClass = object.getClass().getPackage().getName() + ".Ser"; + Class serCls = Class.forName(serClass); + Field field = serCls.getDeclaredField("serialVersionUID"); + field.setAccessible(true); + long serVer = (Long) field.get(null); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = null; + try { + oos = new ObjectOutputStream(baos); + oos.writeObject(object); + } finally { + if (oos != null) { + oos.close(); + } + } + byte[] bytes = baos.toByteArray(); + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); + DataInputStream dis = null; + try { + dis = new DataInputStream(bais); + assertEquals(dis.readShort(), ObjectStreamConstants.STREAM_MAGIC); + assertEquals(dis.readShort(), ObjectStreamConstants.STREAM_VERSION); + assertEquals(dis.readByte(), ObjectStreamConstants.TC_OBJECT); + assertEquals(dis.readByte(), ObjectStreamConstants.TC_CLASSDESC); + assertEquals(dis.readUTF(), serClass); + assertEquals(dis.readLong(), serVer); + assertEquals(dis.readByte(), ObjectStreamConstants.SC_EXTERNALIZABLE | ObjectStreamConstants.SC_BLOCK_DATA); + assertEquals(dis.readShort(), 0); // number of fields + assertEquals(dis.readByte(), ObjectStreamConstants.TC_ENDBLOCKDATA); // end of classdesc + assertEquals(dis.readByte(), ObjectStreamConstants.TC_NULL); // no superclasses + if (expectedBytes.length < 256) { + assertEquals(dis.readByte(), ObjectStreamConstants.TC_BLOCKDATA); + assertEquals(dis.readUnsignedByte(), expectedBytes.length); + } else { + assertEquals(dis.readByte(), ObjectStreamConstants.TC_BLOCKDATALONG); + assertEquals(dis.readInt(), expectedBytes.length); + } + byte[] input = new byte[expectedBytes.length]; + dis.readFully(input); + assertEquals(input, expectedBytes); + if (matches.length > 0) { + for (byte[] match : matches) { + boolean matched = false; + while (matched == false) { + try { + dis.mark(1000); + byte[] possible = new byte[match.length]; + dis.readFully(possible); + assertEquals(possible, match); + matched = true; + } catch (AssertionError ex) { + dis.reset(); + dis.readByte(); // ignore + } + } + } + } else { + assertEquals(dis.readByte(), ObjectStreamConstants.TC_ENDBLOCKDATA); // end of blockdata + assertEquals(dis.read(), -1); + } + } finally { + if (dis != null) { + dis.close(); + } + } + } + +} diff --git a/src/test/java/org/threeten/extra/MockSimplePeriod.java b/src/test/java/org/threeten/extra/MockSimplePeriod.java new file mode 100644 index 00000000..6da62ce0 --- /dev/null +++ b/src/test/java/org/threeten/extra/MockSimplePeriod.java @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.bp; + +import static org.threeten.bp.temporal.ChronoUnit.DAYS; +import static org.threeten.bp.temporal.ChronoUnit.FOREVER; +import static org.threeten.bp.temporal.ChronoUnit.SECONDS; + +import java.util.Collections; +import java.util.List; + +import org.threeten.bp.jdk8.Jdk8Methods; +import org.threeten.bp.temporal.Temporal; +import org.threeten.bp.temporal.TemporalAmount; +import org.threeten.bp.temporal.TemporalUnit; + +/** + * Mock period of time measured using a single unit, such as {@code 3 Days}. + */ +public final class MockSimplePeriod + implements TemporalAmount, Comparable { + + /** + * A constant for a period of zero, measured in days. + */ + public static final MockSimplePeriod ZERO_DAYS = new MockSimplePeriod(0, DAYS); + /** + * A constant for a period of zero, measured in seconds. + */ + public static final MockSimplePeriod ZERO_SECONDS = new MockSimplePeriod(0, SECONDS); + + /** + * The amount of the period. + */ + private final long amount; + /** + * The unit the period is measured in. + */ + private final TemporalUnit unit; + + /** + * Obtains a {@code MockSimplePeriod} from an amount and unit. + *

    + * The parameters represent the two parts of a phrase like '6 Days'. + * + * @param amount the amount of the period, measured in terms of the unit, positive or negative + * @param unit the unit that the period is measured in, must not be the 'Forever' unit, not null + * @return the {@code MockSimplePeriod} instance, not null + * @throws DateTimeException if the period unit is {@link org.threeten.bp.temporal.ChronoUnit#FOREVER}. + */ + public static MockSimplePeriod of(long amount, TemporalUnit unit) { + return new MockSimplePeriod(amount, unit); + } + + private MockSimplePeriod(long amount, TemporalUnit unit) { + Jdk8Methods.requireNonNull(unit, "unit"); + if (unit == FOREVER) { + throw new DateTimeException("Cannot create a period of the Forever unit"); + } + this.amount = amount; + this.unit = unit; + } + + //----------------------------------------------------------------------- + @Override + public List getUnits() { + return Collections.singletonList(unit); + } + + @Override + public long get(TemporalUnit unit) { + if (this.unit.equals(unit)) { + return amount; + } + throw new DateTimeException("Unsupported unit: " + unit); + } + + //----------------------------------------------------------------------- + public long getAmount() { + return amount; + } + + public TemporalUnit getUnit() { + return unit; + } + + //------------------------------------------------------------------------- + @Override + public Temporal addTo(Temporal dateTime) { + return dateTime.plus(amount, unit); + } + + @Override + public Temporal subtractFrom(Temporal dateTime) { + return dateTime.minus(amount, unit); + } + + //----------------------------------------------------------------------- + @Override + public int compareTo(MockSimplePeriod otherPeriod) { + if (unit.equals(otherPeriod.getUnit()) == false) { + throw new IllegalArgumentException("Units cannot be compared: " + unit + " and " + otherPeriod.getUnit()); + } + return Jdk8Methods.compareLongs(amount, otherPeriod.amount); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof MockSimplePeriod) { + MockSimplePeriod other = (MockSimplePeriod) obj; + return this.amount == other.amount && + this.unit.equals(other.unit); + } + return false; + } + + @Override + public int hashCode() { + return unit.hashCode() ^ (int) (amount ^ (amount >>> 32)); + } + + @Override + public String toString() { + return amount + " " + unit; + } + +} diff --git a/src/test/java/org/threeten/extra/TestOffsetDate.java b/src/test/java/org/threeten/extra/TestOffsetDate.java new file mode 100644 index 00000000..a6df2a48 --- /dev/null +++ b/src/test/java/org/threeten/extra/TestOffsetDate.java @@ -0,0 +1,1882 @@ +/* +9 * Copyright (c) 2007-2013, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.bp; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.threeten.bp.Month.DECEMBER; +import static org.threeten.bp.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH; +import static org.threeten.bp.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR; +import static org.threeten.bp.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH; +import static org.threeten.bp.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR; +import static org.threeten.bp.temporal.ChronoField.DAY_OF_MONTH; +import static org.threeten.bp.temporal.ChronoField.DAY_OF_WEEK; +import static org.threeten.bp.temporal.ChronoField.DAY_OF_YEAR; +import static org.threeten.bp.temporal.ChronoField.EPOCH_DAY; +import static org.threeten.bp.temporal.ChronoField.EPOCH_MONTH; +import static org.threeten.bp.temporal.ChronoField.ERA; +import static org.threeten.bp.temporal.ChronoField.MONTH_OF_YEAR; +import static org.threeten.bp.temporal.ChronoField.OFFSET_SECONDS; +import static org.threeten.bp.temporal.ChronoField.YEAR; +import static org.threeten.bp.temporal.ChronoField.YEAR_OF_ERA; + +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import org.threeten.bp.format.DateTimeFormatter; +import org.threeten.bp.format.DateTimeFormatters; +import org.threeten.bp.format.DateTimeParseException; +import org.threeten.bp.temporal.ChronoField; +import org.threeten.bp.temporal.ChronoUnit; +import org.threeten.bp.temporal.ISOChrono; +import org.threeten.bp.temporal.JulianFields; +import org.threeten.bp.temporal.Temporal; +import org.threeten.bp.temporal.TemporalAccessor; +import org.threeten.bp.temporal.TemporalAdder; +import org.threeten.bp.temporal.TemporalAdjuster; +import org.threeten.bp.temporal.TemporalField; +import org.threeten.bp.temporal.TemporalQueries; +import org.threeten.bp.temporal.TemporalSubtractor; + +/** + * Test OffsetDate. + */ +@Test +public class TestOffsetDate extends AbstractDateTimeTest { + private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1); + private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2); + + private OffsetDate TEST_2007_07_15_PONE; + + @BeforeMethod + public void setUp() { + TEST_2007_07_15_PONE = OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PONE); + } + + //----------------------------------------------------------------------- + @Override + protected List samples() { + TemporalAccessor[] array = {TEST_2007_07_15_PONE, OffsetDate.MIN, OffsetDate.MAX}; + return Arrays.asList(array); + } + + @Override + protected List validFields() { + TemporalField[] array = { + DAY_OF_WEEK, + ALIGNED_DAY_OF_WEEK_IN_MONTH, + ALIGNED_DAY_OF_WEEK_IN_YEAR, + DAY_OF_MONTH, + DAY_OF_YEAR, + EPOCH_DAY, + ALIGNED_WEEK_OF_MONTH, + ALIGNED_WEEK_OF_YEAR, + MONTH_OF_YEAR, + EPOCH_MONTH, + YEAR_OF_ERA, + YEAR, + ERA, + OFFSET_SECONDS, + JulianFields.JULIAN_DAY, + JulianFields.MODIFIED_JULIAN_DAY, + JulianFields.RATA_DIE, + }; + return Arrays.asList(array); + } + + @Override + protected List invalidFields() { + List list = new ArrayList<>(Arrays.asList(ChronoField.values())); + list.removeAll(validFields()); + return list; + } + + //----------------------------------------------------------------------- + @Test + public void test_serialization() throws ClassNotFoundException, IOException { + assertSerializable(TEST_2007_07_15_PONE); + assertSerializable(OffsetDate.MIN); + assertSerializable(OffsetDate.MAX); + } + + @Test + public void test_serialization_format() throws ClassNotFoundException, IOException { + assertEqualsSerialisedForm(OffsetDate.of(LocalDate.of(2012, 9, 16), ZoneOffset.of("+01:00"))); + } + + //----------------------------------------------------------------------- + // constants + //----------------------------------------------------------------------- + @Test + public void constant_MIN() { + check(OffsetDate.MIN, Year.MIN_VALUE, 1, 1, ZoneOffset.MAX); + } + + @Test + public void constant_MAX() { + check(OffsetDate.MAX, Year.MAX_VALUE, 12, 31, ZoneOffset.MIN); + } + + //----------------------------------------------------------------------- + // now() + //----------------------------------------------------------------------- + @Test + public void now() { + OffsetDate expected = OffsetDate.now(Clock.systemDefaultZone()); + OffsetDate test = OffsetDate.now(); + for (int i = 0; i < 100; i++) { + if (expected.equals(test)) { + return; + } + expected = OffsetDate.now(Clock.systemDefaultZone()); + test = OffsetDate.now(); + } + assertEquals(test, expected); + } + + @Test + public void now_Clock_allSecsInDay_utc() { + for (int i = 0; i < (2 * 24 * 60 * 60); i++) { + Instant instant = Instant.ofEpochSecond(i); + Clock clock = Clock.fixed(instant, ZoneOffset.UTC); + OffsetDate test = OffsetDate.now(clock); + check(test, 1970, 1, (i < 24 * 60 * 60 ? 1 : 2), ZoneOffset.UTC); + } + } + + @Test + public void now_Clock_allSecsInDay_beforeEpoch() { + for (int i =-1; i >= -(2 * 24 * 60 * 60); i--) { + Instant instant = Instant.ofEpochSecond(i); + Clock clock = Clock.fixed(instant, ZoneOffset.UTC); + OffsetDate test = OffsetDate.now(clock); + check(test, 1969, 12, (i >= -24 * 60 * 60 ? 31 : 30), ZoneOffset.UTC); + } + } + + @Test + public void now_Clock_offsets() { + Instant base = LocalDateTime.of(1970, 1, 1, 12, 0).toInstant(ZoneOffset.UTC); + for (int i = -9; i < 15; i++) { + ZoneOffset offset = ZoneOffset.ofHours(i); + Clock clock = Clock.fixed(base, offset); + OffsetDate test = OffsetDate.now(clock); + check(test, 1970, 1, (i >= 12 ? 2 : 1), offset); + } + } + + @Test(expectedExceptions=NullPointerException.class) + public void now_Clock_nullZoneId() { + OffsetDate.now((ZoneId) null); + } + + @Test(expectedExceptions=NullPointerException.class) + public void now_Clock_nullClock() { + OffsetDate.now((Clock) null); + } + + //----------------------------------------------------------------------- + // factories + //----------------------------------------------------------------------- + private void check(OffsetDate test, int y, int mo, int d, ZoneOffset offset) { + assertEquals(test.getDate(), LocalDate.of(y, mo, d)); + assertEquals(test.getOffset(), offset); + + assertEquals(test.getYear(), y); + assertEquals(test.getMonth().getValue(), mo); + assertEquals(test.getDayOfMonth(), d); + + assertEquals(test, test); + assertEquals(test.hashCode(), test.hashCode()); + assertEquals(OffsetDate.of(LocalDate.of(y, mo, d), offset), test); + } + + //----------------------------------------------------------------------- + @Test + public void factory_of_intMonthInt() { + OffsetDate test = OffsetDate.of(LocalDate.of(2007, Month.JULY, 15), OFFSET_PONE); + check(test, 2007, 7, 15, OFFSET_PONE); + } + + //----------------------------------------------------------------------- + @Test + public void factory_of_ints() { + OffsetDate test = OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PONE); + check(test, 2007, 7, 15, OFFSET_PONE); + } + + //----------------------------------------------------------------------- + @Test + public void factory_of_intsMonthOffset() { + assertEquals(TEST_2007_07_15_PONE, OffsetDate.of(LocalDate.of(2007, Month.JULY, 15), OFFSET_PONE)); + } + + @Test(expectedExceptions=DateTimeException.class) + public void factory_of_intsMonthOffset_dayTooLow() { + OffsetDate.of(LocalDate.of(2007, Month.JANUARY, 0), OFFSET_PONE); + } + + @Test(expectedExceptions=DateTimeException.class) + public void factory_of_intsMonthOffset_dayTooHigh() { + OffsetDate.of(LocalDate.of(2007, Month.JANUARY, 32), OFFSET_PONE); + } + + @Test(expectedExceptions=NullPointerException.class) + public void factory_of_intsMonthOffset_nullMonth() { + OffsetDate.of(LocalDate.of(2007, null, 30), OFFSET_PONE); + } + + @Test(expectedExceptions=DateTimeException.class) + public void factory_of_intsMonthOffset_yearTooLow() { + OffsetDate.of(LocalDate.of(Integer.MIN_VALUE, Month.JANUARY, 1), OFFSET_PONE); + } + + @Test(expectedExceptions=NullPointerException.class) + public void factory_of_intsMonthOffset_nullOffset() { + OffsetDate.of(LocalDate.of(2007, Month.JANUARY, 30), null); + } + + //----------------------------------------------------------------------- + @Test + public void factory_of_intsOffset() { + OffsetDate test = OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PONE); + check(test, 2007, 7, 15, OFFSET_PONE); + } + + @Test(expectedExceptions=DateTimeException.class) + public void factory_of_ints_dayTooLow() { + OffsetDate.of(LocalDate.of(2007, 1, 0), OFFSET_PONE); + } + + @Test(expectedExceptions=DateTimeException.class) + public void factory_of_ints_dayTooHigh() { + OffsetDate.of(LocalDate.of(2007, 1, 32), OFFSET_PONE); + } + + @Test(expectedExceptions=DateTimeException.class) + public void factory_of_ints_monthTooLow() { + OffsetDate.of(LocalDate.of(2007, 0, 1), OFFSET_PONE); + } + + @Test(expectedExceptions=DateTimeException.class) + public void factory_of_ints_monthTooHigh() { + OffsetDate.of(LocalDate.of(2007, 13, 1), OFFSET_PONE); + } + + @Test(expectedExceptions=DateTimeException.class) + public void factory_of_ints_yearTooLow() { + OffsetDate.of(LocalDate.of(Integer.MIN_VALUE, 1, 1), OFFSET_PONE); + } + + @Test(expectedExceptions=NullPointerException.class) + public void factory_of_ints_nullOffset() { + OffsetDate.of(LocalDate.of(2007, 1, 1), (ZoneOffset) null); + } + + //----------------------------------------------------------------------- + @Test + public void factory_of_LocalDateZoneOffset() { + LocalDate localDate = LocalDate.of(2008, 6, 30); + OffsetDate test = OffsetDate.of(localDate, OFFSET_PONE); + check(test, 2008, 6, 30, OFFSET_PONE); + } + + @Test(expectedExceptions=NullPointerException.class) + public void factory_of_LocalDateZoneOffset_nullDate() { + OffsetDate.of((LocalDate) null, OFFSET_PONE); + } + + @Test(expectedExceptions=NullPointerException.class) + public void factory_of_LocalDateZoneOffset_nullOffset() { + LocalDate localDate = LocalDate.of(2008, 6, 30); + OffsetDate.of(localDate, (ZoneOffset) null); + } + + //----------------------------------------------------------------------- + // from(TemporalAccessor) + //----------------------------------------------------------------------- + @Test + public void test_from_TemporalAccessor_OD() { + assertEquals(OffsetDate.from(TEST_2007_07_15_PONE), TEST_2007_07_15_PONE); + } + + @Test + public void test_from_TemporalAccessor_ZDT() { + ZonedDateTime base = LocalDateTime.of(2007, 7, 15, 17, 30).atZone(OFFSET_PONE); + assertEquals(OffsetDate.from(base), TEST_2007_07_15_PONE); + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_from_TemporalAccessor_invalid_noDerive() { + OffsetDate.from(LocalTime.of(12, 30)); + } + + @Test(expectedExceptions=NullPointerException.class) + public void test_from_TemporalAccessor_null() { + OffsetDate.from((TemporalAccessor) null); + } + + //----------------------------------------------------------------------- + // parse() + //----------------------------------------------------------------------- + @Test(dataProvider="sampleToString") + public void factory_parse_validText(int y, int m, int d, String offsetId, String parsable) { + OffsetDate t = OffsetDate.parse(parsable); + assertNotNull(t, parsable); + assertEquals(t.getYear(), y, parsable); + assertEquals(t.getMonth().getValue(), m, parsable); + assertEquals(t.getDayOfMonth(), d, parsable); + assertEquals(t.getOffset(), ZoneOffset.of(offsetId)); + } + + @DataProvider(name="sampleBadParse") + Object[][] provider_sampleBadParse() { + return new Object[][]{ + {"2008/07/05"}, + {"10000-01-01"}, + {"2008-1-1"}, + {"2008--01"}, + {"ABCD-02-01"}, + {"2008-AB-01"}, + {"2008-02-AB"}, + {"-0000-02-01"}, + {"2008-02-01Y"}, + {"2008-02-01+19:00"}, + {"2008-02-01+01/00"}, + {"2008-02-01+1900"}, + {"2008-02-01+01:60"}, + {"2008-02-01+01:30:123"}, + {"2008-02-01"}, + {"2008-02-01+01:00[Europe/Paris]"}, + }; + } + + @Test(dataProvider="sampleBadParse", expectedExceptions=DateTimeParseException.class) + public void factory_parse_invalidText(String unparsable) { + OffsetDate.parse(unparsable); + } + + @Test(expectedExceptions=DateTimeParseException.class) + public void factory_parse_illegalValue() { + OffsetDate.parse("2008-06-32+01:00"); + } + + @Test(expectedExceptions=DateTimeParseException.class) + public void factory_parse_invalidValue() { + OffsetDate.parse("2008-06-31+01:00"); + } + + @Test(expectedExceptions=NullPointerException.class) + public void factory_parse_nullText() { + OffsetDate.parse((String) null); + } + + //----------------------------------------------------------------------- + // parse(DateTimeFormatter) + //----------------------------------------------------------------------- + @Test + public void factory_parse_formatter() { + DateTimeFormatter f = DateTimeFormatters.pattern("y M d XXX"); + OffsetDate test = OffsetDate.parse("2010 12 3 +01:00", f); + assertEquals(test, OffsetDate.of(LocalDate.of(2010, 12, 3), ZoneOffset.ofHours(1))); + } + + @Test(expectedExceptions=NullPointerException.class) + public void factory_parse_formatter_nullText() { + DateTimeFormatter f = DateTimeFormatters.pattern("y M d"); + OffsetDate.parse((String) null, f); + } + + @Test(expectedExceptions=NullPointerException.class) + public void factory_parse_formatter_nullFormatter() { + OffsetDate.parse("ANY", null); + } + + //----------------------------------------------------------------------- + // constructor + //----------------------------------------------------------------------- + @Test(expectedExceptions=NullPointerException.class) + public void constructor_nullDate() throws Throwable { + Constructor con = OffsetDate.class.getDeclaredConstructor(LocalDate.class, ZoneOffset.class); + con.setAccessible(true); + try { + con.newInstance(null, OFFSET_PONE); + } catch (InvocationTargetException ex) { + throw ex.getCause(); + } + } + + @Test(expectedExceptions=NullPointerException.class) + public void constructor_nullOffset() throws Throwable { + Constructor con = OffsetDate.class.getDeclaredConstructor(LocalDate.class, ZoneOffset.class); + con.setAccessible(true); + try { + con.newInstance(LocalDate.of(2008, 6, 30), null); + } catch (InvocationTargetException ex) { + throw ex.getCause(); + } + } + + //----------------------------------------------------------------------- + // basics + //----------------------------------------------------------------------- + @DataProvider(name="sampleDates") + Object[][] provider_sampleDates() { + return new Object[][] { + {2008, 7, 5, OFFSET_PTWO}, + {2007, 7, 5, OFFSET_PONE}, + {2006, 7, 5, OFFSET_PTWO}, + {2005, 7, 5, OFFSET_PONE}, + {2004, 1, 1, OFFSET_PTWO}, + {-1, 1, 2, OFFSET_PONE}, + {999999, 11, 20, ZoneOffset.ofHoursMinutesSeconds(6, 9, 12)}, + }; + } + + @Test(dataProvider="sampleDates") + public void test_get_OffsetDate(int y, int m, int d, ZoneOffset offset) { + LocalDate localDate = LocalDate.of(y, m, d); + OffsetDate a = OffsetDate.of(localDate, offset); + + assertEquals(a.getDate(), localDate); + assertEquals(a.getOffset(), offset); + assertEquals(a.toString(), localDate.toString() + offset.toString()); + assertEquals(a.getYear(), localDate.getYear()); + assertEquals(a.getMonth(), localDate.getMonth()); + assertEquals(a.getDayOfMonth(), localDate.getDayOfMonth()); + assertEquals(a.getDayOfYear(), localDate.getDayOfYear()); + assertEquals(a.getDayOfWeek(), localDate.getDayOfWeek()); + } + + //----------------------------------------------------------------------- + // get(TemporalField) + //----------------------------------------------------------------------- + @Test + public void test_get_TemporalField() { + OffsetDate test = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); + assertEquals(test.get(ChronoField.YEAR), 2008); + assertEquals(test.get(ChronoField.MONTH_OF_YEAR), 6); + assertEquals(test.get(ChronoField.DAY_OF_MONTH), 30); + assertEquals(test.get(ChronoField.DAY_OF_WEEK), 1); + assertEquals(test.get(ChronoField.DAY_OF_YEAR), 182); + + assertEquals(test.get(ChronoField.OFFSET_SECONDS), 3600); + } + + @Test + public void test_getLong_TemporalField() { + OffsetDate test = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); + assertEquals(test.getLong(ChronoField.YEAR), 2008); + assertEquals(test.getLong(ChronoField.MONTH_OF_YEAR), 6); + assertEquals(test.getLong(ChronoField.DAY_OF_MONTH), 30); + assertEquals(test.getLong(ChronoField.DAY_OF_WEEK), 1); + assertEquals(test.getLong(ChronoField.DAY_OF_YEAR), 182); + + assertEquals(test.getLong(ChronoField.OFFSET_SECONDS), 3600); + } + + //----------------------------------------------------------------------- + // query(TemporalQuery) + //----------------------------------------------------------------------- + @Test + public void test_query_chrono() { + assertEquals(TEST_2007_07_15_PONE.query(TemporalQueries.chrono()), ISOChrono.INSTANCE); + assertEquals(TemporalQueries.chrono().queryFrom(TEST_2007_07_15_PONE), ISOChrono.INSTANCE); + } + + @Test + public void test_query_zoneId() { + assertEquals(TEST_2007_07_15_PONE.query(TemporalQueries.zoneId()), null); + assertEquals(TemporalQueries.zoneId().queryFrom(TEST_2007_07_15_PONE), null); + } + + @Test + public void test_query_precision() { + assertEquals(TEST_2007_07_15_PONE.query(TemporalQueries.precision()), ChronoUnit.DAYS); + assertEquals(TemporalQueries.precision().queryFrom(TEST_2007_07_15_PONE), ChronoUnit.DAYS); + } + + @Test + public void test_query_offset() { + assertEquals(TEST_2007_07_15_PONE.query(TemporalQueries.offset()), OFFSET_PONE); + assertEquals(TemporalQueries.offset().queryFrom(TEST_2007_07_15_PONE), OFFSET_PONE); + } + + @Test + public void test_query_zone() { + assertEquals(TEST_2007_07_15_PONE.query(TemporalQueries.zone()), OFFSET_PONE); + assertEquals(TemporalQueries.zone().queryFrom(TEST_2007_07_15_PONE), OFFSET_PONE); + } + + @Test(expectedExceptions=NullPointerException.class) + public void test_query_null() { + TEST_2007_07_15_PONE.query(null); + } + + //----------------------------------------------------------------------- + // withOffset() + //----------------------------------------------------------------------- + @Test + public void test_withOffset() { + OffsetDate base = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); + OffsetDate test = base.withOffset(OFFSET_PTWO); + assertEquals(test.getDate(), base.getDate()); + assertEquals(test.getOffset(), OFFSET_PTWO); + } + + @Test + public void test_withOffset_noChange() { + OffsetDate base = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); + OffsetDate test = base.withOffset(OFFSET_PONE); + assertEquals(test, base); + } + + @Test(expectedExceptions=NullPointerException.class) + public void test_withOffset_null() { + TEST_2007_07_15_PONE.withOffset(null); + } + + //----------------------------------------------------------------------- + // with(WithAdjuster) + //----------------------------------------------------------------------- + @Test + public void test_with_adjustment() { + final OffsetDate sample = OffsetDate.of(LocalDate.of(2012, 3, 4), OFFSET_PONE); + TemporalAdjuster adjuster = new TemporalAdjuster() { + @Override + public Temporal adjustInto(Temporal dateTime) { + return sample; + } + }; + assertEquals(TEST_2007_07_15_PONE.with(adjuster), sample); + } + + @Test + public void test_with_adjustment_LocalDate() { + OffsetDate test = TEST_2007_07_15_PONE.with(LocalDate.of(2008, 6, 30)); + assertEquals(test, OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE)); + } + + @Test + public void test_with_adjustment_OffsetDate() { + OffsetDate test = TEST_2007_07_15_PONE.with(OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO)); + assertEquals(test, OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO)); + } + + @Test + public void test_with_adjustment_ZoneOffset() { + OffsetDate test = TEST_2007_07_15_PONE.with(OFFSET_PTWO); + assertEquals(test, OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PTWO)); + } + + @Test + public void test_with_adjustment_Month() { + OffsetDate test = TEST_2007_07_15_PONE.with(DECEMBER); + assertEquals(test, OffsetDate.of(LocalDate.of(2007, 12, 15), OFFSET_PONE)); + } + + @Test + public void test_with_adjustment_offsetUnchanged() { + OffsetDate base = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); + OffsetDate test = base.with(Year.of(2008)); + assertEquals(test, base); + } + + @Test + public void test_with_adjustment_noChange() { + LocalDate date = LocalDate.of(2008, 6, 30); + OffsetDate base = OffsetDate.of(date, OFFSET_PONE); + OffsetDate test = base.with(date); + assertEquals(test, base); + } + + @Test(expectedExceptions=NullPointerException.class) + public void test_with_adjustment_null() { + TEST_2007_07_15_PONE.with((TemporalAdjuster) null); + } + + //----------------------------------------------------------------------- + // with(TemporalField, long) + //----------------------------------------------------------------------- + @Test + public void test_with_TemporalField() { + OffsetDate test = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); + assertEquals(test.with(ChronoField.YEAR, 2009), OffsetDate.of(LocalDate.of(2009, 6, 30), OFFSET_PONE)); + assertEquals(test.with(ChronoField.MONTH_OF_YEAR, 7), OffsetDate.of(LocalDate.of(2008, 7, 30), OFFSET_PONE)); + assertEquals(test.with(ChronoField.DAY_OF_MONTH, 1), OffsetDate.of(LocalDate.of(2008, 6, 1), OFFSET_PONE)); + assertEquals(test.with(ChronoField.DAY_OF_WEEK, 2), OffsetDate.of(LocalDate.of(2008, 7, 1), OFFSET_PONE)); + assertEquals(test.with(ChronoField.DAY_OF_YEAR, 183), OffsetDate.of(LocalDate.of(2008, 7, 1), OFFSET_PONE)); + + assertEquals(test.with(ChronoField.OFFSET_SECONDS, 7205), OffsetDate.of(LocalDate.of(2008, 6, 30), ZoneOffset.ofHoursMinutesSeconds(2, 0, 5))); + } + + @Test(expectedExceptions=NullPointerException.class) + public void test_with_TemporalField_null() { + TEST_2007_07_15_PONE.with((TemporalField) null, 0); + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_with_TemporalField_invalidField() { + TEST_2007_07_15_PONE.with(ChronoField.AMPM_OF_DAY, 0); + } + + //----------------------------------------------------------------------- + // withYear() + //----------------------------------------------------------------------- + @Test + public void test_withYear_int_normal() { + OffsetDate t = TEST_2007_07_15_PONE.withYear(2008); + assertEquals(t, OffsetDate.of(LocalDate.of(2008, 7, 15), OFFSET_PONE)); + } + + @Test + public void test_withYear_int_noChange() { + OffsetDate t = TEST_2007_07_15_PONE.withYear(2007); + assertEquals(t, TEST_2007_07_15_PONE); + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_withYear_int_invalid() { + TEST_2007_07_15_PONE.withYear(Year.MIN_VALUE - 1); + } + + @Test + public void test_withYear_int_adjustDay() { + OffsetDate t = OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PONE).withYear(2007); + OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PONE); + assertEquals(t, expected); + } + + //----------------------------------------------------------------------- + // withMonth() + //----------------------------------------------------------------------- + @Test + public void test_withMonth_int_normal() { + OffsetDate t = TEST_2007_07_15_PONE.withMonth(1); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 1, 15), OFFSET_PONE)); + } + + @Test + public void test_withMonth_int_noChange() { + OffsetDate t = TEST_2007_07_15_PONE.withMonth(7); + assertEquals(t, TEST_2007_07_15_PONE); + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_withMonth_int_invalid() { + TEST_2007_07_15_PONE.withMonth(13); + } + + @Test + public void test_withMonth_int_adjustDay() { + OffsetDate t = OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PONE).withMonth(11); + OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 11, 30), OFFSET_PONE); + assertEquals(t, expected); + } + + //----------------------------------------------------------------------- + // withDayOfMonth() + //----------------------------------------------------------------------- + @Test + public void test_withDayOfMonth_normal() { + OffsetDate t = TEST_2007_07_15_PONE.withDayOfMonth(1); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 1), OFFSET_PONE)); + } + + @Test + public void test_withDayOfMonth_noChange() { + OffsetDate t = TEST_2007_07_15_PONE.withDayOfMonth(15); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PONE)); + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_withDayOfMonth_invalidForMonth() { + OffsetDate.of(LocalDate.of(2007, 11, 30), OFFSET_PONE).withDayOfMonth(31); + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_withDayOfMonth_invalidAlways() { + OffsetDate.of(LocalDate.of(2007, 11, 30), OFFSET_PONE).withDayOfMonth(32); + } + + //----------------------------------------------------------------------- + // withDayOfYear(int) + //----------------------------------------------------------------------- + @Test + public void test_withDayOfYear_normal() { + OffsetDate t = TEST_2007_07_15_PONE.withDayOfYear(33); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 2, 2), OFFSET_PONE)); + } + + @Test + public void test_withDayOfYear_noChange() { + OffsetDate t = TEST_2007_07_15_PONE.withDayOfYear(31 + 28 + 31 + 30 + 31 + 30 + 15); + assertEquals(t, TEST_2007_07_15_PONE); + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_withDayOfYear_illegal() { + TEST_2007_07_15_PONE.withDayOfYear(367); + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_withDayOfYear_invalid() { + TEST_2007_07_15_PONE.withDayOfYear(366); + } + + //----------------------------------------------------------------------- + // plus(PlusAdjuster) + //----------------------------------------------------------------------- + @Test + public void test_plus_PlusAdjuster() { + MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS); + OffsetDate t = TEST_2007_07_15_PONE.plus(period); + assertEquals(t, OffsetDate.of(LocalDate.of(2008, 2, 15), OFFSET_PONE)); + } + + @Test + public void test_plus_PlusAdjuster_noChange() { + MockSimplePeriod period = MockSimplePeriod.of(0, ChronoUnit.MONTHS); + OffsetDate t = TEST_2007_07_15_PONE.plus(period); + assertEquals(t, TEST_2007_07_15_PONE); + } + + @Test + public void test_plus_PlusAdjuster_zero() { + OffsetDate t = TEST_2007_07_15_PONE.plus(Period.ZERO); + assertEquals(t, TEST_2007_07_15_PONE); + } + + @Test(expectedExceptions=NullPointerException.class) + public void test_plus_PlusAdjuster_null() { + TEST_2007_07_15_PONE.plus((TemporalAdder) null); + } + + //----------------------------------------------------------------------- + // plusYears() + //----------------------------------------------------------------------- + @Test + public void test_plusYears_long_normal() { + OffsetDate t = TEST_2007_07_15_PONE.plusYears(1); + assertEquals(t, OffsetDate.of(LocalDate.of(2008, 7, 15), OFFSET_PONE)); + } + + @Test + public void test_plusYears_long_negative() { + OffsetDate t = TEST_2007_07_15_PONE.plusYears(-1); + assertEquals(t, OffsetDate.of(LocalDate.of(2006, 7, 15), OFFSET_PONE)); + } + + @Test + public void test_plusYears_long_noChange() { + OffsetDate t = TEST_2007_07_15_PONE.plusYears(0); + assertEquals(t, TEST_2007_07_15_PONE); + } + + @Test + public void test_plusYears_long_adjustDay() { + OffsetDate t = OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PONE).plusYears(1); + OffsetDate expected = OffsetDate.of(LocalDate.of(2009, 2, 28), OFFSET_PONE); + assertEquals(t, expected); + } + + @Test + public void test_plusYears_long_big() { + long years = 20L + Year.MAX_VALUE; + OffsetDate test = OffsetDate.of(LocalDate.of(-40, 6, 1), OFFSET_PONE).plusYears(years); + assertEquals(test, OffsetDate.of(LocalDate.of((int) (-40L + years), 6, 1), OFFSET_PONE)); + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_plusYears_long_invalidTooLarge() { + OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 1, 1), OFFSET_PONE).plusYears(1); + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_plusYears_long_invalidTooLargeMaxAddMax() { + OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); + test.plusYears(Long.MAX_VALUE); + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_plusYears_long_invalidTooLargeMaxAddMin() { + OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); + test.plusYears(Long.MIN_VALUE); + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_plusYears_long_invalidTooSmall() { + OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusYears(-1); + } + + //----------------------------------------------------------------------- + // plusMonths() + //----------------------------------------------------------------------- + @Test + public void test_plusMonths_long_normal() { + OffsetDate t = TEST_2007_07_15_PONE.plusMonths(1); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 8, 15), OFFSET_PONE)); + } + + @Test + public void test_plusMonths_long_overYears() { + OffsetDate t = TEST_2007_07_15_PONE.plusMonths(25); + assertEquals(t, OffsetDate.of(LocalDate.of(2009, 8, 15), OFFSET_PONE)); + } + + @Test + public void test_plusMonths_long_negative() { + OffsetDate t = TEST_2007_07_15_PONE.plusMonths(-1); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 6, 15), OFFSET_PONE)); + } + + @Test + public void test_plusMonths_long_negativeAcrossYear() { + OffsetDate t = TEST_2007_07_15_PONE.plusMonths(-7); + assertEquals(t, OffsetDate.of(LocalDate.of(2006, 12, 15), OFFSET_PONE)); + } + + @Test + public void test_plusMonths_long_negativeOverYears() { + OffsetDate t = TEST_2007_07_15_PONE.plusMonths(-31); + assertEquals(t, OffsetDate.of(LocalDate.of(2004, 12, 15), OFFSET_PONE)); + } + + @Test + public void test_plusMonths_long_noChange() { + OffsetDate t = TEST_2007_07_15_PONE.plusMonths(0); + assertEquals(t, TEST_2007_07_15_PONE); + } + + @Test + public void test_plusMonths_long_adjustDayFromLeapYear() { + OffsetDate t = OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PONE).plusMonths(12); + OffsetDate expected = OffsetDate.of(LocalDate.of(2009, 2, 28), OFFSET_PONE); + assertEquals(t, expected); + } + + @Test + public void test_plusMonths_long_adjustDayFromMonthLength() { + OffsetDate t = OffsetDate.of(LocalDate.of(2007, 3, 31), OFFSET_PONE).plusMonths(1); + OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 4, 30), OFFSET_PONE); + assertEquals(t, expected); + } + + @Test + public void test_plusMonths_long_big() { + long months = 20L + Integer.MAX_VALUE; + OffsetDate test = OffsetDate.of(LocalDate.of(-40, 6, 1), OFFSET_PONE).plusMonths(months); + assertEquals(test, OffsetDate.of(LocalDate.of((int) (-40L + months / 12), 6 + (int) (months % 12), 1), OFFSET_PONE)); + } + + @Test(expectedExceptions={DateTimeException.class}) + public void test_plusMonths_long_invalidTooLarge() { + OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE).plusMonths(1); + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_plusMonths_long_invalidTooLargeMaxAddMax() { + OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); + test.plusMonths(Long.MAX_VALUE); + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_plusMonths_long_invalidTooLargeMaxAddMin() { + OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); + test.plusMonths(Long.MIN_VALUE); + } + + @Test(expectedExceptions={DateTimeException.class}) + public void test_plusMonths_long_invalidTooSmall() { + OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusMonths(-1); + } + + //----------------------------------------------------------------------- + // plusWeeks() + //----------------------------------------------------------------------- + @DataProvider(name="samplePlusWeeksSymmetry") + Object[][] provider_samplePlusWeeksSymmetry() { + return new Object[][] { + {OffsetDate.of(LocalDate.of(-1, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(-1, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(-1, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(-1, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(0, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(0, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(0, 2, 29), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(0, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(0, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2007, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2007, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2008, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2008, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2008, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2008, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2099, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2099, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2099, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2099, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2100, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2100, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2100, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2100, 12, 31), OFFSET_PTWO)}, + }; + } + + @Test(dataProvider="samplePlusWeeksSymmetry") + public void test_plusWeeks_symmetry(OffsetDate reference) { + for (int weeks = 0; weeks < 365 * 8; weeks++) { + OffsetDate t = reference.plusWeeks(weeks).plusWeeks(-weeks); + assertEquals(t, reference); + + t = reference.plusWeeks(-weeks).plusWeeks(weeks); + assertEquals(t, reference); + } + } + + @Test + public void test_plusWeeks_normal() { + OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(1); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 22), OFFSET_PONE)); + } + + @Test + public void test_plusWeeks_overMonths() { + OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(9); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 9, 16), OFFSET_PONE)); + } + + @Test + public void test_plusWeeks_overYears() { + OffsetDate t = OffsetDate.of(LocalDate.of(2006, 7, 16), OFFSET_PONE).plusWeeks(52); + assertEquals(t, TEST_2007_07_15_PONE); + } + + @Test + public void test_plusWeeks_overLeapYears() { + OffsetDate t = TEST_2007_07_15_PONE.plusYears(-1).plusWeeks(104); + assertEquals(t, OffsetDate.of(LocalDate.of(2008, 7, 12), OFFSET_PONE)); + } + + @Test + public void test_plusWeeks_negative() { + OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(-1); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 8), OFFSET_PONE)); + } + + @Test + public void test_plusWeeks_negativeAcrossYear() { + OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(-28); + assertEquals(t, OffsetDate.of(LocalDate.of(2006, 12, 31), OFFSET_PONE)); + } + + @Test + public void test_plusWeeks_negativeOverYears() { + OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(-104); + assertEquals(t, OffsetDate.of(LocalDate.of(2005, 7, 17), OFFSET_PONE)); + } + + @Test + public void test_plusWeeks_noChange() { + OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(0); + assertEquals(t, TEST_2007_07_15_PONE); + } + + @Test + public void test_plusWeeks_maximum() { + OffsetDate t = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 24), OFFSET_PONE).plusWeeks(1); + OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE); + assertEquals(t, expected); + } + + @Test + public void test_plusWeeks_minimum() { + OffsetDate t = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 8), OFFSET_PONE).plusWeeks(-1); + OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE); + assertEquals(t, expected); + } + + @Test(expectedExceptions={DateTimeException.class}) + public void test_plusWeeks_invalidTooLarge() { + OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).plusWeeks(1); + } + + @Test(expectedExceptions={DateTimeException.class}) + public void test_plusWeeks_invalidTooSmall() { + OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 7), OFFSET_PONE).plusWeeks(-1); + } + + @Test(expectedExceptions={ArithmeticException.class}) + public void test_plusWeeks_invalidMaxMinusMax() { + OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).plusWeeks(Long.MAX_VALUE); + } + + @Test(expectedExceptions={ArithmeticException.class}) + public void test_plusWeeks_invalidMaxMinusMin() { + OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).plusWeeks(Long.MIN_VALUE); + } + + //----------------------------------------------------------------------- + // plusDays() + //----------------------------------------------------------------------- + @DataProvider(name="samplePlusDaysSymmetry") + Object[][] provider_samplePlusDaysSymmetry() { + return new Object[][] { + {OffsetDate.of(LocalDate.of(-1, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(-1, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(-1, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(-1, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(0, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(0, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(0, 2, 29), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(0, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(0, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2007, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2007, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2008, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2008, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2008, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2008, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2099, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2099, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2099, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2099, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2100, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2100, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2100, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2100, 12, 31), OFFSET_PTWO)}, + }; + } + + @Test(dataProvider="samplePlusDaysSymmetry") + public void test_plusDays_symmetry(OffsetDate reference) { + for (int days = 0; days < 365 * 8; days++) { + OffsetDate t = reference.plusDays(days).plusDays(-days); + assertEquals(t, reference); + + t = reference.plusDays(-days).plusDays(days); + assertEquals(t, reference); + } + } + + @Test + public void test_plusDays_normal() { + OffsetDate t = TEST_2007_07_15_PONE.plusDays(1); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 16), OFFSET_PONE)); + } + + @Test + public void test_plusDays_overMonths() { + OffsetDate t = TEST_2007_07_15_PONE.plusDays(62); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 9, 15), OFFSET_PONE)); + } + + @Test + public void test_plusDays_overYears() { + OffsetDate t = OffsetDate.of(LocalDate.of(2006, 7, 14), OFFSET_PONE).plusDays(366); + assertEquals(t, TEST_2007_07_15_PONE); + } + + @Test + public void test_plusDays_overLeapYears() { + OffsetDate t = TEST_2007_07_15_PONE.plusYears(-1).plusDays(365 + 366); + assertEquals(t, OffsetDate.of(LocalDate.of(2008, 7, 15), OFFSET_PONE)); + } + + @Test + public void test_plusDays_negative() { + OffsetDate t = TEST_2007_07_15_PONE.plusDays(-1); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 14), OFFSET_PONE)); + } + + @Test + public void test_plusDays_negativeAcrossYear() { + OffsetDate t = TEST_2007_07_15_PONE.plusDays(-196); + assertEquals(t, OffsetDate.of(LocalDate.of(2006, 12, 31), OFFSET_PONE)); + } + + @Test + public void test_plusDays_negativeOverYears() { + OffsetDate t = TEST_2007_07_15_PONE.plusDays(-730); + assertEquals(t, OffsetDate.of(LocalDate.of(2005, 7, 15), OFFSET_PONE)); + } + + @Test + public void test_plusDays_noChange() { + OffsetDate t = TEST_2007_07_15_PONE.plusDays(0); + assertEquals(t, TEST_2007_07_15_PONE); + } + + @Test + public void test_plusDays_maximum() { + OffsetDate t = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 30), OFFSET_PONE).plusDays(1); + OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE); + assertEquals(t, expected); + } + + @Test + public void test_plusDays_minimum() { + OffsetDate t = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 2), OFFSET_PONE).plusDays(-1); + OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE); + assertEquals(t, expected); + } + + @Test(expectedExceptions={DateTimeException.class}) + public void test_plusDays_invalidTooLarge() { + OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).plusDays(1); + } + + @Test(expectedExceptions={DateTimeException.class}) + public void test_plusDays_invalidTooSmall() { + OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusDays(-1); + } + + @Test(expectedExceptions=ArithmeticException.class) + public void test_plusDays_overflowTooLarge() { + OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).plusDays(Long.MAX_VALUE); + } + + @Test(expectedExceptions=ArithmeticException.class) + public void test_plusDays_overflowTooSmall() { + OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusDays(Long.MIN_VALUE); + } + + //----------------------------------------------------------------------- + // minus(MinusAdjuster) + //----------------------------------------------------------------------- + @Test + public void test_minus_MinusAdjuster() { + MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS); + OffsetDate t = TEST_2007_07_15_PONE.minus(period); + assertEquals(t, OffsetDate.of(LocalDate.of(2006, 12, 15), OFFSET_PONE)); + } + + @Test + public void test_minus_MinusAdjuster_noChange() { + MockSimplePeriod period = MockSimplePeriod.of(0, ChronoUnit.MONTHS); + OffsetDate t = TEST_2007_07_15_PONE.minus(period); + assertEquals(t, TEST_2007_07_15_PONE); + } + + @Test + public void test_minus_MinusAdjuster_zero() { + OffsetDate t = TEST_2007_07_15_PONE.minus(Period.ZERO); + assertEquals(t, TEST_2007_07_15_PONE); + } + + @Test(expectedExceptions=NullPointerException.class) + public void test_plus_MinusAdjuster_null() { + TEST_2007_07_15_PONE.minus((TemporalSubtractor) null); + } + + //----------------------------------------------------------------------- + // minusYears() + //----------------------------------------------------------------------- + @Test + public void test_minusYears_long_normal() { + OffsetDate t = TEST_2007_07_15_PONE.minusYears(1); + assertEquals(t, OffsetDate.of(LocalDate.of(2006, 7, 15), OFFSET_PONE)); + } + + @Test + public void test_minusYears_long_negative() { + OffsetDate t = TEST_2007_07_15_PONE.minusYears(-1); + assertEquals(t, OffsetDate.of(LocalDate.of(2008, 7, 15), OFFSET_PONE)); + } + + @Test + public void test_minusYears_long_noChange() { + OffsetDate t = TEST_2007_07_15_PONE.minusYears(0); + assertEquals(t, TEST_2007_07_15_PONE); + } + + @Test + public void test_minusYears_long_adjustDay() { + OffsetDate t = OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PONE).minusYears(1); + OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PONE); + assertEquals(t, expected); + } + + @Test + public void test_minusYears_long_big() { + long years = 20L + Year.MAX_VALUE; + OffsetDate test = OffsetDate.of(LocalDate.of(40, 6, 1), OFFSET_PONE).minusYears(years); + assertEquals(test, OffsetDate.of(LocalDate.of((int) (40L - years), 6, 1), OFFSET_PONE)); + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_minusYears_long_invalidTooLarge() { + OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 1, 1), OFFSET_PONE).minusYears(-1); + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_minusYears_long_invalidTooLargeMaxAddMax() { + OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); + test.minusYears(Long.MAX_VALUE); + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_minusYears_long_invalidTooLargeMaxAddMin() { + OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); + test.minusYears(Long.MIN_VALUE); + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_minusYears_long_invalidTooSmall() { + OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusYears(1); + } + + //----------------------------------------------------------------------- + // minusMonths() + //----------------------------------------------------------------------- + @Test + public void test_minusMonths_long_normal() { + OffsetDate t = TEST_2007_07_15_PONE.minusMonths(1); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 6, 15), OFFSET_PONE)); + } + + @Test + public void test_minusMonths_long_overYears() { + OffsetDate t = TEST_2007_07_15_PONE.minusMonths(25); + assertEquals(t, OffsetDate.of(LocalDate.of(2005, 6, 15), OFFSET_PONE)); + } + + @Test + public void test_minusMonths_long_negative() { + OffsetDate t = TEST_2007_07_15_PONE.minusMonths(-1); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 8, 15), OFFSET_PONE)); + } + + @Test + public void test_minusMonths_long_negativeAcrossYear() { + OffsetDate t = TEST_2007_07_15_PONE.minusMonths(-7); + assertEquals(t, OffsetDate.of(LocalDate.of(2008, 2, 15), OFFSET_PONE)); + } + + @Test + public void test_minusMonths_long_negativeOverYears() { + OffsetDate t = TEST_2007_07_15_PONE.minusMonths(-31); + assertEquals(t, OffsetDate.of(LocalDate.of(2010, 2, 15), OFFSET_PONE)); + } + + @Test + public void test_minusMonths_long_noChange() { + OffsetDate t = TEST_2007_07_15_PONE.minusMonths(0); + assertEquals(t, TEST_2007_07_15_PONE); + } + + @Test + public void test_minusMonths_long_adjustDayFromLeapYear() { + OffsetDate t = OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PONE).minusMonths(12); + OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PONE); + assertEquals(t, expected); + } + + @Test + public void test_minusMonths_long_adjustDayFromMonthLength() { + OffsetDate t = OffsetDate.of(LocalDate.of(2007, 3, 31), OFFSET_PONE).minusMonths(1); + OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PONE); + assertEquals(t, expected); + } + + @Test + public void test_minusMonths_long_big() { + long months = 20L + Integer.MAX_VALUE; + OffsetDate test = OffsetDate.of(LocalDate.of(40, 6, 1), OFFSET_PONE).minusMonths(months); + assertEquals(test, OffsetDate.of(LocalDate.of((int) (40L - months / 12), 6 - (int) (months % 12), 1), OFFSET_PONE)); + } + + @Test(expectedExceptions={DateTimeException.class}) + public void test_minusMonths_long_invalidTooLarge() { + OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE).minusMonths(-1); + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_minusMonths_long_invalidTooLargeMaxAddMax() { + OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); + test.minusMonths(Long.MAX_VALUE); + } + + @Test(expectedExceptions=DateTimeException.class) + public void test_minusMonths_long_invalidTooLargeMaxAddMin() { + OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); + test.minusMonths(Long.MIN_VALUE); + } + + @Test(expectedExceptions={DateTimeException.class}) + public void test_minusMonths_long_invalidTooSmall() { + OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusMonths(1); + } + + //----------------------------------------------------------------------- + // minusWeeks() + //----------------------------------------------------------------------- + @DataProvider(name="sampleMinusWeeksSymmetry") + Object[][] provider_sampleMinusWeeksSymmetry() { + return new Object[][] { + {OffsetDate.of(LocalDate.of(-1, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(-1, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(-1, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(-1, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(0, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(0, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(0, 2, 29), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(0, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(0, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2007, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2007, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2008, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2008, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2008, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2008, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2099, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2099, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2099, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2099, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2100, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2100, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2100, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2100, 12, 31), OFFSET_PTWO)}, + }; + } + + @Test(dataProvider="sampleMinusWeeksSymmetry") + public void test_minusWeeks_symmetry(OffsetDate reference) { + for (int weeks = 0; weeks < 365 * 8; weeks++) { + OffsetDate t = reference.minusWeeks(weeks).minusWeeks(-weeks); + assertEquals(t, reference); + + t = reference.minusWeeks(-weeks).minusWeeks(weeks); + assertEquals(t, reference); + } + } + + @Test + public void test_minusWeeks_normal() { + OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(1); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 8), OFFSET_PONE)); + } + + @Test + public void test_minusWeeks_overMonths() { + OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(9); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 5, 13), OFFSET_PONE)); + } + + @Test + public void test_minusWeeks_overYears() { + OffsetDate t = OffsetDate.of(LocalDate.of(2008, 7, 13), OFFSET_PONE).minusWeeks(52); + assertEquals(t, TEST_2007_07_15_PONE); + } + + @Test + public void test_minusWeeks_overLeapYears() { + OffsetDate t = TEST_2007_07_15_PONE.minusYears(-1).minusWeeks(104); + assertEquals(t, OffsetDate.of(LocalDate.of(2006, 7, 18), OFFSET_PONE)); + } + + @Test + public void test_minusWeeks_negative() { + OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(-1); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 22), OFFSET_PONE)); + } + + @Test + public void test_minusWeeks_negativeAcrossYear() { + OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(-28); + assertEquals(t, OffsetDate.of(LocalDate.of(2008, 1, 27), OFFSET_PONE)); + } + + @Test + public void test_minusWeeks_negativeOverYears() { + OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(-104); + assertEquals(t, OffsetDate.of(LocalDate.of(2009, 7, 12), OFFSET_PONE)); + } + + @Test + public void test_minusWeeks_noChange() { + OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(0); + assertEquals(t, TEST_2007_07_15_PONE); + } + + @Test + public void test_minusWeeks_maximum() { + OffsetDate t = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 24), OFFSET_PONE).minusWeeks(-1); + OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE); + assertEquals(t, expected); + } + + @Test + public void test_minusWeeks_minimum() { + OffsetDate t = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 8), OFFSET_PONE).minusWeeks(1); + OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE); + assertEquals(t, expected); + } + + @Test(expectedExceptions={DateTimeException.class}) + public void test_minusWeeks_invalidTooLarge() { + OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).minusWeeks(-1); + } + + @Test(expectedExceptions={DateTimeException.class}) + public void test_minusWeeks_invalidTooSmall() { + OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 7), OFFSET_PONE).minusWeeks(1); + } + + @Test(expectedExceptions={ArithmeticException.class}) + public void test_minusWeeks_invalidMaxMinusMax() { + OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).minusWeeks(Long.MAX_VALUE); + } + + @Test(expectedExceptions={ArithmeticException.class}) + public void test_minusWeeks_invalidMaxMinusMin() { + OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).minusWeeks(Long.MIN_VALUE); + } + + //----------------------------------------------------------------------- + // minusDays() + //----------------------------------------------------------------------- + @DataProvider(name="sampleMinusDaysSymmetry") + Object[][] provider_sampleMinusDaysSymmetry() { + return new Object[][] { + {OffsetDate.of(LocalDate.of(-1, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(-1, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(-1, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(-1, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(0, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(0, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(0, 2, 29), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(0, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(0, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2007, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2007, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2008, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2008, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2008, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2008, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2099, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2099, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2099, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2099, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2100, 1, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2100, 2, 28), OFFSET_PTWO)}, + {OffsetDate.of(LocalDate.of(2100, 3, 1), OFFSET_PONE)}, + {OffsetDate.of(LocalDate.of(2100, 12, 31), OFFSET_PTWO)}, + }; + } + + @Test(dataProvider="sampleMinusDaysSymmetry") + public void test_minusDays_symmetry(OffsetDate reference) { + for (int days = 0; days < 365 * 8; days++) { + OffsetDate t = reference.minusDays(days).minusDays(-days); + assertEquals(t, reference); + + t = reference.minusDays(-days).minusDays(days); + assertEquals(t, reference); + } + } + + @Test + public void test_minusDays_normal() { + OffsetDate t = TEST_2007_07_15_PONE.minusDays(1); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 14), OFFSET_PONE)); + } + + @Test + public void test_minusDays_overMonths() { + OffsetDate t = TEST_2007_07_15_PONE.minusDays(62); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 5, 14), OFFSET_PONE)); + } + + @Test + public void test_minusDays_overYears() { + OffsetDate t = OffsetDate.of(LocalDate.of(2008, 7, 16), OFFSET_PONE).minusDays(367); + assertEquals(t, TEST_2007_07_15_PONE); + } + + @Test + public void test_minusDays_overLeapYears() { + OffsetDate t = TEST_2007_07_15_PONE.plusYears(2).minusDays(365 + 366); + assertEquals(t, TEST_2007_07_15_PONE); + } + + @Test + public void test_minusDays_negative() { + OffsetDate t = TEST_2007_07_15_PONE.minusDays(-1); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 16), OFFSET_PONE)); + } + + @Test + public void test_minusDays_negativeAcrossYear() { + OffsetDate t = TEST_2007_07_15_PONE.minusDays(-169); + assertEquals(t, OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PONE)); + } + + @Test + public void test_minusDays_negativeOverYears() { + OffsetDate t = TEST_2007_07_15_PONE.minusDays(-731); + assertEquals(t, OffsetDate.of(LocalDate.of(2009, 7, 15), OFFSET_PONE)); + } + + @Test + public void test_minusDays_noChange() { + OffsetDate t = TEST_2007_07_15_PONE.minusDays(0); + assertEquals(t, TEST_2007_07_15_PONE); + } + + @Test + public void test_minusDays_maximum() { + OffsetDate t = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 30), OFFSET_PONE).minusDays(-1); + OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE); + assertEquals(t, expected); + } + + @Test + public void test_minusDays_minimum() { + OffsetDate t = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 2), OFFSET_PONE).minusDays(1); + OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE); + assertEquals(t, expected); + } + + @Test(expectedExceptions={DateTimeException.class}) + public void test_minusDays_invalidTooLarge() { + OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).minusDays(-1); + } + + @Test(expectedExceptions={DateTimeException.class}) + public void test_minusDays_invalidTooSmall() { + OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusDays(1); + } + + @Test(expectedExceptions=ArithmeticException.class) + public void test_minusDays_overflowTooLarge() { + OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).minusDays(Long.MIN_VALUE); + } + + @Test(expectedExceptions=ArithmeticException.class) + public void test_minusDays_overflowTooSmall() { + OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusDays(Long.MAX_VALUE); + } + + //----------------------------------------------------------------------- + // atTime() + //----------------------------------------------------------------------- + @Test + public void test_atTime_Local() { + OffsetDate t = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO); + assertEquals(t.atTime(LocalTime.of(11, 30)), + OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30), OFFSET_PTWO)); + } + + @Test(expectedExceptions=NullPointerException.class) + public void test_atTime_Local_nullLocalTime() { + OffsetDate t = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO); + t.atTime((LocalTime) null); + } + + //----------------------------------------------------------------------- + // getDate() + //----------------------------------------------------------------------- + @Test(dataProvider="sampleDates") + public void test_getDate(int year, int month, int day, ZoneOffset offset) { + LocalDate t = LocalDate.of(year, month, day); + assertEquals(OffsetDate.of(LocalDate.of(year, month, day), offset).getDate(), t); + } + + //----------------------------------------------------------------------- + // compareTo() + //----------------------------------------------------------------------- + @Test + public void test_compareTo_date() { + OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 29), OFFSET_PONE); + OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b due to date + assertEquals(a.compareTo(b) < 0, true); + assertEquals(b.compareTo(a) > 0, true); + assertEquals(a.compareTo(a) == 0, true); + assertEquals(b.compareTo(b) == 0, true); + assertEquals(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0, true); + } + + @Test + public void test_compareTo_offset() { + OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO); + OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b due to offset + assertEquals(a.compareTo(b) < 0, true); + assertEquals(b.compareTo(a) > 0, true); + assertEquals(a.compareTo(a) == 0, true); + assertEquals(b.compareTo(b) == 0, true); + assertEquals(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0, true); + } + + @Test + public void test_compareTo_both() { + OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 29), OFFSET_PTWO); + OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b on instant scale + assertEquals(a.compareTo(b) < 0, true); + assertEquals(b.compareTo(a) > 0, true); + assertEquals(a.compareTo(a) == 0, true); + assertEquals(b.compareTo(b) == 0, true); + assertEquals(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0, true); + } + + @Test + public void test_compareTo_24hourDifference() { + OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 29), ZoneOffset.ofHours(-12)); + OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), ZoneOffset.ofHours(12)); // a is before b despite being same time-line time + assertEquals(a.compareTo(b) < 0, true); + assertEquals(b.compareTo(a) > 0, true); + assertEquals(a.compareTo(a) == 0, true); + assertEquals(b.compareTo(b) == 0, true); + assertEquals(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) == 0, true); + } + + @Test(expectedExceptions=NullPointerException.class) + public void test_compareTo_null() { + OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); + a.compareTo(null); + } + + @Test(expectedExceptions=ClassCastException.class) + @SuppressWarnings({"unchecked", "rawtypes"}) + public void compareToNonOffsetDate() { + Comparable c = TEST_2007_07_15_PONE; + c.compareTo(new Object()); + } + + //----------------------------------------------------------------------- + // isAfter() / isBefore() / isEqual() + //----------------------------------------------------------------------- + @Test + public void test_isBeforeIsAfterIsEqual1() { + OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 29), OFFSET_PONE); + OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b due to time + assertEquals(a.isBefore(b), true); + assertEquals(a.isEqual(b), false); + assertEquals(a.isAfter(b), false); + + assertEquals(b.isBefore(a), false); + assertEquals(b.isEqual(a), false); + assertEquals(b.isAfter(a), true); + + assertEquals(a.isBefore(a), false); + assertEquals(b.isBefore(b), false); + + assertEquals(a.isEqual(a), true); + assertEquals(b.isEqual(b), true); + + assertEquals(a.isAfter(a), false); + assertEquals(b.isAfter(b), false); + } + + @Test + public void test_isBeforeIsAfterIsEqual2() { + OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO); + OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b due to offset + assertEquals(a.isBefore(b), true); + assertEquals(a.isEqual(b), false); + assertEquals(a.isAfter(b), false); + + assertEquals(b.isBefore(a), false); + assertEquals(b.isEqual(a), false); + assertEquals(b.isAfter(a), true); + + assertEquals(a.isBefore(a), false); + assertEquals(b.isBefore(b), false); + + assertEquals(a.isEqual(a), true); + assertEquals(b.isEqual(b), true); + + assertEquals(a.isAfter(a), false); + assertEquals(b.isAfter(b), false); + } + + @Test + public void test_isBeforeIsAfterIsEqual_instantComparison() { + OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), ZoneOffset.ofHours(12)); + OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 29), ZoneOffset.ofHours(-12)); // a is same instant as b + assertEquals(a.isBefore(b), false); + assertEquals(a.isEqual(b), true); + assertEquals(a.isAfter(b), false); + + assertEquals(b.isBefore(a), false); + assertEquals(b.isEqual(a), true); + assertEquals(b.isAfter(a), false); + + assertEquals(a.isBefore(a), false); + assertEquals(b.isBefore(b), false); + + assertEquals(a.isEqual(a), true); + assertEquals(b.isEqual(b), true); + + assertEquals(a.isAfter(a), false); + assertEquals(b.isAfter(b), false); + } + + @Test(expectedExceptions=NullPointerException.class) + public void test_isBefore_null() { + OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); + a.isBefore(null); + } + + @Test(expectedExceptions=NullPointerException.class) + public void test_isAfter_null() { + OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); + a.isAfter(null); + } + + @Test(expectedExceptions=NullPointerException.class) + public void test_isEqual_null() { + OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); + a.isEqual(null); + } + + //----------------------------------------------------------------------- + // equals() / hashCode() + //----------------------------------------------------------------------- + @Test(dataProvider="sampleDates") + public void test_equals_true(int y, int m, int d, ZoneOffset offset) { + OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); + OffsetDate b = OffsetDate.of(LocalDate.of(y, m, d), offset); + assertEquals(a.equals(b), true); + assertEquals(a.hashCode() == b.hashCode(), true); + } + @Test(dataProvider="sampleDates") + public void test_equals_false_year_differs(int y, int m, int d, ZoneOffset offset) { + OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); + OffsetDate b = OffsetDate.of(LocalDate.of(y + 1, m, d), offset); + assertEquals(a.equals(b), false); + } + + @Test(dataProvider="sampleDates") + public void test_equals_false_month_differs(int y, int m, int d, ZoneOffset offset) { + OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); + OffsetDate b = OffsetDate.of(LocalDate.of(y, m + 1, d), offset); + assertEquals(a.equals(b), false); + } + + @Test(dataProvider="sampleDates") + public void test_equals_false_day_differs(int y, int m, int d, ZoneOffset offset) { + OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); + OffsetDate b = OffsetDate.of(LocalDate.of(y, m, d + 1), offset); + assertEquals(a.equals(b), false); + } + + @Test(dataProvider="sampleDates") + public void test_equals_false_offset_differs(int y, int m, int d, ZoneOffset ignored) { + OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), OFFSET_PONE); + OffsetDate b = OffsetDate.of(LocalDate.of(y, m, d), OFFSET_PTWO); + assertEquals(a.equals(b), false); + } + + @Test + public void test_equals_itself_true() { + assertEquals(TEST_2007_07_15_PONE.equals(TEST_2007_07_15_PONE), true); + } + + @Test + public void test_equals_string_false() { + assertEquals(TEST_2007_07_15_PONE.equals("2007-07-15"), false); + } + + //----------------------------------------------------------------------- + // toString() + //----------------------------------------------------------------------- + @DataProvider(name="sampleToString") + Object[][] provider_sampleToString() { + return new Object[][] { + {2008, 7, 5, "Z", "2008-07-05Z"}, + {2008, 7, 5, "+00", "2008-07-05Z"}, + {2008, 7, 5, "+0000", "2008-07-05Z"}, + {2008, 7, 5, "+00:00", "2008-07-05Z"}, + {2008, 7, 5, "+000000", "2008-07-05Z"}, + {2008, 7, 5, "+00:00:00", "2008-07-05Z"}, + {2008, 7, 5, "-00", "2008-07-05Z"}, + {2008, 7, 5, "-0000", "2008-07-05Z"}, + {2008, 7, 5, "-00:00", "2008-07-05Z"}, + {2008, 7, 5, "-000000", "2008-07-05Z"}, + {2008, 7, 5, "-00:00:00", "2008-07-05Z"}, + {2008, 7, 5, "+01", "2008-07-05+01:00"}, + {2008, 7, 5, "+0100", "2008-07-05+01:00"}, + {2008, 7, 5, "+01:00", "2008-07-05+01:00"}, + {2008, 7, 5, "+010000", "2008-07-05+01:00"}, + {2008, 7, 5, "+01:00:00", "2008-07-05+01:00"}, + {2008, 7, 5, "+0130", "2008-07-05+01:30"}, + {2008, 7, 5, "+01:30", "2008-07-05+01:30"}, + {2008, 7, 5, "+013000", "2008-07-05+01:30"}, + {2008, 7, 5, "+01:30:00", "2008-07-05+01:30"}, + {2008, 7, 5, "+013040", "2008-07-05+01:30:40"}, + {2008, 7, 5, "+01:30:40", "2008-07-05+01:30:40"}, + }; + } + + @Test(dataProvider="sampleToString") + public void test_toString(int y, int m, int d, String offsetId, String expected) { + OffsetDate t = OffsetDate.of(LocalDate.of(y, m, d), ZoneOffset.of(offsetId)); + String str = t.toString(); + assertEquals(str, expected); + } + + //----------------------------------------------------------------------- + // toString(DateTimeFormatter) + //----------------------------------------------------------------------- + @Test + public void test_toString_formatter() { + DateTimeFormatter f = DateTimeFormatters.pattern("y M d"); + String t = OffsetDate.of(LocalDate.of(2010, 12, 3), OFFSET_PONE).toString(f); + assertEquals(t, "2010 12 3"); + } + + @Test(expectedExceptions=NullPointerException.class) + public void test_toString_formatter_null() { + OffsetDate.of(LocalDate.of(2010, 12, 3), OFFSET_PONE).toString(null); + } + +} From 5ca5a8dc1caad6ede6335ca8eb4cb46c020865ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 3 Apr 2019 18:43:12 +0200 Subject: [PATCH 144/279] Fix TestOffsetDate compilation --- .../threeten/extra/AbstractDateTimeTest.java | 26 +- .../java/org/threeten/extra/AbstractTest.java | 63 +- .../org/threeten/extra/MockSimplePeriod.java | 24 +- .../org/threeten/extra/TestOffsetDate.java | 771 +++++++++--------- 4 files changed, 458 insertions(+), 426 deletions(-) diff --git a/src/test/java/org/threeten/extra/AbstractDateTimeTest.java b/src/test/java/org/threeten/extra/AbstractDateTimeTest.java index acf0764d..8dfa03e9 100644 --- a/src/test/java/org/threeten/extra/AbstractDateTimeTest.java +++ b/src/test/java/org/threeten/extra/AbstractDateTimeTest.java @@ -29,17 +29,18 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.threeten.bp; +package org.threeten.extra; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import java.time.DateTimeException; +import java.time.temporal.TemporalAccessor; +import java.time.temporal.TemporalField; +import java.time.temporal.TemporalQuery; import java.util.List; -import org.testng.annotations.Test; -import org.threeten.bp.temporal.TemporalAccessor; -import org.threeten.bp.temporal.TemporalField; -import org.threeten.bp.temporal.TemporalQuery; +import org.junit.Test; /** * Base test class for {@code DateTime}. @@ -71,7 +72,7 @@ public abstract class AbstractDateTimeTest extends AbstractTest { public void basicTest_isSupported_DateTimeField_supported() { for (TemporalAccessor sample : samples()) { for (TemporalField field : validFields()) { - assertEquals(sample.isSupported(field), true, "Failed on " + sample + " " + field); + assertEquals("Failed on " + sample + " " + field, true, sample.isSupported(field)); } } } @@ -80,7 +81,7 @@ public void basicTest_isSupported_DateTimeField_supported() { public void basicTest_isSupported_DateTimeField_unsupported() { for (TemporalAccessor sample : samples()) { for (TemporalField field : invalidFields()) { - assertEquals(sample.isSupported(field), false, "Failed on " + sample + " " + field); + assertEquals("Failed on " + sample + " " + field, false, sample.isSupported(field)); } } } @@ -88,7 +89,7 @@ public void basicTest_isSupported_DateTimeField_unsupported() { @Test public void basicTest_isSupported_DateTimeField_null() { for (TemporalAccessor sample : samples()) { - assertEquals(sample.isSupported(null), false, "Failed on " + sample); + assertEquals("Failed on " + sample, false, sample.isSupported(null)); } } @@ -222,13 +223,14 @@ public void basicTest_getLong_DateTimeField_null() { @Test public void basicTest_query() { for (TemporalAccessor sample : samples()) { - assertEquals(sample.query(new TemporalQuery() { + assertEquals("foo", sample.query(new TemporalQuery() { @Override public String queryFrom(TemporalAccessor dateTime) { return "foo"; } - }), "foo"); + })); } } } + diff --git a/src/test/java/org/threeten/extra/AbstractTest.java b/src/test/java/org/threeten/extra/AbstractTest.java index 2d11a93b..d7426e14 100644 --- a/src/test/java/org/threeten/extra/AbstractTest.java +++ b/src/test/java/org/threeten/extra/AbstractTest.java @@ -29,11 +29,11 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.threeten.bp; +package org.threeten.extra; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertSame; -import static org.testng.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -66,12 +66,12 @@ protected static boolean isIsoLeap(long year) { protected static void assertSerializable(Object o) throws IOException, ClassNotFoundException { Object deserialisedObject = writeThenRead(o); - assertEquals(deserialisedObject, o); + assertEquals(o, deserialisedObject); } protected static void assertSerializableAndSame(Object o) throws IOException, ClassNotFoundException { Object deserialisedObject = writeThenRead(o); - assertSame(deserialisedObject, o); + assertSame(o, deserialisedObject); } protected static Object writeThenRead(Object o) throws IOException, ClassNotFoundException { @@ -98,10 +98,10 @@ protected static Object writeThenRead(Object o) throws IOException, ClassNotFoun } protected static void assertEqualsSerialisedForm(Object objectSerialised) throws IOException, ClassNotFoundException { - assertEqualsSerialisedForm(objectSerialised, objectSerialised.getClass()); + assertEqualsSerialisedForm(objectSerialised.getClass(), objectSerialised); } - protected static void assertEqualsSerialisedForm(Object objectSerialised, Class cls) throws IOException, ClassNotFoundException { + protected static void assertEqualsSerialisedForm(Class cls, Object objectSerialised) throws IOException, ClassNotFoundException { String className = cls.getSimpleName(); // try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(SERIALISATION_DATA_FOLDER + className + ".bin"))) { // out.writeObject(objectSerialised); @@ -111,7 +111,7 @@ protected static void assertEqualsSerialisedForm(Object objectSerialised, Class< try { in = new ObjectInputStream(new FileInputStream(SERIALISATION_DATA_FOLDER + className + ".bin")); Object objectFromFile = in.readObject(); - assertEquals(objectFromFile, objectSerialised); + assertEquals(objectSerialised, objectFromFile); } finally { if (in != null) { in.close(); @@ -126,10 +126,10 @@ protected static void assertImmutable(Class cls) { for (Field field : fields) { if (field.getName().contains("$") == false) { if (Modifier.isStatic(field.getModifiers())) { - assertTrue(Modifier.isFinal(field.getModifiers()), "Field:" + field.getName()); + assertTrue("Field:" + field.getName(), Modifier.isFinal(field.getModifiers())); } else { - assertTrue(Modifier.isPrivate(field.getModifiers()), "Field:" + field.getName()); - assertTrue(Modifier.isFinal(field.getModifiers()), "Field:" + field.getName()); + assertTrue("Field:" + field.getName(), Modifier.isPrivate(field.getModifiers())); + assertTrue("Field:" + field.getName(), Modifier.isFinal(field.getModifiers())); } } } @@ -139,7 +139,7 @@ protected static void assertImmutable(Class cls) { } } - protected static void assertSerializedBySer(Object object, byte[] expectedBytes, byte[]... matches) throws Exception { + protected static void assertSerializedBySer(byte[] expectedBytes, Object object, byte[]... matches) throws Exception { String serClass = object.getClass().getPackage().getName() + ".Ser"; Class serCls = Class.forName(serClass); Field field = serCls.getDeclaredField("serialVersionUID"); @@ -160,26 +160,26 @@ protected static void assertSerializedBySer(Object object, byte[] expectedBytes, DataInputStream dis = null; try { dis = new DataInputStream(bais); - assertEquals(dis.readShort(), ObjectStreamConstants.STREAM_MAGIC); - assertEquals(dis.readShort(), ObjectStreamConstants.STREAM_VERSION); - assertEquals(dis.readByte(), ObjectStreamConstants.TC_OBJECT); - assertEquals(dis.readByte(), ObjectStreamConstants.TC_CLASSDESC); - assertEquals(dis.readUTF(), serClass); - assertEquals(dis.readLong(), serVer); - assertEquals(dis.readByte(), ObjectStreamConstants.SC_EXTERNALIZABLE | ObjectStreamConstants.SC_BLOCK_DATA); - assertEquals(dis.readShort(), 0); // number of fields - assertEquals(dis.readByte(), ObjectStreamConstants.TC_ENDBLOCKDATA); // end of classdesc - assertEquals(dis.readByte(), ObjectStreamConstants.TC_NULL); // no superclasses + assertEquals(ObjectStreamConstants.STREAM_MAGIC, dis.readShort()); + assertEquals(ObjectStreamConstants.STREAM_VERSION, dis.readShort()); + assertEquals(ObjectStreamConstants.TC_OBJECT, dis.readByte()); + assertEquals(ObjectStreamConstants.TC_CLASSDESC, dis.readByte()); + assertEquals(serClass, dis.readUTF()); + assertEquals(serVer, dis.readLong()); + assertEquals(ObjectStreamConstants.SC_EXTERNALIZABLE | ObjectStreamConstants.SC_BLOCK_DATA, dis.readByte()); + assertEquals(0, dis.readShort()); // number of fields + assertEquals(ObjectStreamConstants.TC_ENDBLOCKDATA, dis.readByte()); // end of classdesc + assertEquals(ObjectStreamConstants.TC_NULL, dis.readByte()); // no superclasses if (expectedBytes.length < 256) { - assertEquals(dis.readByte(), ObjectStreamConstants.TC_BLOCKDATA); - assertEquals(dis.readUnsignedByte(), expectedBytes.length); + assertEquals(ObjectStreamConstants.TC_BLOCKDATA, dis.readByte()); + assertEquals(expectedBytes.length, dis.readUnsignedByte()); } else { - assertEquals(dis.readByte(), ObjectStreamConstants.TC_BLOCKDATALONG); - assertEquals(dis.readInt(), expectedBytes.length); + assertEquals(ObjectStreamConstants.TC_BLOCKDATALONG, dis.readByte()); + assertEquals(expectedBytes.length, dis.readInt()); } byte[] input = new byte[expectedBytes.length]; dis.readFully(input); - assertEquals(input, expectedBytes); + assertEquals(expectedBytes, input); if (matches.length > 0) { for (byte[] match : matches) { boolean matched = false; @@ -188,7 +188,7 @@ protected static void assertSerializedBySer(Object object, byte[] expectedBytes, dis.mark(1000); byte[] possible = new byte[match.length]; dis.readFully(possible); - assertEquals(possible, match); + assertEquals(match, possible); matched = true; } catch (AssertionError ex) { dis.reset(); @@ -197,8 +197,8 @@ protected static void assertSerializedBySer(Object object, byte[] expectedBytes, } } } else { - assertEquals(dis.readByte(), ObjectStreamConstants.TC_ENDBLOCKDATA); // end of blockdata - assertEquals(dis.read(), -1); + assertEquals(ObjectStreamConstants.TC_ENDBLOCKDATA, dis.readByte()); // end of blockdata + assertEquals(-1, dis.read()); } } finally { if (dis != null) { @@ -208,3 +208,4 @@ protected static void assertSerializedBySer(Object object, byte[] expectedBytes, } } + diff --git a/src/test/java/org/threeten/extra/MockSimplePeriod.java b/src/test/java/org/threeten/extra/MockSimplePeriod.java index 6da62ce0..00ccb1dc 100644 --- a/src/test/java/org/threeten/extra/MockSimplePeriod.java +++ b/src/test/java/org/threeten/extra/MockSimplePeriod.java @@ -29,19 +29,19 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.threeten.bp; +package org.threeten.extra; -import static org.threeten.bp.temporal.ChronoUnit.DAYS; -import static org.threeten.bp.temporal.ChronoUnit.FOREVER; -import static org.threeten.bp.temporal.ChronoUnit.SECONDS; +import static java.time.temporal.ChronoUnit.DAYS; +import static java.time.temporal.ChronoUnit.FOREVER; +import static java.time.temporal.ChronoUnit.SECONDS; +import java.time.DateTimeException; +import java.time.temporal.Temporal; +import java.time.temporal.TemporalAmount; +import java.time.temporal.TemporalUnit; import java.util.Collections; import java.util.List; - -import org.threeten.bp.jdk8.Jdk8Methods; -import org.threeten.bp.temporal.Temporal; -import org.threeten.bp.temporal.TemporalAmount; -import org.threeten.bp.temporal.TemporalUnit; +import java.util.Objects; /** * Mock period of time measured using a single unit, such as {@code 3 Days}. @@ -75,14 +75,14 @@ public final class MockSimplePeriod * @param amount the amount of the period, measured in terms of the unit, positive or negative * @param unit the unit that the period is measured in, must not be the 'Forever' unit, not null * @return the {@code MockSimplePeriod} instance, not null - * @throws DateTimeException if the period unit is {@link org.threeten.bp.temporal.ChronoUnit#FOREVER}. + * @throws DateTimeException if the period unit is {@link java.time.temporal.ChronoUnit#FOREVER}. */ public static MockSimplePeriod of(long amount, TemporalUnit unit) { return new MockSimplePeriod(amount, unit); } private MockSimplePeriod(long amount, TemporalUnit unit) { - Jdk8Methods.requireNonNull(unit, "unit"); + Objects.requireNonNull(unit, "unit"); if (unit == FOREVER) { throw new DateTimeException("Cannot create a period of the Forever unit"); } @@ -130,7 +130,7 @@ public int compareTo(MockSimplePeriod otherPeriod) { if (unit.equals(otherPeriod.getUnit()) == false) { throw new IllegalArgumentException("Units cannot be compared: " + unit + " and " + otherPeriod.getUnit()); } - return Jdk8Methods.compareLongs(amount, otherPeriod.amount); + return Long.compare(amount, otherPeriod.amount); } @Override diff --git a/src/test/java/org/threeten/extra/TestOffsetDate.java b/src/test/java/org/threeten/extra/TestOffsetDate.java index a6df2a48..390c3c30 100644 --- a/src/test/java/org/threeten/extra/TestOffsetDate.java +++ b/src/test/java/org/threeten/extra/TestOffsetDate.java @@ -29,62 +29,77 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -package org.threeten.bp; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.threeten.bp.Month.DECEMBER; -import static org.threeten.bp.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH; -import static org.threeten.bp.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR; -import static org.threeten.bp.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH; -import static org.threeten.bp.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR; -import static org.threeten.bp.temporal.ChronoField.DAY_OF_MONTH; -import static org.threeten.bp.temporal.ChronoField.DAY_OF_WEEK; -import static org.threeten.bp.temporal.ChronoField.DAY_OF_YEAR; -import static org.threeten.bp.temporal.ChronoField.EPOCH_DAY; -import static org.threeten.bp.temporal.ChronoField.EPOCH_MONTH; -import static org.threeten.bp.temporal.ChronoField.ERA; -import static org.threeten.bp.temporal.ChronoField.MONTH_OF_YEAR; -import static org.threeten.bp.temporal.ChronoField.OFFSET_SECONDS; -import static org.threeten.bp.temporal.ChronoField.YEAR; -import static org.threeten.bp.temporal.ChronoField.YEAR_OF_ERA; +package org.threeten.extra; + +import static java.time.Month.DECEMBER; +import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH; +import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR; +import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH; +import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR; +import static java.time.temporal.ChronoField.DAY_OF_MONTH; +import static java.time.temporal.ChronoField.DAY_OF_WEEK; +import static java.time.temporal.ChronoField.DAY_OF_YEAR; +import static java.time.temporal.ChronoField.EPOCH_DAY; +import static java.time.temporal.ChronoField.ERA; +import static java.time.temporal.ChronoField.MONTH_OF_YEAR; +import static java.time.temporal.ChronoField.OFFSET_SECONDS; +import static java.time.temporal.ChronoField.PROLEPTIC_MONTH; +import static java.time.temporal.ChronoField.YEAR; +import static java.time.temporal.ChronoField.YEAR_OF_ERA; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.time.Clock; +import java.time.DateTimeException; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.Month; +import java.time.OffsetDateTime; +import java.time.Period; +import java.time.Year; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.chrono.IsoChronology; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoField; +import java.time.temporal.ChronoUnit; +import java.time.temporal.JulianFields; +import java.time.temporal.Temporal; +import java.time.temporal.TemporalAccessor; +import java.time.temporal.TemporalAdjuster; +import java.time.temporal.TemporalAmount; +import java.time.temporal.TemporalField; +import java.time.temporal.TemporalQueries; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; -import org.threeten.bp.format.DateTimeFormatter; -import org.threeten.bp.format.DateTimeFormatters; -import org.threeten.bp.format.DateTimeParseException; -import org.threeten.bp.temporal.ChronoField; -import org.threeten.bp.temporal.ChronoUnit; -import org.threeten.bp.temporal.ISOChrono; -import org.threeten.bp.temporal.JulianFields; -import org.threeten.bp.temporal.Temporal; -import org.threeten.bp.temporal.TemporalAccessor; -import org.threeten.bp.temporal.TemporalAdder; -import org.threeten.bp.temporal.TemporalAdjuster; -import org.threeten.bp.temporal.TemporalField; -import org.threeten.bp.temporal.TemporalQueries; -import org.threeten.bp.temporal.TemporalSubtractor; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.tngtech.java.junit.dataprovider.DataProvider; +import com.tngtech.java.junit.dataprovider.DataProviderRunner; +import com.tngtech.java.junit.dataprovider.UseDataProvider; /** * Test OffsetDate. */ -@Test +@RunWith(DataProviderRunner.class) public class TestOffsetDate extends AbstractDateTimeTest { private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1); private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2); private OffsetDate TEST_2007_07_15_PONE; - @BeforeMethod + @Before public void setUp() { TEST_2007_07_15_PONE = OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PONE); } @@ -108,7 +123,7 @@ protected List validFields() { ALIGNED_WEEK_OF_MONTH, ALIGNED_WEEK_OF_YEAR, MONTH_OF_YEAR, - EPOCH_MONTH, + PROLEPTIC_MONTH, YEAR_OF_ERA, YEAR, ERA, @@ -167,7 +182,7 @@ public void now() { expected = OffsetDate.now(Clock.systemDefaultZone()); test = OffsetDate.now(); } - assertEquals(test, expected); + assertEquals(expected, test); } @Test @@ -201,12 +216,12 @@ public void now_Clock_offsets() { } } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void now_Clock_nullZoneId() { OffsetDate.now((ZoneId) null); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void now_Clock_nullClock() { OffsetDate.now((Clock) null); } @@ -215,16 +230,16 @@ public void now_Clock_nullClock() { // factories //----------------------------------------------------------------------- private void check(OffsetDate test, int y, int mo, int d, ZoneOffset offset) { - assertEquals(test.getDate(), LocalDate.of(y, mo, d)); - assertEquals(test.getOffset(), offset); + assertEquals(LocalDate.of(y, mo, d), test.getDate()); + assertEquals(offset, test.getOffset()); - assertEquals(test.getYear(), y); - assertEquals(test.getMonth().getValue(), mo); - assertEquals(test.getDayOfMonth(), d); + assertEquals(y, test.getYear()); + assertEquals(mo, test.getMonth().getValue()); + assertEquals(d, test.getDayOfMonth()); assertEquals(test, test); assertEquals(test.hashCode(), test.hashCode()); - assertEquals(OffsetDate.of(LocalDate.of(y, mo, d), offset), test); + assertEquals(test, OffsetDate.of(LocalDate.of(y, mo, d), offset)); } //----------------------------------------------------------------------- @@ -244,30 +259,30 @@ public void factory_of_ints() { //----------------------------------------------------------------------- @Test public void factory_of_intsMonthOffset() { - assertEquals(TEST_2007_07_15_PONE, OffsetDate.of(LocalDate.of(2007, Month.JULY, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, Month.JULY, 15), OFFSET_PONE), TEST_2007_07_15_PONE); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void factory_of_intsMonthOffset_dayTooLow() { OffsetDate.of(LocalDate.of(2007, Month.JANUARY, 0), OFFSET_PONE); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void factory_of_intsMonthOffset_dayTooHigh() { OffsetDate.of(LocalDate.of(2007, Month.JANUARY, 32), OFFSET_PONE); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void factory_of_intsMonthOffset_nullMonth() { OffsetDate.of(LocalDate.of(2007, null, 30), OFFSET_PONE); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void factory_of_intsMonthOffset_yearTooLow() { OffsetDate.of(LocalDate.of(Integer.MIN_VALUE, Month.JANUARY, 1), OFFSET_PONE); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void factory_of_intsMonthOffset_nullOffset() { OffsetDate.of(LocalDate.of(2007, Month.JANUARY, 30), null); } @@ -279,32 +294,32 @@ public void factory_of_intsOffset() { check(test, 2007, 7, 15, OFFSET_PONE); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void factory_of_ints_dayTooLow() { OffsetDate.of(LocalDate.of(2007, 1, 0), OFFSET_PONE); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void factory_of_ints_dayTooHigh() { OffsetDate.of(LocalDate.of(2007, 1, 32), OFFSET_PONE); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void factory_of_ints_monthTooLow() { OffsetDate.of(LocalDate.of(2007, 0, 1), OFFSET_PONE); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void factory_of_ints_monthTooHigh() { OffsetDate.of(LocalDate.of(2007, 13, 1), OFFSET_PONE); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void factory_of_ints_yearTooLow() { OffsetDate.of(LocalDate.of(Integer.MIN_VALUE, 1, 1), OFFSET_PONE); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void factory_of_ints_nullOffset() { OffsetDate.of(LocalDate.of(2007, 1, 1), (ZoneOffset) null); } @@ -317,12 +332,12 @@ public void factory_of_LocalDateZoneOffset() { check(test, 2008, 6, 30, OFFSET_PONE); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void factory_of_LocalDateZoneOffset_nullDate() { OffsetDate.of((LocalDate) null, OFFSET_PONE); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void factory_of_LocalDateZoneOffset_nullOffset() { LocalDate localDate = LocalDate.of(2008, 6, 30); OffsetDate.of(localDate, (ZoneOffset) null); @@ -333,21 +348,21 @@ public void factory_of_LocalDateZoneOffset_nullOffset() { //----------------------------------------------------------------------- @Test public void test_from_TemporalAccessor_OD() { - assertEquals(OffsetDate.from(TEST_2007_07_15_PONE), TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, OffsetDate.from(TEST_2007_07_15_PONE)); } @Test public void test_from_TemporalAccessor_ZDT() { ZonedDateTime base = LocalDateTime.of(2007, 7, 15, 17, 30).atZone(OFFSET_PONE); - assertEquals(OffsetDate.from(base), TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, OffsetDate.from(base)); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void test_from_TemporalAccessor_invalid_noDerive() { OffsetDate.from(LocalTime.of(12, 30)); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void test_from_TemporalAccessor_null() { OffsetDate.from((TemporalAccessor) null); } @@ -355,18 +370,19 @@ public void test_from_TemporalAccessor_null() { //----------------------------------------------------------------------- // parse() //----------------------------------------------------------------------- - @Test(dataProvider="sampleToString") + @Test + @UseDataProvider("provider_sampleToString") public void factory_parse_validText(int y, int m, int d, String offsetId, String parsable) { OffsetDate t = OffsetDate.parse(parsable); - assertNotNull(t, parsable); - assertEquals(t.getYear(), y, parsable); - assertEquals(t.getMonth().getValue(), m, parsable); - assertEquals(t.getDayOfMonth(), d, parsable); - assertEquals(t.getOffset(), ZoneOffset.of(offsetId)); + assertNotNull(parsable, t); + assertEquals(parsable, y, t.getYear()); + assertEquals(parsable, m, t.getMonth().getValue()); + assertEquals(parsable, d, t.getDayOfMonth()); + assertEquals(ZoneOffset.of(offsetId), t.getOffset()); } - @DataProvider(name="sampleBadParse") - Object[][] provider_sampleBadParse() { + @DataProvider + public static Object[][] provider_sampleBadParse() { return new Object[][]{ {"2008/07/05"}, {"10000-01-01"}, @@ -387,22 +403,23 @@ Object[][] provider_sampleBadParse() { }; } - @Test(dataProvider="sampleBadParse", expectedExceptions=DateTimeParseException.class) + @Test(expected=DateTimeParseException.class) + @UseDataProvider("provider_sampleBadParse") public void factory_parse_invalidText(String unparsable) { OffsetDate.parse(unparsable); } - @Test(expectedExceptions=DateTimeParseException.class) + @Test(expected=DateTimeParseException.class) public void factory_parse_illegalValue() { OffsetDate.parse("2008-06-32+01:00"); } - @Test(expectedExceptions=DateTimeParseException.class) + @Test(expected=DateTimeParseException.class) public void factory_parse_invalidValue() { OffsetDate.parse("2008-06-31+01:00"); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void factory_parse_nullText() { OffsetDate.parse((String) null); } @@ -412,18 +429,18 @@ public void factory_parse_nullText() { //----------------------------------------------------------------------- @Test public void factory_parse_formatter() { - DateTimeFormatter f = DateTimeFormatters.pattern("y M d XXX"); + DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d XXX"); OffsetDate test = OffsetDate.parse("2010 12 3 +01:00", f); - assertEquals(test, OffsetDate.of(LocalDate.of(2010, 12, 3), ZoneOffset.ofHours(1))); + assertEquals(OffsetDate.of(LocalDate.of(2010, 12, 3), ZoneOffset.ofHours(1)), test); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void factory_parse_formatter_nullText() { - DateTimeFormatter f = DateTimeFormatters.pattern("y M d"); + DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d"); OffsetDate.parse((String) null, f); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void factory_parse_formatter_nullFormatter() { OffsetDate.parse("ANY", null); } @@ -431,7 +448,7 @@ public void factory_parse_formatter_nullFormatter() { //----------------------------------------------------------------------- // constructor //----------------------------------------------------------------------- - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void constructor_nullDate() throws Throwable { Constructor con = OffsetDate.class.getDeclaredConstructor(LocalDate.class, ZoneOffset.class); con.setAccessible(true); @@ -442,7 +459,7 @@ public void constructor_nullDate() throws Throwable { } } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void constructor_nullOffset() throws Throwable { Constructor con = OffsetDate.class.getDeclaredConstructor(LocalDate.class, ZoneOffset.class); con.setAccessible(true); @@ -456,8 +473,8 @@ public void constructor_nullOffset() throws Throwable { //----------------------------------------------------------------------- // basics //----------------------------------------------------------------------- - @DataProvider(name="sampleDates") - Object[][] provider_sampleDates() { + @DataProvider + public static Object[][] provider_sampleDates() { return new Object[][] { {2008, 7, 5, OFFSET_PTWO}, {2007, 7, 5, OFFSET_PONE}, @@ -469,19 +486,20 @@ Object[][] provider_sampleDates() { }; } - @Test(dataProvider="sampleDates") + @Test + @UseDataProvider("provider_sampleDates") public void test_get_OffsetDate(int y, int m, int d, ZoneOffset offset) { LocalDate localDate = LocalDate.of(y, m, d); OffsetDate a = OffsetDate.of(localDate, offset); - assertEquals(a.getDate(), localDate); - assertEquals(a.getOffset(), offset); - assertEquals(a.toString(), localDate.toString() + offset.toString()); - assertEquals(a.getYear(), localDate.getYear()); - assertEquals(a.getMonth(), localDate.getMonth()); - assertEquals(a.getDayOfMonth(), localDate.getDayOfMonth()); - assertEquals(a.getDayOfYear(), localDate.getDayOfYear()); - assertEquals(a.getDayOfWeek(), localDate.getDayOfWeek()); + assertEquals(localDate, a.getDate()); + assertEquals(offset, a.getOffset()); + assertEquals(localDate.toString() + offset.toString(), a.toString()); + assertEquals(localDate.getYear(), a.getYear()); + assertEquals(localDate.getMonth(), a.getMonth()); + assertEquals(localDate.getDayOfMonth(), a.getDayOfMonth()); + assertEquals(localDate.getDayOfYear(), a.getDayOfYear()); + assertEquals(localDate.getDayOfWeek(), a.getDayOfWeek()); } //----------------------------------------------------------------------- @@ -490,25 +508,25 @@ public void test_get_OffsetDate(int y, int m, int d, ZoneOffset offset) { @Test public void test_get_TemporalField() { OffsetDate test = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); - assertEquals(test.get(ChronoField.YEAR), 2008); - assertEquals(test.get(ChronoField.MONTH_OF_YEAR), 6); - assertEquals(test.get(ChronoField.DAY_OF_MONTH), 30); - assertEquals(test.get(ChronoField.DAY_OF_WEEK), 1); - assertEquals(test.get(ChronoField.DAY_OF_YEAR), 182); + assertEquals(2008, test.get(ChronoField.YEAR)); + assertEquals(6, test.get(ChronoField.MONTH_OF_YEAR)); + assertEquals(30, test.get(ChronoField.DAY_OF_MONTH)); + assertEquals(1, test.get(ChronoField.DAY_OF_WEEK)); + assertEquals(182, test.get(ChronoField.DAY_OF_YEAR)); - assertEquals(test.get(ChronoField.OFFSET_SECONDS), 3600); + assertEquals(3600, test.get(ChronoField.OFFSET_SECONDS)); } @Test public void test_getLong_TemporalField() { OffsetDate test = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); - assertEquals(test.getLong(ChronoField.YEAR), 2008); - assertEquals(test.getLong(ChronoField.MONTH_OF_YEAR), 6); - assertEquals(test.getLong(ChronoField.DAY_OF_MONTH), 30); - assertEquals(test.getLong(ChronoField.DAY_OF_WEEK), 1); - assertEquals(test.getLong(ChronoField.DAY_OF_YEAR), 182); + assertEquals(2008, test.getLong(ChronoField.YEAR)); + assertEquals(6, test.getLong(ChronoField.MONTH_OF_YEAR)); + assertEquals(30, test.getLong(ChronoField.DAY_OF_MONTH)); + assertEquals(1, test.getLong(ChronoField.DAY_OF_WEEK)); + assertEquals(182, test.getLong(ChronoField.DAY_OF_YEAR)); - assertEquals(test.getLong(ChronoField.OFFSET_SECONDS), 3600); + assertEquals(3600, test.getLong(ChronoField.OFFSET_SECONDS)); } //----------------------------------------------------------------------- @@ -516,35 +534,35 @@ public void test_getLong_TemporalField() { //----------------------------------------------------------------------- @Test public void test_query_chrono() { - assertEquals(TEST_2007_07_15_PONE.query(TemporalQueries.chrono()), ISOChrono.INSTANCE); - assertEquals(TemporalQueries.chrono().queryFrom(TEST_2007_07_15_PONE), ISOChrono.INSTANCE); + assertEquals(IsoChronology.INSTANCE, TEST_2007_07_15_PONE.query(TemporalQueries.chronology())); + assertEquals(IsoChronology.INSTANCE, TemporalQueries.chronology().queryFrom(TEST_2007_07_15_PONE)); } @Test public void test_query_zoneId() { - assertEquals(TEST_2007_07_15_PONE.query(TemporalQueries.zoneId()), null); - assertEquals(TemporalQueries.zoneId().queryFrom(TEST_2007_07_15_PONE), null); + assertEquals(null, TEST_2007_07_15_PONE.query(TemporalQueries.zoneId())); + assertEquals(null, TemporalQueries.zoneId().queryFrom(TEST_2007_07_15_PONE)); } @Test public void test_query_precision() { - assertEquals(TEST_2007_07_15_PONE.query(TemporalQueries.precision()), ChronoUnit.DAYS); - assertEquals(TemporalQueries.precision().queryFrom(TEST_2007_07_15_PONE), ChronoUnit.DAYS); + assertEquals(ChronoUnit.DAYS, TEST_2007_07_15_PONE.query(TemporalQueries.precision())); + assertEquals(ChronoUnit.DAYS, TemporalQueries.precision().queryFrom(TEST_2007_07_15_PONE)); } @Test public void test_query_offset() { - assertEquals(TEST_2007_07_15_PONE.query(TemporalQueries.offset()), OFFSET_PONE); - assertEquals(TemporalQueries.offset().queryFrom(TEST_2007_07_15_PONE), OFFSET_PONE); + assertEquals(OFFSET_PONE, TEST_2007_07_15_PONE.query(TemporalQueries.offset())); + assertEquals(OFFSET_PONE, TemporalQueries.offset().queryFrom(TEST_2007_07_15_PONE)); } @Test public void test_query_zone() { - assertEquals(TEST_2007_07_15_PONE.query(TemporalQueries.zone()), OFFSET_PONE); - assertEquals(TemporalQueries.zone().queryFrom(TEST_2007_07_15_PONE), OFFSET_PONE); + assertEquals(OFFSET_PONE, TEST_2007_07_15_PONE.query(TemporalQueries.zone())); + assertEquals(OFFSET_PONE, TemporalQueries.zone().queryFrom(TEST_2007_07_15_PONE)); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void test_query_null() { TEST_2007_07_15_PONE.query(null); } @@ -556,18 +574,18 @@ public void test_query_null() { public void test_withOffset() { OffsetDate base = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); OffsetDate test = base.withOffset(OFFSET_PTWO); - assertEquals(test.getDate(), base.getDate()); - assertEquals(test.getOffset(), OFFSET_PTWO); + assertEquals(base.getDate(), test.getDate()); + assertEquals(OFFSET_PTWO, test.getOffset()); } @Test public void test_withOffset_noChange() { OffsetDate base = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); OffsetDate test = base.withOffset(OFFSET_PONE); - assertEquals(test, base); + assertEquals(base, test); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void test_withOffset_null() { TEST_2007_07_15_PONE.withOffset(null); } @@ -584,38 +602,38 @@ public Temporal adjustInto(Temporal dateTime) { return sample; } }; - assertEquals(TEST_2007_07_15_PONE.with(adjuster), sample); + assertEquals(sample, TEST_2007_07_15_PONE.with(adjuster)); } @Test public void test_with_adjustment_LocalDate() { OffsetDate test = TEST_2007_07_15_PONE.with(LocalDate.of(2008, 6, 30)); - assertEquals(test, OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE), test); } @Test public void test_with_adjustment_OffsetDate() { OffsetDate test = TEST_2007_07_15_PONE.with(OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO)); - assertEquals(test, OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO)); + assertEquals(OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO), test); } @Test public void test_with_adjustment_ZoneOffset() { OffsetDate test = TEST_2007_07_15_PONE.with(OFFSET_PTWO); - assertEquals(test, OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PTWO)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PTWO), test); } @Test public void test_with_adjustment_Month() { OffsetDate test = TEST_2007_07_15_PONE.with(DECEMBER); - assertEquals(test, OffsetDate.of(LocalDate.of(2007, 12, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 12, 15), OFFSET_PONE), test); } @Test public void test_with_adjustment_offsetUnchanged() { OffsetDate base = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); OffsetDate test = base.with(Year.of(2008)); - assertEquals(test, base); + assertEquals(base, test); } @Test @@ -623,10 +641,10 @@ public void test_with_adjustment_noChange() { LocalDate date = LocalDate.of(2008, 6, 30); OffsetDate base = OffsetDate.of(date, OFFSET_PONE); OffsetDate test = base.with(date); - assertEquals(test, base); + assertEquals(base, test); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void test_with_adjustment_null() { TEST_2007_07_15_PONE.with((TemporalAdjuster) null); } @@ -637,21 +655,21 @@ public void test_with_adjustment_null() { @Test public void test_with_TemporalField() { OffsetDate test = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); - assertEquals(test.with(ChronoField.YEAR, 2009), OffsetDate.of(LocalDate.of(2009, 6, 30), OFFSET_PONE)); - assertEquals(test.with(ChronoField.MONTH_OF_YEAR, 7), OffsetDate.of(LocalDate.of(2008, 7, 30), OFFSET_PONE)); - assertEquals(test.with(ChronoField.DAY_OF_MONTH, 1), OffsetDate.of(LocalDate.of(2008, 6, 1), OFFSET_PONE)); - assertEquals(test.with(ChronoField.DAY_OF_WEEK, 2), OffsetDate.of(LocalDate.of(2008, 7, 1), OFFSET_PONE)); - assertEquals(test.with(ChronoField.DAY_OF_YEAR, 183), OffsetDate.of(LocalDate.of(2008, 7, 1), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2009, 6, 30), OFFSET_PONE), test.with(ChronoField.YEAR, 2009)); + assertEquals(OffsetDate.of(LocalDate.of(2008, 7, 30), OFFSET_PONE), test.with(ChronoField.MONTH_OF_YEAR, 7)); + assertEquals(OffsetDate.of(LocalDate.of(2008, 6, 1), OFFSET_PONE), test.with(ChronoField.DAY_OF_MONTH, 1)); + assertEquals(OffsetDate.of(LocalDate.of(2008, 7, 1), OFFSET_PONE), test.with(ChronoField.DAY_OF_WEEK, 2)); + assertEquals(OffsetDate.of(LocalDate.of(2008, 7, 1), OFFSET_PONE), test.with(ChronoField.DAY_OF_YEAR, 183)); - assertEquals(test.with(ChronoField.OFFSET_SECONDS, 7205), OffsetDate.of(LocalDate.of(2008, 6, 30), ZoneOffset.ofHoursMinutesSeconds(2, 0, 5))); + assertEquals(OffsetDate.of(LocalDate.of(2008, 6, 30), ZoneOffset.ofHoursMinutesSeconds(2, 0, 5)), test.with(ChronoField.OFFSET_SECONDS, 7205)); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void test_with_TemporalField_null() { TEST_2007_07_15_PONE.with((TemporalField) null, 0); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void test_with_TemporalField_invalidField() { TEST_2007_07_15_PONE.with(ChronoField.AMPM_OF_DAY, 0); } @@ -662,16 +680,16 @@ public void test_with_TemporalField_invalidField() { @Test public void test_withYear_int_normal() { OffsetDate t = TEST_2007_07_15_PONE.withYear(2008); - assertEquals(t, OffsetDate.of(LocalDate.of(2008, 7, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2008, 7, 15), OFFSET_PONE), t); } @Test public void test_withYear_int_noChange() { OffsetDate t = TEST_2007_07_15_PONE.withYear(2007); - assertEquals(t, TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, t); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void test_withYear_int_invalid() { TEST_2007_07_15_PONE.withYear(Year.MIN_VALUE - 1); } @@ -680,7 +698,7 @@ public void test_withYear_int_invalid() { public void test_withYear_int_adjustDay() { OffsetDate t = OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PONE).withYear(2007); OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PONE); - assertEquals(t, expected); + assertEquals(expected, t); } //----------------------------------------------------------------------- @@ -689,16 +707,16 @@ public void test_withYear_int_adjustDay() { @Test public void test_withMonth_int_normal() { OffsetDate t = TEST_2007_07_15_PONE.withMonth(1); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 1, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 1, 15), OFFSET_PONE), t); } @Test public void test_withMonth_int_noChange() { OffsetDate t = TEST_2007_07_15_PONE.withMonth(7); - assertEquals(t, TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, t); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void test_withMonth_int_invalid() { TEST_2007_07_15_PONE.withMonth(13); } @@ -707,7 +725,7 @@ public void test_withMonth_int_invalid() { public void test_withMonth_int_adjustDay() { OffsetDate t = OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PONE).withMonth(11); OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 11, 30), OFFSET_PONE); - assertEquals(t, expected); + assertEquals(expected, t); } //----------------------------------------------------------------------- @@ -716,21 +734,21 @@ public void test_withMonth_int_adjustDay() { @Test public void test_withDayOfMonth_normal() { OffsetDate t = TEST_2007_07_15_PONE.withDayOfMonth(1); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 1), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 1), OFFSET_PONE), t); } @Test public void test_withDayOfMonth_noChange() { OffsetDate t = TEST_2007_07_15_PONE.withDayOfMonth(15); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PONE), t); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void test_withDayOfMonth_invalidForMonth() { OffsetDate.of(LocalDate.of(2007, 11, 30), OFFSET_PONE).withDayOfMonth(31); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void test_withDayOfMonth_invalidAlways() { OffsetDate.of(LocalDate.of(2007, 11, 30), OFFSET_PONE).withDayOfMonth(32); } @@ -741,21 +759,21 @@ public void test_withDayOfMonth_invalidAlways() { @Test public void test_withDayOfYear_normal() { OffsetDate t = TEST_2007_07_15_PONE.withDayOfYear(33); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 2, 2), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 2, 2), OFFSET_PONE), t); } @Test public void test_withDayOfYear_noChange() { OffsetDate t = TEST_2007_07_15_PONE.withDayOfYear(31 + 28 + 31 + 30 + 31 + 30 + 15); - assertEquals(t, TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, t); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void test_withDayOfYear_illegal() { TEST_2007_07_15_PONE.withDayOfYear(367); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void test_withDayOfYear_invalid() { TEST_2007_07_15_PONE.withDayOfYear(366); } @@ -767,25 +785,25 @@ public void test_withDayOfYear_invalid() { public void test_plus_PlusAdjuster() { MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS); OffsetDate t = TEST_2007_07_15_PONE.plus(period); - assertEquals(t, OffsetDate.of(LocalDate.of(2008, 2, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2008, 2, 15), OFFSET_PONE), t); } @Test public void test_plus_PlusAdjuster_noChange() { MockSimplePeriod period = MockSimplePeriod.of(0, ChronoUnit.MONTHS); OffsetDate t = TEST_2007_07_15_PONE.plus(period); - assertEquals(t, TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, t); } @Test public void test_plus_PlusAdjuster_zero() { OffsetDate t = TEST_2007_07_15_PONE.plus(Period.ZERO); - assertEquals(t, TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, t); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void test_plus_PlusAdjuster_null() { - TEST_2007_07_15_PONE.plus((TemporalAdder) null); + TEST_2007_07_15_PONE.plus((TemporalAmount) null); } //----------------------------------------------------------------------- @@ -794,53 +812,53 @@ public void test_plus_PlusAdjuster_null() { @Test public void test_plusYears_long_normal() { OffsetDate t = TEST_2007_07_15_PONE.plusYears(1); - assertEquals(t, OffsetDate.of(LocalDate.of(2008, 7, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2008, 7, 15), OFFSET_PONE), t); } @Test public void test_plusYears_long_negative() { OffsetDate t = TEST_2007_07_15_PONE.plusYears(-1); - assertEquals(t, OffsetDate.of(LocalDate.of(2006, 7, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2006, 7, 15), OFFSET_PONE), t); } @Test public void test_plusYears_long_noChange() { OffsetDate t = TEST_2007_07_15_PONE.plusYears(0); - assertEquals(t, TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, t); } @Test public void test_plusYears_long_adjustDay() { OffsetDate t = OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PONE).plusYears(1); OffsetDate expected = OffsetDate.of(LocalDate.of(2009, 2, 28), OFFSET_PONE); - assertEquals(t, expected); + assertEquals(expected, t); } @Test public void test_plusYears_long_big() { long years = 20L + Year.MAX_VALUE; OffsetDate test = OffsetDate.of(LocalDate.of(-40, 6, 1), OFFSET_PONE).plusYears(years); - assertEquals(test, OffsetDate.of(LocalDate.of((int) (-40L + years), 6, 1), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of((int) (-40L + years), 6, 1), OFFSET_PONE), test); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void test_plusYears_long_invalidTooLarge() { OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 1, 1), OFFSET_PONE).plusYears(1); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void test_plusYears_long_invalidTooLargeMaxAddMax() { OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); test.plusYears(Long.MAX_VALUE); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void test_plusYears_long_invalidTooLargeMaxAddMin() { OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); test.plusYears(Long.MIN_VALUE); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void test_plusYears_long_invalidTooSmall() { OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusYears(-1); } @@ -851,78 +869,78 @@ public void test_plusYears_long_invalidTooSmall() { @Test public void test_plusMonths_long_normal() { OffsetDate t = TEST_2007_07_15_PONE.plusMonths(1); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 8, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 8, 15), OFFSET_PONE), t); } @Test public void test_plusMonths_long_overYears() { OffsetDate t = TEST_2007_07_15_PONE.plusMonths(25); - assertEquals(t, OffsetDate.of(LocalDate.of(2009, 8, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2009, 8, 15), OFFSET_PONE), t); } @Test public void test_plusMonths_long_negative() { OffsetDate t = TEST_2007_07_15_PONE.plusMonths(-1); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 6, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 6, 15), OFFSET_PONE), t); } @Test public void test_plusMonths_long_negativeAcrossYear() { OffsetDate t = TEST_2007_07_15_PONE.plusMonths(-7); - assertEquals(t, OffsetDate.of(LocalDate.of(2006, 12, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2006, 12, 15), OFFSET_PONE), t); } @Test public void test_plusMonths_long_negativeOverYears() { OffsetDate t = TEST_2007_07_15_PONE.plusMonths(-31); - assertEquals(t, OffsetDate.of(LocalDate.of(2004, 12, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2004, 12, 15), OFFSET_PONE), t); } @Test public void test_plusMonths_long_noChange() { OffsetDate t = TEST_2007_07_15_PONE.plusMonths(0); - assertEquals(t, TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, t); } @Test public void test_plusMonths_long_adjustDayFromLeapYear() { OffsetDate t = OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PONE).plusMonths(12); OffsetDate expected = OffsetDate.of(LocalDate.of(2009, 2, 28), OFFSET_PONE); - assertEquals(t, expected); + assertEquals(expected, t); } @Test public void test_plusMonths_long_adjustDayFromMonthLength() { OffsetDate t = OffsetDate.of(LocalDate.of(2007, 3, 31), OFFSET_PONE).plusMonths(1); OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 4, 30), OFFSET_PONE); - assertEquals(t, expected); + assertEquals(expected, t); } @Test public void test_plusMonths_long_big() { long months = 20L + Integer.MAX_VALUE; OffsetDate test = OffsetDate.of(LocalDate.of(-40, 6, 1), OFFSET_PONE).plusMonths(months); - assertEquals(test, OffsetDate.of(LocalDate.of((int) (-40L + months / 12), 6 + (int) (months % 12), 1), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of((int) (-40L + months / 12), 6 + (int) (months % 12), 1), OFFSET_PONE), test); } - @Test(expectedExceptions={DateTimeException.class}) + @Test(expected=DateTimeException.class) public void test_plusMonths_long_invalidTooLarge() { OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE).plusMonths(1); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void test_plusMonths_long_invalidTooLargeMaxAddMax() { OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); test.plusMonths(Long.MAX_VALUE); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void test_plusMonths_long_invalidTooLargeMaxAddMin() { OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); test.plusMonths(Long.MIN_VALUE); } - @Test(expectedExceptions={DateTimeException.class}) + @Test(expected=DateTimeException.class) public void test_plusMonths_long_invalidTooSmall() { OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusMonths(-1); } @@ -930,8 +948,8 @@ public void test_plusMonths_long_invalidTooSmall() { //----------------------------------------------------------------------- // plusWeeks() //----------------------------------------------------------------------- - @DataProvider(name="samplePlusWeeksSymmetry") - Object[][] provider_samplePlusWeeksSymmetry() { + @DataProvider + public static Object[][] provider_samplePlusWeeksSymmetry() { return new Object[][] { {OffsetDate.of(LocalDate.of(-1, 1, 1), OFFSET_PONE)}, {OffsetDate.of(LocalDate.of(-1, 2, 28), OFFSET_PTWO)}, @@ -962,95 +980,96 @@ Object[][] provider_samplePlusWeeksSymmetry() { }; } - @Test(dataProvider="samplePlusWeeksSymmetry") + @Test + @UseDataProvider("provider_samplePlusWeeksSymmetry") public void test_plusWeeks_symmetry(OffsetDate reference) { for (int weeks = 0; weeks < 365 * 8; weeks++) { OffsetDate t = reference.plusWeeks(weeks).plusWeeks(-weeks); - assertEquals(t, reference); + assertEquals(reference, t); t = reference.plusWeeks(-weeks).plusWeeks(weeks); - assertEquals(t, reference); + assertEquals(reference, t); } } @Test public void test_plusWeeks_normal() { OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(1); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 22), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 22), OFFSET_PONE), t); } @Test public void test_plusWeeks_overMonths() { OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(9); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 9, 16), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 9, 16), OFFSET_PONE), t); } @Test public void test_plusWeeks_overYears() { OffsetDate t = OffsetDate.of(LocalDate.of(2006, 7, 16), OFFSET_PONE).plusWeeks(52); - assertEquals(t, TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, t); } @Test public void test_plusWeeks_overLeapYears() { OffsetDate t = TEST_2007_07_15_PONE.plusYears(-1).plusWeeks(104); - assertEquals(t, OffsetDate.of(LocalDate.of(2008, 7, 12), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2008, 7, 12), OFFSET_PONE), t); } @Test public void test_plusWeeks_negative() { OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(-1); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 8), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 8), OFFSET_PONE), t); } @Test public void test_plusWeeks_negativeAcrossYear() { OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(-28); - assertEquals(t, OffsetDate.of(LocalDate.of(2006, 12, 31), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2006, 12, 31), OFFSET_PONE), t); } @Test public void test_plusWeeks_negativeOverYears() { OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(-104); - assertEquals(t, OffsetDate.of(LocalDate.of(2005, 7, 17), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2005, 7, 17), OFFSET_PONE), t); } @Test public void test_plusWeeks_noChange() { OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(0); - assertEquals(t, TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, t); } @Test public void test_plusWeeks_maximum() { OffsetDate t = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 24), OFFSET_PONE).plusWeeks(1); OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE); - assertEquals(t, expected); + assertEquals(expected, t); } @Test public void test_plusWeeks_minimum() { OffsetDate t = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 8), OFFSET_PONE).plusWeeks(-1); OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE); - assertEquals(t, expected); + assertEquals(expected, t); } - @Test(expectedExceptions={DateTimeException.class}) + @Test(expected=DateTimeException.class) public void test_plusWeeks_invalidTooLarge() { OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).plusWeeks(1); } - @Test(expectedExceptions={DateTimeException.class}) + @Test(expected=DateTimeException.class) public void test_plusWeeks_invalidTooSmall() { OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 7), OFFSET_PONE).plusWeeks(-1); } - @Test(expectedExceptions={ArithmeticException.class}) + @Test(expected=ArithmeticException.class) public void test_plusWeeks_invalidMaxMinusMax() { OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).plusWeeks(Long.MAX_VALUE); } - @Test(expectedExceptions={ArithmeticException.class}) + @Test(expected=ArithmeticException.class) public void test_plusWeeks_invalidMaxMinusMin() { OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).plusWeeks(Long.MIN_VALUE); } @@ -1058,8 +1077,8 @@ public void test_plusWeeks_invalidMaxMinusMin() { //----------------------------------------------------------------------- // plusDays() //----------------------------------------------------------------------- - @DataProvider(name="samplePlusDaysSymmetry") - Object[][] provider_samplePlusDaysSymmetry() { + @DataProvider + public static Object[][] provider_samplePlusDaysSymmetry() { return new Object[][] { {OffsetDate.of(LocalDate.of(-1, 1, 1), OFFSET_PONE)}, {OffsetDate.of(LocalDate.of(-1, 2, 28), OFFSET_PTWO)}, @@ -1090,95 +1109,96 @@ Object[][] provider_samplePlusDaysSymmetry() { }; } - @Test(dataProvider="samplePlusDaysSymmetry") + @Test + @UseDataProvider("provider_samplePlusDaysSymmetry") public void test_plusDays_symmetry(OffsetDate reference) { for (int days = 0; days < 365 * 8; days++) { OffsetDate t = reference.plusDays(days).plusDays(-days); - assertEquals(t, reference); + assertEquals(reference, t); t = reference.plusDays(-days).plusDays(days); - assertEquals(t, reference); + assertEquals(reference, t); } } @Test public void test_plusDays_normal() { OffsetDate t = TEST_2007_07_15_PONE.plusDays(1); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 16), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 16), OFFSET_PONE), t); } @Test public void test_plusDays_overMonths() { OffsetDate t = TEST_2007_07_15_PONE.plusDays(62); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 9, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 9, 15), OFFSET_PONE), t); } @Test public void test_plusDays_overYears() { OffsetDate t = OffsetDate.of(LocalDate.of(2006, 7, 14), OFFSET_PONE).plusDays(366); - assertEquals(t, TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, t); } @Test public void test_plusDays_overLeapYears() { OffsetDate t = TEST_2007_07_15_PONE.plusYears(-1).plusDays(365 + 366); - assertEquals(t, OffsetDate.of(LocalDate.of(2008, 7, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2008, 7, 15), OFFSET_PONE), t); } @Test public void test_plusDays_negative() { OffsetDate t = TEST_2007_07_15_PONE.plusDays(-1); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 14), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 14), OFFSET_PONE), t); } @Test public void test_plusDays_negativeAcrossYear() { OffsetDate t = TEST_2007_07_15_PONE.plusDays(-196); - assertEquals(t, OffsetDate.of(LocalDate.of(2006, 12, 31), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2006, 12, 31), OFFSET_PONE), t); } @Test public void test_plusDays_negativeOverYears() { OffsetDate t = TEST_2007_07_15_PONE.plusDays(-730); - assertEquals(t, OffsetDate.of(LocalDate.of(2005, 7, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2005, 7, 15), OFFSET_PONE), t); } @Test public void test_plusDays_noChange() { OffsetDate t = TEST_2007_07_15_PONE.plusDays(0); - assertEquals(t, TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, t); } @Test public void test_plusDays_maximum() { OffsetDate t = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 30), OFFSET_PONE).plusDays(1); OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE); - assertEquals(t, expected); + assertEquals(expected, t); } @Test public void test_plusDays_minimum() { OffsetDate t = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 2), OFFSET_PONE).plusDays(-1); OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE); - assertEquals(t, expected); + assertEquals(expected, t); } - @Test(expectedExceptions={DateTimeException.class}) + @Test(expected=DateTimeException.class) public void test_plusDays_invalidTooLarge() { OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).plusDays(1); } - @Test(expectedExceptions={DateTimeException.class}) + @Test(expected=DateTimeException.class) public void test_plusDays_invalidTooSmall() { OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusDays(-1); } - @Test(expectedExceptions=ArithmeticException.class) + @Test(expected=ArithmeticException.class) public void test_plusDays_overflowTooLarge() { OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).plusDays(Long.MAX_VALUE); } - @Test(expectedExceptions=ArithmeticException.class) + @Test(expected=ArithmeticException.class) public void test_plusDays_overflowTooSmall() { OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusDays(Long.MIN_VALUE); } @@ -1190,25 +1210,25 @@ public void test_plusDays_overflowTooSmall() { public void test_minus_MinusAdjuster() { MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS); OffsetDate t = TEST_2007_07_15_PONE.minus(period); - assertEquals(t, OffsetDate.of(LocalDate.of(2006, 12, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2006, 12, 15), OFFSET_PONE), t); } @Test public void test_minus_MinusAdjuster_noChange() { MockSimplePeriod period = MockSimplePeriod.of(0, ChronoUnit.MONTHS); OffsetDate t = TEST_2007_07_15_PONE.minus(period); - assertEquals(t, TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, t); } @Test public void test_minus_MinusAdjuster_zero() { OffsetDate t = TEST_2007_07_15_PONE.minus(Period.ZERO); - assertEquals(t, TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, t); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void test_plus_MinusAdjuster_null() { - TEST_2007_07_15_PONE.minus((TemporalSubtractor) null); + TEST_2007_07_15_PONE.minus((TemporalAmount) null); } //----------------------------------------------------------------------- @@ -1217,53 +1237,53 @@ public void test_plus_MinusAdjuster_null() { @Test public void test_minusYears_long_normal() { OffsetDate t = TEST_2007_07_15_PONE.minusYears(1); - assertEquals(t, OffsetDate.of(LocalDate.of(2006, 7, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2006, 7, 15), OFFSET_PONE), t); } @Test public void test_minusYears_long_negative() { OffsetDate t = TEST_2007_07_15_PONE.minusYears(-1); - assertEquals(t, OffsetDate.of(LocalDate.of(2008, 7, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2008, 7, 15), OFFSET_PONE), t); } @Test public void test_minusYears_long_noChange() { OffsetDate t = TEST_2007_07_15_PONE.minusYears(0); - assertEquals(t, TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, t); } @Test public void test_minusYears_long_adjustDay() { OffsetDate t = OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PONE).minusYears(1); OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PONE); - assertEquals(t, expected); + assertEquals(expected, t); } @Test public void test_minusYears_long_big() { long years = 20L + Year.MAX_VALUE; OffsetDate test = OffsetDate.of(LocalDate.of(40, 6, 1), OFFSET_PONE).minusYears(years); - assertEquals(test, OffsetDate.of(LocalDate.of((int) (40L - years), 6, 1), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of((int) (40L - years), 6, 1), OFFSET_PONE), test); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void test_minusYears_long_invalidTooLarge() { OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 1, 1), OFFSET_PONE).minusYears(-1); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void test_minusYears_long_invalidTooLargeMaxAddMax() { OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); test.minusYears(Long.MAX_VALUE); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void test_minusYears_long_invalidTooLargeMaxAddMin() { OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); test.minusYears(Long.MIN_VALUE); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void test_minusYears_long_invalidTooSmall() { OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusYears(1); } @@ -1274,78 +1294,78 @@ public void test_minusYears_long_invalidTooSmall() { @Test public void test_minusMonths_long_normal() { OffsetDate t = TEST_2007_07_15_PONE.minusMonths(1); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 6, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 6, 15), OFFSET_PONE), t); } @Test public void test_minusMonths_long_overYears() { OffsetDate t = TEST_2007_07_15_PONE.minusMonths(25); - assertEquals(t, OffsetDate.of(LocalDate.of(2005, 6, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2005, 6, 15), OFFSET_PONE), t); } @Test public void test_minusMonths_long_negative() { OffsetDate t = TEST_2007_07_15_PONE.minusMonths(-1); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 8, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 8, 15), OFFSET_PONE), t); } @Test public void test_minusMonths_long_negativeAcrossYear() { OffsetDate t = TEST_2007_07_15_PONE.minusMonths(-7); - assertEquals(t, OffsetDate.of(LocalDate.of(2008, 2, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2008, 2, 15), OFFSET_PONE), t); } @Test public void test_minusMonths_long_negativeOverYears() { OffsetDate t = TEST_2007_07_15_PONE.minusMonths(-31); - assertEquals(t, OffsetDate.of(LocalDate.of(2010, 2, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2010, 2, 15), OFFSET_PONE), t); } @Test public void test_minusMonths_long_noChange() { OffsetDate t = TEST_2007_07_15_PONE.minusMonths(0); - assertEquals(t, TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, t); } @Test public void test_minusMonths_long_adjustDayFromLeapYear() { OffsetDate t = OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PONE).minusMonths(12); OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PONE); - assertEquals(t, expected); + assertEquals(expected, t); } @Test public void test_minusMonths_long_adjustDayFromMonthLength() { OffsetDate t = OffsetDate.of(LocalDate.of(2007, 3, 31), OFFSET_PONE).minusMonths(1); OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PONE); - assertEquals(t, expected); + assertEquals(expected, t); } @Test public void test_minusMonths_long_big() { long months = 20L + Integer.MAX_VALUE; OffsetDate test = OffsetDate.of(LocalDate.of(40, 6, 1), OFFSET_PONE).minusMonths(months); - assertEquals(test, OffsetDate.of(LocalDate.of((int) (40L - months / 12), 6 - (int) (months % 12), 1), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of((int) (40L - months / 12), 6 - (int) (months % 12), 1), OFFSET_PONE), test); } - @Test(expectedExceptions={DateTimeException.class}) + @Test(expected=DateTimeException.class) public void test_minusMonths_long_invalidTooLarge() { OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE).minusMonths(-1); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void test_minusMonths_long_invalidTooLargeMaxAddMax() { OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); test.minusMonths(Long.MAX_VALUE); } - @Test(expectedExceptions=DateTimeException.class) + @Test(expected=DateTimeException.class) public void test_minusMonths_long_invalidTooLargeMaxAddMin() { OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); test.minusMonths(Long.MIN_VALUE); } - @Test(expectedExceptions={DateTimeException.class}) + @Test(expected=DateTimeException.class) public void test_minusMonths_long_invalidTooSmall() { OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusMonths(1); } @@ -1353,8 +1373,8 @@ public void test_minusMonths_long_invalidTooSmall() { //----------------------------------------------------------------------- // minusWeeks() //----------------------------------------------------------------------- - @DataProvider(name="sampleMinusWeeksSymmetry") - Object[][] provider_sampleMinusWeeksSymmetry() { + @DataProvider + public static Object[][] provider_sampleMinusWeeksSymmetry() { return new Object[][] { {OffsetDate.of(LocalDate.of(-1, 1, 1), OFFSET_PONE)}, {OffsetDate.of(LocalDate.of(-1, 2, 28), OFFSET_PTWO)}, @@ -1385,95 +1405,96 @@ Object[][] provider_sampleMinusWeeksSymmetry() { }; } - @Test(dataProvider="sampleMinusWeeksSymmetry") + @Test + @UseDataProvider("provider_sampleMinusWeeksSymmetry") public void test_minusWeeks_symmetry(OffsetDate reference) { for (int weeks = 0; weeks < 365 * 8; weeks++) { OffsetDate t = reference.minusWeeks(weeks).minusWeeks(-weeks); - assertEquals(t, reference); + assertEquals(reference, t); t = reference.minusWeeks(-weeks).minusWeeks(weeks); - assertEquals(t, reference); + assertEquals(reference, t); } } @Test public void test_minusWeeks_normal() { OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(1); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 8), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 8), OFFSET_PONE), t); } @Test public void test_minusWeeks_overMonths() { OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(9); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 5, 13), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 5, 13), OFFSET_PONE), t); } @Test public void test_minusWeeks_overYears() { OffsetDate t = OffsetDate.of(LocalDate.of(2008, 7, 13), OFFSET_PONE).minusWeeks(52); - assertEquals(t, TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, t); } @Test public void test_minusWeeks_overLeapYears() { OffsetDate t = TEST_2007_07_15_PONE.minusYears(-1).minusWeeks(104); - assertEquals(t, OffsetDate.of(LocalDate.of(2006, 7, 18), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2006, 7, 18), OFFSET_PONE), t); } @Test public void test_minusWeeks_negative() { OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(-1); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 22), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 22), OFFSET_PONE), t); } @Test public void test_minusWeeks_negativeAcrossYear() { OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(-28); - assertEquals(t, OffsetDate.of(LocalDate.of(2008, 1, 27), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2008, 1, 27), OFFSET_PONE), t); } @Test public void test_minusWeeks_negativeOverYears() { OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(-104); - assertEquals(t, OffsetDate.of(LocalDate.of(2009, 7, 12), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2009, 7, 12), OFFSET_PONE), t); } @Test public void test_minusWeeks_noChange() { OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(0); - assertEquals(t, TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, t); } @Test public void test_minusWeeks_maximum() { OffsetDate t = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 24), OFFSET_PONE).minusWeeks(-1); OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE); - assertEquals(t, expected); + assertEquals(expected, t); } @Test public void test_minusWeeks_minimum() { OffsetDate t = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 8), OFFSET_PONE).minusWeeks(1); OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE); - assertEquals(t, expected); + assertEquals(expected, t); } - @Test(expectedExceptions={DateTimeException.class}) + @Test(expected=DateTimeException.class) public void test_minusWeeks_invalidTooLarge() { OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).minusWeeks(-1); } - @Test(expectedExceptions={DateTimeException.class}) + @Test(expected=DateTimeException.class) public void test_minusWeeks_invalidTooSmall() { OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 7), OFFSET_PONE).minusWeeks(1); } - @Test(expectedExceptions={ArithmeticException.class}) + @Test(expected=ArithmeticException.class) public void test_minusWeeks_invalidMaxMinusMax() { OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).minusWeeks(Long.MAX_VALUE); } - @Test(expectedExceptions={ArithmeticException.class}) + @Test(expected=ArithmeticException.class) public void test_minusWeeks_invalidMaxMinusMin() { OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).minusWeeks(Long.MIN_VALUE); } @@ -1481,8 +1502,8 @@ public void test_minusWeeks_invalidMaxMinusMin() { //----------------------------------------------------------------------- // minusDays() //----------------------------------------------------------------------- - @DataProvider(name="sampleMinusDaysSymmetry") - Object[][] provider_sampleMinusDaysSymmetry() { + @DataProvider + public static Object[][] provider_sampleMinusDaysSymmetry() { return new Object[][] { {OffsetDate.of(LocalDate.of(-1, 1, 1), OFFSET_PONE)}, {OffsetDate.of(LocalDate.of(-1, 2, 28), OFFSET_PTWO)}, @@ -1513,95 +1534,96 @@ Object[][] provider_sampleMinusDaysSymmetry() { }; } - @Test(dataProvider="sampleMinusDaysSymmetry") + @Test + @UseDataProvider("provider_sampleMinusDaysSymmetry") public void test_minusDays_symmetry(OffsetDate reference) { for (int days = 0; days < 365 * 8; days++) { OffsetDate t = reference.minusDays(days).minusDays(-days); - assertEquals(t, reference); + assertEquals(reference, t); t = reference.minusDays(-days).minusDays(days); - assertEquals(t, reference); + assertEquals(reference, t); } } @Test public void test_minusDays_normal() { OffsetDate t = TEST_2007_07_15_PONE.minusDays(1); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 14), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 14), OFFSET_PONE), t); } @Test public void test_minusDays_overMonths() { OffsetDate t = TEST_2007_07_15_PONE.minusDays(62); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 5, 14), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 5, 14), OFFSET_PONE), t); } @Test public void test_minusDays_overYears() { OffsetDate t = OffsetDate.of(LocalDate.of(2008, 7, 16), OFFSET_PONE).minusDays(367); - assertEquals(t, TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, t); } @Test public void test_minusDays_overLeapYears() { OffsetDate t = TEST_2007_07_15_PONE.plusYears(2).minusDays(365 + 366); - assertEquals(t, TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, t); } @Test public void test_minusDays_negative() { OffsetDate t = TEST_2007_07_15_PONE.minusDays(-1); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 7, 16), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 16), OFFSET_PONE), t); } @Test public void test_minusDays_negativeAcrossYear() { OffsetDate t = TEST_2007_07_15_PONE.minusDays(-169); - assertEquals(t, OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PONE), t); } @Test public void test_minusDays_negativeOverYears() { OffsetDate t = TEST_2007_07_15_PONE.minusDays(-731); - assertEquals(t, OffsetDate.of(LocalDate.of(2009, 7, 15), OFFSET_PONE)); + assertEquals(OffsetDate.of(LocalDate.of(2009, 7, 15), OFFSET_PONE), t); } @Test public void test_minusDays_noChange() { OffsetDate t = TEST_2007_07_15_PONE.minusDays(0); - assertEquals(t, TEST_2007_07_15_PONE); + assertEquals(TEST_2007_07_15_PONE, t); } @Test public void test_minusDays_maximum() { OffsetDate t = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 30), OFFSET_PONE).minusDays(-1); OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE); - assertEquals(t, expected); + assertEquals(expected, t); } @Test public void test_minusDays_minimum() { OffsetDate t = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 2), OFFSET_PONE).minusDays(1); OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE); - assertEquals(t, expected); + assertEquals(expected, t); } - @Test(expectedExceptions={DateTimeException.class}) + @Test(expected=DateTimeException.class) public void test_minusDays_invalidTooLarge() { OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).minusDays(-1); } - @Test(expectedExceptions={DateTimeException.class}) + @Test(expected=DateTimeException.class) public void test_minusDays_invalidTooSmall() { OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusDays(1); } - @Test(expectedExceptions=ArithmeticException.class) + @Test(expected=ArithmeticException.class) public void test_minusDays_overflowTooLarge() { OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).minusDays(Long.MIN_VALUE); } - @Test(expectedExceptions=ArithmeticException.class) + @Test(expected=ArithmeticException.class) public void test_minusDays_overflowTooSmall() { OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusDays(Long.MAX_VALUE); } @@ -1612,11 +1634,11 @@ public void test_minusDays_overflowTooSmall() { @Test public void test_atTime_Local() { OffsetDate t = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO); - assertEquals(t.atTime(LocalTime.of(11, 30)), - OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30), OFFSET_PTWO)); + assertEquals(OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30), OFFSET_PTWO), + t.atTime(LocalTime.of(11, 30))); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void test_atTime_Local_nullLocalTime() { OffsetDate t = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO); t.atTime((LocalTime) null); @@ -1625,10 +1647,11 @@ public void test_atTime_Local_nullLocalTime() { //----------------------------------------------------------------------- // getDate() //----------------------------------------------------------------------- - @Test(dataProvider="sampleDates") + @Test + @UseDataProvider("provider_sampleDates") public void test_getDate(int year, int month, int day, ZoneOffset offset) { LocalDate t = LocalDate.of(year, month, day); - assertEquals(OffsetDate.of(LocalDate.of(year, month, day), offset).getDate(), t); + assertEquals(t, OffsetDate.of(LocalDate.of(year, month, day), offset).getDate()); } //----------------------------------------------------------------------- @@ -1638,53 +1661,53 @@ public void test_getDate(int year, int month, int day, ZoneOffset offset) { public void test_compareTo_date() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 29), OFFSET_PONE); OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b due to date - assertEquals(a.compareTo(b) < 0, true); - assertEquals(b.compareTo(a) > 0, true); - assertEquals(a.compareTo(a) == 0, true); - assertEquals(b.compareTo(b) == 0, true); - assertEquals(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0, true); + assertEquals(true, a.compareTo(b) < 0); + assertEquals(true, b.compareTo(a) > 0); + assertEquals(true, a.compareTo(a) == 0); + assertEquals(true, b.compareTo(b) == 0); + assertEquals(true, a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0); } @Test public void test_compareTo_offset() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO); OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b due to offset - assertEquals(a.compareTo(b) < 0, true); - assertEquals(b.compareTo(a) > 0, true); - assertEquals(a.compareTo(a) == 0, true); - assertEquals(b.compareTo(b) == 0, true); - assertEquals(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0, true); + assertEquals(true, a.compareTo(b) < 0); + assertEquals(true, b.compareTo(a) > 0); + assertEquals(true, a.compareTo(a) == 0); + assertEquals(true, b.compareTo(b) == 0); + assertEquals(true, a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0); } @Test public void test_compareTo_both() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 29), OFFSET_PTWO); OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b on instant scale - assertEquals(a.compareTo(b) < 0, true); - assertEquals(b.compareTo(a) > 0, true); - assertEquals(a.compareTo(a) == 0, true); - assertEquals(b.compareTo(b) == 0, true); - assertEquals(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0, true); + assertEquals(true, a.compareTo(b) < 0); + assertEquals(true, b.compareTo(a) > 0); + assertEquals(true, a.compareTo(a) == 0); + assertEquals(true, b.compareTo(b) == 0); + assertEquals(true, a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0); } @Test public void test_compareTo_24hourDifference() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 29), ZoneOffset.ofHours(-12)); OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), ZoneOffset.ofHours(12)); // a is before b despite being same time-line time - assertEquals(a.compareTo(b) < 0, true); - assertEquals(b.compareTo(a) > 0, true); - assertEquals(a.compareTo(a) == 0, true); - assertEquals(b.compareTo(b) == 0, true); - assertEquals(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) == 0, true); + assertEquals(true, a.compareTo(b) < 0); + assertEquals(true, b.compareTo(a) > 0); + assertEquals(true, a.compareTo(a) == 0); + assertEquals(true, b.compareTo(b) == 0); + assertEquals(true, a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) == 0); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void test_compareTo_null() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); a.compareTo(null); } - @Test(expectedExceptions=ClassCastException.class) + @Test(expected=ClassCastException.class) @SuppressWarnings({"unchecked", "rawtypes"}) public void compareToNonOffsetDate() { Comparable c = TEST_2007_07_15_PONE; @@ -1698,81 +1721,81 @@ public void compareToNonOffsetDate() { public void test_isBeforeIsAfterIsEqual1() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 29), OFFSET_PONE); OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b due to time - assertEquals(a.isBefore(b), true); - assertEquals(a.isEqual(b), false); - assertEquals(a.isAfter(b), false); + assertEquals(true, a.isBefore(b)); + assertEquals(false, a.isEqual(b)); + assertEquals(false, a.isAfter(b)); - assertEquals(b.isBefore(a), false); - assertEquals(b.isEqual(a), false); - assertEquals(b.isAfter(a), true); + assertEquals(false, b.isBefore(a)); + assertEquals(false, b.isEqual(a)); + assertEquals(true, b.isAfter(a)); - assertEquals(a.isBefore(a), false); - assertEquals(b.isBefore(b), false); + assertEquals(false, a.isBefore(a)); + assertEquals(false, b.isBefore(b)); - assertEquals(a.isEqual(a), true); - assertEquals(b.isEqual(b), true); + assertEquals(true, a.isEqual(a)); + assertEquals(true, b.isEqual(b)); - assertEquals(a.isAfter(a), false); - assertEquals(b.isAfter(b), false); + assertEquals(false, a.isAfter(a)); + assertEquals(false, b.isAfter(b)); } @Test public void test_isBeforeIsAfterIsEqual2() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO); OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b due to offset - assertEquals(a.isBefore(b), true); - assertEquals(a.isEqual(b), false); - assertEquals(a.isAfter(b), false); + assertEquals(true, a.isBefore(b)); + assertEquals(false, a.isEqual(b)); + assertEquals(false, a.isAfter(b)); - assertEquals(b.isBefore(a), false); - assertEquals(b.isEqual(a), false); - assertEquals(b.isAfter(a), true); + assertEquals(false, b.isBefore(a)); + assertEquals(false, b.isEqual(a)); + assertEquals(true, b.isAfter(a)); - assertEquals(a.isBefore(a), false); - assertEquals(b.isBefore(b), false); + assertEquals(false, a.isBefore(a)); + assertEquals(false, b.isBefore(b)); - assertEquals(a.isEqual(a), true); - assertEquals(b.isEqual(b), true); + assertEquals(true, a.isEqual(a)); + assertEquals(true, b.isEqual(b)); - assertEquals(a.isAfter(a), false); - assertEquals(b.isAfter(b), false); + assertEquals(false, a.isAfter(a)); + assertEquals(false, b.isAfter(b)); } @Test public void test_isBeforeIsAfterIsEqual_instantComparison() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), ZoneOffset.ofHours(12)); OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 29), ZoneOffset.ofHours(-12)); // a is same instant as b - assertEquals(a.isBefore(b), false); - assertEquals(a.isEqual(b), true); - assertEquals(a.isAfter(b), false); + assertEquals(false, a.isBefore(b)); + assertEquals(true, a.isEqual(b)); + assertEquals(false, a.isAfter(b)); - assertEquals(b.isBefore(a), false); - assertEquals(b.isEqual(a), true); - assertEquals(b.isAfter(a), false); + assertEquals(false, b.isBefore(a)); + assertEquals(true, b.isEqual(a)); + assertEquals(false, b.isAfter(a)); - assertEquals(a.isBefore(a), false); - assertEquals(b.isBefore(b), false); + assertEquals(false, a.isBefore(a)); + assertEquals(false, b.isBefore(b)); - assertEquals(a.isEqual(a), true); - assertEquals(b.isEqual(b), true); + assertEquals(true, a.isEqual(a)); + assertEquals(true, b.isEqual(b)); - assertEquals(a.isAfter(a), false); - assertEquals(b.isAfter(b), false); + assertEquals(false, a.isAfter(a)); + assertEquals(false, b.isAfter(b)); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void test_isBefore_null() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); a.isBefore(null); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void test_isAfter_null() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); a.isAfter(null); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void test_isEqual_null() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); a.isEqual(null); @@ -1781,56 +1804,61 @@ public void test_isEqual_null() { //----------------------------------------------------------------------- // equals() / hashCode() //----------------------------------------------------------------------- - @Test(dataProvider="sampleDates") + @Test + @UseDataProvider("provider_sampleDates") public void test_equals_true(int y, int m, int d, ZoneOffset offset) { OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); OffsetDate b = OffsetDate.of(LocalDate.of(y, m, d), offset); - assertEquals(a.equals(b), true); - assertEquals(a.hashCode() == b.hashCode(), true); + assertEquals(true, a.equals(b)); + assertEquals(true, a.hashCode() == b.hashCode()); } - @Test(dataProvider="sampleDates") + @Test + @UseDataProvider("provider_sampleDates") public void test_equals_false_year_differs(int y, int m, int d, ZoneOffset offset) { OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); OffsetDate b = OffsetDate.of(LocalDate.of(y + 1, m, d), offset); - assertEquals(a.equals(b), false); + assertEquals(false, a.equals(b)); } - @Test(dataProvider="sampleDates") + @Test + @UseDataProvider("provider_sampleDates") public void test_equals_false_month_differs(int y, int m, int d, ZoneOffset offset) { OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); OffsetDate b = OffsetDate.of(LocalDate.of(y, m + 1, d), offset); - assertEquals(a.equals(b), false); + assertEquals(false, a.equals(b)); } - @Test(dataProvider="sampleDates") + @Test + @UseDataProvider("provider_sampleDates") public void test_equals_false_day_differs(int y, int m, int d, ZoneOffset offset) { OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); OffsetDate b = OffsetDate.of(LocalDate.of(y, m, d + 1), offset); - assertEquals(a.equals(b), false); + assertEquals(false, a.equals(b)); } - @Test(dataProvider="sampleDates") + @Test + @UseDataProvider("provider_sampleDates") public void test_equals_false_offset_differs(int y, int m, int d, ZoneOffset ignored) { OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), OFFSET_PONE); OffsetDate b = OffsetDate.of(LocalDate.of(y, m, d), OFFSET_PTWO); - assertEquals(a.equals(b), false); + assertEquals(false, a.equals(b)); } @Test public void test_equals_itself_true() { - assertEquals(TEST_2007_07_15_PONE.equals(TEST_2007_07_15_PONE), true); + assertEquals(true, TEST_2007_07_15_PONE.equals(TEST_2007_07_15_PONE)); } @Test public void test_equals_string_false() { - assertEquals(TEST_2007_07_15_PONE.equals("2007-07-15"), false); + assertEquals(false, TEST_2007_07_15_PONE.equals("2007-07-15")); } //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider(name="sampleToString") - Object[][] provider_sampleToString() { + @DataProvider + public static Object[][] provider_sampleToString() { return new Object[][] { {2008, 7, 5, "Z", "2008-07-05Z"}, {2008, 7, 5, "+00", "2008-07-05Z"}, @@ -1857,11 +1885,12 @@ Object[][] provider_sampleToString() { }; } - @Test(dataProvider="sampleToString") + @Test + @UseDataProvider("provider_sampleToString") public void test_toString(int y, int m, int d, String offsetId, String expected) { OffsetDate t = OffsetDate.of(LocalDate.of(y, m, d), ZoneOffset.of(offsetId)); String str = t.toString(); - assertEquals(str, expected); + assertEquals(expected, str); } //----------------------------------------------------------------------- @@ -1869,12 +1898,12 @@ public void test_toString(int y, int m, int d, String offsetId, String expected) //----------------------------------------------------------------------- @Test public void test_toString_formatter() { - DateTimeFormatter f = DateTimeFormatters.pattern("y M d"); + DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d"); String t = OffsetDate.of(LocalDate.of(2010, 12, 3), OFFSET_PONE).toString(f); - assertEquals(t, "2010 12 3"); + assertEquals("2010 12 3", t); } - @Test(expectedExceptions=NullPointerException.class) + @Test(expected=NullPointerException.class) public void test_toString_formatter_null() { OffsetDate.of(LocalDate.of(2010, 12, 3), OFFSET_PONE).toString(null); } From 1c89f6c06c5c5c96382c9a555a0dd714c3087ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 3 Apr 2019 18:47:00 +0200 Subject: [PATCH 145/279] Remove custom serialization testing --- .../threeten/extra/AbstractDateTimeTest.java | 2 +- .../java/org/threeten/extra/AbstractTest.java | 211 ------------------ .../org/threeten/extra/TestOffsetDate.java | 14 -- 3 files changed, 1 insertion(+), 226 deletions(-) delete mode 100644 src/test/java/org/threeten/extra/AbstractTest.java diff --git a/src/test/java/org/threeten/extra/AbstractDateTimeTest.java b/src/test/java/org/threeten/extra/AbstractDateTimeTest.java index 8dfa03e9..28457baf 100644 --- a/src/test/java/org/threeten/extra/AbstractDateTimeTest.java +++ b/src/test/java/org/threeten/extra/AbstractDateTimeTest.java @@ -45,7 +45,7 @@ /** * Base test class for {@code DateTime}. */ -public abstract class AbstractDateTimeTest extends AbstractTest { +public abstract class AbstractDateTimeTest { /** * Sample {@code DateTime} objects. diff --git a/src/test/java/org/threeten/extra/AbstractTest.java b/src/test/java/org/threeten/extra/AbstractTest.java deleted file mode 100644 index d7426e14..00000000 --- a/src/test/java/org/threeten/extra/AbstractTest.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * * Neither the name of JSR-310 nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.threeten.extra; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.ObjectStreamConstants; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; - -/** - * Base test class. - */ -public abstract class AbstractTest { - - private static final String SERIALISATION_DATA_FOLDER = "src/test/resources/"; - - protected static boolean isIsoLeap(long year) { - if (year % 4 != 0) { - return false; - } - if (year % 100 == 0 && year % 400 != 0) { - return false; - } - return true; - } - - protected static void assertSerializable(Object o) throws IOException, ClassNotFoundException { - Object deserialisedObject = writeThenRead(o); - assertEquals(o, deserialisedObject); - } - - protected static void assertSerializableAndSame(Object o) throws IOException, ClassNotFoundException { - Object deserialisedObject = writeThenRead(o); - assertSame(o, deserialisedObject); - } - - protected static Object writeThenRead(Object o) throws IOException, ClassNotFoundException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = null; - try { - oos = new ObjectOutputStream(baos); - oos.writeObject(o); - } finally { - if (oos != null) { - oos.close(); - } - } - - ObjectInputStream ois = null; - try { - ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); - return ois.readObject(); - } finally { - if (ois != null) { - ois.close(); - } - } - } - - protected static void assertEqualsSerialisedForm(Object objectSerialised) throws IOException, ClassNotFoundException { - assertEqualsSerialisedForm(objectSerialised.getClass(), objectSerialised); - } - - protected static void assertEqualsSerialisedForm(Class cls, Object objectSerialised) throws IOException, ClassNotFoundException { - String className = cls.getSimpleName(); -// try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(SERIALISATION_DATA_FOLDER + className + ".bin"))) { -// out.writeObject(objectSerialised); -// } - - ObjectInputStream in = null; - try { - in = new ObjectInputStream(new FileInputStream(SERIALISATION_DATA_FOLDER + className + ".bin")); - Object objectFromFile = in.readObject(); - assertEquals(objectSerialised, objectFromFile); - } finally { - if (in != null) { - in.close(); - } - } - } - - protected static void assertImmutable(Class cls) { - assertTrue(Modifier.isPublic(cls.getModifiers())); - assertTrue(Modifier.isFinal(cls.getModifiers())); - Field[] fields = cls.getDeclaredFields(); - for (Field field : fields) { - if (field.getName().contains("$") == false) { - if (Modifier.isStatic(field.getModifiers())) { - assertTrue("Field:" + field.getName(), Modifier.isFinal(field.getModifiers())); - } else { - assertTrue("Field:" + field.getName(), Modifier.isPrivate(field.getModifiers())); - assertTrue("Field:" + field.getName(), Modifier.isFinal(field.getModifiers())); - } - } - } - Constructor[] cons = cls.getDeclaredConstructors(); - for (Constructor con : cons) { - assertTrue(Modifier.isPrivate(con.getModifiers())); - } - } - - protected static void assertSerializedBySer(byte[] expectedBytes, Object object, byte[]... matches) throws Exception { - String serClass = object.getClass().getPackage().getName() + ".Ser"; - Class serCls = Class.forName(serClass); - Field field = serCls.getDeclaredField("serialVersionUID"); - field.setAccessible(true); - long serVer = (Long) field.get(null); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = null; - try { - oos = new ObjectOutputStream(baos); - oos.writeObject(object); - } finally { - if (oos != null) { - oos.close(); - } - } - byte[] bytes = baos.toByteArray(); - ByteArrayInputStream bais = new ByteArrayInputStream(bytes); - DataInputStream dis = null; - try { - dis = new DataInputStream(bais); - assertEquals(ObjectStreamConstants.STREAM_MAGIC, dis.readShort()); - assertEquals(ObjectStreamConstants.STREAM_VERSION, dis.readShort()); - assertEquals(ObjectStreamConstants.TC_OBJECT, dis.readByte()); - assertEquals(ObjectStreamConstants.TC_CLASSDESC, dis.readByte()); - assertEquals(serClass, dis.readUTF()); - assertEquals(serVer, dis.readLong()); - assertEquals(ObjectStreamConstants.SC_EXTERNALIZABLE | ObjectStreamConstants.SC_BLOCK_DATA, dis.readByte()); - assertEquals(0, dis.readShort()); // number of fields - assertEquals(ObjectStreamConstants.TC_ENDBLOCKDATA, dis.readByte()); // end of classdesc - assertEquals(ObjectStreamConstants.TC_NULL, dis.readByte()); // no superclasses - if (expectedBytes.length < 256) { - assertEquals(ObjectStreamConstants.TC_BLOCKDATA, dis.readByte()); - assertEquals(expectedBytes.length, dis.readUnsignedByte()); - } else { - assertEquals(ObjectStreamConstants.TC_BLOCKDATALONG, dis.readByte()); - assertEquals(expectedBytes.length, dis.readInt()); - } - byte[] input = new byte[expectedBytes.length]; - dis.readFully(input); - assertEquals(expectedBytes, input); - if (matches.length > 0) { - for (byte[] match : matches) { - boolean matched = false; - while (matched == false) { - try { - dis.mark(1000); - byte[] possible = new byte[match.length]; - dis.readFully(possible); - assertEquals(match, possible); - matched = true; - } catch (AssertionError ex) { - dis.reset(); - dis.readByte(); // ignore - } - } - } - } else { - assertEquals(ObjectStreamConstants.TC_ENDBLOCKDATA, dis.readByte()); // end of blockdata - assertEquals(-1, dis.read()); - } - } finally { - if (dis != null) { - dis.close(); - } - } - } - -} - diff --git a/src/test/java/org/threeten/extra/TestOffsetDate.java b/src/test/java/org/threeten/extra/TestOffsetDate.java index 390c3c30..72ae3651 100644 --- a/src/test/java/org/threeten/extra/TestOffsetDate.java +++ b/src/test/java/org/threeten/extra/TestOffsetDate.java @@ -49,7 +49,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.time.Clock; @@ -142,19 +141,6 @@ protected List invalidFields() { return list; } - //----------------------------------------------------------------------- - @Test - public void test_serialization() throws ClassNotFoundException, IOException { - assertSerializable(TEST_2007_07_15_PONE); - assertSerializable(OffsetDate.MIN); - assertSerializable(OffsetDate.MAX); - } - - @Test - public void test_serialization_format() throws ClassNotFoundException, IOException { - assertEqualsSerialisedForm(OffsetDate.of(LocalDate.of(2012, 9, 16), ZoneOffset.of("+01:00"))); - } - //----------------------------------------------------------------------- // constants //----------------------------------------------------------------------- From 014b27630d8e749f0993a16bcca4cd755cb92ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 3 Apr 2019 22:41:52 +0200 Subject: [PATCH 146/279] Add Joda-Convert annotations to OffsetDate --- src/main/java/org/threeten/extra/OffsetDate.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/org/threeten/extra/OffsetDate.java b/src/main/java/org/threeten/extra/OffsetDate.java index 2e79f1f9..fed2ddf3 100644 --- a/src/main/java/org/threeten/extra/OffsetDate.java +++ b/src/main/java/org/threeten/extra/OffsetDate.java @@ -66,6 +66,9 @@ import java.time.zone.ZoneRules; import java.util.Objects; +import org.joda.convert.FromString; +import org.joda.convert.ToString; + /** * A date with an offset from UTC/Greenwich in the ISO-8601 calendar system, * such as {@code 2007-12-03+01:00}. @@ -248,6 +251,7 @@ public static OffsetDate from(TemporalAccessor temporal) { * @return the parsed offset date, not null * @throws DateTimeParseException if the text cannot be parsed */ + @FromString public static OffsetDate parse(CharSequence text) { return parse(text, DateTimeFormatter.ISO_OFFSET_DATE); } @@ -1311,6 +1315,7 @@ public int hashCode() { * @return a string representation of this date, not null */ @Override + @ToString public String toString() { return date.toString() + offset.toString(); } From 7f3a6f34e0cfe738a8895434fef318859828874d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 3 Apr 2019 22:55:38 +0200 Subject: [PATCH 147/279] Simplify TestOffsetDate and AbstractDateTimeTest Favors assertTrue(...) over assertEquals(true, ...) etc. Replaces two anonymous classes with lambdas --- .../threeten/extra/AbstractDateTimeTest.java | 16 +- .../org/threeten/extra/TestOffsetDate.java | 143 +++++++++--------- 2 files changed, 76 insertions(+), 83 deletions(-) diff --git a/src/test/java/org/threeten/extra/AbstractDateTimeTest.java b/src/test/java/org/threeten/extra/AbstractDateTimeTest.java index 28457baf..1317561a 100644 --- a/src/test/java/org/threeten/extra/AbstractDateTimeTest.java +++ b/src/test/java/org/threeten/extra/AbstractDateTimeTest.java @@ -32,12 +32,13 @@ package org.threeten.extra; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.time.DateTimeException; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalField; -import java.time.temporal.TemporalQuery; import java.util.List; import org.junit.Test; @@ -72,7 +73,7 @@ public abstract class AbstractDateTimeTest { public void basicTest_isSupported_DateTimeField_supported() { for (TemporalAccessor sample : samples()) { for (TemporalField field : validFields()) { - assertEquals("Failed on " + sample + " " + field, true, sample.isSupported(field)); + assertTrue("Failed on " + sample + " " + field, sample.isSupported(field)); } } } @@ -81,7 +82,7 @@ public void basicTest_isSupported_DateTimeField_supported() { public void basicTest_isSupported_DateTimeField_unsupported() { for (TemporalAccessor sample : samples()) { for (TemporalField field : invalidFields()) { - assertEquals("Failed on " + sample + " " + field, false, sample.isSupported(field)); + assertFalse("Failed on " + sample + " " + field, sample.isSupported(field)); } } } @@ -89,7 +90,7 @@ public void basicTest_isSupported_DateTimeField_unsupported() { @Test public void basicTest_isSupported_DateTimeField_null() { for (TemporalAccessor sample : samples()) { - assertEquals("Failed on " + sample, false, sample.isSupported(null)); + assertFalse("Failed on " + sample, sample.isSupported(null)); } } @@ -223,12 +224,7 @@ public void basicTest_getLong_DateTimeField_null() { @Test public void basicTest_query() { for (TemporalAccessor sample : samples()) { - assertEquals("foo", sample.query(new TemporalQuery() { - @Override - public String queryFrom(TemporalAccessor dateTime) { - return "foo"; - } - })); + assertEquals("foo", sample.query(dateTime -> "foo")); } } diff --git a/src/test/java/org/threeten/extra/TestOffsetDate.java b/src/test/java/org/threeten/extra/TestOffsetDate.java index 72ae3651..3d9ee0ad 100644 --- a/src/test/java/org/threeten/extra/TestOffsetDate.java +++ b/src/test/java/org/threeten/extra/TestOffsetDate.java @@ -47,7 +47,10 @@ import static java.time.temporal.ChronoField.YEAR; import static java.time.temporal.ChronoField.YEAR_OF_ERA; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; @@ -70,7 +73,6 @@ import java.time.temporal.ChronoField; import java.time.temporal.ChronoUnit; import java.time.temporal.JulianFields; -import java.time.temporal.Temporal; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjuster; import java.time.temporal.TemporalAmount; @@ -526,8 +528,8 @@ public void test_query_chrono() { @Test public void test_query_zoneId() { - assertEquals(null, TEST_2007_07_15_PONE.query(TemporalQueries.zoneId())); - assertEquals(null, TemporalQueries.zoneId().queryFrom(TEST_2007_07_15_PONE)); + assertNull(TEST_2007_07_15_PONE.query(TemporalQueries.zoneId())); + assertNull(TemporalQueries.zoneId().queryFrom(TEST_2007_07_15_PONE)); } @Test @@ -582,12 +584,7 @@ public void test_withOffset_null() { @Test public void test_with_adjustment() { final OffsetDate sample = OffsetDate.of(LocalDate.of(2012, 3, 4), OFFSET_PONE); - TemporalAdjuster adjuster = new TemporalAdjuster() { - @Override - public Temporal adjustInto(Temporal dateTime) { - return sample; - } - }; + TemporalAdjuster adjuster = dateTime -> sample; assertEquals(sample, TEST_2007_07_15_PONE.with(adjuster)); } @@ -1647,44 +1644,44 @@ public void test_getDate(int year, int month, int day, ZoneOffset offset) { public void test_compareTo_date() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 29), OFFSET_PONE); OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b due to date - assertEquals(true, a.compareTo(b) < 0); - assertEquals(true, b.compareTo(a) > 0); - assertEquals(true, a.compareTo(a) == 0); - assertEquals(true, b.compareTo(b) == 0); - assertEquals(true, a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0); + assertTrue(a.compareTo(b) < 0); + assertTrue(b.compareTo(a) > 0); + assertTrue(a.compareTo(a) == 0); + assertTrue(b.compareTo(b) == 0); + assertTrue(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0); } @Test public void test_compareTo_offset() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO); OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b due to offset - assertEquals(true, a.compareTo(b) < 0); - assertEquals(true, b.compareTo(a) > 0); - assertEquals(true, a.compareTo(a) == 0); - assertEquals(true, b.compareTo(b) == 0); - assertEquals(true, a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0); + assertTrue(a.compareTo(b) < 0); + assertTrue(b.compareTo(a) > 0); + assertTrue(a.compareTo(a) == 0); + assertTrue(b.compareTo(b) == 0); + assertTrue(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0); } @Test public void test_compareTo_both() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 29), OFFSET_PTWO); OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b on instant scale - assertEquals(true, a.compareTo(b) < 0); - assertEquals(true, b.compareTo(a) > 0); - assertEquals(true, a.compareTo(a) == 0); - assertEquals(true, b.compareTo(b) == 0); - assertEquals(true, a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0); + assertTrue(a.compareTo(b) < 0); + assertTrue(b.compareTo(a) > 0); + assertTrue(a.compareTo(a) == 0); + assertTrue(b.compareTo(b) == 0); + assertTrue(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) < 0); } @Test public void test_compareTo_24hourDifference() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 29), ZoneOffset.ofHours(-12)); OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), ZoneOffset.ofHours(12)); // a is before b despite being same time-line time - assertEquals(true, a.compareTo(b) < 0); - assertEquals(true, b.compareTo(a) > 0); - assertEquals(true, a.compareTo(a) == 0); - assertEquals(true, b.compareTo(b) == 0); - assertEquals(true, a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) == 0); + assertTrue(a.compareTo(b) < 0); + assertTrue(b.compareTo(a) > 0); + assertTrue(a.compareTo(a) == 0); + assertTrue(b.compareTo(b) == 0); + assertTrue(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) == 0); } @Test(expected=NullPointerException.class) @@ -1707,66 +1704,66 @@ public void compareToNonOffsetDate() { public void test_isBeforeIsAfterIsEqual1() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 29), OFFSET_PONE); OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b due to time - assertEquals(true, a.isBefore(b)); - assertEquals(false, a.isEqual(b)); - assertEquals(false, a.isAfter(b)); + assertTrue(a.isBefore(b)); + assertFalse(a.isEqual(b)); + assertFalse(a.isAfter(b)); - assertEquals(false, b.isBefore(a)); - assertEquals(false, b.isEqual(a)); - assertEquals(true, b.isAfter(a)); + assertFalse(b.isBefore(a)); + assertFalse(b.isEqual(a)); + assertTrue(b.isAfter(a)); - assertEquals(false, a.isBefore(a)); - assertEquals(false, b.isBefore(b)); + assertFalse(a.isBefore(a)); + assertFalse(b.isBefore(b)); - assertEquals(true, a.isEqual(a)); - assertEquals(true, b.isEqual(b)); + assertTrue(a.isEqual(a)); + assertTrue(b.isEqual(b)); - assertEquals(false, a.isAfter(a)); - assertEquals(false, b.isAfter(b)); + assertFalse(a.isAfter(a)); + assertFalse(b.isAfter(b)); } @Test public void test_isBeforeIsAfterIsEqual2() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO); OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b due to offset - assertEquals(true, a.isBefore(b)); - assertEquals(false, a.isEqual(b)); - assertEquals(false, a.isAfter(b)); + assertTrue(a.isBefore(b)); + assertFalse(a.isEqual(b)); + assertFalse(a.isAfter(b)); - assertEquals(false, b.isBefore(a)); - assertEquals(false, b.isEqual(a)); - assertEquals(true, b.isAfter(a)); + assertFalse(b.isBefore(a)); + assertFalse(b.isEqual(a)); + assertTrue(b.isAfter(a)); - assertEquals(false, a.isBefore(a)); - assertEquals(false, b.isBefore(b)); + assertFalse(a.isBefore(a)); + assertFalse(b.isBefore(b)); - assertEquals(true, a.isEqual(a)); - assertEquals(true, b.isEqual(b)); + assertTrue(a.isEqual(a)); + assertTrue(b.isEqual(b)); - assertEquals(false, a.isAfter(a)); - assertEquals(false, b.isAfter(b)); + assertFalse(a.isAfter(a)); + assertFalse(b.isAfter(b)); } @Test public void test_isBeforeIsAfterIsEqual_instantComparison() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), ZoneOffset.ofHours(12)); OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 29), ZoneOffset.ofHours(-12)); // a is same instant as b - assertEquals(false, a.isBefore(b)); - assertEquals(true, a.isEqual(b)); - assertEquals(false, a.isAfter(b)); + assertFalse(a.isBefore(b)); + assertTrue(a.isEqual(b)); + assertFalse(a.isAfter(b)); - assertEquals(false, b.isBefore(a)); - assertEquals(true, b.isEqual(a)); - assertEquals(false, b.isAfter(a)); + assertFalse(b.isBefore(a)); + assertTrue(b.isEqual(a)); + assertFalse(b.isAfter(a)); - assertEquals(false, a.isBefore(a)); - assertEquals(false, b.isBefore(b)); + assertFalse(a.isBefore(a)); + assertFalse(b.isBefore(b)); - assertEquals(true, a.isEqual(a)); - assertEquals(true, b.isEqual(b)); + assertTrue(a.isEqual(a)); + assertTrue(b.isEqual(b)); - assertEquals(false, a.isAfter(a)); - assertEquals(false, b.isAfter(b)); + assertFalse(a.isAfter(a)); + assertFalse(b.isAfter(b)); } @Test(expected=NullPointerException.class) @@ -1795,15 +1792,15 @@ public void test_isEqual_null() { public void test_equals_true(int y, int m, int d, ZoneOffset offset) { OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); OffsetDate b = OffsetDate.of(LocalDate.of(y, m, d), offset); - assertEquals(true, a.equals(b)); - assertEquals(true, a.hashCode() == b.hashCode()); + assertTrue(a.equals(b)); + assertTrue(a.hashCode() == b.hashCode()); } @Test @UseDataProvider("provider_sampleDates") public void test_equals_false_year_differs(int y, int m, int d, ZoneOffset offset) { OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); OffsetDate b = OffsetDate.of(LocalDate.of(y + 1, m, d), offset); - assertEquals(false, a.equals(b)); + assertFalse(a.equals(b)); } @Test @@ -1811,7 +1808,7 @@ public void test_equals_false_year_differs(int y, int m, int d, ZoneOffset offse public void test_equals_false_month_differs(int y, int m, int d, ZoneOffset offset) { OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); OffsetDate b = OffsetDate.of(LocalDate.of(y, m + 1, d), offset); - assertEquals(false, a.equals(b)); + assertFalse(a.equals(b)); } @Test @@ -1819,7 +1816,7 @@ public void test_equals_false_month_differs(int y, int m, int d, ZoneOffset offs public void test_equals_false_day_differs(int y, int m, int d, ZoneOffset offset) { OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); OffsetDate b = OffsetDate.of(LocalDate.of(y, m, d + 1), offset); - assertEquals(false, a.equals(b)); + assertFalse(a.equals(b)); } @Test @@ -1827,17 +1824,17 @@ public void test_equals_false_day_differs(int y, int m, int d, ZoneOffset offset public void test_equals_false_offset_differs(int y, int m, int d, ZoneOffset ignored) { OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), OFFSET_PONE); OffsetDate b = OffsetDate.of(LocalDate.of(y, m, d), OFFSET_PTWO); - assertEquals(false, a.equals(b)); + assertFalse(a.equals(b)); } @Test public void test_equals_itself_true() { - assertEquals(true, TEST_2007_07_15_PONE.equals(TEST_2007_07_15_PONE)); + assertTrue(TEST_2007_07_15_PONE.equals(TEST_2007_07_15_PONE)); } @Test public void test_equals_string_false() { - assertEquals(false, TEST_2007_07_15_PONE.equals("2007-07-15")); + assertFalse(TEST_2007_07_15_PONE.equals("2007-07-15")); } //----------------------------------------------------------------------- From 674e80a8acc396be394e5a17cc342d3fed96b4c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 7 Apr 2019 11:38:41 +0200 Subject: [PATCH 148/279] Update OffsetDate related license header --- src/main/java/org/threeten/extra/OffsetDate.java | 2 +- src/test/java/org/threeten/extra/TestOffsetDate.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/threeten/extra/OffsetDate.java b/src/main/java/org/threeten/extra/OffsetDate.java index fed2ddf3..8fd887d1 100644 --- a/src/main/java/org/threeten/extra/OffsetDate.java +++ b/src/main/java/org/threeten/extra/OffsetDate.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007-2013, Stephen Colebourne & Michael Nascimento Santos + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos * * All rights reserved. * diff --git a/src/test/java/org/threeten/extra/TestOffsetDate.java b/src/test/java/org/threeten/extra/TestOffsetDate.java index 3d9ee0ad..4a83398e 100644 --- a/src/test/java/org/threeten/extra/TestOffsetDate.java +++ b/src/test/java/org/threeten/extra/TestOffsetDate.java @@ -1,5 +1,5 @@ /* -9 * Copyright (c) 2007-2013, Stephen Colebourne & Michael Nascimento Santos + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos * * All rights reserved. * From e9551e78cbfbcfe2b39c0627484579995b239832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 7 Apr 2019 11:39:05 +0200 Subject: [PATCH 149/279] Add mwkroening as contributor --- pom.xml | 4 ++++ src/changes/changes.xml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/pom.xml b/pom.xml index 50a18008..358bc5ec 100644 --- a/pom.xml +++ b/pom.xml @@ -74,6 +74,10 @@ Bruno P. Kinoshita https://github.com/kinow + + Martin Kröning + https://github.com/mwkroening + Sebastian Lövdahl https://github.com/slovdahl diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 4ed5e587..0667cb5e 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -8,6 +8,10 @@ + + Add OffsetDate. + Fixes #137. + Add Farsi translations for word-based formatting. Fixes #131. From b8cb4c0a46640bf2310c2a218cf1f470e2016001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 7 Apr 2019 12:01:50 +0200 Subject: [PATCH 150/279] Resolve TODOs in AbstractDateTimeTest --- .../threeten/extra/AbstractDateTimeTest.java | 69 +++++++++---------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/src/test/java/org/threeten/extra/AbstractDateTimeTest.java b/src/test/java/org/threeten/extra/AbstractDateTimeTest.java index 1317561a..af8cd3cc 100644 --- a/src/test/java/org/threeten/extra/AbstractDateTimeTest.java +++ b/src/test/java/org/threeten/extra/AbstractDateTimeTest.java @@ -97,15 +97,14 @@ public void basicTest_isSupported_DateTimeField_null() { //----------------------------------------------------------------------- // range(DateTimeField) //----------------------------------------------------------------------- -// TODO needs implementations of week fields -// @Test -// public void basicTest_range_DateTimeField_supported() { -// for (DateTimeAccessor sample : samples()) { -// for (DateTimeField field : validFields()) { -// sample.range(field); // no exception -// } -// } -// } + @Test + public void basicTest_range_DateTimeField_supported() { + for (TemporalAccessor sample : samples()) { + for (TemporalField field : validFields()) { + sample.range(field); // no exception + } + } + } @Test public void basicTest_range_DateTimeField_unsupported() { @@ -136,24 +135,23 @@ public void basicTest_range_DateTimeField_null() { //----------------------------------------------------------------------- // get(DateTimeField) //----------------------------------------------------------------------- -// TODO needs implementations of week fields -// @Test -// public void basicTest_get_DateTimeField_supported() { -// for (DateTimeAccessor sample : samples()) { -// for (DateTimeField field : validFields()) { -// if (sample.range(field).isIntValue()) { -// sample.get(field); // no exception -// } else { -// try { -// sample.get(field); -// fail("Failed on " + sample + " " + field); -// } catch (DateTimeException ex) { -// // expected -// } -// } -// } -// } -// } + @Test + public void basicTest_get_DateTimeField_supported() { + for (TemporalAccessor sample : samples()) { + for (TemporalField field : validFields()) { + if (sample.range(field).isIntValue()) { + sample.get(field); // no exception + } else { + try { + sample.get(field); + fail("Failed on " + sample + " " + field); + } catch (DateTimeException ex) { + // expected + } + } + } + } + } @Test public void basicTest_get_DateTimeField_unsupported() { @@ -184,15 +182,14 @@ public void basicTest_get_DateTimeField_null() { //----------------------------------------------------------------------- // getLong(DateTimeField) //----------------------------------------------------------------------- -// TODO needs implementations of week fields -// @Test -// public void basicTest_getLong_DateTimeField_supported() { -// for (DateTimeAccessor sample : samples()) { -// for (DateTimeField field : validFields()) { -// sample.getLong(field); // no exception -// } -// } -// } + @Test + public void basicTest_getLong_DateTimeField_supported() { + for (TemporalAccessor sample : samples()) { + for (TemporalField field : validFields()) { + sample.getLong(field); // no exception + } + } + } @Test public void basicTest_getLong_DateTimeField_unsupported() { From 70e87a6e6af50b16e02693b6d50e180e85f8e0cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 7 Apr 2019 12:23:21 +0200 Subject: [PATCH 151/279] Use public API for MIN and MAX instance of OffsetDate --- src/main/java/org/threeten/extra/OffsetDate.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/threeten/extra/OffsetDate.java b/src/main/java/org/threeten/extra/OffsetDate.java index 8fd887d1..515c5807 100644 --- a/src/main/java/org/threeten/extra/OffsetDate.java +++ b/src/main/java/org/threeten/extra/OffsetDate.java @@ -94,7 +94,7 @@ public final class OffsetDate * This combines {@link LocalDate#MIN} and {@link ZoneOffset#MAX}. * This could be used by an application as a "far past" date. */ - public static final OffsetDate MIN = new OffsetDate(LocalDate.MIN, ZoneOffset.MAX); + public static final OffsetDate MIN = OffsetDate.of(LocalDate.MIN, ZoneOffset.MAX); /** * The maximum supported {@code OffsetDate}, '+999999999-12-31-18:00'. * This is the maximum local date in the minimum offset @@ -102,7 +102,7 @@ public final class OffsetDate * This combines {@link LocalDate#MAX} and {@link ZoneOffset#MIN}. * This could be used by an application as a "far future" date. */ - public static final OffsetDate MAX = new OffsetDate(LocalDate.MAX, ZoneOffset.MIN); + public static final OffsetDate MAX = OffsetDate.of(LocalDate.MAX, ZoneOffset.MIN); /** * Serialization version. From a60f7bfae775d19bb1c976c5f0a11d2a5e12d2e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 7 Apr 2019 12:39:34 +0200 Subject: [PATCH 152/279] Rename OffsetDate#toString(DateTimeFormatter) to format(DateTimeFormatter) --- .../java/org/threeten/extra/OffsetDate.java | 29 +++++++++--------- .../org/threeten/extra/TestOffsetDate.java | 30 +++++++++---------- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/main/java/org/threeten/extra/OffsetDate.java b/src/main/java/org/threeten/extra/OffsetDate.java index 515c5807..741e518d 100644 --- a/src/main/java/org/threeten/extra/OffsetDate.java +++ b/src/main/java/org/threeten/extra/OffsetDate.java @@ -1159,6 +1159,20 @@ public long until(Temporal endDate, TemporalUnit unit) { return unit.between(this, endDate); } + /** + * Formats this date using the specified formatter. + *

    + * This date-time will be passed to the formatter to produce a string. + * + * @param formatter the formatter to use, not null + * @return the formatted date string, not null + * @throws DateTimeException if an error occurs during printing + */ + public String format(DateTimeFormatter formatter) { + Objects.requireNonNull(formatter, "formatter"); + return formatter.format(this); + } + //----------------------------------------------------------------------- /** * Returns an offset date-time formed from this date at the specified time. @@ -1320,19 +1334,4 @@ public String toString() { return date.toString() + offset.toString(); } - /** - * Outputs this date as a {@code String} using the formatter. - *

    - * This date will be passed to the formatter - * {@link DateTimeFormatter#format(TemporalAccessor) print method}. - * - * @param formatter the formatter to use, not null - * @return the formatted date string, not null - * @throws DateTimeException if an error occurs during printing - */ - public String toString(DateTimeFormatter formatter) { - Objects.requireNonNull(formatter, "formatter"); - return formatter.format(this); - } - } diff --git a/src/test/java/org/threeten/extra/TestOffsetDate.java b/src/test/java/org/threeten/extra/TestOffsetDate.java index 4a83398e..60763f0b 100644 --- a/src/test/java/org/threeten/extra/TestOffsetDate.java +++ b/src/test/java/org/threeten/extra/TestOffsetDate.java @@ -1611,6 +1611,21 @@ public void test_minusDays_overflowTooSmall() { OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusDays(Long.MAX_VALUE); } + //----------------------------------------------------------------------- + // format(DateTimeFormatter) + //----------------------------------------------------------------------- + @Test + public void test_format_formatter() { + DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d"); + String t = OffsetDate.of(LocalDate.of(2010, 12, 3), OFFSET_PONE).format(f); + assertEquals("2010 12 3", t); + } + + @Test(expected=NullPointerException.class) + public void test_format_formatter_null() { + OffsetDate.of(LocalDate.of(2010, 12, 3), OFFSET_PONE).format(null); + } + //----------------------------------------------------------------------- // atTime() //----------------------------------------------------------------------- @@ -1876,19 +1891,4 @@ public void test_toString(int y, int m, int d, String offsetId, String expected) assertEquals(expected, str); } - //----------------------------------------------------------------------- - // toString(DateTimeFormatter) - //----------------------------------------------------------------------- - @Test - public void test_toString_formatter() { - DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d"); - String t = OffsetDate.of(LocalDate.of(2010, 12, 3), OFFSET_PONE).toString(f); - assertEquals("2010 12 3", t); - } - - @Test(expected=NullPointerException.class) - public void test_toString_formatter_null() { - OffsetDate.of(LocalDate.of(2010, 12, 3), OFFSET_PONE).toString(null); - } - } From c6d37e131b6e5a6ad4707a0eafc46f5b54c5e8b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 7 Apr 2019 12:43:05 +0200 Subject: [PATCH 153/279] Rename OffsetDate#getDate() to toLocalDate() --- src/main/java/org/threeten/extra/OffsetDate.java | 10 +++++----- src/test/java/org/threeten/extra/TestOffsetDate.java | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/threeten/extra/OffsetDate.java b/src/main/java/org/threeten/extra/OffsetDate.java index 741e518d..54227af8 100644 --- a/src/main/java/org/threeten/extra/OffsetDate.java +++ b/src/main/java/org/threeten/extra/OffsetDate.java @@ -505,14 +505,14 @@ public OffsetDate withOffset(ZoneOffset offset) { //----------------------------------------------------------------------- /** - * Gets the {@code LocalDate} part of this date-time. + * Gets the {@code LocalDate} part of this date. *

    * This returns a {@code LocalDate} with the same year, month and day - * as this date-time. + * as this date. * - * @return the date part of this date-time, not null + * @return the date part of this date, not null */ - public LocalDate getDate() { + public LocalDate toLocalDate() { return date; } @@ -1095,7 +1095,7 @@ public R query(TemporalQuery query) { public Temporal adjustInto(Temporal temporal) { return temporal .with(OFFSET_SECONDS, getOffset().getTotalSeconds()) - .with(EPOCH_DAY, getDate().toEpochDay()); + .with(EPOCH_DAY, toLocalDate().toEpochDay()); } /** diff --git a/src/test/java/org/threeten/extra/TestOffsetDate.java b/src/test/java/org/threeten/extra/TestOffsetDate.java index 60763f0b..ac2e9fc5 100644 --- a/src/test/java/org/threeten/extra/TestOffsetDate.java +++ b/src/test/java/org/threeten/extra/TestOffsetDate.java @@ -218,7 +218,7 @@ public void now_Clock_nullClock() { // factories //----------------------------------------------------------------------- private void check(OffsetDate test, int y, int mo, int d, ZoneOffset offset) { - assertEquals(LocalDate.of(y, mo, d), test.getDate()); + assertEquals(LocalDate.of(y, mo, d), test.toLocalDate()); assertEquals(offset, test.getOffset()); assertEquals(y, test.getYear()); @@ -480,7 +480,7 @@ public void test_get_OffsetDate(int y, int m, int d, ZoneOffset offset) { LocalDate localDate = LocalDate.of(y, m, d); OffsetDate a = OffsetDate.of(localDate, offset); - assertEquals(localDate, a.getDate()); + assertEquals(localDate, a.toLocalDate()); assertEquals(offset, a.getOffset()); assertEquals(localDate.toString() + offset.toString(), a.toString()); assertEquals(localDate.getYear(), a.getYear()); @@ -562,7 +562,7 @@ public void test_query_null() { public void test_withOffset() { OffsetDate base = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); OffsetDate test = base.withOffset(OFFSET_PTWO); - assertEquals(base.getDate(), test.getDate()); + assertEquals(base.toLocalDate(), test.toLocalDate()); assertEquals(OFFSET_PTWO, test.getOffset()); } @@ -1643,13 +1643,13 @@ public void test_atTime_Local_nullLocalTime() { } //----------------------------------------------------------------------- - // getDate() + // toLocalDate() //----------------------------------------------------------------------- @Test @UseDataProvider("provider_sampleDates") - public void test_getDate(int year, int month, int day, ZoneOffset offset) { + public void test_toLocalDate(int year, int month, int day, ZoneOffset offset) { LocalDate t = LocalDate.of(year, month, day); - assertEquals(t, OffsetDate.of(LocalDate.of(year, month, day), offset).getDate()); + assertEquals(t, OffsetDate.of(LocalDate.of(year, month, day), offset).toLocalDate()); } //----------------------------------------------------------------------- From 3e0949cc2614ee76ef627fe26098cd3e90a20c43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 7 Apr 2019 12:52:54 +0200 Subject: [PATCH 154/279] Implement OffsetDate#from(int, int, int, ZoneOffset) --- .../java/org/threeten/extra/OffsetDate.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/org/threeten/extra/OffsetDate.java b/src/main/java/org/threeten/extra/OffsetDate.java index 54227af8..fa03ef87 100644 --- a/src/main/java/org/threeten/extra/OffsetDate.java +++ b/src/main/java/org/threeten/extra/OffsetDate.java @@ -187,6 +187,31 @@ public static OffsetDate of(LocalDate date, ZoneOffset offset) { return new OffsetDate(date, offset); } + /** + * Obtains an instance of {@code OffsetDate} from a year, month, day + * and offset. + *

    + * This creates an offset date with the four specified fields. + *

    + * This method exists primarily for writing test cases. + * Non test-code will typically use other methods to create an offset time. + * {@code LocalDate} has one additional convenience variant of the + * equivalent factory method taking fewer arguments. + * They are not provided here to reduce the footprint of the API. + * + * @param year the year to represent, from MIN_YEAR to MAX_YEAR + * @param month the month-of-year to represent, from 1 (January) to 12 (December) + * @param dayOfMonth the day-of-month to represent, from 1 to 31 + * @param offset the zone offset, not null + * @return the offset date, not null + * @throws DateTimeException if the value of any field is out of range, or + * if the day-of-month is invalid for the month-year + */ + public static OffsetDate of(int year, int month, int dayOfMonth, ZoneOffset offset) { + LocalDate d = LocalDate.of(year, month, dayOfMonth); + return new OffsetDate(d, offset); + } + //----------------------------------------------------------------------- /** * Obtains an instance of {@code OffsetDate} from an {@code Instant} and zone ID. From b38c7b153b3f1d5f917298af94398bb31fa79f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 7 Apr 2019 13:29:50 +0200 Subject: [PATCH 155/279] Implement OffsetDate#toEpochSecond(LocalTime) --- .../java/org/threeten/extra/OffsetDate.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/org/threeten/extra/OffsetDate.java b/src/main/java/org/threeten/extra/OffsetDate.java index fa03ef87..c479dcdc 100644 --- a/src/main/java/org/threeten/extra/OffsetDate.java +++ b/src/main/java/org/threeten/extra/OffsetDate.java @@ -1226,6 +1226,24 @@ private long toEpochSecond() { return secs - offset.getTotalSeconds(); } + /** + * Converts this {@code OffsetDate} to the number of seconds since the epoch + * of 1970-01-01T00:00:00Z. + *

    + * This combines this offset date with the specified time + * to calculate the epoch-second value, which is the + * number of elapsed seconds from 1970-01-01T00:00:00Z. + * Instants on the time-line after the epoch are positive, earlier + * are negative. + * + * @param time the local time, not null + * @return the number of seconds since the epoch of 1970-01-01T00:00:00Z, may be negative + */ + public long toEpochSecond(LocalTime time) { + Objects.requireNonNull(time, "time"); + return toEpochSecond() + time.toSecondOfDay(); + } + //----------------------------------------------------------------------- /** * Compares this {@code OffsetDate} to another date. From e2222e78f72627c10f61642764e7300efbce00c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 7 Apr 2019 13:34:57 +0200 Subject: [PATCH 156/279] Rename OffsetDate#withOffset(ZoneOffset) to withOffsetSameLocal(ZoneOffset) --- src/main/java/org/threeten/extra/OffsetDate.java | 5 +++-- .../java/org/threeten/extra/TestOffsetDate.java | 14 +++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/threeten/extra/OffsetDate.java b/src/main/java/org/threeten/extra/OffsetDate.java index c479dcdc..0313284c 100644 --- a/src/main/java/org/threeten/extra/OffsetDate.java +++ b/src/main/java/org/threeten/extra/OffsetDate.java @@ -511,7 +511,8 @@ public ZoneOffset getOffset() { } /** - * Returns a copy of this {@code OffsetDate} with the specified offset. + * Returns a copy of this {@code OffsetDate} with the specified offset ensuring + * that the result has the same local date. *

    * This method returns an object with the same {@code LocalDate} and the specified {@code ZoneOffset}. * No calculation is needed or performed. @@ -523,7 +524,7 @@ public ZoneOffset getOffset() { * @param offset the zone offset to change to, not null * @return an {@code OffsetDate} based on this date with the requested offset, not null */ - public OffsetDate withOffset(ZoneOffset offset) { + public OffsetDate withOffsetSameLocal(ZoneOffset offset) { Objects.requireNonNull(offset, "offset"); return with(date, offset); } diff --git a/src/test/java/org/threeten/extra/TestOffsetDate.java b/src/test/java/org/threeten/extra/TestOffsetDate.java index ac2e9fc5..3369ea0c 100644 --- a/src/test/java/org/threeten/extra/TestOffsetDate.java +++ b/src/test/java/org/threeten/extra/TestOffsetDate.java @@ -556,26 +556,26 @@ public void test_query_null() { } //----------------------------------------------------------------------- - // withOffset() + // withOffsetSameLocal() //----------------------------------------------------------------------- @Test - public void test_withOffset() { + public void test_withOffsetSameLocal() { OffsetDate base = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); - OffsetDate test = base.withOffset(OFFSET_PTWO); + OffsetDate test = base.withOffsetSameLocal(OFFSET_PTWO); assertEquals(base.toLocalDate(), test.toLocalDate()); assertEquals(OFFSET_PTWO, test.getOffset()); } @Test - public void test_withOffset_noChange() { + public void test_withOffsetSameLocal_noChange() { OffsetDate base = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); - OffsetDate test = base.withOffset(OFFSET_PONE); + OffsetDate test = base.withOffsetSameLocal(OFFSET_PONE); assertEquals(base, test); } @Test(expected=NullPointerException.class) - public void test_withOffset_null() { - TEST_2007_07_15_PONE.withOffset(null); + public void test_withOffsetSameLocal_null() { + TEST_2007_07_15_PONE.withOffsetSameLocal(null); } //----------------------------------------------------------------------- From 18babfd052f553c287df058468a2a46075a328f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 7 Apr 2019 13:55:18 +0200 Subject: [PATCH 157/279] Rename TestOffsetDate DataProviders from provider_* to data_* --- .../org/threeten/extra/TestOffsetDate.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/test/java/org/threeten/extra/TestOffsetDate.java b/src/test/java/org/threeten/extra/TestOffsetDate.java index 3369ea0c..067544b0 100644 --- a/src/test/java/org/threeten/extra/TestOffsetDate.java +++ b/src/test/java/org/threeten/extra/TestOffsetDate.java @@ -359,7 +359,7 @@ public void test_from_TemporalAccessor_null() { // parse() //----------------------------------------------------------------------- @Test - @UseDataProvider("provider_sampleToString") + @UseDataProvider("data_sampleToString") public void factory_parse_validText(int y, int m, int d, String offsetId, String parsable) { OffsetDate t = OffsetDate.parse(parsable); assertNotNull(parsable, t); @@ -370,7 +370,7 @@ public void factory_parse_validText(int y, int m, int d, String offsetId, String } @DataProvider - public static Object[][] provider_sampleBadParse() { + public static Object[][] data_sampleBadParse() { return new Object[][]{ {"2008/07/05"}, {"10000-01-01"}, @@ -392,7 +392,7 @@ public static Object[][] provider_sampleBadParse() { } @Test(expected=DateTimeParseException.class) - @UseDataProvider("provider_sampleBadParse") + @UseDataProvider("data_sampleBadParse") public void factory_parse_invalidText(String unparsable) { OffsetDate.parse(unparsable); } @@ -462,7 +462,7 @@ public void constructor_nullOffset() throws Throwable { // basics //----------------------------------------------------------------------- @DataProvider - public static Object[][] provider_sampleDates() { + public static Object[][] data_sampleDates() { return new Object[][] { {2008, 7, 5, OFFSET_PTWO}, {2007, 7, 5, OFFSET_PONE}, @@ -475,7 +475,7 @@ public static Object[][] provider_sampleDates() { } @Test - @UseDataProvider("provider_sampleDates") + @UseDataProvider("data_sampleDates") public void test_get_OffsetDate(int y, int m, int d, ZoneOffset offset) { LocalDate localDate = LocalDate.of(y, m, d); OffsetDate a = OffsetDate.of(localDate, offset); @@ -932,7 +932,7 @@ public void test_plusMonths_long_invalidTooSmall() { // plusWeeks() //----------------------------------------------------------------------- @DataProvider - public static Object[][] provider_samplePlusWeeksSymmetry() { + public static Object[][] data_samplePlusWeeksSymmetry() { return new Object[][] { {OffsetDate.of(LocalDate.of(-1, 1, 1), OFFSET_PONE)}, {OffsetDate.of(LocalDate.of(-1, 2, 28), OFFSET_PTWO)}, @@ -964,7 +964,7 @@ public static Object[][] provider_samplePlusWeeksSymmetry() { } @Test - @UseDataProvider("provider_samplePlusWeeksSymmetry") + @UseDataProvider("data_samplePlusWeeksSymmetry") public void test_plusWeeks_symmetry(OffsetDate reference) { for (int weeks = 0; weeks < 365 * 8; weeks++) { OffsetDate t = reference.plusWeeks(weeks).plusWeeks(-weeks); @@ -1061,7 +1061,7 @@ public void test_plusWeeks_invalidMaxMinusMin() { // plusDays() //----------------------------------------------------------------------- @DataProvider - public static Object[][] provider_samplePlusDaysSymmetry() { + public static Object[][] data_samplePlusDaysSymmetry() { return new Object[][] { {OffsetDate.of(LocalDate.of(-1, 1, 1), OFFSET_PONE)}, {OffsetDate.of(LocalDate.of(-1, 2, 28), OFFSET_PTWO)}, @@ -1093,7 +1093,7 @@ public static Object[][] provider_samplePlusDaysSymmetry() { } @Test - @UseDataProvider("provider_samplePlusDaysSymmetry") + @UseDataProvider("data_samplePlusDaysSymmetry") public void test_plusDays_symmetry(OffsetDate reference) { for (int days = 0; days < 365 * 8; days++) { OffsetDate t = reference.plusDays(days).plusDays(-days); @@ -1357,7 +1357,7 @@ public void test_minusMonths_long_invalidTooSmall() { // minusWeeks() //----------------------------------------------------------------------- @DataProvider - public static Object[][] provider_sampleMinusWeeksSymmetry() { + public static Object[][] data_sampleMinusWeeksSymmetry() { return new Object[][] { {OffsetDate.of(LocalDate.of(-1, 1, 1), OFFSET_PONE)}, {OffsetDate.of(LocalDate.of(-1, 2, 28), OFFSET_PTWO)}, @@ -1389,7 +1389,7 @@ public static Object[][] provider_sampleMinusWeeksSymmetry() { } @Test - @UseDataProvider("provider_sampleMinusWeeksSymmetry") + @UseDataProvider("data_sampleMinusWeeksSymmetry") public void test_minusWeeks_symmetry(OffsetDate reference) { for (int weeks = 0; weeks < 365 * 8; weeks++) { OffsetDate t = reference.minusWeeks(weeks).minusWeeks(-weeks); @@ -1486,7 +1486,7 @@ public void test_minusWeeks_invalidMaxMinusMin() { // minusDays() //----------------------------------------------------------------------- @DataProvider - public static Object[][] provider_sampleMinusDaysSymmetry() { + public static Object[][] data_sampleMinusDaysSymmetry() { return new Object[][] { {OffsetDate.of(LocalDate.of(-1, 1, 1), OFFSET_PONE)}, {OffsetDate.of(LocalDate.of(-1, 2, 28), OFFSET_PTWO)}, @@ -1518,7 +1518,7 @@ public static Object[][] provider_sampleMinusDaysSymmetry() { } @Test - @UseDataProvider("provider_sampleMinusDaysSymmetry") + @UseDataProvider("data_sampleMinusDaysSymmetry") public void test_minusDays_symmetry(OffsetDate reference) { for (int days = 0; days < 365 * 8; days++) { OffsetDate t = reference.minusDays(days).minusDays(-days); @@ -1646,7 +1646,7 @@ public void test_atTime_Local_nullLocalTime() { // toLocalDate() //----------------------------------------------------------------------- @Test - @UseDataProvider("provider_sampleDates") + @UseDataProvider("data_sampleDates") public void test_toLocalDate(int year, int month, int day, ZoneOffset offset) { LocalDate t = LocalDate.of(year, month, day); assertEquals(t, OffsetDate.of(LocalDate.of(year, month, day), offset).toLocalDate()); @@ -1803,7 +1803,7 @@ public void test_isEqual_null() { // equals() / hashCode() //----------------------------------------------------------------------- @Test - @UseDataProvider("provider_sampleDates") + @UseDataProvider("data_sampleDates") public void test_equals_true(int y, int m, int d, ZoneOffset offset) { OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); OffsetDate b = OffsetDate.of(LocalDate.of(y, m, d), offset); @@ -1811,7 +1811,7 @@ public void test_equals_true(int y, int m, int d, ZoneOffset offset) { assertTrue(a.hashCode() == b.hashCode()); } @Test - @UseDataProvider("provider_sampleDates") + @UseDataProvider("data_sampleDates") public void test_equals_false_year_differs(int y, int m, int d, ZoneOffset offset) { OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); OffsetDate b = OffsetDate.of(LocalDate.of(y + 1, m, d), offset); @@ -1819,7 +1819,7 @@ public void test_equals_false_year_differs(int y, int m, int d, ZoneOffset offse } @Test - @UseDataProvider("provider_sampleDates") + @UseDataProvider("data_sampleDates") public void test_equals_false_month_differs(int y, int m, int d, ZoneOffset offset) { OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); OffsetDate b = OffsetDate.of(LocalDate.of(y, m + 1, d), offset); @@ -1827,7 +1827,7 @@ public void test_equals_false_month_differs(int y, int m, int d, ZoneOffset offs } @Test - @UseDataProvider("provider_sampleDates") + @UseDataProvider("data_sampleDates") public void test_equals_false_day_differs(int y, int m, int d, ZoneOffset offset) { OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); OffsetDate b = OffsetDate.of(LocalDate.of(y, m, d + 1), offset); @@ -1835,7 +1835,7 @@ public void test_equals_false_day_differs(int y, int m, int d, ZoneOffset offset } @Test - @UseDataProvider("provider_sampleDates") + @UseDataProvider("data_sampleDates") public void test_equals_false_offset_differs(int y, int m, int d, ZoneOffset ignored) { OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), OFFSET_PONE); OffsetDate b = OffsetDate.of(LocalDate.of(y, m, d), OFFSET_PTWO); @@ -1856,7 +1856,7 @@ public void test_equals_string_false() { // toString() //----------------------------------------------------------------------- @DataProvider - public static Object[][] provider_sampleToString() { + public static Object[][] data_sampleToString() { return new Object[][] { {2008, 7, 5, "Z", "2008-07-05Z"}, {2008, 7, 5, "+00", "2008-07-05Z"}, @@ -1884,7 +1884,7 @@ public static Object[][] provider_sampleToString() { } @Test - @UseDataProvider("provider_sampleToString") + @UseDataProvider("data_sampleToString") public void test_toString(int y, int m, int d, String offsetId, String expected) { OffsetDate t = OffsetDate.of(LocalDate.of(y, m, d), ZoneOffset.of(offsetId)); String str = t.toString(); From 791eea60223b1eb41dc33d396ec6f4958a3f8802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 7 Apr 2019 15:12:04 +0200 Subject: [PATCH 158/279] Update test names of AbstractDateTimeTest --- .../threeten/extra/AbstractDateTimeTest.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/test/java/org/threeten/extra/AbstractDateTimeTest.java b/src/test/java/org/threeten/extra/AbstractDateTimeTest.java index af8cd3cc..e5be0ba9 100644 --- a/src/test/java/org/threeten/extra/AbstractDateTimeTest.java +++ b/src/test/java/org/threeten/extra/AbstractDateTimeTest.java @@ -67,10 +67,10 @@ public abstract class AbstractDateTimeTest { protected abstract List invalidFields(); //----------------------------------------------------------------------- - // isSupported(DateTimeField) + // isSupported(TemporalField) //----------------------------------------------------------------------- @Test - public void basicTest_isSupported_DateTimeField_supported() { + public void basicTest_isSupported_TemporalField_supported() { for (TemporalAccessor sample : samples()) { for (TemporalField field : validFields()) { assertTrue("Failed on " + sample + " " + field, sample.isSupported(field)); @@ -79,7 +79,7 @@ public void basicTest_isSupported_DateTimeField_supported() { } @Test - public void basicTest_isSupported_DateTimeField_unsupported() { + public void basicTest_isSupported_TemporalField_unsupported() { for (TemporalAccessor sample : samples()) { for (TemporalField field : invalidFields()) { assertFalse("Failed on " + sample + " " + field, sample.isSupported(field)); @@ -88,17 +88,17 @@ public void basicTest_isSupported_DateTimeField_unsupported() { } @Test - public void basicTest_isSupported_DateTimeField_null() { + public void basicTest_isSupported_TemporalField_null() { for (TemporalAccessor sample : samples()) { assertFalse("Failed on " + sample, sample.isSupported(null)); } } //----------------------------------------------------------------------- - // range(DateTimeField) + // range(TemporalField) //----------------------------------------------------------------------- @Test - public void basicTest_range_DateTimeField_supported() { + public void basicTest_range_TemporalField_supported() { for (TemporalAccessor sample : samples()) { for (TemporalField field : validFields()) { sample.range(field); // no exception @@ -107,7 +107,7 @@ public void basicTest_range_DateTimeField_supported() { } @Test - public void basicTest_range_DateTimeField_unsupported() { + public void basicTest_range_TemporalField_unsupported() { for (TemporalAccessor sample : samples()) { for (TemporalField field : invalidFields()) { try { @@ -121,7 +121,7 @@ public void basicTest_range_DateTimeField_unsupported() { } @Test - public void basicTest_range_DateTimeField_null() { + public void basicTest_range_TemporalField_null() { for (TemporalAccessor sample : samples()) { try { sample.range(null); @@ -133,10 +133,10 @@ public void basicTest_range_DateTimeField_null() { } //----------------------------------------------------------------------- - // get(DateTimeField) + // get(TemporalField) //----------------------------------------------------------------------- @Test - public void basicTest_get_DateTimeField_supported() { + public void basicTest_get_TemporalField_supported() { for (TemporalAccessor sample : samples()) { for (TemporalField field : validFields()) { if (sample.range(field).isIntValue()) { @@ -154,7 +154,7 @@ public void basicTest_get_DateTimeField_supported() { } @Test - public void basicTest_get_DateTimeField_unsupported() { + public void basicTest_get_TemporalField_unsupported() { for (TemporalAccessor sample : samples()) { for (TemporalField field : invalidFields()) { try { @@ -168,7 +168,7 @@ public void basicTest_get_DateTimeField_unsupported() { } @Test - public void basicTest_get_DateTimeField_null() { + public void basicTest_get_TemporalField_null() { for (TemporalAccessor sample : samples()) { try { sample.get(null); @@ -180,10 +180,10 @@ public void basicTest_get_DateTimeField_null() { } //----------------------------------------------------------------------- - // getLong(DateTimeField) + // getLong(TemporalField) //----------------------------------------------------------------------- @Test - public void basicTest_getLong_DateTimeField_supported() { + public void basicTest_getLong_TemporalField_supported() { for (TemporalAccessor sample : samples()) { for (TemporalField field : validFields()) { sample.getLong(field); // no exception @@ -192,7 +192,7 @@ public void basicTest_getLong_DateTimeField_supported() { } @Test - public void basicTest_getLong_DateTimeField_unsupported() { + public void basicTest_getLong_TemporalField_unsupported() { for (TemporalAccessor sample : samples()) { for (TemporalField field : invalidFields()) { try { @@ -206,7 +206,7 @@ public void basicTest_getLong_DateTimeField_unsupported() { } @Test - public void basicTest_getLong_DateTimeField_null() { + public void basicTest_getLong_TemporalField_null() { for (TemporalAccessor sample : samples()) { try { sample.getLong(null); From 986b175e8b3ff1b8ddb762d73bc45bc7f1981585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Sun, 7 Apr 2019 15:23:03 +0200 Subject: [PATCH 159/279] Add additional tests for OffsetDate --- .../org/threeten/extra/TestOffsetDate.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/src/test/java/org/threeten/extra/TestOffsetDate.java b/src/test/java/org/threeten/extra/TestOffsetDate.java index 067544b0..cae3e79b 100644 --- a/src/test/java/org/threeten/extra/TestOffsetDate.java +++ b/src/test/java/org/threeten/extra/TestOffsetDate.java @@ -78,6 +78,7 @@ import java.time.temporal.TemporalAmount; import java.time.temporal.TemporalField; import java.time.temporal.TemporalQueries; +import java.time.temporal.TemporalUnit; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -490,6 +491,30 @@ public void test_get_OffsetDate(int y, int m, int d, ZoneOffset offset) { assertEquals(localDate.getDayOfWeek(), a.getDayOfWeek()); } + //----------------------------------------------------------------------- + // isSupported(TemporalUnit) + //----------------------------------------------------------------------- + @Test + public void test_isSupported_TemporalUnit() { + assertFalse(TEST_2007_07_15_PONE.isSupported((TemporalUnit) null)); + assertFalse(TEST_2007_07_15_PONE.isSupported(ChronoUnit.NANOS)); + assertFalse(TEST_2007_07_15_PONE.isSupported(ChronoUnit.MICROS)); + assertFalse(TEST_2007_07_15_PONE.isSupported(ChronoUnit.MILLIS)); + assertFalse(TEST_2007_07_15_PONE.isSupported(ChronoUnit.SECONDS)); + assertFalse(TEST_2007_07_15_PONE.isSupported(ChronoUnit.MINUTES)); + assertFalse(TEST_2007_07_15_PONE.isSupported(ChronoUnit.HOURS)); + assertFalse(TEST_2007_07_15_PONE.isSupported(ChronoUnit.HALF_DAYS)); + assertTrue(TEST_2007_07_15_PONE.isSupported(ChronoUnit.DAYS)); + assertTrue(TEST_2007_07_15_PONE.isSupported(ChronoUnit.WEEKS)); + assertTrue(TEST_2007_07_15_PONE.isSupported(ChronoUnit.MONTHS)); + assertTrue(TEST_2007_07_15_PONE.isSupported(ChronoUnit.YEARS)); + assertTrue(TEST_2007_07_15_PONE.isSupported(ChronoUnit.DECADES)); + assertTrue(TEST_2007_07_15_PONE.isSupported(ChronoUnit.CENTURIES)); + assertTrue(TEST_2007_07_15_PONE.isSupported(ChronoUnit.MILLENNIA)); + assertTrue(TEST_2007_07_15_PONE.isSupported(ChronoUnit.ERAS)); + assertFalse(TEST_2007_07_15_PONE.isSupported(ChronoUnit.FOREVER)); + } + //----------------------------------------------------------------------- // get(TemporalField) //----------------------------------------------------------------------- @@ -555,6 +580,43 @@ public void test_query_null() { TEST_2007_07_15_PONE.query(null); } + //----------------------------------------------------------------------- + // adjustInto(Temporal) + //----------------------------------------------------------------------- + @Test + public void test_adjustInto() { + OffsetDateTime odt = OffsetDateTime.of(2007, 12, 3, 10, 15, 30, 0, ZoneOffset.UTC); + OffsetDate od = OffsetDate.of(2008, 1, 4, OFFSET_PONE); + OffsetDateTime expected = OffsetDateTime.of(2008, 1, 4, 10, 15, 30, 0, OFFSET_PONE); + assertEquals(expected, od.adjustInto(odt)); + } + + //----------------------------------------------------------------------- + // until(Temporal, TemporalUnit) + //----------------------------------------------------------------------- + @DataProvider + public static Object[][] data_until() { + return new Object[][] { + {1, OffsetDate.of(2007, 6, 30, OFFSET_PONE), OffsetDate.of(2007, 7, 1, OFFSET_PONE), ChronoUnit.DAYS}, + {1, OffsetDate.of(2007, 6, 30, OFFSET_PONE), OffsetDate.of(2007, 8, 29, OFFSET_PONE), ChronoUnit.MONTHS}, + {2, OffsetDate.of(2007, 6, 30, OFFSET_PONE), OffsetDate.of(2007, 8, 30, OFFSET_PONE), ChronoUnit.MONTHS}, + {2, OffsetDate.of(2007, 6, 30, OFFSET_PONE), OffsetDate.of(2007, 8, 31, OFFSET_PONE), ChronoUnit.MONTHS} + }; + } + + @Test + @UseDataProvider("data_until") + public void test_until(long expected, OffsetDate od1, OffsetDate od2, TemporalUnit unit) { + assertEquals(expected, od1.until(od2, unit)); + assertEquals(-expected, od2.until(od1, unit)); + } + + @Test(expected=DateTimeException.class) + public void test_until_invalidType() { + OffsetDate od1 = OffsetDate.of(2012, 6, 30, OFFSET_PONE); + od1.until(Instant.ofEpochSecond(7), ChronoUnit.SECONDS); + } + //----------------------------------------------------------------------- // withOffsetSameLocal() //----------------------------------------------------------------------- @@ -1652,6 +1714,16 @@ public void test_toLocalDate(int year, int month, int day, ZoneOffset offset) { assertEquals(t, OffsetDate.of(LocalDate.of(year, month, day), offset).toLocalDate()); } + //----------------------------------------------------------------------- + // toEpochSecond(LocalTime) + //----------------------------------------------------------------------- + @Test + public void test_toEpochSecond() { + OffsetDate od = OffsetDate.of(1970, 1, 1, ZoneOffset.UTC); + assertEquals(0, od.toEpochSecond(LocalTime.MIDNIGHT)); + assertEquals(12 * 60 * 60, od.toEpochSecond(LocalTime.MIDNIGHT.plusSeconds(12 * 60 * 60))); + } + //----------------------------------------------------------------------- // compareTo() //----------------------------------------------------------------------- From c4ffe7768f84ffa95874292bf290835932680640 Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Sun, 14 Jul 2019 16:29:55 +0100 Subject: [PATCH 160/279] Tweaks to the Javadoc --- .../java/org/threeten/extra/OffsetDate.java | 284 +++++++++--------- .../org/threeten/extra/TestOffsetDate.java | 8 + 2 files changed, 143 insertions(+), 149 deletions(-) diff --git a/src/main/java/org/threeten/extra/OffsetDate.java b/src/main/java/org/threeten/extra/OffsetDate.java index 0313284c..f43bda8c 100644 --- a/src/main/java/org/threeten/extra/OffsetDate.java +++ b/src/main/java/org/threeten/extra/OffsetDate.java @@ -62,6 +62,7 @@ import java.time.temporal.TemporalQueries; import java.time.temporal.TemporalQuery; import java.time.temporal.TemporalUnit; +import java.time.temporal.UnsupportedTemporalTypeException; import java.time.temporal.ValueRange; import java.time.zone.ZoneRules; import java.util.Objects; @@ -81,8 +82,11 @@ * For example, the value "2nd October 2007 +02:00" can be stored * in an {@code OffsetDate}. * - *

    Specification for implementors

    + *

    Implementation Requirements:

    * This class is immutable and thread-safe. + *

    + * This class must be treated as a value type. Do not synchronize, rely on the + * identity hash code or use the distinction between equals() and ==. */ public final class OffsetDate implements Temporal, TemporalAdjuster, Comparable, Serializable { @@ -195,9 +199,6 @@ public static OffsetDate of(LocalDate date, ZoneOffset offset) { *

    * This method exists primarily for writing test cases. * Non test-code will typically use other methods to create an offset time. - * {@code LocalDate} has one additional convenience variant of the - * equivalent factory method taking fewer arguments. - * They are not provided here to reduce the footprint of the API. * * @param year the year to represent, from MIN_YEAR to MAX_YEAR * @param month the month-of-year to represent, from 1 (January) to 12 (December) @@ -308,6 +309,15 @@ private OffsetDate(LocalDate date, ZoneOffset offset) { this.offset = Objects.requireNonNull(offset, "offset"); } + /** + * Validates the input. + * + * @return the valid object, not null + */ + private Object readResolve() { + return of(date, offset); + } + /** * Returns a new date based on this one, returning {@code this} where possible. * @@ -326,12 +336,11 @@ private OffsetDate with(LocalDate date, ZoneOffset offset) { * Checks if the specified field is supported. *

    * This checks if this date can be queried for the specified field. - * If false, then calling the {@link #range(TemporalField) range} and - * {@link #get(TemporalField) get} methods will throw an exception. + * If false, then calling the {@link #range(TemporalField) range}, + * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)} + * methods will throw an exception. *

    * If the field is a {@link ChronoField} then the query is implemented here. - * The {@link #isSupported(TemporalField) supported fields} will return valid - * values based on this date-time. * The supported fields are: *

      *
    • {@code DAY_OF_WEEK} @@ -343,7 +352,7 @@ private OffsetDate with(LocalDate date, ZoneOffset offset) { *
    • {@code ALIGNED_WEEK_OF_MONTH} *
    • {@code ALIGNED_WEEK_OF_YEAR} *
    • {@code MONTH_OF_YEAR} - *
    • {@code EPOCH_MONTH} + *
    • {@code PROLEPTIC_MONTH} *
    • {@code YEAR_OF_ERA} *
    • {@code YEAR} *
    • {@code ERA} @@ -352,7 +361,7 @@ private OffsetDate with(LocalDate date, ZoneOffset offset) { * All other {@code ChronoField} instances will return false. *

      * If the field is not a {@code ChronoField}, then the result of this method - * is obtained by invoking {@code TemporalField.doIsSupported(TemporalAccessor)} + * is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)} * passing {@code this} as the argument. * Whether the field is supported is determined by the field. * @@ -362,7 +371,7 @@ private OffsetDate with(LocalDate date, ZoneOffset offset) { @Override public boolean isSupported(TemporalField field) { if (field instanceof ChronoField) { - return ((ChronoField) field).isDateBased() || field == OFFSET_SECONDS; + return field.isDateBased() || field == OFFSET_SECONDS; } return field != null && field.isSupportedBy(this); } @@ -398,11 +407,12 @@ public boolean isSupported(TemporalField field) { */ public boolean isSupported(TemporalUnit unit) { if (unit instanceof ChronoUnit) { - return ((ChronoUnit) unit).isDateBased(); + return unit.isDateBased(); } return unit != null && unit.isSupportedBy(this); } + //----------------------------------------------------------------------- /** * Gets the range of valid values for the specified field. *

      @@ -414,16 +424,17 @@ public boolean isSupported(TemporalUnit unit) { * If the field is a {@link ChronoField} then the query is implemented here. * The {@link #isSupported(TemporalField) supported fields} will return * appropriate range instances. - * All other {@code ChronoField} instances will throw a {@code DateTimeException}. + * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. *

      * If the field is not a {@code ChronoField}, then the result of this method - * is obtained by invoking {@code TemporalField.doRange(TemporalAccessor)} + * is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessor)} * passing {@code this} as the argument. * Whether the range can be obtained is determined by the field. * * @param field the field to query the range for, not null * @return the range of valid values for the field, not null * @throws DateTimeException if the range for the field cannot be obtained + * @throws UnsupportedTemporalTypeException if the field is not supported */ @Override public ValueRange range(TemporalField field) { @@ -446,18 +457,21 @@ public ValueRange range(TemporalField field) { *

      * If the field is a {@link ChronoField} then the query is implemented here. * The {@link #isSupported(TemporalField) supported fields} will return valid - * values based on this date, except {@code EPOCH_DAY} and {@code EPOCH_MONTH} + * values based on this date, except {@code EPOCH_DAY} and {@code PROLEPTIC_MONTH} * which are too large to fit in an {@code int} and throw a {@code DateTimeException}. * All other {@code ChronoField} instances will throw a {@code DateTimeException}. *

      * If the field is not a {@code ChronoField}, then the result of this method - * is obtained by invoking {@code TemporalField.doGet(TemporalAccessor)} + * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} * passing {@code this} as the argument. Whether the value can be obtained, * and what the value represents, is determined by the field. * * @param field the field to get, not null * @return the value for the field - * @throws DateTimeException if a value for the field cannot be obtained + * @throws DateTimeException if a value for the field cannot be obtained or + * the value is outside the range of valid values for the field + * @throws UnsupportedTemporalTypeException if the field is not supported or + * the range of values exceeds an {@code int} * @throws ArithmeticException if numeric overflow occurs */ @Override // override for Javadoc @@ -475,16 +489,17 @@ public int get(TemporalField field) { * If the field is a {@link ChronoField} then the query is implemented here. * The {@link #isSupported(TemporalField) supported fields} will return valid * values based on this date. - * All other {@code ChronoField} instances will throw a {@code DateTimeException}. + * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. *

      * If the field is not a {@code ChronoField}, then the result of this method - * is obtained by invoking {@code TemporalField.doGet(TemporalAccessor)} + * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} * passing {@code this} as the argument. Whether the value can be obtained, * and what the value represents, is determined by the field. * * @param field the field to get, not null * @return the value for the field * @throws DateTimeException if a value for the field cannot be obtained + * @throws UnsupportedTemporalTypeException if the field is not supported * @throws ArithmeticException if numeric overflow occurs */ @Override @@ -549,7 +564,7 @@ public LocalDate toLocalDate() { * This method returns the primitive {@code int} value for the year. *

      * The year returned by this method is proleptic as per {@code get(YEAR)}. - * To obtain the year-of-era, use {@code get(YEAR_OF_ERA}. + * To obtain the year-of-era, use {@code get(YEAR_OF_ERA)}. * * @return the year, from MIN_YEAR to MAX_YEAR */ @@ -629,7 +644,7 @@ public DayOfWeek getDayOfWeek() { /** * Returns an adjusted copy of this date. *

      - * This returns a new {@code OffsetDate}, based on this one, with the date adjusted. + * This returns an {@code OffsetDate} based on this one, with the date adjusted. * The adjustment takes place using the specified adjuster strategy object. * Read the documentation of the adjuster to understand what adjustment will be made. *

      @@ -644,8 +659,8 @@ public DayOfWeek getDayOfWeek() { *

      * For example this code returns a date on the last day of July: *

      -     *  import static org.threeten.bp.Month.*;
      -     *  import static org.threeten.bp.temporal.Adjusters.*;
      +     *  import static java.time.Month.*;
      +     *  import static java.time.temporal.TemporalAdjusters.*;
            *
            *  result = offsetDate.with(JULY).with(lastDayOfMonth());
            * 
      @@ -684,7 +699,7 @@ public OffsetDate with(TemporalAdjuster adjuster) { /** * Returns a copy of this date with the specified field set to a new value. *

      - * This returns a new {@code OffsetDate}, based on this one, with the value + * This returns an {@code OffsetDate} based on this one, with the value * for the specified field changed. * This can be used to change any supported field, such as the year, month or day-of-month. * If it is not possible to set the value, because the field is not supported or for @@ -705,10 +720,10 @@ public OffsetDate with(TemporalAdjuster adjuster) { * the matching method on {@link LocalDate#with(TemporalField, long)} LocalDate}. * In this case, the offset is not part of the calculation and will be unchanged. *

      - * All other {@code ChronoField} instances will throw a {@code DateTimeException}. + * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. *

      * If the field is not a {@code ChronoField}, then the result of this method - * is obtained by invoking {@code TemporalField.doWith(Temporal, long)} + * is obtained by invoking {@code TemporalField.adjustInto(Temporal, long)} * passing {@code this} as the argument. In this case, the field determines * whether and how to adjust the instant. *

      @@ -718,6 +733,7 @@ public OffsetDate with(TemporalAdjuster adjuster) { * @param newValue the new value of the field in the result * @return an {@code OffsetDate} based on {@code this} with the specified field set, not null * @throws DateTimeException if the field cannot be set + * @throws UnsupportedTemporalTypeException if the field is not supported * @throws ArithmeticException if numeric overflow occurs */ @Override @@ -735,6 +751,7 @@ public OffsetDate with(TemporalField field, long newValue) { //----------------------------------------------------------------------- /** * Returns a copy of this {@code OffsetDate} with the year altered. + *

      * The offset does not affect the calculation and will be the same in the result. * If the day-of-month is invalid for the year, it will be changed to the last valid day of the month. *

      @@ -750,6 +767,7 @@ public OffsetDate withYear(int year) { /** * Returns a copy of this {@code OffsetDate} with the month-of-year altered. + *

      * The offset does not affect the calculation and will be the same in the result. * If the day-of-month is invalid for the year, it will be changed to the last valid day of the month. *

      @@ -765,6 +783,7 @@ public OffsetDate withMonth(int month) { /** * Returns a copy of this {@code OffsetDate} with the day-of-month altered. + *

      * If the resulting date is invalid, an exception is thrown. * The offset does not affect the calculation and will be the same in the result. *

      @@ -772,8 +791,8 @@ public OffsetDate withMonth(int month) { * * @param dayOfMonth the day-of-month to set in the result, from 1 to 28-31 * @return an {@code OffsetDate} based on this date with the requested day, not null - * @throws DateTimeException if the day-of-month value is invalid - * @throws DateTimeException if the day-of-month is invalid for the month-year + * @throws DateTimeException if the day-of-month value is invalid, + * or if the day-of-month is invalid for the month-year */ public OffsetDate withDayOfMonth(int dayOfMonth) { return with(date.withDayOfMonth(dayOfMonth), offset); @@ -781,14 +800,15 @@ public OffsetDate withDayOfMonth(int dayOfMonth) { /** * Returns a copy of this {@code OffsetDate} with the day-of-year altered. + *

      * If the resulting date is invalid, an exception is thrown. *

      * This instance is immutable and unaffected by this method call. * * @param dayOfYear the day-of-year to set in the result, from 1 to 365-366 * @return an {@code OffsetDate} based on this date with the requested day, not null - * @throws DateTimeException if the day-of-year value is invalid - * @throws DateTimeException if the day-of-year is invalid for the year + * @throws DateTimeException if the day-of-year value is invalid, + * or if the day-of-year is invalid for the year */ public OffsetDate withDayOfYear(int dayOfYear) { return with(date.withDayOfYear(dayOfYear), offset); @@ -798,16 +818,15 @@ public OffsetDate withDayOfYear(int dayOfYear) { /** * Returns a copy of this date with the specified period added. *

      - * This method returns a new date based on this date with the specified period added. - * The adder is typically {@link Period} but may be any other type implementing + * This returns an {@code OffsetDate} based on this one, with the specified amount added. + * The amount is typically {@link Period} but may be any other type implementing * the {@link TemporalAmount} interface. - * The calculation is delegated to the specified adjuster, which typically calls - * back to {@link #plus(long, TemporalUnit)}. - * The offset is not part of the calculation and will be unchanged in the result. + *

      + * This uses {@link TemporalAmount#addTo(Temporal)} to perform the calculation. *

      * This instance is immutable and unaffected by this method call. * - * @param amountToAdd the adder to use, not null + * @param amountToAdd the amount to add, not null * @return an {@code OffsetDate} based on this date with the addition made, not null * @throws DateTimeException if the addition cannot be made * @throws ArithmeticException if numeric overflow occurs @@ -818,20 +837,29 @@ public OffsetDate plus(TemporalAmount amountToAdd) { } /** - * Returns a copy of this date with the specified period added. + * Returns a copy of this date with the specified amount added. + *

      + * This returns an {@code OffsetDate} based on this one, with the amount + * in terms of the unit added. If it is not possible to add the amount, because the + * unit is not supported or for some other reason, an exception is thrown. *

      - * This method returns a new date based on this date with the specified period added. - * This can be used to add any period that is defined by a unit, for example to add years, months or days. - * The unit is responsible for the details of the calculation, including the resolution - * of any edge cases in the calculation. + * If the field is a {@link ChronoUnit} then the addition is implemented by + * {@link LocalDate#plus(long, TemporalUnit)}. * The offset is not part of the calculation and will be unchanged in the result. *

      + * If the field is not a {@code ChronoUnit}, then the result of this method + * is obtained by invoking {@code TemporalUnit.addTo(Temporal, long)} + * passing {@code this} as the argument. In this case, the unit determines + * whether and how to perform the addition. + *

      * This instance is immutable and unaffected by this method call. * * @param amountToAdd the amount of the unit to add to the result, may be negative - * @param unit the unit of the period to add, not null - * @return an {@code OffsetDate} based on this date with the specified period added, not null - * @throws DateTimeException if the unit cannot be added to this type + * @param unit the unit of the amount to add, not null + * @return an {@code OffsetDate} based on this date with the specified amount added, not null + * @throws DateTimeException if the addition cannot be made + * @throws UnsupportedTemporalTypeException if the unit is not supported + * @throws ArithmeticException if numeric overflow occurs */ @Override public OffsetDate plus(long amountToAdd, TemporalUnit unit) { @@ -843,18 +871,10 @@ public OffsetDate plus(long amountToAdd, TemporalUnit unit) { //----------------------------------------------------------------------- /** - * Returns a copy of this {@code OffsetDate} with the specified period in years added. - *

      - * This method adds the specified amount to the years field in three steps: - *

        - *
      1. Add the input years to the year field
      2. - *
      3. Check if the resulting date would be invalid
      4. - *
      5. Adjust the day-of-month to the last valid day if necessary
      6. - *
      + * Returns a copy of this {@code OffsetDate} with the specified number of years added. *

      - * For example, 2008-02-29 (leap year) plus one year would result in the - * invalid date 2009-02-29 (standard year). Instead of returning an invalid - * result, the last valid day of the month, 2009-02-28, is selected instead. + * This uses {@link LocalDate#plusYears(long)} to add the years. + * The offset does not affect the calculation and will be the same in the result. *

      * This instance is immutable and unaffected by this method call. * @@ -867,18 +887,10 @@ public OffsetDate plusYears(long years) { } /** - * Returns a copy of this {@code OffsetDate} with the specified period in months added. + * Returns a copy of this {@code OffsetDate} with the specified number of months added. *

      - * This method adds the specified amount to the months field in three steps: - *

        - *
      1. Add the input months to the month-of-year field
      2. - *
      3. Check if the resulting date would be invalid
      4. - *
      5. Adjust the day-of-month to the last valid day if necessary
      6. - *
      - *

      - * For example, 2007-03-31 plus one month would result in the invalid date - * 2007-04-31. Instead of returning an invalid result, the last valid day - * of the month, 2007-04-30, is selected instead. + * This uses {@link LocalDate#plusMonths(long)} to add the months. + * The offset does not affect the calculation and will be the same in the result. *

      * This instance is immutable and unaffected by this method call. * @@ -891,13 +903,10 @@ public OffsetDate plusMonths(long months) { } /** - * Returns a copy of this {@code OffsetDate} with the specified period in weeks added. + * Returns a copy of this {@code OffsetDate} with the specified number of weeks added. *

      - * This method adds the specified amount in weeks to the days field incrementing - * the month and year fields as necessary to ensure the result remains valid. - * The result is only invalid if the maximum/minimum year is exceeded. - *

      - * For example, 2008-12-31 plus one week would result in 2009-01-07. + * This uses {@link LocalDate#plusWeeks(long)} to add the weeks. + * The offset does not affect the calculation and will be the same in the result. *

      * This instance is immutable and unaffected by this method call. * @@ -910,13 +919,10 @@ public OffsetDate plusWeeks(long weeks) { } /** - * Returns a copy of this {@code OffsetDate} with the specified period in days added. - *

      - * This method adds the specified amount to the days field incrementing the - * month and year fields as necessary to ensure the result remains valid. - * The result is only invalid if the maximum/minimum year is exceeded. + * Returns a copy of this {@code OffsetDate} with the specified number of days added. *

      - * For example, 2008-12-31 plus one day would result in 2009-01-01. + * This uses {@link LocalDate#plusDays(long)} to add the days. + * The offset does not affect the calculation and will be the same in the result. *

      * This instance is immutable and unaffected by this method call. * @@ -930,18 +936,17 @@ public OffsetDate plusDays(long days) { //----------------------------------------------------------------------- /** - * Returns a copy of this date with the specified period subtracted. + * Returns a copy of this date with the specified amount subtracted. *

      - * This method returns a new date based on this date with the specified period subtracted. - * The subtractor is typically {@link Period} but may be any other type implementing + * This returns am {@code OffsetDate} based on this one, with the specified amount subtracted. + * The amount is typically {@link Period} but may be any other type implementing * the {@link TemporalAmount} interface. - * The calculation is delegated to the specified adjuster, which typically calls - * back to {@link #minus(long, TemporalUnit)}. - * The offset is not part of the calculation and will be unchanged in the result. + *

      + * This uses {@link TemporalAmount#subtractFrom(Temporal)} to perform the calculation. *

      * This instance is immutable and unaffected by this method call. * - * @param amountToSubtract the subtractor to use, not null + * @param amountToSubtract the amount to subtract, not null * @return an {@code OffsetDate} based on this date with the subtraction made, not null * @throws DateTimeException if the subtraction cannot be made * @throws ArithmeticException if numeric overflow occurs @@ -952,20 +957,23 @@ public OffsetDate minus(TemporalAmount amountToSubtract) { } /** - * Returns a copy of this date with the specified period subtracted. + * Returns a copy of this date with the specified amount subtracted. *

      - * This method returns a new date based on this date with the specified period subtracted. - * This can be used to subtract any period that is defined by a unit, for example to subtract years, months or days. - * The unit is responsible for the details of the calculation, including the resolution - * of any edge cases in the calculation. - * The offset is not part of the calculation and will be unchanged in the result. + * This returns an {@code OffsetDate} based on this one, with the amount + * in terms of the unit subtracted. If it is not possible to subtract the amount, + * because the unit is not supported or for some other reason, an exception is thrown. + *

      + * This method is equivalent to {@link #plus(long, TemporalUnit)} with the amount negated. + * See that method for a full description of how addition, and thus subtraction, works. *

      * This instance is immutable and unaffected by this method call. * * @param amountToSubtract the amount of the unit to subtract from the result, may be negative - * @param unit the unit of the period to subtract, not null - * @return an {@code OffsetDate} based on this date with the specified period subtracted, not null - * @throws DateTimeException if the unit cannot be added to this type + * @param unit the unit of the amount to subtract, not null + * @return an {@code OffsetDate} based on this date with the specified amount subtracted, not null + * @throws DateTimeException if the subtraction cannot be made + * @throws UnsupportedTemporalTypeException if the unit is not supported + * @throws ArithmeticException if numeric overflow occurs */ @Override public OffsetDate minus(long amountToSubtract, TemporalUnit unit) { @@ -974,18 +982,10 @@ public OffsetDate minus(long amountToSubtract, TemporalUnit unit) { //----------------------------------------------------------------------- /** - * Returns a copy of this {@code OffsetDate} with the specified period in years subtracted. + * Returns a copy of this {@code OffsetDate} with the specified number of years subtracted. *

      - * This method subtracts the specified amount from the years field in three steps: - *

        - *
      1. Subtract the input years to the year field
      2. - *
      3. Check if the resulting date would be invalid
      4. - *
      5. Adjust the day-of-month to the last valid day if necessary
      6. - *
      - *

      - * For example, 2008-02-29 (leap year) minus one year would result in the - * invalid date 2007-02-29 (standard year). Instead of returning an invalid - * result, the last valid day of the month, 2007-02-28, is selected instead. + * This uses {@link LocalDate#minusYears(long)} to subtract the years. + * The offset does not affect the calculation and will be the same in the result. *

      * This instance is immutable and unaffected by this method call. * @@ -998,18 +998,10 @@ public OffsetDate minusYears(long years) { } /** - * Returns a copy of this {@code OffsetDate} with the specified period in months subtracted. - *

      - * This method subtracts the specified amount from the months field in three steps: - *

        - *
      1. Subtract the input months to the month-of-year field
      2. - *
      3. Check if the resulting date would be invalid
      4. - *
      5. Adjust the day-of-month to the last valid day if necessary
      6. - *
      + * Returns a copy of this {@code OffsetDate} with the specified number of months subtracted. *

      - * For example, 2007-03-31 minus one month would result in the invalid date - * 2007-02-31. Instead of returning an invalid result, the last valid day - * of the month, 2007-02-28, is selected instead. + * This uses {@link LocalDate#minusMonths(long)} to subtract the months. + * The offset does not affect the calculation and will be the same in the result. *

      * This instance is immutable and unaffected by this method call. * @@ -1022,13 +1014,10 @@ public OffsetDate minusMonths(long months) { } /** - * Returns a copy of this {@code OffsetDate} with the specified period in weeks subtracted. - *

      - * This method subtracts the specified amount in weeks from the days field decrementing - * the month and year fields as necessary to ensure the result remains valid. - * The result is only invalid if the maximum/minimum year is exceeded. + * Returns a copy of this {@code OffsetDate} with the specified number of weeks subtracted. *

      - * For example, 2009-01-07 minus one week would result in 2008-12-31. + * This uses {@link LocalDate#minusWeeks(long)} to subtract the weeks. + * The offset does not affect the calculation and will be the same in the result. *

      * This instance is immutable and unaffected by this method call. * @@ -1043,11 +1032,8 @@ public OffsetDate minusWeeks(long weeks) { /** * Returns a copy of this {@code OffsetDate} with the specified number of days subtracted. *

      - * This method subtracts the specified amount from the days field decrementing the - * month and year fields as necessary to ensure the result remains valid. - * The result is only invalid if the maximum/minimum year is exceeded. - *

      - * For example, 2009-01-01 minus one day would result in 2008-12-31. + * This uses {@link LocalDate#minusDays(long)} to subtract the days. + * The offset does not affect the calculation and will be the same in the result. *

      * This instance is immutable and unaffected by this method call. * @@ -1132,9 +1118,10 @@ public Temporal adjustInto(Temporal temporal) { * The start and end points are {@code this} and the specified date. * The result will be negative if the end is before the start. * For example, the period in days between two dates can be calculated - * using {@code startDate.periodUntil(endDate, DAYS)}. + * using {@code startDate.until(endDate, DAYS)}. *

      - * The {@code Temporal} passed to this method must be an {@code OffsetDate}. + * The {@code Temporal} passed to this method is converted to a + * {@code OffsetDate} using {@link #from(TemporalAccessor)}. * If the offset differs between the two times, then the specified * end time is normalized to have the same offset as this time. *

      @@ -1143,14 +1130,15 @@ public Temporal adjustInto(Temporal temporal) { * For example, the period in months between 2012-06-15Z and 2012-08-14Z * will only be one month as it is one day short of two months. *

      - * This method operates in association with {@link TemporalUnit#between}. - * The result of this method is a {@code long} representing the amount of - * the specified unit. By contrast, the result of {@code between} is an - * object that can be used directly in addition/subtraction: + * There are two equivalent ways of using this method. + * The first is to invoke this method. + * The second is to use {@link TemporalUnit#between(Temporal, Temporal)}: *

      -     *   long period = start.periodUntil(end, MONTHS);   // this method
      -     *   dateTime.plus(MONTHS.between(start, end));      // use in plus/minus
      +     *   // these two lines are equivalent
      +     *   amount = start.until(end, DAYS);
      +     *   amount = DAYS.between(start, end);
            * 
      + * The choice should be made based on which makes the code more readable. *

      * The calculation is implemented in this method for {@link ChronoUnit}. * The units {@code DAYS}, {@code WEEKS}, {@code MONTHS}, {@code YEARS}, @@ -1159,36 +1147,34 @@ public Temporal adjustInto(Temporal temporal) { *

      * If the unit is not a {@code ChronoUnit}, then the result of this method * is obtained by invoking {@code TemporalUnit.between(Temporal, Temporal)} - * passing {@code this} as the first argument and the input temporal as - * the second argument. + * passing {@code this} as the first argument and the converted input temporal + * as the second argument. *

      * This instance is immutable and unaffected by this method call. * - * @param endDate the end date, which must be an {@code OffsetDate}, not null - * @param unit the unit to measure the period in, not null - * @return the amount of the period between this date and the end date - * @throws DateTimeException if the period cannot be calculated + * @param endExclusive the end time, exclusive, which is converted to an {@code OffsetDate}, not null + * @param unit the unit to measure the amount in, not null + * @return the amount of time between this date and the end date + * @throws DateTimeException if the amount cannot be calculated, or the end + * temporal cannot be converted to an {@code OffsetDate} + * @throws UnsupportedTemporalTypeException if the unit is not supported * @throws ArithmeticException if numeric overflow occurs */ @Override - public long until(Temporal endDate, TemporalUnit unit) { - if (endDate instanceof OffsetDate == false) { - Objects.requireNonNull(endDate, "endDate"); - throw new DateTimeException("Unable to calculate period between objects of two different types"); - } + public long until(Temporal endExclusive, TemporalUnit unit) { + OffsetDate end = OffsetDate.from(endExclusive); if (unit instanceof ChronoUnit) { - OffsetDate end = (OffsetDate) endDate; long offsetDiff = end.offset.getTotalSeconds() - offset.getTotalSeconds(); LocalDate endLocal = end.date.plusDays(Math.floorDiv(-offsetDiff, SECONDS_PER_DAY)); return date.until(endLocal, unit); } - return unit.between(this, endDate); + return unit.between(this, end); } /** * Formats this date using the specified formatter. *

      - * This date-time will be passed to the formatter to produce a string. + * This date will be passed to the formatter to produce a string. * * @param formatter the formatter to use, not null * @return the formatted date string, not null diff --git a/src/test/java/org/threeten/extra/TestOffsetDate.java b/src/test/java/org/threeten/extra/TestOffsetDate.java index cae3e79b..714d1d1d 100644 --- a/src/test/java/org/threeten/extra/TestOffsetDate.java +++ b/src/test/java/org/threeten/extra/TestOffsetDate.java @@ -73,6 +73,7 @@ import java.time.temporal.ChronoField; import java.time.temporal.ChronoUnit; import java.time.temporal.JulianFields; +import java.time.temporal.Temporal; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjuster; import java.time.temporal.TemporalAmount; @@ -611,6 +612,13 @@ public void test_until(long expected, OffsetDate od1, OffsetDate od2, TemporalUn assertEquals(-expected, od2.until(od1, unit)); } + @Test + public void test_until_otherType() { + OffsetDate start = OffsetDate.of(2007, 6, 30, OFFSET_PONE); + Temporal end = OffsetDateTime.of(2007, 8, 31, 12, 0, 0, 0, OFFSET_PONE); + assertEquals(2, start.until(end, ChronoUnit.MONTHS)); + } + @Test(expected=DateTimeException.class) public void test_until_invalidType() { OffsetDate od1 = OffsetDate.of(2012, 6, 30, OFFSET_PONE); From e06564bee152bbbdb364d8f27fc990f06dbe0612 Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Sun, 14 Jul 2019 16:31:05 +0100 Subject: [PATCH 161/279] Fix YearQuarter Javadoc --- .../java/org/threeten/extra/YearQuarter.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/threeten/extra/YearQuarter.java b/src/main/java/org/threeten/extra/YearQuarter.java index 625726d9..7929e091 100644 --- a/src/main/java/org/threeten/extra/YearQuarter.java +++ b/src/main/java/org/threeten/extra/YearQuarter.java @@ -352,7 +352,7 @@ public boolean isSupported(TemporalField field) { /** * Checks if the specified unit is supported. *

      - * This checks if the specified unit can be added to, or subtracted from, this date-time. + * This checks if the specified unit can be added to, or subtracted from, this year-quarter. * If false, then calling the {@link #plus(long, TemporalUnit)} and * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. *

      @@ -617,7 +617,7 @@ public int lengthOfYear() { /** * Returns an adjusted copy of this year-quarter. *

      - * This returns a {@code YearQuarter}, based on this one, with the year-quarter adjusted. + * This returns a {@code YearQuarter} based on this one, with the year-quarter adjusted. * The adjustment takes place using the specified adjuster strategy object. * Read the documentation of the adjuster to understand what adjustment will be made. *

      @@ -644,7 +644,7 @@ public YearQuarter with(TemporalAdjuster adjuster) { /** * Returns a copy of this year-quarter with the specified field set to a new value. *

      - * This returns a {@code YearQuarter}, based on this one, with the value + * This returns a {@code YearQuarter} based on this one, with the value * for the specified field changed. * This can be used to change any supported field, such as the year or quarter. * If it is not possible to set the value, because the field is not supported or for @@ -740,7 +740,7 @@ public YearQuarter withQuarter(int quarter) { /** * Returns a copy of this year-quarter with the specified amount added. *

      - * This returns a {@code YearQuarter}, based on this one, with the specified amount added. + * This returns a {@code YearQuarter} based on this one, with the specified amount added. * The amount is typically {@link Period} but may be any other type implementing * the {@link TemporalAmount} interface. *

      @@ -765,7 +765,7 @@ public YearQuarter plus(TemporalAmount amountToAdd) { /** * Returns a copy of this year-quarter with the specified amount added. *

      - * This returns a {@code YearQuarter}, based on this one, with the amount + * This returns a {@code YearQuarter} based on this one, with the amount * in terms of the unit added. If it is not possible to add the amount, because the * unit is not supported or for some other reason, an exception is thrown. *

      @@ -877,7 +877,7 @@ public YearQuarter plusQuarters(long quartersToAdd) { /** * Returns a copy of this year-quarter with the specified amount subtracted. *

      - * This returns a {@code YearQuarter}, based on this one, with the specified amount subtracted. + * This returns a {@code YearQuarter} based on this one, with the specified amount subtracted. * The amount is typically {@link Period} but may be any other type implementing * the {@link TemporalAmount} interface. *

      @@ -902,7 +902,7 @@ public YearQuarter minus(TemporalAmount amountToSubtract) { /** * Returns a copy of this year-quarter with the specified amount subtracted. *

      - * This returns a {@code YearQuarter}, based on this one, with the amount + * This returns a {@code YearQuarter} based on this one, with the amount * in terms of the unit subtracted. If it is not possible to subtract the amount, * because the unit is not supported or for some other reason, an exception is thrown. *

      @@ -1102,7 +1102,7 @@ public Stream quartersUntil(YearQuarter endExclusive) { throw new IllegalArgumentException(endExclusive + " < " + this); } long intervalLength = until(endExclusive, QUARTER_YEARS); - return LongStream.range(0,intervalLength).mapToObj(n -> plusQuarters(n)); + return LongStream.range(0, intervalLength).mapToObj(n -> plusQuarters(n)); } /** From 5aff57d90102364612fb1fa69399d2e2312585f5 Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Sun, 14 Jul 2019 16:44:26 +0100 Subject: [PATCH 162/279] Bump next version to 1.6.0 --- pom.xml | 2 +- src/changes/changes.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 358bc5ec..b7a94133 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.5.1-SNAPSHOT + 1.6.0-SNAPSHOT Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later https://www.threeten.org/threeten-extra diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 0667cb5e..79e785e0 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,7 +7,7 @@ - + Add OffsetDate. Fixes #137. From d3d6527b99ebdb0faa5a6961f21b9aa7dd3e0449 Mon Sep 17 00:00:00 2001 From: Erik van Paassen Date: Sun, 3 Nov 2019 16:50:15 +0100 Subject: [PATCH 163/279] Mention Seconds, Minutes, Hours, LocalDateRange value types on website. --- src/site/markdown/index.md | 6 +++++- src/site/markdown/userguide.md | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index ba072641..b3cd327c 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -21,11 +21,15 @@ The following features are included: * [`Quarter`](apidocs/org.threeten.extra/org/threeten/extra/Quarter.html) - the four quarters, Q1, Q2, Q3 and Q4 * [`YearQuarter`](apidocs/org.threeten.extra/org/threeten/extra/YearQuarter.html) - combines a year and quarter, 2014-Q4 * [`YearWeek`](apidocs/org.threeten.extra/org/threeten/extra/YearWeek.html) - combines a week-based-year and a week, 2014-W06 -* [`Days`](apidocs/org.threeten.extra/org/threeten/extra/Days.html), +* [`Seconds`](apidocs/org.threeten.extra/org/threeten/extra/Seconds.html), +[`Minutes`](apidocs/org.threeten.extra/org/threeten/extra/Minutes.html), +[`Hours`](apidocs/org.threeten.extra/org/threeten/extra/Hours.html), +[`Days`](apidocs/org.threeten.extra/org/threeten/extra/Days.html), [`Weeks`](apidocs/org.threeten.extra/org/threeten/extra/Weeks.html), [`Months`](apidocs/org.threeten.extra/org/threeten/extra/Months.html) and [`Years`](apidocs/org.threeten.extra/org/threeten/extra/Years.html) - amounts of time * [`Interval`](apidocs/org.threeten.extra/org/threeten/extra/Interval.html) - an interval between two instants +* [`LocalDateRange`](apidocs/org.threeten.extra/org/threeten/extra/LocalDateRange.html) - a range between two dates * [`PeriodDuration`](apidocs/org.threeten.extra/org/threeten/extra/PeriodDuration.html) - combines `Period` and `Duration` * Weekend adjusters * [Coptic](apidocs/org.threeten.extra/org/threeten/extra/chrono/CopticChronology.html) calendar system diff --git a/src/site/markdown/userguide.md b/src/site/markdown/userguide.md index 09d90b87..afde9f2c 100644 --- a/src/site/markdown/userguide.md +++ b/src/site/markdown/userguide.md @@ -15,11 +15,15 @@ These include: * [`Quarter`](apidocs/org.threeten.extra/org/threeten/extra/Quarter.html) - the four quarters, Q1, Q2, Q3 and Q4 * [`YearQuarter`](apidocs/org.threeten.extra/org/threeten/extra/YearQuarter.html) - combines a year and quarter, 2014-Q4 * [`YearWeek`](apidocs/org.threeten.extra/org/threeten/extra/YearWeek.html) - combines a week-based-year and a week, 2014-W06 +* [`Seconds`](apidocs/org.threeten.extra/org/threeten/extra/Seconds.html) - an amount of time measured in seconds +* [`Minutes`](apidocs/org.threeten.extra/org/threeten/extra/Minutes.html) - an amount of time measured in minutes +* [`Hours`](apidocs/org.threeten.extra/org/threeten/extra/Hours.html) - an amount of time measured in hours * [`Days`](apidocs/org.threeten.extra/org/threeten/extra/Days.html) - an amount of time measured in days * [`Weeks`](apidocs/org.threeten.extra/org/threeten/extra/Weeks.html) - an amount of time measured in weeks * [`Months`](apidocs/org.threeten.extra/org/threeten/extra/Months.html) - an amount of time measured in months * [`Years`](apidocs/org.threeten.extra/org/threeten/extra/Years.html) - an amount of time measured in years * [`Interval`](apidocs/org.threeten.extra/org/threeten/extra/Interval.html) - an interval between two instants +* [`LocalDateRange`](apidocs/org.threeten.extra/org/threeten/extra/LocalDateRange.html) - a range between two dates * [`PeriodDuration`](apidocs/org.threeten.extra/org/threeten/extra/PeriodDuration.html) - combines a `Period` and a `Duration` From 5ec3a8f3b5a52ae03077b2f8413acb38015b9077 Mon Sep 17 00:00:00 2001 From: Erik van Paassen Date: Sun, 3 Nov 2019 16:53:22 +0100 Subject: [PATCH 164/279] Mention additional calendar systems on home page of website. --- src/site/markdown/index.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index b3cd327c..17a33f4d 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -32,9 +32,16 @@ The following features are included: * [`LocalDateRange`](apidocs/org.threeten.extra/org/threeten/extra/LocalDateRange.html) - a range between two dates * [`PeriodDuration`](apidocs/org.threeten.extra/org/threeten/extra/PeriodDuration.html) - combines `Period` and `Duration` * Weekend adjusters -* [Coptic](apidocs/org.threeten.extra/org/threeten/extra/chrono/CopticChronology.html) calendar system -* [Ethiopic](apidocs/org.threeten.extra/org/threeten/extra/chrono/EthiopicChronology.html) calendar system -* [Julian](apidocs/org.threeten.extra/org/threeten/extra/chrono/JulianChronology.html) calendar system +* [Accounting](apidocs/org.threeten.extra/org/threeten/extra/chrono/AccountingChronology.html), +[British Cutover](apidocs/org.threeten.extra/org/threeten/extra/chrono/BritishCutoverChronology.html), +[Coptic](apidocs/org.threeten.extra/org/threeten/extra/chrono/CopticChronology.html), +[Discordian](apidocs/org.threeten.extra/org/threeten/extra/chrono/DiscordianChronology.html), +[Ethiopic](apidocs/org.threeten.extra/org/threeten/extra/chrono/EthiopicChronology.html), +[International Fixed](apidocs/org.threeten.extra/org/threeten/extra/chrono/InternationalFixedChronology.html), +[Julian](apidocs/org.threeten.extra/org/threeten/extra/chrono/JulianChronology.html), +[Pax](apidocs/org.threeten.extra/org/threeten/extra/chrono/PaxChronology.html), +[Symmetry010](apidocs/org.threeten.extra/org/threeten/extra/chrono/Symmetry010Chronology.html) and +[Symmetry454](apidocs/org.threeten.extra/org/threeten/extra/chrono/Symmetry454Chronology.html) calendar systems * [Word-based](apidocs/org.threeten.extra/org/threeten/extra/AmountFormats.html) period and duration formatting * Support for the TAI and UTC [time-scales](apidocs/org.threeten.extra/org/threeten/extra/scale/package-summary.html) From c402a812282f5c16db5762a5eee536b1e95e0eff Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Thu, 14 Nov 2019 19:03:03 +0000 Subject: [PATCH 165/279] Fix license link --- src/site/markdown/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index ba072641..098ba06d 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -8,7 +8,7 @@ Some concepts are too specialized or too bulky to make it in. This project provides some of those additional classes as a well-tested and reliable jar. It is curated by the primary author of the Java 8 date and time library, [Stephen Colebourne](https://www.joda.org/). -ThreeTen-Extra is licensed under the business-friendly [BSD 3-clause license](license.html). +ThreeTen-Extra is licensed under the business-friendly [BSD 3-clause license](licenses.html). ## Features From f6e433e2274f8fbca386aa537a27116727eccc43 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Thu, 14 Nov 2019 19:03:03 +0000 Subject: [PATCH 166/279] Fix license link --- src/site/markdown/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index 17a33f4d..2d4fd95f 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -8,7 +8,7 @@ Some concepts are too specialized or too bulky to make it in. This project provides some of those additional classes as a well-tested and reliable jar. It is curated by the primary author of the Java 8 date and time library, [Stephen Colebourne](https://www.joda.org/). -ThreeTen-Extra is licensed under the business-friendly [BSD 3-clause license](license.html). +ThreeTen-Extra is licensed under the business-friendly [BSD 3-clause license](licenses.html). ## Features From a3e9c5131015453539c283bb13ec7c2ecaa66f40 Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Wed, 20 Nov 2019 22:52:30 +0000 Subject: [PATCH 167/279] Further documentation updates, fix CI --- .travis.yml | 3 +-- pom.xml | 4 ++++ src/site/markdown/index.md | 20 ++++++-------------- src/site/markdown/userguide.md | 3 ++- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4effc0ae..4a3239a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,7 @@ sudo: false language: java jdk: - openjdk11 - - oraclejdk9 - - oraclejdk8 + - openjdk8 cache: directories: - "$HOME/.m2/repository" diff --git a/pom.xml b/pom.xml index b7a94133..b8482041 100644 --- a/pom.xml +++ b/pom.xml @@ -90,6 +90,10 @@ Bjørn Erik Pedersen https://github.com/bep + + Erik van Paassen + https://github.com/evpaassen + Björn Raupach https://github.com/raupachz diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index 2d4fd95f..c5f16b3c 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -19,8 +19,9 @@ The following features are included: * [`DayOfYear`](apidocs/org.threeten.extra/org/threeten/extra/DayOfYear.html) - a day-of-year without year * [`AmPm`](apidocs/org.threeten.extra/org/threeten/extra/AmPm.html) - before or after midday * [`Quarter`](apidocs/org.threeten.extra/org/threeten/extra/Quarter.html) - the four quarters, Q1, Q2, Q3 and Q4 -* [`YearQuarter`](apidocs/org.threeten.extra/org/threeten/extra/YearQuarter.html) - combines a year and quarter, 2014-Q4 -* [`YearWeek`](apidocs/org.threeten.extra/org/threeten/extra/YearWeek.html) - combines a week-based-year and a week, 2014-W06 +* [`YearQuarter`](apidocs/org.threeten.extra/org/threeten/extra/YearQuarter.html) - combines year and quarter, 2014-Q4 +* [`YearWeek`](apidocs/org.threeten.extra/org/threeten/extra/YearWeek.html) - a week in a week-based-year, 2014-W06 +* [`OffsetDate`](apidocs/org.threeten.extra/org/threeten/extra/OffsetDate.html) - combines `LocalDate` and `ZoneOffset` * [`Seconds`](apidocs/org.threeten.extra/org/threeten/extra/Seconds.html), [`Minutes`](apidocs/org.threeten.extra/org/threeten/extra/Minutes.html), [`Hours`](apidocs/org.threeten.extra/org/threeten/extra/Hours.html), @@ -31,18 +32,9 @@ The following features are included: * [`Interval`](apidocs/org.threeten.extra/org/threeten/extra/Interval.html) - an interval between two instants * [`LocalDateRange`](apidocs/org.threeten.extra/org/threeten/extra/LocalDateRange.html) - a range between two dates * [`PeriodDuration`](apidocs/org.threeten.extra/org/threeten/extra/PeriodDuration.html) - combines `Period` and `Duration` -* Weekend adjusters -* [Accounting](apidocs/org.threeten.extra/org/threeten/extra/chrono/AccountingChronology.html), -[British Cutover](apidocs/org.threeten.extra/org/threeten/extra/chrono/BritishCutoverChronology.html), -[Coptic](apidocs/org.threeten.extra/org/threeten/extra/chrono/CopticChronology.html), -[Discordian](apidocs/org.threeten.extra/org/threeten/extra/chrono/DiscordianChronology.html), -[Ethiopic](apidocs/org.threeten.extra/org/threeten/extra/chrono/EthiopicChronology.html), -[International Fixed](apidocs/org.threeten.extra/org/threeten/extra/chrono/InternationalFixedChronology.html), -[Julian](apidocs/org.threeten.extra/org/threeten/extra/chrono/JulianChronology.html), -[Pax](apidocs/org.threeten.extra/org/threeten/extra/chrono/PaxChronology.html), -[Symmetry010](apidocs/org.threeten.extra/org/threeten/extra/chrono/Symmetry010Chronology.html) and -[Symmetry454](apidocs/org.threeten.extra/org/threeten/extra/chrono/Symmetry454Chronology.html) calendar systems -* [Word-based](apidocs/org.threeten.extra/org/threeten/extra/AmountFormats.html) period and duration formatting +* More [utilities](apidocs/org.threeten.extra/org/threeten/extra/Temporals.html), such as weekend adjusters +* Extended [formatting](apidocs/org.threeten.extra/org/threeten/extra/AmountFormats.html) of periods and durations, including word-based formatting +* Additional [calendar systems](apidocs/org.threeten.extra/org/threeten/extra/chrono/package-summary.html) * Support for the TAI and UTC [time-scales](apidocs/org.threeten.extra/org/threeten/extra/scale/package-summary.html) diff --git a/src/site/markdown/userguide.md b/src/site/markdown/userguide.md index afde9f2c..7a1a65ca 100644 --- a/src/site/markdown/userguide.md +++ b/src/site/markdown/userguide.md @@ -15,6 +15,7 @@ These include: * [`Quarter`](apidocs/org.threeten.extra/org/threeten/extra/Quarter.html) - the four quarters, Q1, Q2, Q3 and Q4 * [`YearQuarter`](apidocs/org.threeten.extra/org/threeten/extra/YearQuarter.html) - combines a year and quarter, 2014-Q4 * [`YearWeek`](apidocs/org.threeten.extra/org/threeten/extra/YearWeek.html) - combines a week-based-year and a week, 2014-W06 +* [`OffsetDate`](apidocs/org.threeten.extra/org/threeten/extra/OffsetDate.html) - combines `LocalDate` and `ZoneOffset` * [`Seconds`](apidocs/org.threeten.extra/org/threeten/extra/Seconds.html) - an amount of time measured in seconds * [`Minutes`](apidocs/org.threeten.extra/org/threeten/extra/Minutes.html) - an amount of time measured in minutes * [`Hours`](apidocs/org.threeten.extra/org/threeten/extra/Hours.html) - an amount of time measured in hours @@ -24,7 +25,7 @@ These include: * [`Years`](apidocs/org.threeten.extra/org/threeten/extra/Years.html) - an amount of time measured in years * [`Interval`](apidocs/org.threeten.extra/org/threeten/extra/Interval.html) - an interval between two instants * [`LocalDateRange`](apidocs/org.threeten.extra/org/threeten/extra/LocalDateRange.html) - a range between two dates -* [`PeriodDuration`](apidocs/org.threeten.extra/org/threeten/extra/PeriodDuration.html) - combines a `Period` and a `Duration` +* [`PeriodDuration`](apidocs/org.threeten.extra/org/threeten/extra/PeriodDuration.html) - combines `Period` and `Duration` ## Period/Duration formatting From 0890770290b385d91f0d2b4bdde2fd268c279370 Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Tue, 18 Feb 2020 22:45:49 +0000 Subject: [PATCH 168/279] Fix UtcInstant.isLeapSecond Ensure correct answer at start of leap second Fixes #153 --- src/changes/changes.xml | 4 ++++ .../java/org/threeten/extra/scale/UtcInstant.java | 2 +- .../org/threeten/extra/scale/TestUtcInstant.java | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 79e785e0..3f13dabf 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -12,6 +12,10 @@ Add OffsetDate. Fixes #137. + + Fix UtcInstant.isLeapSecond(). + Fixes #153. + Add Farsi translations for word-based formatting. Fixes #131. diff --git a/src/main/java/org/threeten/extra/scale/UtcInstant.java b/src/main/java/org/threeten/extra/scale/UtcInstant.java index 200838f2..40fe58c2 100644 --- a/src/main/java/org/threeten/extra/scale/UtcInstant.java +++ b/src/main/java/org/threeten/extra/scale/UtcInstant.java @@ -306,7 +306,7 @@ public UtcInstant withNanoOfDay(long nanoOfDay) { * @return true if this instant is within a leap second */ public boolean isLeapSecond() { - return nanoOfDay > SECS_PER_DAY * NANOS_PER_SECOND; + return nanoOfDay >= SECS_PER_DAY * NANOS_PER_SECOND; } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/scale/TestUtcInstant.java b/src/test/java/org/threeten/extra/scale/TestUtcInstant.java index 6f7ec55a..e2b872ad 100644 --- a/src/test/java/org/threeten/extra/scale/TestUtcInstant.java +++ b/src/test/java/org/threeten/extra/scale/TestUtcInstant.java @@ -32,6 +32,7 @@ package org.threeten.extra.scale; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -104,11 +105,22 @@ public void factory_ofModifiedJulianDay_long_long() { } } + @Test + public void factory_ofModifiedJulianDay_long_long_endNormal() { + UtcInstant t = UtcInstant.ofModifiedJulianDay(MJD_1972_12_31_LEAP, NANOS_PER_DAY - 1); + assertEquals(MJD_1972_12_31_LEAP, t.getModifiedJulianDay()); + assertEquals(NANOS_PER_DAY - 1, t.getNanoOfDay()); + assertFalse(t.isLeapSecond()); + assertEquals("1972-12-31T23:59:59.999999999Z", t.toString()); + } + @Test public void factory_ofModifiedJulianDay_long_long_startLeap() { UtcInstant t = UtcInstant.ofModifiedJulianDay(MJD_1972_12_31_LEAP, NANOS_PER_DAY); assertEquals(MJD_1972_12_31_LEAP, t.getModifiedJulianDay()); assertEquals(NANOS_PER_DAY, t.getNanoOfDay()); + assertTrue(t.isLeapSecond()); + assertEquals("1972-12-31T23:59:60Z", t.toString()); } @Test @@ -116,6 +128,8 @@ public void factory_ofModifiedJulianDay_long_long_endLeap() { UtcInstant t = UtcInstant.ofModifiedJulianDay(MJD_1972_12_31_LEAP, NANOS_PER_LEAP_DAY - 1); assertEquals(MJD_1972_12_31_LEAP, t.getModifiedJulianDay()); assertEquals(NANOS_PER_LEAP_DAY - 1, t.getNanoOfDay()); + assertTrue(t.isLeapSecond()); + assertEquals("1972-12-31T23:59:60.999999999Z", t.toString()); } @Test(expected = DateTimeException.class) From 3138d2d321570264e7db41fd4769c2362778d450 Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Mon, 9 Mar 2020 22:47:30 +0000 Subject: [PATCH 169/279] Move from Travis to GitHub Actions --- .github/workflows/build.yml | 56 +++++++++++++++++++++++++++++++++++++ .travis.yml | 22 --------------- 2 files changed, 56 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..f9f2eb84 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,56 @@ +name: Build + +on: + push: + branches: + - '*' + tags: + - 'v*' + - 'website*' + pull_request: + branches: + - 'master' + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + java: [1.8, 11] + + steps: + - name: Set up JDK + uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + - name: Checkout + uses: actions/checkout@v2 + - name: Maven cache + uses: actions/cache@v1 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ matrix.java }}-${{ hashFiles('**/pom.xml') }}-${{ hashFiles('.github/workflows/build.yml') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: Maven version + run: | + mkdir -p ./.mvn + echo '-e -B -DtrimStackTrace=false' > ./.mvn/maven.config + mvn --version + mkdir -p target + - name: Maven build + run: | + mvn install site + - name: CodeCov upload + if: matrix.java == '11' + uses: codecov/codecov-action@v1 + with: + file: ./target/site/jacoco/jacoco.xml + + - name: Website + if: matrix.java == '11' && github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/website') || startsWith(github.ref, 'refs/tags/v')) + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_PERSONAL_TOKEN }} + run: | + chmod +x ./.github/website.sh + .github/website.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 4a3239a4..00000000 --- a/.travis.yml +++ /dev/null @@ -1,22 +0,0 @@ -sudo: false -language: java -jdk: - - openjdk11 - - openjdk8 -cache: - directories: - - "$HOME/.m2/repository" -before_cache: - - rm -rf $HOME/.m2/repository/org/threeten -install: - - mvn --version -script: - - mvn install site -e -B - - if [[ $TRAVIS_TAG =~ ^website.*$ ]] && [ "$TRAVIS_JDK_VERSION" == "openjdk11" ]; then chmod +x ./.github/website.sh; .github/website.sh; fi - - if [[ $TRAVIS_TAG =~ ^v.*$ ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_JDK_VERSION" == "openjdk11" ]; then chmod +x ./.github/website.sh; .github/website.sh; fi -after_success: - - bash <(curl -s https://codecov.io/bash) -# secure keys for GITHUB_TOKEN -env: - global: - - secure: FaC3K5L6pGdJgvPcttpq8kV5i+UUsj5FWvETqm82BZWzLTYlQsCL4fl2XfssATiH7hIVioRffYoZP8rQbkNatVV+Pok6wZePSM9kOf7/AUOn0dvwXH718sbWlohOf3R3886/l5rjyJDDmauMABXzLrXxsTlbiQ85QNA0mCbqXJ4= From c1d0fb1bd162e63feef91da54bd453275fa0dbea Mon Sep 17 00:00:00 2001 From: "Stephen Colebourne (CI)" Date: Fri, 20 Mar 2020 08:37:42 +0000 Subject: [PATCH 170/279] Update build --- README.md | 4 ++-- pom.xml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 50d006d7..d7fa1e11 100644 --- a/README.md +++ b/README.md @@ -42,5 +42,5 @@ Tidelift will coordinate the fix and disclosure. * Update version (README.md, index.md, changes.xml) * Commit and push -* `mvn clean release:clean release:prepare release:perform` -* Website will be built and released by Travis +* Run `mvn clean release:clean release:prepare release:perform` on Java 11 +* Website will be built and released by GitHub Actions diff --git a/pom.xml b/pom.xml index b8482041..7623f985 100644 --- a/pom.xml +++ b/pom.xml @@ -804,7 +804,7 @@ de.jutzig github-release-plugin - 1.1.1 + 1.4.0 Release v${project.version} See the [change notes](https://www.threeten.org/threeten-extra/changes-report.html) for more information. From 323a10449b25c2e917db1b0124c481b2ee299f24 Mon Sep 17 00:00:00 2001 From: "Anosh D. Ullenius" Date: Mon, 27 Apr 2020 17:51:55 +0200 Subject: [PATCH 171/279] Remove redundant qualifier & empty statement --- src/main/java/org/threeten/extra/AmountFormats.java | 3 ++- src/main/java/org/threeten/extra/PackedFields.java | 6 +++--- src/main/java/org/threeten/extra/Temporals.java | 2 +- src/main/java/org/threeten/extra/chrono/AccountingDate.java | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/threeten/extra/AmountFormats.java b/src/main/java/org/threeten/extra/AmountFormats.java index 3632faf6..a67a09b2 100644 --- a/src/main/java/org/threeten/extra/AmountFormats.java +++ b/src/main/java/org/threeten/extra/AmountFormats.java @@ -183,7 +183,8 @@ public static String wordBased(Period period, Locale locale) { WordBased wb = new WordBased(formats, bundle.getString(WORDBASED_COMMASPACE), bundle.getString(WORDBASED_SPACEANDSPACE)); Period normPeriod = oppositeSigns(period.getMonths(), period.getYears()) ? period.normalized() : period; - int weeks = 0, days = 0; + int weeks = 0; + int days = 0; if (normPeriod.getDays() % DAYS_PER_WEEK == 0) { weeks = normPeriod.getDays() / DAYS_PER_WEEK; } else { diff --git a/src/main/java/org/threeten/extra/PackedFields.java b/src/main/java/org/threeten/extra/PackedFields.java index cd7fa1cb..a06c0833 100644 --- a/src/main/java/org/threeten/extra/PackedFields.java +++ b/src/main/java/org/threeten/extra/PackedFields.java @@ -115,7 +115,7 @@ private PackedFields() { /** * Implementation of packed date. */ - private static enum PackedDate implements TemporalField { + private enum PackedDate implements TemporalField { INSTANCE; private static final ValueRange RANGE = ValueRange.of(10000101, 99991231); @@ -220,7 +220,7 @@ public String toString() { /** * Implementation of packed hour-min. */ - private static enum PackedHourMin implements TemporalField { + private enum PackedHourMin implements TemporalField { INSTANCE; private static final ValueRange RANGE = ValueRange.of(0, 2359); @@ -311,7 +311,7 @@ public String toString() { /** * Implementation of packed hour-min-sec. */ - private static enum PackedTime implements TemporalField { + private enum PackedTime implements TemporalField { INSTANCE; private static final ValueRange RANGE = ValueRange.of(0, 235959); diff --git a/src/main/java/org/threeten/extra/Temporals.java b/src/main/java/org/threeten/extra/Temporals.java index 0b3f21c2..8a977d96 100644 --- a/src/main/java/org/threeten/extra/Temporals.java +++ b/src/main/java/org/threeten/extra/Temporals.java @@ -130,7 +130,7 @@ public static TemporalAdjuster previousWorkingDayOrSame() { /** * Enum implementing the adjusters. */ - private static enum Adjuster implements TemporalAdjuster { + private enum Adjuster implements TemporalAdjuster { /** Next working day adjuster. */ NEXT_WORKING { @Override diff --git a/src/main/java/org/threeten/extra/chrono/AccountingDate.java b/src/main/java/org/threeten/extra/chrono/AccountingDate.java index 1d500af9..409ff8a7 100644 --- a/src/main/java/org/threeten/extra/chrono/AccountingDate.java +++ b/src/main/java/org/threeten/extra/chrono/AccountingDate.java @@ -407,7 +407,7 @@ public int lengthOfMonth() { @Override public int lengthOfYear() { return (WEEKS_IN_YEAR + (isLeapYear() ? 1 : 0)) * DAYS_IN_WEEK; - }; + } //------------------------------------------------------------------------- @Override From 37612f3f4cd457979bc8cdc53ef45f532d278226 Mon Sep 17 00:00:00 2001 From: "Anosh D. Ullenius" Date: Mon, 27 Apr 2020 17:57:52 +0200 Subject: [PATCH 172/279] Removing commented-out lines of code --- src/main/java/org/threeten/extra/AmountFormats.java | 1 - .../org/threeten/extra/chrono/InternationalFixedDate.java | 1 - src/main/java/org/threeten/extra/chrono/PaxDate.java | 5 ----- .../org/threeten/extra/chrono/Symmetry010Chronology.java | 2 -- .../org/threeten/extra/chrono/Symmetry454Chronology.java | 2 -- src/test/java/org/threeten/extra/TestDays.java | 8 ++++---- 6 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/threeten/extra/AmountFormats.java b/src/main/java/org/threeten/extra/AmountFormats.java index a67a09b2..d02188d8 100644 --- a/src/main/java/org/threeten/extra/AmountFormats.java +++ b/src/main/java/org/threeten/extra/AmountFormats.java @@ -385,7 +385,6 @@ public void formatTo(int value, StringBuilder buf) { } } buf.append(value).append(text[predicates.length]); - return; } } diff --git a/src/main/java/org/threeten/extra/chrono/InternationalFixedDate.java b/src/main/java/org/threeten/extra/chrono/InternationalFixedDate.java index b8f3799d..e42659e8 100644 --- a/src/main/java/org/threeten/extra/chrono/InternationalFixedDate.java +++ b/src/main/java/org/threeten/extra/chrono/InternationalFixedDate.java @@ -634,7 +634,6 @@ InternationalFixedDate plusWeeks(long weeks) { int newYear = Math.toIntExact(Math.floorDiv(calcEm, WEEKS_IN_YEAR)); int newWeek = Math.toIntExact(Math.floorMod(calcEm, WEEKS_IN_YEAR)); int newMonth = 1 + Math.floorDiv(newWeek, WEEKS_IN_MONTH); - //int newDay = 1 + ((newWeek * DAYS_IN_WEEK + ((day - 1) % DAYS_IN_WEEK)) % DAYS_IN_MONTH); int newDay = 1 + ((newWeek * DAYS_IN_WEEK + 8 + (isLeapDay ? 0 : isYearDay ? -1 : (day - 1) % DAYS_IN_WEEK) - 1) % DAYS_IN_MONTH); return create(newYear, newMonth, newDay); diff --git a/src/main/java/org/threeten/extra/chrono/PaxDate.java b/src/main/java/org/threeten/extra/chrono/PaxDate.java index aeba69c5..f5e31f1d 100644 --- a/src/main/java/org/threeten/extra/chrono/PaxDate.java +++ b/src/main/java/org/threeten/extra/chrono/PaxDate.java @@ -347,11 +347,6 @@ private static PaxDate resolvePreviousValid(int prolepticYear, int month, int da private static long getLeapMonthsBefore(long prolepticMonth) { long offsetMonth = prolepticMonth - (prolepticMonth <= 0 ? 13 : 13 - 1); // First, see getLeapYearsBefore(...) for explanations. - // return 18 * Math.floorDiv(offsetMonth, 100 * MONTHS_IN_YEAR + (getLeapYearsBefore(100) + 1)) - // - Math.floorDiv(offsetMonth, 400 * MONTHS_IN_YEAR + (getLeapYearsBefore(400) + 1)) - // + (((Math.floorMod(offsetMonth, 100 * MONTHS_IN_YEAR + (getLeapYearsBefore(100) + 1)) - (offsetMonth <= 0 ? 100 * MONTHS_IN_YEAR + getLeapYearsBefore(100) : 0)) - // / (99 * MONTHS_IN_YEAR + (getLeapYearsBefore(99) + 1))) + (offsetMonth <= 0 ? 1 : 0)) - // + (Math.floorMod(offsetMonth, 100 * MONTHS_IN_YEAR + (getLeapYearsBefore(100) + 1)) + (offsetMonth <= 0 ? 2 * MONTHS_IN_YEAR - 1 : 0)) / (6 * MONTHS_IN_YEAR + 1); return 18L * Math.floorDiv(offsetMonth, 1318) - Math.floorDiv(offsetMonth, 5272) + (((Math.floorMod(offsetMonth, 1318) - (offsetMonth <= 0 ? 1317 : 0)) / 1304) + (offsetMonth <= 0 ? 1 : 0)) diff --git a/src/main/java/org/threeten/extra/chrono/Symmetry010Chronology.java b/src/main/java/org/threeten/extra/chrono/Symmetry010Chronology.java index 3db1b5e5..e6985c1d 100644 --- a/src/main/java/org/threeten/extra/chrono/Symmetry010Chronology.java +++ b/src/main/java/org/threeten/extra/chrono/Symmetry010Chronology.java @@ -152,8 +152,6 @@ public final class Symmetry010Chronology * There are 6 full 293-year cycles from CE 1 to 1758, with 6 * 52 leap years, i.e. 312. * There are 37 leap years from CE 1758 to 1970. */ - //public static final long DAYS_0001_TO_1970 = (DAYS_PER_CYCLE * 6L) + 211L * DAYS_IN_YEAR + 37 * DAYS_IN_WEEK; - //public static final long DAYS_0001_TO_1970_ISO = IsoChronology.INSTANCE.date(1,1,1).toEpochDay() * -1; public static final long DAYS_0001_TO_1970 = (146097 * 5L) - (31L * 365L + 7L) - 1; /** * Highest year in the range. diff --git a/src/main/java/org/threeten/extra/chrono/Symmetry454Chronology.java b/src/main/java/org/threeten/extra/chrono/Symmetry454Chronology.java index 80f565cd..e00eac16 100644 --- a/src/main/java/org/threeten/extra/chrono/Symmetry454Chronology.java +++ b/src/main/java/org/threeten/extra/chrono/Symmetry454Chronology.java @@ -145,8 +145,6 @@ public final class Symmetry454Chronology * There are 6 full 293-year cycles from CE 1 to 1758, with 6 * 52 leap years, i.e. 312. * There are 37 leap years from CE 1758 to 1970. */ - //public static final long DAYS_0001_TO_1970 = (DAYS_PER_CYCLE * 6L) + 211L * DAYS_IN_YEAR + 37 * DAYS_IN_WEEK; - //public static final long DAYS_0001_TO_1970_ISO = IsoChronology.INSTANCE.date(1,1,1).toEpochDay() * -1; public static final long DAYS_0001_TO_1970 = (146097 * 5L) - (31L * 365L + 7L) - 1; /** * Highest year in the range. diff --git a/src/test/java/org/threeten/extra/TestDays.java b/src/test/java/org/threeten/extra/TestDays.java index 9c0e1086..5176e782 100644 --- a/src/test/java/org/threeten/extra/TestDays.java +++ b/src/test/java/org/threeten/extra/TestDays.java @@ -85,15 +85,15 @@ public void test_deserializationSingleton() throws Exception { //----------------------------------------------------------------------- @Test public void test_ZERO() { - assertSame(Days.of(0), Days.ZERO); - assertEquals(Days.of(0), Days.ZERO); + assertSame(Days.ZERO, Days.of(0) ); + assertEquals(Days.ZERO, Days.of(0)); assertEquals(0, Days.ZERO.getAmount()); } @Test public void test_ONE() { - assertSame(Days.of(1), Days.ONE); - assertEquals(Days.of(1), Days.ONE); + assertSame(Days.ONE, Days.of(1)); + assertEquals(Days.ONE, Days.of(1)); assertEquals(1, Days.ONE.getAmount()); } From 16882d57fba216a69dc0c73710f298d5bbfda496 Mon Sep 17 00:00:00 2001 From: "Anosh D. Ullenius" Date: Mon, 27 Apr 2020 18:22:43 +0200 Subject: [PATCH 173/279] Replacing Predicate with IntPredicate --- src/main/java/org/threeten/extra/AmountFormats.java | 3 ++- src/test/java/org/threeten/extra/TestDays.java | 8 ++++---- .../extra/chrono/TestAccountingChronology.java | 3 ++- .../chrono/TestAccountingChronologyBuilder.java | 13 +++++++------ .../extra/chrono/TestDiscordianChronology.java | 3 ++- .../chrono/TestInternationalFixedChronology.java | 4 ++-- .../threeten/extra/chrono/TestPaxChronology.java | 4 ++-- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/threeten/extra/AmountFormats.java b/src/main/java/org/threeten/extra/AmountFormats.java index d02188d8..06c29117 100644 --- a/src/main/java/org/threeten/extra/AmountFormats.java +++ b/src/main/java/org/threeten/extra/AmountFormats.java @@ -254,7 +254,8 @@ public static String wordBased(Period period, Duration duration, Locale locale) WordBased wb = new WordBased(formats, bundle.getString(WORDBASED_COMMASPACE), bundle.getString(WORDBASED_SPACEANDSPACE)); Period normPeriod = oppositeSigns(period.getMonths(), period.getYears()) ? period.normalized() : period; - int weeks = 0, days = 0; + int weeks = 0; + int days = 0; if (normPeriod.getDays() % DAYS_PER_WEEK == 0) { weeks = normPeriod.getDays() / DAYS_PER_WEEK; } else { diff --git a/src/test/java/org/threeten/extra/TestDays.java b/src/test/java/org/threeten/extra/TestDays.java index 5176e782..9c0e1086 100644 --- a/src/test/java/org/threeten/extra/TestDays.java +++ b/src/test/java/org/threeten/extra/TestDays.java @@ -85,15 +85,15 @@ public void test_deserializationSingleton() throws Exception { //----------------------------------------------------------------------- @Test public void test_ZERO() { - assertSame(Days.ZERO, Days.of(0) ); - assertEquals(Days.ZERO, Days.of(0)); + assertSame(Days.of(0), Days.ZERO); + assertEquals(Days.of(0), Days.ZERO); assertEquals(0, Days.ZERO.getAmount()); } @Test public void test_ONE() { - assertSame(Days.ONE, Days.of(1)); - assertEquals(Days.ONE, Days.of(1)); + assertSame(Days.of(1), Days.ONE); + assertEquals(Days.of(1), Days.ONE); assertEquals(1, Days.ONE.getAmount()); } diff --git a/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java b/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java index 6a9928c9..f8d33ead 100644 --- a/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java @@ -71,6 +71,7 @@ import java.time.temporal.ValueRange; import java.time.temporal.WeekFields; import java.util.List; +import java.util.function.IntPredicate; import java.util.function.Predicate; import org.junit.Assert; @@ -308,7 +309,7 @@ public void test_date_ofYearDay_no_chronology() { //----------------------------------------------------------------------- @Test public void test_isLeapYear_loop() { - Predicate isLeapYear = year -> { + IntPredicate isLeapYear = year -> { LocalDate currentYearEnd = LocalDate.of(year, 9, 3).with(TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY)); LocalDate prevYearEnd = LocalDate.of(year - 1, 9, 3).with(TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY)); return prevYearEnd.until(currentYearEnd, DAYS) == 371; diff --git a/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java b/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java index 5407fe1c..0c9e0b8b 100644 --- a/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java +++ b/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java @@ -42,6 +42,7 @@ import java.time.temporal.TemporalAdjusters; import java.time.temporal.ValueRange; import java.util.function.IntFunction; +import java.util.function.IntPredicate; import java.util.function.Predicate; import org.junit.Test; @@ -95,7 +96,7 @@ public void test_isLeapYear_inLastWeekOf(DayOfWeek dayOfWeek, Month ending) { IntFunction getYearEnd = year -> { return LocalDate.of(year, ending, 1).with(TemporalAdjusters.lastDayOfMonth()).with(TemporalAdjusters.previousOrSame(dayOfWeek)); }; - Predicate isLeapYear = year -> { + IntPredicate isLeapYear = year -> { LocalDate currentYearEnd = getYearEnd.apply(year); LocalDate prevYearEnd = getYearEnd.apply(year - 1); return prevYearEnd.until(currentYearEnd, DAYS) == 371; @@ -116,7 +117,7 @@ public void test_isLeapYear_nearestEndOf(DayOfWeek dayOfWeek, Month ending) { IntFunction getYearEnd = year -> { return LocalDate.of(year, ending, 3).plusMonths(1).with(TemporalAdjusters.previousOrSame(dayOfWeek)); }; - Predicate isLeapYear = year -> { + IntPredicate isLeapYear = year -> { LocalDate currentYearEnd = getYearEnd.apply(year); LocalDate prevYearEnd = getYearEnd.apply(year - 1); return prevYearEnd.until(currentYearEnd, DAYS) == 371; @@ -137,7 +138,7 @@ public void test_previousLeapYears_inLastWeekOf(DayOfWeek dayOfWeek, Month endin IntFunction getYearEnd = year -> { return LocalDate.of(year, ending, 1).with(TemporalAdjusters.lastDayOfMonth()).with(TemporalAdjusters.previousOrSame(dayOfWeek)); }; - Predicate isLeapYear = year -> { + IntPredicate isLeapYear = year -> { LocalDate currentYearEnd = getYearEnd.apply(year); LocalDate prevYearEnd = getYearEnd.apply(year - 1); return prevYearEnd.until(currentYearEnd, DAYS) == 371; @@ -167,7 +168,7 @@ public void test_previousLeapYears_nearestEndOf(DayOfWeek dayOfWeek, Month endin IntFunction getYearEnd = year -> { return LocalDate.of(year, ending, 3).plusMonths(1).with(TemporalAdjusters.previousOrSame(dayOfWeek)); }; - Predicate isLeapYear = year -> { + IntPredicate isLeapYear = year -> { LocalDate currentYearEnd = getYearEnd.apply(year); LocalDate prevYearEnd = getYearEnd.apply(year - 1); return prevYearEnd.until(currentYearEnd, DAYS) == 371; @@ -309,7 +310,7 @@ public void test_date_dayOfYear_inLastWeekOf_range(DayOfWeek dayOfWeek, Month en IntFunction getYearEnd = year -> { return LocalDate.of(year, ending, 1).with(TemporalAdjusters.lastDayOfMonth()).with(TemporalAdjusters.previousOrSame(dayOfWeek)); }; - Predicate isLeapYear = year -> { + IntPredicate isLeapYear = year -> { LocalDate currentYearEnd = getYearEnd.apply(year); LocalDate prevYearEnd = getYearEnd.apply(year - 1); return prevYearEnd.until(currentYearEnd, DAYS) == 371; @@ -330,7 +331,7 @@ public void test_date_dayOfYear_nearestEndOf_range(DayOfWeek dayOfWeek, Month en IntFunction getYearEnd = year -> { return LocalDate.of(year, ending, 3).plusMonths(1).with(TemporalAdjusters.previousOrSame(dayOfWeek)); }; - Predicate isLeapYear = year -> { + IntPredicate isLeapYear = year -> { LocalDate currentYearEnd = getYearEnd.apply(year); LocalDate prevYearEnd = getYearEnd.apply(year - 1); return prevYearEnd.until(currentYearEnd, DAYS) == 371; diff --git a/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java b/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java index c0906ff0..0b3050a3 100644 --- a/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java @@ -72,6 +72,7 @@ import java.time.temporal.UnsupportedTemporalTypeException; import java.time.temporal.ValueRange; import java.util.List; +import java.util.function.IntPredicate; import java.util.function.Predicate; import org.junit.Assert; @@ -272,7 +273,7 @@ public void test_chronology_dateYearDay_badDate() { //----------------------------------------------------------------------- @Test public void test_isLeapYear_loop() { - Predicate isLeapYear = year -> { + IntPredicate isLeapYear = year -> { int offsetYear = year - 1166; return offsetYear % 4 == 0 && (offsetYear % 400 == 0 || offsetYear % 100 != 0); }; diff --git a/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java b/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java index 6a5afb4e..efe59e2d 100644 --- a/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java @@ -74,7 +74,7 @@ import java.time.temporal.UnsupportedTemporalTypeException; import java.time.temporal.ValueRange; import java.util.List; -import java.util.function.Predicate; +import java.util.function.IntPredicate; import org.junit.Test; import org.junit.runner.RunWith; @@ -310,7 +310,7 @@ public void test_chronology_dateYearDay_badDate() { //----------------------------------------------------------------------- @Test public void test_isLeapYear_loop() { - Predicate isLeapYear = year -> { + IntPredicate isLeapYear = year -> { return ((year & 3) == 0) && ((year % 100) != 0 || (year % 400) == 0); }; diff --git a/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java b/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java index 36f4736c..6aa62874 100644 --- a/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java @@ -72,7 +72,7 @@ import java.time.temporal.ValueRange; import java.time.temporal.WeekFields; import java.util.List; -import java.util.function.Predicate; +import java.util.function.IntPredicate; import org.junit.Assert; import org.junit.Test; @@ -318,7 +318,7 @@ public void test_chronology_dateYearDay_badDate() { //----------------------------------------------------------------------- @Test public void test_isLeapYear_loop() { - Predicate isLeapYear = year -> { + IntPredicate isLeapYear = year -> { int lastTwoDigits = Math.abs(year % 100); return (year % 400 != 0 && (lastTwoDigits == 0 || lastTwoDigits % 6 == 0)) || lastTwoDigits == 99; }; From 15849c2c6ad2ec4aa9413da63485bee123cee004 Mon Sep 17 00:00:00 2001 From: "Anosh D. Ullenius" Date: Tue, 28 Apr 2020 09:04:14 +0200 Subject: [PATCH 174/279] Minor. Re-added static modifier for enums --- src/main/java/org/threeten/extra/PackedFields.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/threeten/extra/PackedFields.java b/src/main/java/org/threeten/extra/PackedFields.java index a06c0833..cd7fa1cb 100644 --- a/src/main/java/org/threeten/extra/PackedFields.java +++ b/src/main/java/org/threeten/extra/PackedFields.java @@ -115,7 +115,7 @@ private PackedFields() { /** * Implementation of packed date. */ - private enum PackedDate implements TemporalField { + private static enum PackedDate implements TemporalField { INSTANCE; private static final ValueRange RANGE = ValueRange.of(10000101, 99991231); @@ -220,7 +220,7 @@ public String toString() { /** * Implementation of packed hour-min. */ - private enum PackedHourMin implements TemporalField { + private static enum PackedHourMin implements TemporalField { INSTANCE; private static final ValueRange RANGE = ValueRange.of(0, 2359); @@ -311,7 +311,7 @@ public String toString() { /** * Implementation of packed hour-min-sec. */ - private enum PackedTime implements TemporalField { + private static enum PackedTime implements TemporalField { INSTANCE; private static final ValueRange RANGE = ValueRange.of(0, 235959); From a344b3616d9b091f234a6a953f3ecfc50cdbb13f Mon Sep 17 00:00:00 2001 From: "Anosh D. Ullenius" Date: Tue, 28 Apr 2020 11:11:33 +0200 Subject: [PATCH 175/279] Minor. Static modifier for enum --- src/main/java/org/threeten/extra/Temporals.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/threeten/extra/Temporals.java b/src/main/java/org/threeten/extra/Temporals.java index 8a977d96..0b3f21c2 100644 --- a/src/main/java/org/threeten/extra/Temporals.java +++ b/src/main/java/org/threeten/extra/Temporals.java @@ -130,7 +130,7 @@ public static TemporalAdjuster previousWorkingDayOrSame() { /** * Enum implementing the adjusters. */ - private enum Adjuster implements TemporalAdjuster { + private static enum Adjuster implements TemporalAdjuster { /** Next working day adjuster. */ NEXT_WORKING { @Override From b8115c03bfc0848eff36e3ccf6a7812027f3b2e6 Mon Sep 17 00:00:00 2001 From: Alexander Kolinchenko Date: Thu, 14 May 2020 11:50:39 +0300 Subject: [PATCH 176/279] Fix errors in Russian locale WordBased output for numbers ending with 1 - add new predicate End1NotEnd11 - fix wordbased_ru.properties - add tests Fixes ThreeTen/threeten-extra#157 --- .../org/threeten/extra/AmountFormats.java | 10 + .../threeten/extra/wordbased_ru.properties | 16 +- .../org/threeten/extra/TestAmountFormats.java | 279 ++++++++++++++++-- 3 files changed, 279 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/threeten/extra/AmountFormats.java b/src/main/java/org/threeten/extra/AmountFormats.java index 06c29117..9bf07aba 100644 --- a/src/main/java/org/threeten/extra/AmountFormats.java +++ b/src/main/java/org/threeten/extra/AmountFormats.java @@ -124,6 +124,15 @@ public final class AmountFormats { * The predicate that matches 1 or -1. */ private static final IntPredicate PREDICATE_1 = value -> value == 1 || value == -1; + /** + * The predicate that matches numbers ending 1 but not ending 11. + */ + private static final IntPredicate PREDICATE_END1_NOT11 = value -> { + int abs = Math.abs(value); + int last = abs % 10; + int secondLast = (abs % 100) / 10; + return (last == 1 && secondLast != 1); + }; /** * The predicate that matches numbers ending 2, 3 or 4, but not ending 12, 13 or 14. */ @@ -373,6 +382,7 @@ private IntPredicate findPredicate(String predicateStr) { switch (predicateStr) { case "One": return PREDICATE_1; case "End234NotTeens": return PREDICATE_END234_NOTTEENS; + case "End1Not11": return PREDICATE_END1_NOT11; default: throw new IllegalStateException("Invalid word-based resource"); } } diff --git a/src/main/resources/org/threeten/extra/wordbased_ru.properties b/src/main/resources/org/threeten/extra/wordbased_ru.properties index cefc8eec..cea63ec6 100644 --- a/src/main/resources/org/threeten/extra/wordbased_ru.properties +++ b/src/main/resources/org/threeten/extra/wordbased_ru.properties @@ -4,19 +4,19 @@ WordBased.commandand=,\u0438 WordBased.commaspaceand=, \u0438 WordBased.commaspace=,\u0020 WordBased.spaceandspace=\ \u0438\u0020 -WordBased.years.predicates=One|||End234NotTeens +WordBased.years.predicates=End1Not11|||End234NotTeens WordBased.years.list=\ \u0433\u043E\u0434||| \u0433\u043E\u0434\u0430||| \u043B\u0435\u0442 -WordBased.months.predicates=One|||End234NotTeens +WordBased.months.predicates=End1Not11|||End234NotTeens WordBased.months.list=\ \u043C\u0435\u0441\u044F\u0446||| \u043C\u0435\u0441\u044F\u0446\u0430||| \u043C\u0435\u0441\u044F\u0446\u0435\u0432 -WordBased.weeks.predicates=One|||End234NotTeens +WordBased.weeks.predicates=End1Not11|||End234NotTeens WordBased.weeks.list=\ \u043D\u0435\u0434\u0435\u043B\u044F||| \u043D\u0435\u0434\u0435\u043B\u0438||| \u043D\u0435\u0434\u0435\u043B\u044C -WordBased.days.predicates=One|||End234NotTeens +WordBased.days.predicates=End1Not11|||End234NotTeens WordBased.days.list=\ \u0434\u0435\u043D\u044C||| \u0434\u043D\u044F||| \u0434\u043D\u0435\u0439 -WordBased.hours.predicates=One|||End234NotTeens +WordBased.hours.predicates=End1Not11|||End234NotTeens WordBased.hours.list=\ \u0447\u0430\u0441||| \u0447\u0430\u0441\u0430||| \u0447\u0430\u0441\u043E\u0432 -WordBased.minutes.predicates=One|||End234NotTeens +WordBased.minutes.predicates=End1Not11|||End234NotTeens WordBased.minutes.list=\ \u043C\u0438\u043D\u0443\u0442\u0430||| \u043C\u0438\u043D\u0443\u0442\u044B||| \u043C\u0438\u043D\u0443\u0442 -WordBased.seconds.predicates=One|||End234NotTeens +WordBased.seconds.predicates=End1Not11|||End234NotTeens WordBased.seconds.list=\ \u0441\u0435\u043A\u0443\u043D\u0434\u0430||| \u0441\u0435\u043A\u0443\u043D\u0434\u044B||| \u0441\u0435\u043A\u0443\u043D\u0434 -WordBased.milliseconds.predicates=One|||End234NotTeens +WordBased.milliseconds.predicates=End1Not11|||End234NotTeens WordBased.milliseconds.list=\ \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434\u0430||| \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434\u044B||| \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434 diff --git a/src/test/java/org/threeten/extra/TestAmountFormats.java b/src/test/java/org/threeten/extra/TestAmountFormats.java index 7542bfd1..cbb401f1 100644 --- a/src/test/java/org/threeten/extra/TestAmountFormats.java +++ b/src/test/java/org/threeten/extra/TestAmountFormats.java @@ -177,7 +177,7 @@ public void test_wordBased_pl_formatStandard() { } @Test - public void test_wordBased_pl_predicatex() { + public void test_wordBased_pl_predicate() { assertEquals("1 rok", AmountFormats.wordBased(Period.ofYears(1), PL)); assertEquals("2 lata", AmountFormats.wordBased(Period.ofYears(2), PL)); assertEquals("5 lat", AmountFormats.wordBased(Period.ofYears(5), PL)); @@ -279,23 +279,266 @@ public void test_wordBased_pl_predicatex() { assertEquals("36 godzin i 55 minut", AmountFormats.wordBased(Duration.ofMinutes(2215), PL)); } + // ----------------------------------------------------------------------- + // wordBased "ru" locale + // ----------------------------------------------------------------------- @Test - public void test_wordBased_ru_predicate() { - assertEquals("1 \u0433\u043E\u0434", AmountFormats.wordBased(Period.ofYears(1), RU)); - assertEquals("2 \u0433\u043E\u0434\u0430", AmountFormats.wordBased(Period.ofYears(2), RU)); - assertEquals("3 \u0433\u043E\u0434\u0430", AmountFormats.wordBased(Period.ofYears(3), RU)); - assertEquals("4 \u0433\u043E\u0434\u0430", AmountFormats.wordBased(Period.ofYears(4), RU)); - assertEquals("5 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(5), RU)); - assertEquals("11 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(11), RU)); - assertEquals("12 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(12), RU)); - assertEquals("13 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(13), RU)); - assertEquals("14 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(14), RU)); - assertEquals("15 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(15), RU)); - assertEquals("21 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(21), RU)); - assertEquals("22 \u0433\u043E\u0434\u0430", AmountFormats.wordBased(Period.ofYears(22), RU)); - assertEquals("24 \u0433\u043E\u0434\u0430", AmountFormats.wordBased(Period.ofYears(24), RU)); - assertEquals("25 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(25), RU)); - assertEquals("31 \u043B\u0435\u0442", AmountFormats.wordBased(Period.ofYears(31), RU)); - assertEquals("32 \u0433\u043E\u0434\u0430", AmountFormats.wordBased(Period.ofYears(32), RU)); + public void test_wordBased_ru_formatStandard() { + Period period = Period.ofYears(1).plusMonths(2).plusDays(3); + Duration duration = Duration.ofHours(5).plusMinutes(6).plusSeconds(7).plusNanos(8_000_000L); + + String expected = "1 \u0433\u043E\u0434, 2 \u043C\u0435\u0441\u044F\u0446\u0430," + + " 3 \u0434\u043D\u044F, 5 \u0447\u0430\u0441\u043e\u0432, 6 \u043c\u0438\u043d\u0443\u0442," + + " 7 \u0441\u0435\u043A\u0443\u043D\u0434 \u0438 8 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434"; + + assertEquals(expected, AmountFormats.wordBased(period, duration, RU)); + } + + // ----------------------------------------------------------------------- + @Test + @UseDataProvider("wordBased_ru_formatSeparator") + public void test_wordBased_ru_formatSeparator(String expected, Duration duration) { + assertEquals(expected, AmountFormats.wordBased(duration, RU)); + } + + @DataProvider + public static Object[][] wordBased_ru_formatSeparator() { + return new Object[][]{ + {"18 \u0447\u0430\u0441\u043E\u0432 \u0438 32 \u043C\u0438\u043D\u0443\u0442\u044B", Duration.ofMinutes(1112)}, + {"1 \u0441\u0435\u043A\u0443\u043D\u0434\u0430 \u0438 112 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434", Duration.ofMillis(1112)}, + }; + } + + // ----------------------------------------------------------------------- + @Test + @UseDataProvider("wordBased_ru_period_predicate") + public void test_wordBased_ru_period_predicate(String expected, Period period) { + assertEquals(expected, AmountFormats.wordBased(period, RU)); + } + + @DataProvider + public static Object[][] wordBased_ru_period_predicate() { + return new Object[][]{ + +// год \u0433\u043E\u0434 +// года \u0433\u043E\u0434\u0430 +// лет \u043B\u0435\u0442 + {"1 \u0433\u043E\u0434", Period.ofYears(1)}, + {"11 \u043B\u0435\u0442", Period.ofYears(11)}, + {"101 \u0433\u043E\u0434", Period.ofYears(101)}, + {"111 \u043B\u0435\u0442", Period.ofYears(111)}, + {"121 \u0433\u043E\u0434", Period.ofYears(121)}, + {"2001 \u0433\u043E\u0434", Period.ofYears(2001)}, + {"2 \u0433\u043E\u0434\u0430", Period.ofYears(2)}, + {"3 \u0433\u043E\u0434\u0430", Period.ofYears(3)}, + {"4 \u0433\u043E\u0434\u0430", Period.ofYears(4)}, + {"12 \u043B\u0435\u0442", Period.ofYears(12)}, + {"13 \u043B\u0435\u0442", Period.ofYears(13)}, + {"14 \u043B\u0435\u0442", Period.ofYears(14)}, + {"21 \u0433\u043E\u0434", Period.ofYears(21)}, + {"22 \u0433\u043E\u0434\u0430", Period.ofYears(22)}, + {"23 \u0433\u043E\u0434\u0430", Period.ofYears(23)}, + {"24 \u0433\u043E\u0434\u0430", Period.ofYears(24)}, + {"102 \u0433\u043E\u0434\u0430", Period.ofYears(102)}, + {"105 \u043B\u0435\u0442", Period.ofYears(105)}, + {"112 \u043B\u0435\u0442", Period.ofYears(112)}, + {"113 \u043B\u0435\u0442", Period.ofYears(113)}, + {"124 \u0433\u043E\u0434\u0430", Period.ofYears(124)}, + {"5 \u043B\u0435\u0442", Period.ofYears(5)}, + {"15 \u043B\u0435\u0442", Period.ofYears(15)}, + {"25 \u043B\u0435\u0442", Period.ofYears(25)}, + {"106 \u043B\u0435\u0442", Period.ofYears(106)}, + {"1005 \u043B\u0435\u0442", Period.ofYears(1005)}, + {"31 \u0433\u043E\u0434", Period.ofYears(31)}, + {"32 \u0433\u043E\u0434\u0430", Period.ofYears(32)}, + +// меÑÑц \u043C\u0435\u0441\u044F\u0446 +// меÑÑца \u043C\u0435\u0441\u044F\u0446\u0430 +// меÑÑцев \u043C\u0435\u0441\u044F\u0446\u0435\u0432 + {"1 \u043C\u0435\u0441\u044F\u0446", Period.ofMonths(1)}, + {"11 \u043C\u0435\u0441\u044F\u0446\u0435\u0432", Period.ofMonths(11)}, + {"21 \u043C\u0435\u0441\u044F\u0446", Period.ofMonths(21)}, + {"101 \u043C\u0435\u0441\u044F\u0446", Period.ofMonths(101)}, + {"111 \u043C\u0435\u0441\u044F\u0446\u0435\u0432", Period.ofMonths(111)}, + {"121 \u043C\u0435\u0441\u044F\u0446", Period.ofMonths(121)}, + {"2001 \u043C\u0435\u0441\u044F\u0446", Period.ofMonths(2001)}, + {"2 \u043C\u0435\u0441\u044F\u0446\u0430", Period.ofMonths(2)}, + {"3 \u043C\u0435\u0441\u044F\u0446\u0430", Period.ofMonths(3)}, + {"4 \u043C\u0435\u0441\u044F\u0446\u0430", Period.ofMonths(4)}, + {"12 \u043C\u0435\u0441\u044F\u0446\u0435\u0432", Period.ofMonths(12)}, + {"13 \u043C\u0435\u0441\u044F\u0446\u0435\u0432", Period.ofMonths(13)}, + {"14 \u043C\u0435\u0441\u044F\u0446\u0435\u0432", Period.ofMonths(14)}, + {"22 \u043C\u0435\u0441\u044F\u0446\u0430", Period.ofMonths(22)}, + {"23 \u043C\u0435\u0441\u044F\u0446\u0430", Period.ofMonths(23)}, + {"24 \u043C\u0435\u0441\u044F\u0446\u0430", Period.ofMonths(24)}, + {"102 \u043C\u0435\u0441\u044F\u0446\u0430", Period.ofMonths(102)}, + {"112 \u043C\u0435\u0441\u044F\u0446\u0435\u0432", Period.ofMonths(112)}, + {"124 \u043C\u0435\u0441\u044F\u0446\u0430", Period.ofMonths(124)}, + {"5 \u043C\u0435\u0441\u044F\u0446\u0435\u0432", Period.ofMonths(5)}, + {"15 \u043C\u0435\u0441\u044F\u0446\u0435\u0432", Period.ofMonths(15)}, + {"25 \u043C\u0435\u0441\u044F\u0446\u0435\u0432", Period.ofMonths(25)}, + {"105 \u043C\u0435\u0441\u044F\u0446\u0435\u0432", Period.ofMonths(105)}, + {"1005 \u043C\u0435\u0441\u044F\u0446\u0435\u0432", Period.ofMonths(1005)}, + +// Ð½ÐµÐ´ÐµÐ»Ñ \u043D\u0435\u0434\u0435\u043B\u044F +// недели \u043D\u0435\u0434\u0435\u043B\u0438 +// недель \u043D\u0435\u0434\u0435\u043B\u044C + {"1 \u043D\u0435\u0434\u0435\u043B\u044F", Period.ofWeeks(1)}, + {"11 \u043D\u0435\u0434\u0435\u043B\u044C", Period.ofWeeks(11)}, + {"21 \u043D\u0435\u0434\u0435\u043B\u044F", Period.ofWeeks(21)}, + {"101 \u043D\u0435\u0434\u0435\u043B\u044F", Period.ofWeeks(101)}, + {"111 \u043D\u0435\u0434\u0435\u043B\u044C", Period.ofWeeks(111)}, + {"121 \u043D\u0435\u0434\u0435\u043B\u044F", Period.ofWeeks(121)}, + {"2001 \u043D\u0435\u0434\u0435\u043B\u044F", Period.ofWeeks(2001)}, + {"2 \u043D\u0435\u0434\u0435\u043B\u0438", Period.ofWeeks(2)}, + {"3 \u043D\u0435\u0434\u0435\u043B\u0438", Period.ofWeeks(3)}, + {"4 \u043D\u0435\u0434\u0435\u043B\u0438", Period.ofWeeks(4)}, + {"12 \u043D\u0435\u0434\u0435\u043B\u044C", Period.ofWeeks(12)}, + {"13 \u043D\u0435\u0434\u0435\u043B\u044C", Period.ofWeeks(13)}, + {"14 \u043D\u0435\u0434\u0435\u043B\u044C", Period.ofWeeks(14)}, + {"22 \u043D\u0435\u0434\u0435\u043B\u0438", Period.ofWeeks(22)}, + {"23 \u043D\u0435\u0434\u0435\u043B\u0438", Period.ofWeeks(23)}, + {"24 \u043D\u0435\u0434\u0435\u043B\u0438", Period.ofWeeks(24)}, + {"102 \u043D\u0435\u0434\u0435\u043B\u0438", Period.ofWeeks(102)}, + {"112 \u043D\u0435\u0434\u0435\u043B\u044C", Period.ofWeeks(112)}, + {"124 \u043D\u0435\u0434\u0435\u043B\u0438", Period.ofWeeks(124)}, + {"5 \u043D\u0435\u0434\u0435\u043B\u044C", Period.ofWeeks(5)}, + {"15 \u043D\u0435\u0434\u0435\u043B\u044C", Period.ofWeeks(15)}, + {"25 \u043D\u0435\u0434\u0435\u043B\u044C", Period.ofWeeks(25)}, + {"105 \u043D\u0435\u0434\u0435\u043B\u044C", Period.ofWeeks(105)}, + {"1005 \u043D\u0435\u0434\u0435\u043B\u044C", Period.ofWeeks(1005)}, + +// день \u0434\u0435\u043D\u044C +// Ð´Ð½Ñ \u0434\u043D\u044F +// дней \u0434\u043D\u0435\u0439 + {"1 \u0434\u0435\u043D\u044C", Period.ofDays(1)}, + {"11 \u0434\u043D\u0435\u0439", Period.ofDays(11)}, + {"101 \u0434\u0435\u043D\u044C", Period.ofDays(101)}, + {"111 \u0434\u043D\u0435\u0439", Period.ofDays(111)}, + {"121 \u0434\u0435\u043D\u044C", Period.ofDays(121)}, + {"31 \u0434\u0435\u043D\u044C", Period.ofDays(31)}, + {"2001 \u0434\u0435\u043D\u044C", Period.ofDays(2001)}, + {"2 \u0434\u043D\u044F", Period.ofDays(2)}, + {"3 \u0434\u043D\u044F", Period.ofDays(3)}, + {"4 \u0434\u043D\u044F", Period.ofDays(4)}, + {"12 \u0434\u043D\u0435\u0439", Period.ofDays(12)}, + {"13 \u0434\u043D\u0435\u0439", Period.ofDays(13)}, + {"22 \u0434\u043D\u044F", Period.ofDays(22)}, + {"23 \u0434\u043D\u044F", Period.ofDays(23)}, + {"24 \u0434\u043D\u044F", Period.ofDays(24)}, + {"102 \u0434\u043D\u044F", Period.ofDays(102)}, + {"113 \u0434\u043D\u0435\u0439", Period.ofDays(113)}, + {"124 \u0434\u043D\u044F", Period.ofDays(124)}, + {"5 \u0434\u043D\u0435\u0439", Period.ofDays(5)}, + {"15 \u0434\u043D\u0435\u0439", Period.ofDays(15)}, + {"25 \u0434\u043D\u0435\u0439", Period.ofDays(25)}, + {"106 \u0434\u043D\u0435\u0439", Period.ofDays(106)}, + {"1005 \u0434\u043D\u0435\u0439", Period.ofDays(1005)} + }; + } + + // ----------------------------------------------------------------------- + @Test + @UseDataProvider("wordBased_ru_duration_predicate") + public void test_wordBased_ru_duration_predicate(String expected, Duration duration) { + assertEquals(expected, AmountFormats.wordBased(duration, RU)); + } + + @DataProvider + public static Object[][] wordBased_ru_duration_predicate() { + return new Object[][]{ + +// Ñ‡Ð°Ñ \u0447\u0430\u0441 +// чаÑа \u0447\u0430\u0441\u0430 +// чаÑов \u0447\u0430\u0441\u043E\u0432 + {"1 \u0447\u0430\u0441", Duration.ofHours(1)}, + {"11 \u0447\u0430\u0441\u043e\u0432", Duration.ofHours(11)}, + {"21 \u0447\u0430\u0441", Duration.ofHours(21)}, + {"101 \u0447\u0430\u0441", Duration.ofHours(101)}, + {"111 \u0447\u0430\u0441\u043e\u0432", Duration.ofHours(111)}, + {"121 \u0447\u0430\u0441", Duration.ofHours(121)}, + {"2001 \u0447\u0430\u0441", Duration.ofHours(2001)}, + {"2 \u0447\u0430\u0441\u0430", Duration.ofHours(2)}, + {"3 \u0447\u0430\u0441\u0430", Duration.ofHours(3)}, + {"4 \u0447\u0430\u0441\u0430", Duration.ofHours(4)}, + {"12 \u0447\u0430\u0441\u043e\u0432", Duration.ofHours(12)}, + {"13 \u0447\u0430\u0441\u043e\u0432", Duration.ofHours(13)}, + {"14 \u0447\u0430\u0441\u043e\u0432", Duration.ofHours(14)}, + {"22 \u0447\u0430\u0441\u0430", Duration.ofHours(22)}, + {"23 \u0447\u0430\u0441\u0430", Duration.ofHours(23)}, + {"24 \u0447\u0430\u0441\u0430", Duration.ofHours(24)}, + {"102 \u0447\u0430\u0441\u0430", Duration.ofHours(102)}, + {"112 \u0447\u0430\u0441\u043e\u0432", Duration.ofHours(112)}, + {"124 \u0447\u0430\u0441\u0430", Duration.ofHours(124)}, + {"5 \u0447\u0430\u0441\u043e\u0432", Duration.ofHours(5)}, + {"15 \u0447\u0430\u0441\u043e\u0432", Duration.ofHours(15)}, + {"25 \u0447\u0430\u0441\u043e\u0432", Duration.ofHours(25)}, + {"105 \u0447\u0430\u0441\u043e\u0432", Duration.ofHours(105)}, + {"1005 \u0447\u0430\u0441\u043e\u0432", Duration.ofHours(1005)}, + +// минута \u043C\u0438\u043D\u0443\u0442\u0430 +// минуты \u043C\u0438\u043D\u0443\u0442\u044B +// минут \u043C\u0438\u043D\u0443\u0442 + {"1 \u043c\u0438\u043d\u0443\u0442\u0430", Duration.ofMinutes(1)}, + {"11 \u043c\u0438\u043d\u0443\u0442", Duration.ofMinutes(11)}, + {"21 \u043c\u0438\u043d\u0443\u0442\u0430", Duration.ofMinutes(21)}, + {"2 \u043c\u0438\u043d\u0443\u0442\u044b", Duration.ofMinutes(2)}, + {"3 \u043c\u0438\u043d\u0443\u0442\u044b", Duration.ofMinutes(3)}, + {"4 \u043c\u0438\u043d\u0443\u0442\u044b", Duration.ofMinutes(4)}, + {"12 \u043c\u0438\u043d\u0443\u0442", Duration.ofMinutes(12)}, + {"13 \u043c\u0438\u043d\u0443\u0442", Duration.ofMinutes(13)}, + {"14 \u043c\u0438\u043d\u0443\u0442", Duration.ofMinutes(14)}, + {"22 \u043c\u0438\u043d\u0443\u0442\u044b", Duration.ofMinutes(22)}, + {"23 \u043c\u0438\u043d\u0443\u0442\u044b", Duration.ofMinutes(23)}, + {"24 \u043c\u0438\u043d\u0443\u0442\u044b", Duration.ofMinutes(24)}, + {"5 \u043c\u0438\u043d\u0443\u0442", Duration.ofMinutes(5)}, + {"15 \u043c\u0438\u043d\u0443\u0442", Duration.ofMinutes(15)}, + {"25 \u043c\u0438\u043d\u0443\u0442", Duration.ofMinutes(25)}, + +// Ñекунда \u0441\u0435\u043A\u0443\u043D\u0434\u0430 +// Ñекунды \u0441\u0435\u043A\u0443\u043D\u0434\u044B +// Ñекунд \u0441\u0435\u043A\u0443\u043D\u0434 + {"1 \u0441\u0435\u043A\u0443\u043D\u0434\u0430", Duration.ofSeconds(1)}, + {"11 \u0441\u0435\u043A\u0443\u043D\u0434", Duration.ofSeconds(11)}, + {"21 \u0441\u0435\u043A\u0443\u043D\u0434\u0430", Duration.ofSeconds(21)}, + {"2 \u0441\u0435\u043A\u0443\u043D\u0434\u044B", Duration.ofSeconds(2)}, + {"3 \u0441\u0435\u043A\u0443\u043D\u0434\u044B", Duration.ofSeconds(3)}, + {"4 \u0441\u0435\u043A\u0443\u043D\u0434\u044B", Duration.ofSeconds(4)}, + {"12 \u0441\u0435\u043A\u0443\u043D\u0434", Duration.ofSeconds(12)}, + {"13 \u0441\u0435\u043A\u0443\u043D\u0434", Duration.ofSeconds(13)}, + {"14 \u0441\u0435\u043A\u0443\u043D\u0434", Duration.ofSeconds(14)}, + {"22 \u0441\u0435\u043A\u0443\u043D\u0434\u044B", Duration.ofSeconds(22)}, + {"23 \u0441\u0435\u043A\u0443\u043D\u0434\u044B", Duration.ofSeconds(23)}, + {"24 \u0441\u0435\u043A\u0443\u043D\u0434\u044B", Duration.ofSeconds(24)}, + {"5 \u0441\u0435\u043A\u0443\u043D\u0434", Duration.ofSeconds(5)}, + {"15 \u0441\u0435\u043A\u0443\u043D\u0434", Duration.ofSeconds(15)}, + {"25 \u0441\u0435\u043A\u0443\u043D\u0434", Duration.ofSeconds(25)}, + +// миллиÑекунда \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434\u0430 +// миллиÑекунды \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434\u044B +// миллиÑекунд \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434 + {"1 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434\u0430", Duration.ofMillis(1)}, + {"11 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434", Duration.ofMillis(11)}, + {"21 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434\u0430", Duration.ofMillis(21)}, + {"101 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434\u0430", Duration.ofMillis(101)}, + {"111 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434", Duration.ofMillis(111)}, + {"121 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434\u0430", Duration.ofMillis(121)}, + {"2 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434\u044B", Duration.ofMillis(2)}, + {"3 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434\u044B", Duration.ofMillis(3)}, + {"4 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434\u044B", Duration.ofMillis(4)}, + {"12 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434", Duration.ofMillis(12)}, + {"13 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434", Duration.ofMillis(13)}, + {"14 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434", Duration.ofMillis(14)}, + {"22 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434\u044B", Duration.ofMillis(22)}, + {"23 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434\u044B", Duration.ofMillis(23)}, + {"24 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434\u044B", Duration.ofMillis(24)}, + {"102 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434\u044B", Duration.ofMillis(102)}, + {"112 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434", Duration.ofMillis(112)}, + {"124 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434\u044B", Duration.ofMillis(124)}, + {"5 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434", Duration.ofMillis(5)}, + {"15 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434", Duration.ofMillis(15)}, + {"25 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434", Duration.ofMillis(25)}, + {"105 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434", Duration.ofMillis(105)} + }; } } From 4131b74e5758c4e504bf85c7654af376dfb7ce77 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2020 22:33:58 +0100 Subject: [PATCH 177/279] Bump junit from 4.12 to 4.13.1 (#162) Bumps [junit](https://github.com/junit-team/junit4) from 4.12 to 4.13.1. - [Release notes](https://github.com/junit-team/junit4/releases) - [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.12.md) - [Commits](https://github.com/junit-team/junit4/compare/r4.12...r4.13.1) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7623f985..325b2de3 100644 --- a/pom.xml +++ b/pom.xml @@ -474,7 +474,7 @@ junit junit - 4.12 + 4.13.1 test From 2d74b42b640308598db3bef0ff0a7936f47e317d Mon Sep 17 00:00:00 2001 From: JB Nizet Date: Sun, 29 Nov 2020 23:47:12 +0100 Subject: [PATCH 178/279] Fix javadoc of Interval isAfter and isBefore (#159) --- .../java/org/threeten/extra/Interval.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/threeten/extra/Interval.java b/src/main/java/org/threeten/extra/Interval.java index 0aaf9dbd..996f5edf 100644 --- a/src/main/java/org/threeten/extra/Interval.java +++ b/src/main/java/org/threeten/extra/Interval.java @@ -260,7 +260,7 @@ public Instant getStart() { return start; } - /** + /** * Gets the end of this time interval, exclusive. *

      * This will return {@link Instant#MAX} if the range is unbounded at the end. @@ -277,7 +277,7 @@ public Instant getEnd() { * Checks if the range is empty. *

      * An empty range occurs when the start date equals the inclusive end date. - * + * * @return true if the range is empty */ public boolean isEmpty() { @@ -286,7 +286,7 @@ public boolean isEmpty() { /** * Checks if the start of the interval is unbounded. - * + * * @return true if start is unbounded */ public boolean isUnboundedStart() { @@ -295,7 +295,7 @@ public boolean isUnboundedStart() { /** * Checks if the end of the interval is unbounded. - * + * * @return true if end is unbounded */ public boolean isUnboundedEnd() { @@ -408,7 +408,7 @@ public boolean overlaps(Interval other) { *

      * This finds the intersection of two intervals. * This throws an exception if the two intervals are not {@linkplain #isConnected(Interval) connected}. - * + * * @param other the other interval to check for, not null * @return the interval that is the intersection of the two intervals * @throws DateTimeException if the intervals do not connect @@ -436,7 +436,7 @@ public Interval intersection(Interval other) { *

      * This finds the union of two intervals. * This throws an exception if the two intervals are not {@linkplain #isConnected(Interval) connected}. - * + * * @param other the other interval to check for, not null * @return the interval that is the union of the two intervals * @throws DateTimeException if the intervals do not connect @@ -464,7 +464,7 @@ public Interval union(Interval other) { *

      * The result of this method will {@linkplain #encloses(Interval) enclose} * this interval and the specified interval. - * + * * @param other the other interval to check for, not null * @return the interval that spans the two intervals */ @@ -481,7 +481,7 @@ public Interval span(Interval other) { /** * Checks if this interval is after the specified instant. *

      - * The result is true if this instant starts after the specified instant. + * The result is true if this interval starts after the specified instant. * An empty interval behaves as though it is an instant for comparison purposes. * * @param instant the other instant to compare to, not null @@ -494,13 +494,13 @@ public boolean isAfter(Instant instant) { /** * Checks if this interval is before the specified instant. *

      - * The result is true if this instant ends before the specified instant. + * The result is true if this interval ends before the specified instant. * Since intervals do not include their end points, this will return true if the * instant equals the end of the interval. * An empty interval behaves as though it is an instant for comparison purposes. * * @param instant the other instant to compare to, not null - * @return true if the start of this interval is before the specified instant + * @return true if the end of this interval is before or equal to the specified instant */ public boolean isBefore(Instant instant) { return end.compareTo(instant) <= 0 && start.compareTo(instant) < 0; @@ -510,13 +510,13 @@ public boolean isBefore(Instant instant) { /** * Checks if this interval is after the specified interval. *

      - * The result is true if this instant starts after the end of the specified interval. + * The result is true if this interval starts after the end of the specified interval. * Since intervals do not include their end points, this will return true if the - * instant equals the end of the interval. + * two intervals abut. * An empty interval behaves as though it is an instant for comparison purposes. * * @param interval the other interval to compare to, not null - * @return true if this instant is after the specified instant + * @return true if this interval is after the specified interval */ public boolean isAfter(Interval interval) { return start.compareTo(interval.end) >= 0 && !interval.equals(this); @@ -525,13 +525,13 @@ public boolean isAfter(Interval interval) { /** * Checks if this interval is before the specified interval. *

      - * The result is true if this instant ends before the start of the specified interval. + * The result is true if this interval ends before the start of the specified interval. * Since intervals do not include their end points, this will return true if the * two intervals abut. * An empty interval behaves as though it is an instant for comparison purposes. * * @param interval the other interval to compare to, not null - * @return true if this instant is before the specified instant + * @return true if this interval is before the specified interval */ public boolean isBefore(Interval interval) { return end.compareTo(interval.start) <= 0 && !interval.equals(this); From cc42d328e89c36b2a4d11b00d855a5efefc9c75e Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 29 Nov 2020 22:55:31 +0000 Subject: [PATCH 179/279] Make YearWeek implement Temporal (#165) * Make YearWeek implement Temporal * Add tests for Temporal implementation by YearWeek (#163) * test: cover YearWeek.plus() * test: cover YearWeek.with() * test: cover YearWeek.until() * test: cover YearWeek.minus() * test: add more cases for YearWeek.until() * fix: YearWeek.until() returning wrong values Co-authored-by: Max Poliakov <48586126+Jaimies@users.noreply.github.com> --- .../java/org/threeten/extra/YearWeek.java | 311 +++++++++++++++++- .../java/org/threeten/extra/TestYearWeek.java | 114 +++++++ 2 files changed, 419 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/threeten/extra/YearWeek.java b/src/main/java/org/threeten/extra/YearWeek.java index d82bf2d7..c7e95f69 100644 --- a/src/main/java/org/threeten/extra/YearWeek.java +++ b/src/main/java/org/threeten/extra/YearWeek.java @@ -31,9 +31,12 @@ */ package org.threeten.extra; +import static java.time.DayOfWeek.MONDAY; import static java.time.DayOfWeek.THURSDAY; import static java.time.DayOfWeek.WEDNESDAY; +import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.IsoFields.WEEK_BASED_YEAR; +import static java.time.temporal.IsoFields.WEEK_BASED_YEARS; import static java.time.temporal.IsoFields.WEEK_OF_WEEK_BASED_YEAR; import java.io.Serializable; @@ -41,6 +44,7 @@ import java.time.DateTimeException; import java.time.DayOfWeek; import java.time.LocalDate; +import java.time.Period; import java.time.Year; import java.time.ZoneId; import java.time.chrono.Chronology; @@ -50,13 +54,16 @@ import java.time.format.DateTimeParseException; import java.time.format.SignStyle; import java.time.temporal.ChronoField; +import java.time.temporal.ChronoUnit; import java.time.temporal.IsoFields; import java.time.temporal.Temporal; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjuster; +import java.time.temporal.TemporalAmount; import java.time.temporal.TemporalField; import java.time.temporal.TemporalQueries; import java.time.temporal.TemporalQuery; +import java.time.temporal.TemporalUnit; import java.time.temporal.UnsupportedTemporalTypeException; import java.time.temporal.ValueRange; import java.util.Objects; @@ -92,7 +99,7 @@ * identity hash code or use the distinction between equals() and ==. */ public final class YearWeek - implements TemporalAccessor, TemporalAdjuster, Comparable, Serializable { + implements Temporal, TemporalAdjuster, Comparable, Serializable { /** * Serialization version. @@ -341,6 +348,37 @@ public boolean isSupported(TemporalField field) { return field != null && field.isSupportedBy(this); } + /** + * Checks if the specified unit is supported. + *

      + * This checks if the specified unit can be added to, or subtracted from, this date-time. + * If false, then calling the {@link #plus(long, TemporalUnit)} and + * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. + *

      + * If the unit is a {@link ChronoUnit} then the query is implemented here. + * The supported units are: + *

        + *
      • {@code WEEKS} + *
      • {@code WEEK_BASED_YEARS} + *
      + * All other {@code ChronoUnit} instances will return false. + *

      + * If the unit is not a {@code ChronoUnit}, then the result of this method + * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} + * passing {@code this} as the argument. + * Whether the unit is supported is determined by the unit. + * + * @param unit the unit to check, null returns false + * @return true if the unit can be added/subtracted, false if not + */ + @Override + public boolean isSupported(TemporalUnit unit) { + if (unit instanceof ChronoUnit) { + return unit == WEEKS || unit == WEEK_BASED_YEARS; + } + return unit != null && unit.isSupportedBy(this); + } + //----------------------------------------------------------------------- /** * Gets the range of valid values for the specified field. @@ -367,7 +405,7 @@ public ValueRange range(TemporalField field) { if (field == WEEK_OF_WEEK_BASED_YEAR) { return ValueRange.of(1, weekRange(year)); } - return TemporalAccessor.super.range(field); + return Temporal.super.range(field); } /** @@ -398,7 +436,7 @@ public int get(TemporalField field) { if (field == WEEK_OF_WEEK_BASED_YEAR) { return week; } - return TemporalAccessor.super.get(field); + return Temporal.super.get(field); } /** @@ -482,6 +520,75 @@ public int lengthOfYear() { } //----------------------------------------------------------------------- + /** + * Returns an adjusted copy of this year-week. + *

      + * This returns a {@code YearWeek}, based on this one, with the year-week adjusted. + * The adjustment takes place using the specified adjuster strategy object. + * Read the documentation of the adjuster to understand what adjustment will be made. + *

      + * The result of this method is obtained by invoking the + * {@link TemporalAdjuster#adjustInto(Temporal)} method on the + * specified adjuster passing {@code this} as the argument. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param adjuster the adjuster to use, not null + * @return a {@code YearWeek} based on {@code this} with the adjustment made, not null + * @throws DateTimeException if the adjustment cannot be made + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public YearWeek with(TemporalAdjuster adjuster) { + return (YearWeek) adjuster.adjustInto(this); + } + + /** + * Returns a copy of this year-week with the specified field set to a new value. + *

      + * This returns a {@code YearWeek}, based on this one, with the value + * for the specified field changed. + * This can be used to change any supported field, such as the year or week. + * If it is not possible to set the value, because the field is not supported or for + * some other reason, an exception is thrown. + *

      + * If the field is a {@link ChronoField} then the adjustment is implemented here. + * The supported fields behave as follows: + *

        + *
      • {@code WEEK_OF_WEEK_BASED_YEAR} - + * Returns a {@code YearWeek} with the specified week-of-year set as per {@link #withWeek(int)}. + *
      • {@code WEEK_BASED_YEAR} - + * Returns a {@code YearWeek} with the specified year set as per {@link #withYear(int)}. + *
      + *

      + * All {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. + *

      + * If the field is not a {@code ChronoField}, then the result of this method + * is obtained by invoking {@code TemporalField.adjustInto(Temporal, long)} + * passing {@code this} as the argument. In this case, the field determines + * whether and how to adjust the instant. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param field the field to set in the result, not null + * @param newValue the new value of the field in the result + * @return a {@code YearWeek} based on {@code this} with the specified field set, not null + * @throws DateTimeException if the field cannot be set + * @throws UnsupportedTemporalTypeException if the field is not supported + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public YearWeek with(TemporalField field, long newValue) { + if (field == WEEK_OF_WEEK_BASED_YEAR) { + return withWeek(WEEK_OF_WEEK_BASED_YEAR.range().checkValidIntValue(newValue, WEEK_OF_WEEK_BASED_YEAR)); + } else if (field == WEEK_BASED_YEAR) { + return withYear(WEEK_BASED_YEAR.range().checkValidIntValue(newValue, WEEK_BASED_YEAR)); + } else if (field instanceof ChronoField) { + throw new UnsupportedTemporalTypeException("Unsupported field: " + field); + } + return field.adjustInto(this, newValue); + } + /** * Returns a copy of this {@code YearWeek} with the week-based-year altered. *

      @@ -520,6 +627,75 @@ public YearWeek withWeek(int week) { } //----------------------------------------------------------------------- + /** + * Returns a copy of this year-week with the specified amount added. + *

      + * This returns a {@code YearWeek}, based on this one, with the specified amount added. + * The amount is typically {@link Period} but may be any other type implementing + * the {@link TemporalAmount} interface. + *

      + * The calculation is delegated to the amount object by calling + * {@link TemporalAmount#addTo(Temporal)}. The amount implementation is free + * to implement the addition in any way it wishes, however it typically + * calls back to {@link #plus(long, TemporalUnit)}. Consult the documentation + * of the amount implementation to determine if it can be successfully added. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param amountToAdd the amount to add, not null + * @return a {@code YearWeek} based on this year-week with the addition made, not null + * @throws DateTimeException if the addition cannot be made + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public YearWeek plus(TemporalAmount amountToAdd) { + return (YearWeek) amountToAdd.addTo(this); + } + + /** + * Returns a copy of this year-week with the specified amount added. + *

      + * This returns a {@code YearWeek}, based on this one, with the amount + * in terms of the unit added. If it is not possible to add the amount, because the + * unit is not supported or for some other reason, an exception is thrown. + *

      + * If the field is a {@link ChronoUnit} then the addition is implemented here. + * The supported fields behave as follows: + *

        + *
      • {@code WEEKS} - + * Returns a {@code YearWeek} with the weeks added as per {@link #plusWeeks(long)}. + *
      • {@code WEEK_BASED_YEARS} - + * Returns a {@code YearWeek} with the years added as per {@link #plusYears(long)}. + *
      + *

      + * All {@code ChronoUnit} instances will throw an {@code UnsupportedTemporalTypeException}. + *

      + * If the field is not a {@code ChronoUnit}, then the result of this method + * is obtained by invoking {@code TemporalUnit.addTo(Temporal, long)} + * passing {@code this} as the argument. In this case, the unit determines + * whether and how to perform the addition. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param amountToAdd the amount of the unit to add to the result, may be negative + * @param unit the unit of the amount to add, not null + * @return a {@code YearWeek} based on this year-week with the specified amount added, not null + * @throws DateTimeException if the addition cannot be made + * @throws UnsupportedTemporalTypeException if the unit is not supported + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public YearWeek plus(long amountToAdd, TemporalUnit unit) { + if (unit == WEEKS) { + return plusWeeks(amountToAdd); + } else if (unit == WEEK_BASED_YEARS) { + return plusYears(amountToAdd); + } else if (unit instanceof ChronoUnit) { + throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); + } + return unit.addTo(this, amountToAdd); + } + /** * Returns a copy of this year-week with the specified number of years added. *

      @@ -551,10 +727,60 @@ public YearWeek plusWeeks(long weeksToAdd) { if (weeksToAdd == 0) { return this; } - LocalDate mondayOfWeek = atDay(DayOfWeek.MONDAY).plusWeeks(weeksToAdd); + LocalDate mondayOfWeek = atDay(MONDAY).plusWeeks(weeksToAdd); return YearWeek.from(mondayOfWeek); } + //----------------------------------------------------------------------- + /** + * Returns a copy of this year-week with the specified amount subtracted. + *

      + * This returns a {@code YearWeek}, based on this one, with the specified amount subtracted. + * The amount is typically {@link Period} but may be any other type implementing + * the {@link TemporalAmount} interface. + *

      + * The calculation is delegated to the amount object by calling + * {@link TemporalAmount#subtractFrom(Temporal)}. The amount implementation is free + * to implement the subtraction in any way it wishes, however it typically + * calls back to {@link #minus(long, TemporalUnit)}. Consult the documentation + * of the amount implementation to determine if it can be successfully subtracted. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param amountToSubtract the amount to subtract, not null + * @return a {@code YearWeek} based on this year-week with the subtraction made, not null + * @throws DateTimeException if the subtraction cannot be made + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public YearWeek minus(TemporalAmount amountToSubtract) { + return (YearWeek) amountToSubtract.subtractFrom(this); + } + + /** + * Returns a copy of this year-week with the specified amount subtracted. + *

      + * This returns a {@code YearWeek}, based on this one, with the amount + * in terms of the unit subtracted. If it is not possible to subtract the amount, + * because the unit is not supported or for some other reason, an exception is thrown. + *

      + * This method is equivalent to {@link #plus(long, TemporalUnit)} with the amount negated. + * See that method for a full description of how addition, and thus subtraction, works. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param amountToSubtract the amount of the unit to subtract from the result, may be negative + * @param unit the unit of the amount to subtract, not null + * @return a {@code YearWeek} based on this year-week with the specified amount subtracted, not null + * @throws DateTimeException if the subtraction cannot be made + * @throws UnsupportedTemporalTypeException if the unit is not supported + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public YearWeek minus(long amountToSubtract, TemporalUnit unit) { + return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit)); + } + /** * Returns a copy of this year-week with the specified number of years subtracted. *

      @@ -586,7 +812,7 @@ public YearWeek minusWeeks(long weeksToSubtract) { if (weeksToSubtract == 0) { return this; } - LocalDate mondayOfWeek = atDay(DayOfWeek.MONDAY).minusWeeks(weeksToSubtract); + LocalDate mondayOfWeek = atDay(MONDAY).minusWeeks(weeksToSubtract); return YearWeek.from(mondayOfWeek); } @@ -615,7 +841,7 @@ public R query(TemporalQuery query) { if (query == TemporalQueries.chronology()) { return (R) IsoChronology.INSTANCE; } - return TemporalAccessor.super.query(query); + return Temporal.super.query(query); } /** @@ -653,6 +879,79 @@ public Temporal adjustInto(Temporal temporal) { return temporal.with(WEEK_BASED_YEAR, year).with(WEEK_OF_WEEK_BASED_YEAR, week); } + /** + * Calculates the amount of time until another year-week in terms of the specified unit. + *

      + * This calculates the amount of time between two {@code YearWeek} + * objects in terms of a single {@code TemporalUnit}. + * The start and end points are {@code this} and the specified year-week. + * The result will be negative if the end is before the start. + * The {@code Temporal} passed to this method is converted to a + * {@code YearWeek} using {@link #from(TemporalAccessor)}. + * For example, the period in years between two year-weeks can be calculated + * using {@code startYearWeek.until(endYearWeek, YEARS)}. + *

      + * The calculation returns a whole number, representing the number of + * complete units between the two year-weeks. + * For example, the period in years between 2012-W23 and 2032-W22 + * will only be 9 years as it is one week short of 10 years. + *

      + * There are two equivalent ways of using this method. + * The first is to invoke this method. + * The second is to use {@link TemporalUnit#between(Temporal, Temporal)}: + *

      +     *   // these two lines are equivalent
      +     *   amount = start.until(end, WEEKS);
      +     *   amount = WEEKS.between(start, end);
      +     * 
      + * The choice should be made based on which makes the code more readable. + *

      + * The calculation is implemented in this method for units {@code WEEKS} + * and {@code WEEK_BASED_YEARS}. + * Other {@code ChronoUnit} values will throw an exception. + *

      + * If the unit is not a {@code ChronoUnit}, then the result of this method + * is obtained by invoking {@code TemporalUnit.between(Temporal, Temporal)} + * passing {@code this} as the first argument and the converted input temporal + * as the second argument. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param endExclusive the end date, exclusive, which is converted to a {@code YearWeek}, not null + * @param unit the unit to measure the amount in, not null + * @return the amount of time between this year-week and the end year-week + * @throws DateTimeException if the amount cannot be calculated, or the end + * temporal cannot be converted to a {@code YearWeek} + * @throws UnsupportedTemporalTypeException if the unit is not supported + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public long until(Temporal endExclusive, TemporalUnit unit) { + YearWeek end = YearWeek.from(endExclusive); + if (unit == WEEKS) { + return daysUntil(end); + } else if (unit == WEEK_BASED_YEARS) { + return yearsUntil(end); + } else if (unit instanceof ChronoUnit) { + throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); + } + return unit.between(this, end); + } + + private long daysUntil(YearWeek end) { + LocalDate startDate = this.atDay(MONDAY); + LocalDate endDate = end.atDay(MONDAY); + long days = endDate.toEpochDay() - startDate.toEpochDay(); + return days / 7; + } + + private long yearsUntil(YearWeek end) { + long yearsDiff = end.year - this.year; + if (yearsDiff > 0 && end.week < this.week) return yearsDiff - 1; + if (yearsDiff < 0 && end.week > this.week) return yearsDiff + 1; + return yearsDiff; + } + /** * Formats this year-week using the specified formatter. *

      diff --git a/src/test/java/org/threeten/extra/TestYearWeek.java b/src/test/java/org/threeten/extra/TestYearWeek.java index eefea936..1590122b 100644 --- a/src/test/java/org/threeten/extra/TestYearWeek.java +++ b/src/test/java/org/threeten/extra/TestYearWeek.java @@ -89,6 +89,7 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.Year; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.chrono.IsoChronology; @@ -96,10 +97,15 @@ import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoField; +import java.time.temporal.ChronoUnit; +import java.time.temporal.IsoFields; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalAdjuster; +import java.time.temporal.TemporalAdjusters; import java.time.temporal.TemporalField; import java.time.temporal.TemporalQueries; +import java.time.temporal.TemporalUnit; import java.time.temporal.UnsupportedTemporalTypeException; import java.time.temporal.ValueRange; import java.util.Locale; @@ -289,6 +295,16 @@ public static Object[][] data_sampleAtDay() { }; } + @DataProvider + public static Object[][] data_outOfBounds() { + return new Object[][] { + {IsoFields.WEEK_OF_WEEK_BASED_YEAR, 54}, + {IsoFields.WEEK_OF_WEEK_BASED_YEAR, 0}, + {IsoFields.WEEK_BASED_YEAR, 1000000000}, + {IsoFields.WEEK_BASED_YEAR, -1000000000}, + }; + } + //----------------------------------------------------------------------- @Test public void test_interfaces() { @@ -617,6 +633,34 @@ public void test_lengthOfYear() { assertEquals(371, YearWeek.of(2015, 1).lengthOfYear()); } + //----------------------------------------------------------------------- + // with(TemporalField, long) + //----------------------------------------------------------------------- + @Test() + public void test_with() { + assertEquals(YearWeek.of(2015, 10), TEST.with(IsoFields.WEEK_OF_WEEK_BASED_YEAR, 10)); + assertEquals(YearWeek.of(2016, 1), TEST.with(IsoFields.WEEK_BASED_YEAR, 2016)); + } + + @Test(expected = DateTimeException.class) + @UseDataProvider("data_outOfBounds") + public void test_with_outOfBounds(TemporalField field, long newValue) { + TEST.with(field, newValue); + } + + @Test(expected = UnsupportedTemporalTypeException.class) + public void test_with_TemporalAdjuster_unsupportedType() { + TEST.with(ChronoField.MONTH_OF_YEAR, 5); + } + + //----------------------------------------------------------------------- + // with(TemporalAdjuster) + //----------------------------------------------------------------------- + @Test(expected = UnsupportedTemporalTypeException.class) + public void test_with_unsupportedType() { + TEST.with(TemporalAdjusters.firstDayOfMonth()); + } + //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- @@ -704,6 +748,33 @@ public void test_adjustInto_badChronology() { yw.adjustInto(date); } + //----------------------------------------------------------------------- + // until(Temporal, TemporalUnit) + //----------------------------------------------------------------------- + @Test + public void test_until_weeks() { + assertEquals(1, TEST.until(YearWeek.of(2015, 2), ChronoUnit.WEEKS)); + assertEquals(2, TEST.until(YearWeek.of(2015, 3), ChronoUnit.WEEKS)); + assertEquals(52, TEST_NON_LEAP.until(TEST, ChronoUnit.WEEKS)); + assertEquals(53, TEST.until(YearWeek.of(2016, 1), ChronoUnit.WEEKS)); + } + + @Test + public void test_until_years() { + assertEquals(1, TEST.until(YearWeek.of(2016, 1), IsoFields.WEEK_BASED_YEARS)); + assertEquals(-1, TEST.until(YearWeek.of(2014, 1), IsoFields.WEEK_BASED_YEARS)); + assertEquals(0, TEST.until(YearWeek.of(2015, 53), IsoFields.WEEK_BASED_YEARS)); + assertEquals(0, YearWeek.of(2015, 10).until(YearWeek.of(2015, 5), IsoFields.WEEK_BASED_YEARS)); + assertEquals(0, YearWeek.of(2015, 10).until(YearWeek.of(2016, 5), IsoFields.WEEK_BASED_YEARS)); + assertEquals(0, TEST.until(YearWeek.of(2014, 2), IsoFields.WEEK_BASED_YEARS)); + assertEquals(-1, TEST.until(YearWeek.of(2013, 2), IsoFields.WEEK_BASED_YEARS)); + } + + @Test(expected = UnsupportedTemporalTypeException.class) + public void test_until_unsupportedType() { + TEST.until(YearWeek.of(2016, 1), ChronoUnit.MONTHS); + } + //----------------------------------------------------------------------- // range(TemporalField) //----------------------------------------------------------------------- @@ -755,6 +826,28 @@ public void test_withYear_int_min() { TEST.withYear(Integer.MIN_VALUE); } + //----------------------------------------------------------------------- + // plus(int, TemporalUnit) + //----------------------------------------------------------------------- + @Test + public void test_plus() { + assertEquals(YearWeek.of(2015, 2), TEST.plus(1, ChronoUnit.WEEKS)); + assertEquals(YearWeek.of(2016, 1), TEST.plus(1, IsoFields.WEEK_BASED_YEARS)); + } + + @Test(expected = UnsupportedTemporalTypeException.class) + public void test_plus_unsupportedType() { + YearWeek.of(2014, 1).plus(1, ChronoUnit.DAYS); + } + + //----------------------------------------------------------------------- + // plus(TemporalAmount) + //----------------------------------------------------------------------- + @Test + public void test_plus_TemporalAmount() { + assertEquals(YearWeek.of(2015, 2), TEST.plus(Weeks.of(1))); + } + //----------------------------------------------------------------------- // withWeek(int) //----------------------------------------------------------------------- @@ -844,6 +937,27 @@ public void test_plusWeeks_min_long() { TEST.plusWeeks(Long.MIN_VALUE); } + //----------------------------------------------------------------------- + // minus(int, TemporalUnit) + //----------------------------------------------------------------------- + @Test + public void test_minus() { + assertEquals(YearWeek.of(2014, 1), YearWeek.of(2014, 2).minus(1, ChronoUnit.WEEKS)); + } + + @Test(expected = ArithmeticException.class) + public void test_minus_overflow() { + TEST.minus(Long.MIN_VALUE, ChronoUnit.WEEKS); + } + + //----------------------------------------------------------------------- + // minus(TemporalAmount) + //----------------------------------------------------------------------- + @Test + public void test_minus_TemporalAmount() { + assertEquals(YearWeek.of(2014, 1), YearWeek.of(2014, 2).minus(Weeks.of(1))); + } + //----------------------------------------------------------------------- // minusYears(long) //----------------------------------------------------------------------- From bfadb86f1580f2f653f784c2dd9f9423c198471f Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 29 Nov 2020 23:15:29 +0000 Subject: [PATCH 180/279] Update after PR --- pom.xml | 8 ++++++++ src/changes/changes.xml | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/pom.xml b/pom.xml index 325b2de3..8f936dca 100644 --- a/pom.xml +++ b/pom.xml @@ -86,6 +86,10 @@ Steven McCoy https://github.com/steve-o + + JB Nizet + https://github.com/jnizet + Bjørn Erik Pedersen https://github.com/bep @@ -94,6 +98,10 @@ Erik van Paassen https://github.com/evpaassen + + Max Poliakov + https://github.com/Jaimies + Björn Raupach https://github.com/raupachz diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 3f13dabf..cc6b9589 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -8,6 +8,10 @@ + + Make YearWeek implement Temporal. + Fixes #165, #163, #115. + Add OffsetDate. Fixes #137. @@ -36,6 +40,10 @@ Add Norwegian Bokmål and Norwegian Nynorsk translations for word-based formatting. Fixes #125. + + Fix Interval Javadoc. + Fixes #159. + From e1faf52caae627354e1ef951eb6b6f0c0093038e Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 29 Nov 2020 23:26:09 +0000 Subject: [PATCH 181/279] Add isZero/isNegative/isPositive Fixes #148 --- src/changes/changes.xml | 12 ++++++--- src/main/java/org/threeten/extra/Days.java | 27 +++++++++++++++++++ src/main/java/org/threeten/extra/Hours.java | 27 +++++++++++++++++++ src/main/java/org/threeten/extra/Minutes.java | 27 +++++++++++++++++++ src/main/java/org/threeten/extra/Months.java | 27 +++++++++++++++++++ src/main/java/org/threeten/extra/Seconds.java | 27 +++++++++++++++++++ src/main/java/org/threeten/extra/Weeks.java | 27 +++++++++++++++++++ src/main/java/org/threeten/extra/Years.java | 27 +++++++++++++++++++ .../java/org/threeten/extra/TestDays.java | 15 +++++++++++ .../java/org/threeten/extra/TestHours.java | 26 +++++++++++++++--- .../java/org/threeten/extra/TestMinutes.java | 22 ++++++++++++++- .../java/org/threeten/extra/TestMonths.java | 15 +++++++++++ .../java/org/threeten/extra/TestSeconds.java | 22 ++++++++++++++- .../java/org/threeten/extra/TestWeeks.java | 15 +++++++++++ .../java/org/threeten/extra/TestYears.java | 15 +++++++++++ 15 files changed, 322 insertions(+), 9 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index cc6b9589..42206eca 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -8,14 +8,18 @@ - - Make YearWeek implement Temporal. - Fixes #165, #163, #115. - Add OffsetDate. Fixes #137. + + Add isZero(), isPositive(), isNegative() to temporal amount classes. + Fixes #148. + + + Make YearWeek implement Temporal. + Fixes #165, #163, #115. + Fix UtcInstant.isLeapSecond(). Fixes #153. diff --git a/src/main/java/org/threeten/extra/Days.java b/src/main/java/org/threeten/extra/Days.java index 0b6cc2af..8ae5a269 100644 --- a/src/main/java/org/threeten/extra/Days.java +++ b/src/main/java/org/threeten/extra/Days.java @@ -316,6 +316,33 @@ public int getAmount() { return days; } + /** + * Checks if the amount is negative. + * + * @return true if the amount is negative, false if the amount is zero or positive + */ + public boolean isNegative() { + return getAmount() < 0; + } + + /** + * Checks if the amount is zero. + * + * @return true if the amount is zero, false if not + */ + public boolean isZero() { + return getAmount() == 0; + } + + /** + * Checks if the amount is positive. + * + * @return true if the amount is positive, false if the amount is zero or negative + */ + public boolean isPositive() { + return getAmount() > 0; + } + //----------------------------------------------------------------------- /** * Returns a copy of this amount with the specified amount added. diff --git a/src/main/java/org/threeten/extra/Hours.java b/src/main/java/org/threeten/extra/Hours.java index 24f15938..75e1420a 100644 --- a/src/main/java/org/threeten/extra/Hours.java +++ b/src/main/java/org/threeten/extra/Hours.java @@ -298,6 +298,33 @@ public int getAmount() { return hours; } + /** + * Checks if the amount is negative. + * + * @return true if the amount is negative, false if the amount is zero or positive + */ + public boolean isNegative() { + return getAmount() < 0; + } + + /** + * Checks if the amount is zero. + * + * @return true if the amount is zero, false if not + */ + public boolean isZero() { + return getAmount() == 0; + } + + /** + * Checks if the amount is positive. + * + * @return true if the amount is positive, false if the amount is zero or negative + */ + public boolean isPositive() { + return getAmount() > 0; + } + //----------------------------------------------------------------------- /** * Returns a copy of this amount with the specified amount added. diff --git a/src/main/java/org/threeten/extra/Minutes.java b/src/main/java/org/threeten/extra/Minutes.java index 5e4cb2f8..e3994d0b 100644 --- a/src/main/java/org/threeten/extra/Minutes.java +++ b/src/main/java/org/threeten/extra/Minutes.java @@ -332,6 +332,33 @@ public int getAmount() { return minutes; } + /** + * Checks if the amount is negative. + * + * @return true if the amount is negative, false if the amount is zero or positive + */ + public boolean isNegative() { + return getAmount() < 0; + } + + /** + * Checks if the amount is zero. + * + * @return true if the amount is zero, false if not + */ + public boolean isZero() { + return getAmount() == 0; + } + + /** + * Checks if the amount is positive. + * + * @return true if the amount is positive, false if the amount is zero or negative + */ + public boolean isPositive() { + return getAmount() > 0; + } + //----------------------------------------------------------------------- /** * Returns a copy of this amount with the specified amount added. diff --git a/src/main/java/org/threeten/extra/Months.java b/src/main/java/org/threeten/extra/Months.java index d3219113..542b9393 100644 --- a/src/main/java/org/threeten/extra/Months.java +++ b/src/main/java/org/threeten/extra/Months.java @@ -316,6 +316,33 @@ public int getAmount() { return months; } + /** + * Checks if the amount is negative. + * + * @return true if the amount is negative, false if the amount is zero or positive + */ + public boolean isNegative() { + return getAmount() < 0; + } + + /** + * Checks if the amount is zero. + * + * @return true if the amount is zero, false if not + */ + public boolean isZero() { + return getAmount() == 0; + } + + /** + * Checks if the amount is positive. + * + * @return true if the amount is positive, false if the amount is zero or negative + */ + public boolean isPositive() { + return getAmount() > 0; + } + //----------------------------------------------------------------------- /** * Returns a copy of this amount with the specified amount added. diff --git a/src/main/java/org/threeten/extra/Seconds.java b/src/main/java/org/threeten/extra/Seconds.java index 9e00c453..d3cb18a3 100644 --- a/src/main/java/org/threeten/extra/Seconds.java +++ b/src/main/java/org/threeten/extra/Seconds.java @@ -367,6 +367,33 @@ public int getAmount() { return seconds; } + /** + * Checks if the amount is negative. + * + * @return true if the amount is negative, false if the amount is zero or positive + */ + public boolean isNegative() { + return getAmount() < 0; + } + + /** + * Checks if the amount is zero. + * + * @return true if the amount is zero, false if not + */ + public boolean isZero() { + return getAmount() == 0; + } + + /** + * Checks if the amount is positive. + * + * @return true if the amount is positive, false if the amount is zero or negative + */ + public boolean isPositive() { + return getAmount() > 0; + } + //----------------------------------------------------------------------- /** * Returns a copy of this amount with the specified amount added. diff --git a/src/main/java/org/threeten/extra/Weeks.java b/src/main/java/org/threeten/extra/Weeks.java index 27b88468..659abadf 100644 --- a/src/main/java/org/threeten/extra/Weeks.java +++ b/src/main/java/org/threeten/extra/Weeks.java @@ -272,6 +272,33 @@ public int getAmount() { return weeks; } + /** + * Checks if the amount is negative. + * + * @return true if the amount is negative, false if the amount is zero or positive + */ + public boolean isNegative() { + return getAmount() < 0; + } + + /** + * Checks if the amount is zero. + * + * @return true if the amount is zero, false if not + */ + public boolean isZero() { + return getAmount() == 0; + } + + /** + * Checks if the amount is positive. + * + * @return true if the amount is positive, false if the amount is zero or negative + */ + public boolean isPositive() { + return getAmount() > 0; + } + //----------------------------------------------------------------------- /** * Returns a copy of this amount with the specified amount added. diff --git a/src/main/java/org/threeten/extra/Years.java b/src/main/java/org/threeten/extra/Years.java index edc3cfc1..780aab54 100644 --- a/src/main/java/org/threeten/extra/Years.java +++ b/src/main/java/org/threeten/extra/Years.java @@ -272,6 +272,33 @@ public int getAmount() { return years; } + /** + * Checks if the amount is negative. + * + * @return true if the amount is negative, false if the amount is zero or positive + */ + public boolean isNegative() { + return getAmount() < 0; + } + + /** + * Checks if the amount is zero. + * + * @return true if the amount is zero, false if not + */ + public boolean isZero() { + return getAmount() == 0; + } + + /** + * Checks if the amount is positive. + * + * @return true if the amount is positive, false if the amount is zero or negative + */ + public boolean isPositive() { + return getAmount() > 0; + } + //----------------------------------------------------------------------- /** * Returns a copy of this amount with the specified amount added. diff --git a/src/test/java/org/threeten/extra/TestDays.java b/src/test/java/org/threeten/extra/TestDays.java index 9c0e1086..bb269c99 100644 --- a/src/test/java/org/threeten/extra/TestDays.java +++ b/src/test/java/org/threeten/extra/TestDays.java @@ -32,6 +32,7 @@ package org.threeten.extra; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -88,6 +89,9 @@ public void test_ZERO() { assertSame(Days.of(0), Days.ZERO); assertEquals(Days.of(0), Days.ZERO); assertEquals(0, Days.ZERO.getAmount()); + assertFalse(Days.ZERO.isNegative()); + assertTrue(Days.ZERO.isZero()); + assertFalse(Days.ZERO.isPositive()); } @Test @@ -95,6 +99,9 @@ public void test_ONE() { assertSame(Days.of(1), Days.ONE); assertEquals(Days.of(1), Days.ONE); assertEquals(1, Days.ONE.getAmount()); + assertFalse(Days.ONE.isNegative()); + assertFalse(Days.ONE.isZero()); + assertTrue(Days.ONE.isPositive()); } //----------------------------------------------------------------------- @@ -109,6 +116,14 @@ public void test_of() { assertEquals(Integer.MIN_VALUE, Days.of(Integer.MIN_VALUE).getAmount()); } + @Test + public void test_ofMinusOne() { + assertEquals(-1, Days.of(-1).getAmount()); + assertTrue(Days.of(-1).isNegative()); + assertFalse(Days.of(-1).isZero()); + assertFalse(Days.of(-1).isPositive()); + } + //----------------------------------------------------------------------- @Test public void test_ofWeeks() { diff --git a/src/test/java/org/threeten/extra/TestHours.java b/src/test/java/org/threeten/extra/TestHours.java index 448a32c0..d71f93a6 100644 --- a/src/test/java/org/threeten/extra/TestHours.java +++ b/src/test/java/org/threeten/extra/TestHours.java @@ -32,6 +32,7 @@ package org.threeten.extra; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -75,15 +76,18 @@ public void test_deserializationSingleton() throws Exception { assertSame(test, ois.readObject()); } } - + //----------------------------------------------------------------------- @Test public void test_ZERO() { assertSame(Hours.of(0), Hours.ZERO); assertEquals(Hours.of(0), Hours.ZERO); assertEquals(0, Hours.ZERO.getAmount()); + assertFalse(Hours.ZERO.isNegative()); + assertTrue(Hours.ZERO.isZero()); + assertFalse(Hours.ZERO.isPositive()); } - + //----------------------------------------------------------------------- @Test public void test_of() { @@ -95,7 +99,23 @@ public void test_of() { assertEquals(-2, Hours.of(-2).getAmount()); assertEquals(Integer.MIN_VALUE, Hours.of(Integer.MIN_VALUE).getAmount()); } - + + @Test + public void test_ofMinusOne() { + assertEquals(-1, Hours.of(-1).getAmount()); + assertTrue(Hours.of(-1).isNegative()); + assertFalse(Hours.of(-1).isZero()); + assertFalse(Hours.of(-1).isPositive()); + } + + @Test + public void test_ofPlusOne() { + assertEquals(1, Hours.of(1).getAmount()); + assertFalse(Hours.of(1).isNegative()); + assertFalse(Hours.of(1).isZero()); + assertTrue(Hours.of(1).isPositive()); + } + //----------------------------------------------------------------------- @DataProvider public static Object[][] data_valid() { diff --git a/src/test/java/org/threeten/extra/TestMinutes.java b/src/test/java/org/threeten/extra/TestMinutes.java index 449dfe2f..4fed3795 100644 --- a/src/test/java/org/threeten/extra/TestMinutes.java +++ b/src/test/java/org/threeten/extra/TestMinutes.java @@ -32,6 +32,7 @@ package org.threeten.extra; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -82,6 +83,9 @@ public void test_ZERO() { assertSame(Minutes.of(0), Minutes.ZERO); assertEquals(Minutes.of(0), Minutes.ZERO); assertEquals(0, Minutes.ZERO.getAmount()); + assertFalse(Minutes.ZERO.isNegative()); + assertTrue(Minutes.ZERO.isZero()); + assertFalse(Minutes.ZERO.isPositive()); } //----------------------------------------------------------------------- @@ -95,7 +99,23 @@ public void test_of() { assertEquals(-2, Minutes.of(-2).getAmount()); assertEquals(Integer.MIN_VALUE, Minutes.of(Integer.MIN_VALUE).getAmount()); } - + + @Test + public void test_ofMinusOne() { + assertEquals(-1, Hours.of(-1).getAmount()); + assertTrue(Minutes.of(-1).isNegative()); + assertFalse(Minutes.of(-1).isZero()); + assertFalse(Minutes.of(-1).isPositive()); + } + + @Test + public void test_ofPlusOne() { + assertEquals(1, Hours.of(1).getAmount()); + assertFalse(Minutes.of(1).isNegative()); + assertFalse(Minutes.of(1).isZero()); + assertTrue(Minutes.of(1).isPositive()); + } + //----------------------------------------------------------------------- @Test public void test_ofHours() { diff --git a/src/test/java/org/threeten/extra/TestMonths.java b/src/test/java/org/threeten/extra/TestMonths.java index 64d5970d..760faf56 100644 --- a/src/test/java/org/threeten/extra/TestMonths.java +++ b/src/test/java/org/threeten/extra/TestMonths.java @@ -32,6 +32,7 @@ package org.threeten.extra; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -88,6 +89,9 @@ public void test_ZERO() { assertSame(Months.of(0), Months.ZERO); assertEquals(Months.of(0), Months.ZERO); assertEquals(0, Months.ZERO.getAmount()); + assertFalse(Months.ZERO.isNegative()); + assertTrue(Months.ZERO.isZero()); + assertFalse(Months.ZERO.isPositive()); } @Test @@ -95,6 +99,9 @@ public void test_ONE() { assertSame(Months.of(1), Months.ONE); assertEquals(Months.of(1), Months.ONE); assertEquals(1, Months.ONE.getAmount()); + assertFalse(Months.ONE.isNegative()); + assertFalse(Months.ONE.isZero()); + assertTrue(Months.ONE.isPositive()); } //----------------------------------------------------------------------- @@ -109,6 +116,14 @@ public void test_of() { assertEquals(Integer.MIN_VALUE, Months.of(Integer.MIN_VALUE).getAmount()); } + @Test + public void test_ofMinusOne() { + assertEquals(-1, Months.of(-1).getAmount()); + assertTrue(Months.of(-1).isNegative()); + assertFalse(Months.of(-1).isZero()); + assertFalse(Months.of(-1).isPositive()); + } + //----------------------------------------------------------------------- @Test public void test_ofYears() { diff --git a/src/test/java/org/threeten/extra/TestSeconds.java b/src/test/java/org/threeten/extra/TestSeconds.java index 34709110..1d6b76b3 100644 --- a/src/test/java/org/threeten/extra/TestSeconds.java +++ b/src/test/java/org/threeten/extra/TestSeconds.java @@ -32,6 +32,7 @@ package org.threeten.extra; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -82,6 +83,9 @@ public void test_ZERO() { assertSame(Seconds.of(0), Seconds.ZERO); assertEquals(Seconds.of(0), Seconds.ZERO); assertEquals(0, Seconds.ZERO.getAmount()); + assertFalse(Seconds.ZERO.isNegative()); + assertTrue(Seconds.ZERO.isZero()); + assertFalse(Seconds.ZERO.isPositive()); } //----------------------------------------------------------------------- @@ -95,7 +99,23 @@ public void test_of() { assertEquals(-2, Seconds.of(-2).getAmount()); assertEquals(Integer.MIN_VALUE, Seconds.of(Integer.MIN_VALUE).getAmount()); } - + + @Test + public void test_ofMinusOne() { + assertEquals(-1, Seconds.of(-1).getAmount()); + assertTrue(Seconds.of(-1).isNegative()); + assertFalse(Seconds.of(-1).isZero()); + assertFalse(Seconds.of(-1).isPositive()); + } + + @Test + public void test_ofPlusOne() { + assertEquals(1, Seconds.of(1).getAmount()); + assertFalse(Seconds.of(1).isNegative()); + assertFalse(Seconds.of(1).isZero()); + assertTrue(Seconds.of(1).isPositive()); + } + //----------------------------------------------------------------------- @Test public void test_ofHours() { diff --git a/src/test/java/org/threeten/extra/TestWeeks.java b/src/test/java/org/threeten/extra/TestWeeks.java index ff0daced..e0cccced 100644 --- a/src/test/java/org/threeten/extra/TestWeeks.java +++ b/src/test/java/org/threeten/extra/TestWeeks.java @@ -32,6 +32,7 @@ package org.threeten.extra; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -88,6 +89,9 @@ public void test_ZERO() { assertSame(Weeks.of(0), Weeks.ZERO); assertEquals(Weeks.of(0), Weeks.ZERO); assertEquals(0, Weeks.ZERO.getAmount()); + assertFalse(Weeks.ZERO.isNegative()); + assertTrue(Weeks.ZERO.isZero()); + assertFalse(Weeks.ZERO.isPositive()); } @Test @@ -95,6 +99,9 @@ public void test_ONE() { assertSame(Weeks.of(1), Weeks.ONE); assertEquals(Weeks.of(1), Weeks.ONE); assertEquals(1, Weeks.ONE.getAmount()); + assertFalse(Weeks.ONE.isNegative()); + assertFalse(Weeks.ONE.isZero()); + assertTrue(Weeks.ONE.isPositive()); } //----------------------------------------------------------------------- @@ -108,6 +115,14 @@ public void test_of() { assertEquals(Integer.MIN_VALUE, Weeks.of(Integer.MIN_VALUE).getAmount()); } + @Test + public void test_ofMinusOne() { + assertEquals(-1, Weeks.of(-1).getAmount()); + assertTrue(Weeks.of(-1).isNegative()); + assertFalse(Weeks.of(-1).isZero()); + assertFalse(Weeks.of(-1).isPositive()); + } + //----------------------------------------------------------------------- @Test public void test_from_P0W() { diff --git a/src/test/java/org/threeten/extra/TestYears.java b/src/test/java/org/threeten/extra/TestYears.java index e7aa85af..043af527 100644 --- a/src/test/java/org/threeten/extra/TestYears.java +++ b/src/test/java/org/threeten/extra/TestYears.java @@ -32,6 +32,7 @@ package org.threeten.extra; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -88,6 +89,9 @@ public void test_ZERO() { assertSame(Years.of(0), Years.ZERO); assertEquals(Years.of(0), Years.ZERO); assertEquals(0, Years.ZERO.getAmount()); + assertFalse(Years.ZERO.isNegative()); + assertTrue(Years.ZERO.isZero()); + assertFalse(Years.ZERO.isPositive()); } @Test @@ -95,6 +99,9 @@ public void test_ONE() { assertSame(Years.of(1), Years.ONE); assertEquals(Years.of(1), Years.ONE); assertEquals(1, Years.ONE.getAmount()); + assertFalse(Years.ONE.isNegative()); + assertFalse(Years.ONE.isZero()); + assertTrue(Years.ONE.isPositive()); } //----------------------------------------------------------------------- @@ -108,6 +115,14 @@ public void test_of() { assertEquals(Integer.MIN_VALUE, Years.of(Integer.MIN_VALUE).getAmount()); } + @Test + public void test_ofMinusOne() { + assertEquals(-1, Years.of(-1).getAmount()); + assertTrue(Years.of(-1).isNegative()); + assertFalse(Years.of(-1).isZero()); + assertFalse(Years.of(-1).isPositive()); + } + //----------------------------------------------------------------------- @Test public void test_from_P0Y() { From 44a7f43e2a898c179754755468cce6ed578636f4 Mon Sep 17 00:00:00 2001 From: Kurt Alfred Kluever Date: Sun, 29 Nov 2020 18:44:42 -0500 Subject: [PATCH 182/279] Add Year-based static factory methods to YearWeek and YearQuarter (#156) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add YearWeek.of(Year, int), YearQuarter.of(Year, int), and YearQuarter.of(Year, Quarter) * Remove tests which are testing the Year.of() APIs No need to test Year.of(), since that's part of java.time, not ThreeTen-Extra. * Update src/main/java/org/threeten/extra/YearQuarter.java Co-authored-by: MichaÅ‚ Sobkiewicz * Update src/main/java/org/threeten/extra/YearQuarter.java Co-authored-by: MichaÅ‚ Sobkiewicz * Update src/main/java/org/threeten/extra/YearWeek.java Co-authored-by: MichaÅ‚ Sobkiewicz Co-authored-by: MichaÅ‚ Sobkiewicz --- .../java/org/threeten/extra/YearQuarter.java | 23 +++++++++ .../java/org/threeten/extra/YearWeek.java | 15 ++++++ .../org/threeten/extra/TestYearQuarter.java | 50 +++++++++++++++++++ .../java/org/threeten/extra/TestYearWeek.java | 16 ++++++ 4 files changed, 104 insertions(+) diff --git a/src/main/java/org/threeten/extra/YearQuarter.java b/src/main/java/org/threeten/extra/YearQuarter.java index 7929e091..80e899f4 100644 --- a/src/main/java/org/threeten/extra/YearQuarter.java +++ b/src/main/java/org/threeten/extra/YearQuarter.java @@ -178,6 +178,29 @@ public static YearQuarter now(Clock clock) { } //----------------------------------------------------------------------- + /** + * Obtains an instance of {@code YearQuarter} from a year and quarter. + * + * @param year the year to represent, not null + * @param quarter the quarter-of-year to represent, not null + * @return the year-quarter, not null + */ + public static YearQuarter of(Year year, Quarter quarter) { + return of(year.getValue(), quarter); + } + + /** + * Obtains an instance of {@code YearQuarter} from a year and quarter. + * + * @param year the year to represent, not null + * @param quarter the quarter-of-year to represent, from 1 to 4 + * @return the year-quarter, not null + * @throws DateTimeException if the quarter value is invalid + */ + public static YearQuarter of(Year year, int quarter) { + return of(year.getValue(), Quarter.of(quarter)); + } + /** * Obtains an instance of {@code YearQuarter} from a year and quarter. * diff --git a/src/main/java/org/threeten/extra/YearWeek.java b/src/main/java/org/threeten/extra/YearWeek.java index c7e95f69..d1b4d3dd 100644 --- a/src/main/java/org/threeten/extra/YearWeek.java +++ b/src/main/java/org/threeten/extra/YearWeek.java @@ -174,6 +174,21 @@ public static YearWeek now(Clock clock) { } //----------------------------------------------------------------------- + /** + * Obtains an instance of {@code YearWeek} from a week-based-year and week. + *

      + * If the week is 53 and the year does not have 53 weeks, week one of the following + * year is selected. + * + * @param year the week-based-year to represent, not null + * @param week the week-of-week-based-year to represent, from 1 to 53 + * @return the year-week, not null + * @throws DateTimeException if the week value is invalid + */ + public static YearWeek of(Year year, int week) { + return of(year.getValue(), week); + } + /** * Obtains an instance of {@code YearWeek} from a week-based-year and week. *

      diff --git a/src/test/java/org/threeten/extra/TestYearQuarter.java b/src/test/java/org/threeten/extra/TestYearQuarter.java index 64f35506..69d490a5 100644 --- a/src/test/java/org/threeten/extra/TestYearQuarter.java +++ b/src/test/java/org/threeten/extra/TestYearQuarter.java @@ -143,6 +143,56 @@ public void test_serialization() throws IOException, ClassNotFoundException { } } + //----------------------------------------------------------------------- + // of(Year,Quarter) + //----------------------------------------------------------------------- + @Test + public void test_of_Year_Quarter() { + for (int year = -100; year <= 100; year++) { + for (Quarter quarter : Quarter.values()) { + YearQuarter test = YearQuarter.of(Year.of(year), quarter); + assertEquals(year, test.getYear()); + assertEquals(quarter.getValue(), test.getQuarterValue()); + assertEquals(quarter, test.getQuarter()); + } + } + } + + @Test(expected = NullPointerException.class) + public void test_of_Year_Quarter_nullQuarter() { + YearQuarter.of(Year.of(2012), (Quarter) null); + } + + @Test(expected = NullPointerException.class) + public void test_of_Year_Quarter_nullYear() { + YearQuarter.of((Year) null, Quarter.Q2); + } + + @Test(expected = NullPointerException.class) + public void test_of_Year_Quarter_nullBoth() { + YearQuarter.of((Year) null, (Quarter) null); + } + + //----------------------------------------------------------------------- + // of(Year,int) + //----------------------------------------------------------------------- + @Test + public void test_of_Year_int() { + for (int year = -100; year <= 100; year++) { + for (Quarter quarter : Quarter.values()) { + YearQuarter test = YearQuarter.of(Year.of(year), quarter.getValue()); + assertEquals(year, test.getYear()); + assertEquals(quarter.getValue(), test.getQuarterValue()); + assertEquals(quarter, test.getQuarter()); + } + } + } + + @Test(expected = NullPointerException.class) + public void test_of_Year_int_null() { + YearQuarter.of((Year) null, 2); + } + //----------------------------------------------------------------------- // of(int,Quarter) //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestYearWeek.java b/src/test/java/org/threeten/extra/TestYearWeek.java index 1590122b..ab83fcea 100644 --- a/src/test/java/org/threeten/extra/TestYearWeek.java +++ b/src/test/java/org/threeten/extra/TestYearWeek.java @@ -383,6 +383,22 @@ public void now_Clock_nullClock() { YearWeek.now((Clock) null); } + //----------------------------------------------------------------------- + // of(Year, int) + //----------------------------------------------------------------------- + @Test + @UseDataProvider("data_sampleYearWeeks") + public void test_of_Year_int(int year, int week) { + YearWeek yearWeek = YearWeek.of(Year.of(year), week); + assertEquals(year, yearWeek.getYear()); + assertEquals(week, yearWeek.getWeek()); + } + + @Test + public void test_carry_Year_int() { + assertTrue(YearWeek.of(Year.of(2014), 53).equals(TEST)); + } + //----------------------------------------------------------------------- // of(int, int) //----------------------------------------------------------------------- From 706e640fbe8375d690de6c3fba1117566dc14304 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 29 Nov 2020 23:46:27 +0000 Subject: [PATCH 183/279] Update after PR --- pom.xml | 4 ++++ src/changes/changes.xml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/pom.xml b/pom.xml index 8f936dca..f63cf9fc 100644 --- a/pom.xml +++ b/pom.xml @@ -74,6 +74,10 @@ Bruno P. Kinoshita https://github.com/kinow + + Kurt Alfred Kluever + https://github.com/kluever + Martin Kröning https://github.com/mwkroening diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 42206eca..bb64220b 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -12,6 +12,10 @@ Add OffsetDate. Fixes #137. + + Add factory methods taking Year and Quarter objects. + Fixes #155, #156. + Add isZero(), isPositive(), isNegative() to temporal amount classes. Fixes #148. From 94448726713a820dd24b8eab0be195fce58a30ef Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 30 Nov 2020 10:25:28 +0000 Subject: [PATCH 184/279] Create SECURITY.md --- .github/SECURITY.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .github/SECURITY.md diff --git a/.github/SECURITY.md b/.github/SECURITY.md new file mode 100644 index 00000000..f8ff1f13 --- /dev/null +++ b/.github/SECURITY.md @@ -0,0 +1,10 @@ +# Security Policy + +## Supported Versions + +If a security issue occurs, only the latest version is guaranteed to be patched. + +## Reporting a Vulnerability + +To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). +Tidelift will coordinate the fix and disclosure. From f4839af047b7f5ac77cb84c22579a2a44c09330c Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 30 Nov 2020 10:28:51 +0000 Subject: [PATCH 185/279] Create codeql-analysis.yml --- .github/workflows/codeql-analysis.yml | 67 +++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 00000000..b8ed3af4 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,67 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + schedule: + - cron: '41 10 * * 3' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + language: [ 'java' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more: + # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # â„¹ï¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # âœï¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 From 49d493e1bf52e439e67e433de5d4ae54644a53c3 Mon Sep 17 00:00:00 2001 From: spand Date: Mon, 15 Feb 2021 18:39:05 +0100 Subject: [PATCH 186/279] Fix poor javadoc reference to Instant.MIN and Instant.MAX. (#171) --- src/main/java/org/threeten/extra/Interval.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/threeten/extra/Interval.java b/src/main/java/org/threeten/extra/Interval.java index 996f5edf..d08351f3 100644 --- a/src/main/java/org/threeten/extra/Interval.java +++ b/src/main/java/org/threeten/extra/Interval.java @@ -93,8 +93,8 @@ public final class Interval *

      * The end instant must not be before the start instant. * - * @param startInclusive the start instant, inclusive, MIN_DATE treated as unbounded, not null - * @param endExclusive the end instant, exclusive, MAX_DATE treated as unbounded, not null + * @param startInclusive the start instant, inclusive, {@link Instant#MIN} treated as unbounded, not null + * @param endExclusive the end instant, exclusive, {@link Instant#MAX} treated as unbounded, not null * @return the half-open interval, not null * @throws DateTimeException if the end is before the start */ From 0fb256b3334119544ad24cd8565998ec9971884e Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 15 Feb 2021 17:51:31 +0000 Subject: [PATCH 187/279] Update after PR --- pom.xml | 4 ++++ src/changes/changes.xml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/pom.xml b/pom.xml index f63cf9fc..2848f82b 100644 --- a/pom.xml +++ b/pom.xml @@ -122,6 +122,10 @@ Nils Sommer https://github.com/nsommer + + spand + https://github.com/spand + Dimo Velev https://github.com/dimovelev diff --git a/src/changes/changes.xml b/src/changes/changes.xml index bb64220b..bf9158ac 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -48,6 +48,10 @@ Add Norwegian Bokmål and Norwegian Nynorsk translations for word-based formatting. Fixes #125. + + Fix Interval Javadoc. + Fixes #171. + Fix Interval Javadoc. Fixes #159. From 9484d6b374e82b4d299d375850b7faca43d024ff Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Thu, 18 Feb 2021 09:43:29 +0000 Subject: [PATCH 188/279] Add a SemVer note Fixes #164 --- src/site/markdown/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index c5f16b3c..e9b97060 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -53,7 +53,7 @@ Various documentation is available: ## Releases Release 1.5.0 is the current release. -This release is considered stable and worthy of the 1.x tag. +This release is considered stable and worthy of the 1.x tag as per [SemVer](https://semver.org/spec/v2.0.0.html). ThreeTen-Extra requires Java SE 8 or later and has no [dependencies](dependencies.html). From 99f001320fc010e1457f1e8d2189b28b27072a60 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Thu, 18 Feb 2021 10:18:12 +0000 Subject: [PATCH 189/279] Clarify Javadoc of YearWeek.of(Year, int) --- src/main/java/org/threeten/extra/YearWeek.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/threeten/extra/YearWeek.java b/src/main/java/org/threeten/extra/YearWeek.java index d1b4d3dd..6aaaa55b 100644 --- a/src/main/java/org/threeten/extra/YearWeek.java +++ b/src/main/java/org/threeten/extra/YearWeek.java @@ -175,18 +175,25 @@ public static YearWeek now(Clock clock) { //----------------------------------------------------------------------- /** - * Obtains an instance of {@code YearWeek} from a week-based-year and week. + * Obtains an instance of {@code YearWeek} from a year and week. *

      * If the week is 53 and the year does not have 53 weeks, week one of the following * year is selected. + *

      + * Note that this class is based on the week-based-year which aligns to Monday to Sunday weeks, + * whereas {@code Year} is intended to represent standard years aligned from January to December. + * This difference may be seen at the start and/or end of the year. + * This method treats the standard year as though it is the week-based-year. + * Thus, {@code YearWeek.of(Year.of(2020), 1)} creates an object where Monday and Tuesday of the week + * are actually the last two days of 2019. * - * @param year the week-based-year to represent, not null + * @param year the year to represent, not null * @param week the week-of-week-based-year to represent, from 1 to 53 * @return the year-week, not null * @throws DateTimeException if the week value is invalid */ public static YearWeek of(Year year, int week) { - return of(year.getValue(), week); + return of(year.getValue(), week); } /** From e1d9c00856271e1145a47f861e4ded41c324a9f4 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Thu, 18 Feb 2021 10:24:23 +0000 Subject: [PATCH 190/279] Checkstyle fixes --- src/main/java/org/threeten/extra/OffsetDate.java | 1 + src/test/java/org/threeten/extra/TestHours.java | 2 +- src/test/java/org/threeten/extra/TestInterval.java | 2 +- src/test/java/org/threeten/extra/TestLocalDateRange.java | 2 +- src/test/java/org/threeten/extra/TestMinutes.java | 2 +- src/test/java/org/threeten/extra/TestOffsetDate.java | 2 +- src/test/java/org/threeten/extra/TestPeriodDuration.java | 2 +- src/test/java/org/threeten/extra/TestSeconds.java | 2 +- src/test/java/org/threeten/extra/TestYearQuarter.java | 2 +- src/test/java/org/threeten/extra/TestYearWeek.java | 3 +-- .../org/threeten/extra/chrono/TestAccountingChronology.java | 6 +++--- .../extra/chrono/TestAccountingChronologyBuilder.java | 1 - .../threeten/extra/chrono/TestBritishCutoverChronology.java | 5 +++-- .../org/threeten/extra/chrono/TestCopticChronology.java | 5 +++-- .../org/threeten/extra/chrono/TestDiscordianChronology.java | 6 +++--- .../org/threeten/extra/chrono/TestEthiopicChronology.java | 5 +++-- .../extra/chrono/TestInternationalFixedChronology.java | 2 +- .../org/threeten/extra/chrono/TestJulianChronology.java | 5 +++-- .../java/org/threeten/extra/chrono/TestPaxChronology.java | 5 +++-- .../threeten/extra/chrono/TestSymmetry010Chronology.java | 2 +- .../threeten/extra/chrono/TestSymmetry454Chronology.java | 2 +- src/test/java/org/threeten/extra/scale/TestTaiInstant.java | 2 +- src/test/java/org/threeten/extra/scale/TestUtcInstant.java | 2 +- 23 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/threeten/extra/OffsetDate.java b/src/main/java/org/threeten/extra/OffsetDate.java index f43bda8c..1f3731d7 100644 --- a/src/main/java/org/threeten/extra/OffsetDate.java +++ b/src/main/java/org/threeten/extra/OffsetDate.java @@ -405,6 +405,7 @@ public boolean isSupported(TemporalField field) { * @param unit the unit to check, null returns false * @return true if the unit can be added/subtracted, false if not */ + @Override public boolean isSupported(TemporalUnit unit) { if (unit instanceof ChronoUnit) { return unit.isDateBased(); diff --git a/src/test/java/org/threeten/extra/TestHours.java b/src/test/java/org/threeten/extra/TestHours.java index d71f93a6..496df6a0 100644 --- a/src/test/java/org/threeten/extra/TestHours.java +++ b/src/test/java/org/threeten/extra/TestHours.java @@ -447,7 +447,7 @@ public void test_equals_null() { @Test public void test_equals_otherClass() { Hours test5 = Hours.of(5); - assertEquals(false, test5.equals("")); + assertEquals(false, test5.equals((Object) "")); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestInterval.java b/src/test/java/org/threeten/extra/TestInterval.java index a4457be8..7142c100 100644 --- a/src/test/java/org/threeten/extra/TestInterval.java +++ b/src/test/java/org/threeten/extra/TestInterval.java @@ -720,7 +720,7 @@ public void test_equals() { assertEquals(false, a.equals(b)); assertEquals(false, a.equals(c)); assertEquals(false, a.equals(null)); - assertEquals(false, a.equals("")); + assertEquals(false, a.equals((Object) "")); assertEquals(true, a.hashCode() == a2.hashCode()); } diff --git a/src/test/java/org/threeten/extra/TestLocalDateRange.java b/src/test/java/org/threeten/extra/TestLocalDateRange.java index 4381f939..6a5a1dee 100644 --- a/src/test/java/org/threeten/extra/TestLocalDateRange.java +++ b/src/test/java/org/threeten/extra/TestLocalDateRange.java @@ -1206,7 +1206,7 @@ public void test_equals() { assertEquals(false, a.equals(b)); assertEquals(false, a.equals(c)); assertEquals(false, a.equals(null)); - assertEquals(false, a.equals("")); + assertEquals(false, a.equals((Object) "")); assertEquals(true, a.hashCode() == a2.hashCode()); } diff --git a/src/test/java/org/threeten/extra/TestMinutes.java b/src/test/java/org/threeten/extra/TestMinutes.java index 4fed3795..b126cd2f 100644 --- a/src/test/java/org/threeten/extra/TestMinutes.java +++ b/src/test/java/org/threeten/extra/TestMinutes.java @@ -461,7 +461,7 @@ public void test_equals_null() { @Test public void test_equals_otherClass() { Minutes test5 = Minutes.of(5); - assertEquals(false, test5.equals("")); + assertEquals(false, test5.equals((Object) "")); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestOffsetDate.java b/src/test/java/org/threeten/extra/TestOffsetDate.java index 714d1d1d..8fa14676 100644 --- a/src/test/java/org/threeten/extra/TestOffsetDate.java +++ b/src/test/java/org/threeten/extra/TestOffsetDate.java @@ -1929,7 +1929,7 @@ public void test_equals_itself_true() { @Test public void test_equals_string_false() { - assertFalse(TEST_2007_07_15_PONE.equals("2007-07-15")); + assertFalse(TEST_2007_07_15_PONE.equals((Object) "2007-07-15")); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestPeriodDuration.java b/src/test/java/org/threeten/extra/TestPeriodDuration.java index 1be12870..5d90ca52 100644 --- a/src/test/java/org/threeten/extra/TestPeriodDuration.java +++ b/src/test/java/org/threeten/extra/TestPeriodDuration.java @@ -402,7 +402,7 @@ public void test_equals_null() { @Test public void test_equals_otherClass() { PeriodDuration test = PeriodDuration.of(P1Y2M3D, DUR_5); - assertEquals(false, test.equals("")); + assertEquals(false, test.equals((Object) "")); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestSeconds.java b/src/test/java/org/threeten/extra/TestSeconds.java index 1d6b76b3..d5b001b3 100644 --- a/src/test/java/org/threeten/extra/TestSeconds.java +++ b/src/test/java/org/threeten/extra/TestSeconds.java @@ -493,7 +493,7 @@ public void test_equals_null() { @Test public void test_equals_otherClass() { Seconds test5 = Seconds.of(5); - assertEquals(false, test5.equals("")); + assertEquals(false, test5.equals((Object) "")); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestYearQuarter.java b/src/test/java/org/threeten/extra/TestYearQuarter.java index 69d490a5..76f2727e 100644 --- a/src/test/java/org/threeten/extra/TestYearQuarter.java +++ b/src/test/java/org/threeten/extra/TestYearQuarter.java @@ -995,7 +995,7 @@ public void test_equals_nullYearQuarter() { @Test public void test_equals_incorrectType() { - assertEquals(false, TEST.equals("Incorrect type")); + assertEquals(false, TEST.equals((Object) "Incorrect type")); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestYearWeek.java b/src/test/java/org/threeten/extra/TestYearWeek.java index ab83fcea..5f7b9048 100644 --- a/src/test/java/org/threeten/extra/TestYearWeek.java +++ b/src/test/java/org/threeten/extra/TestYearWeek.java @@ -105,7 +105,6 @@ import java.time.temporal.TemporalAdjusters; import java.time.temporal.TemporalField; import java.time.temporal.TemporalQueries; -import java.time.temporal.TemporalUnit; import java.time.temporal.UnsupportedTemporalTypeException; import java.time.temporal.ValueRange; import java.util.Locale; @@ -1082,7 +1081,7 @@ public void test_equals() { @Test public void test_equals_incorrectType() { assertTrue(TEST.equals(null) == false); - assertEquals(false, TEST.equals("Incorrect type")); + assertEquals(false, TEST.equals((Object) "Incorrect type")); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java b/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java index f8d33ead..e6105d50 100644 --- a/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java @@ -54,6 +54,7 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.time.DateTimeException; @@ -72,7 +73,6 @@ import java.time.temporal.WeekFields; import java.util.List; import java.util.function.IntPredicate; -import java.util.function.Predicate; import org.junit.Assert; import org.junit.Test; @@ -775,8 +775,8 @@ public void test_equals() { assertEquals(false, a1.equals(c)); assertEquals(false, a1.equals(d)); - assertEquals(false, a1.equals(null)); - assertEquals(false, a1.equals("")); + assertFalse(a1.equals(null)); + assertFalse(a1.equals((Object) "")); assertEquals(false, a1.getChronology().equals(other.getChronology())); assertEquals(false, a1.equals(other)); diff --git a/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java b/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java index 0c9e0b8b..639da216 100644 --- a/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java +++ b/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java @@ -43,7 +43,6 @@ import java.time.temporal.ValueRange; import java.util.function.IntFunction; import java.util.function.IntPredicate; -import java.util.function.Predicate; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java b/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java index ea7e7c44..3e19aab4 100644 --- a/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java @@ -54,6 +54,7 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.time.DateTimeException; @@ -1307,8 +1308,8 @@ public void test_equals() { assertEquals(false, a1.equals(c)); assertEquals(false, a1.equals(d)); - assertEquals(false, a1.equals(null)); - assertEquals(false, a1.equals("")); + assertFalse(a1.equals(null)); + assertFalse(a1.equals((Object) "")); assertTrue(a1.hashCode() == a2.hashCode()); } diff --git a/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java b/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java index 5637e6c5..265cdde8 100644 --- a/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java @@ -54,6 +54,7 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.time.DateTimeException; @@ -706,8 +707,8 @@ public void test_equals() { assertEquals(false, a1.equals(c)); assertEquals(false, a1.equals(d)); - assertEquals(false, a1.equals(null)); - assertEquals(false, a1.equals("")); + assertFalse(a1.equals(null)); + assertFalse(a1.equals((Object) "")); assertTrue(a1.hashCode() == a2.hashCode()); } diff --git a/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java b/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java index 0b3050a3..1103c75e 100644 --- a/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java @@ -55,6 +55,7 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.time.DateTimeException; @@ -73,7 +74,6 @@ import java.time.temporal.ValueRange; import java.util.List; import java.util.function.IntPredicate; -import java.util.function.Predicate; import org.junit.Assert; import org.junit.Test; @@ -988,8 +988,8 @@ public void test_equals() { assertEquals(false, a1.equals(c)); assertEquals(false, a1.equals(d)); - assertEquals(false, a1.equals(null)); - assertEquals(false, a1.equals("")); + assertFalse(a1.equals(null)); + assertFalse(a1.equals((Object) "")); assertTrue(a1.hashCode() == a2.hashCode()); } diff --git a/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java b/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java index 63167d74..067e537a 100644 --- a/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java @@ -54,6 +54,7 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.time.DateTimeException; @@ -731,8 +732,8 @@ public void test_equals() { assertEquals(false, a1.equals(c)); assertEquals(false, a1.equals(d)); - assertEquals(false, a1.equals(null)); - assertEquals(false, a1.equals("")); + assertFalse(a1.equals(null)); + assertFalse(a1.equals((Object) "")); assertTrue(a1.hashCode() == a2.hashCode()); } diff --git a/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java b/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java index efe59e2d..4cf6aced 100644 --- a/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java @@ -1350,7 +1350,7 @@ public void test_equals(InternationalFixedDate a1, InternationalFixedDate b, Int assertFalse(a1.equals(d)); assertFalse(a1.equals(null)); - assertFalse("".equals(a1)); + assertFalse(a1.equals((Object) "")); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java b/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java index 5080828d..33433c3d 100644 --- a/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java @@ -54,6 +54,7 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.time.DateTimeException; @@ -736,8 +737,8 @@ public void test_equals() { assertEquals(false, a1.equals(c)); assertEquals(false, a1.equals(d)); - assertEquals(false, a1.equals(null)); - assertEquals(false, a1.equals("")); + assertFalse(a1.equals(null)); + assertFalse(a1.equals((Object) "")); assertTrue(a1.hashCode() == a2.hashCode()); } diff --git a/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java b/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java index 6aa62874..44d62833 100644 --- a/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java @@ -54,6 +54,7 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.time.DateTimeException; @@ -888,8 +889,8 @@ public void test_equals() { assertEquals(false, a1.equals(c)); assertEquals(false, a1.equals(d)); - assertEquals(false, a1.equals(null)); - assertEquals(false, a1.equals("")); + assertFalse(a1.equals(null)); + assertFalse(a1.equals((Object) "")); assertTrue(a1.hashCode() == a2.hashCode()); } diff --git a/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java b/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java index 9d1074c8..3fe6e840 100644 --- a/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java @@ -999,7 +999,7 @@ public void test_equals(Symmetry010Date a1, Symmetry010Date b, Symmetry010Date c assertFalse(a1.equals(d)); assertFalse(a1.equals(null)); - assertFalse("".equals(a1)); + assertFalse(a1.equals((Object) "")); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java b/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java index 3e96ed9f..3f1c0cd7 100644 --- a/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java @@ -1007,7 +1007,7 @@ public void test_equals(Symmetry454Date a1, Symmetry454Date b, Symmetry454Date c assertFalse(a1.equals(d)); assertFalse(a1.equals(null)); - assertFalse("".equals(a1)); + assertFalse(a1.equals((Object) "")); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/scale/TestTaiInstant.java b/src/test/java/org/threeten/extra/scale/TestTaiInstant.java index 806bfb3f..d038bc79 100644 --- a/src/test/java/org/threeten/extra/scale/TestTaiInstant.java +++ b/src/test/java/org/threeten/extra/scale/TestTaiInstant.java @@ -811,7 +811,7 @@ public void test_equals_null() { @Test public void test_equals_otherClass() { TaiInstant test5 = TaiInstant.ofTaiSeconds(5L, 20); - assertEquals(false, test5.equals("")); + assertEquals(false, test5.equals((Object) "")); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/scale/TestUtcInstant.java b/src/test/java/org/threeten/extra/scale/TestUtcInstant.java index e2b872ad..eaf01781 100644 --- a/src/test/java/org/threeten/extra/scale/TestUtcInstant.java +++ b/src/test/java/org/threeten/extra/scale/TestUtcInstant.java @@ -570,7 +570,7 @@ public void test_equals_null() { @Test public void test_equals_otherClass() { UtcInstant test5 = UtcInstant.ofModifiedJulianDay(5L, 20); - assertEquals(false, test5.equals("")); + assertEquals(false, test5.equals((Object) "")); } //----------------------------------------------------------------------- From d005cfff500ab5055ae130bcd148724c374251b7 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Thu, 18 Feb 2021 11:32:14 +0000 Subject: [PATCH 191/279] Prepare for release v1.6.0 --- README.md | 4 ++-- src/changes/changes.xml | 2 +- src/site/markdown/index.md | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d7fa1e11..0be4f4e8 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ Various documentation is available: ### Releases -Release 1.5.0 is the current release. -This release is considered stable and worthy of the 1.x tag. +Release 1.6.0 is the current release. +This release is considered stable and worthy of the 1.x tag as per [SemVer](https://semver.org/spec/v2.0.0.html). ThreeTen-Extra requires Java SE 8 or later and has no dependencies. diff --git a/src/changes/changes.xml b/src/changes/changes.xml index bf9158ac..79bd2acf 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,7 +7,7 @@ - + Add OffsetDate. Fixes #137. diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index e9b97060..0d7c4eb8 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -52,7 +52,7 @@ Various documentation is available: ## Releases -Release 1.5.0 is the current release. +Release 1.6.0 is the current release. This release is considered stable and worthy of the 1.x tag as per [SemVer](https://semver.org/spec/v2.0.0.html). ThreeTen-Extra requires Java SE 8 or later and has no [dependencies](dependencies.html). @@ -63,7 +63,7 @@ Available in [Maven Central](https://search.maven.org/search?q=g:org.threeten%20 org.threeten threeten-extra - 1.5.0 + 1.6.0 ``` From 7d7e85cac1d18a775a6fb6495bf5926f63cfd811 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Thu, 18 Feb 2021 11:34:22 +0000 Subject: [PATCH 192/279] [maven-release-plugin] prepare release v1.6.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 2848f82b..027d7027 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.6.0-SNAPSHOT + 1.6.0 Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later https://www.threeten.org/threeten-extra @@ -144,7 +144,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git https://github.com/ThreeTen/threeten-extra - HEAD + v1.6.0 ThreeTen.org From a079e2c194e0e23b09af7b8b8ce9dc5c558de5b5 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Thu, 18 Feb 2021 11:34:33 +0000 Subject: [PATCH 193/279] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 027d7027..bdeb32ea 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.6.0 + 1.6.1-SNAPSHOT Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later https://www.threeten.org/threeten-extra @@ -144,7 +144,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git https://github.com/ThreeTen/threeten-extra - v1.6.0 + HEAD ThreeTen.org From 66fd7651a92aa406bd21f0fc34656822c5b606bd Mon Sep 17 00:00:00 2001 From: mjustin <1580571+mjustin@users.noreply.github.com> Date: Wed, 3 Mar 2021 16:44:42 -0600 Subject: [PATCH 194/279] Upgrade to JUnit 5 (#173) --- pom.xml | 28 +- .../threeten/extra/AbstractDateTimeTest.java | 65 +-- .../java/org/threeten/extra/TestAmPm.java | 65 +-- .../org/threeten/extra/TestAmountFormats.java | 24 +- .../java/org/threeten/extra/TestConvert.java | 16 +- .../org/threeten/extra/TestDayOfMonth.java | 91 +++-- .../org/threeten/extra/TestDayOfYear.java | 87 ++-- .../java/org/threeten/extra/TestDays.java | 141 ++++--- .../java/org/threeten/extra/TestHours.java | 105 +++-- .../java/org/threeten/extra/TestInterval.java | 111 +++-- .../threeten/extra/TestLocalDateRange.java | 189 +++++---- .../java/org/threeten/extra/TestMinutes.java | 135 +++--- .../java/org/threeten/extra/TestMonths.java | 139 +++---- .../org/threeten/extra/TestMutableClock.java | 41 +- .../org/threeten/extra/TestOffsetDate.java | 384 +++++++++--------- .../org/threeten/extra/TestPackedFields.java | 49 +-- .../threeten/extra/TestPeriodDuration.java | 73 ++-- .../java/org/threeten/extra/TestQuarter.java | 77 ++-- .../java/org/threeten/extra/TestSeconds.java | 143 ++++--- .../org/threeten/extra/TestTemporals.java | 57 ++- .../java/org/threeten/extra/TestWeeks.java | 131 +++--- .../org/threeten/extra/TestYearQuarter.java | 180 ++++---- .../java/org/threeten/extra/TestYearWeek.java | 195 +++++---- .../java/org/threeten/extra/TestYears.java | 131 +++--- .../chrono/TestAccountingChronology.java | 132 +++--- .../TestAccountingChronologyBuilder.java | 68 ++-- .../chrono/TestBritishCutoverChronology.java | 133 +++--- .../extra/chrono/TestCopticChronology.java | 117 +++--- .../chrono/TestDiscordianChronology.java | 133 +++--- .../extra/chrono/TestEthiopicChronology.java | 121 +++--- .../TestInternationalFixedChronology.java | 129 +++--- .../extra/chrono/TestJulianChronology.java | 121 +++--- .../extra/chrono/TestPaxChronology.java | 127 +++--- .../chrono/TestSymmetry010Chronology.java | 122 +++--- .../chrono/TestSymmetry454Chronology.java | 126 +++--- .../threeten/extra/scale/TestTaiInstant.java | 81 ++-- .../threeten/extra/scale/TestUtcInstant.java | 116 +++--- .../threeten/extra/scale/TestUtcRules.java | 55 ++- 38 files changed, 2084 insertions(+), 2154 deletions(-) diff --git a/pom.xml b/pom.xml index bdeb32ea..757121c7 100644 --- a/pom.xml +++ b/pom.xml @@ -70,6 +70,10 @@ Stephen A. Imhoff https://github.com/Clockwork-Muse + + M. Justin + https://github.com/mjustin + Bruno P. Kinoshita https://github.com/kinow @@ -488,15 +492,27 @@ test - junit - junit - 4.13.1 + org.junit.jupiter + junit-jupiter-api + 5.7.1 + test + + + org.junit.jupiter + junit-jupiter-params + 5.7.1 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.7.1 test - com.tngtech.java - junit-dataprovider - 1.10.0 + com.tngtech.junit.dataprovider + junit-jupiter-params-dataprovider + 2.8 test diff --git a/src/test/java/org/threeten/extra/AbstractDateTimeTest.java b/src/test/java/org/threeten/extra/AbstractDateTimeTest.java index e5be0ba9..ab270eb4 100644 --- a/src/test/java/org/threeten/extra/AbstractDateTimeTest.java +++ b/src/test/java/org/threeten/extra/AbstractDateTimeTest.java @@ -31,17 +31,17 @@ */ package org.threeten.extra; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.DateTimeException; import java.time.temporal.TemporalAccessor; import java.time.temporal.TemporalField; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Base test class for {@code DateTime}. @@ -73,7 +73,7 @@ public abstract class AbstractDateTimeTest { public void basicTest_isSupported_TemporalField_supported() { for (TemporalAccessor sample : samples()) { for (TemporalField field : validFields()) { - assertTrue("Failed on " + sample + " " + field, sample.isSupported(field)); + assertTrue(sample.isSupported(field), "Failed on " + sample + " " + field); } } } @@ -82,7 +82,7 @@ public void basicTest_isSupported_TemporalField_supported() { public void basicTest_isSupported_TemporalField_unsupported() { for (TemporalAccessor sample : samples()) { for (TemporalField field : invalidFields()) { - assertFalse("Failed on " + sample + " " + field, sample.isSupported(field)); + assertFalse(sample.isSupported(field), "Failed on " + sample + " " + field); } } } @@ -90,7 +90,7 @@ public void basicTest_isSupported_TemporalField_unsupported() { @Test public void basicTest_isSupported_TemporalField_null() { for (TemporalAccessor sample : samples()) { - assertFalse("Failed on " + sample, sample.isSupported(null)); + assertFalse(sample.isSupported(null), "Failed on " + sample); } } @@ -110,12 +110,7 @@ public void basicTest_range_TemporalField_supported() { public void basicTest_range_TemporalField_unsupported() { for (TemporalAccessor sample : samples()) { for (TemporalField field : invalidFields()) { - try { - sample.range(field); - fail("Failed on " + sample + " " + field); - } catch (DateTimeException ex) { - // expected - } + assertThrows(DateTimeException.class, () -> sample.range(field), "Failed on " + sample + " " + field); } } } @@ -123,12 +118,7 @@ public void basicTest_range_TemporalField_unsupported() { @Test public void basicTest_range_TemporalField_null() { for (TemporalAccessor sample : samples()) { - try { - sample.range(null); - fail("Failed on " + sample); - } catch (NullPointerException ex) { - // expected - } + assertThrows(NullPointerException.class, () -> sample.range(null), "Failed on " + sample); } } @@ -142,12 +132,7 @@ public void basicTest_get_TemporalField_supported() { if (sample.range(field).isIntValue()) { sample.get(field); // no exception } else { - try { - sample.get(field); - fail("Failed on " + sample + " " + field); - } catch (DateTimeException ex) { - // expected - } + assertThrows(DateTimeException.class, () -> sample.get(field), "Failed on " + sample + " " + field); } } } @@ -157,12 +142,7 @@ public void basicTest_get_TemporalField_supported() { public void basicTest_get_TemporalField_unsupported() { for (TemporalAccessor sample : samples()) { for (TemporalField field : invalidFields()) { - try { - sample.get(field); - fail("Failed on " + sample + " " + field); - } catch (DateTimeException ex) { - // expected - } + assertThrows(DateTimeException.class, () -> sample.get(field), "Failed on " + sample + " " + field); } } } @@ -170,12 +150,7 @@ public void basicTest_get_TemporalField_unsupported() { @Test public void basicTest_get_TemporalField_null() { for (TemporalAccessor sample : samples()) { - try { - sample.get(null); - fail("Failed on " + sample); - } catch (NullPointerException ex) { - // expected - } + assertThrows(NullPointerException.class, () -> sample.get(null), "Failed on " + sample); } } @@ -195,12 +170,7 @@ public void basicTest_getLong_TemporalField_supported() { public void basicTest_getLong_TemporalField_unsupported() { for (TemporalAccessor sample : samples()) { for (TemporalField field : invalidFields()) { - try { - sample.getLong(field); - fail("Failed on " + sample + " " + field); - } catch (DateTimeException ex) { - // expected - } + assertThrows(DateTimeException.class, () -> sample.getLong(field), "Failed on " + sample + " " + field); } } } @@ -208,12 +178,7 @@ public void basicTest_getLong_TemporalField_unsupported() { @Test public void basicTest_getLong_TemporalField_null() { for (TemporalAccessor sample : samples()) { - try { - sample.getLong(null); - fail("Failed on " + sample); - } catch (NullPointerException ex) { - // expected - } + assertThrows(NullPointerException.class, () -> sample.getLong(null), "Failed on " + sample); } } diff --git a/src/test/java/org/threeten/extra/TestAmPm.java b/src/test/java/org/threeten/extra/TestAmPm.java index 5357a55a..4dc74d45 100644 --- a/src/test/java/org/threeten/extra/TestAmPm.java +++ b/src/test/java/org/threeten/extra/TestAmPm.java @@ -62,9 +62,10 @@ import static java.time.temporal.ChronoField.YEAR; import static java.time.temporal.ChronoField.YEAR_OF_ERA; import static java.time.temporal.ChronoUnit.HALF_DAYS; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.Serializable; import java.time.DateTimeException; @@ -76,7 +77,7 @@ import java.time.temporal.UnsupportedTemporalTypeException; import java.util.Locale; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test AmPm. @@ -103,14 +104,14 @@ public void test_of_int_singleton_equals() { } } - @Test(expected = DateTimeException.class) + @Test public void test_of_int_valueTooLow() { - AmPm.of(-1); + assertThrows(DateTimeException.class, () -> AmPm.of(-1)); } - @Test(expected = DateTimeException.class) + @Test public void test_of_int_valueTooHigh() { - AmPm.of(2); + assertThrows(DateTimeException.class, () -> AmPm.of(2)); } //----------------------------------------------------------------------- @@ -126,14 +127,14 @@ public void test_ofHour_int_singleton() { } } - @Test(expected = DateTimeException.class) + @Test public void test_ofHour_int_valueTooLow() { - AmPm.ofHour(-1); + assertThrows(DateTimeException.class, () -> AmPm.ofHour(-1)); } - @Test(expected = DateTimeException.class) + @Test public void test_ofHour_int_valueTooHigh() { - AmPm.ofHour(24); + assertThrows(DateTimeException.class, () -> AmPm.ofHour(24)); } //----------------------------------------------------------------------- @@ -145,14 +146,14 @@ public void test_from_TemporalAccessor() { assertEquals(AmPm.PM, AmPm.from(LocalTime.of(17, 30))); } - @Test(expected = DateTimeException.class) + @Test public void test_from_TemporalAccessor_invalid_noDerive() { - AmPm.from(LocalDate.of(2007, 7, 30)); + assertThrows(DateTimeException.class, () -> AmPm.from(LocalDate.of(2007, 7, 30))); } - @Test(expected = NullPointerException.class) + @Test public void test_from_TemporalAccessor_null() { - AmPm.from((TemporalAccessor) null); + assertThrows(NullPointerException.class, () -> AmPm.from((TemporalAccessor) null)); } //----------------------------------------------------------------------- @@ -163,14 +164,14 @@ public void test_getDisplayName() { assertEquals("AM", AmPm.AM.getDisplayName(TextStyle.SHORT, Locale.US)); } - @Test(expected = NullPointerException.class) + @Test public void test_getDisplayName_nullStyle() { - AmPm.AM.getDisplayName(null, Locale.US); + assertThrows(NullPointerException.class, () -> AmPm.AM.getDisplayName(null, Locale.US)); } - @Test(expected = NullPointerException.class) + @Test public void test_getDisplayName_nullLocale() { - AmPm.AM.getDisplayName(TextStyle.FULL, null); + assertThrows(NullPointerException.class, () -> AmPm.AM.getDisplayName(TextStyle.FULL, null)); } //----------------------------------------------------------------------- @@ -220,14 +221,14 @@ public void test_range() { assertEquals(AMPM_OF_DAY.range(), AmPm.AM.range(AMPM_OF_DAY)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_range_invalidField() { - AmPm.AM.range(MONTH_OF_YEAR); + assertThrows(UnsupportedTemporalTypeException.class, () -> AmPm.AM.range(MONTH_OF_YEAR)); } - @Test(expected = NullPointerException.class) + @Test public void test_range_null() { - AmPm.AM.range(null); + assertThrows(NullPointerException.class, () -> AmPm.AM.range(null)); } //----------------------------------------------------------------------- @@ -239,14 +240,14 @@ public void test_get() { assertEquals(1, AmPm.PM.get(AMPM_OF_DAY)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_get_invalidField() { - AmPm.PM.get(MONTH_OF_YEAR); + assertThrows(UnsupportedTemporalTypeException.class, () -> AmPm.PM.get(MONTH_OF_YEAR)); } - @Test(expected = NullPointerException.class) + @Test public void test_get_null() { - AmPm.PM.get(null); + assertThrows(NullPointerException.class, () -> AmPm.PM.get(null)); } //----------------------------------------------------------------------- @@ -258,14 +259,14 @@ public void test_getLong() { assertEquals(1, AmPm.PM.getLong(AMPM_OF_DAY)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_getLong_invalidField() { - AmPm.PM.getLong(MONTH_OF_YEAR); + assertThrows(UnsupportedTemporalTypeException.class, () -> AmPm.PM.getLong(MONTH_OF_YEAR)); } - @Test(expected = NullPointerException.class) + @Test public void test_getLong_null() { - AmPm.PM.getLong(null); + assertThrows(NullPointerException.class, () -> AmPm.PM.getLong(null)); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestAmountFormats.java b/src/test/java/org/threeten/extra/TestAmountFormats.java index cbb401f1..54ef21d8 100644 --- a/src/test/java/org/threeten/extra/TestAmountFormats.java +++ b/src/test/java/org/threeten/extra/TestAmountFormats.java @@ -31,23 +31,21 @@ */ package org.threeten.extra; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.time.Duration; import java.time.Period; import java.util.Locale; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test AmountFormats. */ -@RunWith(DataProviderRunner.class) public class TestAmountFormats { private static final Locale PL = new Locale("pl"); @@ -99,7 +97,7 @@ public static Object[][] data_wordBased() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_wordBased") public void test_wordBased(Period period, Locale locale, String expected) { assertEquals(expected, AmountFormats.wordBased(period, locale)); @@ -135,7 +133,7 @@ public static Object[][] duration_wordBased() { }; } - @Test + @ParameterizedTest @UseDataProvider("duration_wordBased") public void test_wordBased(Duration duration, Locale locale, String expected) { assertEquals(expected, AmountFormats.wordBased(duration, locale)); @@ -162,7 +160,7 @@ public static Object[][] period_duration_wordBased() { }; } - @Test + @ParameterizedTest @UseDataProvider("period_duration_wordBased") public void test_wordBased(Period period, Duration duration, Locale locale, String expected) { assertEquals(expected, AmountFormats.wordBased(period, duration, locale)); @@ -295,7 +293,7 @@ public void test_wordBased_ru_formatStandard() { } // ----------------------------------------------------------------------- - @Test + @ParameterizedTest @UseDataProvider("wordBased_ru_formatSeparator") public void test_wordBased_ru_formatSeparator(String expected, Duration duration) { assertEquals(expected, AmountFormats.wordBased(duration, RU)); @@ -310,7 +308,7 @@ public static Object[][] wordBased_ru_formatSeparator() { } // ----------------------------------------------------------------------- - @Test + @ParameterizedTest @UseDataProvider("wordBased_ru_period_predicate") public void test_wordBased_ru_period_predicate(String expected, Period period) { assertEquals(expected, AmountFormats.wordBased(period, RU)); @@ -438,7 +436,7 @@ public static Object[][] wordBased_ru_period_predicate() { } // ----------------------------------------------------------------------- - @Test + @ParameterizedTest @UseDataProvider("wordBased_ru_duration_predicate") public void test_wordBased_ru_duration_predicate(String expected, Duration duration) { assertEquals(expected, AmountFormats.wordBased(duration, RU)); diff --git a/src/test/java/org/threeten/extra/TestConvert.java b/src/test/java/org/threeten/extra/TestConvert.java index 23aa9518..9db548f1 100644 --- a/src/test/java/org/threeten/extra/TestConvert.java +++ b/src/test/java/org/threeten/extra/TestConvert.java @@ -31,7 +31,7 @@ */ package org.threeten.extra; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.time.Duration; import java.time.Instant; @@ -39,16 +39,14 @@ import java.time.Period; import org.joda.convert.StringConvert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.params.ParameterizedTest; + import org.threeten.extra.scale.TaiInstant; import org.threeten.extra.scale.UtcInstant; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; -@RunWith(DataProviderRunner.class) public class TestConvert { @DataProvider @@ -71,13 +69,13 @@ public static Object[][] data_inputs() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_inputs") public void test_convertToString(Object obj, String str) { assertEquals(str, StringConvert.INSTANCE.convertToString(obj)); } - @Test + @ParameterizedTest @UseDataProvider("data_inputs") public void test_convertFromString(Object obj, String str) { assertEquals(obj, StringConvert.INSTANCE.convertFromString(obj.getClass(), str)); diff --git a/src/test/java/org/threeten/extra/TestDayOfMonth.java b/src/test/java/org/threeten/extra/TestDayOfMonth.java index eed62720..940d32c0 100644 --- a/src/test/java/org/threeten/extra/TestDayOfMonth.java +++ b/src/test/java/org/threeten/extra/TestDayOfMonth.java @@ -73,10 +73,11 @@ import static java.time.temporal.ChronoField.SECOND_OF_MINUTE; import static java.time.temporal.ChronoField.YEAR; import static java.time.temporal.ChronoField.YEAR_OF_ERA; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -107,7 +108,7 @@ import java.time.temporal.UnsupportedTemporalTypeException; import java.time.temporal.ValueRange; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test DayOfMonth. @@ -227,14 +228,14 @@ public void test_of_int_singleton() { } } - @Test(expected = DateTimeException.class) + @Test public void test_of_int_tooLow() { - DayOfMonth.of(0); + assertThrows(DateTimeException.class, () -> DayOfMonth.of(0)); } - @Test(expected = DateTimeException.class) + @Test public void test_of_int_tooHigh() { - DayOfMonth.of(32); + assertThrows(DateTimeException.class, () -> DayOfMonth.of(32)); } //----------------------------------------------------------------------- @@ -322,14 +323,14 @@ public void test_from_TemporalAccessor_nonIso() { assertEquals(date.getDayOfMonth(), DayOfMonth.from(JapaneseDate.from(date)).getValue()); } - @Test(expected = DateTimeException.class) + @Test public void test_from_TemporalAccessor_noDerive() { - DayOfMonth.from(LocalTime.NOON); + assertThrows(DateTimeException.class, () -> DayOfMonth.from(LocalTime.NOON)); } - @Test(expected = NullPointerException.class) + @Test public void test_from_TemporalAccessor_null() { - DayOfMonth.from((TemporalAccessor) null); + assertThrows(NullPointerException.class, () -> DayOfMonth.from((TemporalAccessor) null)); } @Test @@ -386,14 +387,14 @@ public void test_range() { assertEquals(DAY_OF_MONTH.range(), TEST.range(DAY_OF_MONTH)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_range_invalidField() { - TEST.range(MONTH_OF_YEAR); + assertThrows(UnsupportedTemporalTypeException.class, () -> TEST.range(MONTH_OF_YEAR)); } - @Test(expected = NullPointerException.class) + @Test public void test_range_null() { - TEST.range((TemporalField) null); + assertThrows(NullPointerException.class, () -> TEST.range((TemporalField) null)); } //----------------------------------------------------------------------- @@ -404,14 +405,14 @@ public void test_get() { assertEquals(12, TEST.get(DAY_OF_MONTH)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_get_invalidField() { - TEST.get(MONTH_OF_YEAR); + assertThrows(UnsupportedTemporalTypeException.class, () -> TEST.get(MONTH_OF_YEAR)); } - @Test(expected = NullPointerException.class) + @Test public void test_get_null() { - TEST.get((TemporalField) null); + assertThrows(NullPointerException.class, () -> TEST.get((TemporalField) null)); } //----------------------------------------------------------------------- @@ -427,19 +428,19 @@ public void test_getLong_derivedField() { assertEquals(12L, TEST.getLong(TestingField.INSTANCE)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_getLong_invalidField() { - TEST.getLong(MONTH_OF_YEAR); + assertThrows(UnsupportedTemporalTypeException.class, () -> TEST.getLong(MONTH_OF_YEAR)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_getLong_invalidField2() { - TEST.getLong(IsoFields.DAY_OF_QUARTER); + assertThrows(UnsupportedTemporalTypeException.class, () -> TEST.getLong(IsoFields.DAY_OF_QUARTER)); } - @Test(expected = NullPointerException.class) + @Test public void test_getLong_null() { - TEST.getLong((TemporalField) null); + assertThrows(NullPointerException.class, () -> TEST.getLong((TemporalField) null)); } //----------------------------------------------------------------------- @@ -547,28 +548,28 @@ public void test_adjustInto() { } } - @Test(expected = DateTimeException.class) + @Test public void test_adjustInto_april31() { LocalDate base = LocalDate.of(2007, 4, 1); DayOfMonth test = DayOfMonth.of(31); - test.adjustInto(base); + assertThrows(DateTimeException.class, () -> test.adjustInto(base)); } - @Test(expected = DateTimeException.class) + @Test public void test_adjustInto_february29_notLeapYear() { LocalDate base = LocalDate.of(2007, 2, 1); DayOfMonth test = DayOfMonth.of(29); - test.adjustInto(base); + assertThrows(DateTimeException.class, () -> test.adjustInto(base)); } - @Test(expected = DateTimeException.class) + @Test public void test_adjustInto_nonIso() { - TEST.adjustInto(JapaneseDate.now()); + assertThrows(DateTimeException.class, () -> TEST.adjustInto(JapaneseDate.now())); } - @Test(expected = NullPointerException.class) + @Test public void test_adjustInto_null() { - TEST.adjustInto((Temporal) null); + assertThrows(NullPointerException.class, () -> TEST.adjustInto((Temporal) null)); } //----------------------------------------------------------------------- @@ -608,9 +609,9 @@ public void test_atMonth_Month_28() { assertEquals(MonthDay.of(12, 28), test.atMonth(DECEMBER)); } - @Test(expected = NullPointerException.class) + @Test public void test_atMonth_null() { - TEST.atMonth((Month) null); + assertThrows(NullPointerException.class, () -> TEST.atMonth((Month) null)); } //----------------------------------------------------------------------- @@ -650,14 +651,14 @@ public void test_atMonth_int_28() { assertEquals(MonthDay.of(12, 28), test.atMonth(12)); } - @Test(expected = DateTimeException.class) + @Test public void test_atMonth_tooLow() { - TEST.atMonth(0); + assertThrows(DateTimeException.class, () -> TEST.atMonth(0)); } - @Test(expected = DateTimeException.class) + @Test public void test_atMonth_tooHigh() { - TEST.atMonth(13); + assertThrows(DateTimeException.class, () -> TEST.atMonth(13)); } //----------------------------------------------------------------------- @@ -698,9 +699,9 @@ public void test_atYearMonth_28() { assertEquals(LocalDate.of(2012, 12, 28), test.atYearMonth(YearMonth.of(2012, 12))); } - @Test(expected = NullPointerException.class) + @Test public void test_atYearMonth_null() { - TEST.atYearMonth((YearMonth) null); + assertThrows(NullPointerException.class, () -> TEST.atYearMonth((YearMonth) null)); } //----------------------------------------------------------------------- @@ -726,11 +727,11 @@ public void test_compareTo() { } } - @Test(expected = NullPointerException.class) + @Test public void test_compareTo_nullDayOfMonth() { DayOfMonth doy = null; DayOfMonth test = DayOfMonth.of(1); - test.compareTo(doy); + assertThrows(NullPointerException.class, () -> test.compareTo(doy)); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestDayOfYear.java b/src/test/java/org/threeten/extra/TestDayOfYear.java index d4818cc2..90735b94 100644 --- a/src/test/java/org/threeten/extra/TestDayOfYear.java +++ b/src/test/java/org/threeten/extra/TestDayOfYear.java @@ -61,8 +61,9 @@ import static java.time.temporal.ChronoField.SECOND_OF_MINUTE; import static java.time.temporal.ChronoField.YEAR; import static java.time.temporal.ChronoField.YEAR_OF_ERA; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -91,7 +92,7 @@ import java.time.temporal.UnsupportedTemporalTypeException; import java.time.temporal.ValueRange; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test DayOfYear. @@ -214,14 +215,14 @@ public void test_of_int() { } } - @Test(expected = DateTimeException.class) + @Test public void test_of_int_tooLow() { - DayOfYear.of(0); + assertThrows(DateTimeException.class, () -> DayOfYear.of(0)); } - @Test(expected = DateTimeException.class) + @Test public void test_of_int_tooHigh() { - DayOfYear.of(367); + assertThrows(DateTimeException.class, () -> DayOfYear.of(367)); } //----------------------------------------------------------------------- @@ -261,14 +262,14 @@ public void test_from_TemporalAccessor_nonIso() { assertEquals(date.getDayOfYear(), DayOfYear.from(JapaneseDate.from(date)).getValue()); } - @Test(expected = DateTimeException.class) + @Test public void test_from_TemporalAccessor_noDerive() { - DayOfYear.from(LocalTime.NOON); + assertThrows(DateTimeException.class, () -> DayOfYear.from(LocalTime.NOON)); } - @Test(expected = NullPointerException.class) + @Test public void test_from_TemporalAccessor_null() { - DayOfYear.from((TemporalAccessor) null); + assertThrows(NullPointerException.class, () -> DayOfYear.from((TemporalAccessor) null)); } @Test @@ -324,14 +325,14 @@ public void test_range() { assertEquals(DAY_OF_YEAR.range(), TEST.range(DAY_OF_YEAR)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_range_invalidField() { - TEST.range(MONTH_OF_YEAR); + assertThrows(UnsupportedTemporalTypeException.class, () -> TEST.range(MONTH_OF_YEAR)); } - @Test(expected = NullPointerException.class) + @Test public void test_range_null() { - TEST.range((TemporalField) null); + assertThrows(NullPointerException.class, () -> TEST.range((TemporalField) null)); } //----------------------------------------------------------------------- @@ -342,14 +343,14 @@ public void test_get() { assertEquals(12, TEST.get(DAY_OF_YEAR)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_get_invalidField() { - TEST.get(MONTH_OF_YEAR); + assertThrows(UnsupportedTemporalTypeException.class, () -> TEST.get(MONTH_OF_YEAR)); } - @Test(expected = NullPointerException.class) + @Test public void test_get_null() { - TEST.get((TemporalField) null); + assertThrows(NullPointerException.class, () -> TEST.get((TemporalField) null)); } //----------------------------------------------------------------------- @@ -365,19 +366,19 @@ public void test_getLong_derivedField() { assertEquals(12L, TEST.getLong(TestingField.INSTANCE)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_getLong_invalidField() { - TEST.getLong(MONTH_OF_YEAR); + assertThrows(UnsupportedTemporalTypeException.class, () -> TEST.getLong(MONTH_OF_YEAR)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_getLong_invalidField2() { - TEST.getLong(IsoFields.DAY_OF_QUARTER); + assertThrows(UnsupportedTemporalTypeException.class, () -> TEST.getLong(IsoFields.DAY_OF_QUARTER)); } - @Test(expected = NullPointerException.class) + @Test public void test_getLong_null() { - TEST.getLong((TemporalField) null); + assertThrows(NullPointerException.class, () -> TEST.getLong((TemporalField) null)); } //----------------------------------------------------------------------- @@ -438,18 +439,18 @@ public void test_adjustInto_fromEndOfYear_notLeapYear() { } } - @Test(expected = DateTimeException.class) + @Test public void test_adjustInto_fromStartOfYear_notLeapYear_day366() { LocalDate base = LocalDate.of(2007, 1, 1); DayOfYear test = DayOfYear.of(LEAP_YEAR_LENGTH); - test.adjustInto(base); + assertThrows(DateTimeException.class, () -> test.adjustInto(base)); } - @Test(expected = DateTimeException.class) + @Test public void test_adjustInto_fromEndOfYear_notLeapYear_day366() { LocalDate base = LocalDate.of(2007, 12, 31); DayOfYear test = DayOfYear.of(LEAP_YEAR_LENGTH); - test.adjustInto(base); + assertThrows(DateTimeException.class, () -> test.adjustInto(base)); } @Test @@ -474,14 +475,14 @@ public void test_adjustInto_fromEndOfYear_leapYear() { } } - @Test(expected = DateTimeException.class) + @Test public void test_adjustInto_nonIso() { - TEST.adjustInto(JapaneseDate.now()); + assertThrows(DateTimeException.class, () -> TEST.adjustInto(JapaneseDate.now())); } - @Test(expected = NullPointerException.class) + @Test public void test_adjustInto_null() { - TEST.adjustInto((Temporal) null); + assertThrows(NullPointerException.class, () -> TEST.adjustInto((Temporal) null)); } //----------------------------------------------------------------------- @@ -497,10 +498,10 @@ public void test_atYear_Year_notLeapYear() { } } - @Test(expected = DateTimeException.class) + @Test public void test_atYear_fromStartOfYear_notLeapYear_day366() { DayOfYear test = DayOfYear.of(LEAP_YEAR_LENGTH); - test.atYear(YEAR_STANDARD); + assertThrows(DateTimeException.class, () -> test.atYear(YEAR_STANDARD)); } @Test @@ -513,9 +514,9 @@ public void test_atYear_Year_leapYear() { } } - @Test(expected = NullPointerException.class) + @Test public void test_atYear_Year_nullYear() { - TEST.atYear((Year) null); + assertThrows(NullPointerException.class, () -> TEST.atYear((Year) null)); } //----------------------------------------------------------------------- @@ -531,10 +532,10 @@ public void test_atYear_int_notLeapYear() { } } - @Test(expected = DateTimeException.class) + @Test public void test_atYear_int_fromStartOfYear_notLeapYear_day366() { DayOfYear test = DayOfYear.of(LEAP_YEAR_LENGTH); - test.atYear(2007); + assertThrows(DateTimeException.class, () -> test.atYear(2007)); } @Test @@ -547,9 +548,9 @@ public void test_atYear_int_leapYear() { } } - @Test(expected = DateTimeException.class) + @Test public void test_atYear_int_invalidDay() { - TEST.atYear(Year.MIN_VALUE - 1); + assertThrows(DateTimeException.class, () -> TEST.atYear(Year.MIN_VALUE - 1)); } //----------------------------------------------------------------------- @@ -575,11 +576,11 @@ public void test_compareTo() { } } - @Test(expected = NullPointerException.class) + @Test public void test_compareTo_nullDayOfYear() { DayOfYear doy = null; DayOfYear test = DayOfYear.of(1); - test.compareTo(doy); + assertThrows(NullPointerException.class, () -> test.compareTo(doy)); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestDays.java b/src/test/java/org/threeten/extra/TestDays.java index bb269c99..e591dbac 100644 --- a/src/test/java/org/threeten/extra/TestDays.java +++ b/src/test/java/org/threeten/extra/TestDays.java @@ -31,10 +31,11 @@ */ package org.threeten.extra; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -51,17 +52,15 @@ import java.time.temporal.Temporal; import java.time.temporal.TemporalAmount; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test class. */ -@RunWith(DataProviderRunner.class) public class TestDays { //----------------------------------------------------------------------- @@ -136,9 +135,9 @@ public void test_ofWeeks() { assertEquals((Integer.MIN_VALUE / 7) * 7, Days.ofWeeks(Integer.MIN_VALUE / 7).getAmount()); } - @Test(expected = ArithmeticException.class) + @Test public void test_ofWeeks_overflow() { - Days.ofWeeks((Integer.MAX_VALUE / 7) + 7); + assertThrows(ArithmeticException.class, () -> Days.ofWeeks((Integer.MAX_VALUE / 7) + 7)); } //----------------------------------------------------------------------- @@ -167,19 +166,19 @@ public void test_from_Duration() { assertEquals(Days.of(2), Days.from(Duration.ofDays(2))); } - @Test(expected = DateTimeException.class) + @Test public void test_from_wrongUnit_remainder() { - Days.from(Duration.ofHours(3)); + assertThrows(DateTimeException.class, () -> Days.from(Duration.ofHours(3))); } - @Test(expected = DateTimeException.class) + @Test public void test_from_wrongUnit_noConversion() { - Days.from(Period.ofMonths(2)); + assertThrows(DateTimeException.class, () -> Days.from(Period.ofMonths(2))); } - @Test(expected = NullPointerException.class) + @Test public void test_from_null() { - Days.from((TemporalAmount) null); + assertThrows(NullPointerException.class, () -> Days.from((TemporalAmount) null)); } //----------------------------------------------------------------------- @@ -214,19 +213,19 @@ public static Object[][] data_valid() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_valid") public void test_parse_CharSequence_valid(String str, int expectedDays) { assertEquals(Days.of(expectedDays), Days.parse(str)); } - @Test + @ParameterizedTest @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, int expectedDays) { assertEquals(Days.of(expectedDays), Days.parse("+" + str)); } - @Test + @ParameterizedTest @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, int expectedDays) { assertEquals(Days.of(-expectedDays), Days.parse("-" + str)); @@ -252,15 +251,15 @@ public static Object[][] data_invalid() { }; } - @Test(expected = DateTimeParseException.class) + @ParameterizedTest @UseDataProvider("data_invalid") public void test_parse_CharSequence_invalid(String str) { - Days.parse(str); + assertThrows(DateTimeParseException.class, () -> Days.parse(str)); } - @Test(expected = NullPointerException.class) + @Test public void test_parse_CharSequence_null() { - Days.parse((CharSequence) null); + assertThrows(NullPointerException.class, () -> Days.parse((CharSequence) null)); } //----------------------------------------------------------------------- @@ -269,9 +268,9 @@ public void test_get() { assertEquals(6, Days.of(6).get(ChronoUnit.DAYS)); } - @Test(expected = DateTimeException.class) + @Test public void test_get_invalidType() { - Days.of(6).get(IsoFields.QUARTER_YEARS); + assertThrows(DateTimeException.class, () -> Days.of(6).get(IsoFields.QUARTER_YEARS)); } //----------------------------------------------------------------------- @@ -280,14 +279,14 @@ public void test_between() { assertEquals(Days.of(365 + 366), Days.between(LocalDate.of(2019, 1, 1), LocalDate.of(2021, 1, 1))); } - @Test(expected = NullPointerException.class) + @Test public void test_between_date_null() { - Days.between(LocalDate.now(), (Temporal) null); + assertThrows(NullPointerException.class, () -> Days.between(LocalDate.now(), (Temporal) null)); } - @Test(expected = NullPointerException.class) + @Test public void test_between_null_date() { - Days.between((Temporal) null, LocalDate.now()); + assertThrows(NullPointerException.class, () -> Days.between((Temporal) null, LocalDate.now())); } //----------------------------------------------------------------------- @@ -311,29 +310,29 @@ public void test_plus_TemporalAmount_Period() { assertEquals(Days.of(Integer.MIN_VALUE), Days.of(Integer.MIN_VALUE + 1).plus(Period.ofDays(-1))); } - @Test(expected = DateTimeException.class) + @Test public void test_plus_TemporalAmount_PeriodYears() { - Days.of(1).plus(Period.ofYears(2)); + assertThrows(DateTimeException.class, () -> Days.of(1).plus(Period.ofYears(2))); } - @Test(expected = DateTimeException.class) + @Test public void test_plus_TemporalAmount_Duration() { - Days.of(1).plus(Duration.ofHours(2)); + assertThrows(DateTimeException.class, () -> Days.of(1).plus(Duration.ofHours(2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_TemporalAmount_overflowTooBig() { - Days.of(Integer.MAX_VALUE - 1).plus(Days.of(2)); + assertThrows(ArithmeticException.class, () -> Days.of(Integer.MAX_VALUE - 1).plus(Days.of(2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_TemporalAmount_overflowTooSmall() { - Days.of(Integer.MIN_VALUE + 1).plus(Days.of(-2)); + assertThrows(ArithmeticException.class, () -> Days.of(Integer.MIN_VALUE + 1).plus(Days.of(-2))); } - @Test(expected = NullPointerException.class) + @Test public void test_plus_TemporalAmount_null() { - Days.of(Integer.MIN_VALUE + 1).plus(null); + assertThrows(NullPointerException.class, () -> Days.of(Integer.MIN_VALUE + 1).plus(null)); } //----------------------------------------------------------------------- @@ -347,14 +346,14 @@ public void test_plus_int() { assertEquals(Days.of(Integer.MIN_VALUE), Days.of(Integer.MIN_VALUE + 1).plus(-1)); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_int_overflowTooBig() { - Days.of(Integer.MAX_VALUE - 1).plus(2); + assertThrows(ArithmeticException.class, () -> Days.of(Integer.MAX_VALUE - 1).plus(2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_int_overflowTooSmall() { - Days.of(Integer.MIN_VALUE + 1).plus(-2); + assertThrows(ArithmeticException.class, () -> Days.of(Integer.MIN_VALUE + 1).plus(-2)); } //----------------------------------------------------------------------- @@ -378,29 +377,29 @@ public void test_minus_TemporalAmount_Period() { assertEquals(Days.of(Integer.MIN_VALUE), Days.of(Integer.MIN_VALUE + 1).minus(Period.ofDays(1))); } - @Test(expected = DateTimeException.class) + @Test public void test_minus_TemporalAmount_PeriodYears() { - Days.of(1).minus(Period.ofYears(2)); + assertThrows(DateTimeException.class, () -> Days.of(1).minus(Period.ofYears(2))); } - @Test(expected = DateTimeException.class) + @Test public void test_minus_TemporalAmount_Duration() { - Days.of(1).minus(Duration.ofHours(2)); + assertThrows(DateTimeException.class, () -> Days.of(1).minus(Duration.ofHours(2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_TemporalAmount_overflowTooBig() { - Days.of(Integer.MAX_VALUE - 1).minus(Days.of(-2)); + assertThrows(ArithmeticException.class, () -> Days.of(Integer.MAX_VALUE - 1).minus(Days.of(-2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_TemporalAmount_overflowTooSmall() { - Days.of(Integer.MIN_VALUE + 1).minus(Days.of(2)); + assertThrows(ArithmeticException.class, () -> Days.of(Integer.MIN_VALUE + 1).minus(Days.of(2))); } - @Test(expected = NullPointerException.class) + @Test public void test_minus_TemporalAmount_null() { - Days.of(Integer.MIN_VALUE + 1).minus(null); + assertThrows(NullPointerException.class, () -> Days.of(Integer.MIN_VALUE + 1).minus(null)); } //----------------------------------------------------------------------- @@ -414,14 +413,14 @@ public void test_minus_int() { assertEquals(Days.of(Integer.MIN_VALUE), Days.of(Integer.MIN_VALUE + 1).minus(1)); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_int_overflowTooBig() { - Days.of(Integer.MAX_VALUE - 1).minus(-2); + assertThrows(ArithmeticException.class, () -> Days.of(Integer.MAX_VALUE - 1).minus(-2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_int_overflowTooSmall() { - Days.of(Integer.MIN_VALUE + 1).minus(2); + assertThrows(ArithmeticException.class, () -> Days.of(Integer.MIN_VALUE + 1).minus(2)); } //----------------------------------------------------------------------- @@ -441,14 +440,14 @@ public void test_multipliedBy_negate() { assertEquals(Days.of(-15), test5.multipliedBy(-3)); } - @Test(expected = ArithmeticException.class) + @Test public void test_multipliedBy_overflowTooBig() { - Days.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2); + assertThrows(ArithmeticException.class, () -> Days.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_multipliedBy_overflowTooSmall() { - Days.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2); + assertThrows(ArithmeticException.class, () -> Days.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2)); } //----------------------------------------------------------------------- @@ -470,9 +469,9 @@ public void test_dividedBy_negate() { assertEquals(Days.of(-4), test12.dividedBy(-3)); } - @Test(expected = ArithmeticException.class) + @Test public void test_dividedBy_divideByZero() { - Days.of(1).dividedBy(0); + assertThrows(ArithmeticException.class, () -> Days.of(1).dividedBy(0)); } //----------------------------------------------------------------------- @@ -484,9 +483,9 @@ public void test_negated() { assertEquals(Days.of(-Integer.MAX_VALUE), Days.of(Integer.MAX_VALUE).negated()); } - @Test(expected = ArithmeticException.class) + @Test public void test_negated_overflow() { - Days.of(Integer.MIN_VALUE).negated(); + assertThrows(ArithmeticException.class, () -> Days.of(Integer.MIN_VALUE).negated()); } //----------------------------------------------------------------------- @@ -499,9 +498,9 @@ public void test_abs() { assertEquals(Days.of(Integer.MAX_VALUE), Days.of(-Integer.MAX_VALUE).abs()); } - @Test(expected = ArithmeticException.class) + @Test public void test_abs_overflow() { - Days.of(Integer.MIN_VALUE).abs(); + assertThrows(ArithmeticException.class, () -> Days.of(Integer.MIN_VALUE).abs()); } //----------------------------------------------------------------------- @@ -535,10 +534,10 @@ public void test_compareTo() { assertEquals(1, test6.compareTo(test5)); } - @Test(expected = NullPointerException.class) + @Test public void test_compareTo_null() { Days test5 = Days.of(5); - test5.compareTo(null); + assertThrows(NullPointerException.class, () -> test5.compareTo(null)); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestHours.java b/src/test/java/org/threeten/extra/TestHours.java index 496df6a0..33252e8b 100644 --- a/src/test/java/org/threeten/extra/TestHours.java +++ b/src/test/java/org/threeten/extra/TestHours.java @@ -31,10 +31,11 @@ */ package org.threeten.extra; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -45,25 +46,23 @@ import java.time.LocalTime; import java.time.format.DateTimeParseException; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test class. */ -@RunWith(DataProviderRunner.class) public class TestHours { - + //----------------------------------------------------------------------- @Test public void test_isSerializable() { assertTrue(Serializable.class.isAssignableFrom(Hours.class)); } - + //----------------------------------------------------------------------- @Test public void test_deserializationSingleton() throws Exception { @@ -143,19 +142,19 @@ public static Object[][] data_valid() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_valid") public void test_parse_CharSequence_valid(String str, int expectedDays) { assertEquals(Hours.of(expectedDays), Hours.parse(str)); } - @Test + @ParameterizedTest @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, int expectedDays) { assertEquals(Hours.of(expectedDays), Hours.parse("+" + str)); } - @Test + @ParameterizedTest @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, int expectedDays) { assertEquals(Hours.of(-expectedDays), Hours.parse("-" + str)); @@ -181,17 +180,17 @@ public static Object[][] data_invalid() { }; } - @Test(expected = DateTimeParseException.class) + @ParameterizedTest @UseDataProvider("data_invalid") public void test_parse_CharSequence_invalid(String str) { - Hours.parse(str); + assertThrows(DateTimeParseException.class, () -> Hours.parse(str)); } - @Test(expected = NullPointerException.class) + @Test public void test_parse_CharSequence_null() { - Hours.parse((CharSequence) null); + assertThrows(NullPointerException.class, () -> Hours.parse((CharSequence) null)); } - + //----------------------------------------------------------------------- @Test public void test_plus_TemporalAmount_Hours() { @@ -213,19 +212,19 @@ public void test_plus_TemporalAmount_Period() { assertEquals(Hours.of(Integer.MIN_VALUE), Hours.of(Integer.MIN_VALUE + 1).plus(Duration.ofHours(-1))); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_TemporalAmount_overflowTooBig() { - Hours.of(Integer.MAX_VALUE - 1).plus(Hours.of(2)); + assertThrows(ArithmeticException.class, () -> Hours.of(Integer.MAX_VALUE - 1).plus(Hours.of(2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_TemporalAmount_overflowTooSmall() { - Hours.of(Integer.MIN_VALUE + 1).plus(Hours.of(-2)); + assertThrows(ArithmeticException.class, () -> Hours.of(Integer.MIN_VALUE + 1).plus(Hours.of(-2))); } - @Test(expected = NullPointerException.class) + @Test public void test_plus_TemporalAmount_null() { - Hours.of(Integer.MIN_VALUE + 1).plus(null); + assertThrows(NullPointerException.class, () -> Hours.of(Integer.MIN_VALUE + 1).plus(null)); } //----------------------------------------------------------------------- @@ -239,14 +238,14 @@ public void test_plus_int() { assertEquals(Hours.of(Integer.MIN_VALUE), Hours.of(Integer.MIN_VALUE + 1).plus(-1)); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_int_overflowTooBig() { - Hours.of(Integer.MAX_VALUE - 1).plus(2); + assertThrows(ArithmeticException.class, () -> Hours.of(Integer.MAX_VALUE - 1).plus(2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_int_overflowTooSmall() { - Hours.of(Integer.MIN_VALUE + 1).plus(-2); + assertThrows(ArithmeticException.class, () -> Hours.of(Integer.MIN_VALUE + 1).plus(-2)); } //----------------------------------------------------------------------- @@ -270,19 +269,19 @@ public void test_minus_TemporalAmount_Duration() { assertEquals(Hours.of(Integer.MIN_VALUE), Hours.of(Integer.MIN_VALUE + 1).minus(Duration.ofHours(1))); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_TemporalAmount_overflowTooBig() { - Hours.of(Integer.MAX_VALUE - 1).minus(Hours.of(-2)); + assertThrows(ArithmeticException.class, () -> Hours.of(Integer.MAX_VALUE - 1).minus(Hours.of(-2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_TemporalAmount_overflowTooSmall() { - Hours.of(Integer.MIN_VALUE + 1).minus(Hours.of(2)); + assertThrows(ArithmeticException.class, () -> Hours.of(Integer.MIN_VALUE + 1).minus(Hours.of(2))); } - @Test(expected = NullPointerException.class) + @Test public void test_minus_TemporalAmount_null() { - Hours.of(Integer.MIN_VALUE + 1).minus(null); + assertThrows(NullPointerException.class, () -> Hours.of(Integer.MIN_VALUE + 1).minus(null)); } //----------------------------------------------------------------------- @@ -296,14 +295,14 @@ public void test_minus_int() { assertEquals(Hours.of(Integer.MIN_VALUE), Hours.of(Integer.MIN_VALUE + 1).minus(1)); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_int_overflowTooBig() { - Hours.of(Integer.MAX_VALUE - 1).minus(-2); + assertThrows(ArithmeticException.class, () -> Hours.of(Integer.MAX_VALUE - 1).minus(-2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_int_overflowTooSmall() { - Hours.of(Integer.MIN_VALUE + 1).minus(2); + assertThrows(ArithmeticException.class, () -> Hours.of(Integer.MIN_VALUE + 1).minus(2)); } //----------------------------------------------------------------------- @@ -323,14 +322,14 @@ public void test_multipliedBy_negate() { assertEquals(Hours.of(-15), test5.multipliedBy(-3)); } - @Test(expected = ArithmeticException.class) + @Test public void test_multipliedBy_overflowTooBig() { - Hours.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2); + assertThrows(ArithmeticException.class, () -> Hours.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_multipliedBy_overflowTooSmall() { - Hours.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2); + assertThrows(ArithmeticException.class, () -> Hours.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2)); } //----------------------------------------------------------------------- @@ -352,9 +351,9 @@ public void test_dividedBy_negate() { assertEquals(Hours.of(-4), test12.dividedBy(-3)); } - @Test(expected = ArithmeticException.class) + @Test public void test_dividedBy_divideByZero() { - Hours.of(1).dividedBy(0); + assertThrows(ArithmeticException.class, () -> Hours.of(1).dividedBy(0)); } //----------------------------------------------------------------------- @@ -366,9 +365,9 @@ public void test_negated() { assertEquals(Hours.of(-Integer.MAX_VALUE), Hours.of(Integer.MAX_VALUE).negated()); } - @Test(expected = ArithmeticException.class) + @Test public void test_negated_overflow() { - Hours.of(Integer.MIN_VALUE).negated(); + assertThrows(ArithmeticException.class, () -> Hours.of(Integer.MIN_VALUE).negated()); } //----------------------------------------------------------------------- @@ -381,9 +380,9 @@ public void test_abs() { assertEquals(Hours.of(Integer.MAX_VALUE), Hours.of(-Integer.MAX_VALUE).abs()); } - @Test(expected = ArithmeticException.class) + @Test public void test_abs_overflow() { - Hours.of(Integer.MIN_VALUE).abs(); + assertThrows(ArithmeticException.class, () -> Hours.of(Integer.MIN_VALUE).abs()); } //----------------------------------------------------------------------- @@ -422,10 +421,10 @@ public void test_compareTo() { assertEquals(1, test6.compareTo(test5)); } - @Test(expected = NullPointerException.class) + @Test public void test_compareTo_null() { Hours test5 = Hours.of(5); - test5.compareTo(null); + assertThrows(NullPointerException.class, () -> test5.compareTo(null)); } //----------------------------------------------------------------------- @@ -467,5 +466,5 @@ public void test_toString() { Hours testM1 = Hours.of(-1); assertEquals("PT-1H", testM1.toString()); } - + } diff --git a/src/test/java/org/threeten/extra/TestInterval.java b/src/test/java/org/threeten/extra/TestInterval.java index 7142c100..94834bc5 100644 --- a/src/test/java/org/threeten/extra/TestInterval.java +++ b/src/test/java/org/threeten/extra/TestInterval.java @@ -33,9 +33,10 @@ import static java.time.temporal.ChronoUnit.HOURS; import static java.time.temporal.ChronoUnit.MONTHS; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -50,17 +51,15 @@ import java.time.ZonedDateTime; import java.time.format.DateTimeParseException; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test class. */ -@RunWith(DataProviderRunner.class) public class TestInterval { static Instant NOW1 = ZonedDateTime.of(2014, 12, 1, 1, 0, 0, 0, ZoneOffset.UTC).toInstant(); @@ -119,19 +118,19 @@ public void test_of_Instant_Instant_empty() { assertEquals(false, test.isUnboundedEnd()); } - @Test(expected = DateTimeException.class) + @Test public void test_of_Instant_Instant_badOrder() { - Interval.of(NOW2, NOW1); + assertThrows(DateTimeException.class, () -> Interval.of(NOW2, NOW1)); } - @Test(expected = NullPointerException.class) + @Test public void test_of_Instant_Instant_nullStart() { - Interval.of(null, NOW2); + assertThrows(NullPointerException.class, () -> Interval.of(null, NOW2)); } - @Test(expected = NullPointerException.class) + @Test public void test_of_Instant_Instant_nullEnd() { - Interval.of(NOW1, (Instant) null); + assertThrows(NullPointerException.class, () -> Interval.of(NOW1, (Instant) null)); } //----------------------------------------------------------------------- @@ -149,19 +148,19 @@ public void test_of_Instant_Duration_zero() { assertEquals(NOW1, test.getEnd()); } - @Test(expected = DateTimeException.class) + @Test public void test_of_Instant_Duration_negative() { - Interval.of(NOW2, Duration.ofSeconds(-1)); + assertThrows(DateTimeException.class, () -> Interval.of(NOW2, Duration.ofSeconds(-1))); } - @Test(expected = NullPointerException.class) + @Test public void test_of_Instant_Duration_nullInstant() { - Interval.of(null, Duration.ZERO); + assertThrows(NullPointerException.class, () -> Interval.of(null, Duration.ZERO)); } - @Test(expected = NullPointerException.class) + @Test public void test_of_Instant_Duration_nullDuration() { - Interval.of(NOW1, (Duration) null); + assertThrows(NullPointerException.class, () -> Interval.of(NOW1, (Duration) null)); } /* Lower and upper bound for Intervals */ @@ -194,8 +193,8 @@ public static Object[][] data_parseValid() { {Instant.MIN.toString() + "/" + Instant.MAX, Instant.MIN, Instant.MAX} }; } - - @Test + + @ParameterizedTest @UseDataProvider("data_parseValid") public void test_parse_CharSequence(String input, Instant start, Instant end) { Interval test = Interval.parse(input); @@ -203,19 +202,19 @@ public void test_parse_CharSequence(String input, Instant start, Instant end) { assertEquals(end, test.getEnd()); } - @Test(expected = DateTimeException.class) + @Test public void test_parse_CharSequence_badOrder() { - Interval.parse(NOW2 + "/" + NOW1); + assertThrows(DateTimeException.class, () -> Interval.parse(NOW2 + "/" + NOW1)); } - @Test(expected = DateTimeParseException.class) + @Test public void test_parse_CharSequence_badFormat() { - Interval.parse(NOW2 + "-" + NOW1); + assertThrows(DateTimeParseException.class, () -> Interval.parse(NOW2 + "-" + NOW1)); } - @Test(expected = NullPointerException.class) + @Test public void test_parse_CharSequence_null() { - Interval.parse(null); + assertThrows(NullPointerException.class, () -> Interval.parse(null)); } //----------------------------------------------------------------------- @@ -227,16 +226,16 @@ public void test_withStart() { assertEquals(NOW3, test.getEnd()); } - @Test(expected = DateTimeException.class) + @Test public void test_withStart_badOrder() { Interval base = Interval.of(NOW1, NOW2); - base.withStart(NOW3); + assertThrows(DateTimeException.class, () -> base.withStart(NOW3)); } - @Test(expected = NullPointerException.class) + @Test public void test_withStart_null() { Interval base = Interval.of(NOW1, NOW2); - base.withStart(null); + assertThrows(NullPointerException.class, () -> base.withStart(null)); } //----------------------------------------------------------------------- @@ -248,16 +247,16 @@ public void test_withEnd() { assertEquals(NOW2, test.getEnd()); } - @Test(expected = DateTimeException.class) + @Test public void test_withEnd_badOrder() { Interval base = Interval.of(NOW2, NOW3); - base.withEnd(NOW1); + assertThrows(DateTimeException.class, () -> base.withEnd(NOW1)); } - @Test(expected = NullPointerException.class) + @Test public void test_withEnd_null() { Interval base = Interval.of(NOW1, NOW2); - base.withEnd(null); + assertThrows(NullPointerException.class, () -> base.withEnd(null)); } //----------------------------------------------------------------------- @@ -289,10 +288,10 @@ public void test_contains_max() { assertEquals(true, test.contains(Instant.MAX)); } - @Test(expected = NullPointerException.class) + @Test public void test_contains_Instant_null() { Interval base = Interval.of(NOW1, NOW2); - base.contains((Instant) null); + assertThrows(NullPointerException.class, () -> base.contains((Instant) null)); } //----------------------------------------------------------------------- @@ -331,10 +330,10 @@ public void test_encloses_Interval_empty() { assertEquals(false, test.encloses(Interval.of(NOW1.plusSeconds(1), NOW1.plusSeconds(2)))); } - @Test(expected = NullPointerException.class) + @Test public void test_encloses_Interval_null() { Interval base = Interval.of(NOW1, NOW2); - base.encloses((Interval) null); + assertThrows(NullPointerException.class, () -> base.encloses((Interval) null)); } //----------------------------------------------------------------------- @@ -372,10 +371,10 @@ public void test_abuts_Interval_empty() { assertEquals(false, test.abuts(Interval.of(NOW1.plusSeconds(1), NOW1.plusSeconds(2)))); } - @Test(expected = NullPointerException.class) + @Test public void test_abuts_Interval_null() { Interval base = Interval.of(NOW1, NOW2); - base.abuts((Interval) null); + assertThrows(NullPointerException.class, () -> base.abuts((Interval) null)); } //----------------------------------------------------------------------- @@ -413,10 +412,10 @@ public void test_isConnected_Interval_empty() { assertEquals(false, test.isConnected(Interval.of(NOW1.plusSeconds(1), NOW1.plusSeconds(2)))); } - @Test(expected = NullPointerException.class) + @Test public void test_isConnected_Interval_null() { Interval base = Interval.of(NOW1, NOW2); - base.isConnected((Interval) null); + assertThrows(NullPointerException.class, () -> base.isConnected((Interval) null)); } //----------------------------------------------------------------------- @@ -454,10 +453,10 @@ public void test_overlaps_Interval_empty() { assertEquals(false, test.overlaps(Interval.of(NOW1.plusSeconds(1), NOW1.plusSeconds(2)))); } - @Test(expected = NullPointerException.class) + @Test public void test_overlaps_Interval_null() { Interval base = Interval.of(NOW1, NOW2); - base.overlaps((Interval) null); + assertThrows(NullPointerException.class, () -> base.overlaps((Interval) null)); } //----------------------------------------------------------------------- @@ -477,7 +476,7 @@ public static Object[][] data_intersection() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_intersection") public void test_intersection( Instant start1, Instant end1, Instant start2, Instant end2, Instant expStart, Instant expEnd) { @@ -489,7 +488,7 @@ public void test_intersection( assertEquals(expected, test1.intersection(test2)); } - @Test + @ParameterizedTest @UseDataProvider("data_intersection") public void test_intersection_reverse( Instant start1, Instant end1, Instant start2, Instant end2, Instant expStart, Instant expEnd) { @@ -501,12 +500,12 @@ public void test_intersection_reverse( assertEquals(expected, test2.intersection(test1)); } - @Test(expected = DateTimeException.class) + @Test public void test_intersectionBad() { Interval test1 = Interval.of(NOW1, NOW2); Interval test2 = Interval.of(NOW3, NOW4); assertEquals(false, test1.isConnected(test2)); - test1.intersection(test2); + assertThrows(DateTimeException.class, () -> test1.intersection(test2)); } @Test @@ -532,7 +531,7 @@ public static Object[][] data_union() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_union") public void test_unionAndSpan( Instant start1, Instant end1, Instant start2, Instant end2, Instant expStart, Instant expEnd) { @@ -545,7 +544,7 @@ public void test_unionAndSpan( assertEquals(expected, test1.span(test2)); } - @Test + @ParameterizedTest @UseDataProvider("data_union") public void test_unionAndSpan_reverse( Instant start1, Instant end1, Instant start2, Instant end2, Instant expStart, Instant expEnd) { @@ -558,7 +557,7 @@ public void test_unionAndSpan_reverse( assertEquals(expected, test2.span(test1)); } - @Test + @ParameterizedTest @UseDataProvider("data_union") public void test_span_enclosesInputs( Instant start1, Instant end1, Instant start2, Instant end2, Instant expStart, Instant expEnd) { @@ -570,12 +569,12 @@ public void test_span_enclosesInputs( assertEquals(true, expected.encloses(test2)); } - @Test(expected = DateTimeException.class) + @Test public void test_union_disconnected() { Interval test1 = Interval.of(NOW1, NOW2); Interval test2 = Interval.of(NOW3, NOW4); assertFalse(test1.isConnected(test2)); - test1.union(test2); + assertThrows(DateTimeException.class, () -> test1.union(test2)); } @Test diff --git a/src/test/java/org/threeten/extra/TestLocalDateRange.java b/src/test/java/org/threeten/extra/TestLocalDateRange.java index 6a5a1dee..ff9afa83 100644 --- a/src/test/java/org/threeten/extra/TestLocalDateRange.java +++ b/src/test/java/org/threeten/extra/TestLocalDateRange.java @@ -31,9 +31,10 @@ */ package org.threeten.extra; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -50,18 +51,16 @@ import java.util.List; import java.util.stream.Collectors; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; import com.google.common.collect.Range; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test date range. */ -@RunWith(DataProviderRunner.class) public class TestLocalDateRange { private static final LocalDate MINP1 = LocalDate.MIN.plusDays(1); @@ -144,19 +143,19 @@ public void test_of_MIN_MAX() { assertEquals("-999999999-01-01/+999999999-12-31", test.toString()); } - @Test(expected = DateTimeException.class) + @Test public void test_of_MIN_MIN() { - LocalDateRange.of(LocalDate.MIN, LocalDate.MIN); + assertThrows(DateTimeException.class, () -> LocalDateRange.of(LocalDate.MIN, LocalDate.MIN)); } - @Test(expected = DateTimeException.class) + @Test public void test_of_MIN_MINP1() { - LocalDateRange.of(LocalDate.MIN, MINP1); + assertThrows(DateTimeException.class, () -> LocalDateRange.of(LocalDate.MIN, MINP1)); } - @Test(expected = DateTimeException.class) + @Test public void test_of_MINP1_MINP1() { - LocalDateRange.of(MINP1, MINP1); + assertThrows(DateTimeException.class, () -> LocalDateRange.of(MINP1, MINP1)); } @Test @@ -198,19 +197,19 @@ public void test_of_MINP2_MINP2() { assertEquals("-999999999-01-03/-999999999-01-03", test.toString()); } - @Test(expected = DateTimeException.class) + @Test public void test_of_MAX_MAX() { - LocalDateRange.of(LocalDate.MAX, LocalDate.MAX); + assertThrows(DateTimeException.class, () -> LocalDateRange.of(LocalDate.MAX, LocalDate.MAX)); } - @Test(expected = DateTimeException.class) + @Test public void test_of_MAXM1_MAX() { - LocalDateRange.of(MAXM1, LocalDate.MAX); + assertThrows(DateTimeException.class, () -> LocalDateRange.of(MAXM1, LocalDate.MAX)); } - @Test(expected = DateTimeException.class) + @Test public void test_of_MAXM1_MAXM1() { - LocalDateRange.of(MAXM1, MAXM1); + assertThrows(DateTimeException.class, () -> LocalDateRange.of(MAXM1, MAXM1)); } @Test @@ -226,9 +225,9 @@ public void test_of_empty() { assertEquals("2012-07-30/2012-07-30", test.toString()); } - @Test(expected = DateTimeException.class) + @Test public void test_of_badOrder() { - LocalDateRange.of(DATE_2012_07_31, DATE_2012_07_30); + assertThrows(DateTimeException.class, () -> LocalDateRange.of(DATE_2012_07_31, DATE_2012_07_30)); } //----------------------------------------------------------------------- @@ -284,9 +283,9 @@ public void test_ofClosed_MIN_MAX() { assertEquals("-999999999-01-01/+999999999-12-31", test.toString()); } - @Test(expected = DateTimeException.class) + @Test public void test_ofClosed_MIN_MIN() { - LocalDateRange.ofClosed(LocalDate.MIN, LocalDate.MIN); + assertThrows(DateTimeException.class, () -> LocalDateRange.ofClosed(LocalDate.MIN, LocalDate.MIN)); } @Test @@ -354,24 +353,24 @@ public void test_ofClosed_MINP2_MINP2() { assertEquals("-999999999-01-03/-999999999-01-04", test.toString()); } - @Test(expected = DateTimeException.class) + @Test public void test_ofClosed_MAX_MAX() { - LocalDateRange.ofClosed(LocalDate.MAX, LocalDate.MAX); + assertThrows(DateTimeException.class, () -> LocalDateRange.ofClosed(LocalDate.MAX, LocalDate.MAX)); } - @Test(expected = DateTimeException.class) + @Test public void test_ofClosed_MAXM1_MAX() { - LocalDateRange.ofClosed(MAXM1, LocalDate.MAX); + assertThrows(DateTimeException.class, () -> LocalDateRange.ofClosed(MAXM1, LocalDate.MAX)); } - @Test(expected = DateTimeException.class) + @Test public void test_ofClosed_MAXM1_MAXM1() { - LocalDateRange.ofClosed(MAXM1, MAXM1); + assertThrows(DateTimeException.class, () -> LocalDateRange.ofClosed(MAXM1, MAXM1)); } - @Test(expected = DateTimeException.class) + @Test public void test_ofClosed_badOrder() { - LocalDateRange.ofClosed(DATE_2012_07_31, DATE_2012_07_30); + assertThrows(DateTimeException.class, () -> LocalDateRange.ofClosed(DATE_2012_07_31, DATE_2012_07_30)); } //----------------------------------------------------------------------- @@ -387,24 +386,24 @@ public void test_ofEmpty() { assertEquals("2012-07-30/2012-07-30", test.toString()); } - @Test(expected = DateTimeException.class) + @Test public void test_ofEmpty_MIN() { - LocalDateRange.ofEmpty(LocalDate.MIN); + assertThrows(DateTimeException.class, () -> LocalDateRange.ofEmpty(LocalDate.MIN)); } - @Test(expected = DateTimeException.class) + @Test public void test_ofEmpty_MINP1() { - LocalDateRange.ofEmpty(MINP1); + assertThrows(DateTimeException.class, () -> LocalDateRange.ofEmpty(MINP1)); } - @Test(expected = DateTimeException.class) + @Test public void test_ofEmpty_MAX() { - LocalDateRange.ofEmpty(LocalDate.MAX); + assertThrows(DateTimeException.class, () -> LocalDateRange.ofEmpty(LocalDate.MAX)); } - @Test(expected = DateTimeException.class) + @Test public void test_ofEmpty_MAXM1() { - LocalDateRange.ofEmpty(MAXM1); + assertThrows(DateTimeException.class, () -> LocalDateRange.ofEmpty(MAXM1)); } //----------------------------------------------------------------------- @@ -433,14 +432,14 @@ public void test_ofUnboundedStart() { assertEquals("-999999999-01-01/2012-07-30", test.toString()); } - @Test(expected = DateTimeException.class) + @Test public void test_ofUnboundedStart_MIN() { - LocalDateRange.ofUnboundedStart(LocalDate.MIN); + assertThrows(DateTimeException.class, () -> LocalDateRange.ofUnboundedStart(LocalDate.MIN)); } - @Test(expected = DateTimeException.class) + @Test public void test_ofUnboundedStart_MINP1() { - LocalDateRange.ofUnboundedStart(MINP1); + assertThrows(DateTimeException.class, () -> LocalDateRange.ofUnboundedStart(MINP1)); } //----------------------------------------------------------------------- @@ -456,14 +455,14 @@ public void test_ofUnboundedEnd() { assertEquals("2012-07-30/+999999999-12-31", test.toString()); } - @Test(expected = DateTimeException.class) + @Test public void test_ofUnboundedEnd_MAX() { - LocalDateRange.ofUnboundedEnd(LocalDate.MAX); + assertThrows(DateTimeException.class, () -> LocalDateRange.ofUnboundedEnd(LocalDate.MAX)); } - @Test(expected = DateTimeException.class) + @Test public void test_ofUnboundedEnd_MAXM1() { - LocalDateRange.ofUnboundedEnd(MAXM1); + assertThrows(DateTimeException.class, () -> LocalDateRange.ofUnboundedEnd(MAXM1)); } //----------------------------------------------------------------------- @@ -478,29 +477,29 @@ public void test_of_period() { assertEquals("2012-07-28/2012-07-31", test.toString()); } - @Test(expected = DateTimeException.class) + @Test public void test_of_period_negative() { - LocalDateRange.of(DATE_2012_07_31, Period.ofDays(-1)); + assertThrows(DateTimeException.class, () -> LocalDateRange.of(DATE_2012_07_31, Period.ofDays(-1))); } - @Test(expected = DateTimeException.class) + @Test public void test_of_period_atMIN() { - LocalDateRange.of(LocalDate.MIN, Period.ofDays(0)); + assertThrows(DateTimeException.class, () -> LocalDateRange.of(LocalDate.MIN, Period.ofDays(0))); } - @Test(expected = DateTimeException.class) + @Test public void test_of_period_atMAX() { - LocalDateRange.of(LocalDate.MAX, Period.ofDays(0)); + assertThrows(DateTimeException.class, () -> LocalDateRange.of(LocalDate.MAX, Period.ofDays(0))); } - @Test(expected = DateTimeException.class) + @Test public void test_of_period_atMAXM1_0D() { - LocalDateRange.of(MAXM1, Period.ofDays(0)); + assertThrows(DateTimeException.class, () -> LocalDateRange.of(MAXM1, Period.ofDays(0))); } - @Test(expected = DateTimeException.class) + @Test public void test_of_period_atMAXM1_1D() { - LocalDateRange.of(MAXM1, Period.ofDays(1)); + assertThrows(DateTimeException.class, () -> LocalDateRange.of(MAXM1, Period.ofDays(1))); } //----------------------------------------------------------------------- @@ -546,19 +545,19 @@ public void test_parse_CharSequence_empty() { assertEquals(DATE_2012_07_27, test.getEnd()); } - @Test(expected = DateTimeException.class) + @Test public void test_parse_CharSequence_badOrder() { - LocalDateRange.parse(DATE_2012_07_29 + "/" + DATE_2012_07_27); + assertThrows(DateTimeException.class, () -> LocalDateRange.parse(DATE_2012_07_29 + "/" + DATE_2012_07_27)); } - @Test(expected = DateTimeParseException.class) + @Test public void test_parse_CharSequence_badFormat() { - LocalDateRange.parse(DATE_2012_07_29 + "-" + DATE_2012_07_27); + assertThrows(DateTimeParseException.class, () -> LocalDateRange.parse(DATE_2012_07_29 + "-" + DATE_2012_07_27)); } - @Test(expected = NullPointerException.class) + @Test public void test_parse_CharSequence_null() { - LocalDateRange.parse(null); + assertThrows(NullPointerException.class, () -> LocalDateRange.parse(null)); } //----------------------------------------------------------------------- @@ -616,10 +615,10 @@ public void test_withStart_empty() { assertEquals(DATE_2012_07_31, test.getEnd()); } - @Test(expected = DateTimeException.class) + @Test public void test_withStart_invalid() { LocalDateRange base = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_30); - base.withStart(DATE_2012_07_31); + assertThrows(DateTimeException.class, () -> base.withStart(DATE_2012_07_31)); } //----------------------------------------------------------------------- @@ -659,10 +658,10 @@ public void test_withEnd_empty() { assertEquals(DATE_2012_07_30, test.getEnd()); } - @Test(expected = DateTimeException.class) + @Test public void test_withEnd_invalid() { LocalDateRange base = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); - base.withEnd(DATE_2012_07_27); + assertThrows(DateTimeException.class, () -> base.withEnd(DATE_2012_07_27)); } //----------------------------------------------------------------------- @@ -752,7 +751,7 @@ public static Object[][] data_queries() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_queries") public void test_encloses( LocalDate start, LocalDate end, boolean isEnclosedBy, boolean abuts, boolean isConnected, boolean overlaps) { @@ -760,7 +759,7 @@ public void test_encloses( assertEquals(isEnclosedBy, test.encloses(LocalDateRange.of(start, end))); } - @Test + @ParameterizedTest @UseDataProvider("data_queries") public void test_abuts( LocalDate start, LocalDate end, boolean isEnclosedBy, boolean abuts, boolean isConnected, boolean overlaps) { @@ -768,7 +767,7 @@ public void test_abuts( assertEquals(abuts, test.abuts(LocalDateRange.of(start, end))); } - @Test + @ParameterizedTest @UseDataProvider("data_queries") public void test_isConnected( LocalDate start, LocalDate end, boolean isEnclosedBy, boolean abuts, boolean isConnected, boolean overlaps) { @@ -776,7 +775,7 @@ public void test_isConnected( assertEquals(isConnected, test.isConnected(LocalDateRange.of(start, end))); } - @Test + @ParameterizedTest @UseDataProvider("data_queries") public void test_overlaps( LocalDate start, LocalDate end, boolean isEnclosedBy, boolean abuts, boolean isConnected, boolean overlaps) { @@ -784,7 +783,7 @@ public void test_overlaps( assertEquals(overlaps, test.overlaps(LocalDateRange.of(start, end))); } - @Test + @ParameterizedTest @UseDataProvider("data_queries") public void test_crossCheck( LocalDate start, LocalDate end, boolean isEnclosedBy, boolean abuts, boolean isConnected, boolean overlaps) { @@ -861,7 +860,7 @@ public static Object[][] data_intersection() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_intersection") public void test_intersection( LocalDate start1, LocalDate end1, LocalDate start2, LocalDate end2, LocalDate expStart, LocalDate expEnd) { @@ -873,7 +872,7 @@ public void test_intersection( assertEquals(expected, test1.intersection(test2)); } - @Test + @ParameterizedTest @UseDataProvider("data_intersection") public void test_intersection_reverse( LocalDate start1, LocalDate end1, LocalDate start2, LocalDate end2, LocalDate expStart, LocalDate expEnd) { @@ -885,12 +884,12 @@ public void test_intersection_reverse( assertEquals(expected, test2.intersection(test1)); } - @Test(expected = DateTimeException.class) + @Test public void test_intersectionBad() { LocalDateRange test1 = LocalDateRange.of(DATE_2012_07_01, DATE_2012_07_28); LocalDateRange test2 = LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_30); assertEquals(false, test1.isConnected(test2)); - test1.intersection(test2); + assertThrows(DateTimeException.class, () -> test1.intersection(test2)); } @Test @@ -916,7 +915,7 @@ public static Object[][] data_union() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_union") public void test_unionAndSpan( LocalDate start1, LocalDate end1, LocalDate start2, LocalDate end2, LocalDate expStart, LocalDate expEnd) { @@ -929,7 +928,7 @@ public void test_unionAndSpan( assertEquals(expected, test1.span(test2)); } - @Test + @ParameterizedTest @UseDataProvider("data_union") public void test_unionAndSpan_reverse( LocalDate start1, LocalDate end1, LocalDate start2, LocalDate end2, LocalDate expStart, LocalDate expEnd) { @@ -942,7 +941,7 @@ public void test_unionAndSpan_reverse( assertEquals(expected, test2.span(test1)); } - @Test + @ParameterizedTest @UseDataProvider("data_union") public void test_span_enclosesInputs( LocalDate start1, LocalDate end1, LocalDate start2, LocalDate end2, LocalDate expStart, LocalDate expEnd) { @@ -954,12 +953,12 @@ public void test_span_enclosesInputs( assertEquals(true, expected.encloses(test2)); } - @Test(expected = DateTimeException.class) + @Test public void test_union_disconnected() { LocalDateRange test1 = LocalDateRange.of(DATE_2012_07_01, DATE_2012_07_28); LocalDateRange test2 = LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_30); assertFalse(test1.isConnected(test2)); - test1.union(test2); + assertThrows(DateTimeException.class, () -> test1.union(test2)); } @Test @@ -1052,14 +1051,14 @@ public static Object[][] data_isBefore() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_isBefore") public void test_isBefore_range(LocalDate start, LocalDate end, boolean before) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); assertEquals(before, test.isBefore(LocalDateRange.of(start, end))); } - @Test + @ParameterizedTest @UseDataProvider("data_isBefore") public void test_isBefore_date(LocalDate start, LocalDate end, boolean before) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); @@ -1132,14 +1131,14 @@ public static Object[][] data_isAfter() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_isAfter") public void test_isAfter_range(LocalDate start, LocalDate end, boolean before) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); assertEquals(before, test.isAfter(LocalDateRange.of(start, end))); } - @Test + @ParameterizedTest @UseDataProvider("data_isAfter") public void test_isAfter_date(LocalDate start, LocalDate end, boolean before) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); @@ -1184,14 +1183,14 @@ public void test_toPeriod() { assertEquals(Period.ofDays(0), LocalDateRange.of(DATE_2012_07_29, DATE_2012_07_29).toPeriod()); } - @Test(expected = ArithmeticException.class) + @Test public void test_toPeriod_unbounded_MIN() { - LocalDateRange.of(LocalDate.MIN, DATE_2012_07_29).toPeriod(); + assertThrows(ArithmeticException.class, () -> LocalDateRange.of(LocalDate.MIN, DATE_2012_07_29).toPeriod()); } - @Test(expected = ArithmeticException.class) + @Test public void test_toPeriod_unbounded_MAX() { - LocalDateRange.of(DATE_2012_07_29, LocalDate.MAX).toPeriod(); + assertThrows(ArithmeticException.class, () -> LocalDateRange.of(DATE_2012_07_29, LocalDate.MAX).toPeriod()); } //----------------------------------------------------------------------- @@ -1234,7 +1233,7 @@ public static List> data_crossCheckGuava() { return list; } - @Test + @ParameterizedTest @UseDataProvider("data_crossCheckGuava") public void crossCheckGuava_encloses( LocalDateRange extraRange1, @@ -1247,7 +1246,7 @@ public void crossCheckGuava_encloses( assertEquals(guava, extra); } - @Test + @ParameterizedTest @UseDataProvider("data_crossCheckGuava") public void crossCheckGuava_isConnected( LocalDateRange extraRange1, @@ -1260,7 +1259,7 @@ public void crossCheckGuava_isConnected( assertEquals(guava, extra); } - @Test + @ParameterizedTest @UseDataProvider("data_crossCheckGuava") public void crossCheckGuava_intersection( LocalDateRange extraRange1, @@ -1288,7 +1287,7 @@ public void crossCheckGuava_intersection( } } - @Test + @ParameterizedTest @UseDataProvider("data_crossCheckGuava") public void crossCheckGuava_span( LocalDateRange extraRange1, diff --git a/src/test/java/org/threeten/extra/TestMinutes.java b/src/test/java/org/threeten/extra/TestMinutes.java index b126cd2f..79468f8f 100644 --- a/src/test/java/org/threeten/extra/TestMinutes.java +++ b/src/test/java/org/threeten/extra/TestMinutes.java @@ -31,10 +31,11 @@ */ package org.threeten.extra; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -45,19 +46,17 @@ import java.time.LocalTime; import java.time.format.DateTimeParseException; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test class. */ -@RunWith(DataProviderRunner.class) public class TestMinutes { - + //----------------------------------------------------------------------- @Test public void test_isSerializable() { @@ -76,7 +75,7 @@ public void test_deserializationSingleton() throws Exception { assertSame(test, ois.readObject()); } } - + //----------------------------------------------------------------------- @Test public void test_ZERO() { @@ -87,7 +86,7 @@ public void test_ZERO() { assertTrue(Minutes.ZERO.isZero()); assertFalse(Minutes.ZERO.isPositive()); } - + //----------------------------------------------------------------------- @Test public void test_of() { @@ -127,12 +126,12 @@ public void test_ofHours() { assertEquals(-120, Minutes.ofHours(-2).getAmount()); assertEquals((Integer.MIN_VALUE / 60) * 60, Minutes.ofHours(Integer.MIN_VALUE / 60).getAmount()); } - - @Test(expected = ArithmeticException.class) + + @Test public void test_ofHours_overflow() { - Minutes.ofHours((Integer.MAX_VALUE / 60) + 60); + assertThrows(ArithmeticException.class, () -> Minutes.ofHours((Integer.MAX_VALUE / 60) + 60)); } - + //----------------------------------------------------------------------- @DataProvider public static Object[][] data_valid() { @@ -177,19 +176,19 @@ public static Object[][] data_valid() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_valid") public void test_parse_CharSequence_valid(String str, int expectedMinutes) { assertEquals(Minutes.of(expectedMinutes), Minutes.parse(str)); } - @Test + @ParameterizedTest @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, int expectedMinutes) { assertEquals(Minutes.of(expectedMinutes), Minutes.parse("+" + str)); } - @Test + @ParameterizedTest @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, int expectedMinutes) { assertEquals(Minutes.of(-expectedMinutes), Minutes.parse("-" + str)); @@ -217,17 +216,17 @@ public static Object[][] data_invalid() { }; } - @Test(expected = DateTimeParseException.class) + @ParameterizedTest @UseDataProvider("data_invalid") public void test_parse_CharSequence_invalid(String str) { - Minutes.parse(str); + assertThrows(DateTimeParseException.class, () -> Minutes.parse(str)); } - @Test(expected = NullPointerException.class) + @Test public void test_parse_CharSequence_null() { - Minutes.parse((CharSequence) null); + assertThrows(NullPointerException.class, () -> Minutes.parse((CharSequence) null)); } - + //----------------------------------------------------------------------- @Test public void test_plus_TemporalAmount_Minutes() { @@ -238,22 +237,22 @@ public void test_plus_TemporalAmount_Minutes() { assertEquals(Minutes.of(Integer.MAX_VALUE), Minutes.of(Integer.MAX_VALUE - 1).plus(Minutes.of(1))); assertEquals(Minutes.of(Integer.MIN_VALUE), Minutes.of(Integer.MIN_VALUE + 1).plus(Minutes.of(-1))); } - - @Test(expected = ArithmeticException.class) + + @Test public void test_plus_TemporalAmount_overflowTooBig() { - Minutes.of(Integer.MAX_VALUE - 1).plus(Minutes.of(2)); + assertThrows(ArithmeticException.class, () -> Minutes.of(Integer.MAX_VALUE - 1).plus(Minutes.of(2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_TemporalAmount_overflowTooSmall() { - Minutes.of(Integer.MIN_VALUE + 1).plus(Minutes.of(-2)); + assertThrows(ArithmeticException.class, () -> Minutes.of(Integer.MIN_VALUE + 1).plus(Minutes.of(-2))); } - @Test(expected = NullPointerException.class) + @Test public void test_plus_TemporalAmount_null() { - Minutes.of(Integer.MIN_VALUE + 1).plus(null); + assertThrows(NullPointerException.class, () -> Minutes.of(Integer.MIN_VALUE + 1).plus(null)); } - + //----------------------------------------------------------------------- @Test public void test_plus_int() { @@ -265,16 +264,16 @@ public void test_plus_int() { assertEquals(Minutes.of(Integer.MIN_VALUE), Minutes.of(Integer.MIN_VALUE + 1).plus(-1)); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_int_overflowTooBig() { - Minutes.of(Integer.MAX_VALUE - 1).plus(2); + assertThrows(ArithmeticException.class, () -> Minutes.of(Integer.MAX_VALUE - 1).plus(2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_int_overflowTooSmall() { - Minutes.of(Integer.MIN_VALUE + 1).plus(-2); + assertThrows(ArithmeticException.class, () -> Minutes.of(Integer.MIN_VALUE + 1).plus(-2)); } - + //----------------------------------------------------------------------- @Test public void test_minus_TemporalAmount_Minutes() { @@ -286,21 +285,21 @@ public void test_minus_TemporalAmount_Minutes() { assertEquals(Minutes.of(Integer.MIN_VALUE), Minutes.of(Integer.MIN_VALUE + 1).minus(Minutes.of(1))); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_TemporalAmount_overflowTooBig() { - Minutes.of(Integer.MAX_VALUE - 1).minus(Minutes.of(-2)); + assertThrows(ArithmeticException.class, () -> Minutes.of(Integer.MAX_VALUE - 1).minus(Minutes.of(-2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_TemporalAmount_overflowTooSmall() { - Minutes.of(Integer.MIN_VALUE + 1).minus(Minutes.of(2)); + assertThrows(ArithmeticException.class, () -> Minutes.of(Integer.MIN_VALUE + 1).minus(Minutes.of(2))); } - @Test(expected = NullPointerException.class) + @Test public void test_minus_TemporalAmount_null() { - Minutes.of(Integer.MIN_VALUE + 1).minus(null); + assertThrows(NullPointerException.class, () -> Minutes.of(Integer.MIN_VALUE + 1).minus(null)); } - + //----------------------------------------------------------------------- @Test public void test_minus_int() { @@ -312,16 +311,16 @@ public void test_minus_int() { assertEquals(Minutes.of(Integer.MIN_VALUE), Minutes.of(Integer.MIN_VALUE + 1).minus(1)); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_int_overflowTooBig() { - Minutes.of(Integer.MAX_VALUE - 1).minus(-2); + assertThrows(ArithmeticException.class, () -> Minutes.of(Integer.MAX_VALUE - 1).minus(-2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_int_overflowTooSmall() { - Minutes.of(Integer.MIN_VALUE + 1).minus(2); + assertThrows(ArithmeticException.class, () -> Minutes.of(Integer.MIN_VALUE + 1).minus(2)); } - + //----------------------------------------------------------------------- @Test public void test_multipliedBy() { @@ -339,16 +338,16 @@ public void test_multipliedBy_negate() { assertEquals(Minutes.of(-15), test5.multipliedBy(-3)); } - @Test(expected = ArithmeticException.class) + @Test public void test_multipliedBy_overflowTooBig() { - Minutes.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2); + assertThrows(ArithmeticException.class, () -> Minutes.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_multipliedBy_overflowTooSmall() { - Minutes.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2); + assertThrows(ArithmeticException.class, () -> Minutes.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2)); } - + //----------------------------------------------------------------------- @Test public void test_dividedBy() { @@ -368,11 +367,11 @@ public void test_dividedBy_negate() { assertEquals(Minutes.of(-4), test12.dividedBy(-3)); } - @Test(expected = ArithmeticException.class) + @Test public void test_dividedBy_divideByZero() { - Minutes.of(1).dividedBy(0); + assertThrows(ArithmeticException.class, () -> Minutes.of(1).dividedBy(0)); } - + //----------------------------------------------------------------------- @Test public void test_negated() { @@ -382,11 +381,11 @@ public void test_negated() { assertEquals(Minutes.of(-Integer.MAX_VALUE), Minutes.of(Integer.MAX_VALUE).negated()); } - @Test(expected = ArithmeticException.class) + @Test public void test_negated_overflow() { - Minutes.of(Integer.MIN_VALUE).negated(); + assertThrows(ArithmeticException.class, () -> Minutes.of(Integer.MIN_VALUE).negated()); } - + //----------------------------------------------------------------------- @Test public void test_abs() { @@ -397,11 +396,11 @@ public void test_abs() { assertEquals(Minutes.of(Integer.MAX_VALUE), Minutes.of(-Integer.MAX_VALUE).abs()); } - @Test(expected = ArithmeticException.class) + @Test public void test_abs_overflow() { - Minutes.of(Integer.MIN_VALUE).abs(); + assertThrows(ArithmeticException.class, () -> Minutes.of(Integer.MIN_VALUE).abs()); } - + //----------------------------------------------------------------------- @Test public void test_addTo() { @@ -425,7 +424,7 @@ public void test_toDuration() { assertEquals(Duration.ofMinutes(i), Minutes.of(i).toDuration()); } } - + //----------------------------------------------------------------------- @Test public void test_compareTo() { @@ -436,10 +435,10 @@ public void test_compareTo() { assertEquals(1, test6.compareTo(test5)); } - @Test(expected = NullPointerException.class) + @Test public void test_compareTo_null() { Minutes test5 = Minutes.of(5); - test5.compareTo(null); + assertThrows(NullPointerException.class, () -> test5.compareTo(null)); } //----------------------------------------------------------------------- @@ -481,5 +480,5 @@ public void test_toString() { Minutes testM1 = Minutes.of(-1); assertEquals("PT-1M", testM1.toString()); } - + } diff --git a/src/test/java/org/threeten/extra/TestMonths.java b/src/test/java/org/threeten/extra/TestMonths.java index 760faf56..de5a6862 100644 --- a/src/test/java/org/threeten/extra/TestMonths.java +++ b/src/test/java/org/threeten/extra/TestMonths.java @@ -31,10 +31,11 @@ */ package org.threeten.extra; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -51,17 +52,17 @@ import java.time.temporal.Temporal; import java.time.temporal.TemporalAmount; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; /** * Test class. */ -@RunWith(DataProviderRunner.class) public class TestMonths { //----------------------------------------------------------------------- @@ -136,9 +137,9 @@ public void test_ofYears() { assertEquals((Integer.MIN_VALUE / 12) * 12, Months.ofYears(Integer.MIN_VALUE / 12).getAmount()); } - @Test(expected = ArithmeticException.class) + @Test public void test_ofYears_overflow() { - Months.ofYears((Integer.MAX_VALUE / 12) + 12); + assertThrows(ArithmeticException.class, () -> Months.ofYears((Integer.MAX_VALUE / 12) + 12)); } //----------------------------------------------------------------------- @@ -167,14 +168,14 @@ public void test_from_yearsAndMonths() { assertEquals(Months.of(41), Months.from(Period.of(3, 5, 0))); } - @Test(expected = DateTimeException.class) + @Test public void test_from_wrongUnit_noConversion() { - Months.from(Period.ofDays(2)); + assertThrows(DateTimeException.class, () -> Months.from(Period.ofDays(2))); } - @Test(expected = NullPointerException.class) + @Test public void test_from_null() { - Months.from((TemporalAmount) null); + assertThrows(NullPointerException.class, () -> Months.from((TemporalAmount) null)); } //----------------------------------------------------------------------- @@ -209,19 +210,19 @@ public static Object[][] data_valid() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_valid") public void test_parse_CharSequence_valid(String str, int expectedDays) { assertEquals(Months.of(expectedDays), Months.parse(str)); } - @Test + @ParameterizedTest @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, int expectedDays) { assertEquals(Months.of(expectedDays), Months.parse("+" + str)); } - @Test + @ParameterizedTest @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, int expectedDays) { assertEquals(Months.of(-expectedDays), Months.parse("-" + str)); @@ -245,15 +246,15 @@ public static Object[][] data_invalid() { }; } - @Test(expected = DateTimeParseException.class) + @ParameterizedTest @UseDataProvider("data_invalid") public void test_parse_CharSequence_invalid(String str) { - Months.parse(str); + assertThrows(DateTimeParseException.class, () -> Months.parse(str)); } - @Test(expected = NullPointerException.class) + @Test public void test_parse_CharSequence_null() { - Months.parse((CharSequence) null); + assertThrows(NullPointerException.class, () -> Months.parse((CharSequence) null)); } //----------------------------------------------------------------------- @@ -262,14 +263,14 @@ public void test_between() { assertEquals(Months.of(24), Months.between(LocalDate.of(2019, 1, 1), LocalDate.of(2021, 1, 1))); } - @Test(expected = NullPointerException.class) + @Test public void test_between_date_null() { - Months.between(LocalDate.now(), (Temporal) null); + assertThrows(NullPointerException.class, () -> Months.between(LocalDate.now(), (Temporal) null)); } - @Test(expected = NullPointerException.class) + @Test public void test_between_null_date() { - Months.between((Temporal) null, LocalDate.now()); + assertThrows(NullPointerException.class, () -> Months.between((Temporal) null, LocalDate.now())); } //----------------------------------------------------------------------- @@ -278,9 +279,9 @@ public void test_get() { assertEquals(6, Months.of(6).get(ChronoUnit.MONTHS)); } - @Test(expected = DateTimeException.class) + @Test public void test_get_invalidType() { - Months.of(6).get(IsoFields.QUARTER_YEARS); + assertThrows(DateTimeException.class, () -> Months.of(6).get(IsoFields.QUARTER_YEARS)); } //----------------------------------------------------------------------- @@ -304,29 +305,29 @@ public void test_plus_TemporalAmount_Period() { assertEquals(Months.of(Integer.MIN_VALUE), Months.of(Integer.MIN_VALUE + 1).plus(Period.ofMonths(-1))); } - @Test(expected = DateTimeException.class) + @Test public void test_plus_TemporalAmount_PeriodDays() { - Months.of(1).plus(Period.ofDays(2)); + assertThrows(DateTimeException.class, () -> Months.of(1).plus(Period.ofDays(2))); } - @Test(expected = DateTimeException.class) + @Test public void test_plus_TemporalAmount_Duration() { - Months.of(1).plus(Duration.ofHours(2)); + assertThrows(DateTimeException.class, () -> Months.of(1).plus(Duration.ofHours(2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_TemporalAmount_overflowTooBig() { - Months.of(Integer.MAX_VALUE - 1).plus(Months.of(2)); + assertThrows(ArithmeticException.class, () -> Months.of(Integer.MAX_VALUE - 1).plus(Months.of(2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_TemporalAmount_overflowTooSmall() { - Months.of(Integer.MIN_VALUE + 1).plus(Months.of(-2)); + assertThrows(ArithmeticException.class, () -> Months.of(Integer.MIN_VALUE + 1).plus(Months.of(-2))); } - @Test(expected = NullPointerException.class) + @Test public void test_plus_TemporalAmount_null() { - Months.of(Integer.MIN_VALUE + 1).plus(null); + assertThrows(NullPointerException.class, () -> Months.of(Integer.MIN_VALUE + 1).plus(null)); } //----------------------------------------------------------------------- @@ -340,14 +341,14 @@ public void test_plus_int() { assertEquals(Months.of(Integer.MIN_VALUE), Months.of(Integer.MIN_VALUE + 1).plus(-1)); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_int_overflowTooBig() { - Months.of(Integer.MAX_VALUE - 1).plus(2); + assertThrows(ArithmeticException.class, () -> Months.of(Integer.MAX_VALUE - 1).plus(2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_int_overflowTooSmall() { - Months.of(Integer.MIN_VALUE + 1).plus(-2); + assertThrows(ArithmeticException.class, () -> Months.of(Integer.MIN_VALUE + 1).plus(-2)); } //----------------------------------------------------------------------- @@ -371,29 +372,29 @@ public void test_minus_TemporalAmount_Period() { assertEquals(Months.of(Integer.MIN_VALUE), Months.of(Integer.MIN_VALUE + 1).minus(Period.ofMonths(1))); } - @Test(expected = DateTimeException.class) + @Test public void test_minus_TemporalAmount_PeriodDays() { - Months.of(1).minus(Period.ofDays(2)); + assertThrows(DateTimeException.class, () -> Months.of(1).minus(Period.ofDays(2))); } - @Test(expected = DateTimeException.class) + @Test public void test_minus_TemporalAmount_Duration() { - Months.of(1).minus(Duration.ofHours(2)); + assertThrows(DateTimeException.class, () -> Months.of(1).minus(Duration.ofHours(2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_TemporalAmount_overflowTooBig() { - Months.of(Integer.MAX_VALUE - 1).minus(Months.of(-2)); + assertThrows(ArithmeticException.class, () -> Months.of(Integer.MAX_VALUE - 1).minus(Months.of(-2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_TemporalAmount_overflowTooSmall() { - Months.of(Integer.MIN_VALUE + 1).minus(Months.of(2)); + assertThrows(ArithmeticException.class, () -> Months.of(Integer.MIN_VALUE + 1).minus(Months.of(2))); } - @Test(expected = NullPointerException.class) + @Test public void test_minus_TemporalAmount_null() { - Months.of(Integer.MIN_VALUE + 1).minus(null); + assertThrows(NullPointerException.class, () -> Months.of(Integer.MIN_VALUE + 1).minus(null)); } //----------------------------------------------------------------------- @@ -407,14 +408,14 @@ public void test_minus_int() { assertEquals(Months.of(Integer.MIN_VALUE), Months.of(Integer.MIN_VALUE + 1).minus(1)); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_int_overflowTooBig() { - Months.of(Integer.MAX_VALUE - 1).minus(-2); + assertThrows(ArithmeticException.class, () -> Months.of(Integer.MAX_VALUE - 1).minus(-2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_int_overflowTooSmall() { - Months.of(Integer.MIN_VALUE + 1).minus(2); + assertThrows(ArithmeticException.class, () -> Months.of(Integer.MIN_VALUE + 1).minus(2)); } //----------------------------------------------------------------------- @@ -434,14 +435,14 @@ public void test_multipliedBy_negate() { assertEquals(Months.of(-15), test5.multipliedBy(-3)); } - @Test(expected = ArithmeticException.class) + @Test public void test_multipliedBy_overflowTooBig() { - Months.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2); + assertThrows(ArithmeticException.class, () -> Months.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_multipliedBy_overflowTooSmall() { - Months.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2); + assertThrows(ArithmeticException.class, () -> Months.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2)); } //----------------------------------------------------------------------- @@ -463,9 +464,9 @@ public void test_dividedBy_negate() { assertEquals(Months.of(-4), test12.dividedBy(-3)); } - @Test(expected = ArithmeticException.class) + @Test public void test_dividedBy_divideByZero() { - Months.of(1).dividedBy(0); + assertThrows(ArithmeticException.class, () -> Months.of(1).dividedBy(0)); } //----------------------------------------------------------------------- @@ -477,9 +478,9 @@ public void test_negated() { assertEquals(Months.of(-Integer.MAX_VALUE), Months.of(Integer.MAX_VALUE).negated()); } - @Test(expected = ArithmeticException.class) + @Test public void test_negated_overflow() { - Months.of(Integer.MIN_VALUE).negated(); + assertThrows(ArithmeticException.class, () -> Months.of(Integer.MIN_VALUE).negated()); } //----------------------------------------------------------------------- @@ -492,9 +493,9 @@ public void test_abs() { assertEquals(Months.of(Integer.MAX_VALUE), Months.of(-Integer.MAX_VALUE).abs()); } - @Test(expected = ArithmeticException.class) + @Test public void test_abs_overflow() { - Months.of(Integer.MIN_VALUE).abs(); + assertThrows(ArithmeticException.class, () -> Months.of(Integer.MIN_VALUE).abs()); } //----------------------------------------------------------------------- @@ -528,10 +529,10 @@ public void test_compareTo() { assertEquals(1, test6.compareTo(test5)); } - @Test(expected = NullPointerException.class) + @Test public void test_compareTo_null() { Months test5 = Months.of(5); - test5.compareTo(null); + assertThrows(NullPointerException.class, () -> test5.compareTo(null)); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestMutableClock.java b/src/test/java/org/threeten/extra/TestMutableClock.java index 81b718ab..ed20ca92 100644 --- a/src/test/java/org/threeten/extra/TestMutableClock.java +++ b/src/test/java/org/threeten/extra/TestMutableClock.java @@ -31,9 +31,10 @@ */ package org.threeten.extra; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -60,7 +61,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test class. @@ -89,14 +90,14 @@ public void test_of() { MutableClock.of(Instant.EPOCH, ZoneOffset.MAX).getZone()); } - @Test(expected = NullPointerException.class) + @Test public void test_of_nullInstant() { - MutableClock.of(null, ZoneOffset.UTC); + assertThrows(NullPointerException.class, () -> MutableClock.of(null, ZoneOffset.UTC)); } - @Test(expected = NullPointerException.class) + @Test public void test_of_nullZone() { - MutableClock.of(Instant.EPOCH, null); + assertThrows(NullPointerException.class, () -> MutableClock.of(Instant.EPOCH, null)); } @Test @@ -117,9 +118,9 @@ public void test_setInstant() { assertEquals(Instant.EPOCH.plusSeconds(10), clock.instant()); } - @Test(expected = NullPointerException.class) + @Test public void test_setInstant_null() { - MutableClock.epochUTC().setInstant(null); + assertThrows(NullPointerException.class, () -> MutableClock.epochUTC().setInstant(null)); } @Test @@ -141,9 +142,9 @@ public void test_add_amountOnly() { clock.instant()); } - @Test(expected = NullPointerException.class) + @Test public void test_add_amountOnly_null() { - MutableClock.epochUTC().add(null); + assertThrows(NullPointerException.class, () -> MutableClock.epochUTC().add(null)); } @Test @@ -165,9 +166,9 @@ public void test_add_amountAndUnit() { clock.instant()); } - @Test(expected = NullPointerException.class) + @Test public void test_add_amountAndUnit_nullUnit() { - MutableClock.epochUTC().add(0, null); + assertThrows(NullPointerException.class, () -> MutableClock.epochUTC().add(0, null)); } @Test @@ -188,9 +189,9 @@ public void test_set_adjuster() { assertEquals(Instant.EPOCH, clock.instant()); } - @Test(expected = NullPointerException.class) + @Test public void test_set_adjuster_null() { - MutableClock.epochUTC().set(null); + assertThrows(NullPointerException.class, () -> MutableClock.epochUTC().set(null)); } @Test @@ -209,9 +210,9 @@ public void test_set_fieldAndValue() { clock.instant()); } - @Test(expected = NullPointerException.class) + @Test public void test_set_fieldAndValue_nullField() { - MutableClock.epochUTC().set(null, 0); + assertThrows(NullPointerException.class, () -> MutableClock.epochUTC().set(null, 0)); } @Test @@ -238,9 +239,9 @@ public void test_withZone() { assertEquals(clock, withSameZone); } - @Test(expected = NullPointerException.class) + @Test public void test_withZone_null() { - MutableClock.epochUTC().withZone(null); + assertThrows(NullPointerException.class, () -> MutableClock.epochUTC().withZone(null)); } @Test diff --git a/src/test/java/org/threeten/extra/TestOffsetDate.java b/src/test/java/org/threeten/extra/TestOffsetDate.java index 8fa14676..16dc0b2f 100644 --- a/src/test/java/org/threeten/extra/TestOffsetDate.java +++ b/src/test/java/org/threeten/extra/TestOffsetDate.java @@ -46,11 +46,12 @@ import static java.time.temporal.ChronoField.PROLEPTIC_MONTH; import static java.time.temporal.ChronoField.YEAR; import static java.time.temporal.ChronoField.YEAR_OF_ERA; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; @@ -84,25 +85,23 @@ import java.util.Arrays; import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test OffsetDate. */ -@RunWith(DataProviderRunner.class) public class TestOffsetDate extends AbstractDateTimeTest { private static final ZoneOffset OFFSET_PONE = ZoneOffset.ofHours(1); private static final ZoneOffset OFFSET_PTWO = ZoneOffset.ofHours(2); private OffsetDate TEST_2007_07_15_PONE; - @Before + @BeforeEach public void setUp() { TEST_2007_07_15_PONE = OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PONE); } @@ -206,14 +205,14 @@ public void now_Clock_offsets() { } } - @Test(expected=NullPointerException.class) + @Test public void now_Clock_nullZoneId() { - OffsetDate.now((ZoneId) null); + assertThrows(NullPointerException.class, () -> OffsetDate.now((ZoneId) null)); } - @Test(expected=NullPointerException.class) + @Test public void now_Clock_nullClock() { - OffsetDate.now((Clock) null); + assertThrows(NullPointerException.class, () -> OffsetDate.now((Clock) null)); } //----------------------------------------------------------------------- @@ -252,29 +251,29 @@ public void factory_of_intsMonthOffset() { assertEquals(OffsetDate.of(LocalDate.of(2007, Month.JULY, 15), OFFSET_PONE), TEST_2007_07_15_PONE); } - @Test(expected=DateTimeException.class) + @Test public void factory_of_intsMonthOffset_dayTooLow() { - OffsetDate.of(LocalDate.of(2007, Month.JANUARY, 0), OFFSET_PONE); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(2007, Month.JANUARY, 0), OFFSET_PONE)); } - @Test(expected=DateTimeException.class) + @Test public void factory_of_intsMonthOffset_dayTooHigh() { - OffsetDate.of(LocalDate.of(2007, Month.JANUARY, 32), OFFSET_PONE); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(2007, Month.JANUARY, 32), OFFSET_PONE)); } - @Test(expected=NullPointerException.class) + @Test public void factory_of_intsMonthOffset_nullMonth() { - OffsetDate.of(LocalDate.of(2007, null, 30), OFFSET_PONE); + assertThrows(NullPointerException.class, () -> OffsetDate.of(LocalDate.of(2007, null, 30), OFFSET_PONE)); } - @Test(expected=DateTimeException.class) + @Test public void factory_of_intsMonthOffset_yearTooLow() { - OffsetDate.of(LocalDate.of(Integer.MIN_VALUE, Month.JANUARY, 1), OFFSET_PONE); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Integer.MIN_VALUE, Month.JANUARY, 1), OFFSET_PONE)); } - @Test(expected=NullPointerException.class) + @Test public void factory_of_intsMonthOffset_nullOffset() { - OffsetDate.of(LocalDate.of(2007, Month.JANUARY, 30), null); + assertThrows(NullPointerException.class, () -> OffsetDate.of(LocalDate.of(2007, Month.JANUARY, 30), null)); } //----------------------------------------------------------------------- @@ -284,34 +283,34 @@ public void factory_of_intsOffset() { check(test, 2007, 7, 15, OFFSET_PONE); } - @Test(expected=DateTimeException.class) + @Test public void factory_of_ints_dayTooLow() { - OffsetDate.of(LocalDate.of(2007, 1, 0), OFFSET_PONE); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(2007, 1, 0), OFFSET_PONE)); } - @Test(expected=DateTimeException.class) + @Test public void factory_of_ints_dayTooHigh() { - OffsetDate.of(LocalDate.of(2007, 1, 32), OFFSET_PONE); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(2007, 1, 32), OFFSET_PONE)); } - @Test(expected=DateTimeException.class) + @Test public void factory_of_ints_monthTooLow() { - OffsetDate.of(LocalDate.of(2007, 0, 1), OFFSET_PONE); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(2007, 0, 1), OFFSET_PONE)); } - @Test(expected=DateTimeException.class) + @Test public void factory_of_ints_monthTooHigh() { - OffsetDate.of(LocalDate.of(2007, 13, 1), OFFSET_PONE); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(2007, 13, 1), OFFSET_PONE)); } - @Test(expected=DateTimeException.class) + @Test public void factory_of_ints_yearTooLow() { - OffsetDate.of(LocalDate.of(Integer.MIN_VALUE, 1, 1), OFFSET_PONE); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Integer.MIN_VALUE, 1, 1), OFFSET_PONE)); } - @Test(expected=NullPointerException.class) + @Test public void factory_of_ints_nullOffset() { - OffsetDate.of(LocalDate.of(2007, 1, 1), (ZoneOffset) null); + assertThrows(NullPointerException.class, () -> OffsetDate.of(LocalDate.of(2007, 1, 1), (ZoneOffset) null)); } //----------------------------------------------------------------------- @@ -322,15 +321,15 @@ public void factory_of_LocalDateZoneOffset() { check(test, 2008, 6, 30, OFFSET_PONE); } - @Test(expected=NullPointerException.class) + @Test public void factory_of_LocalDateZoneOffset_nullDate() { - OffsetDate.of((LocalDate) null, OFFSET_PONE); + assertThrows(NullPointerException.class, () -> OffsetDate.of((LocalDate) null, OFFSET_PONE)); } - @Test(expected=NullPointerException.class) + @Test public void factory_of_LocalDateZoneOffset_nullOffset() { LocalDate localDate = LocalDate.of(2008, 6, 30); - OffsetDate.of(localDate, (ZoneOffset) null); + assertThrows(NullPointerException.class, () -> OffsetDate.of(localDate, (ZoneOffset) null)); } //----------------------------------------------------------------------- @@ -347,27 +346,27 @@ public void test_from_TemporalAccessor_ZDT() { assertEquals(TEST_2007_07_15_PONE, OffsetDate.from(base)); } - @Test(expected=DateTimeException.class) + @Test public void test_from_TemporalAccessor_invalid_noDerive() { - OffsetDate.from(LocalTime.of(12, 30)); + assertThrows(DateTimeException.class, () -> OffsetDate.from(LocalTime.of(12, 30))); } - @Test(expected=NullPointerException.class) + @Test public void test_from_TemporalAccessor_null() { - OffsetDate.from((TemporalAccessor) null); + assertThrows(NullPointerException.class, () -> OffsetDate.from((TemporalAccessor) null)); } //----------------------------------------------------------------------- // parse() //----------------------------------------------------------------------- - @Test + @ParameterizedTest @UseDataProvider("data_sampleToString") public void factory_parse_validText(int y, int m, int d, String offsetId, String parsable) { OffsetDate t = OffsetDate.parse(parsable); - assertNotNull(parsable, t); - assertEquals(parsable, y, t.getYear()); - assertEquals(parsable, m, t.getMonth().getValue()); - assertEquals(parsable, d, t.getDayOfMonth()); + assertNotNull(t, parsable); + assertEquals(y, t.getYear(), parsable); + assertEquals(m, t.getMonth().getValue(), parsable); + assertEquals(d, t.getDayOfMonth(), parsable); assertEquals(ZoneOffset.of(offsetId), t.getOffset()); } @@ -393,25 +392,25 @@ public static Object[][] data_sampleBadParse() { }; } - @Test(expected=DateTimeParseException.class) + @ParameterizedTest @UseDataProvider("data_sampleBadParse") public void factory_parse_invalidText(String unparsable) { - OffsetDate.parse(unparsable); + assertThrows(DateTimeParseException.class, () -> OffsetDate.parse(unparsable)); } - @Test(expected=DateTimeParseException.class) + @Test public void factory_parse_illegalValue() { - OffsetDate.parse("2008-06-32+01:00"); + assertThrows(DateTimeParseException.class, () -> OffsetDate.parse("2008-06-32+01:00")); } - @Test(expected=DateTimeParseException.class) + @Test public void factory_parse_invalidValue() { - OffsetDate.parse("2008-06-31+01:00"); + assertThrows(DateTimeParseException.class, () -> OffsetDate.parse("2008-06-31+01:00")); } - @Test(expected=NullPointerException.class) + @Test public void factory_parse_nullText() { - OffsetDate.parse((String) null); + assertThrows(NullPointerException.class, () -> OffsetDate.parse((String) null)); } //----------------------------------------------------------------------- @@ -424,40 +423,34 @@ public void factory_parse_formatter() { assertEquals(OffsetDate.of(LocalDate.of(2010, 12, 3), ZoneOffset.ofHours(1)), test); } - @Test(expected=NullPointerException.class) + @Test public void factory_parse_formatter_nullText() { DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d"); - OffsetDate.parse((String) null, f); + assertThrows(NullPointerException.class, () -> OffsetDate.parse((String) null, f)); } - @Test(expected=NullPointerException.class) + @Test public void factory_parse_formatter_nullFormatter() { - OffsetDate.parse("ANY", null); + assertThrows(NullPointerException.class, () -> OffsetDate.parse("ANY", null)); } //----------------------------------------------------------------------- // constructor //----------------------------------------------------------------------- - @Test(expected=NullPointerException.class) + @Test public void constructor_nullDate() throws Throwable { Constructor con = OffsetDate.class.getDeclaredConstructor(LocalDate.class, ZoneOffset.class); con.setAccessible(true); - try { - con.newInstance(null, OFFSET_PONE); - } catch (InvocationTargetException ex) { - throw ex.getCause(); - } + InvocationTargetException thrown = assertThrows(InvocationTargetException.class, () -> con.newInstance(null, OFFSET_PONE)); + assertTrue(thrown.getCause() instanceof NullPointerException); } - @Test(expected=NullPointerException.class) + @Test public void constructor_nullOffset() throws Throwable { Constructor con = OffsetDate.class.getDeclaredConstructor(LocalDate.class, ZoneOffset.class); con.setAccessible(true); - try { - con.newInstance(LocalDate.of(2008, 6, 30), null); - } catch (InvocationTargetException ex) { - throw ex.getCause(); - } + InvocationTargetException thrown = assertThrows(InvocationTargetException.class, () -> con.newInstance(LocalDate.of(2008, 6, 30), null)); + assertTrue(thrown.getCause() instanceof NullPointerException); } //----------------------------------------------------------------------- @@ -476,7 +469,7 @@ public static Object[][] data_sampleDates() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_sampleDates") public void test_get_OffsetDate(int y, int m, int d, ZoneOffset offset) { LocalDate localDate = LocalDate.of(y, m, d); @@ -576,9 +569,9 @@ public void test_query_zone() { assertEquals(OFFSET_PONE, TemporalQueries.zone().queryFrom(TEST_2007_07_15_PONE)); } - @Test(expected=NullPointerException.class) + @Test public void test_query_null() { - TEST_2007_07_15_PONE.query(null); + assertThrows(NullPointerException.class, () -> TEST_2007_07_15_PONE.query(null)); } //----------------------------------------------------------------------- @@ -605,7 +598,7 @@ public static Object[][] data_until() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_until") public void test_until(long expected, OffsetDate od1, OffsetDate od2, TemporalUnit unit) { assertEquals(expected, od1.until(od2, unit)); @@ -619,10 +612,10 @@ public void test_until_otherType() { assertEquals(2, start.until(end, ChronoUnit.MONTHS)); } - @Test(expected=DateTimeException.class) + @Test public void test_until_invalidType() { OffsetDate od1 = OffsetDate.of(2012, 6, 30, OFFSET_PONE); - od1.until(Instant.ofEpochSecond(7), ChronoUnit.SECONDS); + assertThrows(DateTimeException.class, () -> od1.until(Instant.ofEpochSecond(7), ChronoUnit.SECONDS)); } //----------------------------------------------------------------------- @@ -643,9 +636,9 @@ public void test_withOffsetSameLocal_noChange() { assertEquals(base, test); } - @Test(expected=NullPointerException.class) + @Test public void test_withOffsetSameLocal_null() { - TEST_2007_07_15_PONE.withOffsetSameLocal(null); + assertThrows(NullPointerException.class, () -> TEST_2007_07_15_PONE.withOffsetSameLocal(null)); } //----------------------------------------------------------------------- @@ -697,9 +690,9 @@ public void test_with_adjustment_noChange() { assertEquals(base, test); } - @Test(expected=NullPointerException.class) + @Test public void test_with_adjustment_null() { - TEST_2007_07_15_PONE.with((TemporalAdjuster) null); + assertThrows(NullPointerException.class, () -> TEST_2007_07_15_PONE.with((TemporalAdjuster) null)); } //----------------------------------------------------------------------- @@ -717,14 +710,14 @@ public void test_with_TemporalField() { assertEquals(OffsetDate.of(LocalDate.of(2008, 6, 30), ZoneOffset.ofHoursMinutesSeconds(2, 0, 5)), test.with(ChronoField.OFFSET_SECONDS, 7205)); } - @Test(expected=NullPointerException.class) + @Test public void test_with_TemporalField_null() { - TEST_2007_07_15_PONE.with((TemporalField) null, 0); + assertThrows(NullPointerException.class, () -> TEST_2007_07_15_PONE.with((TemporalField) null, 0)); } - @Test(expected=DateTimeException.class) + @Test public void test_with_TemporalField_invalidField() { - TEST_2007_07_15_PONE.with(ChronoField.AMPM_OF_DAY, 0); + assertThrows(DateTimeException.class, () -> TEST_2007_07_15_PONE.with(ChronoField.AMPM_OF_DAY, 0)); } //----------------------------------------------------------------------- @@ -742,9 +735,9 @@ public void test_withYear_int_noChange() { assertEquals(TEST_2007_07_15_PONE, t); } - @Test(expected=DateTimeException.class) + @Test public void test_withYear_int_invalid() { - TEST_2007_07_15_PONE.withYear(Year.MIN_VALUE - 1); + assertThrows(DateTimeException.class, () -> TEST_2007_07_15_PONE.withYear(Year.MIN_VALUE - 1)); } @Test @@ -769,9 +762,9 @@ public void test_withMonth_int_noChange() { assertEquals(TEST_2007_07_15_PONE, t); } - @Test(expected=DateTimeException.class) + @Test public void test_withMonth_int_invalid() { - TEST_2007_07_15_PONE.withMonth(13); + assertThrows(DateTimeException.class, () -> TEST_2007_07_15_PONE.withMonth(13)); } @Test @@ -796,14 +789,14 @@ public void test_withDayOfMonth_noChange() { assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PONE), t); } - @Test(expected=DateTimeException.class) + @Test public void test_withDayOfMonth_invalidForMonth() { - OffsetDate.of(LocalDate.of(2007, 11, 30), OFFSET_PONE).withDayOfMonth(31); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(2007, 11, 30), OFFSET_PONE).withDayOfMonth(31)); } - @Test(expected=DateTimeException.class) + @Test public void test_withDayOfMonth_invalidAlways() { - OffsetDate.of(LocalDate.of(2007, 11, 30), OFFSET_PONE).withDayOfMonth(32); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(2007, 11, 30), OFFSET_PONE).withDayOfMonth(32)); } //----------------------------------------------------------------------- @@ -821,14 +814,14 @@ public void test_withDayOfYear_noChange() { assertEquals(TEST_2007_07_15_PONE, t); } - @Test(expected=DateTimeException.class) + @Test public void test_withDayOfYear_illegal() { - TEST_2007_07_15_PONE.withDayOfYear(367); + assertThrows(DateTimeException.class, () -> TEST_2007_07_15_PONE.withDayOfYear(367)); } - @Test(expected=DateTimeException.class) + @Test public void test_withDayOfYear_invalid() { - TEST_2007_07_15_PONE.withDayOfYear(366); + assertThrows(DateTimeException.class, () -> TEST_2007_07_15_PONE.withDayOfYear(366)); } //----------------------------------------------------------------------- @@ -854,9 +847,9 @@ public void test_plus_PlusAdjuster_zero() { assertEquals(TEST_2007_07_15_PONE, t); } - @Test(expected=NullPointerException.class) + @Test public void test_plus_PlusAdjuster_null() { - TEST_2007_07_15_PONE.plus((TemporalAmount) null); + assertThrows(NullPointerException.class, () -> TEST_2007_07_15_PONE.plus((TemporalAmount) null)); } //----------------------------------------------------------------------- @@ -894,26 +887,26 @@ public void test_plusYears_long_big() { assertEquals(OffsetDate.of(LocalDate.of((int) (-40L + years), 6, 1), OFFSET_PONE), test); } - @Test(expected=DateTimeException.class) + @Test public void test_plusYears_long_invalidTooLarge() { - OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 1, 1), OFFSET_PONE).plusYears(1); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 1, 1), OFFSET_PONE).plusYears(1)); } - @Test(expected=DateTimeException.class) + @Test public void test_plusYears_long_invalidTooLargeMaxAddMax() { OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); - test.plusYears(Long.MAX_VALUE); + assertThrows(DateTimeException.class, () -> test.plusYears(Long.MAX_VALUE)); } - @Test(expected=DateTimeException.class) + @Test public void test_plusYears_long_invalidTooLargeMaxAddMin() { OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); - test.plusYears(Long.MIN_VALUE); + assertThrows(DateTimeException.class, () -> test.plusYears(Long.MIN_VALUE)); } - @Test(expected=DateTimeException.class) + @Test public void test_plusYears_long_invalidTooSmall() { - OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusYears(-1); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusYears(-1)); } //----------------------------------------------------------------------- @@ -976,26 +969,26 @@ public void test_plusMonths_long_big() { assertEquals(OffsetDate.of(LocalDate.of((int) (-40L + months / 12), 6 + (int) (months % 12), 1), OFFSET_PONE), test); } - @Test(expected=DateTimeException.class) + @Test public void test_plusMonths_long_invalidTooLarge() { - OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE).plusMonths(1); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE).plusMonths(1)); } - @Test(expected=DateTimeException.class) + @Test public void test_plusMonths_long_invalidTooLargeMaxAddMax() { OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); - test.plusMonths(Long.MAX_VALUE); + assertThrows(DateTimeException.class, () -> test.plusMonths(Long.MAX_VALUE)); } - @Test(expected=DateTimeException.class) + @Test public void test_plusMonths_long_invalidTooLargeMaxAddMin() { OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); - test.plusMonths(Long.MIN_VALUE); + assertThrows(DateTimeException.class, () -> test.plusMonths(Long.MIN_VALUE)); } - @Test(expected=DateTimeException.class) + @Test public void test_plusMonths_long_invalidTooSmall() { - OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusMonths(-1); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusMonths(-1)); } //----------------------------------------------------------------------- @@ -1033,7 +1026,7 @@ public static Object[][] data_samplePlusWeeksSymmetry() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_samplePlusWeeksSymmetry") public void test_plusWeeks_symmetry(OffsetDate reference) { for (int weeks = 0; weeks < 365 * 8; weeks++) { @@ -1107,24 +1100,24 @@ public void test_plusWeeks_minimum() { assertEquals(expected, t); } - @Test(expected=DateTimeException.class) + @Test public void test_plusWeeks_invalidTooLarge() { - OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).plusWeeks(1); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).plusWeeks(1)); } - @Test(expected=DateTimeException.class) + @Test public void test_plusWeeks_invalidTooSmall() { - OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 7), OFFSET_PONE).plusWeeks(-1); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 7), OFFSET_PONE).plusWeeks(-1)); } - @Test(expected=ArithmeticException.class) + @Test public void test_plusWeeks_invalidMaxMinusMax() { - OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).plusWeeks(Long.MAX_VALUE); + assertThrows(ArithmeticException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).plusWeeks(Long.MAX_VALUE)); } - @Test(expected=ArithmeticException.class) + @Test public void test_plusWeeks_invalidMaxMinusMin() { - OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).plusWeeks(Long.MIN_VALUE); + assertThrows(ArithmeticException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).plusWeeks(Long.MIN_VALUE)); } //----------------------------------------------------------------------- @@ -1162,7 +1155,7 @@ public static Object[][] data_samplePlusDaysSymmetry() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_samplePlusDaysSymmetry") public void test_plusDays_symmetry(OffsetDate reference) { for (int days = 0; days < 365 * 8; days++) { @@ -1236,24 +1229,24 @@ public void test_plusDays_minimum() { assertEquals(expected, t); } - @Test(expected=DateTimeException.class) + @Test public void test_plusDays_invalidTooLarge() { - OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).plusDays(1); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).plusDays(1)); } - @Test(expected=DateTimeException.class) + @Test public void test_plusDays_invalidTooSmall() { - OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusDays(-1); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusDays(-1)); } - @Test(expected=ArithmeticException.class) + @Test public void test_plusDays_overflowTooLarge() { - OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).plusDays(Long.MAX_VALUE); + assertThrows(ArithmeticException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).plusDays(Long.MAX_VALUE)); } - @Test(expected=ArithmeticException.class) + @Test public void test_plusDays_overflowTooSmall() { - OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusDays(Long.MIN_VALUE); + assertThrows(ArithmeticException.class, () -> OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusDays(Long.MIN_VALUE)); } //----------------------------------------------------------------------- @@ -1279,9 +1272,9 @@ public void test_minus_MinusAdjuster_zero() { assertEquals(TEST_2007_07_15_PONE, t); } - @Test(expected=NullPointerException.class) + @Test public void test_plus_MinusAdjuster_null() { - TEST_2007_07_15_PONE.minus((TemporalAmount) null); + assertThrows(NullPointerException.class, () -> TEST_2007_07_15_PONE.minus((TemporalAmount) null)); } //----------------------------------------------------------------------- @@ -1319,26 +1312,26 @@ public void test_minusYears_long_big() { assertEquals(OffsetDate.of(LocalDate.of((int) (40L - years), 6, 1), OFFSET_PONE), test); } - @Test(expected=DateTimeException.class) + @Test public void test_minusYears_long_invalidTooLarge() { - OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 1, 1), OFFSET_PONE).minusYears(-1); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 1, 1), OFFSET_PONE).minusYears(-1)); } - @Test(expected=DateTimeException.class) + @Test public void test_minusYears_long_invalidTooLargeMaxAddMax() { OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); - test.minusYears(Long.MAX_VALUE); + assertThrows(DateTimeException.class, () -> test.minusYears(Long.MAX_VALUE)); } - @Test(expected=DateTimeException.class) + @Test public void test_minusYears_long_invalidTooLargeMaxAddMin() { OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); - test.minusYears(Long.MIN_VALUE); + assertThrows(DateTimeException.class, () -> test.minusYears(Long.MIN_VALUE)); } - @Test(expected=DateTimeException.class) + @Test public void test_minusYears_long_invalidTooSmall() { - OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusYears(1); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusYears(1)); } //----------------------------------------------------------------------- @@ -1401,26 +1394,26 @@ public void test_minusMonths_long_big() { assertEquals(OffsetDate.of(LocalDate.of((int) (40L - months / 12), 6 - (int) (months % 12), 1), OFFSET_PONE), test); } - @Test(expected=DateTimeException.class) + @Test public void test_minusMonths_long_invalidTooLarge() { - OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE).minusMonths(-1); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE).minusMonths(-1)); } - @Test(expected=DateTimeException.class) + @Test public void test_minusMonths_long_invalidTooLargeMaxAddMax() { OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); - test.minusMonths(Long.MAX_VALUE); + assertThrows(DateTimeException.class, () -> test.minusMonths(Long.MAX_VALUE)); } - @Test(expected=DateTimeException.class) + @Test public void test_minusMonths_long_invalidTooLargeMaxAddMin() { OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); - test.minusMonths(Long.MIN_VALUE); + assertThrows(DateTimeException.class, () -> test.minusMonths(Long.MIN_VALUE)); } - @Test(expected=DateTimeException.class) + @Test public void test_minusMonths_long_invalidTooSmall() { - OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusMonths(1); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusMonths(1)); } //----------------------------------------------------------------------- @@ -1458,7 +1451,7 @@ public static Object[][] data_sampleMinusWeeksSymmetry() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_sampleMinusWeeksSymmetry") public void test_minusWeeks_symmetry(OffsetDate reference) { for (int weeks = 0; weeks < 365 * 8; weeks++) { @@ -1532,24 +1525,24 @@ public void test_minusWeeks_minimum() { assertEquals(expected, t); } - @Test(expected=DateTimeException.class) + @Test public void test_minusWeeks_invalidTooLarge() { - OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).minusWeeks(-1); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).minusWeeks(-1)); } - @Test(expected=DateTimeException.class) + @Test public void test_minusWeeks_invalidTooSmall() { - OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 7), OFFSET_PONE).minusWeeks(1); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 7), OFFSET_PONE).minusWeeks(1)); } - @Test(expected=ArithmeticException.class) + @Test public void test_minusWeeks_invalidMaxMinusMax() { - OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).minusWeeks(Long.MAX_VALUE); + assertThrows(ArithmeticException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).minusWeeks(Long.MAX_VALUE)); } - @Test(expected=ArithmeticException.class) + @Test public void test_minusWeeks_invalidMaxMinusMin() { - OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).minusWeeks(Long.MIN_VALUE); + assertThrows(ArithmeticException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).minusWeeks(Long.MIN_VALUE)); } //----------------------------------------------------------------------- @@ -1587,7 +1580,7 @@ public static Object[][] data_sampleMinusDaysSymmetry() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_sampleMinusDaysSymmetry") public void test_minusDays_symmetry(OffsetDate reference) { for (int days = 0; days < 365 * 8; days++) { @@ -1661,24 +1654,24 @@ public void test_minusDays_minimum() { assertEquals(expected, t); } - @Test(expected=DateTimeException.class) + @Test public void test_minusDays_invalidTooLarge() { - OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).minusDays(-1); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).minusDays(-1)); } - @Test(expected=DateTimeException.class) + @Test public void test_minusDays_invalidTooSmall() { - OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusDays(1); + assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusDays(1)); } - @Test(expected=ArithmeticException.class) + @Test public void test_minusDays_overflowTooLarge() { - OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).minusDays(Long.MIN_VALUE); + assertThrows(ArithmeticException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).minusDays(Long.MIN_VALUE)); } - @Test(expected=ArithmeticException.class) + @Test public void test_minusDays_overflowTooSmall() { - OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusDays(Long.MAX_VALUE); + assertThrows(ArithmeticException.class, () -> OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusDays(Long.MAX_VALUE)); } //----------------------------------------------------------------------- @@ -1691,9 +1684,9 @@ public void test_format_formatter() { assertEquals("2010 12 3", t); } - @Test(expected=NullPointerException.class) + @Test public void test_format_formatter_null() { - OffsetDate.of(LocalDate.of(2010, 12, 3), OFFSET_PONE).format(null); + assertThrows(NullPointerException.class, () -> OffsetDate.of(LocalDate.of(2010, 12, 3), OFFSET_PONE).format(null)); } //----------------------------------------------------------------------- @@ -1706,16 +1699,16 @@ public void test_atTime_Local() { t.atTime(LocalTime.of(11, 30))); } - @Test(expected=NullPointerException.class) + @Test public void test_atTime_Local_nullLocalTime() { OffsetDate t = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO); - t.atTime((LocalTime) null); + assertThrows(NullPointerException.class, () -> t.atTime((LocalTime) null)); } //----------------------------------------------------------------------- // toLocalDate() //----------------------------------------------------------------------- - @Test + @ParameterizedTest @UseDataProvider("data_sampleDates") public void test_toLocalDate(int year, int month, int day, ZoneOffset offset) { LocalDate t = LocalDate.of(year, month, day); @@ -1779,17 +1772,17 @@ public void test_compareTo_24hourDifference() { assertTrue(a.atTime(LocalTime.MIDNIGHT).toInstant().compareTo(b.atTime(LocalTime.MIDNIGHT).toInstant()) == 0); } - @Test(expected=NullPointerException.class) + @Test public void test_compareTo_null() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); - a.compareTo(null); + assertThrows(NullPointerException.class, () -> a.compareTo(null)); } - @Test(expected=ClassCastException.class) + @Test @SuppressWarnings({"unchecked", "rawtypes"}) public void compareToNonOffsetDate() { Comparable c = TEST_2007_07_15_PONE; - c.compareTo(new Object()); + assertThrows(ClassCastException.class, () -> c.compareTo(new Object())); } //----------------------------------------------------------------------- @@ -1861,28 +1854,28 @@ public void test_isBeforeIsAfterIsEqual_instantComparison() { assertFalse(b.isAfter(b)); } - @Test(expected=NullPointerException.class) + @Test public void test_isBefore_null() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); - a.isBefore(null); + assertThrows(NullPointerException.class, () -> a.isBefore(null)); } - @Test(expected=NullPointerException.class) + @Test public void test_isAfter_null() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); - a.isAfter(null); + assertThrows(NullPointerException.class, () -> a.isAfter(null)); } - @Test(expected=NullPointerException.class) + @Test public void test_isEqual_null() { OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); - a.isEqual(null); + assertThrows(NullPointerException.class, () -> a.isEqual(null)); } //----------------------------------------------------------------------- // equals() / hashCode() //----------------------------------------------------------------------- - @Test + @ParameterizedTest @UseDataProvider("data_sampleDates") public void test_equals_true(int y, int m, int d, ZoneOffset offset) { OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); @@ -1890,7 +1883,8 @@ public void test_equals_true(int y, int m, int d, ZoneOffset offset) { assertTrue(a.equals(b)); assertTrue(a.hashCode() == b.hashCode()); } - @Test + + @ParameterizedTest @UseDataProvider("data_sampleDates") public void test_equals_false_year_differs(int y, int m, int d, ZoneOffset offset) { OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); @@ -1898,7 +1892,7 @@ public void test_equals_false_year_differs(int y, int m, int d, ZoneOffset offse assertFalse(a.equals(b)); } - @Test + @ParameterizedTest @UseDataProvider("data_sampleDates") public void test_equals_false_month_differs(int y, int m, int d, ZoneOffset offset) { OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); @@ -1906,7 +1900,7 @@ public void test_equals_false_month_differs(int y, int m, int d, ZoneOffset offs assertFalse(a.equals(b)); } - @Test + @ParameterizedTest @UseDataProvider("data_sampleDates") public void test_equals_false_day_differs(int y, int m, int d, ZoneOffset offset) { OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); @@ -1914,7 +1908,7 @@ public void test_equals_false_day_differs(int y, int m, int d, ZoneOffset offset assertFalse(a.equals(b)); } - @Test + @ParameterizedTest @UseDataProvider("data_sampleDates") public void test_equals_false_offset_differs(int y, int m, int d, ZoneOffset ignored) { OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), OFFSET_PONE); @@ -1963,7 +1957,7 @@ public static Object[][] data_sampleToString() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_sampleToString") public void test_toString(int y, int m, int d, String offsetId, String expected) { OffsetDate t = OffsetDate.of(LocalDate.of(y, m, d), ZoneOffset.of(offsetId)); diff --git a/src/test/java/org/threeten/extra/TestPackedFields.java b/src/test/java/org/threeten/extra/TestPackedFields.java index f06023c3..731610bf 100644 --- a/src/test/java/org/threeten/extra/TestPackedFields.java +++ b/src/test/java/org/threeten/extra/TestPackedFields.java @@ -35,7 +35,8 @@ import static java.time.temporal.ChronoUnit.FOREVER; import static java.time.temporal.ChronoUnit.MINUTES; import static java.time.temporal.ChronoUnit.SECONDS; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.time.DateTimeException; import java.time.LocalDate; @@ -45,7 +46,7 @@ import java.time.format.DateTimeParseException; import java.time.format.ResolverStyle; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test PackedFields. @@ -68,9 +69,9 @@ public void test_date_basics() { assertEquals(99991231, PackedFields.PACKED_DATE.range().getMaximum()); } - @Test(expected = DateTimeException.class) + @Test public void test_date_rangeRefinedBy_time() { - PackedFields.PACKED_DATE.rangeRefinedBy(LocalTime.of(11, 30)); + assertThrows(DateTimeException.class, () -> PackedFields.PACKED_DATE.rangeRefinedBy(LocalTime.of(11, 30))); } @Test @@ -80,14 +81,14 @@ public void test_date_getFrom() { assertEquals(99991231, LocalDate.of(9999, 12, 31).get(PackedFields.PACKED_DATE)); } - @Test(expected = DateTimeException.class) + @Test public void test_date_getFrom_rangeLow() { - PackedFields.PACKED_DATE.getFrom(LocalDate.of(999, 12, 31)); + assertThrows(DateTimeException.class, () -> PackedFields.PACKED_DATE.getFrom(LocalDate.of(999, 12, 31))); } - @Test(expected = DateTimeException.class) + @Test public void test_date_getFrom_rangeHigh() { - PackedFields.PACKED_DATE.getFrom(LocalDate.of(10000, 1, 1)); + assertThrows(DateTimeException.class, () -> PackedFields.PACKED_DATE.getFrom(LocalDate.of(10000, 1, 1))); } @Test @@ -95,9 +96,9 @@ public void test_date_adjustInto() { assertEquals(LocalDate.of(2015, 12, 3), LocalDate.MIN.with(PackedFields.PACKED_DATE, 20151203)); } - @Test(expected = DateTimeException.class) + @Test public void test_date_adjustInto_range() { - LocalDate.MIN.with(PackedFields.PACKED_DATE, 1230101); + assertThrows(DateTimeException.class, () -> LocalDate.MIN.with(PackedFields.PACKED_DATE, 1230101)); } @Test @@ -106,10 +107,10 @@ public void test_date_resolve() { assertEquals(LocalDate.of(2015, 12, 3), LocalDate.parse("20151203", f)); } - @Test(expected = DateTimeParseException.class) + @Test public void test_date_resolve_invalid_smart() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_DATE).toFormatter(); - LocalDate.parse("20151403", f.withResolverStyle(ResolverStyle.SMART)); + assertThrows(DateTimeParseException.class, () -> LocalDate.parse("20151403", f.withResolverStyle(ResolverStyle.SMART))); } @Test @@ -134,9 +135,9 @@ public void test_hourMin_basics() { assertEquals(2359, PackedFields.PACKED_HOUR_MIN.range().getMaximum()); } - @Test(expected = DateTimeException.class) + @Test public void test_hourMin_rangeRefinedBy_time() { - PackedFields.PACKED_HOUR_MIN.rangeRefinedBy(LocalDate.of(2015, 12, 3)); + assertThrows(DateTimeException.class, () -> PackedFields.PACKED_HOUR_MIN.rangeRefinedBy(LocalDate.of(2015, 12, 3))); } @Test @@ -150,9 +151,9 @@ public void test_hourMin_adjustInto() { assertEquals(LocalTime.of(11, 30), LocalTime.MIDNIGHT.with(PackedFields.PACKED_HOUR_MIN, 1130)); } - @Test(expected = DateTimeException.class) + @Test public void test_hourMin_adjustInto_value() { - LocalDate.MIN.with(PackedFields.PACKED_HOUR_MIN, 1273); + assertThrows(DateTimeException.class, () -> LocalDate.MIN.with(PackedFields.PACKED_HOUR_MIN, 1273)); } @Test @@ -161,10 +162,10 @@ public void test_hourMin_resolve() { assertEquals(LocalTime.of(11, 30), LocalTime.parse("1130", f)); } - @Test(expected = DateTimeParseException.class) + @Test public void test_hourMin_resolve_invalid_smart() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_HOUR_MIN).toFormatter(); - LocalTime.parse("1173", f.withResolverStyle(ResolverStyle.SMART)); + assertThrows(DateTimeParseException.class, () -> LocalTime.parse("1173", f.withResolverStyle(ResolverStyle.SMART))); } @Test @@ -189,9 +190,9 @@ public void test_time_basics() { assertEquals(235959, PackedFields.PACKED_TIME.range().getMaximum()); } - @Test(expected = DateTimeException.class) + @Test public void test_time_rangeRefinedBy_time() { - PackedFields.PACKED_TIME.rangeRefinedBy(LocalDate.of(2015, 12, 3)); + assertThrows(DateTimeException.class, () -> PackedFields.PACKED_TIME.rangeRefinedBy(LocalDate.of(2015, 12, 3))); } @Test @@ -206,9 +207,9 @@ public void test_time_adjustInto() { assertEquals(LocalTime.of(11, 30, 52), LocalTime.MIDNIGHT.with(PackedFields.PACKED_TIME, 113052)); } - @Test(expected = DateTimeException.class) + @Test public void test_time_adjustInto_value() { - LocalDate.MIN.with(PackedFields.PACKED_TIME, 127310); + assertThrows(DateTimeException.class, () -> LocalDate.MIN.with(PackedFields.PACKED_TIME, 127310)); } @Test @@ -217,10 +218,10 @@ public void test_time_resolve() { assertEquals(LocalTime.of(11, 30, 52), LocalTime.parse("113052", f)); } - @Test(expected = DateTimeParseException.class) + @Test public void test_time_resolve_invalid_smart() { DateTimeFormatter f = new DateTimeFormatterBuilder().appendValue(PackedFields.PACKED_TIME).toFormatter(); - LocalTime.parse("117361", f.withResolverStyle(ResolverStyle.SMART)); + assertThrows(DateTimeParseException.class, () -> LocalTime.parse("117361", f.withResolverStyle(ResolverStyle.SMART))); } @Test diff --git a/src/test/java/org/threeten/extra/TestPeriodDuration.java b/src/test/java/org/threeten/extra/TestPeriodDuration.java index 5d90ca52..a7d76cca 100644 --- a/src/test/java/org/threeten/extra/TestPeriodDuration.java +++ b/src/test/java/org/threeten/extra/TestPeriodDuration.java @@ -37,8 +37,9 @@ import static java.time.temporal.ChronoUnit.NANOS; import static java.time.temporal.ChronoUnit.SECONDS; import static java.time.temporal.ChronoUnit.YEARS; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -54,17 +55,15 @@ import java.time.format.DateTimeParseException; import java.util.Arrays; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test class. */ -@RunWith(DataProviderRunner.class) public class TestPeriodDuration { private static final Period P1Y2M3D = Period.of(1, 2, 3); @@ -107,9 +106,9 @@ public void test_ZERO() { assertEquals(0, PeriodDuration.ZERO.get(NANOS)); } - @Test(expected = DateTimeException.class) + @Test public void test_ZERO_getEra() { - PeriodDuration.ZERO.get(ERAS); + assertThrows(DateTimeException.class, () -> PeriodDuration.ZERO.get(ERAS)); } //----------------------------------------------------------------------- @@ -220,19 +219,19 @@ public static Object[][] data_valid() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_valid") public void test_parse_CharSequence_valid(String str, Period period, Duration duration) { assertEquals(PeriodDuration.of(period, duration), PeriodDuration.parse(str)); } - @Test + @ParameterizedTest @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, Period period, Duration duration) { assertEquals(PeriodDuration.of(period, duration), PeriodDuration.parse("+" + str)); } - @Test + @ParameterizedTest @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, Period period, Duration duration) { assertEquals(PeriodDuration.of(period, duration).negated(), PeriodDuration.parse("-" + str)); @@ -256,15 +255,15 @@ public static Object[][] data_invalid() { }; } - @Test(expected = DateTimeParseException.class) + @ParameterizedTest @UseDataProvider("data_invalid") public void test_parse_CharSequence_invalid(String str) { - PeriodDuration.parse(str); + assertThrows(DateTimeParseException.class, () -> PeriodDuration.parse(str)); } - @Test(expected = NullPointerException.class) + @Test public void test_parse_CharSequence_null() { - PeriodDuration.parse((CharSequence) null); + assertThrows(NullPointerException.class, () -> PeriodDuration.parse((CharSequence) null)); } //----------------------------------------------------------------------- @@ -275,19 +274,19 @@ public void test_plus_TemporalAmount_PeriodDuration() { assertEquals(PeriodDuration.of(P1Y2M3D, Duration.ofSeconds(9)), test.plus(Duration.ofSeconds(4))); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_TemporalAmount_overflowTooBig() { - PeriodDuration.of(Period.of(Integer.MAX_VALUE - 1, 0, 0)).plus(PeriodDuration.of(Period.ofYears(2))); + assertThrows(ArithmeticException.class, () -> PeriodDuration.of(Period.of(Integer.MAX_VALUE - 1, 0, 0)).plus(PeriodDuration.of(Period.ofYears(2)))); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_TemporalAmount_overflowTooSmall() { - PeriodDuration.of(Period.of(Integer.MIN_VALUE + 1, 0, 0)).plus(PeriodDuration.of(Period.ofYears(-2))); + assertThrows(ArithmeticException.class, () -> PeriodDuration.of(Period.of(Integer.MIN_VALUE + 1, 0, 0)).plus(PeriodDuration.of(Period.ofYears(-2)))); } - @Test(expected = NullPointerException.class) + @Test public void test_plus_TemporalAmount_null() { - P1Y2M3D.plus(null); + assertThrows(NullPointerException.class, () -> P1Y2M3D.plus(null)); } //----------------------------------------------------------------------- @@ -298,19 +297,19 @@ public void test_minus_TemporalAmount_PeriodDuration() { assertEquals(PeriodDuration.of(P1Y2M3D, Duration.ofSeconds(1)), test.minus(Duration.ofSeconds(4))); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_TemporalAmount_overflowTooBig() { - PeriodDuration.of(Period.of(Integer.MAX_VALUE - 1, 0, 0)).minus(PeriodDuration.of(Period.ofYears(-2))); + assertThrows(ArithmeticException.class, () -> PeriodDuration.of(Period.of(Integer.MAX_VALUE - 1, 0, 0)).minus(PeriodDuration.of(Period.ofYears(-2)))); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_TemporalAmount_overflowTooSmall() { - PeriodDuration.of(Period.of(Integer.MIN_VALUE + 1, 0, 0)).minus(PeriodDuration.of(Period.ofYears(2))); + assertThrows(ArithmeticException.class, () -> PeriodDuration.of(Period.of(Integer.MIN_VALUE + 1, 0, 0)).minus(PeriodDuration.of(Period.ofYears(2)))); } - @Test(expected = NullPointerException.class) + @Test public void test_minus_TemporalAmount_null() { - P1Y2M3D.minus(null); + assertThrows(NullPointerException.class, () -> P1Y2M3D.minus(null)); } //----------------------------------------------------------------------- @@ -323,14 +322,14 @@ public void test_multipliedBy() { assertEquals(PeriodDuration.of(Period.of(-3, -6, -9), Duration.ofSeconds(-15)), test.multipliedBy(-3)); } - @Test(expected = ArithmeticException.class) + @Test public void test_multipliedBy_overflowTooBig() { - PeriodDuration.of(Period.ofYears(Integer.MAX_VALUE / 2 + 1)).multipliedBy(2); + assertThrows(ArithmeticException.class, () -> PeriodDuration.of(Period.ofYears(Integer.MAX_VALUE / 2 + 1)).multipliedBy(2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_multipliedBy_overflowTooSmall() { - PeriodDuration.of(Period.ofYears(Integer.MIN_VALUE / 2 - 1)).multipliedBy(2); + assertThrows(ArithmeticException.class, () -> PeriodDuration.of(Period.ofYears(Integer.MIN_VALUE / 2 - 1)).multipliedBy(2)); } //----------------------------------------------------------------------- @@ -339,9 +338,9 @@ public void test_negated() { assertEquals(PeriodDuration.of(P1Y2M3D.negated(), DUR_5.negated()), PeriodDuration.of(P1Y2M3D, DUR_5).negated()); } - @Test(expected = ArithmeticException.class) + @Test public void test_negated_overflow() { - PeriodDuration.of(Duration.ofSeconds(Long.MIN_VALUE)).negated(); + assertThrows(ArithmeticException.class, () -> PeriodDuration.of(Duration.ofSeconds(Long.MIN_VALUE)).negated()); } //----------------------------------------------------------------------- @@ -364,9 +363,9 @@ public void test_normalizedStandardDays() { PeriodDuration.of(P1Y2M3D, Duration.ofHours(-73)).normalizedStandardDays()); } - @Test(expected = ArithmeticException.class) + @Test public void test_normalizedStandardDaysn_overflow() { - PeriodDuration.of(Duration.ofSeconds(Long.MIN_VALUE)).normalizedStandardDays(); + assertThrows(ArithmeticException.class, () -> PeriodDuration.of(Duration.ofSeconds(Long.MIN_VALUE)).normalizedStandardDays()); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestQuarter.java b/src/test/java/org/threeten/extra/TestQuarter.java index 1b8f6cd0..d825a510 100644 --- a/src/test/java/org/threeten/extra/TestQuarter.java +++ b/src/test/java/org/threeten/extra/TestQuarter.java @@ -63,9 +63,10 @@ import static java.time.temporal.ChronoField.YEAR_OF_ERA; import static java.time.temporal.IsoFields.QUARTER_OF_YEAR; import static java.time.temporal.IsoFields.QUARTER_YEARS; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.threeten.extra.Quarter.Q3; import java.io.Serializable; @@ -82,17 +83,15 @@ import java.time.temporal.UnsupportedTemporalTypeException; import java.util.Locale; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test Quarter. */ -@RunWith(DataProviderRunner.class) public class TestQuarter { //----------------------------------------------------------------------- @@ -115,14 +114,14 @@ public void test_of_int_singleton() { } } - @Test(expected = DateTimeException.class) + @Test public void test_of_int_valueTooLow() { - Quarter.of(0); + assertThrows(DateTimeException.class, () -> Quarter.of(0)); } - @Test(expected = DateTimeException.class) + @Test public void test_of_int_valueTooHigh() { - Quarter.of(5); + assertThrows(DateTimeException.class, () -> Quarter.of(5)); } //----------------------------------------------------------------------- @@ -144,14 +143,14 @@ public void test_ofMonth_int_singleton() { assertSame(Quarter.Q4, Quarter.ofMonth(12)); } - @Test(expected = DateTimeException.class) + @Test public void test_ofMonth_int_valueTooLow() { - Quarter.ofMonth(0); + assertThrows(DateTimeException.class, () -> Quarter.ofMonth(0)); } - @Test(expected = DateTimeException.class) + @Test public void test_ofMonth_int_valueTooHigh() { - Quarter.ofMonth(13); + assertThrows(DateTimeException.class, () -> Quarter.ofMonth(13)); } //----------------------------------------------------------------------- @@ -179,14 +178,14 @@ public void test_from_TemporalAccessor_Month() { assertEquals(Quarter.Q4, Quarter.from(Month.DECEMBER)); } - @Test(expected = DateTimeException.class) + @Test public void test_from_TemporalAccessorl_invalid_noDerive() { - Quarter.from(LocalTime.of(12, 30)); + assertThrows(DateTimeException.class, () -> Quarter.from(LocalTime.of(12, 30))); } - @Test(expected = NullPointerException.class) + @Test public void test_from_TemporalAccessor_null() { - Quarter.from((TemporalAccessor) null); + assertThrows(NullPointerException.class, () -> Quarter.from((TemporalAccessor) null)); } @Test @@ -203,14 +202,14 @@ public void test_getDisplayName() { assertEquals("Q1", Quarter.Q1.getDisplayName(TextStyle.SHORT, Locale.US)); } - @Test(expected = NullPointerException.class) + @Test public void test_getDisplayName_nullStyle() { - Quarter.Q1.getDisplayName(null, Locale.US); + assertThrows(NullPointerException.class, () -> Quarter.Q1.getDisplayName(null, Locale.US)); } - @Test(expected = NullPointerException.class) + @Test public void test_getDisplayName_nullLocale() { - Quarter.Q1.getDisplayName(TextStyle.FULL, null); + assertThrows(NullPointerException.class, () -> Quarter.Q1.getDisplayName(TextStyle.FULL, null)); } //----------------------------------------------------------------------- @@ -261,14 +260,14 @@ public void test_range() { assertEquals(QUARTER_OF_YEAR.range(), Quarter.Q1.range(QUARTER_OF_YEAR)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_range_invalidField() { - Quarter.Q1.range(MONTH_OF_YEAR); + assertThrows(UnsupportedTemporalTypeException.class, () -> Quarter.Q1.range(MONTH_OF_YEAR)); } - @Test(expected = NullPointerException.class) + @Test public void test_range_null() { - Quarter.Q1.range(null); + assertThrows(NullPointerException.class, () -> Quarter.Q1.range(null)); } //----------------------------------------------------------------------- @@ -282,14 +281,14 @@ public void test_get() { assertEquals(4, Quarter.Q4.get(QUARTER_OF_YEAR)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_get_invalidField() { - Quarter.Q2.get(MONTH_OF_YEAR); + assertThrows(UnsupportedTemporalTypeException.class, () -> Quarter.Q2.get(MONTH_OF_YEAR)); } - @Test(expected = NullPointerException.class) + @Test public void test_get_null() { - Quarter.Q2.get(null); + assertThrows(NullPointerException.class, () -> Quarter.Q2.get(null)); } //----------------------------------------------------------------------- @@ -303,14 +302,14 @@ public void test_getLong() { assertEquals(4, Quarter.Q4.getLong(QUARTER_OF_YEAR)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_getLong_invalidField() { - Quarter.Q2.getLong(MONTH_OF_YEAR); + assertThrows(UnsupportedTemporalTypeException.class, () -> Quarter.Q2.getLong(MONTH_OF_YEAR)); } - @Test(expected = NullPointerException.class) + @Test public void test_getLong_null() { - Quarter.Q2.getLong(null); + assertThrows(NullPointerException.class, () -> Quarter.Q2.getLong(null)); } //----------------------------------------------------------------------- @@ -333,7 +332,7 @@ public static Object[][] data_plus() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_plus_long(int base, long amount, int expected) { assertEquals(Quarter.of(expected), Quarter.of(base).plus(amount)); @@ -359,7 +358,7 @@ public static Object[][] data_minus() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_minus") public void test_minus_long(int base, long amount, int expected) { assertEquals(Quarter.of(expected), Quarter.of(base).minus(amount)); diff --git a/src/test/java/org/threeten/extra/TestSeconds.java b/src/test/java/org/threeten/extra/TestSeconds.java index d5b001b3..d8cc0130 100644 --- a/src/test/java/org/threeten/extra/TestSeconds.java +++ b/src/test/java/org/threeten/extra/TestSeconds.java @@ -31,10 +31,11 @@ */ package org.threeten.extra; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -45,19 +46,17 @@ import java.time.LocalTime; import java.time.format.DateTimeParseException; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test class. */ -@RunWith(DataProviderRunner.class) public class TestSeconds { - + //----------------------------------------------------------------------- @Test public void test_isSerializable() { @@ -76,7 +75,7 @@ public void test_deserializationSingleton() throws Exception { assertSame(test, ois.readObject()); } } - + //----------------------------------------------------------------------- @Test public void test_ZERO() { @@ -87,7 +86,7 @@ public void test_ZERO() { assertTrue(Seconds.ZERO.isZero()); assertFalse(Seconds.ZERO.isPositive()); } - + //----------------------------------------------------------------------- @Test public void test_of() { @@ -127,12 +126,12 @@ public void test_ofHours() { assertEquals(-7200, Seconds.ofHours(-2).getAmount()); assertEquals((Integer.MIN_VALUE / 3600) * 3600, Seconds.ofHours(Integer.MIN_VALUE / 3600).getAmount()); } - - @Test(expected = ArithmeticException.class) + + @Test public void test_ofHours_overflow() { - Seconds.ofHours((Integer.MAX_VALUE / 3600) + 3600); + assertThrows(ArithmeticException.class, () -> Seconds.ofHours((Integer.MAX_VALUE / 3600) + 3600)); } - + //----------------------------------------------------------------------- @Test public void test_ofMinutes() { @@ -144,12 +143,12 @@ public void test_ofMinutes() { assertEquals(-120, Seconds.ofMinutes(-2).getAmount()); assertEquals((Integer.MIN_VALUE / 60) * 60, Seconds.ofMinutes(Integer.MIN_VALUE / 60).getAmount()); } - - @Test(expected = ArithmeticException.class) + + @Test public void test_ofMinutes_overflow() { - Seconds.ofMinutes((Integer.MAX_VALUE / 60) + 60); + assertThrows(ArithmeticException.class, () -> Seconds.ofMinutes((Integer.MAX_VALUE / 60) + 60)); } - + //----------------------------------------------------------------------- @DataProvider public static Object[][] data_valid() { @@ -211,19 +210,19 @@ public static Object[][] data_valid() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_valid") public void test_parse_CharSequence_valid(String str, int expectedSeconds) { assertEquals(Seconds.of(expectedSeconds), Seconds.parse(str)); } - @Test + @ParameterizedTest @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, int expectedSeconds) { assertEquals(Seconds.of(expectedSeconds), Seconds.parse("+" + str)); } - @Test + @ParameterizedTest @UseDataProvider("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, int expectedSeconds) { assertEquals(Seconds.of(-expectedSeconds), Seconds.parse("-" + str)); @@ -249,17 +248,17 @@ public static Object[][] data_invalid() { }; } - @Test(expected = DateTimeParseException.class) + @ParameterizedTest @UseDataProvider("data_invalid") public void test_parse_CharSequence_invalid(String str) { - Seconds.parse(str); + assertThrows(DateTimeParseException.class, () -> Seconds.parse(str)); } - @Test(expected = NullPointerException.class) + @Test public void test_parse_CharSequence_null() { - Seconds.parse((CharSequence) null); + assertThrows(NullPointerException.class, () -> Seconds.parse((CharSequence) null)); } - + //----------------------------------------------------------------------- @Test public void test_plus_TemporalAmount_Seconds() { @@ -270,22 +269,22 @@ public void test_plus_TemporalAmount_Seconds() { assertEquals(Seconds.of(Integer.MAX_VALUE), Seconds.of(Integer.MAX_VALUE - 1).plus(Seconds.of(1))); assertEquals(Seconds.of(Integer.MIN_VALUE), Seconds.of(Integer.MIN_VALUE + 1).plus(Seconds.of(-1))); } - - @Test(expected = ArithmeticException.class) + + @Test public void test_plus_TemporalAmount_overflowTooBig() { - Seconds.of(Integer.MAX_VALUE - 1).plus(Seconds.of(2)); + assertThrows(ArithmeticException.class, () -> Seconds.of(Integer.MAX_VALUE - 1).plus(Seconds.of(2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_TemporalAmount_overflowTooSmall() { - Seconds.of(Integer.MIN_VALUE + 1).plus(Seconds.of(-2)); + assertThrows(ArithmeticException.class, () -> Seconds.of(Integer.MIN_VALUE + 1).plus(Seconds.of(-2))); } - @Test(expected = NullPointerException.class) + @Test public void test_plus_TemporalAmount_null() { - Seconds.of(Integer.MIN_VALUE + 1).plus(null); + assertThrows(NullPointerException.class, () -> Seconds.of(Integer.MIN_VALUE + 1).plus(null)); } - + //----------------------------------------------------------------------- @Test public void test_plus_int() { @@ -297,16 +296,16 @@ public void test_plus_int() { assertEquals(Seconds.of(Integer.MIN_VALUE), Seconds.of(Integer.MIN_VALUE + 1).plus(-1)); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_int_overflowTooBig() { - Seconds.of(Integer.MAX_VALUE - 1).plus(2); + assertThrows(ArithmeticException.class, () -> Seconds.of(Integer.MAX_VALUE - 1).plus(2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_int_overflowTooSmall() { - Seconds.of(Integer.MIN_VALUE + 1).plus(-2); + assertThrows(ArithmeticException.class, () -> Seconds.of(Integer.MIN_VALUE + 1).plus(-2)); } - + //----------------------------------------------------------------------- @Test public void test_minus_TemporalAmount_Seconds() { @@ -318,21 +317,21 @@ public void test_minus_TemporalAmount_Seconds() { assertEquals(Seconds.of(Integer.MIN_VALUE), Seconds.of(Integer.MIN_VALUE + 1).minus(Seconds.of(1))); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_TemporalAmount_overflowTooBig() { - Seconds.of(Integer.MAX_VALUE - 1).minus(Seconds.of(-2)); + assertThrows(ArithmeticException.class, () -> Seconds.of(Integer.MAX_VALUE - 1).minus(Seconds.of(-2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_TemporalAmount_overflowTooSmall() { - Seconds.of(Integer.MIN_VALUE + 1).minus(Seconds.of(2)); + assertThrows(ArithmeticException.class, () -> Seconds.of(Integer.MIN_VALUE + 1).minus(Seconds.of(2))); } - @Test(expected = NullPointerException.class) + @Test public void test_minus_TemporalAmount_null() { - Seconds.of(Integer.MIN_VALUE + 1).minus(null); + assertThrows(NullPointerException.class, () -> Seconds.of(Integer.MIN_VALUE + 1).minus(null)); } - + //----------------------------------------------------------------------- @Test public void test_minus_int() { @@ -344,16 +343,16 @@ public void test_minus_int() { assertEquals(Seconds.of(Integer.MIN_VALUE), Seconds.of(Integer.MIN_VALUE + 1).minus(1)); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_int_overflowTooBig() { - Seconds.of(Integer.MAX_VALUE - 1).minus(-2); + assertThrows(ArithmeticException.class, () -> Seconds.of(Integer.MAX_VALUE - 1).minus(-2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_int_overflowTooSmall() { - Seconds.of(Integer.MIN_VALUE + 1).minus(2); + assertThrows(ArithmeticException.class, () -> Seconds.of(Integer.MIN_VALUE + 1).minus(2)); } - + //----------------------------------------------------------------------- @Test public void test_multipliedBy() { @@ -371,16 +370,16 @@ public void test_multipliedBy_negate() { assertEquals(Seconds.of(-15), test5.multipliedBy(-3)); } - @Test(expected = ArithmeticException.class) + @Test public void test_multipliedBy_overflowTooBig() { - Seconds.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2); + assertThrows(ArithmeticException.class, () -> Seconds.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_multipliedBy_overflowTooSmall() { - Seconds.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2); + assertThrows(ArithmeticException.class, () -> Seconds.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2)); } - + //----------------------------------------------------------------------- @Test public void test_dividedBy() { @@ -400,11 +399,11 @@ public void test_dividedBy_negate() { assertEquals(Seconds.of(-4), test12.dividedBy(-3)); } - @Test(expected = ArithmeticException.class) + @Test public void test_dividedBy_divideByZero() { - Seconds.of(1).dividedBy(0); + assertThrows(ArithmeticException.class, () -> Seconds.of(1).dividedBy(0)); } - + //----------------------------------------------------------------------- @Test public void test_negated() { @@ -414,11 +413,11 @@ public void test_negated() { assertEquals(Seconds.of(-Integer.MAX_VALUE), Seconds.of(Integer.MAX_VALUE).negated()); } - @Test(expected = ArithmeticException.class) + @Test public void test_negated_overflow() { - Seconds.of(Integer.MIN_VALUE).negated(); + assertThrows(ArithmeticException.class, () -> Seconds.of(Integer.MIN_VALUE).negated()); } - + //----------------------------------------------------------------------- @Test public void test_abs() { @@ -429,11 +428,11 @@ public void test_abs() { assertEquals(Seconds.of(Integer.MAX_VALUE), Seconds.of(-Integer.MAX_VALUE).abs()); } - @Test(expected = ArithmeticException.class) + @Test public void test_abs_overflow() { - Seconds.of(Integer.MIN_VALUE).abs(); + assertThrows(ArithmeticException.class, () -> Seconds.of(Integer.MIN_VALUE).abs()); } - + //----------------------------------------------------------------------- @Test public void test_addTo() { @@ -457,7 +456,7 @@ public void test_toDuration() { assertEquals(Duration.ofSeconds(i), Seconds.of(i).toDuration()); } } - + //----------------------------------------------------------------------- @Test public void test_compareTo() { @@ -468,10 +467,10 @@ public void test_compareTo() { assertEquals(1, test6.compareTo(test5)); } - @Test(expected = NullPointerException.class) + @Test public void test_compareTo_null() { Seconds test5 = Seconds.of(5); - test5.compareTo(null); + assertThrows(NullPointerException.class, () -> test5.compareTo(null)); } //----------------------------------------------------------------------- @@ -513,5 +512,5 @@ public void test_toString() { Seconds testM1 = Seconds.of(-1); assertEquals("PT-1S", testM1.toString()); } - + } diff --git a/src/test/java/org/threeten/extra/TestTemporals.java b/src/test/java/org/threeten/extra/TestTemporals.java index 7e697586..62e2d99c 100644 --- a/src/test/java/org/threeten/extra/TestTemporals.java +++ b/src/test/java/org/threeten/extra/TestTemporals.java @@ -52,10 +52,11 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static java.time.temporal.IsoFields.QUARTER_YEARS; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -75,17 +76,15 @@ import java.time.temporal.UnsupportedTemporalTypeException; import java.util.concurrent.TimeUnit; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test Temporals. */ -@RunWith(DataProviderRunner.class) public class TestTemporals { //----------------------------------------------------------------------- @@ -366,15 +365,15 @@ public static Object[][] data_parseFirstMatching() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_parseFirstMatching") public void test_parseFirstMatching(String text, DateTimeFormatter fmt1, DateTimeFormatter fmt2) { assertEquals(LocalDate.of(2016, 9, 6), Temporals.parseFirstMatching(text, LocalDate::from, fmt1, fmt2)); } - @Test(expected = DateTimeParseException.class) + @Test public void test_parseFirstMatching_zero() { - Temporals.parseFirstMatching("2016-09-06", LocalDate::from); + assertThrows(DateTimeParseException.class, () -> Temporals.parseFirstMatching("2016-09-06", LocalDate::from)); } @Test @@ -382,9 +381,9 @@ public void test_parseFirstMatching_one() { assertEquals(LocalDate.of(2016, 9, 6), Temporals.parseFirstMatching("2016-09-06", LocalDate::from, DateTimeFormatter.ISO_LOCAL_DATE)); } - @Test(expected = DateTimeParseException.class) + @Test public void test_parseFirstMatching_twoNoMatch() { - Temporals.parseFirstMatching("2016", LocalDate::from, DateTimeFormatter.ISO_LOCAL_DATE, DateTimeFormatter.BASIC_ISO_DATE); + assertThrows(DateTimeParseException.class, () -> Temporals.parseFirstMatching("2016", LocalDate::from, DateTimeFormatter.ISO_LOCAL_DATE, DateTimeFormatter.BASIC_ISO_DATE)); } //----------------------------------------------------------------------- @@ -403,31 +402,31 @@ public static Object[][] data_timeUnitConversion() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_timeUnitConversion") public void test_timeUnit(ChronoUnit chronoUnit, TimeUnit timeUnit) { assertEquals(timeUnit, Temporals.timeUnit(chronoUnit)); } - @Test(expected = IllegalArgumentException.class) + @Test public void test_timeUnit_unknown() { - Temporals.timeUnit(ChronoUnit.MONTHS); + assertThrows(IllegalArgumentException.class, () -> Temporals.timeUnit(ChronoUnit.MONTHS)); } - @Test(expected = NullPointerException.class) + @Test public void test_timeUnit_null() { - Temporals.timeUnit(null); + assertThrows(NullPointerException.class, () -> Temporals.timeUnit(null)); } - @Test + @ParameterizedTest @UseDataProvider("data_timeUnitConversion") public void test_chronoUnit(ChronoUnit chronoUnit, TimeUnit timeUnit) { assertEquals(chronoUnit, Temporals.chronoUnit(timeUnit)); } - @Test(expected = NullPointerException.class) + @Test public void test_chronoUnit_null() { - Temporals.chronoUnit(null); + assertThrows(NullPointerException.class, () -> Temporals.chronoUnit(null)); } //----------------------------------------------------------------------- @@ -580,7 +579,7 @@ public static Object[][] data_convertAmount() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_convertAmount") public void test_convertAmount( long fromAmount, TemporalUnit fromUnit, TemporalUnit resultUnit, @@ -590,7 +589,7 @@ public void test_convertAmount( assertEquals(resultRemainder, result[1]); } - @Test + @ParameterizedTest @UseDataProvider("data_convertAmount") public void test_convertAmount_negative( long fromAmount, TemporalUnit fromUnit, TemporalUnit resultUnit, @@ -641,10 +640,10 @@ public static Object[][] data_convertAmountInvalid() { }; } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_convertAmountInvalid") public void test_convertAmountInvalid(TemporalUnit fromUnit, TemporalUnit resultUnit) { - Temporals.convertAmount(1, fromUnit, resultUnit); + assertThrows(DateTimeException.class, () -> Temporals.convertAmount(1, fromUnit, resultUnit)); } @DataProvider @@ -665,10 +664,10 @@ public static Object[][] data_convertAmountInvalidUnsupported() { }; } - @Test(expected = UnsupportedTemporalTypeException.class) + @ParameterizedTest @UseDataProvider("data_convertAmountInvalidUnsupported") public void test_convertAmountInvalidUnsupported(TemporalUnit fromUnit, TemporalUnit resultUnit) { - Temporals.convertAmount(1, fromUnit, resultUnit); + assertThrows(UnsupportedTemporalTypeException.class, () -> Temporals.convertAmount(1, fromUnit, resultUnit)); } } diff --git a/src/test/java/org/threeten/extra/TestWeeks.java b/src/test/java/org/threeten/extra/TestWeeks.java index e0cccced..510779a8 100644 --- a/src/test/java/org/threeten/extra/TestWeeks.java +++ b/src/test/java/org/threeten/extra/TestWeeks.java @@ -31,10 +31,11 @@ */ package org.threeten.extra; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -51,17 +52,15 @@ import java.time.temporal.Temporal; import java.time.temporal.TemporalAmount; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test class. */ -@RunWith(DataProviderRunner.class) public class TestWeeks { //----------------------------------------------------------------------- @@ -144,19 +143,19 @@ public void test_from_Duration() { assertEquals(Weeks.of(2), Weeks.from(Duration.ofDays(14))); } - @Test(expected = DateTimeException.class) + @Test public void test_from_wrongUnit_remainder() { - Weeks.from(Period.ofDays(3)); + assertThrows(DateTimeException.class, () -> Weeks.from(Period.ofDays(3))); } - @Test(expected = DateTimeException.class) + @Test public void test_from_wrongUnit_noConversion() { - Weeks.from(Period.ofMonths(2)); + assertThrows(DateTimeException.class, () -> Weeks.from(Period.ofMonths(2))); } - @Test(expected = NullPointerException.class) + @Test public void test_from_null() { - Weeks.from((TemporalAmount) null); + assertThrows(NullPointerException.class, () -> Weeks.from((TemporalAmount) null)); } //----------------------------------------------------------------------- @@ -188,15 +187,15 @@ public static Object[][] data_invalid() { }; } - @Test(expected = DateTimeParseException.class) + @ParameterizedTest @UseDataProvider("data_invalid") public void test_parse_CharSequence_invalid(String str) { - Weeks.parse(str); + assertThrows(DateTimeParseException.class, () -> Weeks.parse(str)); } - @Test(expected = NullPointerException.class) + @Test public void test_parse_CharSequence_null() { - Weeks.parse((CharSequence) null); + assertThrows(NullPointerException.class, () -> Weeks.parse((CharSequence) null)); } //----------------------------------------------------------------------- @@ -205,14 +204,14 @@ public void test_between() { assertEquals(Weeks.of(104), Weeks.between(LocalDate.of(2019, 1, 1), LocalDate.of(2021, 1, 1))); } - @Test(expected = NullPointerException.class) + @Test public void test_between_date_null() { - Weeks.between(LocalDate.now(), (Temporal) null); + assertThrows(NullPointerException.class, () -> Weeks.between(LocalDate.now(), (Temporal) null)); } - @Test(expected = NullPointerException.class) + @Test public void test_between_null_date() { - Weeks.between((Temporal) null, LocalDate.now()); + assertThrows(NullPointerException.class, () -> Weeks.between((Temporal) null, LocalDate.now())); } //----------------------------------------------------------------------- @@ -221,9 +220,9 @@ public void test_get() { assertEquals(6, Weeks.of(6).get(ChronoUnit.WEEKS)); } - @Test(expected = DateTimeException.class) + @Test public void test_get_invalidType() { - Weeks.of(6).get(IsoFields.QUARTER_YEARS); + assertThrows(DateTimeException.class, () -> Weeks.of(6).get(IsoFields.QUARTER_YEARS)); } //----------------------------------------------------------------------- @@ -247,29 +246,29 @@ public void test_plus_TemporalAmount_Period() { assertEquals(Weeks.of(Integer.MIN_VALUE), Weeks.of(Integer.MIN_VALUE + 1).plus(Period.ofWeeks(-1))); } - @Test(expected = DateTimeException.class) + @Test public void test_plus_TemporalAmount_PeriodMonths() { - Weeks.of(1).plus(Period.ofMonths(2)); + assertThrows(DateTimeException.class, () -> Weeks.of(1).plus(Period.ofMonths(2))); } - @Test(expected = DateTimeException.class) + @Test public void test_plus_TemporalAmount_Duration() { - Weeks.of(1).plus(Duration.ofHours(2)); + assertThrows(DateTimeException.class, () -> Weeks.of(1).plus(Duration.ofHours(2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_TemporalAmount_overflowTooBig() { - Weeks.of(Integer.MAX_VALUE - 1).plus(Weeks.of(2)); + assertThrows(ArithmeticException.class, () -> Weeks.of(Integer.MAX_VALUE - 1).plus(Weeks.of(2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_TemporalAmount_overflowTooSmall() { - Weeks.of(Integer.MIN_VALUE + 1).plus(Weeks.of(-2)); + assertThrows(ArithmeticException.class, () -> Weeks.of(Integer.MIN_VALUE + 1).plus(Weeks.of(-2))); } - @Test(expected = NullPointerException.class) + @Test public void test_plus_TemporalAmount_null() { - Weeks.of(Integer.MIN_VALUE + 1).plus(null); + assertThrows(NullPointerException.class, () -> Weeks.of(Integer.MIN_VALUE + 1).plus(null)); } //----------------------------------------------------------------------- @@ -283,14 +282,14 @@ public void test_plus_int() { assertEquals(Weeks.of(Integer.MIN_VALUE), Weeks.of(Integer.MIN_VALUE + 1).plus(-1)); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_int_overflowTooBig() { - Weeks.of(Integer.MAX_VALUE - 1).plus(2); + assertThrows(ArithmeticException.class, () -> Weeks.of(Integer.MAX_VALUE - 1).plus(2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_int_overflowTooSmall() { - Weeks.of(Integer.MIN_VALUE + 1).plus(-2); + assertThrows(ArithmeticException.class, () -> Weeks.of(Integer.MIN_VALUE + 1).plus(-2)); } //----------------------------------------------------------------------- @@ -314,29 +313,29 @@ public void test_minus_TemporalAmount_Period() { assertEquals(Weeks.of(Integer.MIN_VALUE), Weeks.of(Integer.MIN_VALUE + 1).minus(Period.ofWeeks(1))); } - @Test(expected = DateTimeException.class) + @Test public void test_minus_TemporalAmount_PeriodMonths() { - Weeks.of(1).minus(Period.ofMonths(2)); + assertThrows(DateTimeException.class, () -> Weeks.of(1).minus(Period.ofMonths(2))); } - @Test(expected = DateTimeException.class) + @Test public void test_minus_TemporalAmount_Duration() { - Weeks.of(1).minus(Duration.ofHours(2)); + assertThrows(DateTimeException.class, () -> Weeks.of(1).minus(Duration.ofHours(2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_TemporalAmount_overflowTooBig() { - Weeks.of(Integer.MAX_VALUE - 1).minus(Weeks.of(-2)); + assertThrows(ArithmeticException.class, () -> Weeks.of(Integer.MAX_VALUE - 1).minus(Weeks.of(-2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_TemporalAmount_overflowTooSmall() { - Weeks.of(Integer.MIN_VALUE + 1).minus(Weeks.of(2)); + assertThrows(ArithmeticException.class, () -> Weeks.of(Integer.MIN_VALUE + 1).minus(Weeks.of(2))); } - @Test(expected = NullPointerException.class) + @Test public void test_minus_TemporalAmount_null() { - Weeks.of(Integer.MIN_VALUE + 1).minus(null); + assertThrows(NullPointerException.class, () -> Weeks.of(Integer.MIN_VALUE + 1).minus(null)); } //----------------------------------------------------------------------- @@ -350,14 +349,14 @@ public void test_minus_int() { assertEquals(Weeks.of(Integer.MIN_VALUE), Weeks.of(Integer.MIN_VALUE + 1).minus(1)); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_int_overflowTooBig() { - Weeks.of(Integer.MAX_VALUE - 1).minus(-2); + assertThrows(ArithmeticException.class, () -> Weeks.of(Integer.MAX_VALUE - 1).minus(-2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_int_overflowTooSmall() { - Weeks.of(Integer.MIN_VALUE + 1).minus(2); + assertThrows(ArithmeticException.class, () -> Weeks.of(Integer.MIN_VALUE + 1).minus(2)); } //----------------------------------------------------------------------- @@ -377,14 +376,14 @@ public void test_multipliedBy_negate() { assertEquals(Weeks.of(-15), test5.multipliedBy(-3)); } - @Test(expected = ArithmeticException.class) + @Test public void test_multipliedBy_overflowTooBig() { - Weeks.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2); + assertThrows(ArithmeticException.class, () -> Weeks.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_multipliedBy_overflowTooSmall() { - Weeks.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2); + assertThrows(ArithmeticException.class, () -> Weeks.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2)); } //----------------------------------------------------------------------- @@ -406,9 +405,9 @@ public void test_dividedBy_negate() { assertEquals(Weeks.of(-4), test12.dividedBy(-3)); } - @Test(expected = ArithmeticException.class) + @Test public void test_dividedBy_divideByZero() { - Weeks.of(1).dividedBy(0); + assertThrows(ArithmeticException.class, () -> Weeks.of(1).dividedBy(0)); } //----------------------------------------------------------------------- @@ -420,9 +419,9 @@ public void test_negated() { assertEquals(Weeks.of(-Integer.MAX_VALUE), Weeks.of(Integer.MAX_VALUE).negated()); } - @Test(expected = ArithmeticException.class) + @Test public void test_negated_overflow() { - Weeks.of(Integer.MIN_VALUE).negated(); + assertThrows(ArithmeticException.class, () -> Weeks.of(Integer.MIN_VALUE).negated()); } //----------------------------------------------------------------------- @@ -435,9 +434,9 @@ public void test_abs() { assertEquals(Weeks.of(Integer.MAX_VALUE), Weeks.of(-Integer.MAX_VALUE).abs()); } - @Test(expected = ArithmeticException.class) + @Test public void test_abs_overflow() { - Weeks.of(Integer.MIN_VALUE).abs(); + assertThrows(ArithmeticException.class, () -> Weeks.of(Integer.MIN_VALUE).abs()); } //----------------------------------------------------------------------- @@ -471,10 +470,10 @@ public void test_compareTo() { assertEquals(1, test6.compareTo(test5)); } - @Test(expected = NullPointerException.class) + @Test public void test_compareTo_null() { Weeks test5 = Weeks.of(5); - test5.compareTo(null); + assertThrows(NullPointerException.class, () -> test5.compareTo(null)); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestYearQuarter.java b/src/test/java/org/threeten/extra/TestYearQuarter.java index 76f2727e..e4caecc4 100644 --- a/src/test/java/org/threeten/extra/TestYearQuarter.java +++ b/src/test/java/org/threeten/extra/TestYearQuarter.java @@ -78,8 +78,9 @@ import static java.time.temporal.IsoFields.DAY_OF_QUARTER; import static java.time.temporal.IsoFields.QUARTER_OF_YEAR; import static java.time.temporal.IsoFields.QUARTER_YEARS; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.threeten.extra.Quarter.Q1; import static org.threeten.extra.Quarter.Q2; import static org.threeten.extra.Quarter.Q3; @@ -111,7 +112,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; /** * Test YearQuarter. @@ -158,19 +160,19 @@ public void test_of_Year_Quarter() { } } - @Test(expected = NullPointerException.class) + @Test public void test_of_Year_Quarter_nullQuarter() { - YearQuarter.of(Year.of(2012), (Quarter) null); + assertThrows(NullPointerException.class, () -> YearQuarter.of(Year.of(2012), (Quarter) null)); } - @Test(expected = NullPointerException.class) + @Test public void test_of_Year_Quarter_nullYear() { - YearQuarter.of((Year) null, Quarter.Q2); + assertThrows(NullPointerException.class, () -> YearQuarter.of((Year) null, Quarter.Q2)); } - @Test(expected = NullPointerException.class) + @Test public void test_of_Year_Quarter_nullBoth() { - YearQuarter.of((Year) null, (Quarter) null); + assertThrows(NullPointerException.class, () -> YearQuarter.of((Year) null, (Quarter) null)); } //----------------------------------------------------------------------- @@ -188,9 +190,9 @@ public void test_of_Year_int() { } } - @Test(expected = NullPointerException.class) + @Test public void test_of_Year_int_null() { - YearQuarter.of((Year) null, 2); + assertThrows(NullPointerException.class, () -> YearQuarter.of((Year) null, 2)); } //----------------------------------------------------------------------- @@ -208,19 +210,19 @@ public void test_of_int_Quarter() { } } - @Test(expected = DateTimeException.class) + @Test public void test_of_int_Quarter_yearTooLow() { - YearQuarter.of(Year.MIN_VALUE - 1, Quarter.Q2); + assertThrows(DateTimeException.class, () -> YearQuarter.of(Year.MIN_VALUE - 1, Quarter.Q2)); } - @Test(expected = DateTimeException.class) + @Test public void test_of_int_Quarter_yearTooHigh() { - YearQuarter.of(Year.MAX_VALUE + 1, Quarter.Q2); + assertThrows(DateTimeException.class, () -> YearQuarter.of(Year.MAX_VALUE + 1, Quarter.Q2)); } - @Test(expected = NullPointerException.class) + @Test public void test_of_int_Quarter_null() { - YearQuarter.of(2012, (Quarter) null); + assertThrows(NullPointerException.class, () -> YearQuarter.of(2012, (Quarter) null)); } //----------------------------------------------------------------------- @@ -240,24 +242,24 @@ public void test_of_int_int() { } } - @Test(expected = DateTimeException.class) + @Test public void test_of_int_int_yearTooLow() { - YearQuarter.of(Year.MIN_VALUE - 1, 1); + assertThrows(DateTimeException.class, () -> YearQuarter.of(Year.MIN_VALUE - 1, 1)); } - @Test(expected = DateTimeException.class) + @Test public void test_of_int_int_yearTooHigh() { - YearQuarter.of(Year.MAX_VALUE + 1, 1); + assertThrows(DateTimeException.class, () -> YearQuarter.of(Year.MAX_VALUE + 1, 1)); } - @Test(expected = DateTimeException.class) + @Test public void test_of_int_int_quarterTooLow() { - YearQuarter.of(2012, 0); + assertThrows(DateTimeException.class, () -> YearQuarter.of(2012, 0)); } - @Test(expected = DateTimeException.class) + @Test public void test_of_int_int_quarterTooHigh() { - YearQuarter.of(2012, 5); + assertThrows(DateTimeException.class, () -> YearQuarter.of(2012, 5)); } //----------------------------------------------------------------------- @@ -285,14 +287,14 @@ public void test_from_TemporalAccessor_leapYear() { } } - @Test(expected = DateTimeException.class) + @Test public void test_from_TemporalAccessor_noDerive() { - YearQuarter.from(LocalTime.NOON); + assertThrows(DateTimeException.class, () -> YearQuarter.from(LocalTime.NOON)); } - @Test(expected = NullPointerException.class) + @Test public void test_from_TemporalAccessor_null() { - YearQuarter.from((TemporalAccessor) null); + assertThrows(NullPointerException.class, () -> YearQuarter.from((TemporalAccessor) null)); } //----------------------------------------------------------------------- @@ -308,19 +310,19 @@ public void test_parse_CharSequence_caseInsensitive() { assertEquals(YearQuarter.of(2012, Q3), YearQuarter.parse("2012-q3")); } - @Test(expected = DateTimeParseException.class) + @Test public void test_parse_CharSequenceDate_invalidYear() { - YearQuarter.parse("12345-Q3"); + assertThrows(DateTimeParseException.class, () -> YearQuarter.parse("12345-Q3")); } - @Test(expected = DateTimeParseException.class) + @Test public void test_parse_CharSequenceDate_invalidQuarter() { - YearQuarter.parse("2012-Q0"); + assertThrows(DateTimeParseException.class, () -> YearQuarter.parse("2012-Q0")); } - @Test(expected = NullPointerException.class) + @Test public void test_parse_CharSequenceDate_nullCharSequence() { - YearQuarter.parse((CharSequence) null); + assertThrows(NullPointerException.class, () -> YearQuarter.parse((CharSequence) null)); } //----------------------------------------------------------------------- @@ -332,21 +334,21 @@ public void test_parse_CharSequenceDateTimeFormatter() { assertEquals(YearQuarter.of(2012, Q3), YearQuarter.parse("Q3 2012", f)); } - @Test(expected = DateTimeParseException.class) + @Test public void test_parse_CharSequenceDateDateTimeFormatter_invalidQuarter() { DateTimeFormatter f = DateTimeFormatter.ofPattern("'Q'Q uuuu"); - YearQuarter.parse("Q0 2012", f); + assertThrows(DateTimeParseException.class, () -> YearQuarter.parse("Q0 2012", f)); } - @Test(expected = NullPointerException.class) + @Test public void test_parse_CharSequenceDateTimeFormatter_nullCharSequence() { DateTimeFormatter f = DateTimeFormatter.ofPattern("'Q'Q uuuu"); - YearQuarter.parse((CharSequence) null, f); + assertThrows(NullPointerException.class, () -> YearQuarter.parse((CharSequence) null, f)); } - @Test(expected = NullPointerException.class) + @Test public void test_parse_CharSequenceDateTimeFormatter_nullDateTimeFormatter() { - YearQuarter.parse("", (DateTimeFormatter) null); + assertThrows(NullPointerException.class, () -> YearQuarter.parse("", (DateTimeFormatter) null)); } //----------------------------------------------------------------------- @@ -424,14 +426,14 @@ public void test_range() { assertEquals(ERA.range(), TEST.range(ERA)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_range_invalidField() { - TEST.range(MONTH_OF_YEAR); + assertThrows(UnsupportedTemporalTypeException.class, () -> TEST.range(MONTH_OF_YEAR)); } - @Test(expected = NullPointerException.class) + @Test public void test_range_null() { - TEST.range((TemporalField) null); + assertThrows(NullPointerException.class, () -> TEST.range((TemporalField) null)); } //----------------------------------------------------------------------- @@ -445,14 +447,14 @@ public void test_get() { assertEquals(1, TEST.get(ERA)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_get_invalidField() { - TEST.get(MONTH_OF_YEAR); + assertThrows(UnsupportedTemporalTypeException.class, () -> TEST.get(MONTH_OF_YEAR)); } - @Test(expected = NullPointerException.class) + @Test public void test_get_null() { - TEST.get((TemporalField) null); + assertThrows(NullPointerException.class, () -> TEST.get((TemporalField) null)); } //----------------------------------------------------------------------- @@ -466,14 +468,14 @@ public void test_getLong() { assertEquals(1L, TEST.getLong(ERA)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_getLong_invalidField() { - TEST.getLong(MONTH_OF_YEAR); + assertThrows(UnsupportedTemporalTypeException.class, () -> TEST.getLong(MONTH_OF_YEAR)); } - @Test(expected = NullPointerException.class) + @Test public void test_getLong_null() { - TEST.getLong((TemporalField) null); + assertThrows(NullPointerException.class, () -> TEST.getLong((TemporalField) null)); } //----------------------------------------------------------------------- @@ -574,14 +576,14 @@ public void test_with_TemporalAdjuster_YearQuarter() { assertEquals(YearQuarter.of(2012, Q3), YearQuarter.of(2007, Q2).with(YearQuarter.of(2012, Q3))); } - @Test(expected = DateTimeException.class) + @Test public void test_with_TemporalAdjuster_LocalDate() { - YearQuarter.of(2007, Q2).with(LocalDate.of(2012, 6, 30)); + assertThrows(DateTimeException.class, () -> YearQuarter.of(2007, Q2).with(LocalDate.of(2012, 6, 30))); } - @Test(expected = NullPointerException.class) + @Test public void test_with_TemporalAdjuster_null() { - YearQuarter.of(2007, Q2).with((TemporalAdjuster) null); + assertThrows(NullPointerException.class, () -> YearQuarter.of(2007, Q2).with((TemporalAdjuster) null)); } //----------------------------------------------------------------------- @@ -592,14 +594,14 @@ public void test_withYear() { assertEquals(YearQuarter.of(2012, Q2), YearQuarter.of(2007, Q2).withYear(2012)); } - @Test(expected = DateTimeException.class) + @Test public void test_withYear_int_quarterTooLow() { - TEST.withYear(Year.MIN_VALUE - 1); + assertThrows(DateTimeException.class, () -> TEST.withYear(Year.MIN_VALUE - 1)); } - @Test(expected = DateTimeException.class) + @Test public void test_withYear_int_quarterTooHigh() { - TEST.withYear(Year.MAX_VALUE + 1); + assertThrows(DateTimeException.class, () -> TEST.withYear(Year.MAX_VALUE + 1)); } //----------------------------------------------------------------------- @@ -610,14 +612,14 @@ public void test_withQuarter_int() { assertEquals(YearQuarter.of(2007, Q1), YearQuarter.of(2007, Q2).withQuarter(1)); } - @Test(expected = DateTimeException.class) + @Test public void test_withQuarter_int_quarterTooLow() { - TEST.withQuarter(0); + assertThrows(DateTimeException.class, () -> TEST.withQuarter(0)); } - @Test(expected = DateTimeException.class) + @Test public void test_withQuarter_int_quarterTooHigh() { - TEST.withQuarter(5); + assertThrows(DateTimeException.class, () -> TEST.withQuarter(5)); } //----------------------------------------------------------------------- @@ -741,9 +743,9 @@ public void test_adjustInto_Temporal_lastValidDay_leap() { assertEquals(expected, YearQuarter.of(2012, Q1).adjustInto(base)); } - @Test(expected = NullPointerException.class) + @Test public void test_adjustInto_Temporal_null() { - TEST.adjustInto((Temporal) null); + assertThrows(NullPointerException.class, () -> TEST.adjustInto((Temporal) null)); } //----------------------------------------------------------------------- @@ -782,27 +784,27 @@ public void test_until_TemporalTemporalUnit_YEARS() { assertEquals(2, YearQuarter.of(2012, Q2).until(YearQuarter.of(2014, Q2), YEARS)); } - @Test(expected = NullPointerException.class) + @Test public void test_until_TemporalTemporalUnit_nullTemporal() { - YearQuarter.of(2012, Q2).until(null, QUARTER_YEARS); + assertThrows(NullPointerException.class, () -> YearQuarter.of(2012, Q2).until(null, QUARTER_YEARS)); } - @Test(expected = NullPointerException.class) + @Test public void test_until_TemporalTemporalUnit_nullTemporalUnit() { - YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q3), null); + assertThrows(NullPointerException.class, () -> YearQuarter.of(2012, Q2).until(YearQuarter.of(2012, Q3), null)); } //----------------------------------------------------------------------- // quartersUntil(YearQuarter) //----------------------------------------------------------------------- - @Test(expected = NullPointerException.class) + @Test public void test_quartersUntil_null() { - YearQuarter.of(2012, Q2).quartersUntil(null); + assertThrows(NullPointerException.class, () -> YearQuarter.of(2012, Q2).quartersUntil(null)); } - @Test(expected = IllegalArgumentException.class) + @Test public void test_quartersUntil_IllegalArgument() { - YearQuarter.of(2012, Q2).quartersUntil(YearQuarter.of(2012, Q1)); + assertThrows(IllegalArgumentException.class, () -> YearQuarter.of(2012, Q2).quartersUntil(YearQuarter.of(2012, Q1))); } @Test @@ -833,9 +835,9 @@ public void test_format() { assertEquals("Q1 2012", YearQuarter.of(2012, Q1).format(f)); } - @Test(expected = NullPointerException.class) + @Test public void test_format_null() { - TEST.format((DateTimeFormatter) null); + assertThrows(NullPointerException.class, () -> TEST.format((DateTimeFormatter) null)); } //----------------------------------------------------------------------- @@ -866,29 +868,29 @@ public void test_atDay_Q1_91_leap() { assertEquals(LocalDate.of(2012, 3, 31), YearQuarter.of(2012, Q1).atDay(91)); } - @Test(expected = DateTimeException.class) + @Test public void test_atDay_Q1_91_notLeap() { - YearQuarter.of(2011, Q1).atDay(91); + assertThrows(DateTimeException.class, () -> YearQuarter.of(2011, Q1).atDay(91)); } - @Test(expected = DateTimeException.class) + @Test public void test_atDay_Q1_92() { - YearQuarter.of(2012, Q1).atDay(92); + assertThrows(DateTimeException.class, () -> YearQuarter.of(2012, Q1).atDay(92)); } - @Test(expected = DateTimeException.class) + @Test public void test_atDay_Q2_92() { - YearQuarter.of(2012, Q2).atDay(92); + assertThrows(DateTimeException.class, () -> YearQuarter.of(2012, Q2).atDay(92)); } - @Test(expected = DateTimeException.class) + @Test public void test_atDay_tooLow() { - TEST.atDay(0); + assertThrows(DateTimeException.class, () -> TEST.atDay(0)); } - @Test(expected = DateTimeException.class) + @Test public void test_atDay_tooHigh() { - TEST.atDay(93); + assertThrows(DateTimeException.class, () -> TEST.atDay(93)); } //----------------------------------------------------------------------- @@ -962,9 +964,9 @@ public void test_compareTo() { } } - @Test(expected = NullPointerException.class) + @Test public void test_compareTo_nullYearQuarter() { - TEST.compareTo(null); + assertThrows(NullPointerException.class, () -> TEST.compareTo(null)); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestYearWeek.java b/src/test/java/org/threeten/extra/TestYearWeek.java index 5f7b9048..a59cac89 100644 --- a/src/test/java/org/threeten/extra/TestYearWeek.java +++ b/src/test/java/org/threeten/extra/TestYearWeek.java @@ -72,9 +72,10 @@ import static java.time.temporal.IsoFields.QUARTER_OF_YEAR; import static java.time.temporal.IsoFields.WEEK_BASED_YEAR; import static java.time.temporal.IsoFields.WEEK_OF_WEEK_BASED_YEAR; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -109,14 +110,12 @@ import java.time.temporal.ValueRange; import java.util.Locale; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; -@RunWith(DataProviderRunner.class) public class TestYearWeek { private static final YearWeek TEST_NON_LEAP = YearWeek.of(2014, 1); @@ -345,9 +344,9 @@ public void test_now() { //----------------------------------------------------------------------- // now(ZoneId) //----------------------------------------------------------------------- - @Test(expected = NullPointerException.class) + @Test public void now_ZoneId_nullZoneId() { - YearWeek.now((ZoneId) null); + assertThrows(NullPointerException.class, () -> YearWeek.now((ZoneId) null)); } @Test @@ -377,15 +376,15 @@ public void now_Clock() { assertEquals(52, test.getWeek()); } - @Test(expected = NullPointerException.class) + @Test public void now_Clock_nullClock() { - YearWeek.now((Clock) null); + assertThrows(NullPointerException.class, () -> YearWeek.now((Clock) null)); } //----------------------------------------------------------------------- // of(Year, int) //----------------------------------------------------------------------- - @Test + @ParameterizedTest @UseDataProvider("data_sampleYearWeeks") public void test_of_Year_int(int year, int week) { YearWeek yearWeek = YearWeek.of(Year.of(year), week); @@ -401,7 +400,7 @@ public void test_carry_Year_int() { //----------------------------------------------------------------------- // of(int, int) //----------------------------------------------------------------------- - @Test + @ParameterizedTest @UseDataProvider("data_sampleYearWeeks") public void test_of(int year, int week) { YearWeek yearWeek = YearWeek.of(year, week); @@ -414,24 +413,24 @@ public void test_carry() { assertTrue(YearWeek.of(2014, 53).equals(TEST)); } - @Test(expected = DateTimeException.class) + @Test public void test_of_year_tooLow() { - YearWeek.of(Integer.MIN_VALUE, 1); + assertThrows(DateTimeException.class, () -> YearWeek.of(Integer.MIN_VALUE, 1)); } - @Test(expected = DateTimeException.class) + @Test public void test_of_year_tooHigh() { - YearWeek.of(Integer.MAX_VALUE, 1); + assertThrows(DateTimeException.class, () -> YearWeek.of(Integer.MAX_VALUE, 1)); } - @Test(expected = DateTimeException.class) + @Test public void test_of_invalidWeekValue() { - YearWeek.of(2015, 54); + assertThrows(DateTimeException.class, () -> YearWeek.of(2015, 54)); } - @Test(expected = DateTimeException.class) + @Test public void test_of_invalidWeekValueZero() { - YearWeek.of(2015, 0); + assertThrows(DateTimeException.class, () -> YearWeek.of(2015, 0)); } //----------------------------------------------------------------------- @@ -479,7 +478,7 @@ public void test_isSupported_TemporalField() { //----------------------------------------------------------------------- // atDay(DayOfWeek) //----------------------------------------------------------------------- - @Test + @ParameterizedTest @UseDataProvider("data_sampleAtDay") public void test_atDay(int weekBasedYear, int weekOfWeekBasedYear, DayOfWeek dayOfWeek, int year, int month, int dayOfMonth) { YearWeek yearWeek = YearWeek.of(weekBasedYear, weekOfWeekBasedYear); @@ -503,15 +502,15 @@ public void test_atDay_loop20years() { } } - @Test(expected = NullPointerException.class) + @Test public void test_atDay_null() { - TEST.atDay(null); + assertThrows(NullPointerException.class, () -> TEST.atDay(null)); } //----------------------------------------------------------------------- // is53WeekYear() //----------------------------------------------------------------------- - @Test + @ParameterizedTest @UseDataProvider("data_53WeekYear") public void test_is53WeekYear(int year) { YearWeek yearWeek = YearWeek.of(year, 1); @@ -573,15 +572,15 @@ public void test_compareTo() { } } - @Test(expected = NullPointerException.class) + @Test public void test_compareTo_nullYearWeek() { - TEST.compareTo(null); + assertThrows(NullPointerException.class, () -> TEST.compareTo(null)); } //----------------------------------------------------------------------- // from(TemporalAccessor) //----------------------------------------------------------------------- - @Test + @ParameterizedTest @UseDataProvider("data_sampleAtDay") public void test_from(int weekBasedYear, int weekOfWeekBasedYear, DayOfWeek dayOfWeek, int year, int month, int dayOfMonth) { YearWeek expected = YearWeek.of(weekBasedYear, weekOfWeekBasedYear); @@ -591,14 +590,14 @@ public void test_from(int weekBasedYear, int weekOfWeekBasedYear, DayOfWeek dayO assertEquals(expected, YearWeek.from(expected)); } - @Test(expected = DateTimeException.class) + @Test public void test_from_TemporalAccessor_noDerive() { - YearWeek.from(LocalTime.NOON); + assertThrows(DateTimeException.class, () -> YearWeek.from(LocalTime.NOON)); } - @Test(expected = NullPointerException.class) + @Test public void test_from_TemporalAccessor_null() { - YearWeek.from((TemporalAccessor) null); + assertThrows(NullPointerException.class, () -> YearWeek.from((TemporalAccessor) null)); } //----------------------------------------------------------------------- @@ -610,14 +609,14 @@ public void test_get() { assertEquals(1, TEST.get(WEEK_OF_WEEK_BASED_YEAR)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_get_invalidField() { - TEST.get(YEAR); + assertThrows(UnsupportedTemporalTypeException.class, () -> TEST.get(YEAR)); } - @Test(expected = NullPointerException.class) + @Test public void test_get_null() { - TEST.get((TemporalField) null); + assertThrows(NullPointerException.class, () -> TEST.get((TemporalField) null)); } //----------------------------------------------------------------------- @@ -629,14 +628,14 @@ public void test_getLong() { assertEquals(1L, TEST.getLong(WEEK_OF_WEEK_BASED_YEAR)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_getLong_invalidField() { - TEST.getLong(YEAR); + assertThrows(UnsupportedTemporalTypeException.class, () -> TEST.getLong(YEAR)); } - @Test(expected = NullPointerException.class) + @Test public void test_getLong_null() { - TEST.getLong((TemporalField) null); + assertThrows(NullPointerException.class, () -> TEST.getLong((TemporalField) null)); } //----------------------------------------------------------------------- @@ -657,23 +656,23 @@ public void test_with() { assertEquals(YearWeek.of(2016, 1), TEST.with(IsoFields.WEEK_BASED_YEAR, 2016)); } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_outOfBounds") public void test_with_outOfBounds(TemporalField field, long newValue) { - TEST.with(field, newValue); + assertThrows(DateTimeException.class, () -> TEST.with(field, newValue)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_with_TemporalAdjuster_unsupportedType() { - TEST.with(ChronoField.MONTH_OF_YEAR, 5); + assertThrows(UnsupportedTemporalTypeException.class, () -> TEST.with(ChronoField.MONTH_OF_YEAR, 5)); } //----------------------------------------------------------------------- // with(TemporalAdjuster) //----------------------------------------------------------------------- - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_with_unsupportedType() { - TEST.with(TemporalAdjusters.firstDayOfMonth()); + assertThrows(UnsupportedTemporalTypeException.class, () -> TEST.with(TemporalAdjusters.firstDayOfMonth())); } //----------------------------------------------------------------------- @@ -692,19 +691,19 @@ public void test_parse_CharSequence() { assertEquals(TEST, YearWeek.parse("2015-W01")); } - @Test(expected = DateTimeParseException.class) + @Test public void test_parse_CharSequenceDate_invalidYear() { - YearWeek.parse("12345-W7"); + assertThrows(DateTimeParseException.class, () -> YearWeek.parse("12345-W7")); } - @Test(expected = DateTimeParseException.class) + @Test public void test_parse_CharSequenceDate_invalidWeek() { - YearWeek.parse("2015-W54"); + assertThrows(DateTimeParseException.class, () -> YearWeek.parse("2015-W54")); } - @Test(expected = NullPointerException.class) + @Test public void test_parse_CharSequenceDate_nullCharSequence() { - YearWeek.parse((CharSequence) null); + assertThrows(NullPointerException.class, () -> YearWeek.parse((CharSequence) null)); } //----------------------------------------------------------------------- @@ -716,21 +715,21 @@ public void test_parse_CharSequenceDateTimeFormatter() { assertEquals(TEST, YearWeek.parse("Mon W1 2015", f)); } - @Test(expected = DateTimeParseException.class) + @Test public void test_parse_CharSequenceDateDateTimeFormatter_invalidWeek() { DateTimeFormatter f = DateTimeFormatter.ofPattern("E 'W'w YYYY").withLocale(Locale.ENGLISH); - YearWeek.parse("Mon W99 2015", f); + assertThrows(DateTimeParseException.class, () -> YearWeek.parse("Mon W99 2015", f)); } - @Test(expected = NullPointerException.class) + @Test public void test_parse_CharSequenceDateTimeFormatter_nullCharSequence() { DateTimeFormatter f = DateTimeFormatter.ofPattern("E 'W'w YYYY").withLocale(Locale.ENGLISH); - YearWeek.parse((CharSequence) null, f); + assertThrows(NullPointerException.class, () -> YearWeek.parse((CharSequence) null, f)); } - @Test(expected = NullPointerException.class) + @Test public void test_parse_CharSequenceDateTimeFormatter_nullDateTimeFormatter() { - YearWeek.parse("", (DateTimeFormatter) null); + assertThrows(NullPointerException.class, () -> YearWeek.parse("", (DateTimeFormatter) null)); } //----------------------------------------------------------------------- @@ -756,11 +755,11 @@ public void test_adjustInto() { assertEquals(LocalDate.of(2016, 1, 9), yw.adjustInto(date)); } - @Test(expected = DateTimeException.class) + @Test public void test_adjustInto_badChronology() { YearWeek yw = YearWeek.of(2016, 1); ThaiBuddhistDate date = ThaiBuddhistDate.from(LocalDate.of(2015, 6, 20)); - yw.adjustInto(date); + assertThrows(DateTimeException.class, () -> yw.adjustInto(date)); } //----------------------------------------------------------------------- @@ -785,9 +784,9 @@ public void test_until_years() { assertEquals(-1, TEST.until(YearWeek.of(2013, 2), IsoFields.WEEK_BASED_YEARS)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_until_unsupportedType() { - TEST.until(YearWeek.of(2016, 1), ChronoUnit.MONTHS); + assertThrows(UnsupportedTemporalTypeException.class, () -> TEST.until(YearWeek.of(2016, 1), ChronoUnit.MONTHS)); } //----------------------------------------------------------------------- @@ -802,14 +801,14 @@ public void test_range() { assertEquals(ValueRange.of(1, 53), TEST.range(WEEK_OF_WEEK_BASED_YEAR)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_range_invalidField() { - TEST.range(YEAR); + assertThrows(UnsupportedTemporalTypeException.class, () -> TEST.range(YEAR)); } - @Test(expected = NullPointerException.class) + @Test public void test_range_null() { - TEST.range((TemporalField) null); + assertThrows(NullPointerException.class, () -> TEST.range((TemporalField) null)); } //----------------------------------------------------------------------- @@ -831,14 +830,14 @@ public void test_withYear_resolve() { assertEquals(YearWeek.of(2014, 52), YearWeek.of(2015, 53).withYear(2014)); } - @Test(expected = DateTimeException.class) + @Test public void test_withYear_int_max() { - TEST.withYear(Integer.MAX_VALUE); + assertThrows(DateTimeException.class, () -> TEST.withYear(Integer.MAX_VALUE)); } - @Test(expected = DateTimeException.class) + @Test public void test_withYear_int_min() { - TEST.withYear(Integer.MIN_VALUE); + assertThrows(DateTimeException.class, () -> TEST.withYear(Integer.MIN_VALUE)); } //----------------------------------------------------------------------- @@ -850,9 +849,9 @@ public void test_plus() { assertEquals(YearWeek.of(2016, 1), TEST.plus(1, IsoFields.WEEK_BASED_YEARS)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_plus_unsupportedType() { - YearWeek.of(2014, 1).plus(1, ChronoUnit.DAYS); + assertThrows(UnsupportedTemporalTypeException.class, () -> YearWeek.of(2014, 1).plus(1, ChronoUnit.DAYS)); } //----------------------------------------------------------------------- @@ -877,14 +876,14 @@ public void test_withWeek_sameWeek() { assertEquals(YearWeek.of(2014, 2), YearWeek.of(2014, 2).withWeek(2)); } - @Test(expected = DateTimeException.class) + @Test public void test_withWeek_int_max() { - TEST.withWeek(Integer.MAX_VALUE); + assertThrows(DateTimeException.class, () -> TEST.withWeek(Integer.MAX_VALUE)); } - @Test(expected = DateTimeException.class) + @Test public void test_withWeek_int_min() { - TEST.withWeek(Integer.MIN_VALUE); + assertThrows(DateTimeException.class, () -> TEST.withWeek(Integer.MIN_VALUE)); } //----------------------------------------------------------------------- @@ -907,14 +906,14 @@ public void test_plusYears_changeWeek() { assertEquals(YearWeek.of(2020, 53), YearWeek.of(2015, 53).plusYears(5)); } - @Test(expected = ArithmeticException.class) + @Test public void test_plusYears_max_long() { - TEST.plusYears(Long.MAX_VALUE); + assertThrows(ArithmeticException.class, () -> TEST.plusYears(Long.MAX_VALUE)); } - @Test(expected = ArithmeticException.class) + @Test public void test_plusYears_min_long() { - TEST.plusYears(Long.MIN_VALUE); + assertThrows(ArithmeticException.class, () -> TEST.plusYears(Long.MIN_VALUE)); } //----------------------------------------------------------------------- @@ -942,14 +941,14 @@ public void test_plusWeeks_negative() { assertEquals(YearWeek.of(2009, 53), TEST.plusWeeks(-261)); } - @Test(expected = ArithmeticException.class) + @Test public void test_plusWeeks_max_long() { - TEST.plusWeeks(Long.MAX_VALUE); + assertThrows(ArithmeticException.class, () -> TEST.plusWeeks(Long.MAX_VALUE)); } - @Test(expected = ArithmeticException.class) + @Test public void test_plusWeeks_min_long() { - TEST.plusWeeks(Long.MIN_VALUE); + assertThrows(ArithmeticException.class, () -> TEST.plusWeeks(Long.MIN_VALUE)); } //----------------------------------------------------------------------- @@ -960,9 +959,9 @@ public void test_minus() { assertEquals(YearWeek.of(2014, 1), YearWeek.of(2014, 2).minus(1, ChronoUnit.WEEKS)); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_overflow() { - TEST.minus(Long.MIN_VALUE, ChronoUnit.WEEKS); + assertThrows(ArithmeticException.class, () -> TEST.minus(Long.MIN_VALUE, ChronoUnit.WEEKS)); } //----------------------------------------------------------------------- @@ -993,14 +992,14 @@ public void test_minusYears_changeWeek() { assertEquals(YearWeek.of(2014, 52), YearWeek.of(2015, 53).minusYears(1)); } - @Test(expected = ArithmeticException.class) + @Test public void test_minusYears_max_long() { - TEST.minusYears(Long.MAX_VALUE); + assertThrows(ArithmeticException.class, () -> TEST.minusYears(Long.MAX_VALUE)); } - @Test(expected = ArithmeticException.class) + @Test public void test_minusYears_min_long() { - TEST.minusYears(Long.MIN_VALUE); + assertThrows(ArithmeticException.class, () -> TEST.minusYears(Long.MIN_VALUE)); } //----------------------------------------------------------------------- @@ -1028,14 +1027,14 @@ public void test_minusWeeks_negative() { assertEquals(YearWeek.of(2021, 1), TEST.minusWeeks(-314)); } - @Test(expected = ArithmeticException.class) + @Test public void test_minWeeks_max_long() { - TEST.plusWeeks(Long.MAX_VALUE); + assertThrows(ArithmeticException.class, () -> TEST.plusWeeks(Long.MAX_VALUE)); } - @Test(expected = ArithmeticException.class) + @Test public void test_minWeeks_min_long() { - TEST.plusWeeks(Long.MIN_VALUE); + assertThrows(ArithmeticException.class, () -> TEST.plusWeeks(Long.MIN_VALUE)); } //----------------------------------------------------------------------- @@ -1055,7 +1054,7 @@ public void test_query() { //----------------------------------------------------------------------- // equals() / hashCode() //----------------------------------------------------------------------- - @Test + @ParameterizedTest @UseDataProvider("data_sampleYearWeeks") public void test_equalsAndHashCodeContract(int year, int week) { YearWeek a = YearWeek.of(year, week); @@ -1098,7 +1097,7 @@ public static Object[][] data_sampleToString() { {-10000, 1, "-10000-W01"},}; } - @Test + @ParameterizedTest @UseDataProvider("data_sampleToString") public void test_toString(int year, int week, String expected) { YearWeek yearWeek = YearWeek.of(year, week); diff --git a/src/test/java/org/threeten/extra/TestYears.java b/src/test/java/org/threeten/extra/TestYears.java index 043af527..529d7e83 100644 --- a/src/test/java/org/threeten/extra/TestYears.java +++ b/src/test/java/org/threeten/extra/TestYears.java @@ -31,10 +31,11 @@ */ package org.threeten.extra; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -51,17 +52,15 @@ import java.time.temporal.Temporal; import java.time.temporal.TemporalAmount; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test class. */ -@RunWith(DataProviderRunner.class) public class TestYears { //----------------------------------------------------------------------- @@ -149,19 +148,19 @@ public void test_from_decadesAndMonths() { assertEquals(Years.of(19), Years.from(new MockDecadesMonths(2, -12))); } - @Test(expected = DateTimeException.class) + @Test public void test_from_wrongUnit_remainder() { - Years.from(Period.ofMonths(3)); + assertThrows(DateTimeException.class, () -> Years.from(Period.ofMonths(3))); } - @Test(expected = DateTimeException.class) + @Test public void test_from_wrongUnit_noConversion() { - Years.from(Period.ofDays(2)); + assertThrows(DateTimeException.class, () -> Years.from(Period.ofDays(2))); } - @Test(expected = NullPointerException.class) + @Test public void test_from_null() { - Years.from((TemporalAmount) null); + assertThrows(NullPointerException.class, () -> Years.from((TemporalAmount) null)); } //----------------------------------------------------------------------- @@ -193,15 +192,15 @@ public static Object[][] data_invalid() { }; } - @Test(expected = DateTimeParseException.class) + @ParameterizedTest @UseDataProvider("data_invalid") public void test_parse_CharSequence_invalid(String str) { - Years.parse(str); + assertThrows(DateTimeParseException.class, () -> Years.parse(str)); } - @Test(expected = NullPointerException.class) + @Test public void test_parse_CharSequence_null() { - Years.parse((CharSequence) null); + assertThrows(NullPointerException.class, () -> Years.parse((CharSequence) null)); } //----------------------------------------------------------------------- @@ -210,14 +209,14 @@ public void test_between() { assertEquals(Years.of(2), Years.between(LocalDate.of(2019, 1, 1), LocalDate.of(2021, 1, 1))); } - @Test(expected = NullPointerException.class) + @Test public void test_between_date_null() { - Years.between(LocalDate.now(), (Temporal) null); + assertThrows(NullPointerException.class, () -> Years.between(LocalDate.now(), (Temporal) null)); } - @Test(expected = NullPointerException.class) + @Test public void test_between_null_date() { - Years.between((Temporal) null, LocalDate.now()); + assertThrows(NullPointerException.class, () -> Years.between((Temporal) null, LocalDate.now())); } //----------------------------------------------------------------------- @@ -226,9 +225,9 @@ public void test_get() { assertEquals(6, Years.of(6).get(ChronoUnit.YEARS)); } - @Test(expected = DateTimeException.class) + @Test public void test_get_invalidType() { - Years.of(6).get(IsoFields.QUARTER_YEARS); + assertThrows(DateTimeException.class, () -> Years.of(6).get(IsoFields.QUARTER_YEARS)); } //----------------------------------------------------------------------- @@ -252,29 +251,29 @@ public void test_plus_TemporalAmount_Period() { assertEquals(Years.of(Integer.MIN_VALUE), Years.of(Integer.MIN_VALUE + 1).plus(Period.ofYears(-1))); } - @Test(expected = DateTimeException.class) + @Test public void test_plus_TemporalAmount_PeriodMonths() { - Years.of(1).plus(Period.ofMonths(2)); + assertThrows(DateTimeException.class, () -> Years.of(1).plus(Period.ofMonths(2))); } - @Test(expected = DateTimeException.class) + @Test public void test_plus_TemporalAmount_Duration() { - Years.of(1).plus(Duration.ofHours(2)); + assertThrows(DateTimeException.class, () -> Years.of(1).plus(Duration.ofHours(2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_TemporalAmount_overflowTooBig() { - Years.of(Integer.MAX_VALUE - 1).plus(Years.of(2)); + assertThrows(ArithmeticException.class, () -> Years.of(Integer.MAX_VALUE - 1).plus(Years.of(2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_TemporalAmount_overflowTooSmall() { - Years.of(Integer.MIN_VALUE + 1).plus(Years.of(-2)); + assertThrows(ArithmeticException.class, () -> Years.of(Integer.MIN_VALUE + 1).plus(Years.of(-2))); } - @Test(expected = NullPointerException.class) + @Test public void test_plus_TemporalAmount_null() { - Years.of(Integer.MIN_VALUE + 1).plus(null); + assertThrows(NullPointerException.class, () -> Years.of(Integer.MIN_VALUE + 1).plus(null)); } //----------------------------------------------------------------------- @@ -288,14 +287,14 @@ public void test_plus_int() { assertEquals(Years.of(Integer.MIN_VALUE), Years.of(Integer.MIN_VALUE + 1).plus(-1)); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_int_overflowTooBig() { - Years.of(Integer.MAX_VALUE - 1).plus(2); + assertThrows(ArithmeticException.class, () -> Years.of(Integer.MAX_VALUE - 1).plus(2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_int_overflowTooSmall() { - Years.of(Integer.MIN_VALUE + 1).plus(-2); + assertThrows(ArithmeticException.class, () -> Years.of(Integer.MIN_VALUE + 1).plus(-2)); } //----------------------------------------------------------------------- @@ -319,29 +318,29 @@ public void test_minus_TemporalAmount_Period() { assertEquals(Years.of(Integer.MIN_VALUE), Years.of(Integer.MIN_VALUE + 1).minus(Period.ofYears(1))); } - @Test(expected = DateTimeException.class) + @Test public void test_minus_TemporalAmount_PeriodMonths() { - Years.of(1).minus(Period.ofMonths(2)); + assertThrows(DateTimeException.class, () -> Years.of(1).minus(Period.ofMonths(2))); } - @Test(expected = DateTimeException.class) + @Test public void test_minus_TemporalAmount_Duration() { - Years.of(1).minus(Duration.ofHours(2)); + assertThrows(DateTimeException.class, () -> Years.of(1).minus(Duration.ofHours(2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_TemporalAmount_overflowTooBig() { - Years.of(Integer.MAX_VALUE - 1).minus(Years.of(-2)); + assertThrows(ArithmeticException.class, () -> Years.of(Integer.MAX_VALUE - 1).minus(Years.of(-2))); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_TemporalAmount_overflowTooSmall() { - Years.of(Integer.MIN_VALUE + 1).minus(Years.of(2)); + assertThrows(ArithmeticException.class, () -> Years.of(Integer.MIN_VALUE + 1).minus(Years.of(2))); } - @Test(expected = NullPointerException.class) + @Test public void test_minus_TemporalAmount_null() { - Years.of(Integer.MIN_VALUE + 1).minus(null); + assertThrows(NullPointerException.class, () -> Years.of(Integer.MIN_VALUE + 1).minus(null)); } //----------------------------------------------------------------------- @@ -355,14 +354,14 @@ public void test_minus_int() { assertEquals(Years.of(Integer.MIN_VALUE), Years.of(Integer.MIN_VALUE + 1).minus(1)); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_int_overflowTooBig() { - Years.of(Integer.MAX_VALUE - 1).minus(-2); + assertThrows(ArithmeticException.class, () -> Years.of(Integer.MAX_VALUE - 1).minus(-2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_int_overflowTooSmall() { - Years.of(Integer.MIN_VALUE + 1).minus(2); + assertThrows(ArithmeticException.class, () -> Years.of(Integer.MIN_VALUE + 1).minus(2)); } //----------------------------------------------------------------------- @@ -382,14 +381,14 @@ public void test_multipliedBy_negate() { assertEquals(Years.of(-15), test5.multipliedBy(-3)); } - @Test(expected = ArithmeticException.class) + @Test public void test_multipliedBy_overflowTooBig() { - Years.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2); + assertThrows(ArithmeticException.class, () -> Years.of(Integer.MAX_VALUE / 2 + 1).multipliedBy(2)); } - @Test(expected = ArithmeticException.class) + @Test public void test_multipliedBy_overflowTooSmall() { - Years.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2); + assertThrows(ArithmeticException.class, () -> Years.of(Integer.MIN_VALUE / 2 - 1).multipliedBy(2)); } //----------------------------------------------------------------------- @@ -411,9 +410,9 @@ public void test_dividedBy_negate() { assertEquals(Years.of(-4), test12.dividedBy(-3)); } - @Test(expected = ArithmeticException.class) + @Test public void test_dividedBy_divideByZero() { - Years.of(1).dividedBy(0); + assertThrows(ArithmeticException.class, () -> Years.of(1).dividedBy(0)); } //----------------------------------------------------------------------- @@ -425,9 +424,9 @@ public void test_negated() { assertEquals(Years.of(-Integer.MAX_VALUE), Years.of(Integer.MAX_VALUE).negated()); } - @Test(expected = ArithmeticException.class) + @Test public void test_negated_overflow() { - Years.of(Integer.MIN_VALUE).negated(); + assertThrows(ArithmeticException.class, () -> Years.of(Integer.MIN_VALUE).negated()); } //----------------------------------------------------------------------- @@ -440,9 +439,9 @@ public void test_abs() { assertEquals(Years.of(Integer.MAX_VALUE), Years.of(-Integer.MAX_VALUE).abs()); } - @Test(expected = ArithmeticException.class) + @Test public void test_abs_overflow() { - Years.of(Integer.MIN_VALUE).abs(); + assertThrows(ArithmeticException.class, () -> Years.of(Integer.MIN_VALUE).abs()); } //----------------------------------------------------------------------- @@ -476,10 +475,10 @@ public void test_compareTo() { assertEquals(1, test6.compareTo(test5)); } - @Test(expected = NullPointerException.class) + @Test public void test_compareTo_null() { Years test5 = Years.of(5); - test5.compareTo(null); + assertThrows(NullPointerException.class, () -> test5.compareTo(null)); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java b/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java index e6105d50..76b0213f 100644 --- a/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java @@ -53,9 +53,10 @@ import static java.time.temporal.ChronoUnit.MONTHS; import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.DateTimeException; import java.time.DayOfWeek; @@ -74,18 +75,15 @@ import java.util.List; import java.util.function.IntPredicate; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test. */ -@RunWith(DataProviderRunner.class) public class TestAccountingChronology { private static AccountingChronology INSTANCE = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST). @@ -96,12 +94,12 @@ public class TestAccountingChronology { //----------------------------------------------------------------------- @Test public void test_chronology_of_name() { - Assert.assertEquals("Accounting", INSTANCE.getId()); + assertEquals("Accounting", INSTANCE.getId()); } @Test public void test_chronology_of_name_id() { - Assert.assertEquals(null, INSTANCE.getCalendarType()); + assertEquals(null, INSTANCE.getCalendarType()); } //----------------------------------------------------------------------- @@ -143,55 +141,55 @@ public static Object[][] data_samples() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_LocalDate_from_AccountingDate(AccountingDate accounting, LocalDate iso) { assertEquals(iso, LocalDate.from(accounting)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_AccountingDate_from_LocalDate(AccountingDate accounting, LocalDate iso) { assertEquals(accounting, AccountingDate.from(INSTANCE, iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_AccountingDate_chronology_dateEpochDay(AccountingDate accounting, LocalDate iso) { assertEquals(accounting, INSTANCE.dateEpochDay(iso.toEpochDay())); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_AccountingDate_toEpochDay(AccountingDate accounting, LocalDate iso) { assertEquals(iso.toEpochDay(), accounting.toEpochDay()); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_AccountingDate_until_CoptiDate(AccountingDate accounting, LocalDate iso) { assertEquals(INSTANCE.period(0, 0, 0), accounting.until(accounting)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_AccountingDate_until_LocalDate(AccountingDate accounting, LocalDate iso) { assertEquals(INSTANCE.period(0, 0, 0), accounting.until(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_LocalDate_until_CoptiDate(AccountingDate accounting, LocalDate iso) { assertEquals(Period.ZERO, iso.until(accounting)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(AccountingDate accounting, LocalDate iso) { assertEquals(accounting, INSTANCE.date(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_plusDays(AccountingDate accounting, LocalDate iso) { assertEquals(iso, LocalDate.from(accounting.plus(0, DAYS))); @@ -201,7 +199,7 @@ public void test_plusDays(AccountingDate accounting, LocalDate iso) { assertEquals(iso.plusDays(-60), LocalDate.from(accounting.plus(-60, DAYS))); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_minusDays(AccountingDate accounting, LocalDate iso) { assertEquals(iso, LocalDate.from(accounting.minus(0, DAYS))); @@ -211,7 +209,7 @@ public void test_minusDays(AccountingDate accounting, LocalDate iso) { assertEquals(iso.minusDays(-60), LocalDate.from(accounting.minus(-60, DAYS))); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_until_DAYS(AccountingDate accounting, LocalDate iso) { assertEquals(0, accounting.until(iso.plusDays(0), DAYS)); @@ -263,45 +261,45 @@ public static Object[][] data_badDates() { }; } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_badDates") public void test_badDates(int year, int month, int dom) { - INSTANCE.date(year, month, dom); + assertThrows(DateTimeException.class, () -> INSTANCE.date(year, month, dom)); } - @Test(expected = DateTimeException.class) + @Test public void test_chronology_dateYearDay_badDate() { - INSTANCE.dateYearDay(2001, 366); + assertThrows(DateTimeException.class, () -> INSTANCE.dateYearDay(2001, 366)); } - @Test(expected = NullPointerException.class) + @Test public void test_date_create_no_chronology() { - AccountingDate.create(null, 2012, 1, 1); + assertThrows(NullPointerException.class, () -> AccountingDate.create(null, 2012, 1, 1)); } - @Test(expected = NullPointerException.class) + @Test public void test_date_from_no_chronology() { - AccountingDate.from(null, LocalDate.of(2012, 1, 1)); + assertThrows(NullPointerException.class, () -> AccountingDate.from(null, LocalDate.of(2012, 1, 1))); } - @Test(expected = NullPointerException.class) + @Test public void test_date_now_no_chronology() { - AccountingDate.now(null); + assertThrows(NullPointerException.class, () -> AccountingDate.now(null)); } - @Test(expected = NullPointerException.class) + @Test public void test_date_of_no_chronology() { - AccountingDate.of(null, 2012, 1, 1); + assertThrows(NullPointerException.class, () -> AccountingDate.of(null, 2012, 1, 1)); } - @Test(expected = NullPointerException.class) + @Test public void test_date_ofEpochDay_no_chronology() { - AccountingDate.ofEpochDay(null, 0); + assertThrows(NullPointerException.class, () -> AccountingDate.ofEpochDay(null, 0)); } - @Test(expected = NullPointerException.class) + @Test public void test_date_ofYearDay_no_chronology() { - AccountingDate.ofYearDay(null, 0, 1); + assertThrows(NullPointerException.class, () -> AccountingDate.ofYearDay(null, 0, 1)); } //----------------------------------------------------------------------- @@ -364,7 +362,7 @@ public static Object[][] data_lengthOfMonth() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(length, INSTANCE.date(year, month, 1).lengthOfMonth()); @@ -413,9 +411,9 @@ public void test_prolepticYear_specific() { assertEquals(-3, INSTANCE.prolepticYear(AccountingEra.BCE, 4)); } - @Test(expected = ClassCastException.class) + @Test public void test_prolepticYear_badEra() { - INSTANCE.prolepticYear(IsoEra.CE, 4); + assertThrows(ClassCastException.class, () -> INSTANCE.prolepticYear(IsoEra.CE, 4)); } @Test @@ -424,9 +422,9 @@ public void test_Chronology_eraOf() { assertEquals(AccountingEra.BCE, INSTANCE.eraOf(0)); } - @Test(expected = DateTimeException.class) + @Test public void test_Chronology_eraOf_invalid() { - INSTANCE.eraOf(2); + assertThrows(DateTimeException.class, () -> INSTANCE.eraOf(2)); } @Test @@ -479,15 +477,15 @@ public static Object[][] data_ranges() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(ValueRange.of(expectedMin, expectedMax), INSTANCE.date(year, month, dom).range(field)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_range_unsupported() { - INSTANCE.date(2012, 6, 28).range(MINUTE_OF_DAY); + assertThrows(UnsupportedTemporalTypeException.class, () -> INSTANCE.date(2012, 6, 28).range(MINUTE_OF_DAY)); } //----------------------------------------------------------------------- @@ -514,15 +512,15 @@ public static Object[][] data_getLong() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(expected, INSTANCE.date(year, month, dom).getLong(field)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_getLong_unsupported() { - INSTANCE.date(2012, 6, 28).getLong(MINUTE_OF_DAY); + assertThrows(UnsupportedTemporalTypeException.class, () -> INSTANCE.date(2012, 6, 28).getLong(MINUTE_OF_DAY)); } //----------------------------------------------------------------------- @@ -566,7 +564,7 @@ public static Object[][] data_with() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, @@ -574,9 +572,9 @@ public void test_with_TemporalField(int year, int month, int dom, assertEquals(INSTANCE.date(expectedYear, expectedMonth, expectedDom), INSTANCE.date(year, month, dom).with(field, value)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_with_TemporalField_unsupported() { - INSTANCE.date(2012, 6, 28).with(MINUTE_OF_DAY, 0); + assertThrows(UnsupportedTemporalTypeException.class, () -> INSTANCE.date(2012, 6, 28).with(MINUTE_OF_DAY, 0)); } //----------------------------------------------------------------------- @@ -606,10 +604,10 @@ public void test_adjust_toLocalDate() { assertEquals(INSTANCE.date(2012, 12, 5), test); } - @Test(expected = DateTimeException.class) + @Test public void test_adjust_toMonth() { AccountingDate accounting = INSTANCE.date(2000, 1, 4); - accounting.with(Month.APRIL); + assertThrows(DateTimeException.class, () -> accounting.with(Month.APRIL)); } //----------------------------------------------------------------------- @@ -660,7 +658,7 @@ public static Object[][] data_plus() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, @@ -668,7 +666,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, assertEquals(INSTANCE.date(expectedYear, expectedMonth, expectedDom), INSTANCE.date(year, month, dom).plus(amount, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, @@ -677,9 +675,9 @@ public void test_minus_TemporalUnit( assertEquals(INSTANCE.date(expectedYear, expectedMonth, expectedDom), INSTANCE.date(year, month, dom).minus(amount, unit)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_plus_TemporalUnit_unsupported() { - INSTANCE.date(2012, 6, 28).plus(0, MINUTES); + assertThrows(UnsupportedTemporalTypeException.class, () -> INSTANCE.date(2012, 6, 28).plus(0, MINUTES)); } //----------------------------------------------------------------------- @@ -714,7 +712,7 @@ public static Object[][] data_until() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, @@ -725,11 +723,11 @@ public void test_until_TemporalUnit( assertEquals(expected, start.until(end, unit)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_until_TemporalUnit_unsupported() { AccountingDate start = INSTANCE.date(2012, 6, 28); AccountingDate end = INSTANCE.date(2012, 7, 1); - start.until(end, MINUTES); + assertThrows(UnsupportedTemporalTypeException.class, () -> start.until(end, MINUTES)); } //----------------------------------------------------------------------- @@ -738,9 +736,9 @@ public void test_plus_Period() { assertEquals(INSTANCE.date(2014, 8, 1), INSTANCE.date(2014, 5, 26).plus(INSTANCE.period(0, 2, 3))); } - @Test(expected = DateTimeException.class) + @Test public void test_plus_Period_ISO() { - assertEquals(INSTANCE.date(2014, 7, 26), INSTANCE.date(2014, 5, 26).plus(Period.ofMonths(2))); + assertThrows(DateTimeException.class, () -> INSTANCE.date(2014, 5, 26).plus(Period.ofMonths(2))); } @Test @@ -748,9 +746,9 @@ public void test_minus_Period() { assertEquals(INSTANCE.date(2014, 3, 23), INSTANCE.date(2014, 5, 26).minus(INSTANCE.period(0, 2, 3))); } - @Test(expected = DateTimeException.class) + @Test public void test_minus_Period_ISO() { - assertEquals(INSTANCE.date(2014, 3, 26), INSTANCE.date(2014, 5, 26).minus(Period.ofMonths(2))); + assertThrows(DateTimeException.class, () -> INSTANCE.date(2014, 5, 26).minus(Period.ofMonths(2))); } //----------------------------------------------------------------------- @@ -794,7 +792,7 @@ public static Object[][] data_toString() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_toString") public void test_toString(AccountingDate accounting, String expected) { assertEquals(expected, accounting.toString()); diff --git a/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java b/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java index 639da216..2a1d9e16 100644 --- a/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java +++ b/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java @@ -32,7 +32,8 @@ package org.threeten.extra.chrono; import static java.time.temporal.ChronoUnit.DAYS; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.time.DateTimeException; import java.time.DayOfWeek; @@ -44,17 +45,14 @@ import java.util.function.IntFunction; import java.util.function.IntPredicate; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test. */ -@RunWith(DataProviderRunner.class) public class TestAccountingChronologyBuilder { //----------------------------------------------------------------------- @@ -85,7 +83,7 @@ public static Object[][] data_yearEnding() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_yearEnding") public void test_isLeapYear_inLastWeekOf(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) @@ -106,7 +104,7 @@ public void test_isLeapYear_inLastWeekOf(DayOfWeek dayOfWeek, Month ending) { } } - @Test + @ParameterizedTest @UseDataProvider("data_yearEnding") public void test_isLeapYear_nearestEndOf(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) @@ -127,7 +125,7 @@ public void test_isLeapYear_nearestEndOf(DayOfWeek dayOfWeek, Month ending) { } } - @Test + @ParameterizedTest @UseDataProvider("data_yearEnding") public void test_previousLeapYears_inLastWeekOf(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) @@ -157,7 +155,7 @@ public void test_previousLeapYears_inLastWeekOf(DayOfWeek dayOfWeek, Month endin } } - @Test + @ParameterizedTest @UseDataProvider("data_yearEnding") public void test_previousLeapYears_nearestEndOf(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) @@ -187,7 +185,7 @@ public void test_previousLeapYears_nearestEndOf(DayOfWeek dayOfWeek, Month endin } } - @Test + @ParameterizedTest @UseDataProvider("data_yearEnding") public void test_date_int_int_int_inLastWeekOf(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) @@ -203,7 +201,7 @@ public void test_date_int_int_int_inLastWeekOf(DayOfWeek dayOfWeek, Month ending } } - @Test + @ParameterizedTest @UseDataProvider("data_yearEnding") public void test_date_int_int_int_nearestEndOf(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) @@ -269,7 +267,7 @@ public static Object[][] data_range() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_range") public void test_range(AccountingYearDivision division, int leapWeekInMonth, ValueRange expectedWeekOfMonthRange, ValueRange expectedDayOfMonthRange, ValueRange expectedMonthRange, ValueRange expectedProlepticMonthRange) { @@ -284,7 +282,7 @@ public void test_range(AccountingYearDivision division, int leapWeekInMonth, assertEquals(expectedProlepticMonthRange, chronology.range(ChronoField.PROLEPTIC_MONTH)); } - @Test + @ParameterizedTest @UseDataProvider("data_weeksInMonth") public void test_date_dayOfMonth_range(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST) @@ -299,7 +297,7 @@ public void test_date_dayOfMonth_range(AccountingYearDivision division, int[] we } } - @Test + @ParameterizedTest @UseDataProvider("data_yearEnding") public void test_date_dayOfYear_inLastWeekOf_range(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) @@ -320,7 +318,7 @@ public void test_date_dayOfYear_inLastWeekOf_range(DayOfWeek dayOfWeek, Month en } } - @Test + @ParameterizedTest @UseDataProvider("data_yearEnding") public void test_date_dayOfYear_nearestEndOf_range(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) @@ -373,7 +371,7 @@ public static Object[][] data_weeksInMonth() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_weeksInMonth") public void test_getWeeksInMonth(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST) @@ -386,7 +384,7 @@ public void test_getWeeksInMonth(AccountingYearDivision division, int[] weeksInM } } - @Test + @ParameterizedTest @UseDataProvider("data_weeksInMonth") public void test_getWeeksAtStartOf(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST) @@ -399,7 +397,7 @@ public void test_getWeeksAtStartOf(AccountingYearDivision division, int[] weeksI } } - @Test + @ParameterizedTest @UseDataProvider("data_weeksInMonth") public void test_getMonthFromElapsedWeeks(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST) @@ -417,33 +415,35 @@ public void test_getMonthFromElapsedWeeks(AccountingYearDivision division, int[] } } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_weeksInMonth") public void test_negativeWeeks_getMonthFromElapsedWeekspublic(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { assertEquals(1, division.getMonthFromElapsedWeeks(0)); - division.getMonthFromElapsedWeeks(-1); + assertThrows(DateTimeException.class, () -> division.getMonthFromElapsedWeeks(-1)); } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_weeksInMonth") public void test_extraWeeks_getMonthFromElapsedWeekspublic(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { int elapsedWeeks = 0; for (int month = 1; month <= weeksInMonth.length; month++) { elapsedWeeks += weeksInMonth[month - 1]; } - assertEquals(weeksInMonth.length, division.getMonthFromElapsedWeeks(elapsedWeeks)); - division.getMonthFromElapsedWeeks(elapsedWeeks + 1); + int finalElapsedWeeks = elapsedWeeks; + assertThrows(DateTimeException.class, () -> division.getMonthFromElapsedWeeks(finalElapsedWeeks)); + assertThrows(DateTimeException.class, () -> division.getMonthFromElapsedWeeks(finalElapsedWeeks + 1)); } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_weeksInMonth") public void test_extraWeeksLeap_getMonthFromElapsedWeekspublic(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { int elapsedWeeks = 1; for (int month = 1; month <= weeksInMonth.length; month++) { elapsedWeeks += weeksInMonth[month - 1]; } - assertEquals(weeksInMonth.length, division.getMonthFromElapsedWeeks(elapsedWeeks, leapWeekInMonth)); - division.getMonthFromElapsedWeeks(elapsedWeeks + 1, leapWeekInMonth); + int finalElapsedWeeks = elapsedWeeks; + assertThrows(DateTimeException.class, () -> division.getMonthFromElapsedWeeks(finalElapsedWeeks, leapWeekInMonth)); + assertThrows(DateTimeException.class, () -> division.getMonthFromElapsedWeeks(finalElapsedWeeks + 1, leapWeekInMonth)); } //----------------------------------------------------------------------- @@ -465,20 +465,20 @@ public static Object[][] data_badChronology() { }; } - @Test(expected = IllegalStateException.class) + @ParameterizedTest @UseDataProvider("data_badChronology") public void test_badChronology_nearestEndOf(DayOfWeek dayOfWeek, Month ending, AccountingYearDivision division, int leapWeekInMonth) { - new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) + assertThrows(IllegalStateException.class, () -> new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) .withDivision(division).leapWeekInMonth(leapWeekInMonth) - .toChronology(); + .toChronology()); } - @Test(expected = IllegalStateException.class) + @ParameterizedTest @UseDataProvider("data_badChronology") public void test_badChronology_inLastWeekOf(DayOfWeek dayOfWeek, Month ending, AccountingYearDivision division, int leapWeekInMonth) { - new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) + assertThrows(IllegalStateException.class, () -> new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) .withDivision(division).leapWeekInMonth(leapWeekInMonth) - .toChronology(); + .toChronology()); } } diff --git a/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java b/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java index 3e19aab4..4adc951b 100644 --- a/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java @@ -53,9 +53,11 @@ import static java.time.temporal.ChronoUnit.MONTHS; import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.DateTimeException; import java.time.Instant; @@ -83,18 +85,15 @@ import java.util.List; import java.util.TimeZone; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test. */ -@RunWith(DataProviderRunner.class) public class TestBritishCutoverChronology { //----------------------------------------------------------------------- @@ -103,10 +102,10 @@ public class TestBritishCutoverChronology { @Test public void test_chronology_of_name() { Chronology chrono = Chronology.of("BritishCutover"); - Assert.assertNotNull(chrono); - Assert.assertEquals(BritishCutoverChronology.INSTANCE, chrono); - Assert.assertEquals("BritishCutover", chrono.getId()); - Assert.assertEquals(null, chrono.getCalendarType()); + assertNotNull(chrono); + assertEquals(BritishCutoverChronology.INSTANCE, chrono); + assertEquals("BritishCutover", chrono.getId()); + assertEquals(null, chrono.getCalendarType()); } //----------------------------------------------------------------------- @@ -157,55 +156,55 @@ public static Object[][] data_samples() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_LocalDate_from_BritishCutoverDate(BritishCutoverDate cutover, LocalDate iso) { assertEquals(iso, LocalDate.from(cutover)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_BritishCutoverDate_from_LocalDate(BritishCutoverDate cutover, LocalDate iso) { assertEquals(cutover, BritishCutoverDate.from(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_BritishCutoverDate_chronology_dateEpochDay(BritishCutoverDate cutover, LocalDate iso) { assertEquals(cutover, BritishCutoverChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_BritishCutoverDate_toEpochDay(BritishCutoverDate cutover, LocalDate iso) { assertEquals(iso.toEpochDay(), cutover.toEpochDay()); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_BritishCutoverDate_until_BritishCutoverDate(BritishCutoverDate cutover, LocalDate iso) { assertEquals(BritishCutoverChronology.INSTANCE.period(0, 0, 0), cutover.until(cutover)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_BritishCutoverDate_until_LocalDate(BritishCutoverDate cutover, LocalDate iso) { assertEquals(BritishCutoverChronology.INSTANCE.period(0, 0, 0), cutover.until(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_LocalDate_until_BritishCutoverDate(BritishCutoverDate cutover, LocalDate iso) { assertEquals(Period.ZERO, iso.until(cutover)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(BritishCutoverDate cutover, LocalDate iso) { assertEquals(cutover, BritishCutoverChronology.INSTANCE.date(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_plusDays(BritishCutoverDate cutover, LocalDate iso) { assertEquals(iso, LocalDate.from(cutover.plus(0, DAYS))); @@ -215,7 +214,7 @@ public void test_plusDays(BritishCutoverDate cutover, LocalDate iso) { assertEquals(iso.plusDays(-60), LocalDate.from(cutover.plus(-60, DAYS))); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_minusDays(BritishCutoverDate cutover, LocalDate iso) { assertEquals(iso, LocalDate.from(cutover.minus(0, DAYS))); @@ -225,7 +224,7 @@ public void test_minusDays(BritishCutoverDate cutover, LocalDate iso) { assertEquals(iso.minusDays(-60), LocalDate.from(cutover.minus(-60, DAYS))); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_until_DAYS(BritishCutoverDate cutover, LocalDate iso) { assertEquals(0, cutover.until(iso.plusDays(0), DAYS)); @@ -277,15 +276,15 @@ public static Object[][] data_badDates() { }; } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_badDates") public void test_badDates(int year, int month, int dom) { - BritishCutoverDate.of(year, month, dom); + assertThrows(DateTimeException.class, () -> BritishCutoverDate.of(year, month, dom)); } - @Test(expected = DateTimeException.class) + @Test public void test_Chronology_dateYearDay_badDate() { - BritishCutoverChronology.INSTANCE.dateYearDay(2001, 366); + assertThrows(DateTimeException.class, () -> BritishCutoverChronology.INSTANCE.dateYearDay(2001, 366)); } //----------------------------------------------------------------------- @@ -399,7 +398,7 @@ public static Object[][] data_lengthOfMonth() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(length, BritishCutoverDate.of(year, month, 1).lengthOfMonth()); @@ -440,13 +439,13 @@ public static Object[][] data_lengthOfYear() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_lengthOfYear") public void test_lengthOfYear_atStart(int year, int length) { assertEquals(length, BritishCutoverDate.of(year, 1, 1).lengthOfYear()); } - @Test + @ParameterizedTest @UseDataProvider("data_lengthOfYear") public void test_lengthOfYear_atEnd(int year, int length) { assertEquals(length, BritishCutoverDate.of(year, 12, 31).lengthOfYear()); @@ -507,9 +506,9 @@ public void test_prolepticYear_specific() { assertEquals(-3, BritishCutoverChronology.INSTANCE.prolepticYear(JulianEra.BC, 4)); } - @Test(expected = ClassCastException.class) + @Test public void test_prolepticYear_badEra() { - BritishCutoverChronology.INSTANCE.prolepticYear(IsoEra.CE, 4); + assertThrows(ClassCastException.class, () -> BritishCutoverChronology.INSTANCE.prolepticYear(IsoEra.CE, 4)); } @Test @@ -518,9 +517,9 @@ public void test_Chronology_eraOf() { assertEquals(JulianEra.BC, BritishCutoverChronology.INSTANCE.eraOf(0)); } - @Test(expected = DateTimeException.class) + @Test public void test_Chronology_eraOf_invalid() { - BritishCutoverChronology.INSTANCE.eraOf(2); + assertThrows(DateTimeException.class, () -> BritishCutoverChronology.INSTANCE.eraOf(2)); } @Test @@ -633,15 +632,15 @@ public static Object[][] data_ranges() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(ValueRange.of(expectedMin, expectedMax), BritishCutoverDate.of(year, month, dom).range(field)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_range_unsupported() { - BritishCutoverDate.of(2012, 6, 30).range(MINUTE_OF_DAY); + assertThrows(UnsupportedTemporalTypeException.class, () -> BritishCutoverDate.of(2012, 6, 30).range(MINUTE_OF_DAY)); } //----------------------------------------------------------------------- @@ -695,15 +694,15 @@ public static Object[][] data_getLong() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(expected, BritishCutoverDate.of(year, month, dom).getLong(field)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_getLong_unsupported() { - BritishCutoverDate.of(2012, 6, 30).getLong(MINUTE_OF_DAY); + assertThrows(UnsupportedTemporalTypeException.class, () -> BritishCutoverDate.of(2012, 6, 30).getLong(MINUTE_OF_DAY)); } //----------------------------------------------------------------------- @@ -807,7 +806,7 @@ public static Object[][] data_with() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, @@ -815,9 +814,9 @@ public void test_with_TemporalField(int year, int month, int dom, assertEquals(BritishCutoverDate.of(expectedYear, expectedMonth, expectedDom), BritishCutoverDate.of(year, month, dom).with(field, value)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_with_TemporalField_unsupported() { - BritishCutoverDate.of(2012, 6, 30).with(MINUTE_OF_DAY, 0); + assertThrows(UnsupportedTemporalTypeException.class, () -> BritishCutoverDate.of(2012, 6, 30).with(MINUTE_OF_DAY, 0)); } //----------------------------------------------------------------------- @@ -835,7 +834,7 @@ public static Object[][] data_lastDayOfMonth() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_lastDayOfMonth") public void test_adjust_lastDayOfMonth(BritishCutoverDate input, BritishCutoverDate expected) { BritishCutoverDate test = input.with(TemporalAdjusters.lastDayOfMonth()); @@ -856,17 +855,17 @@ public static Object[][] data_withLocalDate() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_withLocalDate") public void test_adjust_LocalDate(BritishCutoverDate input, LocalDate local, BritishCutoverDate expected) { BritishCutoverDate test = input.with(local); assertEquals(expected, test); } - @Test(expected = DateTimeException.class) + @Test public void test_adjust_toMonth() { BritishCutoverDate cutover = BritishCutoverDate.of(2000, 1, 4); - cutover.with(Month.APRIL); + assertThrows(DateTimeException.class, () -> cutover.with(Month.APRIL)); } //----------------------------------------------------------------------- @@ -941,7 +940,7 @@ public static Object[][] data_plus() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, @@ -949,7 +948,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, assertEquals(BritishCutoverDate.of(expectedYear, expectedMonth, expectedDom), BritishCutoverDate.of(year, month, dom).plus(amount, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, @@ -960,9 +959,9 @@ public void test_minus_TemporalUnit( } } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_plus_TemporalUnit_unsupported() { - BritishCutoverDate.of(2012, 6, 30).plus(0, MINUTES); + assertThrows(UnsupportedTemporalTypeException.class, () -> BritishCutoverDate.of(2012, 6, 30).plus(0, MINUTES)); } //----------------------------------------------------------------------- @@ -1021,7 +1020,7 @@ public static Object[][] data_until() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, @@ -1032,11 +1031,11 @@ public void test_until_TemporalUnit( assertEquals(expected, start.until(end, unit)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_until_TemporalUnit_unsupported() { BritishCutoverDate start = BritishCutoverDate.of(2012, 6, 30); BritishCutoverDate end = BritishCutoverDate.of(2012, 7, 1); - start.until(end, MINUTES); + assertThrows(UnsupportedTemporalTypeException.class, () -> start.until(end, MINUTES)); } //----------------------------------------------------------------------- @@ -1053,11 +1052,9 @@ public void test_plus_Period() { BritishCutoverDate.of(2014, 5, 26).plus(BritishCutoverChronology.INSTANCE.period(0, 2, 3))); } - @Test(expected = DateTimeException.class) + @Test public void test_plus_Period_ISO() { - assertEquals( - BritishCutoverDate.of(2014, 7, 26), - BritishCutoverDate.of(2014, 5, 26).plus(Period.ofMonths(2))); + assertThrows(DateTimeException.class, () -> BritishCutoverDate.of(2014, 5, 26).plus(Period.ofMonths(2))); } @Test @@ -1070,11 +1067,9 @@ public void test_minus_Period() { BritishCutoverDate.of(2014, 5, 26).minus(BritishCutoverChronology.INSTANCE.period(0, 2, 3))); } - @Test(expected = DateTimeException.class) + @Test public void test_minus_Period_ISO() { - assertEquals( - BritishCutoverDate.of(2014, 3, 26), - BritishCutoverDate.of(2014, 5, 26).minus(Period.ofMonths(2))); + assertThrows(DateTimeException.class, () -> BritishCutoverDate.of(2014, 5, 26).minus(Period.ofMonths(2))); } //----------------------------------------------------------------------- @@ -1224,7 +1219,7 @@ public static Object[][] data_untilCLD() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_untilCLD") public void test_until_CLD( int year1, int month1, int dom1, @@ -1238,7 +1233,7 @@ public void test_until_CLD( c); } - @Test + @ParameterizedTest @UseDataProvider("data_untilCLD") public void test_until_CLD_plus( int year1, int month1, int dom1, @@ -1264,9 +1259,9 @@ public void test_atTime() { assertEquals(test, test2); } - @Test(expected = NullPointerException.class) + @Test public void test_atTime_null() { - BritishCutoverDate.of(2014, 5, 26).atTime(null); + assertThrows(NullPointerException.class, () -> BritishCutoverDate.of(2014, 5, 26).atTime(null)); } //----------------------------------------------------------------------- @@ -1325,7 +1320,7 @@ public static Object[][] data_toString() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_toString") public void test_toString(BritishCutoverDate cutover, String expected) { assertEquals(expected, cutover.toString()); diff --git a/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java b/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java index 265cdde8..00fa1d04 100644 --- a/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java @@ -53,9 +53,11 @@ import static java.time.temporal.ChronoUnit.MONTHS; import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; @@ -72,18 +74,15 @@ import java.time.temporal.WeekFields; import java.util.List; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test. */ -@RunWith(DataProviderRunner.class) public class TestCopticChronology { //----------------------------------------------------------------------- @@ -92,19 +91,19 @@ public class TestCopticChronology { @Test public void test_chronology_of_name() { Chronology chrono = Chronology.of("Coptic"); - Assert.assertNotNull(chrono); - Assert.assertEquals(CopticChronology.INSTANCE, chrono); - Assert.assertEquals("Coptic", chrono.getId()); - Assert.assertEquals("coptic", chrono.getCalendarType()); + assertNotNull(chrono); + assertEquals(CopticChronology.INSTANCE, chrono); + assertEquals("Coptic", chrono.getId()); + assertEquals("coptic", chrono.getCalendarType()); } @Test public void test_chronology_of_name_id() { Chronology chrono = Chronology.of("coptic"); - Assert.assertNotNull(chrono); - Assert.assertEquals(CopticChronology.INSTANCE, chrono); - Assert.assertEquals("Coptic", chrono.getId()); - Assert.assertEquals("coptic", chrono.getCalendarType()); + assertNotNull(chrono); + assertEquals(CopticChronology.INSTANCE, chrono); + assertEquals("Coptic", chrono.getId()); + assertEquals("coptic", chrono.getCalendarType()); } //----------------------------------------------------------------------- @@ -138,55 +137,55 @@ public static Object[][] data_samples() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_LocalDate_from_CopticDate(CopticDate coptic, LocalDate iso) { assertEquals(iso, LocalDate.from(coptic)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_CopticDate_from_LocalDate(CopticDate coptic, LocalDate iso) { assertEquals(coptic, CopticDate.from(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_CopticDate_chronology_dateEpochDay(CopticDate coptic, LocalDate iso) { assertEquals(coptic, CopticChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_CopticDate_toEpochDay(CopticDate coptic, LocalDate iso) { assertEquals(iso.toEpochDay(), coptic.toEpochDay()); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_CopticDate_until_CopticDate(CopticDate coptic, LocalDate iso) { assertEquals(CopticChronology.INSTANCE.period(0, 0, 0), coptic.until(coptic)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_CopticDate_until_LocalDate(CopticDate coptic, LocalDate iso) { assertEquals(CopticChronology.INSTANCE.period(0, 0, 0), coptic.until(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_LocalDate_until_CopticDate(CopticDate coptic, LocalDate iso) { assertEquals(Period.ZERO, iso.until(coptic)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(CopticDate coptic, LocalDate iso) { assertEquals(coptic, CopticChronology.INSTANCE.date(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_plusDays(CopticDate coptic, LocalDate iso) { assertEquals(iso, LocalDate.from(coptic.plus(0, DAYS))); @@ -196,7 +195,7 @@ public void test_plusDays(CopticDate coptic, LocalDate iso) { assertEquals(iso.plusDays(-60), LocalDate.from(coptic.plus(-60, DAYS))); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_minusDays(CopticDate coptic, LocalDate iso) { assertEquals(iso, LocalDate.from(coptic.minus(0, DAYS))); @@ -206,7 +205,7 @@ public void test_minusDays(CopticDate coptic, LocalDate iso) { assertEquals(iso.minusDays(-60), LocalDate.from(coptic.minus(-60, DAYS))); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_until_DAYS(CopticDate coptic, LocalDate iso) { assertEquals(0, coptic.until(iso.plusDays(0), DAYS)); @@ -247,15 +246,15 @@ public static Object[][] data_badDates() { }; } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_badDates") public void test_badDates(int year, int month, int dom) { - CopticDate.of(year, month, dom); + assertThrows(DateTimeException.class, () -> CopticDate.of(year, month, dom)); } - @Test(expected = DateTimeException.class) + @Test public void test_chronology_dateYearDay_badDate() { - CopticChronology.INSTANCE.dateYearDay(1728, 366); + assertThrows(DateTimeException.class, () -> CopticChronology.INSTANCE.dateYearDay(1728, 366)); } //----------------------------------------------------------------------- @@ -309,7 +308,7 @@ public static Object[][] data_lengthOfMonth() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(length, CopticDate.of(year, month, 1).lengthOfMonth()); @@ -364,9 +363,9 @@ public void test_Chronology_eraOf() { assertEquals(CopticEra.BEFORE_AM, CopticChronology.INSTANCE.eraOf(0)); } - @Test(expected = DateTimeException.class) + @Test public void test_Chronology_eraOf_invalid() { - CopticChronology.INSTANCE.eraOf(2); + assertThrows(DateTimeException.class, () -> CopticChronology.INSTANCE.eraOf(2)); } @Test @@ -420,15 +419,15 @@ public static Object[][] data_ranges() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(ValueRange.of(expectedMin, expectedMax), CopticDate.of(year, month, dom).range(field)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_range_unsupported() { - CopticDate.of(1727, 6, 30).range(MINUTE_OF_DAY); + assertThrows(UnsupportedTemporalTypeException.class, () -> CopticDate.of(1727, 6, 30).range(MINUTE_OF_DAY)); } //----------------------------------------------------------------------- @@ -455,15 +454,15 @@ public static Object[][] data_getLong() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(expected, CopticDate.of(year, month, dom).getLong(field)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_getLong_unsupported() { - CopticDate.of(1727, 6, 30).getLong(MINUTE_OF_DAY); + assertThrows(UnsupportedTemporalTypeException.class, () -> CopticDate.of(1727, 6, 30).getLong(MINUTE_OF_DAY)); } //----------------------------------------------------------------------- @@ -505,7 +504,7 @@ public static Object[][] data_with() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, @@ -513,9 +512,9 @@ public void test_with_TemporalField(int year, int month, int dom, assertEquals(CopticDate.of(expectedYear, expectedMonth, expectedDom), CopticDate.of(year, month, dom).with(field, value)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_with_TemporalField_unsupported() { - CopticDate.of(1727, 6, 30).with(MINUTE_OF_DAY, 0); + assertThrows(UnsupportedTemporalTypeException.class, () -> CopticDate.of(1727, 6, 30).with(MINUTE_OF_DAY, 0)); } //----------------------------------------------------------------------- @@ -545,10 +544,10 @@ public void test_adjust_toLocalDate() { assertEquals(CopticDate.of(1728, 10, 29), test); } - @Test(expected = DateTimeException.class) + @Test public void test_adjust_toMonth() { CopticDate coptic = CopticDate.of(1726, 1, 4); - coptic.with(Month.APRIL); + assertThrows(DateTimeException.class, () -> coptic.with(Month.APRIL)); } //----------------------------------------------------------------------- @@ -599,7 +598,7 @@ public static Object[][] data_plus() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, @@ -607,7 +606,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, assertEquals(CopticDate.of(expectedYear, expectedMonth, expectedDom), CopticDate.of(year, month, dom).plus(amount, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, @@ -616,9 +615,9 @@ public void test_minus_TemporalUnit( assertEquals(CopticDate.of(expectedYear, expectedMonth, expectedDom), CopticDate.of(year, month, dom).minus(amount, unit)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_plus_TemporalUnit_unsupported() { - CopticDate.of(1727, 6, 30).plus(0, MINUTES); + assertThrows(UnsupportedTemporalTypeException.class, () -> CopticDate.of(1727, 6, 30).plus(0, MINUTES)); } //----------------------------------------------------------------------- @@ -627,9 +626,9 @@ public void test_plus_Period() { assertEquals(CopticDate.of(1727, 7, 29), CopticDate.of(1727, 5, 26).plus(CopticChronology.INSTANCE.period(0, 2, 3))); } - @Test(expected = DateTimeException.class) + @Test public void test_plus_Period_ISO() { - assertEquals(CopticDate.of(1727, 7, 26), CopticDate.of(1727, 5, 26).plus(Period.ofMonths(2))); + assertThrows(DateTimeException.class, () -> CopticDate.of(1727, 5, 26).plus(Period.ofMonths(2))); } @Test @@ -637,9 +636,9 @@ public void test_minus_Period() { assertEquals(CopticDate.of(1727, 3, 23), CopticDate.of(1727, 5, 26).minus(CopticChronology.INSTANCE.period(0, 2, 3))); } - @Test(expected = DateTimeException.class) + @Test public void test_minus_Period_ISO() { - assertEquals(CopticDate.of(1727, 3, 26), CopticDate.of(1727, 5, 26).minus(Period.ofMonths(2))); + assertThrows(DateTimeException.class, () -> CopticDate.of(1727, 5, 26).minus(Period.ofMonths(2))); } //----------------------------------------------------------------------- @@ -672,7 +671,7 @@ public static Object[][] data_until() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, @@ -683,11 +682,11 @@ public void test_until_TemporalUnit( assertEquals(expected, start.until(end, unit)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_until_TemporalUnit_unsupported() { CopticDate start = CopticDate.of(1726, 6, 30); CopticDate end = CopticDate.of(1726, 7, 1); - start.until(end, MINUTES); + assertThrows(UnsupportedTemporalTypeException.class, () -> start.until(end, MINUTES)); } //----------------------------------------------------------------------- @@ -727,7 +726,7 @@ public static Object[][] data_toString() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_toString") public void test_toString(CopticDate coptic, String expected) { assertEquals(expected, coptic.toString()); diff --git a/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java b/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java index 1103c75e..5795e4c4 100644 --- a/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java @@ -54,9 +54,11 @@ import static java.time.temporal.ChronoUnit.MONTHS; import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; @@ -75,18 +77,15 @@ import java.util.List; import java.util.function.IntPredicate; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test. */ -@RunWith(DataProviderRunner.class) public class TestDiscordianChronology { //----------------------------------------------------------------------- @@ -95,19 +94,19 @@ public class TestDiscordianChronology { @Test public void test_chronology_of_name() { Chronology chrono = Chronology.of("Discordian"); - Assert.assertNotNull(chrono); - Assert.assertEquals(DiscordianChronology.INSTANCE, chrono); - Assert.assertEquals("Discordian", chrono.getId()); - Assert.assertEquals("discordian", chrono.getCalendarType()); + assertNotNull(chrono); + assertEquals(DiscordianChronology.INSTANCE, chrono); + assertEquals("Discordian", chrono.getId()); + assertEquals("discordian", chrono.getCalendarType()); } @Test public void test_chronology_of_name_id() { Chronology chrono = Chronology.of("discordian"); - Assert.assertNotNull(chrono); - Assert.assertEquals(DiscordianChronology.INSTANCE, chrono); - Assert.assertEquals("Discordian", chrono.getId()); - Assert.assertEquals("discordian", chrono.getCalendarType()); + assertNotNull(chrono); + assertEquals(DiscordianChronology.INSTANCE, chrono); + assertEquals("Discordian", chrono.getId()); + assertEquals("discordian", chrono.getCalendarType()); } //----------------------------------------------------------------------- @@ -154,55 +153,55 @@ public static Object[][] data_samples() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_LocalDate_from_DiscordianDate(DiscordianDate discordian, LocalDate iso) { assertEquals(iso, LocalDate.from(discordian)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_DiscordianDate_from_LocalDate(DiscordianDate discordian, LocalDate iso) { assertEquals(discordian, DiscordianDate.from(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_DiscordianDate_chronology_dateEpochDay(DiscordianDate discordian, LocalDate iso) { assertEquals(discordian, DiscordianChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_DiscordianDate_toEpochDay(DiscordianDate discordian, LocalDate iso) { assertEquals(iso.toEpochDay(), discordian.toEpochDay()); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_DiscordianDate_until_DiscordianDate(DiscordianDate discordian, LocalDate iso) { assertEquals(DiscordianChronology.INSTANCE.period(0, 0, 0), discordian.until(discordian)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_DiscordianDate_until_LocalDate(DiscordianDate discordian, LocalDate iso) { assertEquals(DiscordianChronology.INSTANCE.period(0, 0, 0), discordian.until(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_LocalDate_until_DiscordianDate(DiscordianDate discordian, LocalDate iso) { assertEquals(Period.ZERO, iso.until(discordian)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(DiscordianDate discordian, LocalDate iso) { assertEquals(discordian, DiscordianChronology.INSTANCE.date(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_plusDays(DiscordianDate discordian, LocalDate iso) { assertEquals(iso, LocalDate.from(discordian.plus(0, DAYS))); @@ -212,7 +211,7 @@ public void test_plusDays(DiscordianDate discordian, LocalDate iso) { assertEquals(iso.plusDays(-60), LocalDate.from(discordian.plus(-60, DAYS))); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_minusDays(DiscordianDate discordian, LocalDate iso) { assertEquals(iso, LocalDate.from(discordian.minus(0, DAYS))); @@ -222,7 +221,7 @@ public void test_minusDays(DiscordianDate discordian, LocalDate iso) { assertEquals(iso.minusDays(-60), LocalDate.from(discordian.minus(-60, DAYS))); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_until_DAYS(DiscordianDate discordian, LocalDate iso) { assertEquals(0, discordian.until(iso.plusDays(0), DAYS)); @@ -257,15 +256,15 @@ public static Object[][] data_badDates() { }; } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_badDates") public void test_badDates(int year, int month, int dom) { - DiscordianDate.of(year, month, dom); + assertThrows(DateTimeException.class, () -> DiscordianDate.of(year, month, dom)); } - @Test(expected = DateTimeException.class) + @Test public void test_chronology_dateYearDay_badDate() { - DiscordianChronology.INSTANCE.dateYearDay(2001, 366); + assertThrows(DateTimeException.class, () -> DiscordianChronology.INSTANCE.dateYearDay(2001, 366)); } //----------------------------------------------------------------------- @@ -321,7 +320,7 @@ public static Object[][] data_lengthOfMonth() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(length, DiscordianDate.of(year, month, 1).lengthOfMonth()); @@ -369,9 +368,9 @@ public void test_prolepticYear_specific() { assertEquals(1, DiscordianChronology.INSTANCE.prolepticYear(DiscordianEra.YOLD, 1)); } - @Test(expected = ClassCastException.class) + @Test public void test_prolepticYear_badEra() { - DiscordianChronology.INSTANCE.prolepticYear(IsoEra.CE, 4); + assertThrows(ClassCastException.class, () -> DiscordianChronology.INSTANCE.prolepticYear(IsoEra.CE, 4)); } @Test @@ -379,10 +378,10 @@ public void test_Chronology_eraOf() { assertEquals(DiscordianEra.YOLD, DiscordianChronology.INSTANCE.eraOf(1)); } - @Test(expected = DateTimeException.class) + @Test public void test_Chronology_eraOf_invalid() { - DiscordianChronology.INSTANCE.eraOf(2); - DiscordianChronology.INSTANCE.eraOf(0); + assertThrows(DateTimeException.class, () -> DiscordianChronology.INSTANCE.eraOf(2)); + assertThrows(DateTimeException.class, () -> DiscordianChronology.INSTANCE.eraOf(0)); } @Test @@ -457,15 +456,15 @@ public static Object[][] data_ranges() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(ValueRange.of(expectedMin, expectedMax), DiscordianDate.of(year, month, dom).range(field)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_range_unsupported() { - DiscordianDate.of(2012, 5, 30).range(MINUTE_OF_DAY); + assertThrows(UnsupportedTemporalTypeException.class, () -> DiscordianDate.of(2012, 5, 30).range(MINUTE_OF_DAY)); } //----------------------------------------------------------------------- @@ -511,15 +510,15 @@ public static Object[][] data_getLong() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(expected, DiscordianDate.of(year, month, dom).getLong(field)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_getLong_unsupported() { - DiscordianDate.of(2012, 1, 30).getLong(MINUTE_OF_DAY); + assertThrows(UnsupportedTemporalTypeException.class, () -> DiscordianDate.of(2012, 1, 30).getLong(MINUTE_OF_DAY)); } //----------------------------------------------------------------------- @@ -600,7 +599,7 @@ public static Object[][] data_with() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, @@ -633,15 +632,15 @@ public static Object[][] data_with_bad() { }; } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_with_bad") public void test_with_TemporalField_badValue(int year, int month, int dom, TemporalField field, long value) { - DiscordianDate.of(year, month, dom).with(field, value); + assertThrows(DateTimeException.class, () -> DiscordianDate.of(year, month, dom).with(field, value)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_with_TemporalField_unsupported() { - DiscordianDate.of(2012, 5, 30).with(MINUTE_OF_DAY, 0); + assertThrows(UnsupportedTemporalTypeException.class, () -> DiscordianDate.of(2012, 5, 30).with(MINUTE_OF_DAY, 0)); } //----------------------------------------------------------------------- @@ -671,10 +670,10 @@ public void test_adjust_toLocalDate() { assertEquals(DiscordianDate.of(3178, 3, 41), test); } - @Test(expected = DateTimeException.class) + @Test public void test_adjust_toMonth() { DiscordianDate discordian = DiscordianDate.of(2000, 1, 4); - discordian.with(Month.APRIL); + assertThrows(DateTimeException.class, () -> discordian.with(Month.APRIL)); } //----------------------------------------------------------------------- @@ -766,7 +765,7 @@ public static Object[][] data_minus_leap() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, @@ -774,7 +773,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, assertEquals(DiscordianDate.of(expectedYear, expectedMonth, expectedDom), DiscordianDate.of(year, month, dom).plus(amount, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_plus_leap") public void test_plus_leap_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, @@ -782,7 +781,7 @@ public void test_plus_leap_TemporalUnit(int year, int month, int dom, assertEquals(DiscordianDate.of(expectedYear, expectedMonth, expectedDom), DiscordianDate.of(year, month, dom).plus(amount, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, @@ -791,7 +790,7 @@ public void test_minus_TemporalUnit( assertEquals(DiscordianDate.of(expectedYear, expectedMonth, expectedDom), DiscordianDate.of(year, month, dom).minus(amount, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_minus_leap") public void test_minus_leap_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, @@ -800,9 +799,9 @@ public void test_minus_leap_TemporalUnit( assertEquals(DiscordianDate.of(expectedYear, expectedMonth, expectedDom), DiscordianDate.of(year, month, dom).minus(amount, unit)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_plus_TemporalUnit_unsupported() { - DiscordianDate.of(2012, 5, 30).plus(0, MINUTES); + assertThrows(UnsupportedTemporalTypeException.class, () -> DiscordianDate.of(2012, 5, 30).plus(0, MINUTES)); } //----------------------------------------------------------------------- @@ -920,7 +919,7 @@ public static Object[][] data_until_period() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, @@ -931,7 +930,7 @@ public void test_until_TemporalUnit( assertEquals(expected, start.until(end, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_until_period") public void test_until_end( int year1, int month1, int dom1, @@ -943,11 +942,11 @@ public void test_until_end( assertEquals(period, start.until(end)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_until_TemporalUnit_unsupported() { DiscordianDate start = DiscordianDate.of(2012, 1, 30); DiscordianDate end = DiscordianDate.of(2012, 2, 1); - start.until(end, MINUTES); + assertThrows(UnsupportedTemporalTypeException.class, () -> start.until(end, MINUTES)); } //----------------------------------------------------------------------- @@ -956,9 +955,9 @@ public void test_plus_Period() { assertEquals(DiscordianDate.of(2015, 2, 29), DiscordianDate.of(2014, 5, 26).plus(DiscordianChronology.INSTANCE.period(0, 2, 3))); } - @Test(expected = DateTimeException.class) + @Test public void test_plus_Period_ISO() { - assertEquals(DiscordianDate.of(2015, 2, 26), DiscordianDate.of(2014, 5, 26).plus(Period.ofMonths(2))); + assertThrows(DateTimeException.class, () -> DiscordianDate.of(2014, 5, 26).plus(Period.ofMonths(2))); } @Test @@ -966,9 +965,9 @@ public void test_minus_Period() { assertEquals(DiscordianDate.of(2014, 3, 23), DiscordianDate.of(2014, 5, 26).minus(DiscordianChronology.INSTANCE.period(0, 2, 3))); } - @Test(expected = DateTimeException.class) + @Test public void test_minus_Period_ISO() { - assertEquals(DiscordianDate.of(2014, 3, 26), DiscordianDate.of(2014, 5, 26).minus(Period.ofMonths(2))); + assertThrows(DateTimeException.class, () -> DiscordianDate.of(2014, 5, 26).minus(Period.ofMonths(2))); } //----------------------------------------------------------------------- @@ -1006,7 +1005,7 @@ public static Object[][] data_toString() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_toString") public void test_toString(DiscordianDate discordian, String expected) { assertEquals(expected, discordian.toString()); diff --git a/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java b/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java index 067e537a..34ff8893 100644 --- a/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java @@ -53,9 +53,11 @@ import static java.time.temporal.ChronoUnit.MONTHS; import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; @@ -72,18 +74,15 @@ import java.time.temporal.WeekFields; import java.util.List; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test. */ -@RunWith(DataProviderRunner.class) public class TestEthiopicChronology { //----------------------------------------------------------------------- @@ -92,19 +91,19 @@ public class TestEthiopicChronology { @Test public void test_chronology_of_name() { Chronology chrono = Chronology.of("Ethiopic"); - Assert.assertNotNull(chrono); - Assert.assertEquals(EthiopicChronology.INSTANCE, chrono); - Assert.assertEquals("Ethiopic", chrono.getId()); - Assert.assertEquals("ethiopic", chrono.getCalendarType()); + assertNotNull(chrono); + assertEquals(EthiopicChronology.INSTANCE, chrono); + assertEquals("Ethiopic", chrono.getId()); + assertEquals("ethiopic", chrono.getCalendarType()); } @Test public void test_chronology_of_name_id() { Chronology chrono = Chronology.of("ethiopic"); - Assert.assertNotNull(chrono); - Assert.assertEquals(EthiopicChronology.INSTANCE, chrono); - Assert.assertEquals("Ethiopic", chrono.getId()); - Assert.assertEquals("ethiopic", chrono.getCalendarType()); + assertNotNull(chrono); + assertEquals(EthiopicChronology.INSTANCE, chrono); + assertEquals("Ethiopic", chrono.getId()); + assertEquals("ethiopic", chrono.getCalendarType()); } //----------------------------------------------------------------------- @@ -139,55 +138,55 @@ public static Object[][] data_samples() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_LocalDate_from_EthiopicDate(EthiopicDate ethiopic, LocalDate iso) { assertEquals(iso, LocalDate.from(ethiopic)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_EthiopicDate_from_LocalDate(EthiopicDate ethiopic, LocalDate iso) { assertEquals(ethiopic, EthiopicDate.from(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_EthiopicDate_chronology_dateEpochDay(EthiopicDate ethiopic, LocalDate iso) { assertEquals(ethiopic, EthiopicChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_EthiopicDate_toEpochDay(EthiopicDate ethiopic, LocalDate iso) { assertEquals(iso.toEpochDay(), ethiopic.toEpochDay()); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_EthiopicDate_until_EthiopicDate(EthiopicDate ethiopic, LocalDate iso) { assertEquals(EthiopicChronology.INSTANCE.period(0, 0, 0), ethiopic.until(ethiopic)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_EthiopicDate_until_LocalDate(EthiopicDate ethiopic, LocalDate iso) { assertEquals(EthiopicChronology.INSTANCE.period(0, 0, 0), ethiopic.until(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_LocalDate_until_EthiopicDate(EthiopicDate ethiopic, LocalDate iso) { assertEquals(Period.ZERO, iso.until(ethiopic)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(EthiopicDate ethiopic, LocalDate iso) { assertEquals(ethiopic, EthiopicChronology.INSTANCE.date(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_plusDays(EthiopicDate ethiopic, LocalDate iso) { assertEquals(iso, LocalDate.from(ethiopic.plus(0, DAYS))); @@ -197,7 +196,7 @@ public void test_plusDays(EthiopicDate ethiopic, LocalDate iso) { assertEquals(iso.plusDays(-60), LocalDate.from(ethiopic.plus(-60, DAYS))); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_minusDays(EthiopicDate ethiopic, LocalDate iso) { assertEquals(iso, LocalDate.from(ethiopic.minus(0, DAYS))); @@ -207,7 +206,7 @@ public void test_minusDays(EthiopicDate ethiopic, LocalDate iso) { assertEquals(iso.minusDays(-60), LocalDate.from(ethiopic.minus(-60, DAYS))); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_until_DAYS(EthiopicDate ethiopic, LocalDate iso) { assertEquals(0, ethiopic.until(iso.plusDays(0), DAYS)); @@ -248,15 +247,15 @@ public static Object[][] data_badDates() { }; } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_badDates") public void test_badDates(int year, int month, int dom) { - EthiopicDate.of(year, month, dom); + assertThrows(DateTimeException.class, () -> EthiopicDate.of(year, month, dom)); } - @Test(expected = DateTimeException.class) + @Test public void test_chronology_dateYearDay_badDate() { - EthiopicChronology.INSTANCE.dateYearDay(2008, 366); + assertThrows(DateTimeException.class, () -> EthiopicChronology.INSTANCE.dateYearDay(2008, 366)); } //----------------------------------------------------------------------- @@ -310,7 +309,7 @@ public static Object[][] data_lengthOfMonth() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(length, EthiopicDate.of(year, month, 1).lengthOfMonth()); @@ -365,9 +364,9 @@ public void test_Chronology_eraOf() { assertEquals(EthiopicEra.BEFORE_INCARNATION, EthiopicChronology.INSTANCE.eraOf(0)); } - @Test(expected = DateTimeException.class) + @Test public void test_Chronology_eraOf_invalid() { - EthiopicChronology.INSTANCE.eraOf(2); + assertThrows(DateTimeException.class, () -> EthiopicChronology.INSTANCE.eraOf(2)); } @Test @@ -421,15 +420,15 @@ public static Object[][] data_ranges() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(ValueRange.of(expectedMin, expectedMax), EthiopicDate.of(year, month, dom).range(field)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_range_unsupported() { - EthiopicDate.of(2007, 6, 30).range(MINUTE_OF_DAY); + assertThrows(UnsupportedTemporalTypeException.class, () -> EthiopicDate.of(2007, 6, 30).range(MINUTE_OF_DAY)); } //----------------------------------------------------------------------- @@ -456,15 +455,15 @@ public static Object[][] data_getLong() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(expected, EthiopicDate.of(year, month, dom).getLong(field)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_getLong_unsupported() { - EthiopicDate.of(2007, 6, 30).getLong(MINUTE_OF_DAY); + assertThrows(UnsupportedTemporalTypeException.class, () -> EthiopicDate.of(2007, 6, 30).getLong(MINUTE_OF_DAY)); } //----------------------------------------------------------------------- @@ -509,7 +508,7 @@ public static Object[][] data_with() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, @@ -532,15 +531,15 @@ public static Object[][] data_with_bad() { }; } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_with_bad") public void test_with_TemporalField_badValue(int year, int month, int dom, TemporalField field, long value) { - EthiopicDate.of(year, month, dom).with(field, value); + assertThrows(DateTimeException.class, () -> EthiopicDate.of(year, month, dom).with(field, value)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_with_TemporalField_unsupported() { - EthiopicDate.of(2006, 6, 30).with(MINUTE_OF_DAY, 0); + assertThrows(UnsupportedTemporalTypeException.class, () -> EthiopicDate.of(2006, 6, 30).with(MINUTE_OF_DAY, 0)); } //----------------------------------------------------------------------- @@ -570,10 +569,10 @@ public void test_adjust_toLocalDate() { assertEquals(EthiopicDate.of(2004, 2, 5), test); } - @Test(expected = DateTimeException.class) + @Test public void test_adjust_toMonth() { EthiopicDate ethiopic = EthiopicDate.of(2004, 1, 4); - ethiopic.with(Month.APRIL); + assertThrows(DateTimeException.class, () -> ethiopic.with(Month.APRIL)); } //----------------------------------------------------------------------- @@ -624,7 +623,7 @@ public static Object[][] data_plus() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, @@ -632,7 +631,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, assertEquals(EthiopicDate.of(expectedYear, expectedMonth, expectedDom), EthiopicDate.of(year, month, dom).plus(amount, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, @@ -641,9 +640,9 @@ public void test_minus_TemporalUnit( assertEquals(EthiopicDate.of(expectedYear, expectedMonth, expectedDom), EthiopicDate.of(year, month, dom).minus(amount, unit)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_plus_TemporalUnit_unsupported() { - EthiopicDate.of(2006, 6, 30).plus(0, MINUTES); + assertThrows(UnsupportedTemporalTypeException.class, () -> EthiopicDate.of(2006, 6, 30).plus(0, MINUTES)); } //----------------------------------------------------------------------- @@ -652,9 +651,9 @@ public void test_plus_Period() { assertEquals(EthiopicDate.of(2006, 7, 29), EthiopicDate.of(2006, 5, 26).plus(EthiopicChronology.INSTANCE.period(0, 2, 3))); } - @Test(expected = DateTimeException.class) + @Test public void test_plus_Period_ISO() { - assertEquals(EthiopicDate.of(2006, 7, 26), EthiopicDate.of(2006, 5, 26).plus(Period.ofMonths(2))); + assertThrows(DateTimeException.class, () -> EthiopicDate.of(2006, 5, 26).plus(Period.ofMonths(2))); } @Test @@ -662,9 +661,9 @@ public void test_minus_Period() { assertEquals(EthiopicDate.of(2006, 3, 23), EthiopicDate.of(2006, 5, 26).minus(EthiopicChronology.INSTANCE.period(0, 2, 3))); } - @Test(expected = DateTimeException.class) + @Test public void test_minus_Period_ISO() { - assertEquals(EthiopicDate.of(2006, 3, 26), EthiopicDate.of(2006, 5, 26).minus(Period.ofMonths(2))); + assertThrows(DateTimeException.class, () -> EthiopicDate.of(2006, 5, 26).minus(Period.ofMonths(2))); } //----------------------------------------------------------------------- @@ -697,7 +696,7 @@ public static Object[][] data_until() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, @@ -708,11 +707,11 @@ public void test_until_TemporalUnit( assertEquals(expected, start.until(end, unit)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_until_TemporalUnit_unsupported() { EthiopicDate start = EthiopicDate.of(2006, 6, 30); EthiopicDate end = EthiopicDate.of(2006, 7, 1); - start.until(end, MINUTES); + assertThrows(UnsupportedTemporalTypeException.class, () -> start.until(end, MINUTES)); } //----------------------------------------------------------------------- @@ -752,7 +751,7 @@ public static Object[][] data_toString() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_toString") public void test_toString(EthiopicDate ethiopic, String expected) { assertEquals(expected, ethiopic.toString()); diff --git a/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java b/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java index 4cf6aced..fc36cd3c 100644 --- a/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java @@ -54,10 +54,11 @@ import static java.time.temporal.ChronoUnit.MONTHS; import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; @@ -76,18 +77,16 @@ import java.util.List; import java.util.function.IntPredicate; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test. */ @SuppressWarnings({"static-method", "javadoc"}) -@RunWith(DataProviderRunner.class) public class TestInternationalFixedChronology { //----------------------------------------------------------------------- @@ -152,55 +151,55 @@ public static Object[][] data_samples() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_LocalDate_from_InternationalFixedDate(InternationalFixedDate fixed, LocalDate iso) { assertEquals(iso, LocalDate.from(fixed)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_InternationalFixedDate_from_LocalDate(InternationalFixedDate fixed, LocalDate iso) { assertEquals(fixed, InternationalFixedDate.from(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_InternationalFixedDate_chronology_dateEpochDay(InternationalFixedDate fixed, LocalDate iso) { assertEquals(fixed, InternationalFixedChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_InternationalFixedDate_toEpochDay(InternationalFixedDate fixed, LocalDate iso) { assertEquals(iso.toEpochDay(), fixed.toEpochDay()); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_InternationalFixedDate_until_InternationalFixedDate(InternationalFixedDate fixed, LocalDate iso) { assertEquals(InternationalFixedChronology.INSTANCE.period(0, 0, 0), fixed.until(fixed)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_InternationalFixedDate_until_LocalDate(InternationalFixedDate fixed, LocalDate iso) { assertEquals(InternationalFixedChronology.INSTANCE.period(0, 0, 0), fixed.until(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_LocalDate_until_InternationalFixedDate(InternationalFixedDate fixed, LocalDate iso) { assertEquals(Period.ZERO, iso.until(fixed)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(InternationalFixedDate fixed, LocalDate iso) { assertEquals(fixed, InternationalFixedChronology.INSTANCE.date(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_plusDays(InternationalFixedDate fixed, LocalDate iso) { assertEquals(iso, LocalDate.from(fixed.plus(0, DAYS))); @@ -212,7 +211,7 @@ public void test_plusDays(InternationalFixedDate fixed, LocalDate iso) { } } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_minusDays(InternationalFixedDate fixed, LocalDate iso) { assertEquals(iso, LocalDate.from(fixed.minus(0, DAYS))); @@ -225,7 +224,7 @@ public void test_minusDays(InternationalFixedDate fixed, LocalDate iso) { } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_until_DAYS(InternationalFixedDate fixed, LocalDate iso) { assertEquals(0, fixed.until(iso.plusDays(0), DAYS)); @@ -277,10 +276,10 @@ public static Object[][] data_badDates() { }; } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_badDates") public void test_badDates(int year, int month, int dom) { - InternationalFixedDate.of(year, month, dom); + assertThrows(DateTimeException.class, () -> InternationalFixedDate.of(year, month, dom)); } @DataProvider @@ -294,15 +293,15 @@ public static Object[][] data_badLeapDates() { }; } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_badLeapDates") public void badLeapDayDates(int year) { - InternationalFixedDate.of(year, 6, 29); + assertThrows(DateTimeException.class, () -> InternationalFixedDate.of(year, 6, 29)); } - @Test(expected = DateTimeException.class) + @Test public void test_chronology_dateYearDay_badDate() { - InternationalFixedChronology.INSTANCE.dateYearDay(2001, 366); + assertThrows(DateTimeException.class, () -> InternationalFixedChronology.INSTANCE.dateYearDay(2001, 366)); } //----------------------------------------------------------------------- @@ -355,13 +354,13 @@ public static Object[][] data_lengthOfMonth() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int day, int length) { assertEquals(length, InternationalFixedDate.of(year, month, day).lengthOfMonth()); } - @Test + @ParameterizedTest @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonthFirst(int year, int month, int day, int length) { assertEquals(length, InternationalFixedDate.of(year, month, 1).lengthOfMonth()); @@ -422,15 +421,15 @@ public static Object[][] data_prolepticYear_bad() { }; } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_prolepticYear_bad") public void test_prolepticYearBad(int year) { - InternationalFixedChronology.INSTANCE.prolepticYear(InternationalFixedEra.CE, year); + assertThrows(DateTimeException.class, () -> InternationalFixedChronology.INSTANCE.prolepticYear(InternationalFixedEra.CE, year)); } - @Test(expected = ClassCastException.class) + @Test public void test_prolepticYear_badEra() { - InternationalFixedChronology.INSTANCE.prolepticYear(IsoEra.CE, 4); + assertThrows(ClassCastException.class, () -> InternationalFixedChronology.INSTANCE.prolepticYear(IsoEra.CE, 4)); } @Test @@ -438,9 +437,9 @@ public void test_Chronology_eraOf() { assertEquals(InternationalFixedEra.CE, InternationalFixedChronology.INSTANCE.eraOf(1)); } - @Test(expected = DateTimeException.class) + @Test public void test_Chronology_eraOf_invalid() { - InternationalFixedChronology.INSTANCE.eraOf(0); + assertThrows(DateTimeException.class, () -> InternationalFixedChronology.INSTANCE.eraOf(0)); } @Test @@ -533,15 +532,15 @@ public static Object[][] data_ranges() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, ValueRange range) { assertEquals(range, InternationalFixedDate.of(year, month, dom).range(field)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_range_unsupported() { - InternationalFixedDate.of(2012, 6, 28).range(MINUTE_OF_DAY); + assertThrows(UnsupportedTemporalTypeException.class, () -> InternationalFixedDate.of(2012, 6, 28).range(MINUTE_OF_DAY)); } //----------------------------------------------------------------------- @@ -615,15 +614,15 @@ public static Object[][] data_getLong() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(expected, InternationalFixedDate.of(year, month, dom).getLong(field)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_getLong_unsupported() { - InternationalFixedDate.of(2012, 6, 28).getLong(MINUTE_OF_DAY); + assertThrows(UnsupportedTemporalTypeException.class, () -> InternationalFixedDate.of(2012, 6, 28).getLong(MINUTE_OF_DAY)); } //----------------------------------------------------------------------- @@ -763,7 +762,7 @@ public static Object[][] data_with() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, @@ -830,15 +829,15 @@ public static Object[][] data_with_bad() { }; } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_with_bad") public void test_with_TemporalField_badValue(int year, int month, int dom, TemporalField field, long value) { - InternationalFixedDate.of(year, month, dom).with(field, value); + assertThrows(DateTimeException.class, () -> InternationalFixedDate.of(year, month, dom).with(field, value)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_with_TemporalField_unsupported() { - InternationalFixedDate.of(2012, 6, 28).with(MINUTE_OF_DAY, 0); + assertThrows(UnsupportedTemporalTypeException.class, () -> InternationalFixedDate.of(2012, 6, 28).with(MINUTE_OF_DAY, 0)); } //----------------------------------------------------------------------- @@ -855,7 +854,7 @@ public static Object[][] data_temporalAdjusters_lastDayOfMonth() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_temporalAdjusters_lastDayOfMonth") public void test_temporalAdjusters_LastDayOfMonth(int year, int month, int day, int expectedYear, int expectedMonth, int expectedDay) { InternationalFixedDate base = InternationalFixedDate.of(year, month, day); @@ -874,10 +873,10 @@ public void test_adjust_toLocalDate() { assertEquals(InternationalFixedDate.of(2012, 7, 19), test); } - @Test(expected = DateTimeException.class) + @Test public void test_adjust_toMonth() { InternationalFixedDate fixed = InternationalFixedDate.of(2000, 1, 4); - fixed.with(Month.APRIL); + assertThrows(DateTimeException.class, () -> fixed.with(Month.APRIL)); } //----------------------------------------------------------------------- @@ -1022,7 +1021,7 @@ public static Object[][] data_minus_leap_and_year_day() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, @@ -1030,7 +1029,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, assertEquals(InternationalFixedDate.of(expectedYear, expectedMonth, expectedDom), InternationalFixedDate.of(year, month, dom).plus(amount, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_plus_leap_and_year_day") public void test_plus_leap_and_year_day_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, @@ -1038,7 +1037,7 @@ public void test_plus_leap_and_year_day_TemporalUnit(int year, int month, int do assertEquals(InternationalFixedDate.of(expectedYear, expectedMonth, expectedDom), InternationalFixedDate.of(year, month, dom).plus(amount, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, @@ -1047,7 +1046,7 @@ public void test_minus_TemporalUnit( assertEquals(InternationalFixedDate.of(expectedYear, expectedMonth, expectedDom), InternationalFixedDate.of(year, month, dom).minus(amount, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_minus_leap_and_year_day") public void test_minus_leap_and_year_day_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, @@ -1056,9 +1055,9 @@ public void test_minus_leap_and_year_day_TemporalUnit( assertEquals(InternationalFixedDate.of(expectedYear, expectedMonth, expectedDom), InternationalFixedDate.of(year, month, dom).minus(amount, unit)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_plus_TemporalUnit_unsupported() { - InternationalFixedDate.of(2012, 6, 28).plus(0, MINUTES); + assertThrows(UnsupportedTemporalTypeException.class, () -> InternationalFixedDate.of(2012, 6, 28).plus(0, MINUTES)); } //----------------------------------------------------------------------- @@ -1272,7 +1271,7 @@ public static Object[][] data_until_period() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, @@ -1283,7 +1282,7 @@ public void test_until_TemporalUnit( assertEquals(expected, start.until(end, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_until_period") public void test_until_end( int year1, int month1, int dom1, @@ -1295,11 +1294,11 @@ public void test_until_end( assertEquals(period, start.until(end)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_until_TemporalUnit_unsupported() { InternationalFixedDate start = InternationalFixedDate.of(2012, 6, 28); InternationalFixedDate end = InternationalFixedDate.of(2012, 7, 1); - start.until(end, MINUTES); + assertThrows(UnsupportedTemporalTypeException.class, () -> start.until(end, MINUTES)); } //----------------------------------------------------------------------- @@ -1310,9 +1309,9 @@ public void test_plus_Period() { assertEquals(InternationalFixedDate.of(2014, 8, 1), InternationalFixedDate.of(2014, 5, 26).plus(InternationalFixedChronology.INSTANCE.period(0, 2, 3))); } - @Test(expected = DateTimeException.class) + @Test public void test_plus_Period_ISO() { - assertEquals(InternationalFixedDate.of(2014, 7, 26), InternationalFixedDate.of(2014, 5, 26).plus(Period.ofMonths(2))); + assertThrows(DateTimeException.class, () -> InternationalFixedDate.of(2014, 5, 26).plus(Period.ofMonths(2))); } @Test @@ -1320,9 +1319,9 @@ public void test_minus_Period() { assertEquals(InternationalFixedDate.of(2014, 3, 23), InternationalFixedDate.of(2014, 5, 26).minus(InternationalFixedChronology.INSTANCE.period(0, 2, 3))); } - @Test(expected = DateTimeException.class) + @Test public void test_minus_Period_ISO() { - assertEquals(InternationalFixedDate.of(2014, 3, 26), InternationalFixedDate.of(2014, 5, 26).minus(Period.ofMonths(2))); + assertThrows(DateTimeException.class, () -> InternationalFixedDate.of(2014, 5, 26).minus(Period.ofMonths(2))); } //----------------------------------------------------------------------- @@ -1340,7 +1339,7 @@ public static Object[][] data_equals() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_equals") public void test_equals(InternationalFixedDate a1, InternationalFixedDate b, InternationalFixedDate c, InternationalFixedDate d) { @@ -1368,7 +1367,7 @@ public static Object[][] data_toString() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_toString") public void test_toString(InternationalFixedDate date, String expected) { assertEquals(expected, date.toString()); diff --git a/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java b/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java index 33433c3d..3315953b 100644 --- a/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java @@ -53,9 +53,11 @@ import static java.time.temporal.ChronoUnit.MONTHS; import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; @@ -73,18 +75,15 @@ import java.time.temporal.WeekFields; import java.util.List; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test. */ -@RunWith(DataProviderRunner.class) public class TestJulianChronology { //----------------------------------------------------------------------- @@ -93,19 +92,19 @@ public class TestJulianChronology { @Test public void test_chronology_of_name() { Chronology chrono = Chronology.of("Julian"); - Assert.assertNotNull(chrono); - Assert.assertEquals(JulianChronology.INSTANCE, chrono); - Assert.assertEquals("Julian", chrono.getId()); - Assert.assertEquals("julian", chrono.getCalendarType()); + assertNotNull(chrono); + assertEquals(JulianChronology.INSTANCE, chrono); + assertEquals("Julian", chrono.getId()); + assertEquals("julian", chrono.getCalendarType()); } @Test public void test_chronology_of_name_id() { Chronology chrono = Chronology.of("julian"); - Assert.assertNotNull(chrono); - Assert.assertEquals(JulianChronology.INSTANCE, chrono); - Assert.assertEquals("Julian", chrono.getId()); - Assert.assertEquals("julian", chrono.getCalendarType()); + assertNotNull(chrono); + assertEquals(JulianChronology.INSTANCE, chrono); + assertEquals("Julian", chrono.getId()); + assertEquals("julian", chrono.getCalendarType()); } //----------------------------------------------------------------------- @@ -147,55 +146,55 @@ public static Object[][] data_samples() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_LocalDate_from_JulianDate(JulianDate julian, LocalDate iso) { assertEquals(iso, LocalDate.from(julian)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_JulianDate_from_LocalDate(JulianDate julian, LocalDate iso) { assertEquals(julian, JulianDate.from(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_JulianDate_chronology_dateEpochDay(JulianDate julian, LocalDate iso) { assertEquals(julian, JulianChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_JulianDate_toEpochDay(JulianDate julian, LocalDate iso) { assertEquals(iso.toEpochDay(), julian.toEpochDay()); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_JulianDate_until_JulianDate(JulianDate julian, LocalDate iso) { assertEquals(JulianChronology.INSTANCE.period(0, 0, 0), julian.until(julian)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_JulianDate_until_LocalDate(JulianDate julian, LocalDate iso) { assertEquals(JulianChronology.INSTANCE.period(0, 0, 0), julian.until(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_LocalDate_until_JulianDate(JulianDate julian, LocalDate iso) { assertEquals(Period.ZERO, iso.until(julian)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(JulianDate julian, LocalDate iso) { assertEquals(julian, JulianChronology.INSTANCE.date(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_plusDays(JulianDate julian, LocalDate iso) { assertEquals(iso, LocalDate.from(julian.plus(0, DAYS))); @@ -205,7 +204,7 @@ public void test_plusDays(JulianDate julian, LocalDate iso) { assertEquals(iso.plusDays(-60), LocalDate.from(julian.plus(-60, DAYS))); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_minusDays(JulianDate julian, LocalDate iso) { assertEquals(iso, LocalDate.from(julian.minus(0, DAYS))); @@ -215,7 +214,7 @@ public void test_minusDays(JulianDate julian, LocalDate iso) { assertEquals(iso.minusDays(-60), LocalDate.from(julian.minus(-60, DAYS))); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_until_DAYS(JulianDate julian, LocalDate iso) { assertEquals(0, julian.until(iso.plusDays(0), DAYS)); @@ -267,15 +266,15 @@ public static Object[][] data_badDates() { }; } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_badDates") public void test_badDates(int year, int month, int dom) { - JulianDate.of(year, month, dom); + assertThrows(DateTimeException.class, () -> JulianDate.of(year, month, dom)); } - @Test(expected = DateTimeException.class) + @Test public void test_chronology_dateYearDay_badDate() { - JulianChronology.INSTANCE.dateYearDay(2001, 366); + assertThrows(DateTimeException.class, () -> JulianChronology.INSTANCE.dateYearDay(2001, 366)); } //----------------------------------------------------------------------- @@ -334,7 +333,7 @@ public static Object[][] data_lengthOfMonth() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(length, JulianDate.of(year, month, 1).lengthOfMonth()); @@ -383,9 +382,9 @@ public void test_prolepticYear_specific() { assertEquals(-3, JulianChronology.INSTANCE.prolepticYear(JulianEra.BC, 4)); } - @Test(expected = ClassCastException.class) + @Test public void test_prolepticYear_badEra() { - JulianChronology.INSTANCE.prolepticYear(IsoEra.CE, 4); + assertThrows(ClassCastException.class, () -> JulianChronology.INSTANCE.prolepticYear(IsoEra.CE, 4)); } @Test @@ -394,9 +393,9 @@ public void test_Chronology_eraOf() { assertEquals(JulianEra.BC, JulianChronology.INSTANCE.eraOf(0)); } - @Test(expected = DateTimeException.class) + @Test public void test_Chronology_eraOf_invalid() { - JulianChronology.INSTANCE.eraOf(2); + assertThrows(DateTimeException.class, () -> JulianChronology.INSTANCE.eraOf(2)); } @Test @@ -447,15 +446,15 @@ public static Object[][] data_ranges() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(ValueRange.of(expectedMin, expectedMax), JulianDate.of(year, month, dom).range(field)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_range_unsupported() { - JulianDate.of(2012, 6, 30).range(MINUTE_OF_DAY); + assertThrows(UnsupportedTemporalTypeException.class, () -> JulianDate.of(2012, 6, 30).range(MINUTE_OF_DAY)); } //----------------------------------------------------------------------- @@ -482,15 +481,15 @@ public static Object[][] data_getLong() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(expected, JulianDate.of(year, month, dom).getLong(field)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_getLong_unsupported() { - JulianDate.of(2012, 6, 30).getLong(MINUTE_OF_DAY); + assertThrows(UnsupportedTemporalTypeException.class, () -> JulianDate.of(2012, 6, 30).getLong(MINUTE_OF_DAY)); } //----------------------------------------------------------------------- @@ -533,7 +532,7 @@ public static Object[][] data_with() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, @@ -541,9 +540,9 @@ public void test_with_TemporalField(int year, int month, int dom, assertEquals(JulianDate.of(expectedYear, expectedMonth, expectedDom), JulianDate.of(year, month, dom).with(field, value)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_with_TemporalField_unsupported() { - JulianDate.of(2012, 6, 30).with(MINUTE_OF_DAY, 0); + assertThrows(UnsupportedTemporalTypeException.class, () -> JulianDate.of(2012, 6, 30).with(MINUTE_OF_DAY, 0)); } //----------------------------------------------------------------------- @@ -573,10 +572,10 @@ public void test_adjust_toLocalDate() { assertEquals(JulianDate.of(2012, 6, 23), test); } - @Test(expected = DateTimeException.class) + @Test public void test_adjust_toMonth() { JulianDate julian = JulianDate.of(2000, 1, 4); - julian.with(Month.APRIL); + assertThrows(DateTimeException.class, () -> julian.with(Month.APRIL)); } //----------------------------------------------------------------------- @@ -627,7 +626,7 @@ public static Object[][] data_plus() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, @@ -635,7 +634,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, assertEquals(JulianDate.of(expectedYear, expectedMonth, expectedDom), JulianDate.of(year, month, dom).plus(amount, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, @@ -644,9 +643,9 @@ public void test_minus_TemporalUnit( assertEquals(JulianDate.of(expectedYear, expectedMonth, expectedDom), JulianDate.of(year, month, dom).minus(amount, unit)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_plus_TemporalUnit_unsupported() { - JulianDate.of(2012, 6, 30).plus(0, MINUTES); + assertThrows(UnsupportedTemporalTypeException.class, () -> JulianDate.of(2012, 6, 30).plus(0, MINUTES)); } //----------------------------------------------------------------------- @@ -681,7 +680,7 @@ public static Object[][] data_until() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, @@ -692,11 +691,11 @@ public void test_until_TemporalUnit( assertEquals(expected, start.until(end, unit)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_until_TemporalUnit_unsupported() { JulianDate start = JulianDate.of(2012, 6, 30); JulianDate end = JulianDate.of(2012, 7, 1); - start.until(end, MINUTES); + assertThrows(UnsupportedTemporalTypeException.class, () -> start.until(end, MINUTES)); } //----------------------------------------------------------------------- @@ -705,9 +704,9 @@ public void test_plus_Period() { assertEquals(JulianDate.of(2014, 7, 29), JulianDate.of(2014, 5, 26).plus(JulianChronology.INSTANCE.period(0, 2, 3))); } - @Test(expected = DateTimeException.class) + @Test public void test_plus_Period_ISO() { - assertEquals(JulianDate.of(2014, 7, 26), JulianDate.of(2014, 5, 26).plus(Period.ofMonths(2))); + assertThrows(DateTimeException.class, () -> JulianDate.of(2014, 5, 26).plus(Period.ofMonths(2))); } @Test @@ -715,9 +714,9 @@ public void test_minus_Period() { assertEquals(JulianDate.of(2014, 3, 23), JulianDate.of(2014, 5, 26).minus(JulianChronology.INSTANCE.period(0, 2, 3))); } - @Test(expected = DateTimeException.class) + @Test public void test_minus_Period_ISO() { - assertEquals(JulianDate.of(2014, 3, 26), JulianDate.of(2014, 5, 26).minus(Period.ofMonths(2))); + assertThrows(DateTimeException.class, () -> JulianDate.of(2014, 5, 26).minus(Period.ofMonths(2))); } //----------------------------------------------------------------------- @@ -754,7 +753,7 @@ public static Object[][] data_toString() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_toString") public void test_toString(JulianDate julian, String expected) { assertEquals(expected, julian.toString()); diff --git a/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java b/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java index 44d62833..1cf394f4 100644 --- a/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java @@ -53,9 +53,11 @@ import static java.time.temporal.ChronoUnit.MONTHS; import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; @@ -75,19 +77,16 @@ import java.util.List; import java.util.function.IntPredicate; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test. */ @SuppressWarnings({"static-method", "javadoc"}) -@RunWith(DataProviderRunner.class) public class TestPaxChronology { //----------------------------------------------------------------------- @@ -96,19 +95,19 @@ public class TestPaxChronology { @Test public void test_chronology_of_name() { Chronology chrono = Chronology.of("Pax"); - Assert.assertNotNull(chrono); - Assert.assertEquals(PaxChronology.INSTANCE, chrono); - Assert.assertEquals("Pax", chrono.getId()); - Assert.assertEquals("pax", chrono.getCalendarType()); + assertNotNull(chrono); + assertEquals(PaxChronology.INSTANCE, chrono); + assertEquals("Pax", chrono.getId()); + assertEquals("pax", chrono.getCalendarType()); } @Test public void test_chronology_of_name_id() { Chronology chrono = Chronology.of("pax"); - Assert.assertNotNull(chrono); - Assert.assertEquals(PaxChronology.INSTANCE, chrono); - Assert.assertEquals("Pax", chrono.getId()); - Assert.assertEquals("pax", chrono.getCalendarType()); + assertNotNull(chrono); + assertEquals(PaxChronology.INSTANCE, chrono); + assertEquals("Pax", chrono.getId()); + assertEquals("pax", chrono.getCalendarType()); } //----------------------------------------------------------------------- @@ -179,55 +178,55 @@ public static Object[][] data_samples() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_LocalDate_from_PaxDate(PaxDate pax, LocalDate iso) { assertEquals(iso, LocalDate.from(pax)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_PaxDate_from_LocalDate(PaxDate pax, LocalDate iso) { assertEquals(pax, PaxDate.from(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_PaxDate_chronology_dateEpochDay(PaxDate pax, LocalDate iso) { assertEquals(pax, PaxChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_PaxDate_toEpochDay(PaxDate pax, LocalDate iso) { assertEquals(iso.toEpochDay(), pax.toEpochDay()); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_PaxDate_until_PaxDate(PaxDate pax, LocalDate iso) { assertEquals(PaxChronology.INSTANCE.period(0, 0, 0), pax.until(pax)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_PaxDate_until_LocalDate(PaxDate pax, LocalDate iso) { assertEquals(PaxChronology.INSTANCE.period(0, 0, 0), pax.until(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_LocalDate_until_PaxDate(PaxDate pax, LocalDate iso) { assertEquals(Period.ZERO, iso.until(pax)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(PaxDate pax, LocalDate iso) { assertEquals(pax, PaxChronology.INSTANCE.date(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_plusDays(PaxDate pax, LocalDate iso) { assertEquals(iso, LocalDate.from(pax.plus(0, DAYS))); @@ -237,7 +236,7 @@ public void test_plusDays(PaxDate pax, LocalDate iso) { assertEquals(iso.plusDays(-60), LocalDate.from(pax.plus(-60, DAYS))); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_minusDays(PaxDate pax, LocalDate iso) { assertEquals(iso, LocalDate.from(pax.minus(0, DAYS))); @@ -247,7 +246,7 @@ public void test_minusDays(PaxDate pax, LocalDate iso) { assertEquals(iso.minusDays(-60), LocalDate.from(pax.minus(-60, DAYS))); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_until_DAYS(PaxDate pax, LocalDate iso) { assertEquals(0, pax.until(iso.plusDays(0), DAYS)); @@ -303,15 +302,15 @@ public static Object[][] data_badDates() { }; } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_badDates") public void test_badDates(int year, int month, int dom) { - PaxDate.of(year, month, dom); + assertThrows(DateTimeException.class, () -> PaxDate.of(year, month, dom)); } - @Test(expected = DateTimeException.class) + @Test public void test_chronology_dateYearDay_badDate() { - PaxChronology.INSTANCE.dateYearDay(2001, 365); + assertThrows(DateTimeException.class, () -> PaxChronology.INSTANCE.dateYearDay(2001, 365)); } //----------------------------------------------------------------------- @@ -383,7 +382,7 @@ public static Object[][] data_lengthOfMonth() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(length, PaxDate.of(year, month, 1).lengthOfMonth()); @@ -432,9 +431,9 @@ public void test_prolepticYear_specific() { assertEquals(-3, PaxChronology.INSTANCE.prolepticYear(PaxEra.BCE, 4)); } - @Test(expected = ClassCastException.class) + @Test public void test_prolepticYear_badEra() { - PaxChronology.INSTANCE.prolepticYear(IsoEra.CE, 4); + assertThrows(ClassCastException.class, () -> PaxChronology.INSTANCE.prolepticYear(IsoEra.CE, 4)); } @Test @@ -443,9 +442,9 @@ public void test_Chronology_eraOf() { assertEquals(PaxEra.BCE, PaxChronology.INSTANCE.eraOf(0)); } - @Test(expected = DateTimeException.class) + @Test public void test_Chronology_eraOf_invalid() { - PaxChronology.INSTANCE.eraOf(2); + assertThrows(DateTimeException.class, () -> PaxChronology.INSTANCE.eraOf(2)); } @Test @@ -502,15 +501,15 @@ public static Object[][] data_ranges() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(ValueRange.of(expectedMin, expectedMax), PaxDate.of(year, month, dom).range(field)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_range_unsupported() { - PaxDate.of(2012, 6, 28).range(MINUTE_OF_DAY); + assertThrows(UnsupportedTemporalTypeException.class, () -> PaxDate.of(2012, 6, 28).range(MINUTE_OF_DAY)); } //----------------------------------------------------------------------- @@ -537,15 +536,15 @@ public static Object[][] data_getLong() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(expected, PaxDate.of(year, month, dom).getLong(field)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_getLong_unsupported() { - PaxDate.of(2012, 6, 28).getLong(MINUTE_OF_DAY); + assertThrows(UnsupportedTemporalTypeException.class, () -> PaxDate.of(2012, 6, 28).getLong(MINUTE_OF_DAY)); } //----------------------------------------------------------------------- @@ -588,7 +587,7 @@ public static Object[][] data_with() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, @@ -596,9 +595,9 @@ public void test_with_TemporalField(int year, int month, int dom, assertEquals(PaxDate.of(expectedYear, expectedMonth, expectedDom), PaxDate.of(year, month, dom).with(field, value)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_with_TemporalField_unsupported() { - PaxDate.of(2012, 6, 28).with(MINUTE_OF_DAY, 0); + assertThrows(UnsupportedTemporalTypeException.class, () -> PaxDate.of(2012, 6, 28).with(MINUTE_OF_DAY, 0)); } //----------------------------------------------------------------------- @@ -628,10 +627,10 @@ public void test_adjust_toLocalDate() { assertEquals(PaxDate.of(2012, 7, 27), test); } - @Test(expected = DateTimeException.class) + @Test public void test_adjust_toMonth() { PaxDate pax = PaxDate.of(2000, 1, 4); - pax.with(Month.APRIL); + assertThrows(DateTimeException.class, () -> pax.with(Month.APRIL)); } //----------------------------------------------------------------------- @@ -710,7 +709,7 @@ public static Object[][] data_minus_leap() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, @@ -718,7 +717,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, assertEquals(PaxDate.of(expectedYear, expectedMonth, expectedDom), PaxDate.of(year, month, dom).plus(amount, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_plus_leap") public void test_plus_leap_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, @@ -726,7 +725,7 @@ public void test_plus_leap_TemporalUnit(int year, int month, int dom, test_plus_TemporalUnit(year, month, dom, amount, unit, expectedYear, expectedMonth, expectedDom); } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, @@ -735,7 +734,7 @@ public void test_minus_TemporalUnit( assertEquals(PaxDate.of(expectedYear, expectedMonth, expectedDom), PaxDate.of(year, month, dom).minus(amount, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_minus_leap") public void test_minus_leap_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, @@ -743,9 +742,9 @@ public void test_minus_leap_TemporalUnit(int year, int month, int dom, test_minus_TemporalUnit(year, month, dom, amount, unit, expectedYear, expectedMonth, expectedDom); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_plus_TemporalUnit_unsupported() { - PaxDate.of(2012, 6, 10).plus(0, MINUTES); + assertThrows(UnsupportedTemporalTypeException.class, () -> PaxDate.of(2012, 6, 10).plus(0, MINUTES)); } //----------------------------------------------------------------------- @@ -821,7 +820,7 @@ public static Object[][] data_until_period() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, @@ -832,7 +831,7 @@ public void test_until_TemporalUnit( assertEquals(expected, start.until(end, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_until_period") public void test_until_end( int year1, int month1, int dom1, @@ -844,11 +843,11 @@ public void test_until_end( assertEquals(period, start.until(end)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_until_TemporalUnit_unsupported() { PaxDate start = PaxDate.of(2012, 6, 28); PaxDate end = PaxDate.of(2012, 7, 1); - start.until(end, MINUTES); + assertThrows(UnsupportedTemporalTypeException.class, () -> start.until(end, MINUTES)); } //----------------------------------------------------------------------- @@ -857,9 +856,9 @@ public void test_plus_Period() { assertEquals(PaxDate.of(2014, 7, 28), PaxDate.of(2014, 5, 26).plus(PaxChronology.INSTANCE.period(0, 2, 2))); } - @Test(expected = DateTimeException.class) + @Test public void test_plus_Period_ISO() { - assertEquals(PaxDate.of(2014, 7, 26), PaxDate.of(2014, 5, 26).plus(Period.ofMonths(2))); + assertThrows(DateTimeException.class, () -> PaxDate.of(2014, 5, 26).plus(Period.ofMonths(2))); } @Test @@ -867,9 +866,9 @@ public void test_minus_Period() { assertEquals(PaxDate.of(2014, 3, 23), PaxDate.of(2014, 5, 26).minus(PaxChronology.INSTANCE.period(0, 2, 3))); } - @Test(expected = DateTimeException.class) + @Test public void test_minus_Period_ISO() { - assertEquals(PaxDate.of(2014, 3, 26), PaxDate.of(2014, 5, 26).minus(Period.ofMonths(2))); + assertThrows(DateTimeException.class, () -> PaxDate.of(2014, 5, 26).minus(Period.ofMonths(2))); } //----------------------------------------------------------------------- @@ -906,7 +905,7 @@ public static Object[][] data_toString() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_toString") public void test_toString(PaxDate pax, String expected) { assertEquals(expected, pax.toString()); diff --git a/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java b/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java index 3fe6e840..cf2e9b2b 100644 --- a/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java @@ -55,10 +55,11 @@ import static java.time.temporal.ChronoUnit.MONTHS; import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; @@ -80,18 +81,16 @@ import java.time.temporal.ValueRange; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test. */ @SuppressWarnings({"static-method", "javadoc"}) -@RunWith(DataProviderRunner.class) public class TestSymmetry010Chronology { //----------------------------------------------------------------------- @@ -146,55 +145,55 @@ public static Object[][] data_samples() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_LocalDate_from_Symmetry010Date(Symmetry010Date sym010, LocalDate iso) { assertEquals(iso, LocalDate.from(sym010)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_Symmetry010Date_from_LocalDate(Symmetry010Date sym010, LocalDate iso) { assertEquals(sym010, Symmetry010Date.from(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_Symmetry010Date_chronology_dateEpochDay(Symmetry010Date sym010, LocalDate iso) { assertEquals(sym010, Symmetry010Chronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_Symmetry010Date_toEpochDay(Symmetry010Date sym010, LocalDate iso) { assertEquals(iso.toEpochDay(), sym010.toEpochDay()); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_Symmetry010Date_until_Symmetry010Date(Symmetry010Date sym010, LocalDate iso) { assertEquals(Symmetry010Chronology.INSTANCE.period(0, 0, 0), sym010.until(sym010)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_Symmetry010Date_until_LocalDate(Symmetry010Date sym010, LocalDate iso) { assertEquals(Symmetry010Chronology.INSTANCE.period(0, 0, 0), sym010.until(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(Symmetry010Date sym010, LocalDate iso) { assertEquals(sym010, Symmetry010Chronology.INSTANCE.date(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_LocalDate_until_Symmetry010Date(Symmetry010Date sym010, LocalDate iso) { assertEquals(Period.ZERO, iso.until(sym010)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_plusDays(Symmetry010Date sym010, LocalDate iso) { assertEquals(iso, LocalDate.from(sym010.plus(0, DAYS))); @@ -204,7 +203,7 @@ public void test_plusDays(Symmetry010Date sym010, LocalDate iso) { assertEquals(iso.plusDays(-60), LocalDate.from(sym010.plus(-60, DAYS))); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_minusDays(Symmetry010Date sym010, LocalDate iso) { assertEquals(iso, LocalDate.from(sym010.minus(0, DAYS))); @@ -214,7 +213,7 @@ public void test_minusDays(Symmetry010Date sym010, LocalDate iso) { assertEquals(iso.minusDays(-60), LocalDate.from(sym010.minus(-60, DAYS))); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_until_DAYS(Symmetry010Date sym010, LocalDate iso) { assertEquals(0, sym010.until(iso.plusDays(0), DAYS)); @@ -256,10 +255,10 @@ public static Object[][] data_badDates() { }; } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_badDates") public void test_badDates(int year, int month, int dom) { - Symmetry010Date.of(year, month, dom); + assertThrows(DateTimeException.class, () -> Symmetry010Date.of(year, month, dom)); } @DataProvider @@ -272,10 +271,10 @@ public static Object[][] data_badLeapDates() { }; } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_badLeapDates") public void badLeapDayDates(int year) { - Symmetry010Date.of(year, 12, 37); + assertThrows(DateTimeException.class, () -> Symmetry010Date.of(year, 12, 37)); } //----------------------------------------------------------------------- @@ -326,13 +325,13 @@ public static Object[][] data_lengthOfMonth() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int day, int length) { assertEquals(length, Symmetry010Date.of(year, month, day).lengthOfMonth()); } - @Test + @ParameterizedTest @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonthFirst(int year, int month, int day, int length) { assertEquals(length, Symmetry010Date.of(year, month, 1).lengthOfMonth()); @@ -422,10 +421,10 @@ public static Object[][] data_prolepticYear_badEra() { }; } - @Test(expected = ClassCastException.class) + @ParameterizedTest @UseDataProvider("data_prolepticYear_badEra") public void test_prolepticYear_badEra(Era era) { - Symmetry010Chronology.INSTANCE.prolepticYear(era, 4); + assertThrows(ClassCastException.class, () -> Symmetry010Chronology.INSTANCE.prolepticYear(era, 4)); } @Test @@ -434,9 +433,9 @@ public void test_Chronology_eraOf() { assertEquals(IsoEra.CE, Symmetry010Chronology.INSTANCE.eraOf(1)); } - @Test(expected = DateTimeException.class) + @Test public void test_Chronology_eraOf_invalid() { - Symmetry010Chronology.INSTANCE.eraOf(2); + assertThrows(DateTimeException.class, () -> Symmetry010Chronology.INSTANCE.eraOf(2)); } @Test @@ -516,15 +515,15 @@ public static Object[][] data_ranges() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, ValueRange range) { assertEquals(range, Symmetry010Date.of(year, month, dom).range(field)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_range_unsupported() { - Symmetry010Date.of(2012, 6, 28).range(MINUTE_OF_DAY); + assertThrows(UnsupportedTemporalTypeException.class, () -> Symmetry010Date.of(2012, 6, 28).range(MINUTE_OF_DAY)); } //----------------------------------------------------------------------- @@ -565,15 +564,15 @@ public static Object[][] data_getLong() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(expected, Symmetry010Date.of(year, month, dom).getLong(field)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_getLong_unsupported() { - Symmetry010Date.of(2012, 6, 28).getLong(MINUTE_OF_DAY); + assertThrows(UnsupportedTemporalTypeException.class, () -> Symmetry010Date.of(2012, 6, 28).getLong(MINUTE_OF_DAY)); } //----------------------------------------------------------------------- @@ -655,7 +654,7 @@ public static Object[][] data_with() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, @@ -702,15 +701,15 @@ public static Object[][] data_with_bad() { }; } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_with_bad") public void test_with_TemporalField_badValue(int year, int month, int dom, TemporalField field, long value) { - Symmetry010Date.of(year, month, dom).with(field, value); + assertThrows(DateTimeException.class, () -> Symmetry010Date.of(year, month, dom).with(field, value)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_with_TemporalField_unsupported() { - Symmetry010Date.of(2012, 6, 28).with(MINUTE_OF_DAY, 10); + assertThrows(UnsupportedTemporalTypeException.class, () -> Symmetry010Date.of(2012, 6, 28).with(MINUTE_OF_DAY, 10)); } //----------------------------------------------------------------------- @@ -735,7 +734,7 @@ public static Object[][] data_temporalAdjusters_lastDayOfMonth() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_temporalAdjusters_lastDayOfMonth") public void test_temporalAdjusters_LastDayOfMonth(int year, int month, int day, int expectedYear, int expectedMonth, int expectedDay) { Symmetry010Date base = Symmetry010Date.of(year, month, day); @@ -754,10 +753,10 @@ public void test_adjust_toLocalDate() { assertEquals(Symmetry010Date.of(2012, 7, 5), test); } - @Test(expected = DateTimeException.class) + @Test public void test_adjust_toMonth() { Symmetry010Date sym010 = Symmetry010Date.of(2000, 1, 4); - sym010.with(Month.APRIL); + assertThrows(DateTimeException.class, () -> sym010.with(Month.APRIL)); } //----------------------------------------------------------------------- @@ -837,7 +836,7 @@ public static Object[][] data_plus_leapWeek() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, @@ -845,7 +844,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, assertEquals(Symmetry010Date.of(expectedYear, expectedMonth, expectedDom), Symmetry010Date.of(year, month, dom).plus(amount, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_plus_leapWeek") public void test_plus_leapWeek_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, @@ -853,7 +852,7 @@ public void test_plus_leapWeek_TemporalUnit(int year, int month, int dom, assertEquals(Symmetry010Date.of(expectedYear, expectedMonth, expectedDom), Symmetry010Date.of(year, month, dom).plus(amount, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, @@ -862,7 +861,7 @@ public void test_minus_TemporalUnit( assertEquals(Symmetry010Date.of(expectedYear, expectedMonth, expectedDom), Symmetry010Date.of(year, month, dom).minus(amount, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_plus_leapWeek") public void test_minus_leapWeek_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, @@ -871,9 +870,9 @@ public void test_minus_leapWeek_TemporalUnit( assertEquals(Symmetry010Date.of(expectedYear, expectedMonth, expectedDom), Symmetry010Date.of(year, month, dom).minus(amount, unit)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_plus_TemporalUnit_unsupported() { - Symmetry010Date.of(2012, 6, 28).plus(0, MINUTES); + assertThrows(UnsupportedTemporalTypeException.class, () -> Symmetry010Date.of(2012, 6, 28).plus(0, MINUTES)); } //----------------------------------------------------------------------- @@ -922,7 +921,7 @@ public static Object[][] data_until_period() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, @@ -933,7 +932,7 @@ public void test_until_TemporalUnit( assertEquals(expected, start.until(end, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_until_period") public void test_until_end( int year1, int month1, int dom1, @@ -945,11 +944,11 @@ public void test_until_end( assertEquals(period, start.until(end)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_until_TemporalUnit_unsupported() { Symmetry010Date start = Symmetry010Date.of(2012, 6, 28); Symmetry010Date end = Symmetry010Date.of(2012, 7, 1); - start.until(end, MINUTES); + assertThrows(UnsupportedTemporalTypeException.class, () -> start.until(end, MINUTES)); } //----------------------------------------------------------------------- @@ -961,10 +960,9 @@ public void test_plus_Period() { Symmetry010Date.of(2014, 5, 21).plus(Symmetry010Chronology.INSTANCE.period(0, 2, 8))); } - @Test(expected = DateTimeException.class) + @Test public void test_plus_Period_ISO() { - assertEquals(Symmetry010Date.of(2014, 7, 26), - Symmetry010Date.of(2014, 5, 26).plus(Period.ofMonths(2))); + assertThrows(DateTimeException.class, () -> Symmetry010Date.of(2014, 5, 26).plus(Period.ofMonths(2))); } @Test @@ -973,9 +971,9 @@ public void test_minus_Period() { Symmetry010Date.of(2014, 5, 26).minus(Symmetry010Chronology.INSTANCE.period(0, 2, 3))); } - @Test(expected = DateTimeException.class) + @Test public void test_minus_Period_ISO() { - assertEquals(Symmetry010Date.of(2014, 3, 26), Symmetry010Date.of(2014, 5, 26).minus(Period.ofMonths(2))); + assertThrows(DateTimeException.class, () -> Symmetry010Date.of(2014, 5, 26).minus(Period.ofMonths(2))); } //----------------------------------------------------------------------- @@ -990,7 +988,7 @@ public static Object[][] data_equals() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_equals") public void test_equals(Symmetry010Date a1, Symmetry010Date b, Symmetry010Date c, Symmetry010Date d) { assertTrue(a1.equals(a1)); @@ -1015,7 +1013,7 @@ public static Object[][] data_toString() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_toString") public void test_toString(Symmetry010Date date, String expected) { assertEquals(expected, date.toString()); diff --git a/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java b/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java index 3f1c0cd7..c47c3305 100644 --- a/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java @@ -55,10 +55,11 @@ import static java.time.temporal.ChronoUnit.MONTHS; import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; @@ -80,18 +81,16 @@ import java.time.temporal.ValueRange; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test. */ @SuppressWarnings({"static-method", "javadoc"}) -@RunWith(DataProviderRunner.class) public class TestSymmetry454Chronology { //----------------------------------------------------------------------- @@ -146,55 +145,55 @@ public static Object[][] data_samples() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_LocalDate_from_Symmetry454Date(Symmetry454Date sym454, LocalDate iso) { assertEquals(iso, LocalDate.from(sym454)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_Symmetry454Date_from_LocalDate(Symmetry454Date sym454, LocalDate iso) { assertEquals(sym454, Symmetry454Date.from(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_Symmetry454Date_chronology_dateEpochDay(Symmetry454Date sym454, LocalDate iso) { assertEquals(sym454, Symmetry454Chronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_Symmetry454Date_toEpochDay(Symmetry454Date sym454, LocalDate iso) { assertEquals(iso.toEpochDay(), sym454.toEpochDay()); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_Symmetry454Date_until_Symmetry454Date(Symmetry454Date sym454, LocalDate iso) { assertEquals(Symmetry454Chronology.INSTANCE.period(0, 0, 0), sym454.until(sym454)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_Symmetry454Date_until_LocalDate(Symmetry454Date sym454, LocalDate iso) { assertEquals(Symmetry454Chronology.INSTANCE.period(0, 0, 0), sym454.until(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_Chronology_date_Temporal(Symmetry454Date sym454, LocalDate iso) { assertEquals(sym454, Symmetry454Chronology.INSTANCE.date(iso)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_LocalDate_until_Symmetry454Date(Symmetry454Date sym454, LocalDate iso) { assertEquals(Period.ZERO, iso.until(sym454)); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_plusDays(Symmetry454Date sym454, LocalDate iso) { assertEquals(iso, LocalDate.from(sym454.plus(0, DAYS))); @@ -204,7 +203,7 @@ public void test_plusDays(Symmetry454Date sym454, LocalDate iso) { assertEquals(iso.plusDays(-60), LocalDate.from(sym454.plus(-60, DAYS))); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_minusDays(Symmetry454Date sym454, LocalDate iso) { assertEquals(iso, LocalDate.from(sym454.minus(0, DAYS))); @@ -214,7 +213,7 @@ public void test_minusDays(Symmetry454Date sym454, LocalDate iso) { assertEquals(iso.minusDays(-60), LocalDate.from(sym454.minus(-60, DAYS))); } - @Test + @ParameterizedTest @UseDataProvider("data_samples") public void test_until_DAYS(Symmetry454Date sym454, LocalDate iso) { assertEquals(0, sym454.until(iso.plusDays(0), DAYS)); @@ -256,10 +255,10 @@ public static Object[][] data_badDates() { }; } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_badDates") public void test_badDates(int year, int month, int dom) { - Symmetry454Date.of(year, month, dom); + assertThrows(DateTimeException.class, () -> Symmetry454Date.of(year, month, dom)); } @DataProvider @@ -272,15 +271,15 @@ public static Object[][] data_badLeapDates() { }; } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_badLeapDates") public void test_badLeapDayDates(int year) { - Symmetry454Date.of(year, 12, 29); + assertThrows(DateTimeException.class, () -> Symmetry454Date.of(year, 12, 29)); } - @Test(expected = DateTimeException.class) + @Test public void test_chronology_dateYearDay_badDate() { - Symmetry454Chronology.INSTANCE.dateYearDay(2000, 365); + assertThrows(DateTimeException.class, () -> Symmetry454Chronology.INSTANCE.dateYearDay(2000, 365)); } //----------------------------------------------------------------------- @@ -331,13 +330,13 @@ public static Object[][] data_lengthOfMonth() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int day, int length) { assertEquals(length, Symmetry454Date.of(year, month, day).lengthOfMonth()); } - @Test + @ParameterizedTest @UseDataProvider("data_lengthOfMonth") public void test_lengthOfMonthFirst(int year, int month, int day, int length) { assertEquals(length, Symmetry454Date.of(year, month, 1).lengthOfMonth()); @@ -428,10 +427,10 @@ public static Object[][] data_prolepticYear_badEra() { }; } - @Test(expected = ClassCastException.class) + @ParameterizedTest @UseDataProvider("data_prolepticYear_badEra") public void test_prolepticYear_badEra(Era era) { - Symmetry454Chronology.INSTANCE.prolepticYear(era, 4); + assertThrows(ClassCastException.class, () -> Symmetry454Chronology.INSTANCE.prolepticYear(era, 4)); } @Test @@ -440,9 +439,9 @@ public void test_Chronology_eraOf() { assertEquals(IsoEra.CE, Symmetry454Chronology.INSTANCE.eraOf(1)); } - @Test(expected = DateTimeException.class) + @Test public void test_Chronology_eraOf_invalid() { - Symmetry454Chronology.INSTANCE.eraOf(2); + assertThrows(DateTimeException.class, () -> Symmetry454Chronology.INSTANCE.eraOf(2)); } @Test @@ -522,15 +521,15 @@ public static Object[][] data_ranges() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, ValueRange range) { assertEquals(range, Symmetry454Date.of(year, month, dom).range(field)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_range_unsupported() { - Symmetry454Date.of(2012, 6, 28).range(MINUTE_OF_DAY); + assertThrows(UnsupportedTemporalTypeException.class, () -> Symmetry454Date.of(2012, 6, 28).range(MINUTE_OF_DAY)); } //----------------------------------------------------------------------- @@ -571,15 +570,15 @@ public static Object[][] data_getLong() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(expected, Symmetry454Date.of(year, month, dom).getLong(field)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_getLong_unsupported() { - Symmetry454Date.of(2012, 6, 28).getLong(MINUTE_OF_DAY); + assertThrows(UnsupportedTemporalTypeException.class, () -> Symmetry454Date.of(2012, 6, 28).getLong(MINUTE_OF_DAY)); } //----------------------------------------------------------------------- @@ -661,7 +660,7 @@ public static Object[][] data_with() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, @@ -710,15 +709,15 @@ public static Object[][] data_with_bad() { }; } - @Test(expected = DateTimeException.class) + @ParameterizedTest @UseDataProvider("data_with_bad") public void test_with_TemporalField_badValue(int year, int month, int dom, TemporalField field, long value) { - Symmetry454Date.of(year, month, dom).with(field, value); + assertThrows(DateTimeException.class, () -> Symmetry454Date.of(year, month, dom).with(field, value)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_with_TemporalField_unsupported() { - Symmetry454Date.of(2012, 6, 28).with(MINUTE_OF_DAY, 10); + assertThrows(UnsupportedTemporalTypeException.class, () -> Symmetry454Date.of(2012, 6, 28).with(MINUTE_OF_DAY, 10)); } //----------------------------------------------------------------------- @@ -743,7 +742,7 @@ public static Object[][] data_temporalAdjusters_lastDayOfMonth() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_temporalAdjusters_lastDayOfMonth") public void test_temporalAdjusters_LastDayOfMonth(int year, int month, int day, int expectedYear, int expectedMonth, int expectedDay) { Symmetry454Date base = Symmetry454Date.of(year, month, day); @@ -762,10 +761,10 @@ public void test_adjust_toLocalDate() { assertEquals(Symmetry454Date.of(2012, 7, 5), test); } - @Test(expected = DateTimeException.class) + @Test public void test_adjust_toMonth() { Symmetry454Date sym454 = Symmetry454Date.of(2000, 1, 4); - sym454.with(Month.APRIL); + assertThrows(DateTimeException.class, () -> sym454.with(Month.APRIL)); } //----------------------------------------------------------------------- @@ -845,7 +844,7 @@ public static Object[][] data_plus_leapWeek() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, @@ -853,7 +852,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, assertEquals(Symmetry454Date.of(expectedYear, expectedMonth, expectedDom), Symmetry454Date.of(year, month, dom).plus(amount, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_plus_leapWeek") public void test_plus_leapWeek_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, @@ -861,7 +860,7 @@ public void test_plus_leapWeek_TemporalUnit(int year, int month, int dom, assertEquals(Symmetry454Date.of(expectedYear, expectedMonth, expectedDom), Symmetry454Date.of(year, month, dom).plus(amount, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, @@ -870,7 +869,7 @@ public void test_minus_TemporalUnit( assertEquals(Symmetry454Date.of(expectedYear, expectedMonth, expectedDom), Symmetry454Date.of(year, month, dom).minus(amount, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_plus_leapWeek") public void test_minus_leapWeek_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, @@ -879,9 +878,9 @@ public void test_minus_leapWeek_TemporalUnit( assertEquals(Symmetry454Date.of(expectedYear, expectedMonth, expectedDom), Symmetry454Date.of(year, month, dom).minus(amount, unit)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_plus_TemporalUnit_unsupported() { - Symmetry454Date.of(2012, 6, 28).plus(0, MINUTES); + assertThrows(UnsupportedTemporalTypeException.class, () -> Symmetry454Date.of(2012, 6, 28).plus(0, MINUTES)); } //----------------------------------------------------------------------- @@ -930,7 +929,7 @@ public static Object[][] data_until_period() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, @@ -941,7 +940,7 @@ public void test_until_TemporalUnit( assertEquals(expected, start.until(end, unit)); } - @Test + @ParameterizedTest @UseDataProvider("data_until_period") public void test_until_end( int year1, int month1, int dom1, @@ -953,11 +952,11 @@ public void test_until_end( assertEquals(period, start.until(end)); } - @Test(expected = UnsupportedTemporalTypeException.class) + @Test public void test_until_TemporalUnit_unsupported() { Symmetry454Date start = Symmetry454Date.of(2012, 6, 28); Symmetry454Date end = Symmetry454Date.of(2012, 7, 1); - start.until(end, MINUTES); + assertThrows(UnsupportedTemporalTypeException.class, () -> start.until(end, MINUTES)); } //----------------------------------------------------------------------- @@ -969,10 +968,9 @@ public void test_plus_Period() { Symmetry454Date.of(2014, 5, 21).plus(Symmetry454Chronology.INSTANCE.period(0, 2, 8))); } - @Test(expected = DateTimeException.class) + @Test public void test_plus_Period_ISO() { - assertEquals(Symmetry454Date.of(2014, 7, 26), - Symmetry454Date.of(2014, 5, 26).plus(Period.ofMonths(2))); + assertThrows(DateTimeException.class, () -> Symmetry454Date.of(2014, 5, 26).plus(Period.ofMonths(2))); } @Test @@ -981,9 +979,9 @@ public void test_minus_Period() { Symmetry454Date.of(2014, 5, 26).minus(Symmetry454Chronology.INSTANCE.period(0, 2, 3))); } - @Test(expected = DateTimeException.class) + @Test public void test_minus_Period_ISO() { - assertEquals(Symmetry454Date.of(2014, 3, 26), Symmetry454Date.of(2014, 5, 26).minus(Period.ofMonths(2))); + assertThrows(DateTimeException.class, () -> Symmetry454Date.of(2014, 5, 26).minus(Period.ofMonths(2))); } //----------------------------------------------------------------------- @@ -998,7 +996,7 @@ public static Object[][] data_equals() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_equals") public void test_equals(Symmetry454Date a1, Symmetry454Date b, Symmetry454Date c, Symmetry454Date d) { assertTrue(a1.equals(a1)); @@ -1023,7 +1021,7 @@ public static Object[][] data_toString() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_toString") public void test_toString(Symmetry454Date date, String expected) { assertEquals(expected, date.toString()); diff --git a/src/test/java/org/threeten/extra/scale/TestTaiInstant.java b/src/test/java/org/threeten/extra/scale/TestTaiInstant.java index d038bc79..289107bb 100644 --- a/src/test/java/org/threeten/extra/scale/TestTaiInstant.java +++ b/src/test/java/org/threeten/extra/scale/TestTaiInstant.java @@ -31,9 +31,9 @@ */ package org.threeten.extra.scale; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -44,17 +44,15 @@ import java.time.Instant; import java.time.format.DateTimeParseException; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test TaiInstant. */ -@RunWith(DataProviderRunner.class) public class TestTaiInstant { //----------------------------------------------------------------------- @@ -110,9 +108,9 @@ public void factory_ofTaiSeconds_long_long_nanosNegativeAdjusted() { assertEquals(999999999, test.getNano()); } - @Test(expected = ArithmeticException.class) + @Test public void factory_ofTaiSeconds_long_long_tooBig() { - TaiInstant.ofTaiSeconds(Long.MAX_VALUE, 1000000000); + assertThrows(ArithmeticException.class, () -> TaiInstant.ofTaiSeconds(Long.MAX_VALUE, 1000000000)); } //----------------------------------------------------------------------- @@ -125,9 +123,9 @@ public void factory_of_Instant() { assertEquals(2, test.getNano()); } - @Test(expected = NullPointerException.class) + @Test public void factory_of_Instant_null() { - TaiInstant.of((Instant) null); + assertThrows(NullPointerException.class, () -> TaiInstant.of((Instant) null)); } //----------------------------------------------------------------------- @@ -144,9 +142,9 @@ public void factory_of_UtcInstant() { } } - @Test(expected = NullPointerException.class) + @Test public void factory_of_UtcInstant_null() { - TaiInstant.of((UtcInstant) null); + assertThrows(NullPointerException.class, () -> TaiInstant.of((UtcInstant) null)); } //----------------------------------------------------------------------- @@ -176,15 +174,15 @@ public static Object[][] data_badParse() { }; } - @Test(expected = DateTimeParseException.class) + @ParameterizedTest @UseDataProvider("data_badParse") public void factory_parse_CharSequence_invalid(String str) { - TaiInstant.parse(str); + assertThrows(DateTimeParseException.class, () -> TaiInstant.parse(str)); } - @Test(expected = NullPointerException.class) + @Test public void factory_parse_CharSequence_null() { - TaiInstant.parse((String) null); + assertThrows(NullPointerException.class, () -> TaiInstant.parse((String) null)); } //----------------------------------------------------------------------- @@ -202,7 +200,7 @@ public static Object[][] data_withTAISeconds() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_withTAISeconds") public void test_withTAISeconds(long tai, long nanos, long newTai, Long expectedTai, Long expectedNanos) { TaiInstant i = TaiInstant.ofTaiSeconds(tai, nanos).withTaiSeconds(newTai); @@ -225,21 +223,16 @@ public static Object[][] data_withNano() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_withNano") public void test_withNano(long tai, long nanos, int newNano, Long expectedTai, Long expectedNanos) { TaiInstant i = TaiInstant.ofTaiSeconds(tai, nanos); if (expectedTai != null) { - i = i.withNano(newNano); - assertEquals(expectedTai.longValue(), i.getTaiSeconds()); - assertEquals(expectedNanos.longValue(), i.getNano()); + TaiInstant withNano = i.withNano(newNano); + assertEquals(expectedTai.longValue(), withNano.getTaiSeconds()); + assertEquals(expectedNanos.longValue(), withNano.getNano()); } else { - try { - i = i.withNano(newNano); - fail(); - } catch (IllegalArgumentException ex) { - // expected - } + assertThrows(IllegalArgumentException.class, () -> i.withNano(newNano)); } } @@ -431,7 +424,7 @@ public static Object[][] data_plus() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_plus(long seconds, int nanos, long plusSeconds, int plusNanos, long expectedSeconds, int expectedNanoOfSecond) { TaiInstant i = TaiInstant.ofTaiSeconds(seconds, nanos).plus(Duration.ofSeconds(plusSeconds, plusNanos)); @@ -439,16 +432,16 @@ public void test_plus(long seconds, int nanos, long plusSeconds, int plusNanos, assertEquals(expectedNanoOfSecond, i.getNano()); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_overflowTooBig() { TaiInstant i = TaiInstant.ofTaiSeconds(Long.MAX_VALUE, 999999999); - i.plus(Duration.ofSeconds(0, 1)); + assertThrows(ArithmeticException.class, () -> i.plus(Duration.ofSeconds(0, 1))); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_overflowTooSmall() { TaiInstant i = TaiInstant.ofTaiSeconds(Long.MIN_VALUE, 0); - i.plus(Duration.ofSeconds(-1, 999999999)); + assertThrows(ArithmeticException.class, () -> i.plus(Duration.ofSeconds(-1, 999999999))); } //----------------------------------------------------------------------- @@ -639,7 +632,7 @@ public static Object[][] data_minus() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_minus") public void test_minus(long seconds, int nanos, long minusSeconds, int minusNanos, long expectedSeconds, int expectedNanoOfSecond) { TaiInstant i = TaiInstant.ofTaiSeconds(seconds, nanos).minus(Duration.ofSeconds(minusSeconds, minusNanos)); @@ -647,16 +640,16 @@ public void test_minus(long seconds, int nanos, long minusSeconds, int minusNano assertEquals(expectedNanoOfSecond, i.getNano()); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_overflowTooSmall() { TaiInstant i = TaiInstant.ofTaiSeconds(Long.MIN_VALUE, 0); - i.minus(Duration.ofSeconds(0, 1)); + assertThrows(ArithmeticException.class, () -> i.minus(Duration.ofSeconds(0, 1))); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_overflowTooBig() { TaiInstant i = TaiInstant.ofTaiSeconds(Long.MAX_VALUE, 999999999); - i.minus(Duration.ofSeconds(-1, 999999999)); + assertThrows(ArithmeticException.class, () -> i.minus(Duration.ofSeconds(-1, 999999999))); } //----------------------------------------------------------------------- @@ -758,17 +751,17 @@ void doTest_comparisons_TaiInstant(TaiInstant... instants) { } } - @Test(expected = NullPointerException.class) + @Test public void test_compareTo_ObjectNull() { TaiInstant a = TaiInstant.ofTaiSeconds(0L, 0); - a.compareTo(null); + assertThrows(NullPointerException.class, () -> a.compareTo(null)); } - @Test(expected = ClassCastException.class) + @Test @SuppressWarnings({"unchecked", "rawtypes"}) public void test_compareToNonTaiInstant() { Comparable c = TaiInstant.ofTaiSeconds(0L, 2); - c.compareTo(new Object()); + assertThrows(ClassCastException.class, () -> c.compareTo(new Object())); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/scale/TestUtcInstant.java b/src/test/java/org/threeten/extra/scale/TestUtcInstant.java index eaf01781..e10e5450 100644 --- a/src/test/java/org/threeten/extra/scale/TestUtcInstant.java +++ b/src/test/java/org/threeten/extra/scale/TestUtcInstant.java @@ -31,10 +31,10 @@ */ package org.threeten.extra.scale; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -46,17 +46,15 @@ import java.time.Instant; import java.time.format.DateTimeParseException; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test UtcInstant. */ -@RunWith(DataProviderRunner.class) public class TestUtcInstant { private static final long MJD_1972_12_30 = 41681; @@ -132,19 +130,19 @@ public void factory_ofModifiedJulianDay_long_long_endLeap() { assertEquals("1972-12-31T23:59:60.999999999Z", t.toString()); } - @Test(expected = DateTimeException.class) + @Test public void factory_ofModifiedJulianDay_long_long_nanosNegative() { - UtcInstant.ofModifiedJulianDay(MJD_1973_01_01, -1); + assertThrows(DateTimeException.class, () -> UtcInstant.ofModifiedJulianDay(MJD_1973_01_01, -1)); } - @Test(expected = DateTimeException.class) + @Test public void factory_ofModifiedJulianDay_long_long_nanosTooBig_notLeap() { - UtcInstant.ofModifiedJulianDay(MJD_1973_01_01, NANOS_PER_DAY); + assertThrows(DateTimeException.class, () -> UtcInstant.ofModifiedJulianDay(MJD_1973_01_01, NANOS_PER_DAY)); } - @Test(expected = DateTimeException.class) + @Test public void factory_ofModifiedJulianDay_long_long_nanosTooBig_leap() { - UtcInstant.ofModifiedJulianDay(MJD_1972_12_31_LEAP, NANOS_PER_LEAP_DAY); + assertThrows(DateTimeException.class, () -> UtcInstant.ofModifiedJulianDay(MJD_1972_12_31_LEAP, NANOS_PER_LEAP_DAY)); } //----------------------------------------------------------------------- @@ -157,9 +155,9 @@ public void factory_of_Instant() { assertEquals(2, test.getNanoOfDay()); } - @Test(expected = NullPointerException.class) + @Test public void factory_of_Instant_null() { - UtcInstant.of((Instant) null); + assertThrows(NullPointerException.class, () -> UtcInstant.of((Instant) null)); } //----------------------------------------------------------------------- @@ -176,9 +174,9 @@ public void factory_of_TaiInstant() { } } - @Test(expected = NullPointerException.class) + @Test public void factory_of_TaiInstant_null() { - UtcInstant.of((TaiInstant) null); + assertThrows(NullPointerException.class, () -> UtcInstant.of((TaiInstant) null)); } //----------------------------------------------------------------------- @@ -199,20 +197,20 @@ public static Object[][] data_badParse() { }; } - @Test(expected = DateTimeParseException.class) + @ParameterizedTest @UseDataProvider("data_badParse") public void factory_parse_CharSequence_invalid(String str) { - UtcInstant.parse(str); + assertThrows(DateTimeException.class, () -> UtcInstant.parse(str)); } - @Test(expected = DateTimeException.class) + @Test public void factory_parse_CharSequence_invalidLeapSecond() { - UtcInstant.parse("1972-11-11T23:59:60Z"); // leap second but not leap day + assertThrows(DateTimeException.class, () -> UtcInstant.parse("1972-11-11T23:59:60Z")); // leap second but not leap day } - @Test(expected = NullPointerException.class) + @Test public void factory_parse_CharSequence_null() { - UtcInstant.parse((String) null); + assertThrows(NullPointerException.class, () -> UtcInstant.parse((String) null)); } //----------------------------------------------------------------------- @@ -234,21 +232,16 @@ public static Object[][] data_withModifiedJulianDay() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_withModifiedJulianDay") public void test_withModifiedJulianDay(long mjd, long nanos, long newMjd, Long expectedMjd, Long expectedNanos) { UtcInstant i = UtcInstant.ofModifiedJulianDay(mjd, nanos); if (expectedMjd != null) { - i = i.withModifiedJulianDay(newMjd); - assertEquals(expectedMjd.longValue(), i.getModifiedJulianDay()); - assertEquals(expectedNanos.longValue(), i.getNanoOfDay()); + UtcInstant withModifiedJulianDay = i.withModifiedJulianDay(newMjd); + assertEquals(expectedMjd.longValue(), withModifiedJulianDay.getModifiedJulianDay()); + assertEquals(expectedNanos.longValue(), withModifiedJulianDay.getNanoOfDay()); } else { - try { - i = i.withModifiedJulianDay(newMjd); - fail(); - } catch (DateTimeException ex) { - // expected - } + assertThrows(DateTimeException.class, () -> i.withModifiedJulianDay(newMjd)); } } @@ -277,21 +270,16 @@ public static Object[][] data_withNanoOfDay() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_withNanoOfDay") public void test_withNanoOfDay(long mjd, long nanos, long newNanoOfDay, Long expectedMjd, Long expectedNanos) { UtcInstant i = UtcInstant.ofModifiedJulianDay(mjd, nanos); if (expectedMjd != null) { - i = i.withNanoOfDay(newNanoOfDay); - assertEquals(expectedMjd.longValue(), i.getModifiedJulianDay()); - assertEquals(expectedNanos.longValue(), i.getNanoOfDay()); + UtcInstant withNanoOfDay = i.withNanoOfDay(newNanoOfDay); + assertEquals(expectedMjd.longValue(), withNanoOfDay.getModifiedJulianDay()); + assertEquals(expectedNanos.longValue(), withNanoOfDay.getNanoOfDay()); } else { - try { - i = i.withNanoOfDay(newNanoOfDay); - fail(); - } catch (DateTimeException ex) { - // expected - } + assertThrows(DateTimeException.class, () -> i.withNanoOfDay(newNanoOfDay)); } } @@ -333,7 +321,7 @@ public static Object[][] data_plus() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_plus") public void test_plus(long mjd, long nanos, long plusSeconds, int plusNanos, long expectedMjd, long expectedNanos) { UtcInstant i = UtcInstant.ofModifiedJulianDay(mjd, nanos).plus(Duration.ofSeconds(plusSeconds, plusNanos)); @@ -341,16 +329,16 @@ public void test_plus(long mjd, long nanos, long plusSeconds, int plusNanos, lon assertEquals(expectedNanos, i.getNanoOfDay()); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_overflowTooBig() { UtcInstant i = UtcInstant.ofModifiedJulianDay(Long.MAX_VALUE, NANOS_PER_DAY - 1); - i.plus(Duration.ofNanos(1)); + assertThrows(ArithmeticException.class, () -> i.plus(Duration.ofNanos(1))); } - @Test(expected = ArithmeticException.class) + @Test public void test_plus_overflowTooSmall() { UtcInstant i = UtcInstant.ofModifiedJulianDay(Long.MIN_VALUE, 0); - i.plus(Duration.ofNanos(-1)); + assertThrows(ArithmeticException.class, () -> i.plus(Duration.ofNanos(-1))); } //----------------------------------------------------------------------- @@ -391,7 +379,7 @@ public static Object[][] data_minus() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_minus") public void test_minus(long mjd, long nanos, long minusSeconds, int minusNanos, long expectedMjd, long expectedNanos) { UtcInstant i = UtcInstant.ofModifiedJulianDay(mjd, nanos).minus(Duration.ofSeconds(minusSeconds, minusNanos)); @@ -399,16 +387,16 @@ public void test_minus(long mjd, long nanos, long minusSeconds, int minusNanos, assertEquals(expectedNanos, i.getNanoOfDay()); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_overflowTooSmall() { UtcInstant i = UtcInstant.ofModifiedJulianDay(Long.MIN_VALUE, 0); - i.minus(Duration.ofNanos(1)); + assertThrows(ArithmeticException.class, () -> i.minus(Duration.ofNanos(1))); } - @Test(expected = ArithmeticException.class) + @Test public void test_minus_overflowTooBig() { UtcInstant i = UtcInstant.ofModifiedJulianDay(Long.MAX_VALUE, NANOS_PER_DAY - 1); - i.minus(Duration.ofNanos(-1)); + assertThrows(ArithmeticException.class, () -> i.minus(Duration.ofNanos(-1))); } //----------------------------------------------------------------------- @@ -456,10 +444,10 @@ public void test_toTaiInstant() { } } - @Test(expected = ArithmeticException.class) + @Test public void test_toTaiInstant_maxInvalid() { UtcInstant utc = UtcInstant.ofModifiedJulianDay(Long.MAX_VALUE, 0); - utc.toTaiInstant(); + assertThrows(ArithmeticException.class, () -> utc.toTaiInstant()); } //----------------------------------------------------------------------- @@ -517,17 +505,17 @@ void doTest_comparisons_UtcInstant(UtcInstant... instants) { } } - @Test(expected = NullPointerException.class) + @Test public void test_compareTo_ObjectNull() { UtcInstant a = UtcInstant.ofModifiedJulianDay(0L, 0); - a.compareTo(null); + assertThrows(NullPointerException.class, () -> a.compareTo(null)); } - @Test(expected = ClassCastException.class) + @Test @SuppressWarnings({"unchecked", "rawtypes"}) public void test_compareToNonUtcInstant() { Comparable c = UtcInstant.ofModifiedJulianDay(0L, 2); - c.compareTo(new Object()); + assertThrows(ClassCastException.class, () -> c.compareTo(new Object())); } //----------------------------------------------------------------------- @@ -613,13 +601,13 @@ public static Object[][] data_toString() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_toString") public void test_toString(long mjd, long nod, String expected) { assertEquals(expected, UtcInstant.ofModifiedJulianDay(mjd, nod).toString()); } - @Test + @ParameterizedTest @UseDataProvider("data_toString") public void test_toString_parse(long mjd, long nod, String str) { assertEquals(UtcInstant.ofModifiedJulianDay(mjd, nod), UtcInstant.parse(str)); diff --git a/src/test/java/org/threeten/extra/scale/TestUtcRules.java b/src/test/java/org/threeten/extra/scale/TestUtcRules.java index 51b23913..fe84bda8 100644 --- a/src/test/java/org/threeten/extra/scale/TestUtcRules.java +++ b/src/test/java/org/threeten/extra/scale/TestUtcRules.java @@ -31,9 +31,10 @@ */ package org.threeten.extra.scale; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -49,23 +50,21 @@ import java.time.temporal.JulianFields; import java.util.Arrays; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; -import com.tngtech.java.junit.dataprovider.DataProvider; -import com.tngtech.java.junit.dataprovider.DataProviderRunner; -import com.tngtech.java.junit.dataprovider.UseDataProvider; +import com.tngtech.junit.dataprovider.DataProvider; +import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test SystemLeapSecondRules. */ -@RunWith(DataProviderRunner.class) public class TestUtcRules { SystemUtcRules rules; - @Before + @BeforeEach public void setUp() throws Exception { Constructor con = SystemUtcRules.class.getDeclaredConstructor(); con.setAccessible(true); @@ -237,7 +236,7 @@ public static Object[][] data_leapSeconds() { }; } - @Test + @ParameterizedTest @UseDataProvider("data_leapSeconds") public void test_leapSeconds(long mjd, int adjust, int offset, String checkDate) { assertEquals(LocalDate.parse(checkDate).getLong(JulianFields.MODIFIED_JULIAN_DAY), mjd); @@ -349,14 +348,14 @@ public void test_convertToUtc_TaiInstant_2100() { assertEquals(tai, rules.convertToTai(expected)); // check reverse } - @Test(expected = NullPointerException.class) + @Test public void test_convertToUtc_TaiInstant_null() { - rules.convertToUtc((TaiInstant) null); + assertThrows(NullPointerException.class, () -> rules.convertToUtc((TaiInstant) null)); } - @Test(expected = NullPointerException.class) + @Test public void test_convertToTai_UtcInstant_null() { - rules.convertToTai((UtcInstant) null); + assertThrows(NullPointerException.class, () -> rules.convertToTai((UtcInstant) null)); } //------------------------------------------------------------------------- @@ -518,42 +517,42 @@ public void test_registerLeapSecond_equalEarlierDate_sameLeap() { assertEquals(adj, rules.getLeapSecondAdjustment(mjd)); } - @Test(expected = IllegalArgumentException.class) + @Test public void test_registerLeapSecond_equalLastDate_differentLeap() { long[] dates = rules.getLeapSecondDates(); long mjd = dates[dates.length - 1]; int adj = rules.getLeapSecondAdjustment(mjd); - rules.register(mjd, -adj); + assertThrows(IllegalArgumentException.class, () -> rules.register(mjd, -adj)); } - @Test(expected = IllegalArgumentException.class) + @Test public void test_registerLeapSecond_equalEarlierDate_differentLeap() { long[] dates = rules.getLeapSecondDates(); long mjd = dates[dates.length - 2]; int adj = rules.getLeapSecondAdjustment(mjd); - rules.register(mjd, -adj); + assertThrows(IllegalArgumentException.class, () -> rules.register(mjd, -adj)); } - @Test(expected = IllegalArgumentException.class) + @Test public void test_registerLeapSecond_beforeLastDate() { long[] dates = rules.getLeapSecondDates(); long mjd = dates[dates.length - 1] - 1; - rules.register(mjd, 1); + assertThrows(IllegalArgumentException.class, () -> rules.register(mjd, 1)); } - @Test(expected = IllegalArgumentException.class) + @Test public void test_registerLeapSecond_invalidAdjustment_zero() { - rules.register(MJD_2100, 0); + assertThrows(IllegalArgumentException.class, () -> rules.register(MJD_2100, 0)); } - @Test(expected = IllegalArgumentException.class) + @Test public void test_registerLeapSecond_invalidAdjustment_minusTwo() { - rules.register(MJD_2100, -2); + assertThrows(IllegalArgumentException.class, () -> rules.register(MJD_2100, -2)); } - @Test(expected = IllegalArgumentException.class) + @Test public void test_registerLeapSecond_invalidAdjustment_three() { - rules.register(MJD_2100, 3); + assertThrows(IllegalArgumentException.class, () -> rules.register(MJD_2100, 3)); } //----------------------------------------------------------------------- From ab9adfdff0b6719b471332368c3f8acfc6a48939 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Wed, 3 Mar 2021 22:52:57 +0000 Subject: [PATCH 195/279] Organize imports --- src/test/java/org/threeten/extra/TestConvert.java | 1 - src/test/java/org/threeten/extra/TestMonths.java | 2 -- src/test/java/org/threeten/extra/TestYearQuarter.java | 1 - src/test/java/org/threeten/extra/scale/TestUtcInstant.java | 1 - 4 files changed, 5 deletions(-) diff --git a/src/test/java/org/threeten/extra/TestConvert.java b/src/test/java/org/threeten/extra/TestConvert.java index 9db548f1..b646fec5 100644 --- a/src/test/java/org/threeten/extra/TestConvert.java +++ b/src/test/java/org/threeten/extra/TestConvert.java @@ -40,7 +40,6 @@ import org.joda.convert.StringConvert; import org.junit.jupiter.params.ParameterizedTest; - import org.threeten.extra.scale.TaiInstant; import org.threeten.extra.scale.UtcInstant; diff --git a/src/test/java/org/threeten/extra/TestMonths.java b/src/test/java/org/threeten/extra/TestMonths.java index de5a6862..30083d0d 100644 --- a/src/test/java/org/threeten/extra/TestMonths.java +++ b/src/test/java/org/threeten/extra/TestMonths.java @@ -57,8 +57,6 @@ import com.tngtech.junit.dataprovider.DataProvider; import com.tngtech.junit.dataprovider.UseDataProvider; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; /** * Test class. diff --git a/src/test/java/org/threeten/extra/TestYearQuarter.java b/src/test/java/org/threeten/extra/TestYearQuarter.java index e4caecc4..90e777b2 100644 --- a/src/test/java/org/threeten/extra/TestYearQuarter.java +++ b/src/test/java/org/threeten/extra/TestYearQuarter.java @@ -113,7 +113,6 @@ import java.util.stream.Stream; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; /** * Test YearQuarter. diff --git a/src/test/java/org/threeten/extra/scale/TestUtcInstant.java b/src/test/java/org/threeten/extra/scale/TestUtcInstant.java index e10e5450..78127f3f 100644 --- a/src/test/java/org/threeten/extra/scale/TestUtcInstant.java +++ b/src/test/java/org/threeten/extra/scale/TestUtcInstant.java @@ -44,7 +44,6 @@ import java.time.DateTimeException; import java.time.Duration; import java.time.Instant; -import java.time.format.DateTimeParseException; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; From e7e0512dd33b4aa855eb66c40b6bc08eec8b770f Mon Sep 17 00:00:00 2001 From: Steven Paligo Date: Sun, 14 Mar 2021 22:27:33 -0600 Subject: [PATCH 196/279] Fixed incorrect comment on UtcInstant#parse(CharSequence) that implied it can parse TAI instants --- src/main/java/org/threeten/extra/scale/UtcInstant.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/threeten/extra/scale/UtcInstant.java b/src/main/java/org/threeten/extra/scale/UtcInstant.java index 40fe58c2..16a63fa9 100644 --- a/src/main/java/org/threeten/extra/scale/UtcInstant.java +++ b/src/main/java/org/threeten/extra/scale/UtcInstant.java @@ -196,12 +196,12 @@ public static UtcInstant of(TaiInstant instant) { //------------------------------------------------------------------------- /** * Obtains an instance of {@code UtcInstant} from a text string - * {@code 2007-12-03T10:15:30.00Z}. + * (e.g. {@code 2007-12-03T10:15:30.00Z}). *

      * The string must represent a valid instant in UTC and is parsed using * {@link DateTimeFormatter#ISO_INSTANT} with leap seconds handled. * - * @param text the text to parse such as "12345.123456789s(TAI)", not null + * @param text the text to parse such as "2007-12-03T10:15:30.00Z", not null * @return the parsed instant, not null * @throws DateTimeParseException if the text cannot be parsed * @throws DateTimeException if parsed text represents an invalid leap second From 46e785fe0dd3247536431c1a254211da5a95ca11 Mon Sep 17 00:00:00 2001 From: Steven Paligo Date: Sun, 14 Mar 2021 23:31:26 -0600 Subject: [PATCH 197/279] Cache the result of UtcInstant#toString() in case it is called multiple times (it is an expensive operation) --- .../java/org/threeten/extra/scale/UtcInstant.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/threeten/extra/scale/UtcInstant.java b/src/main/java/org/threeten/extra/scale/UtcInstant.java index 16a63fa9..d02eae25 100644 --- a/src/main/java/org/threeten/extra/scale/UtcInstant.java +++ b/src/main/java/org/threeten/extra/scale/UtcInstant.java @@ -121,12 +121,18 @@ public final class UtcInstant * The Modified Julian Day, from the epoch of 1858-11-17. */ private final long mjDay; + /** * The number of nanoseconds, later along the time-line, from the MJD field. * This is always positive and includes leap seconds. */ private final long nanoOfDay; + /** + * A cache of the result from {@link #toString()} + */ + private transient String stringValue = null; + //----------------------------------------------------------------------- /** * Obtains an instance of {@code UtcInstant} from a Modified Julian Day with @@ -467,6 +473,9 @@ public int hashCode() { @Override @ToString public String toString() { + if (stringValue != null) { + return stringValue; + } LocalDate date = LocalDate.MAX.with(JulianFields.MODIFIED_JULIAN_DAY, mjDay); // TODO: capacity/import issues StringBuilder buf = new StringBuilder(30); int sod = (int) (nanoOfDay / NANOS_PER_SECOND); @@ -494,7 +503,7 @@ public String toString() { } } buf.append('Z'); - return buf.toString(); + stringValue = buf.toString(); + return stringValue; } - } From c9f23c34c80ca8f35864530d88cefa64665deebc Mon Sep 17 00:00:00 2001 From: Steven Paligo Date: Sun, 21 Mar 2021 00:08:43 -0600 Subject: [PATCH 198/279] Fixed newline changes that violate the project's code format standards --- src/main/java/org/threeten/extra/scale/UtcInstant.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/threeten/extra/scale/UtcInstant.java b/src/main/java/org/threeten/extra/scale/UtcInstant.java index d02eae25..c13a7093 100644 --- a/src/main/java/org/threeten/extra/scale/UtcInstant.java +++ b/src/main/java/org/threeten/extra/scale/UtcInstant.java @@ -121,13 +121,11 @@ public final class UtcInstant * The Modified Julian Day, from the epoch of 1858-11-17. */ private final long mjDay; - /** * The number of nanoseconds, later along the time-line, from the MJD field. * This is always positive and includes leap seconds. */ private final long nanoOfDay; - /** * A cache of the result from {@link #toString()} */ @@ -506,4 +504,5 @@ public String toString() { stringValue = buf.toString(); return stringValue; } + } From 9f997a3ed65877307a63d76dacfd3e952425cde6 Mon Sep 17 00:00:00 2001 From: Steven Paligo Date: Sun, 21 Mar 2021 00:15:01 -0600 Subject: [PATCH 199/279] Fixed comment so it doesn't confuse Javadoc --- src/main/java/org/threeten/extra/scale/UtcInstant.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/threeten/extra/scale/UtcInstant.java b/src/main/java/org/threeten/extra/scale/UtcInstant.java index c13a7093..a3de0b15 100644 --- a/src/main/java/org/threeten/extra/scale/UtcInstant.java +++ b/src/main/java/org/threeten/extra/scale/UtcInstant.java @@ -199,8 +199,8 @@ public static UtcInstant of(TaiInstant instant) { //------------------------------------------------------------------------- /** - * Obtains an instance of {@code UtcInstant} from a text string - * (e.g. {@code 2007-12-03T10:15:30.00Z}). + * Obtains an instance of {@code UtcInstant} from a text string, + * such as {@code 2007-12-03T10:15:30.00Z}. *

      * The string must represent a valid instant in UTC and is parsed using * {@link DateTimeFormatter#ISO_INSTANT} with leap seconds handled. From dd50dfe858641c32e84b6090dc720c835f9aab40 Mon Sep 17 00:00:00 2001 From: Steven Paligo Date: Mon, 22 Mar 2021 12:42:25 -0600 Subject: [PATCH 200/279] Split UtcInstant#toString() into hot and cold methods that conform to the racy single-check idiom --- .../org/threeten/extra/scale/UtcInstant.java | 75 +++++++++++-------- 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/src/main/java/org/threeten/extra/scale/UtcInstant.java b/src/main/java/org/threeten/extra/scale/UtcInstant.java index a3de0b15..972600e5 100644 --- a/src/main/java/org/threeten/extra/scale/UtcInstant.java +++ b/src/main/java/org/threeten/extra/scale/UtcInstant.java @@ -471,38 +471,51 @@ public int hashCode() { @Override @ToString public String toString() { - if (stringValue != null) { - return stringValue; + String currentStringValue = stringValue; + if (currentStringValue == null) { + stringValue = currentStringValue = calculateStringValue(); } - LocalDate date = LocalDate.MAX.with(JulianFields.MODIFIED_JULIAN_DAY, mjDay); // TODO: capacity/import issues - StringBuilder buf = new StringBuilder(30); - int sod = (int) (nanoOfDay / NANOS_PER_SECOND); - int hourValue = sod / (60 * 60); - int minuteValue = (sod / 60) % 60; - int secondValue = sod % 60; - int nanoValue = (int) (nanoOfDay % NANOS_PER_SECOND); - if (hourValue == 24) { - hourValue = 23; - minuteValue = 59; - secondValue = 60; - } - buf.append(date).append('T') - .append(hourValue < 10 ? "0" : "").append(hourValue) - .append(minuteValue < 10 ? ":0" : ":").append(minuteValue) - .append(secondValue < 10 ? ":0" : ":").append(secondValue); - if (nanoValue > 0) { - buf.append('.'); - if (nanoValue % 1000_000 == 0) { - buf.append(Integer.toString((nanoValue / 1000_000) + 1000).substring(1)); - } else if (nanoValue % 1000 == 0) { - buf.append(Integer.toString((nanoValue / 1000) + 1000_000).substring(1)); - } else { - buf.append(Integer.toString((nanoValue) + 1000_000_000).substring(1)); - } - } - buf.append('Z'); - stringValue = buf.toString(); - return stringValue; + return currentStringValue; + } + + /** + * Calculates a string representation of this instant. + *

      + * The string is formatted using ISO-8601. + * The output includes seconds, 9 nanosecond digits and a trailing 'Z'. + * The time-of-day will be 23:59:60 during a positive leap second. + * + * @return a representation of this instant, not null + */ + private String calculateStringValue() { + LocalDate date = LocalDate.MAX.with(JulianFields.MODIFIED_JULIAN_DAY, mjDay); // TODO: capacity/import issues + StringBuilder buf = new StringBuilder(30); + int sod = (int) (nanoOfDay / NANOS_PER_SECOND); + int hourValue = sod / (60 * 60); + int minuteValue = (sod / 60) % 60; + int secondValue = sod % 60; + int nanoValue = (int) (nanoOfDay % NANOS_PER_SECOND); + if (hourValue == 24) { + hourValue = 23; + minuteValue = 59; + secondValue = 60; + } + buf.append(date).append('T') + .append(hourValue < 10 ? "0" : "").append(hourValue) + .append(minuteValue < 10 ? ":0" : ":").append(minuteValue) + .append(secondValue < 10 ? ":0" : ":").append(secondValue); + if (nanoValue > 0) { + buf.append('.'); + if (nanoValue % 1000_000 == 0) { + buf.append(Integer.toString((nanoValue / 1000_000) + 1000).substring(1)); + } else if (nanoValue % 1000 == 0) { + buf.append(Integer.toString((nanoValue / 1000) + 1000_000).substring(1)); + } else { + buf.append(Integer.toString((nanoValue) + 1000_000_000).substring(1)); + } + } + buf.append('Z'); + return buf.toString(); } } From a02685b2e41053b3b3bb2b290e703c841dd94f9a Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sat, 27 Mar 2021 13:03:23 +0000 Subject: [PATCH 201/279] Update after PR --- pom.xml | 4 + src/changes/changes.xml | 6 ++ .../org/threeten/extra/scale/UtcInstant.java | 75 +++++++++---------- 3 files changed, 44 insertions(+), 41 deletions(-) diff --git a/pom.xml b/pom.xml index 757121c7..c42e1a65 100644 --- a/pom.xml +++ b/pom.xml @@ -98,6 +98,10 @@ JB Nizet https://github.com/jnizet + + Steven Paligo + https://github.com/stevenpaligo + Bjørn Erik Pedersen https://github.com/bep diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 79bd2acf..03687cac 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,6 +7,12 @@ + + + Cache UtcInstant::toString(). + Fixes #177. + + Add OffsetDate. diff --git a/src/main/java/org/threeten/extra/scale/UtcInstant.java b/src/main/java/org/threeten/extra/scale/UtcInstant.java index 972600e5..da1a243c 100644 --- a/src/main/java/org/threeten/extra/scale/UtcInstant.java +++ b/src/main/java/org/threeten/extra/scale/UtcInstant.java @@ -129,7 +129,7 @@ public final class UtcInstant /** * A cache of the result from {@link #toString()} */ - private transient String stringValue = null; + private transient String toString; //----------------------------------------------------------------------- /** @@ -471,51 +471,44 @@ public int hashCode() { @Override @ToString public String toString() { - String currentStringValue = stringValue; + // racy single-check idiom + String currentStringValue = toString; if (currentStringValue == null) { - stringValue = currentStringValue = calculateStringValue(); + toString = currentStringValue = buildToString(); } return currentStringValue; } - /** - * Calculates a string representation of this instant. - *

      - * The string is formatted using ISO-8601. - * The output includes seconds, 9 nanosecond digits and a trailing 'Z'. - * The time-of-day will be 23:59:60 during a positive leap second. - * - * @return a representation of this instant, not null - */ - private String calculateStringValue() { - LocalDate date = LocalDate.MAX.with(JulianFields.MODIFIED_JULIAN_DAY, mjDay); // TODO: capacity/import issues - StringBuilder buf = new StringBuilder(30); - int sod = (int) (nanoOfDay / NANOS_PER_SECOND); - int hourValue = sod / (60 * 60); - int minuteValue = (sod / 60) % 60; - int secondValue = sod % 60; - int nanoValue = (int) (nanoOfDay % NANOS_PER_SECOND); - if (hourValue == 24) { - hourValue = 23; - minuteValue = 59; - secondValue = 60; - } - buf.append(date).append('T') - .append(hourValue < 10 ? "0" : "").append(hourValue) - .append(minuteValue < 10 ? ":0" : ":").append(minuteValue) - .append(secondValue < 10 ? ":0" : ":").append(secondValue); - if (nanoValue > 0) { - buf.append('.'); - if (nanoValue % 1000_000 == 0) { - buf.append(Integer.toString((nanoValue / 1000_000) + 1000).substring(1)); - } else if (nanoValue % 1000 == 0) { - buf.append(Integer.toString((nanoValue / 1000) + 1000_000).substring(1)); - } else { - buf.append(Integer.toString((nanoValue) + 1000_000_000).substring(1)); - } - } - buf.append('Z'); - return buf.toString(); + // produces the string representation of this instant + private String buildToString() { + LocalDate date = LocalDate.MAX.with(JulianFields.MODIFIED_JULIAN_DAY, mjDay); // TODO: capacity/import issues + StringBuilder buf = new StringBuilder(30); + int sod = (int) (nanoOfDay / NANOS_PER_SECOND); + int hourValue = sod / (60 * 60); + int minuteValue = (sod / 60) % 60; + int secondValue = sod % 60; + int nanoValue = (int) (nanoOfDay % NANOS_PER_SECOND); + if (hourValue == 24) { + hourValue = 23; + minuteValue = 59; + secondValue = 60; + } + buf.append(date).append('T') + .append(hourValue < 10 ? "0" : "").append(hourValue) + .append(minuteValue < 10 ? ":0" : ":").append(minuteValue) + .append(secondValue < 10 ? ":0" : ":").append(secondValue); + if (nanoValue > 0) { + buf.append('.'); + if (nanoValue % 1000_000 == 0) { + buf.append(Integer.toString((nanoValue / 1000_000) + 1000).substring(1)); + } else if (nanoValue % 1000 == 0) { + buf.append(Integer.toString((nanoValue / 1000) + 1000_000).substring(1)); + } else { + buf.append(Integer.toString((nanoValue) + 1000_000_000).substring(1)); + } + } + buf.append('Z'); + return buf.toString(); } } From 0f56b86c914724be1d49520f76311646467fb818 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Fri, 2 Apr 2021 10:33:05 +0100 Subject: [PATCH 202/279] Enhance OffsetDate tests Fixes #181 --- src/changes/changes.xml | 4 + .../org/threeten/extra/TestOffsetDate.java | 621 ++++++++---------- 2 files changed, 292 insertions(+), 333 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 03687cac..bf9168ba 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -12,6 +12,10 @@ Cache UtcInstant::toString(). Fixes #177. + + Enhance OffsetDate tests. + Fixes #181. + diff --git a/src/test/java/org/threeten/extra/TestOffsetDate.java b/src/test/java/org/threeten/extra/TestOffsetDate.java index 16dc0b2f..616d293b 100644 --- a/src/test/java/org/threeten/extra/TestOffsetDate.java +++ b/src/test/java/org/threeten/extra/TestOffsetDate.java @@ -61,7 +61,6 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; -import java.time.Month; import java.time.OffsetDateTime; import java.time.Period; import java.time.Year; @@ -103,7 +102,7 @@ public class TestOffsetDate extends AbstractDateTimeTest { @BeforeEach public void setUp() { - TEST_2007_07_15_PONE = OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PONE); + TEST_2007_07_15_PONE = OffsetDate.of(2007, 7, 15, OFFSET_PONE); } //----------------------------------------------------------------------- @@ -228,89 +227,45 @@ private void check(OffsetDate test, int y, int mo, int d, ZoneOffset offset) { assertEquals(test, test); assertEquals(test.hashCode(), test.hashCode()); + assertEquals(test, OffsetDate.of(y, mo, d, offset)); assertEquals(test, OffsetDate.of(LocalDate.of(y, mo, d), offset)); } - //----------------------------------------------------------------------- - @Test - public void factory_of_intMonthInt() { - OffsetDate test = OffsetDate.of(LocalDate.of(2007, Month.JULY, 15), OFFSET_PONE); - check(test, 2007, 7, 15, OFFSET_PONE); - } - - //----------------------------------------------------------------------- - @Test - public void factory_of_ints() { - OffsetDate test = OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PONE); - check(test, 2007, 7, 15, OFFSET_PONE); - } - - //----------------------------------------------------------------------- - @Test - public void factory_of_intsMonthOffset() { - assertEquals(OffsetDate.of(LocalDate.of(2007, Month.JULY, 15), OFFSET_PONE), TEST_2007_07_15_PONE); - } - - @Test - public void factory_of_intsMonthOffset_dayTooLow() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(2007, Month.JANUARY, 0), OFFSET_PONE)); - } - - @Test - public void factory_of_intsMonthOffset_dayTooHigh() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(2007, Month.JANUARY, 32), OFFSET_PONE)); - } - - @Test - public void factory_of_intsMonthOffset_nullMonth() { - assertThrows(NullPointerException.class, () -> OffsetDate.of(LocalDate.of(2007, null, 30), OFFSET_PONE)); - } - - @Test - public void factory_of_intsMonthOffset_yearTooLow() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Integer.MIN_VALUE, Month.JANUARY, 1), OFFSET_PONE)); - } - - @Test - public void factory_of_intsMonthOffset_nullOffset() { - assertThrows(NullPointerException.class, () -> OffsetDate.of(LocalDate.of(2007, Month.JANUARY, 30), null)); - } - //----------------------------------------------------------------------- @Test public void factory_of_intsOffset() { - OffsetDate test = OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PONE); + OffsetDate test = OffsetDate.of(2007, 7, 15, OFFSET_PONE); check(test, 2007, 7, 15, OFFSET_PONE); } @Test public void factory_of_ints_dayTooLow() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(2007, 1, 0), OFFSET_PONE)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(2007, 1, 0, OFFSET_PONE)); } @Test public void factory_of_ints_dayTooHigh() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(2007, 1, 32), OFFSET_PONE)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(2007, 1, 32, OFFSET_PONE)); } @Test public void factory_of_ints_monthTooLow() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(2007, 0, 1), OFFSET_PONE)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(2007, 0, 1, OFFSET_PONE)); } @Test public void factory_of_ints_monthTooHigh() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(2007, 13, 1), OFFSET_PONE)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(2007, 13, 1, OFFSET_PONE)); } @Test public void factory_of_ints_yearTooLow() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Integer.MIN_VALUE, 1, 1), OFFSET_PONE)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(Integer.MIN_VALUE, 1, 1, OFFSET_PONE)); } @Test public void factory_of_ints_nullOffset() { - assertThrows(NullPointerException.class, () -> OffsetDate.of(LocalDate.of(2007, 1, 1), (ZoneOffset) null)); + assertThrows(NullPointerException.class, () -> OffsetDate.of(2007, 1, 1, (ZoneOffset) null)); } //----------------------------------------------------------------------- @@ -420,7 +375,7 @@ public void factory_parse_nullText() { public void factory_parse_formatter() { DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d XXX"); OffsetDate test = OffsetDate.parse("2010 12 3 +01:00", f); - assertEquals(OffsetDate.of(LocalDate.of(2010, 12, 3), ZoneOffset.ofHours(1)), test); + assertEquals(OffsetDate.of(2010, 12, 3, ZoneOffset.ofHours(1)), test); } @Test @@ -514,7 +469,7 @@ public void test_isSupported_TemporalUnit() { //----------------------------------------------------------------------- @Test public void test_get_TemporalField() { - OffsetDate test = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); + OffsetDate test = OffsetDate.of(2008, 6, 30, OFFSET_PONE); assertEquals(2008, test.get(ChronoField.YEAR)); assertEquals(6, test.get(ChronoField.MONTH_OF_YEAR)); assertEquals(30, test.get(ChronoField.DAY_OF_MONTH)); @@ -526,7 +481,7 @@ public void test_get_TemporalField() { @Test public void test_getLong_TemporalField() { - OffsetDate test = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); + OffsetDate test = OffsetDate.of(2008, 6, 30, OFFSET_PONE); assertEquals(2008, test.getLong(ChronoField.YEAR)); assertEquals(6, test.getLong(ChronoField.MONTH_OF_YEAR)); assertEquals(30, test.getLong(ChronoField.DAY_OF_MONTH)); @@ -623,7 +578,7 @@ public void test_until_invalidType() { //----------------------------------------------------------------------- @Test public void test_withOffsetSameLocal() { - OffsetDate base = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); + OffsetDate base = OffsetDate.of(2008, 6, 30, OFFSET_PONE); OffsetDate test = base.withOffsetSameLocal(OFFSET_PTWO); assertEquals(base.toLocalDate(), test.toLocalDate()); assertEquals(OFFSET_PTWO, test.getOffset()); @@ -631,7 +586,7 @@ public void test_withOffsetSameLocal() { @Test public void test_withOffsetSameLocal_noChange() { - OffsetDate base = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); + OffsetDate base = OffsetDate.of(2008, 6, 30, OFFSET_PONE); OffsetDate test = base.withOffsetSameLocal(OFFSET_PONE); assertEquals(base, test); } @@ -646,7 +601,7 @@ public void test_withOffsetSameLocal_null() { //----------------------------------------------------------------------- @Test public void test_with_adjustment() { - final OffsetDate sample = OffsetDate.of(LocalDate.of(2012, 3, 4), OFFSET_PONE); + final OffsetDate sample = OffsetDate.of(2012, 3, 4, OFFSET_PONE); TemporalAdjuster adjuster = dateTime -> sample; assertEquals(sample, TEST_2007_07_15_PONE.with(adjuster)); } @@ -654,30 +609,30 @@ public void test_with_adjustment() { @Test public void test_with_adjustment_LocalDate() { OffsetDate test = TEST_2007_07_15_PONE.with(LocalDate.of(2008, 6, 30)); - assertEquals(OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE), test); + assertEquals(OffsetDate.of(2008, 6, 30, OFFSET_PONE), test); } @Test public void test_with_adjustment_OffsetDate() { - OffsetDate test = TEST_2007_07_15_PONE.with(OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO)); - assertEquals(OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO), test); + OffsetDate test = TEST_2007_07_15_PONE.with(OffsetDate.of(2008, 6, 30, OFFSET_PTWO)); + assertEquals(OffsetDate.of(2008, 6, 30, OFFSET_PTWO), test); } @Test public void test_with_adjustment_ZoneOffset() { OffsetDate test = TEST_2007_07_15_PONE.with(OFFSET_PTWO); - assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PTWO), test); + assertEquals(OffsetDate.of(2007, 7, 15, OFFSET_PTWO), test); } @Test public void test_with_adjustment_Month() { OffsetDate test = TEST_2007_07_15_PONE.with(DECEMBER); - assertEquals(OffsetDate.of(LocalDate.of(2007, 12, 15), OFFSET_PONE), test); + assertEquals(OffsetDate.of(2007, 12, 15, OFFSET_PONE), test); } @Test public void test_with_adjustment_offsetUnchanged() { - OffsetDate base = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); + OffsetDate base = OffsetDate.of(2008, 6, 30, OFFSET_PONE); OffsetDate test = base.with(Year.of(2008)); assertEquals(base, test); } @@ -700,14 +655,14 @@ public void test_with_adjustment_null() { //----------------------------------------------------------------------- @Test public void test_with_TemporalField() { - OffsetDate test = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); - assertEquals(OffsetDate.of(LocalDate.of(2009, 6, 30), OFFSET_PONE), test.with(ChronoField.YEAR, 2009)); - assertEquals(OffsetDate.of(LocalDate.of(2008, 7, 30), OFFSET_PONE), test.with(ChronoField.MONTH_OF_YEAR, 7)); - assertEquals(OffsetDate.of(LocalDate.of(2008, 6, 1), OFFSET_PONE), test.with(ChronoField.DAY_OF_MONTH, 1)); - assertEquals(OffsetDate.of(LocalDate.of(2008, 7, 1), OFFSET_PONE), test.with(ChronoField.DAY_OF_WEEK, 2)); - assertEquals(OffsetDate.of(LocalDate.of(2008, 7, 1), OFFSET_PONE), test.with(ChronoField.DAY_OF_YEAR, 183)); + OffsetDate test = OffsetDate.of(2008, 6, 30, OFFSET_PONE); + assertEquals(OffsetDate.of(2009, 6, 30, OFFSET_PONE), test.with(ChronoField.YEAR, 2009)); + assertEquals(OffsetDate.of(2008, 7, 30, OFFSET_PONE), test.with(ChronoField.MONTH_OF_YEAR, 7)); + assertEquals(OffsetDate.of(2008, 6, 1, OFFSET_PONE), test.with(ChronoField.DAY_OF_MONTH, 1)); + assertEquals(OffsetDate.of(2008, 7, 1, OFFSET_PONE), test.with(ChronoField.DAY_OF_WEEK, 2)); + assertEquals(OffsetDate.of(2008, 7, 1, OFFSET_PONE), test.with(ChronoField.DAY_OF_YEAR, 183)); - assertEquals(OffsetDate.of(LocalDate.of(2008, 6, 30), ZoneOffset.ofHoursMinutesSeconds(2, 0, 5)), test.with(ChronoField.OFFSET_SECONDS, 7205)); + assertEquals(OffsetDate.of(2008, 6, 30, ZoneOffset.ofHoursMinutesSeconds(2, 0, 5)), test.with(ChronoField.OFFSET_SECONDS, 7205)); } @Test @@ -726,7 +681,7 @@ public void test_with_TemporalField_invalidField() { @Test public void test_withYear_int_normal() { OffsetDate t = TEST_2007_07_15_PONE.withYear(2008); - assertEquals(OffsetDate.of(LocalDate.of(2008, 7, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2008, 7, 15, OFFSET_PONE), t); } @Test @@ -742,8 +697,8 @@ public void test_withYear_int_invalid() { @Test public void test_withYear_int_adjustDay() { - OffsetDate t = OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PONE).withYear(2007); - OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PONE); + OffsetDate t = OffsetDate.of(2008, 2, 29, OFFSET_PONE).withYear(2007); + OffsetDate expected = OffsetDate.of(2007, 2, 28, OFFSET_PONE); assertEquals(expected, t); } @@ -753,7 +708,7 @@ public void test_withYear_int_adjustDay() { @Test public void test_withMonth_int_normal() { OffsetDate t = TEST_2007_07_15_PONE.withMonth(1); - assertEquals(OffsetDate.of(LocalDate.of(2007, 1, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 1, 15, OFFSET_PONE), t); } @Test @@ -769,8 +724,8 @@ public void test_withMonth_int_invalid() { @Test public void test_withMonth_int_adjustDay() { - OffsetDate t = OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PONE).withMonth(11); - OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 11, 30), OFFSET_PONE); + OffsetDate t = OffsetDate.of(2007, 12, 31, OFFSET_PONE).withMonth(11); + OffsetDate expected = OffsetDate.of(2007, 11, 30, OFFSET_PONE); assertEquals(expected, t); } @@ -780,23 +735,23 @@ public void test_withMonth_int_adjustDay() { @Test public void test_withDayOfMonth_normal() { OffsetDate t = TEST_2007_07_15_PONE.withDayOfMonth(1); - assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 1), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 7, 1, OFFSET_PONE), t); } @Test public void test_withDayOfMonth_noChange() { OffsetDate t = TEST_2007_07_15_PONE.withDayOfMonth(15); - assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 7, 15, OFFSET_PONE), t); } @Test public void test_withDayOfMonth_invalidForMonth() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(2007, 11, 30), OFFSET_PONE).withDayOfMonth(31)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(2007, 11, 30, OFFSET_PONE).withDayOfMonth(31)); } @Test public void test_withDayOfMonth_invalidAlways() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(2007, 11, 30), OFFSET_PONE).withDayOfMonth(32)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(2007, 11, 30, OFFSET_PONE).withDayOfMonth(32)); } //----------------------------------------------------------------------- @@ -805,7 +760,7 @@ public void test_withDayOfMonth_invalidAlways() { @Test public void test_withDayOfYear_normal() { OffsetDate t = TEST_2007_07_15_PONE.withDayOfYear(33); - assertEquals(OffsetDate.of(LocalDate.of(2007, 2, 2), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 2, 2, OFFSET_PONE), t); } @Test @@ -831,7 +786,7 @@ public void test_withDayOfYear_invalid() { public void test_plus_PlusAdjuster() { MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS); OffsetDate t = TEST_2007_07_15_PONE.plus(period); - assertEquals(OffsetDate.of(LocalDate.of(2008, 2, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2008, 2, 15, OFFSET_PONE), t); } @Test @@ -858,13 +813,13 @@ public void test_plus_PlusAdjuster_null() { @Test public void test_plusYears_long_normal() { OffsetDate t = TEST_2007_07_15_PONE.plusYears(1); - assertEquals(OffsetDate.of(LocalDate.of(2008, 7, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2008, 7, 15, OFFSET_PONE), t); } @Test public void test_plusYears_long_negative() { OffsetDate t = TEST_2007_07_15_PONE.plusYears(-1); - assertEquals(OffsetDate.of(LocalDate.of(2006, 7, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2006, 7, 15, OFFSET_PONE), t); } @Test @@ -875,38 +830,38 @@ public void test_plusYears_long_noChange() { @Test public void test_plusYears_long_adjustDay() { - OffsetDate t = OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PONE).plusYears(1); - OffsetDate expected = OffsetDate.of(LocalDate.of(2009, 2, 28), OFFSET_PONE); + OffsetDate t = OffsetDate.of(2008, 2, 29, OFFSET_PONE).plusYears(1); + OffsetDate expected = OffsetDate.of(2009, 2, 28, OFFSET_PONE); assertEquals(expected, t); } @Test public void test_plusYears_long_big() { long years = 20L + Year.MAX_VALUE; - OffsetDate test = OffsetDate.of(LocalDate.of(-40, 6, 1), OFFSET_PONE).plusYears(years); - assertEquals(OffsetDate.of(LocalDate.of((int) (-40L + years), 6, 1), OFFSET_PONE), test); + OffsetDate test = OffsetDate.of(-40, 6, 1, OFFSET_PONE).plusYears(years); + assertEquals(OffsetDate.of((int) (-40L + years), 6, 1, OFFSET_PONE), test); } @Test public void test_plusYears_long_invalidTooLarge() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 1, 1), OFFSET_PONE).plusYears(1)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(Year.MAX_VALUE, 1, 1, OFFSET_PONE).plusYears(1)); } @Test public void test_plusYears_long_invalidTooLargeMaxAddMax() { - OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); + OffsetDate test = OffsetDate.of(Year.MAX_VALUE, 12, 1, OFFSET_PONE); assertThrows(DateTimeException.class, () -> test.plusYears(Long.MAX_VALUE)); } @Test public void test_plusYears_long_invalidTooLargeMaxAddMin() { - OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); + OffsetDate test = OffsetDate.of(Year.MAX_VALUE, 12, 1, OFFSET_PONE); assertThrows(DateTimeException.class, () -> test.plusYears(Long.MIN_VALUE)); } @Test public void test_plusYears_long_invalidTooSmall() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusYears(-1)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(Year.MIN_VALUE, 1, 1, OFFSET_PONE).plusYears(-1)); } //----------------------------------------------------------------------- @@ -915,31 +870,31 @@ public void test_plusYears_long_invalidTooSmall() { @Test public void test_plusMonths_long_normal() { OffsetDate t = TEST_2007_07_15_PONE.plusMonths(1); - assertEquals(OffsetDate.of(LocalDate.of(2007, 8, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 8, 15, OFFSET_PONE), t); } @Test public void test_plusMonths_long_overYears() { OffsetDate t = TEST_2007_07_15_PONE.plusMonths(25); - assertEquals(OffsetDate.of(LocalDate.of(2009, 8, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2009, 8, 15, OFFSET_PONE), t); } @Test public void test_plusMonths_long_negative() { OffsetDate t = TEST_2007_07_15_PONE.plusMonths(-1); - assertEquals(OffsetDate.of(LocalDate.of(2007, 6, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 6, 15, OFFSET_PONE), t); } @Test public void test_plusMonths_long_negativeAcrossYear() { OffsetDate t = TEST_2007_07_15_PONE.plusMonths(-7); - assertEquals(OffsetDate.of(LocalDate.of(2006, 12, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2006, 12, 15, OFFSET_PONE), t); } @Test public void test_plusMonths_long_negativeOverYears() { OffsetDate t = TEST_2007_07_15_PONE.plusMonths(-31); - assertEquals(OffsetDate.of(LocalDate.of(2004, 12, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2004, 12, 15, OFFSET_PONE), t); } @Test @@ -950,45 +905,45 @@ public void test_plusMonths_long_noChange() { @Test public void test_plusMonths_long_adjustDayFromLeapYear() { - OffsetDate t = OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PONE).plusMonths(12); - OffsetDate expected = OffsetDate.of(LocalDate.of(2009, 2, 28), OFFSET_PONE); + OffsetDate t = OffsetDate.of(2008, 2, 29, OFFSET_PONE).plusMonths(12); + OffsetDate expected = OffsetDate.of(2009, 2, 28, OFFSET_PONE); assertEquals(expected, t); } @Test public void test_plusMonths_long_adjustDayFromMonthLength() { - OffsetDate t = OffsetDate.of(LocalDate.of(2007, 3, 31), OFFSET_PONE).plusMonths(1); - OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 4, 30), OFFSET_PONE); + OffsetDate t = OffsetDate.of(2007, 3, 31, OFFSET_PONE).plusMonths(1); + OffsetDate expected = OffsetDate.of(2007, 4, 30, OFFSET_PONE); assertEquals(expected, t); } @Test public void test_plusMonths_long_big() { long months = 20L + Integer.MAX_VALUE; - OffsetDate test = OffsetDate.of(LocalDate.of(-40, 6, 1), OFFSET_PONE).plusMonths(months); - assertEquals(OffsetDate.of(LocalDate.of((int) (-40L + months / 12), 6 + (int) (months % 12), 1), OFFSET_PONE), test); + OffsetDate test = OffsetDate.of(-40, 6, 1, OFFSET_PONE).plusMonths(months); + assertEquals(OffsetDate.of((int) (-40L + months / 12), 6 + (int) (months % 12), 1, OFFSET_PONE), test); } @Test public void test_plusMonths_long_invalidTooLarge() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE).plusMonths(1)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(Year.MAX_VALUE, 12, 1, OFFSET_PONE).plusMonths(1)); } @Test public void test_plusMonths_long_invalidTooLargeMaxAddMax() { - OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); + OffsetDate test = OffsetDate.of(Year.MAX_VALUE, 12, 1, OFFSET_PONE); assertThrows(DateTimeException.class, () -> test.plusMonths(Long.MAX_VALUE)); } @Test public void test_plusMonths_long_invalidTooLargeMaxAddMin() { - OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); + OffsetDate test = OffsetDate.of(Year.MAX_VALUE, 12, 1, OFFSET_PONE); assertThrows(DateTimeException.class, () -> test.plusMonths(Long.MIN_VALUE)); } @Test public void test_plusMonths_long_invalidTooSmall() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusMonths(-1)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(Year.MIN_VALUE, 1, 1, OFFSET_PONE).plusMonths(-1)); } //----------------------------------------------------------------------- @@ -997,32 +952,32 @@ public void test_plusMonths_long_invalidTooSmall() { @DataProvider public static Object[][] data_samplePlusWeeksSymmetry() { return new Object[][] { - {OffsetDate.of(LocalDate.of(-1, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(-1, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(-1, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(-1, 12, 31), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(0, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(0, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(0, 2, 29), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(0, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(0, 12, 31), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2007, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2007, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2008, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2008, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2008, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2008, 12, 31), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2099, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2099, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2099, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2099, 12, 31), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2100, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2100, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2100, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2100, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(-1, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(-1, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(-1, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(-1, 12, 31, OFFSET_PTWO)}, + {OffsetDate.of(0, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(0, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(0, 2, 29, OFFSET_PTWO)}, + {OffsetDate.of(0, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(0, 12, 31, OFFSET_PTWO)}, + {OffsetDate.of(2007, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(2007, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(2007, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(2007, 12, 31, OFFSET_PTWO)}, + {OffsetDate.of(2008, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(2008, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(2008, 2, 29, OFFSET_PTWO)}, + {OffsetDate.of(2008, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(2008, 12, 31, OFFSET_PTWO)}, + {OffsetDate.of(2099, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(2099, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(2099, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(2099, 12, 31, OFFSET_PTWO)}, + {OffsetDate.of(2100, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(2100, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(2100, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(2100, 12, 31, OFFSET_PTWO)}, }; } @@ -1041,43 +996,43 @@ public void test_plusWeeks_symmetry(OffsetDate reference) { @Test public void test_plusWeeks_normal() { OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(1); - assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 22), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 7, 22, OFFSET_PONE), t); } @Test public void test_plusWeeks_overMonths() { OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(9); - assertEquals(OffsetDate.of(LocalDate.of(2007, 9, 16), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 9, 16, OFFSET_PONE), t); } @Test public void test_plusWeeks_overYears() { - OffsetDate t = OffsetDate.of(LocalDate.of(2006, 7, 16), OFFSET_PONE).plusWeeks(52); + OffsetDate t = OffsetDate.of(2006, 7, 16, OFFSET_PONE).plusWeeks(52); assertEquals(TEST_2007_07_15_PONE, t); } @Test public void test_plusWeeks_overLeapYears() { OffsetDate t = TEST_2007_07_15_PONE.plusYears(-1).plusWeeks(104); - assertEquals(OffsetDate.of(LocalDate.of(2008, 7, 12), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2008, 7, 12, OFFSET_PONE), t); } @Test public void test_plusWeeks_negative() { OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(-1); - assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 8), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 7, 8, OFFSET_PONE), t); } @Test public void test_plusWeeks_negativeAcrossYear() { OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(-28); - assertEquals(OffsetDate.of(LocalDate.of(2006, 12, 31), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2006, 12, 31, OFFSET_PONE), t); } @Test public void test_plusWeeks_negativeOverYears() { OffsetDate t = TEST_2007_07_15_PONE.plusWeeks(-104); - assertEquals(OffsetDate.of(LocalDate.of(2005, 7, 17), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2005, 7, 17, OFFSET_PONE), t); } @Test @@ -1088,36 +1043,36 @@ public void test_plusWeeks_noChange() { @Test public void test_plusWeeks_maximum() { - OffsetDate t = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 24), OFFSET_PONE).plusWeeks(1); - OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE); + OffsetDate t = OffsetDate.of(Year.MAX_VALUE, 12, 24, OFFSET_PONE).plusWeeks(1); + OffsetDate expected = OffsetDate.of(Year.MAX_VALUE, 12, 31, OFFSET_PONE); assertEquals(expected, t); } @Test public void test_plusWeeks_minimum() { - OffsetDate t = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 8), OFFSET_PONE).plusWeeks(-1); - OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE); + OffsetDate t = OffsetDate.of(Year.MIN_VALUE, 1, 8, OFFSET_PONE).plusWeeks(-1); + OffsetDate expected = OffsetDate.of(Year.MIN_VALUE, 1, 1, OFFSET_PONE); assertEquals(expected, t); } @Test public void test_plusWeeks_invalidTooLarge() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).plusWeeks(1)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(Year.MAX_VALUE, 12, 25, OFFSET_PONE).plusWeeks(1)); } @Test public void test_plusWeeks_invalidTooSmall() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 7), OFFSET_PONE).plusWeeks(-1)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(Year.MIN_VALUE, 1, 7, OFFSET_PONE).plusWeeks(-1)); } @Test public void test_plusWeeks_invalidMaxMinusMax() { - assertThrows(ArithmeticException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).plusWeeks(Long.MAX_VALUE)); + assertThrows(ArithmeticException.class, () -> OffsetDate.of(Year.MAX_VALUE, 12, 25, OFFSET_PONE).plusWeeks(Long.MAX_VALUE)); } @Test public void test_plusWeeks_invalidMaxMinusMin() { - assertThrows(ArithmeticException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).plusWeeks(Long.MIN_VALUE)); + assertThrows(ArithmeticException.class, () -> OffsetDate.of(Year.MAX_VALUE, 12, 25, OFFSET_PONE).plusWeeks(Long.MIN_VALUE)); } //----------------------------------------------------------------------- @@ -1126,32 +1081,32 @@ public void test_plusWeeks_invalidMaxMinusMin() { @DataProvider public static Object[][] data_samplePlusDaysSymmetry() { return new Object[][] { - {OffsetDate.of(LocalDate.of(-1, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(-1, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(-1, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(-1, 12, 31), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(0, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(0, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(0, 2, 29), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(0, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(0, 12, 31), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2007, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2007, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2008, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2008, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2008, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2008, 12, 31), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2099, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2099, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2099, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2099, 12, 31), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2100, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2100, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2100, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2100, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(-1, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(-1, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(-1, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(-1, 12, 31, OFFSET_PTWO)}, + {OffsetDate.of(0, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(0, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(0, 2, 29, OFFSET_PTWO)}, + {OffsetDate.of(0, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(0, 12, 31, OFFSET_PTWO)}, + {OffsetDate.of(2007, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(2007, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(2007, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(2007, 12, 31, OFFSET_PTWO)}, + {OffsetDate.of(2008, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(2008, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(2008, 2, 29, OFFSET_PTWO)}, + {OffsetDate.of(2008, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(2008, 12, 31, OFFSET_PTWO)}, + {OffsetDate.of(2099, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(2099, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(2099, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(2099, 12, 31, OFFSET_PTWO)}, + {OffsetDate.of(2100, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(2100, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(2100, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(2100, 12, 31, OFFSET_PTWO)}, }; } @@ -1170,43 +1125,43 @@ public void test_plusDays_symmetry(OffsetDate reference) { @Test public void test_plusDays_normal() { OffsetDate t = TEST_2007_07_15_PONE.plusDays(1); - assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 16), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 7, 16, OFFSET_PONE), t); } @Test public void test_plusDays_overMonths() { OffsetDate t = TEST_2007_07_15_PONE.plusDays(62); - assertEquals(OffsetDate.of(LocalDate.of(2007, 9, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 9, 15, OFFSET_PONE), t); } @Test public void test_plusDays_overYears() { - OffsetDate t = OffsetDate.of(LocalDate.of(2006, 7, 14), OFFSET_PONE).plusDays(366); + OffsetDate t = OffsetDate.of(2006, 7, 14, OFFSET_PONE).plusDays(366); assertEquals(TEST_2007_07_15_PONE, t); } @Test public void test_plusDays_overLeapYears() { OffsetDate t = TEST_2007_07_15_PONE.plusYears(-1).plusDays(365 + 366); - assertEquals(OffsetDate.of(LocalDate.of(2008, 7, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2008, 7, 15, OFFSET_PONE), t); } @Test public void test_plusDays_negative() { OffsetDate t = TEST_2007_07_15_PONE.plusDays(-1); - assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 14), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 7, 14, OFFSET_PONE), t); } @Test public void test_plusDays_negativeAcrossYear() { OffsetDate t = TEST_2007_07_15_PONE.plusDays(-196); - assertEquals(OffsetDate.of(LocalDate.of(2006, 12, 31), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2006, 12, 31, OFFSET_PONE), t); } @Test public void test_plusDays_negativeOverYears() { OffsetDate t = TEST_2007_07_15_PONE.plusDays(-730); - assertEquals(OffsetDate.of(LocalDate.of(2005, 7, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2005, 7, 15, OFFSET_PONE), t); } @Test @@ -1217,36 +1172,36 @@ public void test_plusDays_noChange() { @Test public void test_plusDays_maximum() { - OffsetDate t = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 30), OFFSET_PONE).plusDays(1); - OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE); + OffsetDate t = OffsetDate.of(Year.MAX_VALUE, 12, 30, OFFSET_PONE).plusDays(1); + OffsetDate expected = OffsetDate.of(Year.MAX_VALUE, 12, 31, OFFSET_PONE); assertEquals(expected, t); } @Test public void test_plusDays_minimum() { - OffsetDate t = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 2), OFFSET_PONE).plusDays(-1); - OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE); + OffsetDate t = OffsetDate.of(Year.MIN_VALUE, 1, 2, OFFSET_PONE).plusDays(-1); + OffsetDate expected = OffsetDate.of(Year.MIN_VALUE, 1, 1, OFFSET_PONE); assertEquals(expected, t); } @Test public void test_plusDays_invalidTooLarge() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).plusDays(1)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(Year.MAX_VALUE, 12, 31, OFFSET_PONE).plusDays(1)); } @Test public void test_plusDays_invalidTooSmall() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusDays(-1)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(Year.MIN_VALUE, 1, 1, OFFSET_PONE).plusDays(-1)); } @Test public void test_plusDays_overflowTooLarge() { - assertThrows(ArithmeticException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).plusDays(Long.MAX_VALUE)); + assertThrows(ArithmeticException.class, () -> OffsetDate.of(Year.MAX_VALUE, 12, 31, OFFSET_PONE).plusDays(Long.MAX_VALUE)); } @Test public void test_plusDays_overflowTooSmall() { - assertThrows(ArithmeticException.class, () -> OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).plusDays(Long.MIN_VALUE)); + assertThrows(ArithmeticException.class, () -> OffsetDate.of(Year.MIN_VALUE, 1, 1, OFFSET_PONE).plusDays(Long.MIN_VALUE)); } //----------------------------------------------------------------------- @@ -1256,7 +1211,7 @@ public void test_plusDays_overflowTooSmall() { public void test_minus_MinusAdjuster() { MockSimplePeriod period = MockSimplePeriod.of(7, ChronoUnit.MONTHS); OffsetDate t = TEST_2007_07_15_PONE.minus(period); - assertEquals(OffsetDate.of(LocalDate.of(2006, 12, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2006, 12, 15, OFFSET_PONE), t); } @Test @@ -1283,13 +1238,13 @@ public void test_plus_MinusAdjuster_null() { @Test public void test_minusYears_long_normal() { OffsetDate t = TEST_2007_07_15_PONE.minusYears(1); - assertEquals(OffsetDate.of(LocalDate.of(2006, 7, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2006, 7, 15, OFFSET_PONE), t); } @Test public void test_minusYears_long_negative() { OffsetDate t = TEST_2007_07_15_PONE.minusYears(-1); - assertEquals(OffsetDate.of(LocalDate.of(2008, 7, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2008, 7, 15, OFFSET_PONE), t); } @Test @@ -1300,38 +1255,38 @@ public void test_minusYears_long_noChange() { @Test public void test_minusYears_long_adjustDay() { - OffsetDate t = OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PONE).minusYears(1); - OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PONE); + OffsetDate t = OffsetDate.of(2008, 2, 29, OFFSET_PONE).minusYears(1); + OffsetDate expected = OffsetDate.of(2007, 2, 28, OFFSET_PONE); assertEquals(expected, t); } @Test public void test_minusYears_long_big() { long years = 20L + Year.MAX_VALUE; - OffsetDate test = OffsetDate.of(LocalDate.of(40, 6, 1), OFFSET_PONE).minusYears(years); - assertEquals(OffsetDate.of(LocalDate.of((int) (40L - years), 6, 1), OFFSET_PONE), test); + OffsetDate test = OffsetDate.of(40, 6, 1, OFFSET_PONE).minusYears(years); + assertEquals(OffsetDate.of((int) (40L - years), 6, 1, OFFSET_PONE), test); } @Test public void test_minusYears_long_invalidTooLarge() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 1, 1), OFFSET_PONE).minusYears(-1)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(Year.MAX_VALUE, 1, 1, OFFSET_PONE).minusYears(-1)); } @Test public void test_minusYears_long_invalidTooLargeMaxAddMax() { - OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); + OffsetDate test = OffsetDate.of(Year.MAX_VALUE, 12, 1, OFFSET_PONE); assertThrows(DateTimeException.class, () -> test.minusYears(Long.MAX_VALUE)); } @Test public void test_minusYears_long_invalidTooLargeMaxAddMin() { - OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); + OffsetDate test = OffsetDate.of(Year.MAX_VALUE, 12, 1, OFFSET_PONE); assertThrows(DateTimeException.class, () -> test.minusYears(Long.MIN_VALUE)); } @Test public void test_minusYears_long_invalidTooSmall() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusYears(1)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(Year.MIN_VALUE, 1, 1, OFFSET_PONE).minusYears(1)); } //----------------------------------------------------------------------- @@ -1340,31 +1295,31 @@ public void test_minusYears_long_invalidTooSmall() { @Test public void test_minusMonths_long_normal() { OffsetDate t = TEST_2007_07_15_PONE.minusMonths(1); - assertEquals(OffsetDate.of(LocalDate.of(2007, 6, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 6, 15, OFFSET_PONE), t); } @Test public void test_minusMonths_long_overYears() { OffsetDate t = TEST_2007_07_15_PONE.minusMonths(25); - assertEquals(OffsetDate.of(LocalDate.of(2005, 6, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2005, 6, 15, OFFSET_PONE), t); } @Test public void test_minusMonths_long_negative() { OffsetDate t = TEST_2007_07_15_PONE.minusMonths(-1); - assertEquals(OffsetDate.of(LocalDate.of(2007, 8, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 8, 15, OFFSET_PONE), t); } @Test public void test_minusMonths_long_negativeAcrossYear() { OffsetDate t = TEST_2007_07_15_PONE.minusMonths(-7); - assertEquals(OffsetDate.of(LocalDate.of(2008, 2, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2008, 2, 15, OFFSET_PONE), t); } @Test public void test_minusMonths_long_negativeOverYears() { OffsetDate t = TEST_2007_07_15_PONE.minusMonths(-31); - assertEquals(OffsetDate.of(LocalDate.of(2010, 2, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2010, 2, 15, OFFSET_PONE), t); } @Test @@ -1375,45 +1330,45 @@ public void test_minusMonths_long_noChange() { @Test public void test_minusMonths_long_adjustDayFromLeapYear() { - OffsetDate t = OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PONE).minusMonths(12); - OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PONE); + OffsetDate t = OffsetDate.of(2008, 2, 29, OFFSET_PONE).minusMonths(12); + OffsetDate expected = OffsetDate.of(2007, 2, 28, OFFSET_PONE); assertEquals(expected, t); } @Test public void test_minusMonths_long_adjustDayFromMonthLength() { - OffsetDate t = OffsetDate.of(LocalDate.of(2007, 3, 31), OFFSET_PONE).minusMonths(1); - OffsetDate expected = OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PONE); + OffsetDate t = OffsetDate.of(2007, 3, 31, OFFSET_PONE).minusMonths(1); + OffsetDate expected = OffsetDate.of(2007, 2, 28, OFFSET_PONE); assertEquals(expected, t); } @Test public void test_minusMonths_long_big() { long months = 20L + Integer.MAX_VALUE; - OffsetDate test = OffsetDate.of(LocalDate.of(40, 6, 1), OFFSET_PONE).minusMonths(months); - assertEquals(OffsetDate.of(LocalDate.of((int) (40L - months / 12), 6 - (int) (months % 12), 1), OFFSET_PONE), test); + OffsetDate test = OffsetDate.of(40, 6, 1, OFFSET_PONE).minusMonths(months); + assertEquals(OffsetDate.of((int) (40L - months / 12), 6 - (int) (months % 12), 1, OFFSET_PONE), test); } @Test public void test_minusMonths_long_invalidTooLarge() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE).minusMonths(-1)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(Year.MAX_VALUE, 12, 1, OFFSET_PONE).minusMonths(-1)); } @Test public void test_minusMonths_long_invalidTooLargeMaxAddMax() { - OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); + OffsetDate test = OffsetDate.of(Year.MAX_VALUE, 12, 1, OFFSET_PONE); assertThrows(DateTimeException.class, () -> test.minusMonths(Long.MAX_VALUE)); } @Test public void test_minusMonths_long_invalidTooLargeMaxAddMin() { - OffsetDate test = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 1), OFFSET_PONE); + OffsetDate test = OffsetDate.of(Year.MAX_VALUE, 12, 1, OFFSET_PONE); assertThrows(DateTimeException.class, () -> test.minusMonths(Long.MIN_VALUE)); } @Test public void test_minusMonths_long_invalidTooSmall() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusMonths(1)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(Year.MIN_VALUE, 1, 1, OFFSET_PONE).minusMonths(1)); } //----------------------------------------------------------------------- @@ -1422,32 +1377,32 @@ public void test_minusMonths_long_invalidTooSmall() { @DataProvider public static Object[][] data_sampleMinusWeeksSymmetry() { return new Object[][] { - {OffsetDate.of(LocalDate.of(-1, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(-1, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(-1, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(-1, 12, 31), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(0, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(0, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(0, 2, 29), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(0, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(0, 12, 31), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2007, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2007, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2008, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2008, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2008, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2008, 12, 31), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2099, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2099, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2099, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2099, 12, 31), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2100, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2100, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2100, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2100, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(-1, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(-1, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(-1, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(-1, 12, 31, OFFSET_PTWO)}, + {OffsetDate.of(0, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(0, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(0, 2, 29, OFFSET_PTWO)}, + {OffsetDate.of(0, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(0, 12, 31, OFFSET_PTWO)}, + {OffsetDate.of(2007, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(2007, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(2007, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(2007, 12, 31, OFFSET_PTWO)}, + {OffsetDate.of(2008, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(2008, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(2008, 2, 29, OFFSET_PTWO)}, + {OffsetDate.of(2008, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(2008, 12, 31, OFFSET_PTWO)}, + {OffsetDate.of(2099, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(2099, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(2099, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(2099, 12, 31, OFFSET_PTWO)}, + {OffsetDate.of(2100, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(2100, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(2100, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(2100, 12, 31, OFFSET_PTWO)}, }; } @@ -1466,43 +1421,43 @@ public void test_minusWeeks_symmetry(OffsetDate reference) { @Test public void test_minusWeeks_normal() { OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(1); - assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 8), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 7, 8, OFFSET_PONE), t); } @Test public void test_minusWeeks_overMonths() { OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(9); - assertEquals(OffsetDate.of(LocalDate.of(2007, 5, 13), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 5, 13, OFFSET_PONE), t); } @Test public void test_minusWeeks_overYears() { - OffsetDate t = OffsetDate.of(LocalDate.of(2008, 7, 13), OFFSET_PONE).minusWeeks(52); + OffsetDate t = OffsetDate.of(2008, 7, 13, OFFSET_PONE).minusWeeks(52); assertEquals(TEST_2007_07_15_PONE, t); } @Test public void test_minusWeeks_overLeapYears() { OffsetDate t = TEST_2007_07_15_PONE.minusYears(-1).minusWeeks(104); - assertEquals(OffsetDate.of(LocalDate.of(2006, 7, 18), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2006, 7, 18, OFFSET_PONE), t); } @Test public void test_minusWeeks_negative() { OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(-1); - assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 22), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 7, 22, OFFSET_PONE), t); } @Test public void test_minusWeeks_negativeAcrossYear() { OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(-28); - assertEquals(OffsetDate.of(LocalDate.of(2008, 1, 27), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2008, 1, 27, OFFSET_PONE), t); } @Test public void test_minusWeeks_negativeOverYears() { OffsetDate t = TEST_2007_07_15_PONE.minusWeeks(-104); - assertEquals(OffsetDate.of(LocalDate.of(2009, 7, 12), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2009, 7, 12, OFFSET_PONE), t); } @Test @@ -1513,36 +1468,36 @@ public void test_minusWeeks_noChange() { @Test public void test_minusWeeks_maximum() { - OffsetDate t = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 24), OFFSET_PONE).minusWeeks(-1); - OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE); + OffsetDate t = OffsetDate.of(Year.MAX_VALUE, 12, 24, OFFSET_PONE).minusWeeks(-1); + OffsetDate expected = OffsetDate.of(Year.MAX_VALUE, 12, 31, OFFSET_PONE); assertEquals(expected, t); } @Test public void test_minusWeeks_minimum() { - OffsetDate t = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 8), OFFSET_PONE).minusWeeks(1); - OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE); + OffsetDate t = OffsetDate.of(Year.MIN_VALUE, 1, 8, OFFSET_PONE).minusWeeks(1); + OffsetDate expected = OffsetDate.of(Year.MIN_VALUE, 1, 1, OFFSET_PONE); assertEquals(expected, t); } @Test public void test_minusWeeks_invalidTooLarge() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).minusWeeks(-1)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(Year.MAX_VALUE, 12, 25, OFFSET_PONE).minusWeeks(-1)); } @Test public void test_minusWeeks_invalidTooSmall() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 7), OFFSET_PONE).minusWeeks(1)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(Year.MIN_VALUE, 1, 7, OFFSET_PONE).minusWeeks(1)); } @Test public void test_minusWeeks_invalidMaxMinusMax() { - assertThrows(ArithmeticException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).minusWeeks(Long.MAX_VALUE)); + assertThrows(ArithmeticException.class, () -> OffsetDate.of(Year.MAX_VALUE, 12, 25, OFFSET_PONE).minusWeeks(Long.MAX_VALUE)); } @Test public void test_minusWeeks_invalidMaxMinusMin() { - assertThrows(ArithmeticException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 25), OFFSET_PONE).minusWeeks(Long.MIN_VALUE)); + assertThrows(ArithmeticException.class, () -> OffsetDate.of(Year.MAX_VALUE, 12, 25, OFFSET_PONE).minusWeeks(Long.MIN_VALUE)); } //----------------------------------------------------------------------- @@ -1551,32 +1506,32 @@ public void test_minusWeeks_invalidMaxMinusMin() { @DataProvider public static Object[][] data_sampleMinusDaysSymmetry() { return new Object[][] { - {OffsetDate.of(LocalDate.of(-1, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(-1, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(-1, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(-1, 12, 31), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(0, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(0, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(0, 2, 29), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(0, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(0, 12, 31), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2007, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2007, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2007, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2008, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2008, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2008, 2, 29), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2008, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2008, 12, 31), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2099, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2099, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2099, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2099, 12, 31), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2100, 1, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2100, 2, 28), OFFSET_PTWO)}, - {OffsetDate.of(LocalDate.of(2100, 3, 1), OFFSET_PONE)}, - {OffsetDate.of(LocalDate.of(2100, 12, 31), OFFSET_PTWO)}, + {OffsetDate.of(-1, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(-1, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(-1, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(-1, 12, 31, OFFSET_PTWO)}, + {OffsetDate.of(0, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(0, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(0, 2, 29, OFFSET_PTWO)}, + {OffsetDate.of(0, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(0, 12, 31, OFFSET_PTWO)}, + {OffsetDate.of(2007, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(2007, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(2007, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(2007, 12, 31, OFFSET_PTWO)}, + {OffsetDate.of(2008, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(2008, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(2008, 2, 29, OFFSET_PTWO)}, + {OffsetDate.of(2008, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(2008, 12, 31, OFFSET_PTWO)}, + {OffsetDate.of(2099, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(2099, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(2099, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(2099, 12, 31, OFFSET_PTWO)}, + {OffsetDate.of(2100, 1, 1, OFFSET_PONE)}, + {OffsetDate.of(2100, 2, 28, OFFSET_PTWO)}, + {OffsetDate.of(2100, 3, 1, OFFSET_PONE)}, + {OffsetDate.of(2100, 12, 31, OFFSET_PTWO)}, }; } @@ -1595,18 +1550,18 @@ public void test_minusDays_symmetry(OffsetDate reference) { @Test public void test_minusDays_normal() { OffsetDate t = TEST_2007_07_15_PONE.minusDays(1); - assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 14), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 7, 14, OFFSET_PONE), t); } @Test public void test_minusDays_overMonths() { OffsetDate t = TEST_2007_07_15_PONE.minusDays(62); - assertEquals(OffsetDate.of(LocalDate.of(2007, 5, 14), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 5, 14, OFFSET_PONE), t); } @Test public void test_minusDays_overYears() { - OffsetDate t = OffsetDate.of(LocalDate.of(2008, 7, 16), OFFSET_PONE).minusDays(367); + OffsetDate t = OffsetDate.of(2008, 7, 16, OFFSET_PONE).minusDays(367); assertEquals(TEST_2007_07_15_PONE, t); } @@ -1619,19 +1574,19 @@ public void test_minusDays_overLeapYears() { @Test public void test_minusDays_negative() { OffsetDate t = TEST_2007_07_15_PONE.minusDays(-1); - assertEquals(OffsetDate.of(LocalDate.of(2007, 7, 16), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 7, 16, OFFSET_PONE), t); } @Test public void test_minusDays_negativeAcrossYear() { OffsetDate t = TEST_2007_07_15_PONE.minusDays(-169); - assertEquals(OffsetDate.of(LocalDate.of(2007, 12, 31), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2007, 12, 31, OFFSET_PONE), t); } @Test public void test_minusDays_negativeOverYears() { OffsetDate t = TEST_2007_07_15_PONE.minusDays(-731); - assertEquals(OffsetDate.of(LocalDate.of(2009, 7, 15), OFFSET_PONE), t); + assertEquals(OffsetDate.of(2009, 7, 15, OFFSET_PONE), t); } @Test @@ -1642,36 +1597,36 @@ public void test_minusDays_noChange() { @Test public void test_minusDays_maximum() { - OffsetDate t = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 30), OFFSET_PONE).minusDays(-1); - OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE); + OffsetDate t = OffsetDate.of(Year.MAX_VALUE, 12, 30, OFFSET_PONE).minusDays(-1); + OffsetDate expected = OffsetDate.of(Year.MAX_VALUE, 12, 31, OFFSET_PONE); assertEquals(expected, t); } @Test public void test_minusDays_minimum() { - OffsetDate t = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 2), OFFSET_PONE).minusDays(1); - OffsetDate expected = OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE); + OffsetDate t = OffsetDate.of(Year.MIN_VALUE, 1, 2, OFFSET_PONE).minusDays(1); + OffsetDate expected = OffsetDate.of(Year.MIN_VALUE, 1, 1, OFFSET_PONE); assertEquals(expected, t); } @Test public void test_minusDays_invalidTooLarge() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).minusDays(-1)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(Year.MAX_VALUE, 12, 31, OFFSET_PONE).minusDays(-1)); } @Test public void test_minusDays_invalidTooSmall() { - assertThrows(DateTimeException.class, () -> OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusDays(1)); + assertThrows(DateTimeException.class, () -> OffsetDate.of(Year.MIN_VALUE, 1, 1, OFFSET_PONE).minusDays(1)); } @Test public void test_minusDays_overflowTooLarge() { - assertThrows(ArithmeticException.class, () -> OffsetDate.of(LocalDate.of(Year.MAX_VALUE, 12, 31), OFFSET_PONE).minusDays(Long.MIN_VALUE)); + assertThrows(ArithmeticException.class, () -> OffsetDate.of(Year.MAX_VALUE, 12, 31, OFFSET_PONE).minusDays(Long.MIN_VALUE)); } @Test public void test_minusDays_overflowTooSmall() { - assertThrows(ArithmeticException.class, () -> OffsetDate.of(LocalDate.of(Year.MIN_VALUE, 1, 1), OFFSET_PONE).minusDays(Long.MAX_VALUE)); + assertThrows(ArithmeticException.class, () -> OffsetDate.of(Year.MIN_VALUE, 1, 1, OFFSET_PONE).minusDays(Long.MAX_VALUE)); } //----------------------------------------------------------------------- @@ -1680,13 +1635,13 @@ public void test_minusDays_overflowTooSmall() { @Test public void test_format_formatter() { DateTimeFormatter f = DateTimeFormatter.ofPattern("y M d"); - String t = OffsetDate.of(LocalDate.of(2010, 12, 3), OFFSET_PONE).format(f); + String t = OffsetDate.of(2010, 12, 3, OFFSET_PONE).format(f); assertEquals("2010 12 3", t); } @Test public void test_format_formatter_null() { - assertThrows(NullPointerException.class, () -> OffsetDate.of(LocalDate.of(2010, 12, 3), OFFSET_PONE).format(null)); + assertThrows(NullPointerException.class, () -> OffsetDate.of(2010, 12, 3, OFFSET_PONE).format(null)); } //----------------------------------------------------------------------- @@ -1694,14 +1649,14 @@ public void test_format_formatter_null() { //----------------------------------------------------------------------- @Test public void test_atTime_Local() { - OffsetDate t = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO); + OffsetDate t = OffsetDate.of(2008, 6, 30, OFFSET_PTWO); assertEquals(OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30), OFFSET_PTWO), t.atTime(LocalTime.of(11, 30))); } @Test public void test_atTime_Local_nullLocalTime() { - OffsetDate t = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO); + OffsetDate t = OffsetDate.of(2008, 6, 30, OFFSET_PTWO); assertThrows(NullPointerException.class, () -> t.atTime((LocalTime) null)); } @@ -1712,7 +1667,7 @@ public void test_atTime_Local_nullLocalTime() { @UseDataProvider("data_sampleDates") public void test_toLocalDate(int year, int month, int day, ZoneOffset offset) { LocalDate t = LocalDate.of(year, month, day); - assertEquals(t, OffsetDate.of(LocalDate.of(year, month, day), offset).toLocalDate()); + assertEquals(t, OffsetDate.of(year, month, day, offset).toLocalDate()); } //----------------------------------------------------------------------- @@ -1730,8 +1685,8 @@ public void test_toEpochSecond() { //----------------------------------------------------------------------- @Test public void test_compareTo_date() { - OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 29), OFFSET_PONE); - OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b due to date + OffsetDate a = OffsetDate.of(2008, 6, 29, OFFSET_PONE); + OffsetDate b = OffsetDate.of(2008, 6, 30, OFFSET_PONE); // a is before b due to date assertTrue(a.compareTo(b) < 0); assertTrue(b.compareTo(a) > 0); assertTrue(a.compareTo(a) == 0); @@ -1741,8 +1696,8 @@ public void test_compareTo_date() { @Test public void test_compareTo_offset() { - OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO); - OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b due to offset + OffsetDate a = OffsetDate.of(2008, 6, 30, OFFSET_PTWO); + OffsetDate b = OffsetDate.of(2008, 6, 30, OFFSET_PONE); // a is before b due to offset assertTrue(a.compareTo(b) < 0); assertTrue(b.compareTo(a) > 0); assertTrue(a.compareTo(a) == 0); @@ -1752,8 +1707,8 @@ public void test_compareTo_offset() { @Test public void test_compareTo_both() { - OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 29), OFFSET_PTWO); - OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b on instant scale + OffsetDate a = OffsetDate.of(2008, 6, 29, OFFSET_PTWO); + OffsetDate b = OffsetDate.of(2008, 6, 30, OFFSET_PONE); // a is before b on instant scale assertTrue(a.compareTo(b) < 0); assertTrue(b.compareTo(a) > 0); assertTrue(a.compareTo(a) == 0); @@ -1763,8 +1718,8 @@ public void test_compareTo_both() { @Test public void test_compareTo_24hourDifference() { - OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 29), ZoneOffset.ofHours(-12)); - OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), ZoneOffset.ofHours(12)); // a is before b despite being same time-line time + OffsetDate a = OffsetDate.of(2008, 6, 29, ZoneOffset.ofHours(-12)); + OffsetDate b = OffsetDate.of(2008, 6, 30, ZoneOffset.ofHours(12)); // a is before b despite being same time-line time assertTrue(a.compareTo(b) < 0); assertTrue(b.compareTo(a) > 0); assertTrue(a.compareTo(a) == 0); @@ -1774,7 +1729,7 @@ public void test_compareTo_24hourDifference() { @Test public void test_compareTo_null() { - OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); + OffsetDate a = OffsetDate.of(2008, 6, 30, OFFSET_PONE); assertThrows(NullPointerException.class, () -> a.compareTo(null)); } @@ -1790,8 +1745,8 @@ public void compareToNonOffsetDate() { //----------------------------------------------------------------------- @Test public void test_isBeforeIsAfterIsEqual1() { - OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 29), OFFSET_PONE); - OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b due to time + OffsetDate a = OffsetDate.of(2008, 6, 29, OFFSET_PONE); + OffsetDate b = OffsetDate.of(2008, 6, 30, OFFSET_PONE); // a is before b due to time assertTrue(a.isBefore(b)); assertFalse(a.isEqual(b)); assertFalse(a.isAfter(b)); @@ -1812,8 +1767,8 @@ public void test_isBeforeIsAfterIsEqual1() { @Test public void test_isBeforeIsAfterIsEqual2() { - OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PTWO); - OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); // a is before b due to offset + OffsetDate a = OffsetDate.of(2008, 6, 30, OFFSET_PTWO); + OffsetDate b = OffsetDate.of(2008, 6, 30, OFFSET_PONE); // a is before b due to offset assertTrue(a.isBefore(b)); assertFalse(a.isEqual(b)); assertFalse(a.isAfter(b)); @@ -1834,8 +1789,8 @@ public void test_isBeforeIsAfterIsEqual2() { @Test public void test_isBeforeIsAfterIsEqual_instantComparison() { - OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), ZoneOffset.ofHours(12)); - OffsetDate b = OffsetDate.of(LocalDate.of(2008, 6, 29), ZoneOffset.ofHours(-12)); // a is same instant as b + OffsetDate a = OffsetDate.of(2008, 6, 30, ZoneOffset.ofHours(12)); + OffsetDate b = OffsetDate.of(2008, 6, 29, ZoneOffset.ofHours(-12)); // a is same instant as b assertFalse(a.isBefore(b)); assertTrue(a.isEqual(b)); assertFalse(a.isAfter(b)); @@ -1856,19 +1811,19 @@ public void test_isBeforeIsAfterIsEqual_instantComparison() { @Test public void test_isBefore_null() { - OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); + OffsetDate a = OffsetDate.of(2008, 6, 30, OFFSET_PONE); assertThrows(NullPointerException.class, () -> a.isBefore(null)); } @Test public void test_isAfter_null() { - OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); + OffsetDate a = OffsetDate.of(2008, 6, 30, OFFSET_PONE); assertThrows(NullPointerException.class, () -> a.isAfter(null)); } @Test public void test_isEqual_null() { - OffsetDate a = OffsetDate.of(LocalDate.of(2008, 6, 30), OFFSET_PONE); + OffsetDate a = OffsetDate.of(2008, 6, 30, OFFSET_PONE); assertThrows(NullPointerException.class, () -> a.isEqual(null)); } @@ -1878,8 +1833,8 @@ public void test_isEqual_null() { @ParameterizedTest @UseDataProvider("data_sampleDates") public void test_equals_true(int y, int m, int d, ZoneOffset offset) { - OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); - OffsetDate b = OffsetDate.of(LocalDate.of(y, m, d), offset); + OffsetDate a = OffsetDate.of(y, m, d, offset); + OffsetDate b = OffsetDate.of(y, m, d, offset); assertTrue(a.equals(b)); assertTrue(a.hashCode() == b.hashCode()); } @@ -1887,32 +1842,32 @@ public void test_equals_true(int y, int m, int d, ZoneOffset offset) { @ParameterizedTest @UseDataProvider("data_sampleDates") public void test_equals_false_year_differs(int y, int m, int d, ZoneOffset offset) { - OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); - OffsetDate b = OffsetDate.of(LocalDate.of(y + 1, m, d), offset); + OffsetDate a = OffsetDate.of(y, m, d, offset); + OffsetDate b = OffsetDate.of(y + 1, m, d, offset); assertFalse(a.equals(b)); } @ParameterizedTest @UseDataProvider("data_sampleDates") public void test_equals_false_month_differs(int y, int m, int d, ZoneOffset offset) { - OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); - OffsetDate b = OffsetDate.of(LocalDate.of(y, m + 1, d), offset); + OffsetDate a = OffsetDate.of(y, m, d, offset); + OffsetDate b = OffsetDate.of(y, m + 1, d, offset); assertFalse(a.equals(b)); } @ParameterizedTest @UseDataProvider("data_sampleDates") public void test_equals_false_day_differs(int y, int m, int d, ZoneOffset offset) { - OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), offset); - OffsetDate b = OffsetDate.of(LocalDate.of(y, m, d + 1), offset); + OffsetDate a = OffsetDate.of(y, m, d, offset); + OffsetDate b = OffsetDate.of(y, m, d + 1, offset); assertFalse(a.equals(b)); } @ParameterizedTest @UseDataProvider("data_sampleDates") public void test_equals_false_offset_differs(int y, int m, int d, ZoneOffset ignored) { - OffsetDate a = OffsetDate.of(LocalDate.of(y, m, d), OFFSET_PONE); - OffsetDate b = OffsetDate.of(LocalDate.of(y, m, d), OFFSET_PTWO); + OffsetDate a = OffsetDate.of(y, m, d, OFFSET_PONE); + OffsetDate b = OffsetDate.of(y, m, d, OFFSET_PTWO); assertFalse(a.equals(b)); } @@ -1960,7 +1915,7 @@ public static Object[][] data_sampleToString() { @ParameterizedTest @UseDataProvider("data_sampleToString") public void test_toString(int y, int m, int d, String offsetId, String expected) { - OffsetDate t = OffsetDate.of(LocalDate.of(y, m, d), ZoneOffset.of(offsetId)); + OffsetDate t = OffsetDate.of(y, m, d, ZoneOffset.of(offsetId)); String str = t.toString(); assertEquals(expected, str); } From af91b85d5f9aaec559b366b51127370fa78a5853 Mon Sep 17 00:00:00 2001 From: Tristan Swadell Date: Tue, 6 Apr 2021 00:43:23 -0700 Subject: [PATCH 203/279] Add support for unit-based duration parsing to AmountFormats --- .../org/threeten/extra/AmountFormats.java | 300 +++++++++++++++++- .../org/threeten/extra/TestAmountFormats.java | 49 +++ 2 files changed, 346 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/threeten/extra/AmountFormats.java b/src/main/java/org/threeten/extra/AmountFormats.java index 9bf07aba..0d4844d4 100644 --- a/src/main/java/org/threeten/extra/AmountFormats.java +++ b/src/main/java/org/threeten/extra/AmountFormats.java @@ -34,9 +34,13 @@ import java.time.Duration; import java.time.Period; import java.time.temporal.TemporalAmount; +import java.util.Arrays; +import java.util.List; import java.util.Locale; import java.util.Objects; +import java.util.Optional; import java.util.ResourceBundle; +import java.util.function.Function; import java.util.function.IntPredicate; import java.util.regex.Pattern; import java.util.stream.Stream; @@ -142,6 +146,22 @@ public final class AmountFormats { int secondLast = (abs % 100) / 10; return (last >= 2 && last <= 4 && secondLast != 1); }; + /** + * List of DurationUnit values ordered by longest suffix first. + */ + private static final List DURATION_UNITS = + Arrays.asList(new DurationUnit("ns", Duration.ofNanos(1)), + new DurationUnit("µs", Duration.ofNanos(1000)), // U+00B5 = micro symbol + new DurationUnit("μs", Duration.ofNanos(1000)), // U+03BC = Greek letter mu + new DurationUnit("us", Duration.ofNanos(1000)), + new DurationUnit("ms", Duration.ofMillis(1)), + new DurationUnit("s", Duration.ofSeconds(1)), + new DurationUnit("m", Duration.ofMinutes(1)), + new DurationUnit("h", Duration.ofHours(1))); + /** + * Zero value for an absent fractional component of a numeric duration string. + */ + private static final FractionScalarPart EMPTY_FRACTION = new FractionScalarPart(0, 0); //----------------------------------------------------------------------- /** @@ -150,7 +170,7 @@ public final class AmountFormats { * To obtain the ISO-8601 format of a {@code Period} or {@code Duration} * individually, simply call {@code toString()}. * See also {@link PeriodDuration}. - * + * * @param period the period to format * @param duration the duration to format * @return the ISO-8601 format for the period and duration @@ -287,6 +307,186 @@ private static boolean oppositeSigns(int a, int b) { return a < 0 ? (b >= 0) : (b < 0); } + // ------------------------------------------------------------------------- + /** + * Parses a unit-based duration string to a duration value. + *

      + * This is an implementation of Golang's {@link https://golang.org/pkg/time/#ParseDuration}: + * ParseDuration parses a duration string. A duration string is a possibly + * signed sequence of decimal numbers, each with optional fraction and a + * unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are + * "ns", "us" (or "µs"), "ms", "s", "m", "h". + *

      + * Note, the value "0" is specially supported as {@code Duration.ZERO}, but + * unlike the Go implementation infinite durations are not supported. + * + * @param durationText the formatted unit-based duration string. + * @return the {@code Duration} value represented by the string, if possible. + */ + public static Optional parseUnitBasedDuration(CharSequence durationText) { + // return no duration from null input strings. + if (durationText == null) { + return Optional.empty(); + } + + // consume the leading sign - or + if one is present. + int sign = 1; + Optional updatedText = consumePrefix(durationText, '-'); + if (updatedText.isPresent()) { + sign = -1; + durationText = updatedText.get(); + } else { + durationText = consumePrefix(durationText, '+').orElse(durationText); + } + // special case for a string of "0" + if (durationText.equals("0")) { + return Optional.of(Duration.ZERO); + } + // special case, empty string as an invalid duration. + if (durationText.length() == 0) { + return Optional.empty(); + } + + Duration value = Duration.ZERO; + int durationTextLength = durationText.length(); + while (durationTextLength > 0) { + Optional optIntegerPart = + consumeDurationLeadingInt(durationText); + // check for a missing leading integer. + if (!optIntegerPart.isPresent()) { + return Optional.empty(); + } + ParsedUnitPart integerPart = optIntegerPart.get(); + durationText = integerPart.remainingText(); + DurationScalar leadingInt = integerPart; + DurationScalar fraction = EMPTY_FRACTION; + Optional dot = consumePrefix(durationText, '.'); + if (dot.isPresent()) { + durationText = dot.get(); + Optional optFractionPart = + consumeDurationFraction(durationText); + // dot '.' present, but no fractional part, return. + if (!optFractionPart.isPresent()) { + return Optional.empty(); + } + // update the remaining string and fraction. + ParsedUnitPart fractionPart = optFractionPart.get(); + durationText = fractionPart.remainingText(); + fraction = fractionPart; + } + + Optional unitPart = findUnit(durationText); + // no matching unit found, return. + if (!unitPart.isPresent()) { + return Optional.empty(); + } + DurationUnit unit = unitPart.get(); + Optional optUnitValue = leadingInt.applyTo(unit); + if (!optUnitValue.isPresent()) { + return Optional.empty(); + } + Duration unitValue = optUnitValue.get(); + Optional optFractionValue = fraction.applyTo(unit); + if (!optFractionValue.isPresent()) { + return Optional.empty(); + } + try { + unitValue = unitValue.plus(optFractionValue.get()); + value = value.plus(unitValue); + } catch (ArithmeticException e) { + // overflow of the valid range possible for a Duration + return Optional.empty(); + } + // update the remaining text and text length. + durationText = unit.consumeDurationUnit(durationText); + durationTextLength = durationText.length(); + } + return sign < 0 ? Optional.of(value.negated()) : Optional.of(value); + } + + // consume the fractional part of a unit-based duration, e.g. + // .. + private static Optional consumeDurationLeadingInt(CharSequence text) { + long integerPart = 0; + int i = 0; + int valueLength = text.length(); + for (; i < valueLength; i++) { + char c = text.charAt(i); + if (c < '0' || c > '9') { + break; + } + // overflow of a single numeric specifier for a duration. + if (integerPart > Long.MAX_VALUE / 10) { + return Optional.empty(); + } + integerPart *= 10; + integerPart += (long) (c - '0'); + // overflow of a single numeric specifier for a duration. + if (integerPart < 0) { + return Optional.empty(); + } + } + // if no text was consumed, return empty. + if (i == 0) { + return Optional.empty(); + } + return Optional.of( + new ParsedUnitPart(text.subSequence(i, text.length()), + new IntegerScalarPart(integerPart))); + } + + // consume the fractional part of a unit-based duration, e.g. + // .. + private static Optional consumeDurationFraction(CharSequence text) { + int i = 0; + long fraction = 0; + long scale = 1; + boolean overflow = false; + for (; i < text.length(); i++) { + char c = text.charAt(i); + if (c < '0' || c > '9') { + break; + } + // for the fractional part, it's possible to overflow; however, + // this does not invalidate the duration, but rather it means that + // the precision of the fractional part is truncated to 999,999,999. + if (overflow || fraction > Long.MAX_VALUE / 10) { + continue; + } + long tmp = fraction * 10 + (long) (c - '0'); + if (tmp < 0) { + overflow = true; + continue; + } + fraction = tmp; + scale *= 10; + } + if (i == 0) { + return Optional.empty(); + } + return Optional.of( + new ParsedUnitPart(text.subSequence(i, text.length()), + new FractionScalarPart(fraction, scale))); + } + + // find the duration unit at the beginning of the input text, if present. + private static Optional findUnit(CharSequence text) { + return DURATION_UNITS.stream() + .sequential() + .filter(du -> du.prefixMatchesUnit(text)) + .findFirst(); + } + + // consume the indicated {@code prefix} if it exists at the beginning of the + // text, returning the + // remaining string if the prefix was consumed. + private static Optional consumePrefix(CharSequence text, char prefix) { + if (text.length() > 0 && text.charAt(0) == prefix) { + return Optional.of(text.subSequence(1, text.length())); + } + return Optional.empty(); + } + private AmountFormats() { } @@ -329,7 +529,7 @@ String format(int[] values) { // data holder for single/plural formats static interface UnitFormat { - + static UnitFormat of(ResourceBundle bundle, String keyStem) { if (bundle.containsKey(keyStem + "s.predicates")) { String predicateList = bundle.getString(keyStem + "s.predicates"); @@ -343,7 +543,7 @@ static UnitFormat of(ResourceBundle bundle, String keyStem) { return new SinglePluralFormat(single, plural); } } - + void formatTo(int value, StringBuilder buf); } @@ -399,4 +599,98 @@ public void formatTo(int value, StringBuilder buf) { } } + // ------------------------------------------------------------------------- + // data holder for a duration unit string and its associated Duration value. + static class DurationUnit { + private final String abbrev; + private final Duration value; + + private DurationUnit(String abbrev, Duration value) { + this.abbrev = abbrev; + this.value = value; + } + + // whether the input text starts with the unit abbreviation. + boolean prefixMatchesUnit(CharSequence text) { + return text.length() >= abbrev.length() + && abbrev.equals(text.subSequence(0, abbrev.length())); + } + + // consume the duration unit and returning the remaining text. + CharSequence consumeDurationUnit(CharSequence text) { + return text.subSequence(abbrev.length(), text.length()); + } + + // scale the unit by the input scalingFunction, returning a value if + // one is produced, or an empty result when the operation results in an + // arithmetic overflow. + Optional scaleBy(Function scaleFunc) { + try { + return Optional.of(scaleFunc.apply(value)); + } catch (ArithmeticException e) { + return Optional.empty(); + } + } + } + + // interface for computing a duration from a duration unit and a scalar. + static interface DurationScalar { + // returns a duration value on a successful computation, and an empty + // result otherwise. + Optional applyTo(DurationUnit unit); + } + + // data holder for parsed fragments of a floating point duration scalar. + static class ParsedUnitPart implements DurationScalar { + private final CharSequence remainingText; + private final DurationScalar scalar; + + private ParsedUnitPart(CharSequence remainingText, DurationScalar scalar) { + this.remainingText = remainingText; + this.scalar = scalar; + } + + @Override + public Optional applyTo(DurationUnit unit) { + return scalar.applyTo(unit); + } + + CharSequence remainingText() { + return remainingText; + } + } + + // data holder for the leading integer value of a duration scalar. + static class IntegerScalarPart implements DurationScalar { + private final long value; + + private IntegerScalarPart(long value) { + this.value = value; + } + + @Override + public Optional applyTo(DurationUnit unit) { + return unit.scaleBy(d -> d.multipliedBy(value)); + } + } + + // data holder for the fractional floating point value of a duration + // scalar. + static class FractionScalarPart implements DurationScalar { + private final long value; + private final long scale; + + private FractionScalarPart(long value, long scale) { + this.value = value; + this.scale = scale; + } + + @Override + public Optional applyTo(DurationUnit unit) { + if (value == 0) { + return Optional.of(Duration.ZERO); + } + return unit.scaleBy(d -> d.multipliedBy(value).dividedBy(scale)); + } + } } diff --git a/src/test/java/org/threeten/extra/TestAmountFormats.java b/src/test/java/org/threeten/extra/TestAmountFormats.java index 54ef21d8..47b370a3 100644 --- a/src/test/java/org/threeten/extra/TestAmountFormats.java +++ b/src/test/java/org/threeten/extra/TestAmountFormats.java @@ -539,4 +539,53 @@ public static Object[][] wordBased_ru_duration_predicate() { {"105 \u043C\u0438\u043B\u043B\u0438\u0441\u0435\u043A\u0443\u043D\u0434", Duration.ofMillis(105)} }; } + + // ----------------------------------------------------------------------- + @ParameterizedTest + @UseDataProvider("duration_unitBased") + public void test_parseUnitBasedDuration(Duration expected, String input) { + assertEquals(expected, AmountFormats.parseUnitBasedDuration(input).orElse(null)); + } + + @DataProvider + public static Object[][] duration_unitBased() { + return new Object[][] { + // Failure cases. + {null, null}, + {null, ""}, + {null, "+"}, + {null, "-"}, + {null, "."}, + {null, ".1s"}, + {null, "inf"}, + {null, "-inf"}, + {null, "1.b"}, + {null, "1.1ps"}, + {null, String.format("%dh", Long.MAX_VALUE)}, // overflow in create duration + {null, String.format("%dh", Long.MAX_VALUE + 1)}, // overflow in leading int + {null, String.format("%ds2s", Long.MAX_VALUE - 1)}, // overflow on int add + // overflow on fraction add + {null, String.format("%d.1s2.999999999s", Long.MAX_VALUE - 2)}, + + // Passing cases. + {Duration.ZERO, "0"}, + {Duration.ofHours(1), "+1h"}, + {Duration.ofHours(1).negated(), "-1h"}, + {Duration.ofHours(1).plusMinutes(15).negated(), "-1.25h"}, + {Duration.ofSeconds(15).plusMillis(110), "15.11s"}, + {Duration.ofHours(1).plusMinutes(2).plusSeconds(3).plusMillis(400), "1h2m3.4s"}, + {Duration.ofMinutes(1), "1m"}, + {Duration.ofSeconds(1), "1s"}, + {Duration.ofMillis(1), "1ms"}, + {Duration.ofNanos(1000), "1us"}, + {Duration.ofNanos(1000), "1µs"}, // U+00B5 = micro symbol + {Duration.ofNanos(1000), "1μs"}, // U+03BC = Greek letter mu + {Duration.ofNanos(1), "1ns"}, + {Duration.ofHours(1).plusMinutes(1).plusSeconds(1), "1h1m1s"}, + // Loss of precision, but still a valid duration. + {Duration.ofSeconds(1).plusNanos(999_999_999), "1.9999999999999999999999999999s"}, + // Adding duration values to exactly the max duration. + {Duration.ofSeconds(Long.MAX_VALUE), String.format("%ds%ds", Long.MAX_VALUE - 2, 2)}, + }; + } } From 4007f1032bdd7a5b971074a674e79153e99d1d0d Mon Sep 17 00:00:00 2001 From: Johannes Jensen Date: Mon, 22 Feb 2021 16:43:42 +0100 Subject: [PATCH 204/279] Add containedBy(Start|End) for checking the separate parts of the contains check. --- .../java/org/threeten/extra/Interval.java | 30 ++++++ .../java/org/threeten/extra/TestInterval.java | 91 +++++++++++++++++++ 2 files changed, 121 insertions(+) diff --git a/src/main/java/org/threeten/extra/Interval.java b/src/main/java/org/threeten/extra/Interval.java index d08351f3..633e8d3e 100644 --- a/src/main/java/org/threeten/extra/Interval.java +++ b/src/main/java/org/threeten/extra/Interval.java @@ -342,6 +342,36 @@ public boolean contains(Instant instant) { return start.compareTo(instant) <= 0 && (instant.compareTo(end) < 0 || isUnboundedEnd()); } + /** + * Checks if this intervals start contains the specified instant. In essence the start part of {@code contains(Instant)} + *

      + * This checks if the specified instant is within the bounds of the start of this interval. + * If this range has an unbounded start then {@code containsFloor(Instant#MIN)} returns true. + * If this range has an unbounded end then {@code containsFloor(Instant#MAX)} returns true. + * + * @param instant the instant, not null + * @return true if this interval start contains the instant + */ + public boolean containedByStart(Instant instant) { + Objects.requireNonNull(instant, "instant"); + return start.compareTo(instant) <= 0; + } + + /** + * Checks if this intervals end contains the specified instant. In essence the end part of {@code contains(Instant)} + *

      + * This checks if the specified instant is within the bounds of the end of this interval. + * If this range has an unbounded start then {@code containsHigher(Instant#MIN)} returns true. + * If this range has an unbounded end then {@code containsHigher(Instant#MAX)} returns true. + * + * @param instant the instant, not null + * @return true if this intervals end contains the instant + */ + public boolean containedByEnd(Instant instant) { + Objects.requireNonNull(instant, "instant"); + return instant.compareTo(end) < 0 || isUnboundedEnd(); + } + /** * Checks if this interval encloses the specified interval. *

      diff --git a/src/test/java/org/threeten/extra/TestInterval.java b/src/test/java/org/threeten/extra/TestInterval.java index 94834bc5..a457b8e4 100644 --- a/src/test/java/org/threeten/extra/TestInterval.java +++ b/src/test/java/org/threeten/extra/TestInterval.java @@ -294,6 +294,97 @@ public void test_contains_Instant_null() { assertThrows(NullPointerException.class, () -> base.contains((Instant) null)); } + //----------------------------------------------------------------------- + @Test + public void test_containedByStart_Instant() { + Interval test = Interval.of(NOW1, NOW2); + assertEquals(false, test.containedByStart(NOW1.minusSeconds(1))); + assertEquals(true, test.containedByStart(NOW1)); + assertEquals(true, test.containedByStart(NOW1.plusSeconds(1))); + assertEquals(true, test.containedByStart(NOW2.minusSeconds(1))); + assertEquals(true, test.containedByStart(NOW2)); + } + + @Test + public void test_containedByStart_Instant_baseEmpty() { + Interval test = Interval.of(NOW1, NOW1); + assertEquals(false, test.containedByStart(NOW1.minusSeconds(1))); + assertEquals(true, test.containedByStart(NOW1)); + assertEquals(true, test.containedByStart(NOW1.plusSeconds(1))); + } + + @Test + public void test_containedByStart_min(){ + Interval test = Interval.of(Instant.MIN, NOW2); + assertEquals(true, test.containedByStart(Instant.MIN)); + assertEquals(true, test.containedByStart(NOW1)); + assertEquals(true, test.containedByStart(NOW2)); + assertEquals(true, test.containedByStart(NOW3)); + assertEquals(true, test.containedByStart(Instant.MAX)); + } + + @Test + public void test_containedByStart_max(){ + Interval test = Interval.of(NOW2, Instant.MAX); + assertEquals(false, test.containedByStart(Instant.MIN)); + assertEquals(false, test.containedByStart(NOW1)); + assertEquals(true, test.containedByStart(NOW2)); + assertEquals(true, test.containedByStart(NOW3)); + assertEquals(true, test.containedByStart(Instant.MAX)); + } + + @Test(expected = NullPointerException.class) + public void test_containedByStart_Instant_null() { + Interval base = Interval.of(NOW1, NOW2); + base.containedByStart((Instant) null); + } + + //----------------------------------------------------------------------- + @Test + public void test_containedByEnd_Instant() { + Interval test = Interval.of(NOW1, NOW2); + assertEquals(true, test.containedByEnd(NOW1.minusSeconds(1))); + assertEquals(true, test.containedByEnd(NOW1)); + assertEquals(true, test.containedByEnd(NOW1.plusSeconds(1))); + assertEquals(true, test.containedByEnd(NOW2.minusSeconds(1))); + assertEquals(false, test.containedByEnd(NOW2)); + assertEquals(false, test.containedByEnd(NOW3)); + } + + @Test + public void test_containedByEnd_Instant_baseEmpty() { + Interval test = Interval.of(NOW1, NOW1); + assertEquals(true, test.containedByEnd(NOW1.minusSeconds(1))); + assertEquals(false, test.containedByEnd(NOW1)); + assertEquals(false, test.containedByEnd(NOW1.plusSeconds(1))); + } + + @Test + public void test_containedByEnd_min(){ + Interval test = Interval.of(Instant.MIN, NOW2); + assertEquals(true, test.containedByEnd(Instant.MIN)); + assertEquals(true, test.containedByEnd(NOW1)); + assertEquals(false, test.containedByEnd(NOW2)); + assertEquals(false, test.containedByEnd(NOW3)); + assertEquals(false, test.containedByEnd(Instant.MAX)); + } + + @Test + public void test_containedByEnd_max(){ + Interval test = Interval.of(NOW2, Instant.MAX); + assertEquals(true, test.containedByEnd(Instant.MIN)); + assertEquals(true, test.containedByEnd(NOW1)); + assertEquals(true, test.containedByEnd(NOW2)); + assertEquals(true, test.containedByEnd(NOW3)); + assertEquals(true, test.containedByEnd(Instant.MAX)); + } + + @Test(expected = NullPointerException.class) + public void test_containedByEnd_Instant_null() { + Interval base = Interval.of(NOW1, NOW2); + base.containedByEnd((Instant) null); + } + //----------------------------------------------------------------------- @Test public void test_encloses_Interval() { From 9a3fc31380ef3b1a479108c7232d65b8ed0cd800 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Thu, 15 Apr 2021 23:45:35 +0100 Subject: [PATCH 205/279] Add Interval comparison methods Add set of eight methods that cover all use cases --- pom.xml | 4 + src/changes/changes.xml | 4 + .../java/org/threeten/extra/Interval.java | 237 ++++++++++++------ .../java/org/threeten/extra/TestInterval.java | 204 ++++++++------- 4 files changed, 284 insertions(+), 165 deletions(-) diff --git a/pom.xml b/pom.xml index c42e1a65..b667204a 100644 --- a/pom.xml +++ b/pom.xml @@ -70,6 +70,10 @@ Stephen A. Imhoff https://github.com/Clockwork-Muse + + Johannes Jensen + https://github.com/spand + M. Justin https://github.com/mjustin diff --git a/src/changes/changes.xml b/src/changes/changes.xml index bf9168ba..9fbb3bfa 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -8,6 +8,10 @@ + + Additional comparison methods on Interval. + Fixes #174. + Cache UtcInstant::toString(). Fixes #177. diff --git a/src/main/java/org/threeten/extra/Interval.java b/src/main/java/org/threeten/extra/Interval.java index 633e8d3e..e7fc5358 100644 --- a/src/main/java/org/threeten/extra/Interval.java +++ b/src/main/java/org/threeten/extra/Interval.java @@ -326,52 +326,6 @@ public Interval withEnd(Instant end) { } //----------------------------------------------------------------------- - /** - * Checks if this interval contains the specified instant. - *

      - * This checks if the specified instant is within the bounds of this interval. - * If this range has an unbounded start then {@code contains(Instant#MIN)} returns true. - * If this range has an unbounded end then {@code contains(Instant#MAX)} returns true. - * If this range is empty then this method always returns false. - * - * @param instant the instant, not null - * @return true if this interval contains the instant - */ - public boolean contains(Instant instant) { - Objects.requireNonNull(instant, "instant"); - return start.compareTo(instant) <= 0 && (instant.compareTo(end) < 0 || isUnboundedEnd()); - } - - /** - * Checks if this intervals start contains the specified instant. In essence the start part of {@code contains(Instant)} - *

      - * This checks if the specified instant is within the bounds of the start of this interval. - * If this range has an unbounded start then {@code containsFloor(Instant#MIN)} returns true. - * If this range has an unbounded end then {@code containsFloor(Instant#MAX)} returns true. - * - * @param instant the instant, not null - * @return true if this interval start contains the instant - */ - public boolean containedByStart(Instant instant) { - Objects.requireNonNull(instant, "instant"); - return start.compareTo(instant) <= 0; - } - - /** - * Checks if this intervals end contains the specified instant. In essence the end part of {@code contains(Instant)} - *

      - * This checks if the specified instant is within the bounds of the end of this interval. - * If this range has an unbounded start then {@code containsHigher(Instant#MIN)} returns true. - * If this range has an unbounded end then {@code containsHigher(Instant#MAX)} returns true. - * - * @param instant the instant, not null - * @return true if this intervals end contains the instant - */ - public boolean containedByEnd(Instant instant) { - Objects.requireNonNull(instant, "instant"); - return instant.compareTo(end) < 0 || isUnboundedEnd(); - } - /** * Checks if this interval encloses the specified interval. *

      @@ -509,62 +463,197 @@ public Interval span(Interval other) { //------------------------------------------------------------------------- /** - * Checks if this interval is after the specified instant. + * Checks if this interval is after the specified interval. *

      - * The result is true if this interval starts after the specified instant. + * The result is true if this interval starts after the end of the specified interval. + * Since intervals do not include their end points, this will return true if the + * two intervals abut. * An empty interval behaves as though it is an instant for comparison purposes. * - * @param instant the other instant to compare to, not null - * @return true if the start of this interval is after the specified instant + * @param interval the other interval to compare to, not null + * @return true if this interval is after the specified interval */ - public boolean isAfter(Instant instant) { - return start.compareTo(instant) > 0; + public boolean isAfter(Interval interval) { + return start.compareTo(interval.end) >= 0 && !interval.equals(this); } /** - * Checks if this interval is before the specified instant. + * Checks if this interval is before the specified interval. *

      - * The result is true if this interval ends before the specified instant. + * The result is true if this interval ends before the start of the specified interval. * Since intervals do not include their end points, this will return true if the - * instant equals the end of the interval. + * two intervals abut. * An empty interval behaves as though it is an instant for comparison purposes. * - * @param instant the other instant to compare to, not null - * @return true if the end of this interval is before or equal to the specified instant + * @param interval the other interval to compare to, not null + * @return true if this interval is before the specified interval */ - public boolean isBefore(Instant instant) { - return end.compareTo(instant) <= 0 && start.compareTo(instant) < 0; + public boolean isBefore(Interval interval) { + return end.compareTo(interval.start) <= 0 && !interval.equals(this); } //------------------------------------------------------------------------- /** - * Checks if this interval is after the specified interval. + * Checks if this interval starts on or before the specified instant. *

      - * The result is true if this interval starts after the end of the specified interval. - * Since intervals do not include their end points, this will return true if the - * two intervals abut. + * This method compares the start of the interval to the instant. + * An interval with an unbounded start is considered to start at {@code Instant.MIN}. + * + * @param instant the instant, not null + * @return true if this interval starts before the instant + */ + public boolean startsBefore(Instant instant) { + Objects.requireNonNull(instant, "instant"); + return start.compareTo(instant) < 0; + } + + /** + * Checks if this interval starts at or before the specified instant. + *

      + * This method compares the start of the interval to the instant. + * An interval with an unbounded start is considered to start at {@code Instant.MIN}. + * + * @param instant the instant, not null + * @return true if this interval starts at or before the instant + */ + public boolean startsAtOrBefore(Instant instant) { + Objects.requireNonNull(instant, "instant"); + return start.compareTo(instant) <= 0; + } + + /** + * Checks if this interval starts on or after the specified instant. + *

      + * This method compares the start of the interval to the instant. + * An interval with an unbounded start is considered to start at {@code Instant.MIN}. + * + * @param instant the instant, not null + * @return true if this interval starts after the instant + */ + public boolean startsAfter(Instant instant) { + Objects.requireNonNull(instant, "instant"); + return start.compareTo(instant) > 0; + } + + /** + * Checks if this interval starts at or after the specified instant. + *

      + * This method compares the start of the interval to the instant. + * An interval with an unbounded start is considered to start at {@code Instant.MIN}. + * + * @param instant the instant, not null + * @return true if this interval starts at or after the instant + */ + public boolean startsAtOrAfter(Instant instant) { + Objects.requireNonNull(instant, "instant"); + return start.compareTo(instant) >= 0; + } + + //------------------------------------------------------------------------- + /** + * Checks if this interval ends before the specified instant. + *

      + * This method compares the end of the interval to the instant. + * An interval with an unbounded end is considered to end after {@code Instant.MAX}. + * + * @param instant the instant, not null + * @return true if this interval ends before the instant + */ + public boolean endsBefore(Instant instant) { + Objects.requireNonNull(instant, "instant"); + return end.compareTo(instant) < 0 && !isUnboundedEnd(); + } + + /** + * Checks if this interval ends at or before the specified instant. + *

      + * This method compares the end of the interval to the instant. + * An interval with an unbounded end is considered to end after {@code Instant.MAX}. + * + * @param instant the instant, not null + * @return true if this interval ends at or before the instant + */ + public boolean endsAtOrBefore(Instant instant) { + Objects.requireNonNull(instant, "instant"); + return end.compareTo(instant) <= 0 && !isUnboundedEnd(); + } + + /** + * Checks if this interval ends after the specified instant. + *

      + * This method compares the end of the interval to the instant. + * An interval with an unbounded end is considered to end after {@code Instant.MAX}. + * + * @param instant the instant, not null + * @return true if this interval ends after the instant + */ + public boolean endsAfter(Instant instant) { + Objects.requireNonNull(instant, "instant"); + return end.compareTo(instant) > 0 || isUnboundedEnd(); + } + + /** + * Checks if this interval ends after the specified instant. + *

      + * This method compares the end of the interval to the instant. + * An interval with an unbounded end is considered to end after {@code Instant.MAX}. + * + * @param instant the instant, not null + * @return true if this interval ends at or after the instant + */ + public boolean endsAtOrAfter(Instant instant) { + Objects.requireNonNull(instant, "instant"); + return end.compareTo(instant) >= 0 || isUnboundedEnd(); + } + + //------------------------------------------------------------------------- + /** + * Checks if this interval contains the specified instant. + *

      + * This checks if the specified instant is within the bounds of this interval. + * If this interval has an unbounded start then {@code contains(Instant#MIN)} returns true. + * If this interval has an unbounded end then {@code contains(Instant#MAX)} returns true. + * If this interval is empty then this method always returns false. + *

      + * This is equivalent to {@link #startsAtOrBefore(Instant)} {@code &&} {@link #endsAfter(Instant)}. + * + * @param instant the instant, not null + * @return true if this interval contains the instant + */ + public boolean contains(Instant instant) { + return startsAtOrBefore(instant) && endsAfter(instant); + } + + /** + * Checks if this interval is after the specified instant. + *

      + * The result is true if this interval starts after the specified instant. * An empty interval behaves as though it is an instant for comparison purposes. + *

      + * This is equivalent to {@link #startsAfter(Instant)}. * - * @param interval the other interval to compare to, not null - * @return true if this interval is after the specified interval + * @param instant the other instant to compare to, not null + * @return true if the start of this interval is after the specified instant */ - public boolean isAfter(Interval interval) { - return start.compareTo(interval.end) >= 0 && !interval.equals(this); + public boolean isAfter(Instant instant) { + return startsAfter(instant); } /** - * Checks if this interval is before the specified interval. + * Checks if this interval is before the specified instant. *

      - * The result is true if this interval ends before the start of the specified interval. + * The result is true if this interval ends before the specified instant. * Since intervals do not include their end points, this will return true if the - * two intervals abut. + * instant equals the end of the interval. * An empty interval behaves as though it is an instant for comparison purposes. + *

      + * This is equivalent to {@link #endsAtOrBefore(Instant)} {@code &&} {@link #startsBefore(Instant)}. * - * @param interval the other interval to compare to, not null - * @return true if this interval is before the specified interval + * @param instant the other instant to compare to, not null + * @return true if the end of this interval is before or equal to the specified instant */ - public boolean isBefore(Interval interval) { - return end.compareTo(interval.start) <= 0 && !interval.equals(this); + public boolean isBefore(Instant instant) { + return endsAtOrBefore(instant) && startsBefore(instant); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestInterval.java b/src/test/java/org/threeten/extra/TestInterval.java index a457b8e4..ebe18cfe 100644 --- a/src/test/java/org/threeten/extra/TestInterval.java +++ b/src/test/java/org/threeten/extra/TestInterval.java @@ -53,6 +53,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import com.tngtech.junit.dataprovider.DataProvider; import com.tngtech.junit.dataprovider.UseDataProvider; @@ -66,6 +67,12 @@ public class TestInterval { static Instant NOW2 = NOW1.plusSeconds(60); static Instant NOW3 = NOW2.plusSeconds(60); static Instant NOW4 = NOW3.plusSeconds(60); + static Instant NOW11 = NOW1.plusSeconds(11); + static Instant NOW12 = NOW1.plusSeconds(12); + static Instant NOW13 = NOW1.plusSeconds(13); + static Instant NOW14 = NOW1.plusSeconds(14); + static Instant NOW15 = NOW1.plusSeconds(15); + static Instant NOW16 = NOW1.plusSeconds(16); //----------------------------------------------------------------------- @Test @@ -294,97 +301,6 @@ public void test_contains_Instant_null() { assertThrows(NullPointerException.class, () -> base.contains((Instant) null)); } - //----------------------------------------------------------------------- - @Test - public void test_containedByStart_Instant() { - Interval test = Interval.of(NOW1, NOW2); - assertEquals(false, test.containedByStart(NOW1.minusSeconds(1))); - assertEquals(true, test.containedByStart(NOW1)); - assertEquals(true, test.containedByStart(NOW1.plusSeconds(1))); - assertEquals(true, test.containedByStart(NOW2.minusSeconds(1))); - assertEquals(true, test.containedByStart(NOW2)); - } - - @Test - public void test_containedByStart_Instant_baseEmpty() { - Interval test = Interval.of(NOW1, NOW1); - assertEquals(false, test.containedByStart(NOW1.minusSeconds(1))); - assertEquals(true, test.containedByStart(NOW1)); - assertEquals(true, test.containedByStart(NOW1.plusSeconds(1))); - } - - @Test - public void test_containedByStart_min(){ - Interval test = Interval.of(Instant.MIN, NOW2); - assertEquals(true, test.containedByStart(Instant.MIN)); - assertEquals(true, test.containedByStart(NOW1)); - assertEquals(true, test.containedByStart(NOW2)); - assertEquals(true, test.containedByStart(NOW3)); - assertEquals(true, test.containedByStart(Instant.MAX)); - } - - @Test - public void test_containedByStart_max(){ - Interval test = Interval.of(NOW2, Instant.MAX); - assertEquals(false, test.containedByStart(Instant.MIN)); - assertEquals(false, test.containedByStart(NOW1)); - assertEquals(true, test.containedByStart(NOW2)); - assertEquals(true, test.containedByStart(NOW3)); - assertEquals(true, test.containedByStart(Instant.MAX)); - } - - @Test(expected = NullPointerException.class) - public void test_containedByStart_Instant_null() { - Interval base = Interval.of(NOW1, NOW2); - base.containedByStart((Instant) null); - } - - //----------------------------------------------------------------------- - @Test - public void test_containedByEnd_Instant() { - Interval test = Interval.of(NOW1, NOW2); - assertEquals(true, test.containedByEnd(NOW1.minusSeconds(1))); - assertEquals(true, test.containedByEnd(NOW1)); - assertEquals(true, test.containedByEnd(NOW1.plusSeconds(1))); - assertEquals(true, test.containedByEnd(NOW2.minusSeconds(1))); - assertEquals(false, test.containedByEnd(NOW2)); - assertEquals(false, test.containedByEnd(NOW3)); - } - - @Test - public void test_containedByEnd_Instant_baseEmpty() { - Interval test = Interval.of(NOW1, NOW1); - assertEquals(true, test.containedByEnd(NOW1.minusSeconds(1))); - assertEquals(false, test.containedByEnd(NOW1)); - assertEquals(false, test.containedByEnd(NOW1.plusSeconds(1))); - } - - @Test - public void test_containedByEnd_min(){ - Interval test = Interval.of(Instant.MIN, NOW2); - assertEquals(true, test.containedByEnd(Instant.MIN)); - assertEquals(true, test.containedByEnd(NOW1)); - assertEquals(false, test.containedByEnd(NOW2)); - assertEquals(false, test.containedByEnd(NOW3)); - assertEquals(false, test.containedByEnd(Instant.MAX)); - } - - @Test - public void test_containedByEnd_max(){ - Interval test = Interval.of(NOW2, Instant.MAX); - assertEquals(true, test.containedByEnd(Instant.MIN)); - assertEquals(true, test.containedByEnd(NOW1)); - assertEquals(true, test.containedByEnd(NOW2)); - assertEquals(true, test.containedByEnd(NOW3)); - assertEquals(true, test.containedByEnd(Instant.MAX)); - } - - @Test(expected = NullPointerException.class) - public void test_containedByEnd_Instant_null() { - Interval base = Interval.of(NOW1, NOW2); - base.containedByEnd((Instant) null); - } - //----------------------------------------------------------------------- @Test public void test_encloses_Interval() { @@ -683,6 +599,112 @@ public void test_unionAndSpan_same() { assertEquals(test, test.span(test)); } + //----------------------------------------------------------------------- + static Object[][] data_starts() { + return new Object[][] { + // normal + {Interval.of(NOW12, NOW14), NOW11, false, false, true, true}, + {Interval.of(NOW12, NOW14), NOW12, false, true, false, true}, + {Interval.of(NOW12, NOW14), NOW13, true, true, false, false}, + {Interval.of(NOW12, NOW14), NOW14, true, true, false, false}, + {Interval.of(NOW12, NOW14), NOW15, true, true, false, false}, + // empty interval + {Interval.of(NOW12, NOW12), NOW11, false, false, true, true}, + {Interval.of(NOW12, NOW12), NOW12, false, true, false, true}, + {Interval.of(NOW12, NOW12), NOW13, true, true, false, false}, + // unbounded start + {Interval.of(Instant.MIN, NOW12), Instant.MIN, false, true, false, true}, + {Interval.of(Instant.MIN, NOW12), NOW11, true, true, false, false}, + {Interval.of(Instant.MIN, NOW12), NOW12, true, true, false, false}, + {Interval.of(Instant.MIN, NOW12), NOW13, true, true, false, false}, + {Interval.of(Instant.MIN, NOW12), Instant.MAX, true, true, false, false}, + // unbounded end + {Interval.of(NOW12, Instant.MAX), Instant.MIN, false, false, true, true}, + {Interval.of(NOW12, Instant.MAX), NOW11, false, false, true, true}, + {Interval.of(NOW12, Instant.MAX), NOW12, false, true, false, true}, + {Interval.of(NOW12, Instant.MAX), NOW13, true, true, false, false}, + {Interval.of(NOW12, Instant.MAX), Instant.MAX, true, true, false, false}, + }; + } + + @ParameterizedTest + @MethodSource("data_starts") + public void test_starts_Instant( + Interval test, + Instant instant, + boolean expectedStartsBefore, + boolean expectedStartsAtOrBefore, + boolean expectedStartsAfter, + boolean expectedStartsAtOrAfter) { + + assertEquals(expectedStartsBefore, test.startsBefore(instant)); + assertEquals(expectedStartsAtOrBefore, test.startsAtOrBefore(instant)); + assertEquals(expectedStartsAfter, test.startsAfter(instant)); + assertEquals(expectedStartsAtOrAfter, test.startsAtOrAfter(instant)); + } + + @Test + public void test_starts_Instant_null() { + Interval base = Interval.of(NOW12, NOW14); + assertThrows(NullPointerException.class, () -> base.startsBefore((Instant) null)); + assertThrows(NullPointerException.class, () -> base.startsAtOrBefore((Instant) null)); + assertThrows(NullPointerException.class, () -> base.startsAfter((Instant) null)); + assertThrows(NullPointerException.class, () -> base.startsAtOrAfter((Instant) null)); + } + + //----------------------------------------------------------------------- + static Object[][] data_ends() { + return new Object[][] { + // normal + {Interval.of(NOW12, NOW14), NOW11, false, false, true, true}, + {Interval.of(NOW12, NOW14), NOW12, false, false, true, true}, + {Interval.of(NOW12, NOW14), NOW13, false, false, true, true}, + {Interval.of(NOW12, NOW14), NOW14, false, true, false, true}, + {Interval.of(NOW12, NOW14), NOW15, true, true, false, false}, + // empty interval + {Interval.of(NOW12, NOW12), NOW11, false, false, true, true}, + {Interval.of(NOW12, NOW12), NOW12, false, true, false, true}, + {Interval.of(NOW12, NOW12), NOW13, true, true, false, false}, + // unbounded start + {Interval.of(Instant.MIN, NOW12), Instant.MIN, false, false, true, true}, + {Interval.of(Instant.MIN, NOW12), NOW11, false, false, true, true}, + {Interval.of(Instant.MIN, NOW12), NOW12, false, true, false, true}, + {Interval.of(Instant.MIN, NOW12), NOW13, true, true, false, false}, + {Interval.of(Instant.MIN, NOW12), Instant.MAX, true, true, false, false}, + // unbounded end + {Interval.of(NOW12, Instant.MAX), Instant.MIN, false, false, true, true}, + {Interval.of(NOW12, Instant.MAX), NOW11, false, false, true, true}, + {Interval.of(NOW12, Instant.MAX), NOW12, false, false, true, true}, + {Interval.of(NOW12, Instant.MAX), NOW13, false, false, true, true}, + {Interval.of(NOW12, Instant.MAX), Instant.MAX, false, false, true, true}, + }; + } + + @ParameterizedTest + @MethodSource("data_ends") + public void test_ends_Instant( + Interval test, + Instant instant, + boolean expectedEndsBefore, + boolean expectedEndsAtOrBefore, + boolean expectedEndsAfter, + boolean expectedEndsAtOrAfter) { + + assertEquals(expectedEndsBefore, test.endsBefore(instant)); + assertEquals(expectedEndsAtOrBefore, test.endsAtOrBefore(instant)); + assertEquals(expectedEndsAfter, test.endsAfter(instant)); + assertEquals(expectedEndsAtOrAfter, test.endsAtOrAfter(instant)); + } + + @Test + public void test_ends_Instant_null() { + Interval base = Interval.of(NOW12, NOW14); +// assertThrows(NullPointerException.class, () -> base.endsBefore((Instant) null)); +// assertThrows(NullPointerException.class, () -> base.endsOnOrBefore((Instant) null)); + assertThrows(NullPointerException.class, () -> base.endsAfter((Instant) null)); +// assertThrows(NullPointerException.class, () -> base.endsOnOrAfter((Instant) null)); + } + //----------------------------------------------------------------------- @Test public void test_isAfter_Instant() { From 7917e26732dd6bf7f552595047dafa4dba53a85c Mon Sep 17 00:00:00 2001 From: Tristan Swadell Date: Fri, 16 Apr 2021 09:55:40 -0700 Subject: [PATCH 206/279] Replace the Optional return with a Duration and a DateTimeParseException --- .../org/threeten/extra/AmountFormats.java | 138 +++++++++--------- .../org/threeten/extra/TestAmountFormats.java | 69 ++++++--- 2 files changed, 114 insertions(+), 93 deletions(-) diff --git a/src/main/java/org/threeten/extra/AmountFormats.java b/src/main/java/org/threeten/extra/AmountFormats.java index 0d4844d4..03b74f5e 100644 --- a/src/main/java/org/threeten/extra/AmountFormats.java +++ b/src/main/java/org/threeten/extra/AmountFormats.java @@ -33,6 +33,7 @@ import java.time.Duration; import java.time.Period; +import java.time.format.DateTimeParseException; import java.time.temporal.TemporalAmount; import java.util.Arrays; import java.util.List; @@ -309,104 +310,94 @@ private static boolean oppositeSigns(int a, int b) { // ------------------------------------------------------------------------- /** - * Parses a unit-based duration string to a duration value. + * Parses formatted durations based on units. *

      - * This is an implementation of Golang's {@link https://golang.org/pkg/time/#ParseDuration}: - * ParseDuration parses a duration string. A duration string is a possibly - * signed sequence of decimal numbers, each with optional fraction and a - * unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are - * "ns", "us" (or "µs"), "ms", "s", "m", "h". - *

      - * Note, the value "0" is specially supported as {@code Duration.ZERO}, but - * unlike the Go implementation infinite durations are not supported. + * The behaviour matches the Golang + * duration parser; however, infinite durations are not supported. * * @param durationText the formatted unit-based duration string. * @return the {@code Duration} value represented by the string, if possible. */ - public static Optional parseUnitBasedDuration(CharSequence durationText) { - // return no duration from null input strings. - if (durationText == null) { - return Optional.empty(); - } + public static Duration parseUnitBasedDuration(CharSequence durationText) { + Objects.requireNonNull(durationText, "durationText must not be null"); + + // variables for tracking error positions during parsing. + int offset = 0; + CharSequence original = durationText; // consume the leading sign - or + if one is present. int sign = 1; Optional updatedText = consumePrefix(durationText, '-'); if (updatedText.isPresent()) { sign = -1; + offset += 1; durationText = updatedText.get(); } else { - durationText = consumePrefix(durationText, '+').orElse(durationText); + updatedText = consumePrefix(durationText, '+'); + if (updatedText.isPresent()) { + offset += 1; + } + durationText = updatedText.orElse(durationText); } // special case for a string of "0" if (durationText.equals("0")) { - return Optional.of(Duration.ZERO); + return Duration.ZERO; } // special case, empty string as an invalid duration. if (durationText.length() == 0) { - return Optional.empty(); + throw new DateTimeParseException("Not a numeric value", original, 0); } Duration value = Duration.ZERO; int durationTextLength = durationText.length(); while (durationTextLength > 0) { - Optional optIntegerPart = - consumeDurationLeadingInt(durationText); - // check for a missing leading integer. - if (!optIntegerPart.isPresent()) { - return Optional.empty(); - } - ParsedUnitPart integerPart = optIntegerPart.get(); + ParsedUnitPart integerPart = + consumeDurationLeadingInt(durationText, original, offset); + offset += (durationText.length() - integerPart.remainingText().length()); durationText = integerPart.remainingText(); DurationScalar leadingInt = integerPart; DurationScalar fraction = EMPTY_FRACTION; Optional dot = consumePrefix(durationText, '.'); if (dot.isPresent()) { + offset += 1; durationText = dot.get(); - Optional optFractionPart = - consumeDurationFraction(durationText); - // dot '.' present, but no fractional part, return. - if (!optFractionPart.isPresent()) { - return Optional.empty(); - } + ParsedUnitPart fractionPart = + consumeDurationFraction(durationText, original, offset); // update the remaining string and fraction. - ParsedUnitPart fractionPart = optFractionPart.get(); + offset += (durationText.length() - fractionPart.remainingText().length()); durationText = fractionPart.remainingText(); fraction = fractionPart; } - Optional unitPart = findUnit(durationText); - // no matching unit found, return. - if (!unitPart.isPresent()) { - return Optional.empty(); - } - DurationUnit unit = unitPart.get(); - Optional optUnitValue = leadingInt.applyTo(unit); - if (!optUnitValue.isPresent()) { - return Optional.empty(); - } - Duration unitValue = optUnitValue.get(); - Optional optFractionValue = fraction.applyTo(unit); - if (!optFractionValue.isPresent()) { - return Optional.empty(); + Optional optUnit = findUnit(durationText); + if (!optUnit.isPresent()) { + throw new DateTimeParseException( + "Invalid duration unit", original, offset); } + DurationUnit unit = optUnit.get(); try { - unitValue = unitValue.plus(optFractionValue.get()); + Duration unitValue = leadingInt.applyTo(unit); + Duration fractionValue = fraction.applyTo(unit); + unitValue = unitValue.plus(fractionValue); value = value.plus(unitValue); } catch (ArithmeticException e) { - // overflow of the valid range possible for a Duration - return Optional.empty(); + throw new DateTimeParseException( + "Duration string exceeds valid numeric range", + original, offset, e); } // update the remaining text and text length. - durationText = unit.consumeDurationUnit(durationText); + CharSequence remainingText = unit.consumeDurationUnit(durationText); + offset += (durationText.length() - remainingText.length()); + durationText = remainingText; durationTextLength = durationText.length(); } - return sign < 0 ? Optional.of(value.negated()) : Optional.of(value); + return sign < 0 ? value.negated() : value; } // consume the fractional part of a unit-based duration, e.g. // .. - private static Optional consumeDurationLeadingInt(CharSequence text) { + private static ParsedUnitPart consumeDurationLeadingInt(CharSequence text, + CharSequence original, int offset) { long integerPart = 0; int i = 0; int valueLength = text.length(); @@ -417,27 +408,32 @@ private static Optional consumeDurationLeadingInt(CharSequence t } // overflow of a single numeric specifier for a duration. if (integerPart > Long.MAX_VALUE / 10) { - return Optional.empty(); + throw new DateTimeParseException( + "Duration string exceeds valid numeric range", + original, i + offset); } integerPart *= 10; integerPart += (long) (c - '0'); // overflow of a single numeric specifier for a duration. if (integerPart < 0) { - return Optional.empty(); + throw new DateTimeParseException( + "Duration string exceeds valid numeric range", + original, i + offset); } } // if no text was consumed, return empty. if (i == 0) { - return Optional.empty(); + throw new DateTimeParseException( + "Missing leading integer", original, offset); } - return Optional.of( - new ParsedUnitPart(text.subSequence(i, text.length()), - new IntegerScalarPart(integerPart))); + return new ParsedUnitPart(text.subSequence(i, text.length()), + new IntegerScalarPart(integerPart)); } // consume the fractional part of a unit-based duration, e.g. // .. - private static Optional consumeDurationFraction(CharSequence text) { + private static ParsedUnitPart consumeDurationFraction(CharSequence text, + CharSequence original, int offset) { int i = 0; long fraction = 0; long scale = 1; @@ -462,11 +458,11 @@ private static Optional consumeDurationFraction(CharSequence tex scale *= 10; } if (i == 0) { - return Optional.empty(); + throw new DateTimeParseException( + "Missing numeric fraction after '.'", original, offset); } - return Optional.of( - new ParsedUnitPart(text.subSequence(i, text.length()), - new FractionScalarPart(fraction, scale))); + return new ParsedUnitPart(text.subSequence(i, text.length()), + new FractionScalarPart(fraction, scale)); } // find the duration unit at the beginning of the input text, if present. @@ -624,12 +620,8 @@ CharSequence consumeDurationUnit(CharSequence text) { // scale the unit by the input scalingFunction, returning a value if // one is produced, or an empty result when the operation results in an // arithmetic overflow. - Optional scaleBy(Function scaleFunc) { - try { - return Optional.of(scaleFunc.apply(value)); - } catch (ArithmeticException e) { - return Optional.empty(); - } + Duration scaleBy(Function scaleFunc) { + return scaleFunc.apply(value); } } @@ -637,7 +629,7 @@ Optional scaleBy(Function scaleFunc) { static interface DurationScalar { // returns a duration value on a successful computation, and an empty // result otherwise. - Optional applyTo(DurationUnit unit); + Duration applyTo(DurationUnit unit); } // data holder for parsed fragments of a floating point duration scalar. @@ -651,7 +643,7 @@ private ParsedUnitPart(CharSequence remainingText, DurationScalar scalar) { } @Override - public Optional applyTo(DurationUnit unit) { + public Duration applyTo(DurationUnit unit) { return scalar.applyTo(unit); } @@ -669,7 +661,7 @@ private IntegerScalarPart(long value) { } @Override - public Optional applyTo(DurationUnit unit) { + public Duration applyTo(DurationUnit unit) { return unit.scaleBy(d -> d.multipliedBy(value)); } } @@ -686,9 +678,9 @@ private FractionScalarPart(long value, long scale) { } @Override - public Optional applyTo(DurationUnit unit) { + public Duration applyTo(DurationUnit unit) { if (value == 0) { - return Optional.of(Duration.ZERO); + return Duration.ZERO; } return unit.scaleBy(d -> d.multipliedBy(value).dividedBy(scale)); } diff --git a/src/test/java/org/threeten/extra/TestAmountFormats.java b/src/test/java/org/threeten/extra/TestAmountFormats.java index 47b370a3..36969b8d 100644 --- a/src/test/java/org/threeten/extra/TestAmountFormats.java +++ b/src/test/java/org/threeten/extra/TestAmountFormats.java @@ -32,9 +32,11 @@ package org.threeten.extra; import static org.junit.jupiter.api.Assertions.assertEquals; - +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.Duration; import java.time.Period; +import java.time.format.DateTimeParseException; import java.util.Locale; import org.junit.jupiter.api.Test; @@ -544,30 +546,12 @@ public static Object[][] wordBased_ru_duration_predicate() { @ParameterizedTest @UseDataProvider("duration_unitBased") public void test_parseUnitBasedDuration(Duration expected, String input) { - assertEquals(expected, AmountFormats.parseUnitBasedDuration(input).orElse(null)); + assertEquals(expected, AmountFormats.parseUnitBasedDuration(input)); } @DataProvider public static Object[][] duration_unitBased() { return new Object[][] { - // Failure cases. - {null, null}, - {null, ""}, - {null, "+"}, - {null, "-"}, - {null, "."}, - {null, ".1s"}, - {null, "inf"}, - {null, "-inf"}, - {null, "1.b"}, - {null, "1.1ps"}, - {null, String.format("%dh", Long.MAX_VALUE)}, // overflow in create duration - {null, String.format("%dh", Long.MAX_VALUE + 1)}, // overflow in leading int - {null, String.format("%ds2s", Long.MAX_VALUE - 1)}, // overflow on int add - // overflow on fraction add - {null, String.format("%d.1s2.999999999s", Long.MAX_VALUE - 2)}, - - // Passing cases. {Duration.ZERO, "0"}, {Duration.ofHours(1), "+1h"}, {Duration.ofHours(1).negated(), "-1h"}, @@ -588,4 +572,49 @@ public static Object[][] duration_unitBased() { {Duration.ofSeconds(Long.MAX_VALUE), String.format("%ds%ds", Long.MAX_VALUE - 2, 2)}, }; } + + @ParameterizedTest + @UseDataProvider("duration_unitBasedErrors") + public void test_parseUnitBasedDurationErrors(Exception e, String input) { + Exception thrown = + assertThrows(e.getClass(), () -> AmountFormats.parseUnitBasedDuration(input)); + assertEquals(e.getMessage(), thrown.getMessage()); + if (e instanceof DateTimeParseException) { + DateTimeParseException expected = (DateTimeParseException) e; + DateTimeParseException actual = (DateTimeParseException) thrown; + assertEquals(expected.getParsedString(), actual.getParsedString()); + assertEquals(expected.getErrorIndex(), actual.getErrorIndex()); + } + } + + @DataProvider + public static Object[][] duration_unitBasedErrors() { + return new Object[][] { + {new NullPointerException("durationText must not be null"), null}, + {new DateTimeParseException("Not a numeric value", "", 0), ""}, + {new DateTimeParseException("Not a numeric value", "+", 0), "+"}, + {new DateTimeParseException("Not a numeric value", "-", 0), "-"}, + {new DateTimeParseException("Missing leading integer", ".", 0), "."}, + {new DateTimeParseException("Missing leading integer", ".1s", 0), ".1s"}, + {new DateTimeParseException("Missing leading integer", "inf", 0), "inf"}, + {new DateTimeParseException("Missing leading integer", "-inf", 1), "-inf"}, + {new DateTimeParseException("Missing numeric fraction after '.'", "1.b", 2), "1.b"}, + {new DateTimeParseException("Invalid duration unit", "1.1ps", 3), "1.1ps"}, + {new DateTimeParseException( + "Duration string exceeds valid numeric range", "9223372036854775807h", 19), + String.format("%dh", Long.MAX_VALUE)}, // overflow in create duration + {new DateTimeParseException( + "Duration string exceeds valid numeric range", "-9223372036854775808h", 19), + String.format("%dh", Long.MAX_VALUE + 1)}, // overflow in leading int + {new DateTimeParseException( + "Duration string exceeds valid numeric range", + "9223372036854775806s2s", 21), + String.format("%ds2s", Long.MAX_VALUE - 1)}, // overflow on int add + // overflow on fraction add + {new DateTimeParseException( + "Duration string exceeds valid numeric range", + "9223372036854775805.1s2.999999999s", 33), + String.format("%d.1s2.999999999s", Long.MAX_VALUE - 2)} + }; + } } From 1bc1c08c0a114b87cbc3c692f784155fe95b4c76 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 20 Apr 2021 10:43:32 +0100 Subject: [PATCH 207/279] Remove codecov Change name of secret --- .github/workflows/build.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f9f2eb84..53ba05ad 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,16 +41,11 @@ jobs: - name: Maven build run: | mvn install site - - name: CodeCov upload - if: matrix.java == '11' - uses: codecov/codecov-action@v1 - with: - file: ./target/site/jacoco/jacoco.xml - name: Website if: matrix.java == '11' && github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/website') || startsWith(github.ref, 'refs/tags/v')) env: - GITHUB_TOKEN: ${{ secrets.GITHUB_PERSONAL_TOKEN }} + GITHUB_TOKEN: ${{ secrets.PERSONAL_TOKEN_GH }} run: | chmod +x ./.github/website.sh .github/website.sh From 336a73d926167dd319e004a4227ff4db337f8516 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 26 Apr 2021 23:00:48 +0100 Subject: [PATCH 208/279] Fix tests --- src/test/java/org/threeten/extra/TestInterval.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/threeten/extra/TestInterval.java b/src/test/java/org/threeten/extra/TestInterval.java index ebe18cfe..7578d2a5 100644 --- a/src/test/java/org/threeten/extra/TestInterval.java +++ b/src/test/java/org/threeten/extra/TestInterval.java @@ -600,7 +600,7 @@ public void test_unionAndSpan_same() { } //----------------------------------------------------------------------- - static Object[][] data_starts() { + public static Object[][] data_starts() { return new Object[][] { // normal {Interval.of(NOW12, NOW14), NOW11, false, false, true, true}, @@ -653,7 +653,7 @@ public void test_starts_Instant_null() { } //----------------------------------------------------------------------- - static Object[][] data_ends() { + public static Object[][] data_ends() { return new Object[][] { // normal {Interval.of(NOW12, NOW14), NOW11, false, false, true, true}, From cbe70d4335fc2aacac1f5005791f4819df075645 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 26 Apr 2021 23:30:18 +0100 Subject: [PATCH 209/279] Update after PRs --- pom.xml | 6 +++--- src/changes/changes.xml | 6 +++++- src/main/java/org/threeten/extra/AmountFormats.java | 8 +++++++- src/test/java/org/threeten/extra/TestAmountFormats.java | 2 +- src/test/java/org/threeten/extra/TestInterval.java | 6 +++--- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index b667204a..1cae061f 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.6.1-SNAPSHOT + 1.7.0-SNAPSHOT Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later https://www.threeten.org/threeten-extra @@ -135,8 +135,8 @@ https://github.com/nsommer - spand - https://github.com/spand + Tristan Swadell + https://github.com/TristonianJones Dimo Velev diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 9fbb3bfa..9a09ae7a 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,11 +7,15 @@ - + Additional comparison methods on Interval. Fixes #174. + + Add Go-compatible duration parsing. + Fixes #182. + Cache UtcInstant::toString(). Fixes #177. diff --git a/src/main/java/org/threeten/extra/AmountFormats.java b/src/main/java/org/threeten/extra/AmountFormats.java index 03b74f5e..208c1abd 100644 --- a/src/main/java/org/threeten/extra/AmountFormats.java +++ b/src/main/java/org/threeten/extra/AmountFormats.java @@ -313,7 +313,13 @@ private static boolean oppositeSigns(int a, int b) { * Parses formatted durations based on units. *

      * The behaviour matches the Golang - * duration parser; however, infinite durations are not supported. + * duration parser, however, infinite durations are not supported. + *

      + * The duration format is a possibly signed sequence of decimal numbers, each with optional + * fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are + * "ns", "us" (or "µs"), "ms", "s", "m", "h". + *

      + * Note, the value "0" is specially supported as {@code Duration.ZERO}. * * @param durationText the formatted unit-based duration string. * @return the {@code Duration} value represented by the string, if possible. diff --git a/src/test/java/org/threeten/extra/TestAmountFormats.java b/src/test/java/org/threeten/extra/TestAmountFormats.java index 36969b8d..423c0c8f 100644 --- a/src/test/java/org/threeten/extra/TestAmountFormats.java +++ b/src/test/java/org/threeten/extra/TestAmountFormats.java @@ -33,7 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; + import java.time.Duration; import java.time.Period; import java.time.format.DateTimeParseException; diff --git a/src/test/java/org/threeten/extra/TestInterval.java b/src/test/java/org/threeten/extra/TestInterval.java index 7578d2a5..5f3c4d5f 100644 --- a/src/test/java/org/threeten/extra/TestInterval.java +++ b/src/test/java/org/threeten/extra/TestInterval.java @@ -699,10 +699,10 @@ public void test_ends_Instant( @Test public void test_ends_Instant_null() { Interval base = Interval.of(NOW12, NOW14); -// assertThrows(NullPointerException.class, () -> base.endsBefore((Instant) null)); -// assertThrows(NullPointerException.class, () -> base.endsOnOrBefore((Instant) null)); + assertThrows(NullPointerException.class, () -> base.endsBefore((Instant) null)); + assertThrows(NullPointerException.class, () -> base.endsAtOrBefore((Instant) null)); assertThrows(NullPointerException.class, () -> base.endsAfter((Instant) null)); -// assertThrows(NullPointerException.class, () -> base.endsOnOrAfter((Instant) null)); + assertThrows(NullPointerException.class, () -> base.endsAtOrAfter((Instant) null)); } //----------------------------------------------------------------------- From dabe22127745b87ec82d3d1f918e06a5c901f8f9 Mon Sep 17 00:00:00 2001 From: Harald Kuhr Date: Tue, 27 Apr 2021 12:19:15 +0200 Subject: [PATCH 210/279] Fix for #184 A more natural way to create unbounded Intervals --- .../java/org/threeten/extra/Interval.java | 24 ++++++++++ .../java/org/threeten/extra/TestInterval.java | 48 +++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/src/main/java/org/threeten/extra/Interval.java b/src/main/java/org/threeten/extra/Interval.java index e7fc5358..71eab159 100644 --- a/src/main/java/org/threeten/extra/Interval.java +++ b/src/main/java/org/threeten/extra/Interval.java @@ -129,6 +129,30 @@ public static Interval of(Instant startInclusive, Duration duration) { return new Interval(startInclusive, startInclusive.plus(duration)); } + /** + * Obtains an instance of {@code Interval} with the specified start instant and unbounded end. + * + * @param startInclusive the start instant, inclusive, not null + * + * @return a new {@code Instant} with the specified start instant. + */ + public static Interval startingAt(final Instant startInclusive) { + Objects.requireNonNull(startInclusive, "startInclusive"); + return Interval.ALL.withStart(startInclusive); + } + + /** + * Obtains an instance of {@code Interval} with unbounded start and the specified end instant. + * + * @param endExclusive the end instant, exclusive, not null + * + * @return a new {@code Instant} with the specified end instant. + */ + public static Interval endingAt(final Instant endExclusive) { + Objects.requireNonNull(endExclusive, "endExclusive"); + return Interval.ALL.withEnd(endExclusive); + } + //----------------------------------------------------------------------- /** * Obtains an instance of {@code Interval} from a text string such as diff --git a/src/test/java/org/threeten/extra/TestInterval.java b/src/test/java/org/threeten/extra/TestInterval.java index 5f3c4d5f..5f8e7b1f 100644 --- a/src/test/java/org/threeten/extra/TestInterval.java +++ b/src/test/java/org/threeten/extra/TestInterval.java @@ -170,6 +170,54 @@ public void test_of_Instant_Duration_nullDuration() { assertThrows(NullPointerException.class, () -> Interval.of(NOW1, (Duration) null)); } + //----------------------------------------------------------------------- + @Test + public void test_startingAt_Instant_createsUnboundedEnd() { + Interval interval = Interval.startingAt(NOW1); + + assertEquals(NOW1, interval.getStart()); + assertTrue(interval.isUnboundedEnd()); + assertFalse(interval.isEmpty()); + } + + @Test + public void test_startingAt_InstantMAX_createsUnboundedEndEmpty() { + Interval interval = Interval.startingAt(Instant.MAX); + + assertEquals(Instant.MAX, interval.getStart()); + assertTrue(interval.isUnboundedEnd()); + assertTrue(interval.isEmpty()); + } + + @Test + public void test_startingAt_null() { + assertThrows(NullPointerException.class, () -> Interval.startingAt(null)); + } + + //----------------------------------------------------------------------- + @Test + public void test_endingAt_createsUnboundedStart() { + Interval interval = Interval.endingAt(NOW1); + + assertEquals(NOW1, interval.getEnd()); + assertTrue(interval.isUnboundedStart()); + assertFalse(interval.isEmpty()); + } + + @Test + public void test_sendingAt_InstantMIN_createsUnboundedStartEmpty() { + Interval interval = Interval.endingAt(Instant.MIN); + + assertEquals(Instant.MIN, interval.getEnd()); + assertTrue(interval.isUnboundedStart()); + assertTrue(interval.isEmpty()); + } + + @Test + public void test_endingAt_null() { + assertThrows(NullPointerException.class, () -> Interval.endingAt(null)); + } + /* Lower and upper bound for Intervals */ private static final Instant MIN_OFFSET_DATE_TIME = OffsetDateTime.MIN.plusDays(1L).toInstant(); private static final Instant MAX_OFFSET_DATE_TIME = OffsetDateTime.MAX.minusDays(1L).toInstant(); From e8a765a2232bd03003cc3a4231aa54876b83bfb6 Mon Sep 17 00:00:00 2001 From: Harald Kuhr Date: Tue, 27 Apr 2021 12:54:56 +0200 Subject: [PATCH 211/279] Added tests for Instant.MIN/MAX for completeness. --- src/test/java/org/threeten/extra/TestInterval.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/test/java/org/threeten/extra/TestInterval.java b/src/test/java/org/threeten/extra/TestInterval.java index 5f8e7b1f..0aaa7f3c 100644 --- a/src/test/java/org/threeten/extra/TestInterval.java +++ b/src/test/java/org/threeten/extra/TestInterval.java @@ -189,6 +189,13 @@ public void test_startingAt_InstantMAX_createsUnboundedEndEmpty() { assertTrue(interval.isEmpty()); } + @Test + public void test_startingAt_InstantMIN_isALL() { + Interval interval = Interval.startingAt(Instant.MIN); + + assertEquals(Interval.ALL, interval); + } + @Test public void test_startingAt_null() { assertThrows(NullPointerException.class, () -> Interval.startingAt(null)); @@ -213,6 +220,13 @@ public void test_sendingAt_InstantMIN_createsUnboundedStartEmpty() { assertTrue(interval.isEmpty()); } + @Test + public void test_endingAt_InstantMAX_isALL() { + Interval interval = Interval.endingAt(Instant.MAX); + + assertEquals(Interval.ALL, interval); + } + @Test public void test_endingAt_null() { assertThrows(NullPointerException.class, () -> Interval.endingAt(null)); From bc239b7c65adf8f3f708c8db0f14b55d044f3157 Mon Sep 17 00:00:00 2001 From: Harald Kuhr Date: Tue, 27 Apr 2021 13:21:55 +0200 Subject: [PATCH 212/279] Added tests for unbounded end contains Interval.MIN + document current behavior. --- src/main/java/org/threeten/extra/Interval.java | 2 +- src/test/java/org/threeten/extra/TestInterval.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/threeten/extra/Interval.java b/src/main/java/org/threeten/extra/Interval.java index e7fc5358..1e556560 100644 --- a/src/main/java/org/threeten/extra/Interval.java +++ b/src/main/java/org/threeten/extra/Interval.java @@ -613,7 +613,7 @@ public boolean endsAtOrAfter(Instant instant) { * This checks if the specified instant is within the bounds of this interval. * If this interval has an unbounded start then {@code contains(Instant#MIN)} returns true. * If this interval has an unbounded end then {@code contains(Instant#MAX)} returns true. - * If this interval is empty then this method always returns false. + * Otherwise, if this interval is empty then this method returns false. *

      * This is equivalent to {@link #startsAtOrBefore(Instant)} {@code &&} {@link #endsAfter(Instant)}. * diff --git a/src/test/java/org/threeten/extra/TestInterval.java b/src/test/java/org/threeten/extra/TestInterval.java index 5f3c4d5f..a6d1b1fa 100644 --- a/src/test/java/org/threeten/extra/TestInterval.java +++ b/src/test/java/org/threeten/extra/TestInterval.java @@ -285,6 +285,14 @@ public void test_contains_Instant_baseEmpty() { assertEquals(false, test.contains(NOW1.plusSeconds(1))); } + @Test + public void test_contains_min() { + Interval test = Interval.of(Instant.MIN, NOW2); + assertEquals(true, test.contains(Instant.MIN)); + assertEquals(true, test.contains(NOW1)); + assertEquals(false, test.contains(NOW2)); + } + @Test public void test_contains_max() { Interval test = Interval.of(NOW2, Instant.MAX); From 74784213fd38bad486699e0364280ff30f474b81 Mon Sep 17 00:00:00 2001 From: Harald Kuhr Date: Wed, 28 Apr 2021 08:42:06 +0200 Subject: [PATCH 213/279] Review: Removed blank lines in JavaDoc and final on parameters. --- src/main/java/org/threeten/extra/Interval.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/threeten/extra/Interval.java b/src/main/java/org/threeten/extra/Interval.java index 71eab159..473c6eef 100644 --- a/src/main/java/org/threeten/extra/Interval.java +++ b/src/main/java/org/threeten/extra/Interval.java @@ -133,10 +133,9 @@ public static Interval of(Instant startInclusive, Duration duration) { * Obtains an instance of {@code Interval} with the specified start instant and unbounded end. * * @param startInclusive the start instant, inclusive, not null - * * @return a new {@code Instant} with the specified start instant. */ - public static Interval startingAt(final Instant startInclusive) { + public static Interval startingAt(Instant startInclusive) { Objects.requireNonNull(startInclusive, "startInclusive"); return Interval.ALL.withStart(startInclusive); } @@ -145,10 +144,9 @@ public static Interval startingAt(final Instant startInclusive) { * Obtains an instance of {@code Interval} with unbounded start and the specified end instant. * * @param endExclusive the end instant, exclusive, not null - * * @return a new {@code Instant} with the specified end instant. */ - public static Interval endingAt(final Instant endExclusive) { + public static Interval endingAt(Instant endExclusive) { Objects.requireNonNull(endExclusive, "endExclusive"); return Interval.ALL.withEnd(endExclusive); } From 01f5e014d8e158e32353355b1c09956794c6d8a8 Mon Sep 17 00:00:00 2001 From: Steven Paligo Date: Mon, 3 May 2021 15:32:16 -0600 Subject: [PATCH 214/279] Added isBefore() and isAfter() to TaiInstant and UtcInstant --- .../org/threeten/extra/scale/TaiInstant.java | 26 +++++++++++++++++++ .../org/threeten/extra/scale/UtcInstant.java | 26 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/main/java/org/threeten/extra/scale/TaiInstant.java b/src/main/java/org/threeten/extra/scale/TaiInstant.java index 970abb8e..9b89bb14 100644 --- a/src/main/java/org/threeten/extra/scale/TaiInstant.java +++ b/src/main/java/org/threeten/extra/scale/TaiInstant.java @@ -414,6 +414,32 @@ public int compareTo(TaiInstant otherInstant) { return nanos - otherInstant.nanos; } + /** + * Checks if this instant is after the specified instant. + *

      + * The comparison is based on the time-line position of the instants. + * + * @param otherInstant the other instant to compare to, not null + * @return true if this instant is after the specified instant + * @throws NullPointerException if otherInstant is null + */ + public boolean isAfter(TaiInstant otherInstant) { + return compareTo(otherInstant) > 0; + } + + /** + * Checks if this instant is before the specified instant. + *

      + * The comparison is based on the time-line position of the instants. + * + * @param otherInstant the other instant to compare to, not null + * @return true if this instant is before the specified instant + * @throws NullPointerException if otherInstant is null + */ + public boolean isBefore(TaiInstant otherInstant) { + return compareTo(otherInstant) < 0; + } + //----------------------------------------------------------------------- /** * Checks if this instant is equal to the specified {@code TaiInstant}. diff --git a/src/main/java/org/threeten/extra/scale/UtcInstant.java b/src/main/java/org/threeten/extra/scale/UtcInstant.java index da1a243c..0723cf2a 100644 --- a/src/main/java/org/threeten/extra/scale/UtcInstant.java +++ b/src/main/java/org/threeten/extra/scale/UtcInstant.java @@ -426,6 +426,32 @@ public int compareTo(UtcInstant otherInstant) { return Long.compare(nanoOfDay, otherInstant.nanoOfDay); } + /** + * Checks if this instant is after the specified instant. + *

      + * The comparison is based on the time-line position of the instants. + * + * @param otherInstant the other instant to compare to, not null + * @return true if this instant is after the specified instant + * @throws NullPointerException if otherInstant is null + */ + public boolean isAfter(UtcInstant otherInstant) { + return compareTo(otherInstant) > 0; + } + + /** + * Checks if this instant is before the specified instant. + *

      + * The comparison is based on the time-line position of the instants. + * + * @param otherInstant the other instant to compare to, not null + * @return true if this instant is before the specified instant + * @throws NullPointerException if otherInstant is null + */ + public boolean isBefore(UtcInstant otherInstant) { + return compareTo(otherInstant) < 0; + } + //----------------------------------------------------------------------- /** * Checks if this instant is equal to the specified {@code UtcInstant}. From b7892197898c73ffaf41407a495887c36b724730 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Thu, 6 May 2021 21:55:53 +0100 Subject: [PATCH 215/279] Update after PR --- pom.xml | 4 ++++ src/changes/changes.xml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/pom.xml b/pom.xml index 1cae061f..027f4b3c 100644 --- a/pom.xml +++ b/pom.xml @@ -90,6 +90,10 @@ Martin Kröning https://github.com/mwkroening + + Harald Kuhr + https://github.com/haraldk + Sebastian Lövdahl https://github.com/slovdahl diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 9a09ae7a..d5ee8287 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -12,6 +12,10 @@ Additional comparison methods on Interval. Fixes #174. + + Meaningful factory methods for unbounded intervals. + Fixes #174. + Add Go-compatible duration parsing. Fixes #182. From 28f100b913b407c72fdcb509ff02eb6de4d68bb3 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Thu, 6 May 2021 22:23:59 +0100 Subject: [PATCH 216/279] Upgrade and fix checkstyle; Upgrade Guava Fixes #179 Fixes #152 --- pom.xml | 24 ++++++++++++-- src/main/checkstyle/checkstyle.xml | 31 ++++++++++--------- .../org/threeten/extra/AmountFormats.java | 15 +++++---- .../java/org/threeten/extra/YearWeek.java | 8 +++-- .../org/threeten/extra/scale/UtcInstant.java | 3 +- 5 files changed, 52 insertions(+), 29 deletions(-) diff --git a/pom.xml b/pom.xml index 027f4b3c..8feb252e 100644 --- a/pom.xml +++ b/pom.xml @@ -500,8 +500,26 @@ com.google.guava guava - 26.0-jre + 30.1.1-jre test + + + com.google.code.findbugs + jsr305 + + + org.checkerframework + checker-qual + + + com.google.errorprone + error_prone_annotations + + + com.google.j2objc + j2objc-annotations + + org.junit.jupiter @@ -891,7 +909,7 @@ 4.1.0 2.12.1 - 2.17 + 3.1.2 3.1.0 3.8.0 3.0.0-M1 @@ -927,7 +945,7 @@ true none - 8.18 + 8.41 src/main/checkstyle/checkstyle.xml false diff --git a/src/main/checkstyle/checkstyle.xml b/src/main/checkstyle/checkstyle.xml index 27b4c24a..f7a7b6d5 100644 --- a/src/main/checkstyle/checkstyle.xml +++ b/src/main/checkstyle/checkstyle.xml @@ -30,12 +30,6 @@ - - - - - - @@ -43,11 +37,6 @@ - - - - - @@ -60,6 +49,9 @@ + + + @@ -122,20 +114,29 @@ + + + + + + + - - - - + + + + + + diff --git a/src/main/java/org/threeten/extra/AmountFormats.java b/src/main/java/org/threeten/extra/AmountFormats.java index 208c1abd..facbf480 100644 --- a/src/main/java/org/threeten/extra/AmountFormats.java +++ b/src/main/java/org/threeten/extra/AmountFormats.java @@ -407,7 +407,7 @@ private static ParsedUnitPart consumeDurationLeadingInt(CharSequence text, long integerPart = 0; int i = 0; int valueLength = text.length(); - for (; i < valueLength; i++) { + for ( ; i < valueLength; i++) { char c = text.charAt(i); if (c < '0' || c > '9') { break; @@ -429,8 +429,7 @@ private static ParsedUnitPart consumeDurationLeadingInt(CharSequence text, } // if no text was consumed, return empty. if (i == 0) { - throw new DateTimeParseException( - "Missing leading integer", original, offset); + throw new DateTimeParseException("Missing leading integer", original, offset); } return new ParsedUnitPart(text.subSequence(i, text.length()), new IntegerScalarPart(integerPart)); @@ -444,7 +443,7 @@ private static ParsedUnitPart consumeDurationFraction(CharSequence text, long fraction = 0; long scale = 1; boolean overflow = false; - for (; i < text.length(); i++) { + for ( ; i < text.length(); i++) { char c = text.charAt(i); if (c < '0' || c > '9') { break; @@ -603,7 +602,7 @@ public void formatTo(int value, StringBuilder buf) { // ------------------------------------------------------------------------- // data holder for a duration unit string and its associated Duration value. - static class DurationUnit { + static final class DurationUnit { private final String abbrev; private final Duration value; @@ -639,7 +638,7 @@ static interface DurationScalar { } // data holder for parsed fragments of a floating point duration scalar. - static class ParsedUnitPart implements DurationScalar { + static final class ParsedUnitPart implements DurationScalar { private final CharSequence remainingText; private final DurationScalar scalar; @@ -659,7 +658,7 @@ CharSequence remainingText() { } // data holder for the leading integer value of a duration scalar. - static class IntegerScalarPart implements DurationScalar { + static final class IntegerScalarPart implements DurationScalar { private final long value; private IntegerScalarPart(long value) { @@ -674,7 +673,7 @@ public Duration applyTo(DurationUnit unit) { // data holder for the fractional floating point value of a duration // scalar. - static class FractionScalarPart implements DurationScalar { + static final class FractionScalarPart implements DurationScalar { private final long value; private final long scale; diff --git a/src/main/java/org/threeten/extra/YearWeek.java b/src/main/java/org/threeten/extra/YearWeek.java index 6aaaa55b..456708d6 100644 --- a/src/main/java/org/threeten/extra/YearWeek.java +++ b/src/main/java/org/threeten/extra/YearWeek.java @@ -969,8 +969,12 @@ private long daysUntil(YearWeek end) { private long yearsUntil(YearWeek end) { long yearsDiff = end.year - this.year; - if (yearsDiff > 0 && end.week < this.week) return yearsDiff - 1; - if (yearsDiff < 0 && end.week > this.week) return yearsDiff + 1; + if (yearsDiff > 0 && end.week < this.week) { + return yearsDiff - 1; + } + if (yearsDiff < 0 && end.week > this.week) { + return yearsDiff + 1; + } return yearsDiff; } diff --git a/src/main/java/org/threeten/extra/scale/UtcInstant.java b/src/main/java/org/threeten/extra/scale/UtcInstant.java index da1a243c..f11c79c5 100644 --- a/src/main/java/org/threeten/extra/scale/UtcInstant.java +++ b/src/main/java/org/threeten/extra/scale/UtcInstant.java @@ -474,7 +474,8 @@ public String toString() { // racy single-check idiom String currentStringValue = toString; if (currentStringValue == null) { - toString = currentStringValue = buildToString(); + currentStringValue = buildToString(); + toString = currentStringValue; } return currentStringValue; } From 0d0d025efbd01d52056d5baed869ecf130d67284 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 1 Aug 2021 08:11:31 +0100 Subject: [PATCH 217/279] Update after PR --- src/changes/changes.xml | 4 ++++ .../threeten/extra/scale/TestTaiInstant.java | 17 ++++++++++++----- .../threeten/extra/scale/TestUtcInstant.java | 6 ++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index d5ee8287..f0d96e21 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -8,6 +8,10 @@ + + Additional comparison methods on UtcInstant/TaiInstant. + Fixes #189. + Additional comparison methods on Interval. Fixes #174. diff --git a/src/test/java/org/threeten/extra/scale/TestTaiInstant.java b/src/test/java/org/threeten/extra/scale/TestTaiInstant.java index 289107bb..ae8647da 100644 --- a/src/test/java/org/threeten/extra/scale/TestTaiInstant.java +++ b/src/test/java/org/threeten/extra/scale/TestTaiInstant.java @@ -32,6 +32,7 @@ package org.threeten.extra.scale; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -738,14 +739,20 @@ void doTest_comparisons_TaiInstant(TaiInstant... instants) { for (int j = 0; j < instants.length; j++) { TaiInstant b = instants[j]; if (i < j) { - assertEquals(true, a.compareTo(b) < 0); - assertEquals(false, a.equals(b)); + assertTrue(a.compareTo(b) < 0); + assertFalse(a.equals(b)); + assertTrue(a.isBefore(b)); + assertFalse(a.isAfter(b)); } else if (i > j) { - assertEquals(true, a.compareTo(b) > 0); - assertEquals(false, a.equals(b)); + assertTrue(a.compareTo(b) > 0); + assertFalse(a.equals(b)); + assertFalse(a.isBefore(b)); + assertTrue(a.isAfter(b)); } else { assertEquals(0, a.compareTo(b)); - assertEquals(true, a.equals(b)); + assertTrue(a.equals(b)); + assertFalse(a.isBefore(b)); + assertFalse(a.isAfter(b)); } } } diff --git a/src/test/java/org/threeten/extra/scale/TestUtcInstant.java b/src/test/java/org/threeten/extra/scale/TestUtcInstant.java index 78127f3f..a7d72382 100644 --- a/src/test/java/org/threeten/extra/scale/TestUtcInstant.java +++ b/src/test/java/org/threeten/extra/scale/TestUtcInstant.java @@ -493,12 +493,18 @@ void doTest_comparisons_UtcInstant(UtcInstant... instants) { if (i < j) { assertEquals(-1, a.compareTo(b)); assertEquals(false, a.equals(b)); + assertTrue(a.isBefore(b)); + assertFalse(a.isAfter(b)); } else if (i > j) { assertEquals(1, a.compareTo(b)); assertEquals(false, a.equals(b)); + assertFalse(a.isBefore(b)); + assertTrue(a.isAfter(b)); } else { assertEquals(0, a.compareTo(b)); assertEquals(true, a.equals(b)); + assertFalse(a.isBefore(b)); + assertFalse(a.isAfter(b)); } } } From b852a2f325e3e1d1143c4f0fea67b0cb3ae21351 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 1 Aug 2021 08:36:32 +0100 Subject: [PATCH 218/279] Prepare for release --- README.md | 12 ++++++++++-- src/changes/changes.xml | 2 +- src/site/markdown/index.md | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0be4f4e8..37ee5074 100644 --- a/README.md +++ b/README.md @@ -17,14 +17,22 @@ Various documentation is available: ### Releases -Release 1.6.0 is the current release. +Release 1.7.0 is the current release. This release is considered stable and worthy of the 1.x tag as per [SemVer](https://semver.org/spec/v2.0.0.html). ThreeTen-Extra requires Java SE 8 or later and has no dependencies. Available in the [Maven Central repository](https://search.maven.org/search?q=g:org.threeten%20AND%20a:threeten-extra&core=gav) -![Tidelift dependency check](https://tidelift.com/badges/github/ThreeTen/threeten-extra) +``` + + org.threeten + threeten-extra + 1.7.0 + +``` + +![Tidelift lifted](https://img.shields.io/badge/-lifted!-2dd160.svg?colorA=58595b&style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAAOCAYAAADJ7fe0AAAAAXNSR0IArs4c6QAAAAlwSFlzAAAWJQAAFiUBSVIk8AAAAVlpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6dGlmZj0iaHR0cDovL25zLmFkb2JlLmNvbS90aWZmLzEuMC8iPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgICA8L3JkZjpEZXNjcmlwdGlvbj4KICAgPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4KTMInWQAAAVhJREFUKBV1kj0vBFEUhmd2sdZHh2IlGhKFQuOviEYiNlFodCqtUqPxA%2FwCjUTnDygkGoVERFQaZFlE9nreO%2BdM5u5wkifvuee892Pu3CyEcA0DeIc%2B9IwftJsR6Cko3uCjguZdjuBZhhwmYDjGrOC96WED41UtsgEdGEAPlmAfpuAbFF%2BFZLfoMfRBGzThDtLgePPwBIpdddGzOArhPHUXowbNptE2www6a%2Fm96Y3pHN7oQ1s%2B13pxt1ENaKzBFWyWzaJ%2BRO0C9Jny6VPSoKjLVbMDC5bn5OPuJF%2BBSe95PVEMuugY5AegS9fCh7BedP45hRnj8TC34QQUe9bTZyh2KgvFk2vc8GIlXyTfsvqr6bPpNgv52ynnlomZJNpB70Xhl%2Bf6Sa02p1bApEfnETwxVa%2Faj%2BW%2FFtHltmxS%2FO3krvpTtTnVgu%2F6gvHRFvG78Ef3kOe5PimJXycY74blT5R%2BAAAAAElFTkSuQmCC) ### Support diff --git a/src/changes/changes.xml b/src/changes/changes.xml index f0d96e21..70059403 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,7 +7,7 @@ - + Additional comparison methods on UtcInstant/TaiInstant. Fixes #189. diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index 0d7c4eb8..faf94004 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -52,7 +52,7 @@ Various documentation is available: ## Releases -Release 1.6.0 is the current release. +Release 1.7.0 is the current release. This release is considered stable and worthy of the 1.x tag as per [SemVer](https://semver.org/spec/v2.0.0.html). ThreeTen-Extra requires Java SE 8 or later and has no [dependencies](dependencies.html). @@ -63,7 +63,7 @@ Available in [Maven Central](https://search.maven.org/search?q=g:org.threeten%20 org.threeten threeten-extra - 1.6.0 + 1.7.0 ``` From b2c4d3f32e3202943224cf030e2124ab47978128 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 1 Aug 2021 11:05:49 +0100 Subject: [PATCH 219/279] Fix release plugin --- pom.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pom.xml b/pom.xml index 8feb252e..6b6f21e0 100644 --- a/pom.xml +++ b/pom.xml @@ -390,6 +390,13 @@ v@{project.version} true + + + org.kohsuke + github-api + 1.132 + + From c76c7a1120072bde78966a32c55543cc6db15185 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 1 Aug 2021 11:07:34 +0100 Subject: [PATCH 220/279] [maven-release-plugin] prepare release v1.7.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 6b6f21e0..f55eb565 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.7.0-SNAPSHOT + 1.7.0 Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later https://www.threeten.org/threeten-extra @@ -160,7 +160,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git https://github.com/ThreeTen/threeten-extra - HEAD + v1.7.0 ThreeTen.org From e86f407ce31a407af1e280888bf3e16fb85c13a5 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 1 Aug 2021 11:07:42 +0100 Subject: [PATCH 221/279] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index f55eb565..b10295d8 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.7.0 + 1.7.1-SNAPSHOT Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later https://www.threeten.org/threeten-extra @@ -160,7 +160,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git https://github.com/ThreeTen/threeten-extra - v1.7.0 + HEAD ThreeTen.org From 00b32e25e26a490fa120ef35cbf20783bd250603 Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Fri, 24 Dec 2021 13:14:08 +1100 Subject: [PATCH 222/279] upgrade dependencies for guava, junit and github-api --- pom.xml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index b10295d8..8ac0a160 100644 --- a/pom.xml +++ b/pom.xml @@ -394,7 +394,7 @@ org.kohsuke github-api - 1.132 + 1.301 @@ -500,14 +500,14 @@ org.joda joda-convert - 2.2.0 + 2.2.2 compile true com.google.guava guava - 30.1.1-jre + 31.0.1-jre test @@ -531,19 +531,19 @@ org.junit.jupiter junit-jupiter-api - 5.7.1 + ${junit.version} test org.junit.jupiter junit-jupiter-params - 5.7.1 + ${junit.version} test org.junit.jupiter junit-jupiter-engine - 5.7.1 + ${junit.version} test @@ -911,6 +911,8 @@ + + 5.8.2 3.1.1 4.1.0 From 7a070c07f803d926da41815791f60ad278fb6824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Raupach?= Date: Wed, 29 Dec 2021 10:32:51 +0100 Subject: [PATCH 223/279] Add MyBatis type handlers to the list of related projects (#197) --- src/site/markdown/related.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/site/markdown/related.md b/src/site/markdown/related.md index ba5d3d21..dead271e 100644 --- a/src/site/markdown/related.md +++ b/src/site/markdown/related.md @@ -6,6 +6,7 @@ These projects are independent - no guarantees of quality are given! * [JPA adapters](https://github.com/marschall/threeten-jpa) - Integration with JPA * [JAXB adapters](https://github.com/threeten-jaxb/threeten-jaxb) - Integration with JAXB * [ObjectLab Holiday calculation](http://objectlabkit.sourceforge.net/) - Support for working and non-working days, plus how to calculate and resolve holidays, from a finance industry perspective. +* [MyBatis Type Handlers](https://github.com/mybatis/typehandlers-threeten-extra) - The MyBatis type handlers supporting types of ThreeTen-Extra. If your open source library provides a value added feature on top of JSR-310 or ThreeTen-Extra, then let us know! Just send a pull request to edit this page. From eee5a8b7811e0cf0cd977e0e88a33418fe45a3bb Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Wed, 29 Dec 2021 20:46:21 +1100 Subject: [PATCH 224/279] Fix javadoc for TaiInstant (#195) --- .../org/threeten/extra/scale/TaiInstant.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/threeten/extra/scale/TaiInstant.java b/src/main/java/org/threeten/extra/scale/TaiInstant.java index 9b89bb14..d6b9ed58 100644 --- a/src/main/java/org/threeten/extra/scale/TaiInstant.java +++ b/src/main/java/org/threeten/extra/scale/TaiInstant.java @@ -147,7 +147,7 @@ public static TaiInstant ofTaiSeconds(long taiSeconds, long nanoAdjustment) { * This method uses the latest available system rules. * The conversion first maps from UTC-SLS to UTC, then converts to TAI. *

      - * Conversion from an {@code Instant} will not be completely accurate near + * Conversion from an {@link Instant} will not be completely accurate near * a leap second in accordance with UTC-SLS. * * @param instant the instant to convert, not null @@ -192,7 +192,7 @@ public static TaiInstant of(UtcInstant instant) { * The seconds part must contain only numbers and a possible leading negative sign. * The nanoseconds part must contain exactly nine digits. * The trailing literal must be exactly specified. - * This format parses the {@code toString} format. + * This format parses the {@link toString} format. * * @param text the text to parse such as "12345.123456789s(TAI)", not null * @return the parsed instant, not null @@ -233,7 +233,7 @@ private TaiInstant(long taiSeconds, int nanoOfSecond) { *

      * The TAI second count is a simple incrementing count of seconds where * second 0 is 1958-01-01T00:00:00(TAI). - * The nanosecond part of the day is returned by {@code getNanosOfSecond}. + * The nanosecond part of the second is returned by {@link getNano}. * * @return the seconds from the epoch of 1958-01-01T00:00:00(TAI) */ @@ -247,7 +247,7 @@ public long getTaiSeconds() { *

      * The TAI second count is a simple incrementing count of seconds where * second 0 is 1958-01-01T00:00:00(TAI). - * The nanosecond part of the day is returned by {@code getNanosOfSecond}. + * The nanosecond offset of the second is returned by {@code getNano}. *

      * This instance is immutable and unaffected by this method call. * @@ -263,7 +263,7 @@ public TaiInstant withTaiSeconds(long taiSeconds) { * of the second. *

      * The nanosecond-of-second value measures the total number of nanoseconds from - * the second returned by {@code getTaiSeconds()}. + * the second returned by {@link getTaiSeconds()}. * * @return the nanoseconds within the second, from 0 to 999,999,999 */ @@ -275,7 +275,7 @@ public int getNano() { * Returns a copy of this {@code TaiInstant} with the nano-of-second value changed. *

      * The nanosecond-of-second value measures the total number of nanoseconds from - * the second returned by {@code getTaiSeconds()}. + * the second returned by {@link getTaiSeconds()}. *

      * This instance is immutable and unaffected by this method call. * @@ -368,7 +368,7 @@ public Duration durationUntil(TaiInstant otherInstant) { * This method uses the latest available system rules. * The conversion first maps from TAI to UTC, then converts to UTC-SLS. *

      - * Conversion to an {@code Instant} will not be completely accurate near + * Conversion to an {@link Instant} will not be completely accurate near * a leap second in accordance with UTC-SLS. * * @return an {@code Instant} representing the best approximation of this instant, not null @@ -385,7 +385,7 @@ public Instant toInstant() { * Converting a TAI instant to UTC requires leap second rules. * This method uses the latest available system rules. *

      - * The {@code UtcInstant} will represent exactly the same point on the + * The {@link UtcInstant} will represent exactly the same point on the * time-line as per the available leap-second rules. * If the leap-second rules change then conversion back to TAI may * result in a different instant. From 636e5f9c78034a2ea981dc4a73369f8aaf7f790a Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Sun, 6 Mar 2022 22:43:35 +1100 Subject: [PATCH 225/279] Java 17 compatibility updates (#199) --- pom.xml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 8ac0a160..2da37eb7 100644 --- a/pom.xml +++ b/pom.xml @@ -218,13 +218,6 @@ org.apache.felix maven-bundle-plugin ${maven-bundle-plugin.version} - - - biz.aQute.bnd - biz.aQute.bndlib - ${bndlib.version} - - bundle-manifest @@ -915,7 +908,7 @@ 5.8.2 3.1.1 - 4.1.0 + 5.1.4 2.12.1 3.1.2 @@ -940,8 +933,7 @@ 3.0.0-M3 3.0.0-M3 1.1 - 4.1.0 - 0.8.3 + 0.8.7 1.6.8 3.1.11 From 40b5c9274bc2c57e96c318c18d3009a30d476f0b Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 16 May 2022 08:50:42 +0100 Subject: [PATCH 226/279] Fix Javadoc --- src/main/java/org/threeten/extra/scale/TaiInstant.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/threeten/extra/scale/TaiInstant.java b/src/main/java/org/threeten/extra/scale/TaiInstant.java index d6b9ed58..ec771ecd 100644 --- a/src/main/java/org/threeten/extra/scale/TaiInstant.java +++ b/src/main/java/org/threeten/extra/scale/TaiInstant.java @@ -263,7 +263,7 @@ public TaiInstant withTaiSeconds(long taiSeconds) { * of the second. *

      * The nanosecond-of-second value measures the total number of nanoseconds from - * the second returned by {@link getTaiSeconds()}. + * the second returned by {@link #getTaiSeconds()}. * * @return the nanoseconds within the second, from 0 to 999,999,999 */ @@ -275,7 +275,7 @@ public int getNano() { * Returns a copy of this {@code TaiInstant} with the nano-of-second value changed. *

      * The nanosecond-of-second value measures the total number of nanoseconds from - * the second returned by {@link getTaiSeconds()}. + * the second returned by {@link #getTaiSeconds()}. *

      * This instance is immutable and unaffected by this method call. * From cc8fdf9007b720d737148a1e61584172fbab12fa Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sat, 4 Jun 2022 16:23:54 +0100 Subject: [PATCH 227/279] Ensure YearWeek.isSupported(ChronoUnit) works Fixes #192 --- .../java/org/threeten/extra/YearWeek.java | 10 +++--- .../java/org/threeten/extra/TestYearWeek.java | 35 +++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/threeten/extra/YearWeek.java b/src/main/java/org/threeten/extra/YearWeek.java index 456708d6..148212ae 100644 --- a/src/main/java/org/threeten/extra/YearWeek.java +++ b/src/main/java/org/threeten/extra/YearWeek.java @@ -344,13 +344,12 @@ private YearWeek with(int newYear, int newWeek) { * If false, then calling the {@link #range(TemporalField) range} and * {@link #get(TemporalField) get} methods will throw an exception. *

      - * If the field is a {@link ChronoField} then the query is implemented here. * The supported fields are: *

        *
      • {@code WEEK_OF_WEEK_BASED_YEAR} *
      • {@code WEEK_BASED_YEAR} *
      - * All {@code ChronoField} instances will return false. + * All other {@code ChronoField} instances will return false. *

      * If the field is not a {@code ChronoField}, then the result of this method * is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)} @@ -377,7 +376,6 @@ public boolean isSupported(TemporalField field) { * If false, then calling the {@link #plus(long, TemporalUnit)} and * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. *

      - * If the unit is a {@link ChronoUnit} then the query is implemented here. * The supported units are: *

        *
      • {@code WEEKS} @@ -395,8 +393,10 @@ public boolean isSupported(TemporalField field) { */ @Override public boolean isSupported(TemporalUnit unit) { - if (unit instanceof ChronoUnit) { - return unit == WEEKS || unit == WEEK_BASED_YEARS; + if (unit == WEEKS || unit == WEEK_BASED_YEARS) { + return true; + } else if (unit instanceof ChronoUnit) { + return false; } return unit != null && unit.isSupportedBy(this); } diff --git a/src/test/java/org/threeten/extra/TestYearWeek.java b/src/test/java/org/threeten/extra/TestYearWeek.java index a59cac89..f908c653 100644 --- a/src/test/java/org/threeten/extra/TestYearWeek.java +++ b/src/test/java/org/threeten/extra/TestYearWeek.java @@ -68,9 +68,22 @@ import static java.time.temporal.ChronoField.SECOND_OF_MINUTE; import static java.time.temporal.ChronoField.YEAR; import static java.time.temporal.ChronoField.YEAR_OF_ERA; +import static java.time.temporal.ChronoUnit.CENTURIES; +import static java.time.temporal.ChronoUnit.DAYS; +import static java.time.temporal.ChronoUnit.HOURS; +import static java.time.temporal.ChronoUnit.MICROS; +import static java.time.temporal.ChronoUnit.MILLIS; +import static java.time.temporal.ChronoUnit.MINUTES; +import static java.time.temporal.ChronoUnit.MONTHS; +import static java.time.temporal.ChronoUnit.NANOS; +import static java.time.temporal.ChronoUnit.SECONDS; +import static java.time.temporal.ChronoUnit.WEEKS; +import static java.time.temporal.ChronoUnit.YEARS; import static java.time.temporal.IsoFields.DAY_OF_QUARTER; import static java.time.temporal.IsoFields.QUARTER_OF_YEAR; +import static java.time.temporal.IsoFields.QUARTER_YEARS; import static java.time.temporal.IsoFields.WEEK_BASED_YEAR; +import static java.time.temporal.IsoFields.WEEK_BASED_YEARS; import static java.time.temporal.IsoFields.WEEK_OF_WEEK_BASED_YEAR; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -106,6 +119,7 @@ import java.time.temporal.TemporalAdjusters; import java.time.temporal.TemporalField; import java.time.temporal.TemporalQueries; +import java.time.temporal.TemporalUnit; import java.time.temporal.UnsupportedTemporalTypeException; import java.time.temporal.ValueRange; import java.util.Locale; @@ -475,6 +489,27 @@ public void test_isSupported_TemporalField() { assertEquals(true, TEST.isSupported(WEEK_OF_WEEK_BASED_YEAR)); } + //----------------------------------------------------------------------- + // isSupported(TemporalUnit) + //----------------------------------------------------------------------- + @Test + public void test_isSupported_TemporalUnit() { + assertEquals(false, TEST.isSupported((TemporalUnit) null)); + assertEquals(false, TEST.isSupported(NANOS)); + assertEquals(false, TEST.isSupported(MICROS)); + assertEquals(false, TEST.isSupported(MILLIS)); + assertEquals(false, TEST.isSupported(SECONDS)); + assertEquals(false, TEST.isSupported(MINUTES)); + assertEquals(false, TEST.isSupported(HOURS)); + assertEquals(false, TEST.isSupported(DAYS)); + assertEquals(true, TEST.isSupported(WEEKS)); + assertEquals(false, TEST.isSupported(MONTHS)); + assertEquals(false, TEST.isSupported(YEARS)); + assertEquals(false, TEST.isSupported(CENTURIES)); + assertEquals(true, TEST.isSupported(WEEK_BASED_YEARS)); + assertEquals(false, TEST.isSupported(QUARTER_YEARS)); + } + //----------------------------------------------------------------------- // atDay(DayOfWeek) //----------------------------------------------------------------------- From 1c6781df3441f461b724391e830254e189b2d208 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sat, 4 Jun 2022 17:14:19 +0100 Subject: [PATCH 228/279] Upgrade CodeQL --- .github/workflows/codeql-analysis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index b8ed3af4..b95a95bc 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -39,7 +39,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -50,7 +50,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v1 + uses: github/codeql-action/autobuild@v2 # â„¹ï¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -64,4 +64,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v2 From e8f3c940e030c650efe174b671ca3f6dd2d7e1f2 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sat, 4 Jun 2022 17:32:32 +0100 Subject: [PATCH 229/279] Utilities to work with Durations as numbers (#147) * Avoid throwing exceptions * Use rounding and saturation * Clarify Javadoc and add tests * Remove invalid code --- .../java/org/threeten/extra/Temporals.java | 88 ++++++++++++ .../org/threeten/extra/TestTemporals.java | 129 ++++++++++++++++-- 2 files changed, 202 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/threeten/extra/Temporals.java b/src/main/java/org/threeten/extra/Temporals.java index 0b3f21c2..7edbaadc 100644 --- a/src/main/java/org/threeten/extra/Temporals.java +++ b/src/main/java/org/threeten/extra/Temporals.java @@ -37,8 +37,12 @@ import static java.time.temporal.ChronoUnit.FOREVER; import static java.time.temporal.ChronoUnit.WEEKS; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.math.RoundingMode; import java.text.ParsePosition; import java.time.DateTimeException; +import java.time.Duration; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.time.temporal.ChronoUnit; @@ -386,4 +390,88 @@ private static int monthMonthFactor(TemporalUnit unit, TemporalUnit fromUnit, Te return 3; // quarters } + //------------------------------------------------------------------------- + /** + * Converts a duration to a {@code BigDecimal} with a scale of 9. + * + * @param duration the duration to convert, not null + * @return the {@code BigDecimal} equivalent of the duration, in seconds with a scale of 9 + */ + public static BigDecimal durationToBigDecimalSeconds(Duration duration) { + return BigDecimal.valueOf(duration.getSeconds()).add(BigDecimal.valueOf(duration.getNano(), 9)); + } + + /** + * Converts a {@code BigDecimal} representing seconds to a duration, saturating if necessary. + *

        + * No exception is thrown by this method. + * Numbers are rounded up to the nearest nanosecond (away from zero). + * The duration will saturate at the biggest positive or negative {@code Duration}. + * + * @param seconds the number of seconds to convert, positive or negative + * @return a {@code Duration}, not null + */ + public static Duration durationFromBigDecimalSeconds(BigDecimal seconds) { + BigInteger nanos = seconds.setScale(9, RoundingMode.UP).movePointRight(9).toBigIntegerExact(); + BigInteger[] divRem = nanos.divideAndRemainder(BigInteger.valueOf(1_000_000_000)); + if (divRem[0].bitLength() > 63) { + if (divRem[0].signum() >= 1) { + return Duration.ofSeconds(Long.MAX_VALUE, 999_999_999); + } else { + return Duration.ofSeconds(Long.MIN_VALUE); + } + } + return Duration.ofSeconds(divRem[0].longValue(), divRem[1].intValue()); + } + + /** + * Converts a duration to a {@code double}. + * + * @param duration the duration to convert, not null + * @return the {@code double} equivalent of the duration, in seconds + */ + public static double durationToDoubleSeconds(Duration duration) { + if (duration.getSeconds() < 1_000_000_000) { + return duration.toNanos() / 1_000_000_000d; + } + return durationToBigDecimalSeconds(duration).doubleValue(); + } + + /** + * Converts a {@code double} representing seconds to a duration, saturating if necessary. + *

        + * No exception is thrown by this method. + * Numbers are rounded up to the nearest nanosecond (away from zero). + * The duration will saturate at the biggest positive or negative {@code Duration}. + * + * @param seconds the number of seconds to convert, positive or negative + * @return a {@code Duration}, not null + */ + public static Duration durationFromDoubleSeconds(double seconds) { + return durationFromBigDecimalSeconds(BigDecimal.valueOf(seconds)); + } + + /** + * Multiplies a duration by a {@code double}. + *

        + * The amount is rounded away from zero, thus the result is only zero if zero is passed in. + * See {@link #durationToBigDecimalSeconds(Duration)} and {@link #durationFromBigDecimalSeconds(BigDecimal)}. + * Note that due to the rounding up, 1 nanosecond multiplied by any number smaller than 1 will still be 1 nanosecond. + * + * @param duration the duration to multiply, not null + * @param multiplicand the multiplication factor + * @return the multiplied duration, not null + */ + public static Duration multiply(Duration duration, double multiplicand) { + if (multiplicand == 0d || duration.isZero()) { + return Duration.ZERO; + } + if (multiplicand == 1d) { + return duration; + } + BigDecimal amount = durationToBigDecimalSeconds(duration); + amount = amount.multiply(BigDecimal.valueOf(multiplicand)); + return durationFromBigDecimalSeconds(amount); + } + } diff --git a/src/test/java/org/threeten/extra/TestTemporals.java b/src/test/java/org/threeten/extra/TestTemporals.java index 62e2d99c..858cc652 100644 --- a/src/test/java/org/threeten/extra/TestTemporals.java +++ b/src/test/java/org/threeten/extra/TestTemporals.java @@ -64,7 +64,9 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import java.math.BigDecimal; import java.time.DateTimeException; +import java.time.Duration; import java.time.LocalDate; import java.time.Month; import java.time.format.DateTimeFormatter; @@ -78,9 +80,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test Temporals. @@ -357,7 +357,6 @@ public void test_previousWorkingDayOrSame_yearChange() { //----------------------------------------------------------------------- // parseFirstMatching() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_parseFirstMatching() { return new Object[][] { {"2016-09-06", DateTimeFormatter.ISO_LOCAL_DATE, DateTimeFormatter.BASIC_ISO_DATE}, @@ -366,7 +365,7 @@ public static Object[][] data_parseFirstMatching() { } @ParameterizedTest - @UseDataProvider("data_parseFirstMatching") + @MethodSource("data_parseFirstMatching") public void test_parseFirstMatching(String text, DateTimeFormatter fmt1, DateTimeFormatter fmt2) { assertEquals(LocalDate.of(2016, 9, 6), Temporals.parseFirstMatching(text, LocalDate::from, fmt1, fmt2)); } @@ -389,7 +388,6 @@ public void test_parseFirstMatching_twoNoMatch() { //----------------------------------------------------------------------- // chronoUnit() / timeUnit() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_timeUnitConversion() { return new Object[][] { {ChronoUnit.NANOS, TimeUnit.NANOSECONDS}, @@ -403,7 +401,7 @@ public static Object[][] data_timeUnitConversion() { } @ParameterizedTest - @UseDataProvider("data_timeUnitConversion") + @MethodSource("data_timeUnitConversion") public void test_timeUnit(ChronoUnit chronoUnit, TimeUnit timeUnit) { assertEquals(timeUnit, Temporals.timeUnit(chronoUnit)); } @@ -419,7 +417,7 @@ public void test_timeUnit_null() { } @ParameterizedTest - @UseDataProvider("data_timeUnitConversion") + @MethodSource("data_timeUnitConversion") public void test_chronoUnit(ChronoUnit chronoUnit, TimeUnit timeUnit) { assertEquals(chronoUnit, Temporals.chronoUnit(timeUnit)); } @@ -432,7 +430,6 @@ public void test_chronoUnit_null() { //----------------------------------------------------------------------- // convertAmount() //------------------------------------------------------------------------- - @DataProvider public static Object[][] data_convertAmount() { return new Object[][] { {2L, NANOS, SECONDS, 0L, 2L}, @@ -580,7 +577,7 @@ public static Object[][] data_convertAmount() { } @ParameterizedTest - @UseDataProvider("data_convertAmount") + @MethodSource("data_convertAmount") public void test_convertAmount( long fromAmount, TemporalUnit fromUnit, TemporalUnit resultUnit, long resultWhole, long resultRemainder) { @@ -590,7 +587,7 @@ public void test_convertAmount( } @ParameterizedTest - @UseDataProvider("data_convertAmount") + @MethodSource("data_convertAmount") public void test_convertAmount_negative( long fromAmount, TemporalUnit fromUnit, TemporalUnit resultUnit, long resultWhole, long resultRemainder) { @@ -621,7 +618,6 @@ public void test_convertAmountSameUnit_nonZero() { } } - @DataProvider public static Object[][] data_convertAmountInvalid() { return new Object[][] { {SECONDS, MONTHS}, @@ -641,12 +637,11 @@ public static Object[][] data_convertAmountInvalid() { } @ParameterizedTest - @UseDataProvider("data_convertAmountInvalid") + @MethodSource("data_convertAmountInvalid") public void test_convertAmountInvalid(TemporalUnit fromUnit, TemporalUnit resultUnit) { assertThrows(DateTimeException.class, () -> Temporals.convertAmount(1, fromUnit, resultUnit)); } - @DataProvider public static Object[][] data_convertAmountInvalidUnsupported() { return new Object[][] { {SECONDS, ERAS}, @@ -665,9 +660,113 @@ public static Object[][] data_convertAmountInvalidUnsupported() { } @ParameterizedTest - @UseDataProvider("data_convertAmountInvalidUnsupported") + @MethodSource("data_convertAmountInvalidUnsupported") public void test_convertAmountInvalidUnsupported(TemporalUnit fromUnit, TemporalUnit resultUnit) { assertThrows(UnsupportedTemporalTypeException.class, () -> Temporals.convertAmount(1, fromUnit, resultUnit)); } + //----------------------------------------------------------------------- + // duration to/from BigDecimal/double + //------------------------------------------------------------------------- + public static Object[][] data_durationConversions() { + return new Object[][] { + {Duration.ZERO, BigDecimal.valueOf(0, 9), 0d}, + {Duration.ofSeconds(1, 0), new BigDecimal("1.000000000"), 1d}, + {Duration.ofSeconds(1, 500_000_000), new BigDecimal("1.500000000"), 1.5d}, + {Duration.ofSeconds(0, -400_000_000), new BigDecimal("-0.400000000"), -0.4d}, + }; + } + + @ParameterizedTest + @MethodSource("data_durationConversions") + public void test_durationToBigDecimalSeconds(Duration input, BigDecimal expected, double ignored) { + BigDecimal test = Temporals.durationToBigDecimalSeconds(input); + assertEquals(expected, test); + assertEquals(9, test.scale()); + } + + @ParameterizedTest + @MethodSource("data_durationConversions") + public void test_durationFromBigDecimalSeconds(Duration expected, BigDecimal input, double ignored) { + Duration test = Temporals.durationFromBigDecimalSeconds(input); + assertEquals(expected, test); + } + + @ParameterizedTest + @MethodSource("data_durationConversions") + public void test_durationToDoubleSeconds(Duration input, BigDecimal ignored, double expected) { + double test = Temporals.durationToDoubleSeconds(input); + assertEquals(expected, test, 0d); + } + + @ParameterizedTest + @MethodSource("data_durationConversions") + public void test_durationFromDoubleSeconds(Duration expected, BigDecimal ignored, double input) { + Duration test = Temporals.durationFromDoubleSeconds(input); + assertEquals(expected, test); + } + + @Test + public void test_durationFromBigDecimalSeconds_manyDecimals() { + Duration test = Temporals.durationFromBigDecimalSeconds(BigDecimal.valueOf(122233322251L, 11)); + assertEquals(Duration.ofSeconds(1, 222333223), test); + } + + @Test + public void test_durationFromDoubleSeconds_manyDecimals() { + Duration test = Temporals.durationFromDoubleSeconds(1.22233322251d); + assertEquals(Duration.ofSeconds(1, 222333223), test); + } + + @Test + public void test_durationFromBigDecimalSeconds_tooLargePositive() { + Duration test = Temporals.durationFromBigDecimalSeconds(BigDecimal.valueOf(122233322251L, -10)); + assertEquals(Duration.ofSeconds(Long.MAX_VALUE, 999_999_999), test); + } + + @Test + public void test_durationFromBigDecimalSeconds_tooLargeNegative() { + Duration test = Temporals.durationFromBigDecimalSeconds(BigDecimal.valueOf(-122233322251L, -10)); + assertEquals(Duration.ofSeconds(Long.MIN_VALUE), test); + } + + @Test + public void test_durationFromDoubleSeconds_tooLargePositive() { + Duration test = Temporals.durationFromDoubleSeconds(122233322251e10); + assertEquals(Duration.ofSeconds(Long.MAX_VALUE, 999_999_999), test); + } + + @Test + public void test_durationFromDoubleSeconds_tooLargeNegative() { + Duration test = Temporals.durationFromDoubleSeconds(-122233322251e10); + assertEquals(Duration.ofSeconds(Long.MIN_VALUE), test); + } + + //----------------------------------------------------------------------- + // duration multiply + //------------------------------------------------------------------------- + public static Object[][] data_durationMultiply() { + return new Object[][] { + {Duration.ZERO, 0d, Duration.ZERO}, + {Duration.ZERO, 1d, Duration.ZERO}, + {Duration.ZERO, 2d, Duration.ZERO}, + {Duration.ofSeconds(1, 0), 0d, Duration.ZERO}, + {Duration.ofSeconds(1, 0), -0d, Duration.ZERO}, + {Duration.ofSeconds(1, 0), 1d, Duration.ofSeconds(1, 0)}, + {Duration.ofSeconds(1, 0), 2d, Duration.ofSeconds(2, 0)}, + {Duration.ofSeconds(1, 500_000_000), 2d, Duration.ofSeconds(3, 0)}, + {Duration.ofSeconds(1, 0), 1e-12, Duration.ofNanos(1)}, + {Duration.ofNanos(1), 1e-12, Duration.ofNanos(1)}, + {Duration.ofSeconds(Long.MAX_VALUE - 1, 0), 1.1d, Duration.ofSeconds(Long.MAX_VALUE, 999_999_999)}, + {Duration.ofSeconds(Long.MAX_VALUE - 1, 0), -1.1d, Duration.ofSeconds(Long.MIN_VALUE, 0)}, + }; + } + + @ParameterizedTest + @MethodSource("data_durationMultiply") + public void test_durationMultiply(Duration input, double multiplicand, Duration expected) { + Duration test = Temporals.multiply(input, multiplicand); + assertEquals(expected, test); + } + } From a32fd5d66233d7c27c71f75d4071a0a980917673 Mon Sep 17 00:00:00 2001 From: "Stephen A. Imhoff" Date: Wed, 8 Jun 2022 14:18:07 -0700 Subject: [PATCH 230/279] Switch to junit-native MethodSource for data. (#203) --- pom.xml | 31 +++----- .../org/threeten/extra/TestAmountFormats.java | 28 +++---- .../java/org/threeten/extra/TestConvert.java | 9 +-- .../java/org/threeten/extra/TestDays.java | 14 ++-- .../java/org/threeten/extra/TestHours.java | 14 ++-- .../java/org/threeten/extra/TestInterval.java | 34 ++++---- .../threeten/extra/TestLocalDateRange.java | 70 ++++++++-------- .../java/org/threeten/extra/TestMinutes.java | 14 ++-- .../java/org/threeten/extra/TestMonths.java | 14 ++-- .../org/threeten/extra/TestOffsetDate.java | 42 ++++------ .../threeten/extra/TestPeriodDuration.java | 14 ++-- .../java/org/threeten/extra/TestQuarter.java | 10 +-- .../java/org/threeten/extra/TestSeconds.java | 14 ++-- .../org/threeten/extra/TestTemporals.java | 2 +- .../java/org/threeten/extra/TestWeeks.java | 7 +- .../java/org/threeten/extra/TestYearWeek.java | 25 +++--- .../java/org/threeten/extra/TestYears.java | 7 +- .../chrono/TestAccountingChronology.java | 53 +++++-------- .../TestAccountingChronologyBuilder.java | 46 +++++------ .../chrono/TestBritishCutoverChronology.java | 75 +++++++----------- .../extra/chrono/TestCopticChronology.java | 53 +++++-------- .../chrono/TestDiscordianChronology.java | 65 ++++++--------- .../extra/chrono/TestEthiopicChronology.java | 56 ++++++------- .../TestInternationalFixedChronology.java | 79 +++++++------------ .../extra/chrono/TestJulianChronology.java | 53 +++++-------- .../extra/chrono/TestPaxChronology.java | 62 ++++++--------- .../chrono/TestSymmetry010Chronology.java | 78 +++++++----------- .../chrono/TestSymmetry454Chronology.java | 78 +++++++----------- .../threeten/extra/scale/TestTaiInstant.java | 19 ++--- .../threeten/extra/scale/TestUtcInstant.java | 24 ++---- .../threeten/extra/scale/TestUtcRules.java | 7 +- 31 files changed, 423 insertions(+), 674 deletions(-) diff --git a/pom.xml b/pom.xml index 2da37eb7..e3334968 100644 --- a/pom.xml +++ b/pom.xml @@ -489,6 +489,17 @@ + + + + org.junit + junit-bom + 5.8.2 + pom + import + + + org.joda @@ -523,28 +534,10 @@ org.junit.jupiter - junit-jupiter-api + junit-jupiter ${junit.version} test - - org.junit.jupiter - junit-jupiter-params - ${junit.version} - test - - - org.junit.jupiter - junit-jupiter-engine - ${junit.version} - test - - - com.tngtech.junit.dataprovider - junit-jupiter-params-dataprovider - 2.8 - test - diff --git a/src/test/java/org/threeten/extra/TestAmountFormats.java b/src/test/java/org/threeten/extra/TestAmountFormats.java index 423c0c8f..a91e1e26 100644 --- a/src/test/java/org/threeten/extra/TestAmountFormats.java +++ b/src/test/java/org/threeten/extra/TestAmountFormats.java @@ -41,9 +41,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test AmountFormats. @@ -62,7 +60,6 @@ public void test_iso8601() { } //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_wordBased() { return new Object[][] { {Period.ofYears(0), Locale.ROOT, "0 days"}, @@ -100,12 +97,11 @@ public static Object[][] data_wordBased() { } @ParameterizedTest - @UseDataProvider("data_wordBased") + @MethodSource("data_wordBased") public void test_wordBased(Period period, Locale locale, String expected) { assertEquals(expected, AmountFormats.wordBased(period, locale)); } - @DataProvider public static Object[][] duration_wordBased() { return new Object[][] { {Duration.ofMinutes(180 + 2), Locale.ENGLISH, "3 hours and 2 minutes"}, @@ -136,12 +132,11 @@ public static Object[][] duration_wordBased() { } @ParameterizedTest - @UseDataProvider("duration_wordBased") + @MethodSource("duration_wordBased") public void test_wordBased(Duration duration, Locale locale, String expected) { assertEquals(expected, AmountFormats.wordBased(duration, locale)); } - @DataProvider public static Object[][] period_duration_wordBased() { return new Object[][] { {Period.ofDays(1), Duration.ofMinutes(180 + 2), Locale.ROOT, "1 day, 3 hours and 2 minutes"}, @@ -163,7 +158,7 @@ public static Object[][] period_duration_wordBased() { } @ParameterizedTest - @UseDataProvider("period_duration_wordBased") + @MethodSource("period_duration_wordBased") public void test_wordBased(Period period, Duration duration, Locale locale, String expected) { assertEquals(expected, AmountFormats.wordBased(period, duration, locale)); } @@ -296,12 +291,11 @@ public void test_wordBased_ru_formatStandard() { // ----------------------------------------------------------------------- @ParameterizedTest - @UseDataProvider("wordBased_ru_formatSeparator") + @MethodSource("wordBased_ru_formatSeparator") public void test_wordBased_ru_formatSeparator(String expected, Duration duration) { assertEquals(expected, AmountFormats.wordBased(duration, RU)); } - @DataProvider public static Object[][] wordBased_ru_formatSeparator() { return new Object[][]{ {"18 \u0447\u0430\u0441\u043E\u0432 \u0438 32 \u043C\u0438\u043D\u0443\u0442\u044B", Duration.ofMinutes(1112)}, @@ -311,12 +305,11 @@ public static Object[][] wordBased_ru_formatSeparator() { // ----------------------------------------------------------------------- @ParameterizedTest - @UseDataProvider("wordBased_ru_period_predicate") + @MethodSource("wordBased_ru_period_predicate") public void test_wordBased_ru_period_predicate(String expected, Period period) { assertEquals(expected, AmountFormats.wordBased(period, RU)); } - @DataProvider public static Object[][] wordBased_ru_period_predicate() { return new Object[][]{ @@ -439,12 +432,11 @@ public static Object[][] wordBased_ru_period_predicate() { // ----------------------------------------------------------------------- @ParameterizedTest - @UseDataProvider("wordBased_ru_duration_predicate") + @MethodSource("wordBased_ru_duration_predicate") public void test_wordBased_ru_duration_predicate(String expected, Duration duration) { assertEquals(expected, AmountFormats.wordBased(duration, RU)); } - @DataProvider public static Object[][] wordBased_ru_duration_predicate() { return new Object[][]{ @@ -544,12 +536,11 @@ public static Object[][] wordBased_ru_duration_predicate() { // ----------------------------------------------------------------------- @ParameterizedTest - @UseDataProvider("duration_unitBased") + @MethodSource("duration_unitBased") public void test_parseUnitBasedDuration(Duration expected, String input) { assertEquals(expected, AmountFormats.parseUnitBasedDuration(input)); } - @DataProvider public static Object[][] duration_unitBased() { return new Object[][] { {Duration.ZERO, "0"}, @@ -574,7 +565,7 @@ public static Object[][] duration_unitBased() { } @ParameterizedTest - @UseDataProvider("duration_unitBasedErrors") + @MethodSource("duration_unitBasedErrors") public void test_parseUnitBasedDurationErrors(Exception e, String input) { Exception thrown = assertThrows(e.getClass(), () -> AmountFormats.parseUnitBasedDuration(input)); @@ -587,7 +578,6 @@ public void test_parseUnitBasedDurationErrors(Exception e, String input) { } } - @DataProvider public static Object[][] duration_unitBasedErrors() { return new Object[][] { {new NullPointerException("durationText must not be null"), null}, diff --git a/src/test/java/org/threeten/extra/TestConvert.java b/src/test/java/org/threeten/extra/TestConvert.java index b646fec5..5ff8ef8d 100644 --- a/src/test/java/org/threeten/extra/TestConvert.java +++ b/src/test/java/org/threeten/extra/TestConvert.java @@ -40,15 +40,12 @@ import org.joda.convert.StringConvert; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.threeten.extra.scale.TaiInstant; import org.threeten.extra.scale.UtcInstant; -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; - public class TestConvert { - @DataProvider public static Object[][] data_inputs() { return new Object[][] { {Seconds.of(23), "PT23S"}, @@ -69,13 +66,13 @@ public static Object[][] data_inputs() { } @ParameterizedTest - @UseDataProvider("data_inputs") + @MethodSource("data_inputs") public void test_convertToString(Object obj, String str) { assertEquals(str, StringConvert.INSTANCE.convertToString(obj)); } @ParameterizedTest - @UseDataProvider("data_inputs") + @MethodSource("data_inputs") public void test_convertFromString(Object obj, String str) { assertEquals(obj, StringConvert.INSTANCE.convertFromString(obj.getClass(), str)); } diff --git a/src/test/java/org/threeten/extra/TestDays.java b/src/test/java/org/threeten/extra/TestDays.java index e591dbac..1c0a8d27 100644 --- a/src/test/java/org/threeten/extra/TestDays.java +++ b/src/test/java/org/threeten/extra/TestDays.java @@ -54,9 +54,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test class. @@ -182,7 +180,6 @@ public void test_from_null() { } //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_valid() { return new Object[][] { {"P0D", 0}, @@ -214,24 +211,23 @@ public static Object[][] data_valid() { } @ParameterizedTest - @UseDataProvider("data_valid") + @MethodSource("data_valid") public void test_parse_CharSequence_valid(String str, int expectedDays) { assertEquals(Days.of(expectedDays), Days.parse(str)); } @ParameterizedTest - @UseDataProvider("data_valid") + @MethodSource("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, int expectedDays) { assertEquals(Days.of(expectedDays), Days.parse("+" + str)); } @ParameterizedTest - @UseDataProvider("data_valid") + @MethodSource("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, int expectedDays) { assertEquals(Days.of(-expectedDays), Days.parse("-" + str)); } - @DataProvider public static Object[][] data_invalid() { return new Object[][] { {"P3Y"}, @@ -252,7 +248,7 @@ public static Object[][] data_invalid() { } @ParameterizedTest - @UseDataProvider("data_invalid") + @MethodSource("data_invalid") public void test_parse_CharSequence_invalid(String str) { assertThrows(DateTimeParseException.class, () -> Days.parse(str)); } diff --git a/src/test/java/org/threeten/extra/TestHours.java b/src/test/java/org/threeten/extra/TestHours.java index 33252e8b..8c0af9c2 100644 --- a/src/test/java/org/threeten/extra/TestHours.java +++ b/src/test/java/org/threeten/extra/TestHours.java @@ -48,9 +48,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test class. @@ -116,7 +114,6 @@ public void test_ofPlusOne() { } //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_valid() { return new Object[][] { {"PT0H", 0}, @@ -143,24 +140,23 @@ public static Object[][] data_valid() { } @ParameterizedTest - @UseDataProvider("data_valid") + @MethodSource("data_valid") public void test_parse_CharSequence_valid(String str, int expectedDays) { assertEquals(Hours.of(expectedDays), Hours.parse(str)); } @ParameterizedTest - @UseDataProvider("data_valid") + @MethodSource("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, int expectedDays) { assertEquals(Hours.of(expectedDays), Hours.parse("+" + str)); } @ParameterizedTest - @UseDataProvider("data_valid") + @MethodSource("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, int expectedDays) { assertEquals(Hours.of(-expectedDays), Hours.parse("-" + str)); } - @DataProvider public static Object[][] data_invalid() { return new Object[][] { {"P3W"}, @@ -181,7 +177,7 @@ public static Object[][] data_invalid() { } @ParameterizedTest - @UseDataProvider("data_invalid") + @MethodSource("data_invalid") public void test_parse_CharSequence_invalid(String str) { assertThrows(DateTimeParseException.class, () -> Hours.parse(str)); } diff --git a/src/test/java/org/threeten/extra/TestInterval.java b/src/test/java/org/threeten/extra/TestInterval.java index dcfae05f..d7b698cd 100644 --- a/src/test/java/org/threeten/extra/TestInterval.java +++ b/src/test/java/org/threeten/extra/TestInterval.java @@ -55,9 +55,6 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; - /** * Test class. */ @@ -237,7 +234,6 @@ public void test_endingAt_null() { private static final Instant MAX_OFFSET_DATE_TIME = OffsetDateTime.MAX.minusDays(1L).toInstant(); //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_parseValid() { Instant minPlusOneDay = Instant.MIN.plus(Duration.ofDays(1)); Instant maxMinusOneDay = Instant.MAX.minus(Duration.ofDays(1)); @@ -264,7 +260,7 @@ public static Object[][] data_parseValid() { } @ParameterizedTest - @UseDataProvider("data_parseValid") + @MethodSource("data_parseValid") public void test_parse_CharSequence(String input, Instant start, Instant end) { Interval test = Interval.parse(input); assertEquals(start, test.getStart()); @@ -537,7 +533,6 @@ public void test_overlaps_Interval_null() { } //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_intersection() { return new Object[][] { // adjacent @@ -554,7 +549,7 @@ public static Object[][] data_intersection() { } @ParameterizedTest - @UseDataProvider("data_intersection") + @MethodSource("data_intersection") public void test_intersection( Instant start1, Instant end1, Instant start2, Instant end2, Instant expStart, Instant expEnd) { @@ -566,7 +561,7 @@ public void test_intersection( } @ParameterizedTest - @UseDataProvider("data_intersection") + @MethodSource("data_intersection") public void test_intersection_reverse( Instant start1, Instant end1, Instant start2, Instant end2, Instant expStart, Instant expEnd) { @@ -592,7 +587,6 @@ public void test_intersection_same() { } //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_union() { return new Object[][] { // adjacent @@ -609,7 +603,7 @@ public static Object[][] data_union() { } @ParameterizedTest - @UseDataProvider("data_union") + @MethodSource("data_union") public void test_unionAndSpan( Instant start1, Instant end1, Instant start2, Instant end2, Instant expStart, Instant expEnd) { @@ -622,7 +616,7 @@ public void test_unionAndSpan( } @ParameterizedTest - @UseDataProvider("data_union") + @MethodSource("data_union") public void test_unionAndSpan_reverse( Instant start1, Instant end1, Instant start2, Instant end2, Instant expStart, Instant expEnd) { @@ -635,7 +629,7 @@ public void test_unionAndSpan_reverse( } @ParameterizedTest - @UseDataProvider("data_union") + @MethodSource("data_union") public void test_span_enclosesInputs( Instant start1, Instant end1, Instant start2, Instant end2, Instant expStart, Instant expEnd) { @@ -696,17 +690,17 @@ public static Object[][] data_starts() { {Interval.of(NOW12, Instant.MAX), Instant.MAX, true, true, false, false}, }; } - + @ParameterizedTest @MethodSource("data_starts") public void test_starts_Instant( - Interval test, - Instant instant, + Interval test, + Instant instant, boolean expectedStartsBefore, boolean expectedStartsAtOrBefore, boolean expectedStartsAfter, boolean expectedStartsAtOrAfter) { - + assertEquals(expectedStartsBefore, test.startsBefore(instant)); assertEquals(expectedStartsAtOrBefore, test.startsAtOrBefore(instant)); assertEquals(expectedStartsAfter, test.startsAfter(instant)); @@ -749,17 +743,17 @@ public static Object[][] data_ends() { {Interval.of(NOW12, Instant.MAX), Instant.MAX, false, false, true, true}, }; } - + @ParameterizedTest @MethodSource("data_ends") public void test_ends_Instant( - Interval test, - Instant instant, + Interval test, + Instant instant, boolean expectedEndsBefore, boolean expectedEndsAtOrBefore, boolean expectedEndsAfter, boolean expectedEndsAtOrAfter) { - + assertEquals(expectedEndsBefore, test.endsBefore(instant)); assertEquals(expectedEndsAtOrBefore, test.endsAtOrBefore(instant)); assertEquals(expectedEndsAfter, test.endsAfter(instant)); diff --git a/src/test/java/org/threeten/extra/TestLocalDateRange.java b/src/test/java/org/threeten/extra/TestLocalDateRange.java index ff9afa83..9f81fc1e 100644 --- a/src/test/java/org/threeten/extra/TestLocalDateRange.java +++ b/src/test/java/org/threeten/extra/TestLocalDateRange.java @@ -47,16 +47,16 @@ import java.time.format.DateTimeParseException; import java.time.temporal.ChronoUnit; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import static org.junit.jupiter.params.provider.Arguments.arguments; +import org.junit.jupiter.params.provider.MethodSource; import com.google.common.collect.Range; -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; /** * Test date range. @@ -702,7 +702,6 @@ public void test_contains_max() { } //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_queries() { return new Object[][] { // before start @@ -752,7 +751,7 @@ public static Object[][] data_queries() { } @ParameterizedTest - @UseDataProvider("data_queries") + @MethodSource("data_queries") public void test_encloses( LocalDate start, LocalDate end, boolean isEnclosedBy, boolean abuts, boolean isConnected, boolean overlaps) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); @@ -760,7 +759,7 @@ public void test_encloses( } @ParameterizedTest - @UseDataProvider("data_queries") + @MethodSource("data_queries") public void test_abuts( LocalDate start, LocalDate end, boolean isEnclosedBy, boolean abuts, boolean isConnected, boolean overlaps) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); @@ -768,7 +767,7 @@ public void test_abuts( } @ParameterizedTest - @UseDataProvider("data_queries") + @MethodSource("data_queries") public void test_isConnected( LocalDate start, LocalDate end, boolean isEnclosedBy, boolean abuts, boolean isConnected, boolean overlaps) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); @@ -776,7 +775,7 @@ public void test_isConnected( } @ParameterizedTest - @UseDataProvider("data_queries") + @MethodSource("data_queries") public void test_overlaps( LocalDate start, LocalDate end, boolean isEnclosedBy, boolean abuts, boolean isConnected, boolean overlaps) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); @@ -784,7 +783,7 @@ public void test_overlaps( } @ParameterizedTest - @UseDataProvider("data_queries") + @MethodSource("data_queries") public void test_crossCheck( LocalDate start, LocalDate end, boolean isEnclosedBy, boolean abuts, boolean isConnected, boolean overlaps) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); @@ -844,7 +843,6 @@ public void test_overlaps_baseEmpty() { } //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_intersection() { return new Object[][] { // adjacent @@ -861,7 +859,7 @@ public static Object[][] data_intersection() { } @ParameterizedTest - @UseDataProvider("data_intersection") + @MethodSource("data_intersection") public void test_intersection( LocalDate start1, LocalDate end1, LocalDate start2, LocalDate end2, LocalDate expStart, LocalDate expEnd) { @@ -873,7 +871,7 @@ public void test_intersection( } @ParameterizedTest - @UseDataProvider("data_intersection") + @MethodSource("data_intersection") public void test_intersection_reverse( LocalDate start1, LocalDate end1, LocalDate start2, LocalDate end2, LocalDate expStart, LocalDate expEnd) { @@ -899,7 +897,6 @@ public void test_intersection_same() { } //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_union() { return new Object[][] { // adjacent @@ -916,7 +913,7 @@ public static Object[][] data_union() { } @ParameterizedTest - @UseDataProvider("data_union") + @MethodSource("data_union") public void test_unionAndSpan( LocalDate start1, LocalDate end1, LocalDate start2, LocalDate end2, LocalDate expStart, LocalDate expEnd) { @@ -929,7 +926,7 @@ public void test_unionAndSpan( } @ParameterizedTest - @UseDataProvider("data_union") + @MethodSource("data_union") public void test_unionAndSpan_reverse( LocalDate start1, LocalDate end1, LocalDate start2, LocalDate end2, LocalDate expStart, LocalDate expEnd) { @@ -942,7 +939,7 @@ public void test_unionAndSpan_reverse( } @ParameterizedTest - @UseDataProvider("data_union") + @MethodSource("data_union") public void test_span_enclosesInputs( LocalDate start1, LocalDate end1, LocalDate start2, LocalDate end2, LocalDate expStart, LocalDate expEnd) { @@ -1008,7 +1005,6 @@ public void test_stream_MAXM2_MAX() { } //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_isBefore() { return new Object[][] { // before start @@ -1052,14 +1048,14 @@ public static Object[][] data_isBefore() { } @ParameterizedTest - @UseDataProvider("data_isBefore") + @MethodSource("data_isBefore") public void test_isBefore_range(LocalDate start, LocalDate end, boolean before) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); assertEquals(before, test.isBefore(LocalDateRange.of(start, end))); } @ParameterizedTest - @UseDataProvider("data_isBefore") + @MethodSource("data_isBefore") public void test_isBefore_date(LocalDate start, LocalDate end, boolean before) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); assertEquals(before, test.isBefore(start)); @@ -1085,7 +1081,6 @@ public void test_isBefore_date_empty() { } //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_isAfter() { return new Object[][] { // before start @@ -1132,14 +1127,14 @@ public static Object[][] data_isAfter() { } @ParameterizedTest - @UseDataProvider("data_isAfter") + @MethodSource("data_isAfter") public void test_isAfter_range(LocalDate start, LocalDate end, boolean before) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); assertEquals(before, test.isAfter(LocalDateRange.of(start, end))); } @ParameterizedTest - @UseDataProvider("data_isAfter") + @MethodSource("data_isAfter") public void test_isAfter_date(LocalDate start, LocalDate end, boolean before) { LocalDateRange test = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_31); assertEquals(before, test.isAfter(end.minusDays(1))); @@ -1210,9 +1205,8 @@ public void test_equals() { } //----------------------------------------------------------------------- - @DataProvider - public static List> data_crossCheckGuava() { - List> list = new ArrayList<>(); + public static List data_crossCheckGuava() { + List list = new ArrayList<>(); for (int i1 = 1; i1 < 5; i1++) { for (int j1 = i1; j1 < 5; j1++) { LocalDate date11 = LocalDate.of(2016, 1, i1); @@ -1225,7 +1219,7 @@ public static List> data_crossCheckGuava() { LocalDate date22 = LocalDate.of(2016, 1, j2); LocalDateRange extraRange2 = LocalDateRange.of(date21, date22); Range guavaRange2 = Range.closedOpen(date21, date22); - list.add(Arrays.asList(extraRange1, extraRange2, guavaRange1, guavaRange2)); + list.add(arguments(extraRange1, extraRange2, guavaRange1, guavaRange2)); } } } @@ -1234,11 +1228,11 @@ public static List> data_crossCheckGuava() { } @ParameterizedTest - @UseDataProvider("data_crossCheckGuava") + @MethodSource("data_crossCheckGuava") public void crossCheckGuava_encloses( LocalDateRange extraRange1, - LocalDateRange extraRange2, - Range guavaRange1, + LocalDateRange extraRange2, + Range guavaRange1, Range guavaRange2) { boolean extra = extraRange1.encloses(extraRange2); @@ -1247,11 +1241,11 @@ public void crossCheckGuava_encloses( } @ParameterizedTest - @UseDataProvider("data_crossCheckGuava") + @MethodSource("data_crossCheckGuava") public void crossCheckGuava_isConnected( LocalDateRange extraRange1, - LocalDateRange extraRange2, - Range guavaRange1, + LocalDateRange extraRange2, + Range guavaRange1, Range guavaRange2) { boolean extra = extraRange1.isConnected(extraRange2); @@ -1260,11 +1254,11 @@ public void crossCheckGuava_isConnected( } @ParameterizedTest - @UseDataProvider("data_crossCheckGuava") + @MethodSource("data_crossCheckGuava") public void crossCheckGuava_intersection( LocalDateRange extraRange1, - LocalDateRange extraRange2, - Range guavaRange1, + LocalDateRange extraRange2, + Range guavaRange1, Range guavaRange2) { LocalDateRange extra = null; @@ -1288,11 +1282,11 @@ public void crossCheckGuava_intersection( } @ParameterizedTest - @UseDataProvider("data_crossCheckGuava") + @MethodSource("data_crossCheckGuava") public void crossCheckGuava_span( LocalDateRange extraRange1, - LocalDateRange extraRange2, - Range guavaRange1, + LocalDateRange extraRange2, + Range guavaRange1, Range guavaRange2) { LocalDateRange extra = extraRange1.span(extraRange2); diff --git a/src/test/java/org/threeten/extra/TestMinutes.java b/src/test/java/org/threeten/extra/TestMinutes.java index 79468f8f..d8e92e8a 100644 --- a/src/test/java/org/threeten/extra/TestMinutes.java +++ b/src/test/java/org/threeten/extra/TestMinutes.java @@ -48,9 +48,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test class. @@ -133,7 +131,6 @@ public void test_ofHours_overflow() { } //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_valid() { return new Object[][] { {"PT0M", 0}, @@ -177,24 +174,23 @@ public static Object[][] data_valid() { } @ParameterizedTest - @UseDataProvider("data_valid") + @MethodSource("data_valid") public void test_parse_CharSequence_valid(String str, int expectedMinutes) { assertEquals(Minutes.of(expectedMinutes), Minutes.parse(str)); } @ParameterizedTest - @UseDataProvider("data_valid") + @MethodSource("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, int expectedMinutes) { assertEquals(Minutes.of(expectedMinutes), Minutes.parse("+" + str)); } @ParameterizedTest - @UseDataProvider("data_valid") + @MethodSource("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, int expectedMinutes) { assertEquals(Minutes.of(-expectedMinutes), Minutes.parse("-" + str)); } - @DataProvider public static Object[][] data_invalid() { return new Object[][] { {"P3W"}, @@ -217,7 +213,7 @@ public static Object[][] data_invalid() { } @ParameterizedTest - @UseDataProvider("data_invalid") + @MethodSource("data_invalid") public void test_parse_CharSequence_invalid(String str) { assertThrows(DateTimeParseException.class, () -> Minutes.parse(str)); } diff --git a/src/test/java/org/threeten/extra/TestMonths.java b/src/test/java/org/threeten/extra/TestMonths.java index 30083d0d..2e91fa41 100644 --- a/src/test/java/org/threeten/extra/TestMonths.java +++ b/src/test/java/org/threeten/extra/TestMonths.java @@ -54,9 +54,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test class. @@ -177,7 +175,6 @@ public void test_from_null() { } //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_valid() { return new Object[][] { {"P0M", 0}, @@ -209,24 +206,23 @@ public static Object[][] data_valid() { } @ParameterizedTest - @UseDataProvider("data_valid") + @MethodSource("data_valid") public void test_parse_CharSequence_valid(String str, int expectedDays) { assertEquals(Months.of(expectedDays), Months.parse(str)); } @ParameterizedTest - @UseDataProvider("data_valid") + @MethodSource("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, int expectedDays) { assertEquals(Months.of(expectedDays), Months.parse("+" + str)); } @ParameterizedTest - @UseDataProvider("data_valid") + @MethodSource("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, int expectedDays) { assertEquals(Months.of(-expectedDays), Months.parse("-" + str)); } - @DataProvider public static Object[][] data_invalid() { return new Object[][] { {"P3W"}, @@ -245,7 +241,7 @@ public static Object[][] data_invalid() { } @ParameterizedTest - @UseDataProvider("data_invalid") + @MethodSource("data_invalid") public void test_parse_CharSequence_invalid(String str) { assertThrows(DateTimeParseException.class, () -> Months.parse(str)); } diff --git a/src/test/java/org/threeten/extra/TestOffsetDate.java b/src/test/java/org/threeten/extra/TestOffsetDate.java index 616d293b..a5e6331d 100644 --- a/src/test/java/org/threeten/extra/TestOffsetDate.java +++ b/src/test/java/org/threeten/extra/TestOffsetDate.java @@ -87,9 +87,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test OffsetDate. @@ -315,7 +313,7 @@ public void test_from_TemporalAccessor_null() { // parse() //----------------------------------------------------------------------- @ParameterizedTest - @UseDataProvider("data_sampleToString") + @MethodSource("data_sampleToString") public void factory_parse_validText(int y, int m, int d, String offsetId, String parsable) { OffsetDate t = OffsetDate.parse(parsable); assertNotNull(t, parsable); @@ -325,7 +323,6 @@ public void factory_parse_validText(int y, int m, int d, String offsetId, String assertEquals(ZoneOffset.of(offsetId), t.getOffset()); } - @DataProvider public static Object[][] data_sampleBadParse() { return new Object[][]{ {"2008/07/05"}, @@ -348,7 +345,7 @@ public static Object[][] data_sampleBadParse() { } @ParameterizedTest - @UseDataProvider("data_sampleBadParse") + @MethodSource("data_sampleBadParse") public void factory_parse_invalidText(String unparsable) { assertThrows(DateTimeParseException.class, () -> OffsetDate.parse(unparsable)); } @@ -411,7 +408,6 @@ public void constructor_nullOffset() throws Throwable { //----------------------------------------------------------------------- // basics //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_sampleDates() { return new Object[][] { {2008, 7, 5, OFFSET_PTWO}, @@ -425,7 +421,7 @@ public static Object[][] data_sampleDates() { } @ParameterizedTest - @UseDataProvider("data_sampleDates") + @MethodSource("data_sampleDates") public void test_get_OffsetDate(int y, int m, int d, ZoneOffset offset) { LocalDate localDate = LocalDate.of(y, m, d); OffsetDate a = OffsetDate.of(localDate, offset); @@ -543,7 +539,6 @@ public void test_adjustInto() { //----------------------------------------------------------------------- // until(Temporal, TemporalUnit) //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_until() { return new Object[][] { {1, OffsetDate.of(2007, 6, 30, OFFSET_PONE), OffsetDate.of(2007, 7, 1, OFFSET_PONE), ChronoUnit.DAYS}, @@ -554,7 +549,7 @@ public static Object[][] data_until() { } @ParameterizedTest - @UseDataProvider("data_until") + @MethodSource("data_until") public void test_until(long expected, OffsetDate od1, OffsetDate od2, TemporalUnit unit) { assertEquals(expected, od1.until(od2, unit)); assertEquals(-expected, od2.until(od1, unit)); @@ -949,7 +944,6 @@ public void test_plusMonths_long_invalidTooSmall() { //----------------------------------------------------------------------- // plusWeeks() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_samplePlusWeeksSymmetry() { return new Object[][] { {OffsetDate.of(-1, 1, 1, OFFSET_PONE)}, @@ -982,7 +976,7 @@ public static Object[][] data_samplePlusWeeksSymmetry() { } @ParameterizedTest - @UseDataProvider("data_samplePlusWeeksSymmetry") + @MethodSource("data_samplePlusWeeksSymmetry") public void test_plusWeeks_symmetry(OffsetDate reference) { for (int weeks = 0; weeks < 365 * 8; weeks++) { OffsetDate t = reference.plusWeeks(weeks).plusWeeks(-weeks); @@ -1078,7 +1072,6 @@ public void test_plusWeeks_invalidMaxMinusMin() { //----------------------------------------------------------------------- // plusDays() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_samplePlusDaysSymmetry() { return new Object[][] { {OffsetDate.of(-1, 1, 1, OFFSET_PONE)}, @@ -1111,7 +1104,7 @@ public static Object[][] data_samplePlusDaysSymmetry() { } @ParameterizedTest - @UseDataProvider("data_samplePlusDaysSymmetry") + @MethodSource("data_samplePlusDaysSymmetry") public void test_plusDays_symmetry(OffsetDate reference) { for (int days = 0; days < 365 * 8; days++) { OffsetDate t = reference.plusDays(days).plusDays(-days); @@ -1374,7 +1367,6 @@ public void test_minusMonths_long_invalidTooSmall() { //----------------------------------------------------------------------- // minusWeeks() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_sampleMinusWeeksSymmetry() { return new Object[][] { {OffsetDate.of(-1, 1, 1, OFFSET_PONE)}, @@ -1407,7 +1399,7 @@ public static Object[][] data_sampleMinusWeeksSymmetry() { } @ParameterizedTest - @UseDataProvider("data_sampleMinusWeeksSymmetry") + @MethodSource("data_sampleMinusWeeksSymmetry") public void test_minusWeeks_symmetry(OffsetDate reference) { for (int weeks = 0; weeks < 365 * 8; weeks++) { OffsetDate t = reference.minusWeeks(weeks).minusWeeks(-weeks); @@ -1503,7 +1495,6 @@ public void test_minusWeeks_invalidMaxMinusMin() { //----------------------------------------------------------------------- // minusDays() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_sampleMinusDaysSymmetry() { return new Object[][] { {OffsetDate.of(-1, 1, 1, OFFSET_PONE)}, @@ -1536,7 +1527,7 @@ public static Object[][] data_sampleMinusDaysSymmetry() { } @ParameterizedTest - @UseDataProvider("data_sampleMinusDaysSymmetry") + @MethodSource("data_sampleMinusDaysSymmetry") public void test_minusDays_symmetry(OffsetDate reference) { for (int days = 0; days < 365 * 8; days++) { OffsetDate t = reference.minusDays(days).minusDays(-days); @@ -1664,7 +1655,7 @@ public void test_atTime_Local_nullLocalTime() { // toLocalDate() //----------------------------------------------------------------------- @ParameterizedTest - @UseDataProvider("data_sampleDates") + @MethodSource("data_sampleDates") public void test_toLocalDate(int year, int month, int day, ZoneOffset offset) { LocalDate t = LocalDate.of(year, month, day); assertEquals(t, OffsetDate.of(year, month, day, offset).toLocalDate()); @@ -1831,7 +1822,7 @@ public void test_isEqual_null() { // equals() / hashCode() //----------------------------------------------------------------------- @ParameterizedTest - @UseDataProvider("data_sampleDates") + @MethodSource("data_sampleDates") public void test_equals_true(int y, int m, int d, ZoneOffset offset) { OffsetDate a = OffsetDate.of(y, m, d, offset); OffsetDate b = OffsetDate.of(y, m, d, offset); @@ -1840,7 +1831,7 @@ public void test_equals_true(int y, int m, int d, ZoneOffset offset) { } @ParameterizedTest - @UseDataProvider("data_sampleDates") + @MethodSource("data_sampleDates") public void test_equals_false_year_differs(int y, int m, int d, ZoneOffset offset) { OffsetDate a = OffsetDate.of(y, m, d, offset); OffsetDate b = OffsetDate.of(y + 1, m, d, offset); @@ -1848,7 +1839,7 @@ public void test_equals_false_year_differs(int y, int m, int d, ZoneOffset offse } @ParameterizedTest - @UseDataProvider("data_sampleDates") + @MethodSource("data_sampleDates") public void test_equals_false_month_differs(int y, int m, int d, ZoneOffset offset) { OffsetDate a = OffsetDate.of(y, m, d, offset); OffsetDate b = OffsetDate.of(y, m + 1, d, offset); @@ -1856,7 +1847,7 @@ public void test_equals_false_month_differs(int y, int m, int d, ZoneOffset offs } @ParameterizedTest - @UseDataProvider("data_sampleDates") + @MethodSource("data_sampleDates") public void test_equals_false_day_differs(int y, int m, int d, ZoneOffset offset) { OffsetDate a = OffsetDate.of(y, m, d, offset); OffsetDate b = OffsetDate.of(y, m, d + 1, offset); @@ -1864,7 +1855,7 @@ public void test_equals_false_day_differs(int y, int m, int d, ZoneOffset offset } @ParameterizedTest - @UseDataProvider("data_sampleDates") + @MethodSource("data_sampleDates") public void test_equals_false_offset_differs(int y, int m, int d, ZoneOffset ignored) { OffsetDate a = OffsetDate.of(y, m, d, OFFSET_PONE); OffsetDate b = OffsetDate.of(y, m, d, OFFSET_PTWO); @@ -1884,7 +1875,6 @@ public void test_equals_string_false() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_sampleToString() { return new Object[][] { {2008, 7, 5, "Z", "2008-07-05Z"}, @@ -1913,7 +1903,7 @@ public static Object[][] data_sampleToString() { } @ParameterizedTest - @UseDataProvider("data_sampleToString") + @MethodSource("data_sampleToString") public void test_toString(int y, int m, int d, String offsetId, String expected) { OffsetDate t = OffsetDate.of(y, m, d, ZoneOffset.of(offsetId)); String str = t.toString(); diff --git a/src/test/java/org/threeten/extra/TestPeriodDuration.java b/src/test/java/org/threeten/extra/TestPeriodDuration.java index a7d76cca..55514a61 100644 --- a/src/test/java/org/threeten/extra/TestPeriodDuration.java +++ b/src/test/java/org/threeten/extra/TestPeriodDuration.java @@ -57,9 +57,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test class. @@ -194,7 +192,6 @@ public void test_from() { } //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_valid() { return new Object[][] { {"P1Y2M3W4DT5H6M7S", Period.of(1, 2, 3 * 7 + 4), Duration.ofHours(5).plusMinutes(6).plusSeconds(7)}, @@ -220,24 +217,23 @@ public static Object[][] data_valid() { } @ParameterizedTest - @UseDataProvider("data_valid") + @MethodSource("data_valid") public void test_parse_CharSequence_valid(String str, Period period, Duration duration) { assertEquals(PeriodDuration.of(period, duration), PeriodDuration.parse(str)); } @ParameterizedTest - @UseDataProvider("data_valid") + @MethodSource("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, Period period, Duration duration) { assertEquals(PeriodDuration.of(period, duration), PeriodDuration.parse("+" + str)); } @ParameterizedTest - @UseDataProvider("data_valid") + @MethodSource("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, Period period, Duration duration) { assertEquals(PeriodDuration.of(period, duration).negated(), PeriodDuration.parse("-" + str)); } - @DataProvider public static Object[][] data_invalid() { return new Object[][] { {"P3Q"}, @@ -256,7 +252,7 @@ public static Object[][] data_invalid() { } @ParameterizedTest - @UseDataProvider("data_invalid") + @MethodSource("data_invalid") public void test_parse_CharSequence_invalid(String str) { assertThrows(DateTimeParseException.class, () -> PeriodDuration.parse(str)); } diff --git a/src/test/java/org/threeten/extra/TestQuarter.java b/src/test/java/org/threeten/extra/TestQuarter.java index d825a510..3b60be79 100644 --- a/src/test/java/org/threeten/extra/TestQuarter.java +++ b/src/test/java/org/threeten/extra/TestQuarter.java @@ -85,9 +85,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test Quarter. @@ -315,7 +313,6 @@ public void test_getLong_null() { //----------------------------------------------------------------------- // plus(long), plus(long,unit) //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_plus() { return new Object[][] { {1, -5, 4}, @@ -333,7 +330,7 @@ public static Object[][] data_plus() { } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_plus_long(int base, long amount, int expected) { assertEquals(Quarter.of(expected), Quarter.of(base).plus(amount)); } @@ -341,7 +338,6 @@ public void test_plus_long(int base, long amount, int expected) { //----------------------------------------------------------------------- // minus(long), minus(long,unit) //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_minus() { return new Object[][] { {1, -5, 2}, @@ -359,7 +355,7 @@ public static Object[][] data_minus() { } @ParameterizedTest - @UseDataProvider("data_minus") + @MethodSource("data_minus") public void test_minus_long(int base, long amount, int expected) { assertEquals(Quarter.of(expected), Quarter.of(base).minus(amount)); } diff --git a/src/test/java/org/threeten/extra/TestSeconds.java b/src/test/java/org/threeten/extra/TestSeconds.java index d8cc0130..e1188334 100644 --- a/src/test/java/org/threeten/extra/TestSeconds.java +++ b/src/test/java/org/threeten/extra/TestSeconds.java @@ -48,9 +48,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test class. @@ -150,7 +148,6 @@ public void test_ofMinutes_overflow() { } //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_valid() { return new Object[][] { {"PT0S", 0}, @@ -211,24 +208,23 @@ public static Object[][] data_valid() { } @ParameterizedTest - @UseDataProvider("data_valid") + @MethodSource("data_valid") public void test_parse_CharSequence_valid(String str, int expectedSeconds) { assertEquals(Seconds.of(expectedSeconds), Seconds.parse(str)); } @ParameterizedTest - @UseDataProvider("data_valid") + @MethodSource("data_valid") public void test_parse_CharSequence_valid_initialPlus(String str, int expectedSeconds) { assertEquals(Seconds.of(expectedSeconds), Seconds.parse("+" + str)); } @ParameterizedTest - @UseDataProvider("data_valid") + @MethodSource("data_valid") public void test_parse_CharSequence_valid_initialMinus(String str, int expectedSeconds) { assertEquals(Seconds.of(-expectedSeconds), Seconds.parse("-" + str)); } - @DataProvider public static Object[][] data_invalid() { return new Object[][] { {"P3W"}, @@ -249,7 +245,7 @@ public static Object[][] data_invalid() { } @ParameterizedTest - @UseDataProvider("data_invalid") + @MethodSource("data_invalid") public void test_parse_CharSequence_invalid(String str) { assertThrows(DateTimeParseException.class, () -> Seconds.parse(str)); } diff --git a/src/test/java/org/threeten/extra/TestTemporals.java b/src/test/java/org/threeten/extra/TestTemporals.java index 858cc652..7eaa1463 100644 --- a/src/test/java/org/threeten/extra/TestTemporals.java +++ b/src/test/java/org/threeten/extra/TestTemporals.java @@ -153,7 +153,7 @@ public void test_nextWorkingDay_yearChange() { test = Temporals.nextWorkingDay().adjustInto(saturday); assertEquals(LocalDate.of(2012, JANUARY, 2), test); } - + //----------------------------------------------------------------------- // nextWorkingDayOrSame() //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestWeeks.java b/src/test/java/org/threeten/extra/TestWeeks.java index 510779a8..13174605 100644 --- a/src/test/java/org/threeten/extra/TestWeeks.java +++ b/src/test/java/org/threeten/extra/TestWeeks.java @@ -54,9 +54,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test class. @@ -170,7 +168,6 @@ public void test_parse_CharSequence() { assertEquals(Weeks.of(2), Weeks.parse("-P-2W")); } - @DataProvider public static Object[][] data_invalid() { return new Object[][] { {"P3Y"}, @@ -188,7 +185,7 @@ public static Object[][] data_invalid() { } @ParameterizedTest - @UseDataProvider("data_invalid") + @MethodSource("data_invalid") public void test_parse_CharSequence_invalid(String str) { assertThrows(DateTimeParseException.class, () -> Weeks.parse(str)); } diff --git a/src/test/java/org/threeten/extra/TestYearWeek.java b/src/test/java/org/threeten/extra/TestYearWeek.java index f908c653..f9ece612 100644 --- a/src/test/java/org/threeten/extra/TestYearWeek.java +++ b/src/test/java/org/threeten/extra/TestYearWeek.java @@ -126,16 +126,13 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; public class TestYearWeek { private static final YearWeek TEST_NON_LEAP = YearWeek.of(2014, 1); private static final YearWeek TEST = YearWeek.of(2015, 1); - @DataProvider public static Object[][] data_sampleYearWeeks() { return new Object[][]{ {2015, 1}, @@ -197,7 +194,6 @@ public static Object[][] data_sampleYearWeeks() { }; } - @DataProvider public static Object[][] data_53WeekYear() { return new Object[][]{ {4}, @@ -274,7 +270,6 @@ public static Object[][] data_53WeekYear() { }; } - @DataProvider public static Object[][] data_sampleAtDay() { return new Object[][]{ {2014, 52, MONDAY, 2014, 12, 22}, @@ -307,7 +302,6 @@ public static Object[][] data_sampleAtDay() { }; } - @DataProvider public static Object[][] data_outOfBounds() { return new Object[][] { {IsoFields.WEEK_OF_WEEK_BASED_YEAR, 54}, @@ -399,7 +393,7 @@ public void now_Clock_nullClock() { // of(Year, int) //----------------------------------------------------------------------- @ParameterizedTest - @UseDataProvider("data_sampleYearWeeks") + @MethodSource("data_sampleYearWeeks") public void test_of_Year_int(int year, int week) { YearWeek yearWeek = YearWeek.of(Year.of(year), week); assertEquals(year, yearWeek.getYear()); @@ -415,7 +409,7 @@ public void test_carry_Year_int() { // of(int, int) //----------------------------------------------------------------------- @ParameterizedTest - @UseDataProvider("data_sampleYearWeeks") + @MethodSource("data_sampleYearWeeks") public void test_of(int year, int week) { YearWeek yearWeek = YearWeek.of(year, week); assertEquals(year, yearWeek.getYear()); @@ -514,7 +508,7 @@ public void test_isSupported_TemporalUnit() { // atDay(DayOfWeek) //----------------------------------------------------------------------- @ParameterizedTest - @UseDataProvider("data_sampleAtDay") + @MethodSource("data_sampleAtDay") public void test_atDay(int weekBasedYear, int weekOfWeekBasedYear, DayOfWeek dayOfWeek, int year, int month, int dayOfMonth) { YearWeek yearWeek = YearWeek.of(weekBasedYear, weekOfWeekBasedYear); LocalDate expected = LocalDate.of(year, month, dayOfMonth); @@ -546,7 +540,7 @@ public void test_atDay_null() { // is53WeekYear() //----------------------------------------------------------------------- @ParameterizedTest - @UseDataProvider("data_53WeekYear") + @MethodSource("data_53WeekYear") public void test_is53WeekYear(int year) { YearWeek yearWeek = YearWeek.of(year, 1); assertTrue(yearWeek.is53WeekYear()); @@ -616,7 +610,7 @@ public void test_compareTo_nullYearWeek() { // from(TemporalAccessor) //----------------------------------------------------------------------- @ParameterizedTest - @UseDataProvider("data_sampleAtDay") + @MethodSource("data_sampleAtDay") public void test_from(int weekBasedYear, int weekOfWeekBasedYear, DayOfWeek dayOfWeek, int year, int month, int dayOfMonth) { YearWeek expected = YearWeek.of(weekBasedYear, weekOfWeekBasedYear); LocalDate ld = LocalDate.of(year, month, dayOfMonth); @@ -692,7 +686,7 @@ public void test_with() { } @ParameterizedTest - @UseDataProvider("data_outOfBounds") + @MethodSource("data_outOfBounds") public void test_with_outOfBounds(TemporalField field, long newValue) { assertThrows(DateTimeException.class, () -> TEST.with(field, newValue)); } @@ -1090,7 +1084,7 @@ public void test_query() { // equals() / hashCode() //----------------------------------------------------------------------- @ParameterizedTest - @UseDataProvider("data_sampleYearWeeks") + @MethodSource("data_sampleYearWeeks") public void test_equalsAndHashCodeContract(int year, int week) { YearWeek a = YearWeek.of(year, week); YearWeek b = YearWeek.of(year, week); @@ -1121,7 +1115,6 @@ public void test_equals_incorrectType() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_sampleToString() { return new Object[][]{ {2015, 1, "2015-W01"}, @@ -1133,7 +1126,7 @@ public static Object[][] data_sampleToString() { } @ParameterizedTest - @UseDataProvider("data_sampleToString") + @MethodSource("data_sampleToString") public void test_toString(int year, int week, String expected) { YearWeek yearWeek = YearWeek.of(year, week); String s = yearWeek.toString(); diff --git a/src/test/java/org/threeten/extra/TestYears.java b/src/test/java/org/threeten/extra/TestYears.java index 529d7e83..6f49e9bf 100644 --- a/src/test/java/org/threeten/extra/TestYears.java +++ b/src/test/java/org/threeten/extra/TestYears.java @@ -54,9 +54,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test class. @@ -175,7 +173,6 @@ public void test_parse_CharSequence() { assertEquals(Years.of(2), Years.parse("-P-2Y")); } - @DataProvider public static Object[][] data_invalid() { return new Object[][] { {"P3M"}, @@ -193,7 +190,7 @@ public static Object[][] data_invalid() { } @ParameterizedTest - @UseDataProvider("data_invalid") + @MethodSource("data_invalid") public void test_parse_CharSequence_invalid(String str) { assertThrows(DateTimeParseException.class, () -> Years.parse(str)); } diff --git a/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java b/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java index 76b0213f..8254a2db 100644 --- a/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java @@ -77,9 +77,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test. @@ -105,7 +103,6 @@ public void test_chronology_of_name_id() { //----------------------------------------------------------------------- // creation, toLocalDate() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_samples() { return new Object[][] { {INSTANCE.date(1, 1, 1), LocalDate.of(0, 9, 4)}, @@ -142,55 +139,55 @@ public static Object[][] data_samples() { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_LocalDate_from_AccountingDate(AccountingDate accounting, LocalDate iso) { assertEquals(iso, LocalDate.from(accounting)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_AccountingDate_from_LocalDate(AccountingDate accounting, LocalDate iso) { assertEquals(accounting, AccountingDate.from(INSTANCE, iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_AccountingDate_chronology_dateEpochDay(AccountingDate accounting, LocalDate iso) { assertEquals(accounting, INSTANCE.dateEpochDay(iso.toEpochDay())); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_AccountingDate_toEpochDay(AccountingDate accounting, LocalDate iso) { assertEquals(iso.toEpochDay(), accounting.toEpochDay()); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_AccountingDate_until_CoptiDate(AccountingDate accounting, LocalDate iso) { assertEquals(INSTANCE.period(0, 0, 0), accounting.until(accounting)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_AccountingDate_until_LocalDate(AccountingDate accounting, LocalDate iso) { assertEquals(INSTANCE.period(0, 0, 0), accounting.until(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_LocalDate_until_CoptiDate(AccountingDate accounting, LocalDate iso) { assertEquals(Period.ZERO, iso.until(accounting)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_Chronology_date_Temporal(AccountingDate accounting, LocalDate iso) { assertEquals(accounting, INSTANCE.date(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_plusDays(AccountingDate accounting, LocalDate iso) { assertEquals(iso, LocalDate.from(accounting.plus(0, DAYS))); assertEquals(iso.plusDays(1), LocalDate.from(accounting.plus(1, DAYS))); @@ -200,7 +197,7 @@ public void test_plusDays(AccountingDate accounting, LocalDate iso) { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_minusDays(AccountingDate accounting, LocalDate iso) { assertEquals(iso, LocalDate.from(accounting.minus(0, DAYS))); assertEquals(iso.minusDays(1), LocalDate.from(accounting.minus(1, DAYS))); @@ -210,7 +207,7 @@ public void test_minusDays(AccountingDate accounting, LocalDate iso) { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_until_DAYS(AccountingDate accounting, LocalDate iso) { assertEquals(0, accounting.until(iso.plusDays(0), DAYS)); assertEquals(1, accounting.until(iso.plusDays(1), DAYS)); @@ -218,7 +215,6 @@ public void test_until_DAYS(AccountingDate accounting, LocalDate iso) { assertEquals(-40, accounting.until(iso.minusDays(40), DAYS)); } - @DataProvider public static Object[][] data_badDates() { return new Object[][] { {2012, 0, 0}, @@ -262,7 +258,7 @@ public static Object[][] data_badDates() { } @ParameterizedTest - @UseDataProvider("data_badDates") + @MethodSource("data_badDates") public void test_badDates(int year, int month, int dom) { assertThrows(DateTimeException.class, () -> INSTANCE.date(year, month, dom)); } @@ -338,7 +334,6 @@ public void test_isLeapYear_specific() { assertEquals(false, INSTANCE.isLeapYear(-6)); } - @DataProvider public static Object[][] data_lengthOfMonth() { return new Object[][] { {2012, 1, 28}, @@ -363,7 +358,7 @@ public static Object[][] data_lengthOfMonth() { } @ParameterizedTest - @UseDataProvider("data_lengthOfMonth") + @MethodSource("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(length, INSTANCE.date(year, month, 1).lengthOfMonth()); } @@ -450,7 +445,6 @@ public void test_Chronology_range() { //----------------------------------------------------------------------- // AccountingDate.range //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_ranges() { return new Object[][] { {2012, 1, 23, DAY_OF_MONTH, 1, 28}, @@ -478,7 +472,7 @@ public static Object[][] data_ranges() { } @ParameterizedTest - @UseDataProvider("data_ranges") + @MethodSource("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(ValueRange.of(expectedMin, expectedMax), INSTANCE.date(year, month, dom).range(field)); } @@ -491,7 +485,6 @@ public void test_range_unsupported() { //----------------------------------------------------------------------- // AccountingDate.getLong //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_getLong() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 5}, @@ -513,7 +506,7 @@ public static Object[][] data_getLong() { } @ParameterizedTest - @UseDataProvider("data_getLong") + @MethodSource("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(expected, INSTANCE.date(year, month, dom).getLong(field)); } @@ -526,7 +519,6 @@ public void test_getLong_unsupported() { //----------------------------------------------------------------------- // AccountingDate.with //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_with() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 3, 2014, 5, 24}, @@ -565,7 +557,7 @@ public static Object[][] data_with() { } @ParameterizedTest - @UseDataProvider("data_with") + @MethodSource("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { @@ -630,7 +622,6 @@ public void test_LocalDateTime_adjustToAccountingDate() { //----------------------------------------------------------------------- // AccountingDate.plus //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_plus() { return new Object[][] { {2014, 5, 26, 0, DAYS, 2014, 5, 26}, @@ -659,7 +650,7 @@ public static Object[][] data_plus() { } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { @@ -667,7 +658,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -683,7 +674,6 @@ public void test_plus_TemporalUnit_unsupported() { //----------------------------------------------------------------------- // AccountingDate.until //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_until() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, DAYS, 0}, @@ -713,7 +703,7 @@ public static Object[][] data_until() { } @ParameterizedTest - @UseDataProvider("data_until") + @MethodSource("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -784,7 +774,6 @@ public void test_equals() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_toString() { return new Object[][] { {INSTANCE.date(1, 1, 1), "Accounting calendar ends on SUNDAY nearest end of AUGUST, year divided in THIRTEEN_EVEN_MONTHS_OF_4_WEEKS with leap-week in month 13 CE 1-01-01"}, @@ -793,7 +782,7 @@ public static Object[][] data_toString() { } @ParameterizedTest - @UseDataProvider("data_toString") + @MethodSource("data_toString") public void test_toString(AccountingDate accounting, String expected) { assertEquals(expected, accounting.toString()); } diff --git a/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java b/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java index 2a1d9e16..4d381f79 100644 --- a/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java +++ b/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java @@ -46,9 +46,7 @@ import java.util.function.IntPredicate; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test. @@ -58,7 +56,6 @@ public class TestAccountingChronologyBuilder { //----------------------------------------------------------------------- // isLeapYear(), date(int, int, int) //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_yearEnding() { return new Object[][] { {DayOfWeek.MONDAY, Month.JANUARY}, @@ -84,7 +81,7 @@ public static Object[][] data_yearEnding() { } @ParameterizedTest - @UseDataProvider("data_yearEnding") + @MethodSource("data_yearEnding") public void test_isLeapYear_inLastWeekOf(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) @@ -105,7 +102,7 @@ public void test_isLeapYear_inLastWeekOf(DayOfWeek dayOfWeek, Month ending) { } @ParameterizedTest - @UseDataProvider("data_yearEnding") + @MethodSource("data_yearEnding") public void test_isLeapYear_nearestEndOf(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) @@ -126,7 +123,7 @@ public void test_isLeapYear_nearestEndOf(DayOfWeek dayOfWeek, Month ending) { } @ParameterizedTest - @UseDataProvider("data_yearEnding") + @MethodSource("data_yearEnding") public void test_previousLeapYears_inLastWeekOf(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) @@ -156,7 +153,7 @@ public void test_previousLeapYears_inLastWeekOf(DayOfWeek dayOfWeek, Month endin } @ParameterizedTest - @UseDataProvider("data_yearEnding") + @MethodSource("data_yearEnding") public void test_previousLeapYears_nearestEndOf(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) @@ -186,7 +183,7 @@ public void test_previousLeapYears_nearestEndOf(DayOfWeek dayOfWeek, Month endin } @ParameterizedTest - @UseDataProvider("data_yearEnding") + @MethodSource("data_yearEnding") public void test_date_int_int_int_inLastWeekOf(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) @@ -202,7 +199,7 @@ public void test_date_int_int_int_inLastWeekOf(DayOfWeek dayOfWeek, Month ending } @ParameterizedTest - @UseDataProvider("data_yearEnding") + @MethodSource("data_yearEnding") public void test_date_int_int_int_nearestEndOf(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) @@ -220,7 +217,6 @@ public void test_date_int_int_int_nearestEndOf(DayOfWeek dayOfWeek, Month ending //----------------------------------------------------------------------- // range(MONTH_OF_YEAR), range(DAY_OF_MONTH) //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_range() { return new Object[][] { {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, 1, @@ -268,7 +264,7 @@ public static Object[][] data_range() { } @ParameterizedTest - @UseDataProvider("data_range") + @MethodSource("data_range") public void test_range(AccountingYearDivision division, int leapWeekInMonth, ValueRange expectedWeekOfMonthRange, ValueRange expectedDayOfMonthRange, ValueRange expectedMonthRange, ValueRange expectedProlepticMonthRange) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST) @@ -283,7 +279,7 @@ public void test_range(AccountingYearDivision division, int leapWeekInMonth, } @ParameterizedTest - @UseDataProvider("data_weeksInMonth") + @MethodSource("data_weeksInMonth") public void test_date_dayOfMonth_range(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST) .withDivision(division).leapWeekInMonth(leapWeekInMonth) @@ -298,7 +294,7 @@ public void test_date_dayOfMonth_range(AccountingYearDivision division, int[] we } @ParameterizedTest - @UseDataProvider("data_yearEnding") + @MethodSource("data_yearEnding") public void test_date_dayOfYear_inLastWeekOf_range(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) @@ -319,7 +315,7 @@ public void test_date_dayOfYear_inLastWeekOf_range(DayOfWeek dayOfWeek, Month en } @ParameterizedTest - @UseDataProvider("data_yearEnding") + @MethodSource("data_yearEnding") public void test_date_dayOfYear_nearestEndOf_range(DayOfWeek dayOfWeek, Month ending) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) @@ -340,10 +336,9 @@ public void test_date_dayOfYear_nearestEndOf_range(DayOfWeek dayOfWeek, Month en } //----------------------------------------------------------------------- - // getWeeksInMonth(month), + // getWeeksInMonth(month), // getWeeksAtStartOfMonth(weeks), getMonthFromElapsedWeeks(weeks) //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_weeksInMonth() { return new Object[][] { {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, new int[] {4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5}, 1}, @@ -372,7 +367,7 @@ public static Object[][] data_weeksInMonth() { } @ParameterizedTest - @UseDataProvider("data_weeksInMonth") + @MethodSource("data_weeksInMonth") public void test_getWeeksInMonth(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST) .withDivision(division).leapWeekInMonth(leapWeekInMonth) @@ -385,7 +380,7 @@ public void test_getWeeksInMonth(AccountingYearDivision division, int[] weeksInM } @ParameterizedTest - @UseDataProvider("data_weeksInMonth") + @MethodSource("data_weeksInMonth") public void test_getWeeksAtStartOf(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST) .withDivision(division).leapWeekInMonth(leapWeekInMonth) @@ -398,7 +393,7 @@ public void test_getWeeksAtStartOf(AccountingYearDivision division, int[] weeksI } @ParameterizedTest - @UseDataProvider("data_weeksInMonth") + @MethodSource("data_weeksInMonth") public void test_getMonthFromElapsedWeeks(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST) .withDivision(division).leapWeekInMonth(leapWeekInMonth) @@ -416,14 +411,14 @@ public void test_getMonthFromElapsedWeeks(AccountingYearDivision division, int[] } @ParameterizedTest - @UseDataProvider("data_weeksInMonth") + @MethodSource("data_weeksInMonth") public void test_negativeWeeks_getMonthFromElapsedWeekspublic(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { assertEquals(1, division.getMonthFromElapsedWeeks(0)); assertThrows(DateTimeException.class, () -> division.getMonthFromElapsedWeeks(-1)); } @ParameterizedTest - @UseDataProvider("data_weeksInMonth") + @MethodSource("data_weeksInMonth") public void test_extraWeeks_getMonthFromElapsedWeekspublic(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { int elapsedWeeks = 0; for (int month = 1; month <= weeksInMonth.length; month++) { @@ -435,7 +430,7 @@ public void test_extraWeeks_getMonthFromElapsedWeekspublic(AccountingYearDivisio } @ParameterizedTest - @UseDataProvider("data_weeksInMonth") + @MethodSource("data_weeksInMonth") public void test_extraWeeksLeap_getMonthFromElapsedWeekspublic(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { int elapsedWeeks = 1; for (int month = 1; month <= weeksInMonth.length; month++) { @@ -449,7 +444,6 @@ public void test_extraWeeksLeap_getMonthFromElapsedWeekspublic(AccountingYearDiv //----------------------------------------------------------------------- // toChronology() failures. //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_badChronology() { return new Object[][] { {DayOfWeek.MONDAY, Month.JANUARY, AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS, 0}, @@ -466,7 +460,7 @@ public static Object[][] data_badChronology() { } @ParameterizedTest - @UseDataProvider("data_badChronology") + @MethodSource("data_badChronology") public void test_badChronology_nearestEndOf(DayOfWeek dayOfWeek, Month ending, AccountingYearDivision division, int leapWeekInMonth) { assertThrows(IllegalStateException.class, () -> new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) .withDivision(division).leapWeekInMonth(leapWeekInMonth) @@ -474,7 +468,7 @@ public void test_badChronology_nearestEndOf(DayOfWeek dayOfWeek, Month ending, A } @ParameterizedTest - @UseDataProvider("data_badChronology") + @MethodSource("data_badChronology") public void test_badChronology_inLastWeekOf(DayOfWeek dayOfWeek, Month ending, AccountingYearDivision division, int leapWeekInMonth) { assertThrows(IllegalStateException.class, () -> new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) .withDivision(division).leapWeekInMonth(leapWeekInMonth) diff --git a/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java b/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java index 4adc951b..36bf1a58 100644 --- a/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java @@ -87,9 +87,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test. @@ -111,7 +109,6 @@ public void test_chronology_of_name() { //----------------------------------------------------------------------- // creation, toLocalDate() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_samples() { return new Object[][] { {BritishCutoverDate.of(1, 1, 1), LocalDate.of(0, 12, 30)}, @@ -157,55 +154,55 @@ public static Object[][] data_samples() { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_LocalDate_from_BritishCutoverDate(BritishCutoverDate cutover, LocalDate iso) { assertEquals(iso, LocalDate.from(cutover)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_BritishCutoverDate_from_LocalDate(BritishCutoverDate cutover, LocalDate iso) { assertEquals(cutover, BritishCutoverDate.from(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_BritishCutoverDate_chronology_dateEpochDay(BritishCutoverDate cutover, LocalDate iso) { assertEquals(cutover, BritishCutoverChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_BritishCutoverDate_toEpochDay(BritishCutoverDate cutover, LocalDate iso) { assertEquals(iso.toEpochDay(), cutover.toEpochDay()); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_BritishCutoverDate_until_BritishCutoverDate(BritishCutoverDate cutover, LocalDate iso) { assertEquals(BritishCutoverChronology.INSTANCE.period(0, 0, 0), cutover.until(cutover)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_BritishCutoverDate_until_LocalDate(BritishCutoverDate cutover, LocalDate iso) { assertEquals(BritishCutoverChronology.INSTANCE.period(0, 0, 0), cutover.until(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_LocalDate_until_BritishCutoverDate(BritishCutoverDate cutover, LocalDate iso) { assertEquals(Period.ZERO, iso.until(cutover)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_Chronology_date_Temporal(BritishCutoverDate cutover, LocalDate iso) { assertEquals(cutover, BritishCutoverChronology.INSTANCE.date(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_plusDays(BritishCutoverDate cutover, LocalDate iso) { assertEquals(iso, LocalDate.from(cutover.plus(0, DAYS))); assertEquals(iso.plusDays(1), LocalDate.from(cutover.plus(1, DAYS))); @@ -215,7 +212,7 @@ public void test_plusDays(BritishCutoverDate cutover, LocalDate iso) { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_minusDays(BritishCutoverDate cutover, LocalDate iso) { assertEquals(iso, LocalDate.from(cutover.minus(0, DAYS))); assertEquals(iso.minusDays(1), LocalDate.from(cutover.minus(1, DAYS))); @@ -225,7 +222,7 @@ public void test_minusDays(BritishCutoverDate cutover, LocalDate iso) { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_until_DAYS(BritishCutoverDate cutover, LocalDate iso) { assertEquals(0, cutover.until(iso.plusDays(0), DAYS)); assertEquals(1, cutover.until(iso.plusDays(1), DAYS)); @@ -233,7 +230,6 @@ public void test_until_DAYS(BritishCutoverDate cutover, LocalDate iso) { assertEquals(-40, cutover.until(iso.minusDays(40), DAYS)); } - @DataProvider public static Object[][] data_badDates() { return new Object[][] { {1900, 0, 0}, @@ -277,7 +273,7 @@ public static Object[][] data_badDates() { } @ParameterizedTest - @UseDataProvider("data_badDates") + @MethodSource("data_badDates") public void test_badDates(int year, int month, int dom) { assertThrows(DateTimeException.class, () -> BritishCutoverDate.of(year, month, dom)); } @@ -329,7 +325,6 @@ public void test_Chronology_getCutover() { //----------------------------------------------------------------------- // lengthOfMonth() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_lengthOfMonth() { return new Object[][] { {1700, 1, 31}, @@ -399,7 +394,7 @@ public static Object[][] data_lengthOfMonth() { } @ParameterizedTest - @UseDataProvider("data_lengthOfMonth") + @MethodSource("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(length, BritishCutoverDate.of(year, month, 1).lengthOfMonth()); } @@ -407,7 +402,6 @@ public void test_lengthOfMonth(int year, int month, int length) { //----------------------------------------------------------------------- // lengthOfYear() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_lengthOfYear() { return new Object[][] { {-101, 365}, @@ -440,13 +434,13 @@ public static Object[][] data_lengthOfYear() { } @ParameterizedTest - @UseDataProvider("data_lengthOfYear") + @MethodSource("data_lengthOfYear") public void test_lengthOfYear_atStart(int year, int length) { assertEquals(length, BritishCutoverDate.of(year, 1, 1).lengthOfYear()); } @ParameterizedTest - @UseDataProvider("data_lengthOfYear") + @MethodSource("data_lengthOfYear") public void test_lengthOfYear_atEnd(int year, int length) { assertEquals(length, BritishCutoverDate.of(year, 12, 31).lengthOfYear()); } @@ -546,7 +540,6 @@ public void test_Chronology_range() { //----------------------------------------------------------------------- // BritishCutoverDate.range //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_ranges() { return new Object[][] { {1700, 1, 23, DAY_OF_MONTH, 1, 31}, @@ -633,7 +626,7 @@ public static Object[][] data_ranges() { } @ParameterizedTest - @UseDataProvider("data_ranges") + @MethodSource("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(ValueRange.of(expectedMin, expectedMax), BritishCutoverDate.of(year, month, dom).range(field)); } @@ -646,7 +639,6 @@ public void test_range_unsupported() { //----------------------------------------------------------------------- // BritishCutoverDate.getLong //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_getLong() { return new Object[][] { {1752, 5, 26, DAY_OF_WEEK, 2}, @@ -695,7 +687,7 @@ public static Object[][] data_getLong() { } @ParameterizedTest - @UseDataProvider("data_getLong") + @MethodSource("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(expected, BritishCutoverDate.of(year, month, dom).getLong(field)); } @@ -708,7 +700,6 @@ public void test_getLong_unsupported() { //----------------------------------------------------------------------- // BritishCutoverDate.with //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_with() { return new Object[][] { {1752, 9, 2, DAY_OF_WEEK, 1, 1752, 8, 31}, @@ -807,7 +798,7 @@ public static Object[][] data_with() { } @ParameterizedTest - @UseDataProvider("data_with") + @MethodSource("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { @@ -822,7 +813,6 @@ public void test_with_TemporalField_unsupported() { //----------------------------------------------------------------------- // BritishCutoverDate.with(TemporalAdjuster) //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_lastDayOfMonth() { return new Object[][] { {BritishCutoverDate.of(1752, 2, 23), BritishCutoverDate.of(1752, 2, 29)}, @@ -835,7 +825,7 @@ public static Object[][] data_lastDayOfMonth() { } @ParameterizedTest - @UseDataProvider("data_lastDayOfMonth") + @MethodSource("data_lastDayOfMonth") public void test_adjust_lastDayOfMonth(BritishCutoverDate input, BritishCutoverDate expected) { BritishCutoverDate test = input.with(TemporalAdjusters.lastDayOfMonth()); assertEquals(expected, test); @@ -844,7 +834,6 @@ public void test_adjust_lastDayOfMonth(BritishCutoverDate input, BritishCutoverD //----------------------------------------------------------------------- // BritishCutoverDate.with(Local*) //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_withLocalDate() { return new Object[][] { {BritishCutoverDate.of(1752, 9, 2), LocalDate.of(1752, 9, 12), BritishCutoverDate.of(1752, 9, 1)}, @@ -856,7 +845,7 @@ public static Object[][] data_withLocalDate() { } @ParameterizedTest - @UseDataProvider("data_withLocalDate") + @MethodSource("data_withLocalDate") public void test_adjust_LocalDate(BritishCutoverDate input, LocalDate local, BritishCutoverDate expected) { BritishCutoverDate test = input.with(local); assertEquals(expected, test); @@ -888,7 +877,6 @@ public void test_LocalDateTime_withBritishCutoverDate() { //----------------------------------------------------------------------- // BritishCutoverDate.plus //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_plus() { return new Object[][] { {1752, 9, 2, -1, DAYS, 1752, 9, 1, true}, @@ -941,7 +929,7 @@ public static Object[][] data_plus() { } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom, boolean bidi) { @@ -949,7 +937,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -967,7 +955,6 @@ public void test_plus_TemporalUnit_unsupported() { //----------------------------------------------------------------------- // BritishCutoverDate.until //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_until() { return new Object[][] { {1752, 9, 1, 1752, 9, 2, DAYS, 1}, @@ -1021,7 +1008,7 @@ public static Object[][] data_until() { } @ParameterizedTest - @UseDataProvider("data_until") + @MethodSource("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -1073,7 +1060,6 @@ public void test_minus_Period_ISO() { } //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_untilCLD() { return new Object[][] { {1752, 7, 2, 1752, 7, 1, 0, 0, -1}, @@ -1175,7 +1161,7 @@ public static Object[][] data_untilCLD() { {1752, 9, 14, 1752, 10, 13, 0, 0, 29}, {1752, 9, 14, 1752, 10, 14, 0, 1, 0}, {1752, 9, 14, 1752, 10, 15, 0, 1, 1}, - + {1752, 9, 24, 1752, 7, 23, 0, -2, -1}, {1752, 9, 24, 1752, 7, 24, 0, -2, 0}, {1752, 9, 24, 1752, 8, 23, 0, -1, -1}, @@ -1192,7 +1178,7 @@ public static Object[][] data_untilCLD() { {1752, 9, 24, 1752, 10, 23, 0, 0, 29}, {1752, 9, 24, 1752, 10, 24, 0, 1, 0}, {1752, 9, 24, 1752, 10, 25, 0, 1, 1}, - + {1752, 10, 3, 1752, 10, 1, 0, 0, -2}, {1752, 10, 3, 1752, 9, 30, 0, 0, -3}, {1752, 10, 3, 1752, 9, 16, 0, 0, -17}, @@ -1204,7 +1190,7 @@ public static Object[][] data_untilCLD() { {1752, 10, 3, 1752, 8, 4, 0, -1, -30}, {1752, 10, 3, 1752, 8, 3, 0, -2, 0}, {1752, 10, 3, 1752, 8, 2, 0, -2, -1}, - + {1752, 10, 4, 1752, 10, 1, 0, 0, -3}, {1752, 10, 4, 1752, 9, 30, 0, 0, -4}, {1752, 10, 4, 1752, 9, 16, 0, 0, -18}, @@ -1220,7 +1206,7 @@ public static Object[][] data_untilCLD() { } @ParameterizedTest - @UseDataProvider("data_untilCLD") + @MethodSource("data_untilCLD") public void test_until_CLD( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -1234,7 +1220,7 @@ public void test_until_CLD( } @ParameterizedTest - @UseDataProvider("data_untilCLD") + @MethodSource("data_untilCLD") public void test_until_CLD_plus( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -1312,7 +1298,6 @@ public void test_equals() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_toString() { return new Object[][] { {BritishCutoverDate.of(1, 1, 1), "BritishCutover AD 1-01-01"}, @@ -1321,7 +1306,7 @@ public static Object[][] data_toString() { } @ParameterizedTest - @UseDataProvider("data_toString") + @MethodSource("data_toString") public void test_toString(BritishCutoverDate cutover, String expected) { assertEquals(expected, cutover.toString()); } diff --git a/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java b/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java index 00fa1d04..61c02cf2 100644 --- a/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java @@ -76,9 +76,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test. @@ -109,7 +107,6 @@ public void test_chronology_of_name_id() { //----------------------------------------------------------------------- // creation, toLocalDate() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_samples() { return new Object[][] { {CopticDate.of(-1, 13, 6), LocalDate.of(283, 8, 29)}, @@ -138,55 +135,55 @@ public static Object[][] data_samples() { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_LocalDate_from_CopticDate(CopticDate coptic, LocalDate iso) { assertEquals(iso, LocalDate.from(coptic)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_CopticDate_from_LocalDate(CopticDate coptic, LocalDate iso) { assertEquals(coptic, CopticDate.from(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_CopticDate_chronology_dateEpochDay(CopticDate coptic, LocalDate iso) { assertEquals(coptic, CopticChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_CopticDate_toEpochDay(CopticDate coptic, LocalDate iso) { assertEquals(iso.toEpochDay(), coptic.toEpochDay()); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_CopticDate_until_CopticDate(CopticDate coptic, LocalDate iso) { assertEquals(CopticChronology.INSTANCE.period(0, 0, 0), coptic.until(coptic)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_CopticDate_until_LocalDate(CopticDate coptic, LocalDate iso) { assertEquals(CopticChronology.INSTANCE.period(0, 0, 0), coptic.until(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_LocalDate_until_CopticDate(CopticDate coptic, LocalDate iso) { assertEquals(Period.ZERO, iso.until(coptic)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_Chronology_date_Temporal(CopticDate coptic, LocalDate iso) { assertEquals(coptic, CopticChronology.INSTANCE.date(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_plusDays(CopticDate coptic, LocalDate iso) { assertEquals(iso, LocalDate.from(coptic.plus(0, DAYS))); assertEquals(iso.plusDays(1), LocalDate.from(coptic.plus(1, DAYS))); @@ -196,7 +193,7 @@ public void test_plusDays(CopticDate coptic, LocalDate iso) { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_minusDays(CopticDate coptic, LocalDate iso) { assertEquals(iso, LocalDate.from(coptic.minus(0, DAYS))); assertEquals(iso.minusDays(1), LocalDate.from(coptic.minus(1, DAYS))); @@ -206,7 +203,7 @@ public void test_minusDays(CopticDate coptic, LocalDate iso) { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_until_DAYS(CopticDate coptic, LocalDate iso) { assertEquals(0, coptic.until(iso.plusDays(0), DAYS)); assertEquals(1, coptic.until(iso.plusDays(1), DAYS)); @@ -214,7 +211,6 @@ public void test_until_DAYS(CopticDate coptic, LocalDate iso) { assertEquals(-40, coptic.until(iso.minusDays(40), DAYS)); } - @DataProvider public static Object[][] data_badDates() { return new Object[][] { {1728, 0, 0}, @@ -247,7 +243,7 @@ public static Object[][] data_badDates() { } @ParameterizedTest - @UseDataProvider("data_badDates") + @MethodSource("data_badDates") public void test_badDates(int year, int month, int dom) { assertThrows(DateTimeException.class, () -> CopticDate.of(year, month, dom)); } @@ -288,7 +284,6 @@ public void test_isLeapYear_specific() { assertEquals(false, CopticChronology.INSTANCE.isLeapYear(-6)); } - @DataProvider public static Object[][] data_lengthOfMonth() { return new Object[][] { {1726, 1, 30}, @@ -309,7 +304,7 @@ public static Object[][] data_lengthOfMonth() { } @ParameterizedTest - @UseDataProvider("data_lengthOfMonth") + @MethodSource("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(length, CopticDate.of(year, month, 1).lengthOfMonth()); } @@ -390,7 +385,6 @@ public void test_Chronology_range() { //----------------------------------------------------------------------- // CopticDate.range //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_ranges() { return new Object[][] { {1727, 1, 23, DAY_OF_MONTH, 1, 30}, @@ -420,7 +414,7 @@ public static Object[][] data_ranges() { } @ParameterizedTest - @UseDataProvider("data_ranges") + @MethodSource("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(ValueRange.of(expectedMin, expectedMax), CopticDate.of(year, month, dom).range(field)); } @@ -433,7 +427,6 @@ public void test_range_unsupported() { //----------------------------------------------------------------------- // CopticDate.getLong //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_getLong() { return new Object[][] { {1727, 6, 8, DAY_OF_WEEK, 2}, @@ -455,7 +448,7 @@ public static Object[][] data_getLong() { } @ParameterizedTest - @UseDataProvider("data_getLong") + @MethodSource("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(expected, CopticDate.of(year, month, dom).getLong(field)); } @@ -468,7 +461,6 @@ public void test_getLong_unsupported() { //----------------------------------------------------------------------- // CopticDate.with //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_with() { return new Object[][] { {1727, 6, 8, DAY_OF_WEEK, 4, 1727, 6, 10}, @@ -505,7 +497,7 @@ public static Object[][] data_with() { } @ParameterizedTest - @UseDataProvider("data_with") + @MethodSource("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { @@ -570,7 +562,6 @@ public void test_LocalDateTime_adjustToCopticDate() { //----------------------------------------------------------------------- // CopticDate.plus //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_plus() { return new Object[][] { {1726, 5, 26, 0, DAYS, 1726, 5, 26}, @@ -599,7 +590,7 @@ public static Object[][] data_plus() { } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { @@ -607,7 +598,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -644,7 +635,6 @@ public void test_minus_Period_ISO() { //----------------------------------------------------------------------- // CopticDate.until //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_until() { return new Object[][] { {1726, 5, 26, 1726, 5, 26, DAYS, 0}, @@ -672,7 +662,7 @@ public static Object[][] data_until() { } @ParameterizedTest - @UseDataProvider("data_until") + @MethodSource("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -715,7 +705,6 @@ public void test_equals() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_toString() { return new Object[][] { {CopticDate.of(1, 1, 1), "Coptic AM 1-01-01"}, @@ -727,7 +716,7 @@ public static Object[][] data_toString() { } @ParameterizedTest - @UseDataProvider("data_toString") + @MethodSource("data_toString") public void test_toString(CopticDate coptic, String expected) { assertEquals(expected, coptic.toString()); } diff --git a/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java b/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java index 5795e4c4..69b65be6 100644 --- a/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java @@ -79,9 +79,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test. @@ -112,7 +110,6 @@ public void test_chronology_of_name_id() { //----------------------------------------------------------------------- // creation, toLocalDate() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_samples() { return new Object[][] { {DiscordianDate.of(2, 1, 1), LocalDate.of(-1164, 1, 1)}, @@ -154,55 +151,55 @@ public static Object[][] data_samples() { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_LocalDate_from_DiscordianDate(DiscordianDate discordian, LocalDate iso) { assertEquals(iso, LocalDate.from(discordian)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_DiscordianDate_from_LocalDate(DiscordianDate discordian, LocalDate iso) { assertEquals(discordian, DiscordianDate.from(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_DiscordianDate_chronology_dateEpochDay(DiscordianDate discordian, LocalDate iso) { assertEquals(discordian, DiscordianChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_DiscordianDate_toEpochDay(DiscordianDate discordian, LocalDate iso) { assertEquals(iso.toEpochDay(), discordian.toEpochDay()); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_DiscordianDate_until_DiscordianDate(DiscordianDate discordian, LocalDate iso) { assertEquals(DiscordianChronology.INSTANCE.period(0, 0, 0), discordian.until(discordian)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_DiscordianDate_until_LocalDate(DiscordianDate discordian, LocalDate iso) { assertEquals(DiscordianChronology.INSTANCE.period(0, 0, 0), discordian.until(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_LocalDate_until_DiscordianDate(DiscordianDate discordian, LocalDate iso) { assertEquals(Period.ZERO, iso.until(discordian)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_Chronology_date_Temporal(DiscordianDate discordian, LocalDate iso) { assertEquals(discordian, DiscordianChronology.INSTANCE.date(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_plusDays(DiscordianDate discordian, LocalDate iso) { assertEquals(iso, LocalDate.from(discordian.plus(0, DAYS))); assertEquals(iso.plusDays(1), LocalDate.from(discordian.plus(1, DAYS))); @@ -212,7 +209,7 @@ public void test_plusDays(DiscordianDate discordian, LocalDate iso) { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_minusDays(DiscordianDate discordian, LocalDate iso) { assertEquals(iso, LocalDate.from(discordian.minus(0, DAYS))); assertEquals(iso.minusDays(1), LocalDate.from(discordian.minus(1, DAYS))); @@ -222,7 +219,7 @@ public void test_minusDays(DiscordianDate discordian, LocalDate iso) { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_until_DAYS(DiscordianDate discordian, LocalDate iso) { assertEquals(0, discordian.until(iso.plusDays(0), DAYS)); assertEquals(1, discordian.until(iso.plusDays(1), DAYS)); @@ -230,7 +227,6 @@ public void test_until_DAYS(DiscordianDate discordian, LocalDate iso) { assertEquals(-40, discordian.until(iso.minusDays(40), DAYS)); } - @DataProvider public static Object[][] data_badDates() { return new Object[][] { {1900, 0, 0}, @@ -257,7 +253,7 @@ public static Object[][] data_badDates() { } @ParameterizedTest - @UseDataProvider("data_badDates") + @MethodSource("data_badDates") public void test_badDates(int year, int month, int dom) { assertThrows(DateTimeException.class, () -> DiscordianDate.of(year, month, dom)); } @@ -302,7 +298,6 @@ public void test_isLeapYear_specific() { assertEquals(false, DiscordianChronology.INSTANCE.isLeapYear(1160)); } - @DataProvider public static Object[][] data_lengthOfMonth() { return new Object[][] { {1900, 1, 73}, @@ -321,7 +316,7 @@ public static Object[][] data_lengthOfMonth() { } @ParameterizedTest - @UseDataProvider("data_lengthOfMonth") + @MethodSource("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(length, DiscordianDate.of(year, month, 1).lengthOfMonth()); } @@ -414,7 +409,6 @@ public void test_Chronology_range() { //----------------------------------------------------------------------- // DiscordianDate.range //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_ranges() { return new Object[][] { // St Tibs is in its own month, so (0 to 0) or (1 to 73) @@ -457,7 +451,7 @@ public static Object[][] data_ranges() { } @ParameterizedTest - @UseDataProvider("data_ranges") + @MethodSource("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(ValueRange.of(expectedMin, expectedMax), DiscordianDate.of(year, month, dom).range(field)); } @@ -470,7 +464,6 @@ public void test_range_unsupported() { //----------------------------------------------------------------------- // DiscordianDate.getLong //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_getLong() { return new Object[][] { {2014, 1, 26, DAY_OF_WEEK, 1}, @@ -511,7 +504,7 @@ public static Object[][] data_getLong() { } @ParameterizedTest - @UseDataProvider("data_getLong") + @MethodSource("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(expected, DiscordianDate.of(year, month, dom).getLong(field)); } @@ -524,7 +517,6 @@ public void test_getLong_unsupported() { //----------------------------------------------------------------------- // DiscordianDate.with //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_with() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 1, 2014, 5, 24}, @@ -600,14 +592,13 @@ public static Object[][] data_with() { } @ParameterizedTest - @UseDataProvider("data_with") + @MethodSource("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(DiscordianDate.of(expectedYear, expectedMonth, expectedDom), DiscordianDate.of(year, month, dom).with(field, value)); } - @DataProvider public static Object[][] data_with_bad() { return new Object[][] { {2013, 1, 1, DAY_OF_WEEK, 0}, @@ -633,7 +624,7 @@ public static Object[][] data_with_bad() { } @ParameterizedTest - @UseDataProvider("data_with_bad") + @MethodSource("data_with_bad") public void test_with_TemporalField_badValue(int year, int month, int dom, TemporalField field, long value) { assertThrows(DateTimeException.class, () -> DiscordianDate.of(year, month, dom).with(field, value)); } @@ -696,7 +687,6 @@ public void test_LocalDateTime_adjustToDiscordianDate() { //----------------------------------------------------------------------- // DiscordianDate.plus //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_plus() { return new Object[][] { {2014, 5, 26, 0, DAYS, 2014, 5, 26}, @@ -723,7 +713,6 @@ public static Object[][] data_plus() { }; } - @DataProvider public static Object[][] data_plus_leap() { return new Object[][] { {2014, 0, 0, 0, DAYS, 2014, 0, 0}, @@ -744,7 +733,6 @@ public static Object[][] data_plus_leap() { }; } - @DataProvider public static Object[][] data_minus_leap() { return new Object[][] { {2014, 0, 0, 0, DAYS, 2014, 0, 0}, @@ -766,7 +754,7 @@ public static Object[][] data_minus_leap() { } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { @@ -774,7 +762,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, } @ParameterizedTest - @UseDataProvider("data_plus_leap") + @MethodSource("data_plus_leap") public void test_plus_leap_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { @@ -782,7 +770,7 @@ public void test_plus_leap_TemporalUnit(int year, int month, int dom, } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -791,7 +779,7 @@ public void test_minus_TemporalUnit( } @ParameterizedTest - @UseDataProvider("data_minus_leap") + @MethodSource("data_minus_leap") public void test_minus_leap_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -807,7 +795,6 @@ public void test_plus_TemporalUnit_unsupported() { //----------------------------------------------------------------------- // DiscordianDate.until //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_until() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, DAYS, 0}, @@ -873,7 +860,6 @@ public static Object[][] data_until() { }; } - @DataProvider public static Object[][] data_until_period() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, 0, 0, 0}, @@ -920,7 +906,7 @@ public static Object[][] data_until_period() { } @ParameterizedTest - @UseDataProvider("data_until") + @MethodSource("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -931,7 +917,7 @@ public void test_until_TemporalUnit( } @ParameterizedTest - @UseDataProvider("data_until_period") + @MethodSource("data_until_period") public void test_until_end( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -996,7 +982,6 @@ public void test_equals() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_toString() { return new Object[][] { {DiscordianDate.of(1, 1, 1), "Discordian YOLD 1-1-01"}, @@ -1006,7 +991,7 @@ public static Object[][] data_toString() { } @ParameterizedTest - @UseDataProvider("data_toString") + @MethodSource("data_toString") public void test_toString(DiscordianDate discordian, String expected) { assertEquals(expected, discordian.toString()); } diff --git a/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java b/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java index 34ff8893..33f48b48 100644 --- a/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java @@ -76,9 +76,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test. @@ -109,7 +107,6 @@ public void test_chronology_of_name_id() { //----------------------------------------------------------------------- // creation, toLocalDate() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_samples() { return new Object[][] { {EthiopicDate.of(-1, 13, 6), LocalDate.of(7, 8, 27)}, @@ -139,55 +136,55 @@ public static Object[][] data_samples() { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_LocalDate_from_EthiopicDate(EthiopicDate ethiopic, LocalDate iso) { assertEquals(iso, LocalDate.from(ethiopic)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_EthiopicDate_from_LocalDate(EthiopicDate ethiopic, LocalDate iso) { assertEquals(ethiopic, EthiopicDate.from(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_EthiopicDate_chronology_dateEpochDay(EthiopicDate ethiopic, LocalDate iso) { assertEquals(ethiopic, EthiopicChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_EthiopicDate_toEpochDay(EthiopicDate ethiopic, LocalDate iso) { assertEquals(iso.toEpochDay(), ethiopic.toEpochDay()); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_EthiopicDate_until_EthiopicDate(EthiopicDate ethiopic, LocalDate iso) { assertEquals(EthiopicChronology.INSTANCE.period(0, 0, 0), ethiopic.until(ethiopic)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_EthiopicDate_until_LocalDate(EthiopicDate ethiopic, LocalDate iso) { assertEquals(EthiopicChronology.INSTANCE.period(0, 0, 0), ethiopic.until(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_LocalDate_until_EthiopicDate(EthiopicDate ethiopic, LocalDate iso) { assertEquals(Period.ZERO, iso.until(ethiopic)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_Chronology_date_Temporal(EthiopicDate ethiopic, LocalDate iso) { assertEquals(ethiopic, EthiopicChronology.INSTANCE.date(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_plusDays(EthiopicDate ethiopic, LocalDate iso) { assertEquals(iso, LocalDate.from(ethiopic.plus(0, DAYS))); assertEquals(iso.plusDays(1), LocalDate.from(ethiopic.plus(1, DAYS))); @@ -197,7 +194,7 @@ public void test_plusDays(EthiopicDate ethiopic, LocalDate iso) { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_minusDays(EthiopicDate ethiopic, LocalDate iso) { assertEquals(iso, LocalDate.from(ethiopic.minus(0, DAYS))); assertEquals(iso.minusDays(1), LocalDate.from(ethiopic.minus(1, DAYS))); @@ -207,7 +204,7 @@ public void test_minusDays(EthiopicDate ethiopic, LocalDate iso) { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_until_DAYS(EthiopicDate ethiopic, LocalDate iso) { assertEquals(0, ethiopic.until(iso.plusDays(0), DAYS)); assertEquals(1, ethiopic.until(iso.plusDays(1), DAYS)); @@ -215,7 +212,6 @@ public void test_until_DAYS(EthiopicDate ethiopic, LocalDate iso) { assertEquals(-40, ethiopic.until(iso.minusDays(40), DAYS)); } - @DataProvider public static Object[][] data_badDates() { return new Object[][] { {2008, 0, 0}, @@ -248,7 +244,7 @@ public static Object[][] data_badDates() { } @ParameterizedTest - @UseDataProvider("data_badDates") + @MethodSource("data_badDates") public void test_badDates(int year, int month, int dom) { assertThrows(DateTimeException.class, () -> EthiopicDate.of(year, month, dom)); } @@ -289,7 +285,6 @@ public void test_isLeapYear_specific() { assertEquals(false, EthiopicChronology.INSTANCE.isLeapYear(-6)); } - @DataProvider public static Object[][] data_lengthOfMonth() { return new Object[][] { {2006, 1, 30}, @@ -310,7 +305,7 @@ public static Object[][] data_lengthOfMonth() { } @ParameterizedTest - @UseDataProvider("data_lengthOfMonth") + @MethodSource("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(length, EthiopicDate.of(year, month, 1).lengthOfMonth()); } @@ -391,7 +386,6 @@ public void test_Chronology_range() { //----------------------------------------------------------------------- // EthiopicDate.range //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_ranges() { return new Object[][] { {2007, 1, 23, DAY_OF_MONTH, 1, 30}, @@ -421,7 +415,7 @@ public static Object[][] data_ranges() { } @ParameterizedTest - @UseDataProvider("data_ranges") + @MethodSource("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(ValueRange.of(expectedMin, expectedMax), EthiopicDate.of(year, month, dom).range(field)); } @@ -434,7 +428,6 @@ public void test_range_unsupported() { //----------------------------------------------------------------------- // EthiopicDate.getLong //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_getLong() { return new Object[][] { {2007, 6, 8, DAY_OF_WEEK, 7}, @@ -456,7 +449,7 @@ public static Object[][] data_getLong() { } @ParameterizedTest - @UseDataProvider("data_getLong") + @MethodSource("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(expected, EthiopicDate.of(year, month, dom).getLong(field)); } @@ -469,7 +462,6 @@ public void test_getLong_unsupported() { //----------------------------------------------------------------------- // EthiopicDate.with //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_with() { return new Object[][] { {2007, 6, 8, DAY_OF_WEEK, 3, 2007, 6, 4}, @@ -509,14 +501,13 @@ public static Object[][] data_with() { } @ParameterizedTest - @UseDataProvider("data_with") + @MethodSource("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(EthiopicDate.of(expectedYear, expectedMonth, expectedDom), EthiopicDate.of(year, month, dom).with(field, value)); } - @DataProvider public static Object[][] data_with_bad() { return new Object[][] { {2007, 6, 8, DAY_OF_WEEK, 0}, @@ -532,7 +523,7 @@ public static Object[][] data_with_bad() { } @ParameterizedTest - @UseDataProvider("data_with_bad") + @MethodSource("data_with_bad") public void test_with_TemporalField_badValue(int year, int month, int dom, TemporalField field, long value) { assertThrows(DateTimeException.class, () -> EthiopicDate.of(year, month, dom).with(field, value)); } @@ -595,7 +586,6 @@ public void test_LocalDateTime_adjustToEthiopicDate() { //----------------------------------------------------------------------- // EthiopicDate.plus //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_plus() { return new Object[][] { {2006, 5, 26, 0, DAYS, 2006, 5, 26}, @@ -624,7 +614,7 @@ public static Object[][] data_plus() { } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { @@ -632,7 +622,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -669,7 +659,6 @@ public void test_minus_Period_ISO() { //----------------------------------------------------------------------- // EthiopicDate.until //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_until() { return new Object[][] { {2006, 5, 26, 2006, 5, 26, DAYS, 0}, @@ -697,7 +686,7 @@ public static Object[][] data_until() { } @ParameterizedTest - @UseDataProvider("data_until") + @MethodSource("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -740,7 +729,6 @@ public void test_equals() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_toString() { return new Object[][] { {EthiopicDate.of(1, 1, 1), "Ethiopic INCARNATION 1-01-01"}, @@ -752,7 +740,7 @@ public static Object[][] data_toString() { } @ParameterizedTest - @UseDataProvider("data_toString") + @MethodSource("data_toString") public void test_toString(EthiopicDate ethiopic, String expected) { assertEquals(expected, ethiopic.toString()); } diff --git a/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java b/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java index fc36cd3c..6559e26a 100644 --- a/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java @@ -79,9 +79,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test. @@ -104,7 +102,6 @@ public void test_chronology() { //----------------------------------------------------------------------- // creation, toLocalDate() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_samples() { return new Object[][] { {InternationalFixedDate.of(1, 1, 1), LocalDate.of(1, 1, 1)}, @@ -152,55 +149,55 @@ public static Object[][] data_samples() { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_LocalDate_from_InternationalFixedDate(InternationalFixedDate fixed, LocalDate iso) { assertEquals(iso, LocalDate.from(fixed)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_InternationalFixedDate_from_LocalDate(InternationalFixedDate fixed, LocalDate iso) { assertEquals(fixed, InternationalFixedDate.from(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_InternationalFixedDate_chronology_dateEpochDay(InternationalFixedDate fixed, LocalDate iso) { assertEquals(fixed, InternationalFixedChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_InternationalFixedDate_toEpochDay(InternationalFixedDate fixed, LocalDate iso) { assertEquals(iso.toEpochDay(), fixed.toEpochDay()); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_InternationalFixedDate_until_InternationalFixedDate(InternationalFixedDate fixed, LocalDate iso) { assertEquals(InternationalFixedChronology.INSTANCE.period(0, 0, 0), fixed.until(fixed)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_InternationalFixedDate_until_LocalDate(InternationalFixedDate fixed, LocalDate iso) { assertEquals(InternationalFixedChronology.INSTANCE.period(0, 0, 0), fixed.until(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_LocalDate_until_InternationalFixedDate(InternationalFixedDate fixed, LocalDate iso) { assertEquals(Period.ZERO, iso.until(fixed)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_Chronology_date_Temporal(InternationalFixedDate fixed, LocalDate iso) { assertEquals(fixed, InternationalFixedChronology.INSTANCE.date(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_plusDays(InternationalFixedDate fixed, LocalDate iso) { assertEquals(iso, LocalDate.from(fixed.plus(0, DAYS))); assertEquals(iso.plusDays(1), LocalDate.from(fixed.plus(1, DAYS))); @@ -212,7 +209,7 @@ public void test_plusDays(InternationalFixedDate fixed, LocalDate iso) { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_minusDays(InternationalFixedDate fixed, LocalDate iso) { assertEquals(iso, LocalDate.from(fixed.minus(0, DAYS))); if (LocalDate.ofYearDay(1, 35).isBefore(iso)) { @@ -225,7 +222,7 @@ public void test_minusDays(InternationalFixedDate fixed, LocalDate iso) { @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_until_DAYS(InternationalFixedDate fixed, LocalDate iso) { assertEquals(0, fixed.until(iso.plusDays(0), DAYS)); assertEquals(1, fixed.until(iso.plusDays(1), DAYS)); @@ -235,7 +232,6 @@ public void test_until_DAYS(InternationalFixedDate fixed, LocalDate iso) { } } - @DataProvider public static Object[][] data_badDates() { return new Object[][] { {-1, 13, 28}, @@ -277,12 +273,11 @@ public static Object[][] data_badDates() { } @ParameterizedTest - @UseDataProvider("data_badDates") + @MethodSource("data_badDates") public void test_badDates(int year, int month, int dom) { assertThrows(DateTimeException.class, () -> InternationalFixedDate.of(year, month, dom)); } - @DataProvider public static Object[][] data_badLeapDates() { return new Object[][] { {1}, @@ -294,7 +289,7 @@ public static Object[][] data_badLeapDates() { } @ParameterizedTest - @UseDataProvider("data_badLeapDates") + @MethodSource("data_badLeapDates") public void badLeapDayDates(int year) { assertThrows(DateTimeException.class, () -> InternationalFixedDate.of(year, 6, 29)); } @@ -334,7 +329,6 @@ public void test_isLeapYear_specific() { //----------------------------------------------------------------------- // lengthOfMonth() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_lengthOfMonth() { return new Object[][] { {1900, 1, 28, 28}, @@ -355,13 +349,13 @@ public static Object[][] data_lengthOfMonth() { } @ParameterizedTest - @UseDataProvider("data_lengthOfMonth") + @MethodSource("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int day, int length) { assertEquals(length, InternationalFixedDate.of(year, month, day).lengthOfMonth()); } @ParameterizedTest - @UseDataProvider("data_lengthOfMonth") + @MethodSource("data_lengthOfMonth") public void test_lengthOfMonthFirst(int year, int month, int day, int length) { assertEquals(length, InternationalFixedDate.of(year, month, 1).lengthOfMonth()); } @@ -412,7 +406,6 @@ public void test_prolepticYear_specific() { assertEquals(1582, InternationalFixedChronology.INSTANCE.prolepticYear(InternationalFixedEra.CE, 1582)); } - @DataProvider public static Object[][] data_prolepticYear_bad() { return new Object[][] { {-10}, @@ -422,7 +415,7 @@ public static Object[][] data_prolepticYear_bad() { } @ParameterizedTest - @UseDataProvider("data_prolepticYear_bad") + @MethodSource("data_prolepticYear_bad") public void test_prolepticYearBad(int year) { assertThrows(DateTimeException.class, () -> InternationalFixedChronology.INSTANCE.prolepticYear(InternationalFixedEra.CE, year)); } @@ -472,7 +465,6 @@ public void test_Chronology_range() { //----------------------------------------------------------------------- // InternationalFixedDate.range //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_ranges() { return new Object[][] { // Leap Day and Year Day are members of months @@ -533,7 +525,7 @@ public static Object[][] data_ranges() { } @ParameterizedTest - @UseDataProvider("data_ranges") + @MethodSource("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, ValueRange range) { assertEquals(range, InternationalFixedDate.of(year, month, dom).range(field)); } @@ -546,7 +538,6 @@ public void test_range_unsupported() { //----------------------------------------------------------------------- // InternationalFixedDate.getLong //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_getLong() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 5}, @@ -615,7 +606,7 @@ public static Object[][] data_getLong() { } @ParameterizedTest - @UseDataProvider("data_getLong") + @MethodSource("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(expected, InternationalFixedDate.of(year, month, dom).getLong(field)); } @@ -628,7 +619,6 @@ public void test_getLong_unsupported() { //----------------------------------------------------------------------- // InternationalFixedDate.with //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_with() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 1, 2014, 5, 22}, @@ -763,14 +753,13 @@ public static Object[][] data_with() { } @ParameterizedTest - @UseDataProvider("data_with") + @MethodSource("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(InternationalFixedDate.of(expectedYear, expectedMonth, expectedDom), InternationalFixedDate.of(year, month, dom).with(field, value)); } - @DataProvider public static Object[][] data_with_bad() { return new Object[][] { {2013, 1, 1, ALIGNED_DAY_OF_WEEK_IN_MONTH, 0}, @@ -830,7 +819,7 @@ public static Object[][] data_with_bad() { } @ParameterizedTest - @UseDataProvider("data_with_bad") + @MethodSource("data_with_bad") public void test_with_TemporalField_badValue(int year, int month, int dom, TemporalField field, long value) { assertThrows(DateTimeException.class, () -> InternationalFixedDate.of(year, month, dom).with(field, value)); } @@ -843,7 +832,6 @@ public void test_with_TemporalField_unsupported() { //----------------------------------------------------------------------- // InternationalFixedDate.with(TemporalAdjuster) //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_temporalAdjusters_lastDayOfMonth() { return new Object[][] { {2012, 6, 23, 2012, 6, 29}, @@ -855,7 +843,7 @@ public static Object[][] data_temporalAdjusters_lastDayOfMonth() { } @ParameterizedTest - @UseDataProvider("data_temporalAdjusters_lastDayOfMonth") + @MethodSource("data_temporalAdjusters_lastDayOfMonth") public void test_temporalAdjusters_LastDayOfMonth(int year, int month, int day, int expectedYear, int expectedMonth, int expectedDay) { InternationalFixedDate base = InternationalFixedDate.of(year, month, day); InternationalFixedDate expected = InternationalFixedDate.of(expectedYear, expectedMonth, expectedDay); @@ -900,7 +888,6 @@ public void test_LocalDateTime_adjustToInternationalFixedDate() { // InternationalFixedDate.plus // InternationalFixedDate.minus //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_plus() { return new Object[][] { {2014, 5, 26, 0, DAYS, 2014, 5, 26}, @@ -936,7 +923,6 @@ public static Object[][] data_plus() { }; } - @DataProvider public static Object[][] data_plus_leap_and_year_day() { return new Object[][] { {2014, 13, 29, 0, DAYS, 2014, 13, 29}, @@ -978,7 +964,6 @@ public static Object[][] data_plus_leap_and_year_day() { }; } - @DataProvider public static Object[][] data_minus_leap_and_year_day() { return new Object[][] { {2014, 13, 29, 0, DAYS, 2014, 13, 29}, @@ -1022,7 +1007,7 @@ public static Object[][] data_minus_leap_and_year_day() { } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { @@ -1030,7 +1015,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, } @ParameterizedTest - @UseDataProvider("data_plus_leap_and_year_day") + @MethodSource("data_plus_leap_and_year_day") public void test_plus_leap_and_year_day_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { @@ -1038,7 +1023,7 @@ public void test_plus_leap_and_year_day_TemporalUnit(int year, int month, int do } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -1047,7 +1032,7 @@ public void test_minus_TemporalUnit( } @ParameterizedTest - @UseDataProvider("data_minus_leap_and_year_day") + @MethodSource("data_minus_leap_and_year_day") public void test_minus_leap_and_year_day_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -1063,7 +1048,6 @@ public void test_plus_TemporalUnit_unsupported() { //----------------------------------------------------------------------- // InternationalFixedDate.until //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_until() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, DAYS, 0}, @@ -1195,7 +1179,6 @@ public static Object[][] data_until() { }; } - @DataProvider public static Object[][] data_until_period() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, 0, 0, 0}, @@ -1272,7 +1255,7 @@ public static Object[][] data_until_period() { } @ParameterizedTest - @UseDataProvider("data_until") + @MethodSource("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -1283,7 +1266,7 @@ public void test_until_TemporalUnit( } @ParameterizedTest - @UseDataProvider("data_until_period") + @MethodSource("data_until_period") public void test_until_end( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -1327,7 +1310,6 @@ public void test_minus_Period_ISO() { //----------------------------------------------------------------------- // equals() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_equals() { return new Object[][] { {InternationalFixedDate.of(2000, 1, 3), @@ -1340,7 +1322,7 @@ public static Object[][] data_equals() { } @ParameterizedTest - @UseDataProvider("data_equals") + @MethodSource("data_equals") public void test_equals(InternationalFixedDate a1, InternationalFixedDate b, InternationalFixedDate c, InternationalFixedDate d) { assertTrue(a1.equals(a1)); @@ -1355,7 +1337,6 @@ public void test_equals(InternationalFixedDate a1, InternationalFixedDate b, Int //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_toString() { return new Object[][] { {InternationalFixedDate.of(1, 1, 1), "Ifc CE 1/01/01"}, @@ -1368,7 +1349,7 @@ public static Object[][] data_toString() { } @ParameterizedTest - @UseDataProvider("data_toString") + @MethodSource("data_toString") public void test_toString(InternationalFixedDate date, String expected) { assertEquals(expected, date.toString()); } diff --git a/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java b/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java index 3315953b..d9c77347 100644 --- a/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java @@ -77,9 +77,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test. @@ -110,7 +108,6 @@ public void test_chronology_of_name_id() { //----------------------------------------------------------------------- // creation, toLocalDate() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_samples() { return new Object[][] { {JulianDate.of(1, 1, 1), LocalDate.of(0, 12, 30)}, @@ -147,55 +144,55 @@ public static Object[][] data_samples() { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_LocalDate_from_JulianDate(JulianDate julian, LocalDate iso) { assertEquals(iso, LocalDate.from(julian)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_JulianDate_from_LocalDate(JulianDate julian, LocalDate iso) { assertEquals(julian, JulianDate.from(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_JulianDate_chronology_dateEpochDay(JulianDate julian, LocalDate iso) { assertEquals(julian, JulianChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_JulianDate_toEpochDay(JulianDate julian, LocalDate iso) { assertEquals(iso.toEpochDay(), julian.toEpochDay()); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_JulianDate_until_JulianDate(JulianDate julian, LocalDate iso) { assertEquals(JulianChronology.INSTANCE.period(0, 0, 0), julian.until(julian)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_JulianDate_until_LocalDate(JulianDate julian, LocalDate iso) { assertEquals(JulianChronology.INSTANCE.period(0, 0, 0), julian.until(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_LocalDate_until_JulianDate(JulianDate julian, LocalDate iso) { assertEquals(Period.ZERO, iso.until(julian)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_Chronology_date_Temporal(JulianDate julian, LocalDate iso) { assertEquals(julian, JulianChronology.INSTANCE.date(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_plusDays(JulianDate julian, LocalDate iso) { assertEquals(iso, LocalDate.from(julian.plus(0, DAYS))); assertEquals(iso.plusDays(1), LocalDate.from(julian.plus(1, DAYS))); @@ -205,7 +202,7 @@ public void test_plusDays(JulianDate julian, LocalDate iso) { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_minusDays(JulianDate julian, LocalDate iso) { assertEquals(iso, LocalDate.from(julian.minus(0, DAYS))); assertEquals(iso.minusDays(1), LocalDate.from(julian.minus(1, DAYS))); @@ -215,7 +212,7 @@ public void test_minusDays(JulianDate julian, LocalDate iso) { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_until_DAYS(JulianDate julian, LocalDate iso) { assertEquals(0, julian.until(iso.plusDays(0), DAYS)); assertEquals(1, julian.until(iso.plusDays(1), DAYS)); @@ -223,7 +220,6 @@ public void test_until_DAYS(JulianDate julian, LocalDate iso) { assertEquals(-40, julian.until(iso.minusDays(40), DAYS)); } - @DataProvider public static Object[][] data_badDates() { return new Object[][] { {1900, 0, 0}, @@ -267,7 +263,7 @@ public static Object[][] data_badDates() { } @ParameterizedTest - @UseDataProvider("data_badDates") + @MethodSource("data_badDates") public void test_badDates(int year, int month, int dom) { assertThrows(DateTimeException.class, () -> JulianDate.of(year, month, dom)); } @@ -308,7 +304,6 @@ public void test_isLeapYear_specific() { assertEquals(false, JulianChronology.INSTANCE.isLeapYear(-6)); } - @DataProvider public static Object[][] data_lengthOfMonth() { return new Object[][] { {1900, 1, 31}, @@ -334,7 +329,7 @@ public static Object[][] data_lengthOfMonth() { } @ParameterizedTest - @UseDataProvider("data_lengthOfMonth") + @MethodSource("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(length, JulianDate.of(year, month, 1).lengthOfMonth()); } @@ -420,7 +415,6 @@ public void test_Chronology_range() { //----------------------------------------------------------------------- // JulianDate.range //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_ranges() { return new Object[][] { {2012, 1, 23, DAY_OF_MONTH, 1, 31}, @@ -447,7 +441,7 @@ public static Object[][] data_ranges() { } @ParameterizedTest - @UseDataProvider("data_ranges") + @MethodSource("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(ValueRange.of(expectedMin, expectedMax), JulianDate.of(year, month, dom).range(field)); } @@ -460,7 +454,6 @@ public void test_range_unsupported() { //----------------------------------------------------------------------- // JulianDate.getLong //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_getLong() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 7}, @@ -482,7 +475,7 @@ public static Object[][] data_getLong() { } @ParameterizedTest - @UseDataProvider("data_getLong") + @MethodSource("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(expected, JulianDate.of(year, month, dom).getLong(field)); } @@ -495,7 +488,6 @@ public void test_getLong_unsupported() { //----------------------------------------------------------------------- // JulianDate.with //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_with() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 3, 2014, 5, 22}, @@ -533,7 +525,7 @@ public static Object[][] data_with() { } @ParameterizedTest - @UseDataProvider("data_with") + @MethodSource("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { @@ -598,7 +590,6 @@ public void test_LocalDateTime_adjustToJulianDate() { //----------------------------------------------------------------------- // JulianDate.plus //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_plus() { return new Object[][] { {2014, 5, 26, 0, DAYS, 2014, 5, 26}, @@ -627,7 +618,7 @@ public static Object[][] data_plus() { } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { @@ -635,7 +626,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -651,7 +642,6 @@ public void test_plus_TemporalUnit_unsupported() { //----------------------------------------------------------------------- // JulianDate.until //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_until() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, DAYS, 0}, @@ -681,7 +671,7 @@ public static Object[][] data_until() { } @ParameterizedTest - @UseDataProvider("data_until") + @MethodSource("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -745,7 +735,6 @@ public void test_equals() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_toString() { return new Object[][] { {JulianDate.of(1, 1, 1), "Julian AD 1-01-01"}, @@ -754,7 +743,7 @@ public static Object[][] data_toString() { } @ParameterizedTest - @UseDataProvider("data_toString") + @MethodSource("data_toString") public void test_toString(JulianDate julian, String expected) { assertEquals(expected, julian.toString()); } diff --git a/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java b/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java index 1cf394f4..3deca728 100644 --- a/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java @@ -79,9 +79,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test. @@ -113,7 +111,6 @@ public void test_chronology_of_name_id() { //----------------------------------------------------------------------- // creation, toLocalDate() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_samples() { return new Object[][] { {PaxDate.of(1, 1, 1), LocalDate.of(0, 12, 31)}, @@ -179,55 +176,55 @@ public static Object[][] data_samples() { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_LocalDate_from_PaxDate(PaxDate pax, LocalDate iso) { assertEquals(iso, LocalDate.from(pax)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_PaxDate_from_LocalDate(PaxDate pax, LocalDate iso) { assertEquals(pax, PaxDate.from(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_PaxDate_chronology_dateEpochDay(PaxDate pax, LocalDate iso) { assertEquals(pax, PaxChronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_PaxDate_toEpochDay(PaxDate pax, LocalDate iso) { assertEquals(iso.toEpochDay(), pax.toEpochDay()); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_PaxDate_until_PaxDate(PaxDate pax, LocalDate iso) { assertEquals(PaxChronology.INSTANCE.period(0, 0, 0), pax.until(pax)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_PaxDate_until_LocalDate(PaxDate pax, LocalDate iso) { assertEquals(PaxChronology.INSTANCE.period(0, 0, 0), pax.until(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_LocalDate_until_PaxDate(PaxDate pax, LocalDate iso) { assertEquals(Period.ZERO, iso.until(pax)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_Chronology_date_Temporal(PaxDate pax, LocalDate iso) { assertEquals(pax, PaxChronology.INSTANCE.date(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_plusDays(PaxDate pax, LocalDate iso) { assertEquals(iso, LocalDate.from(pax.plus(0, DAYS))); assertEquals(iso.plusDays(1), LocalDate.from(pax.plus(1, DAYS))); @@ -237,7 +234,7 @@ public void test_plusDays(PaxDate pax, LocalDate iso) { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_minusDays(PaxDate pax, LocalDate iso) { assertEquals(iso, LocalDate.from(pax.minus(0, DAYS))); assertEquals(iso.minusDays(1), LocalDate.from(pax.minus(1, DAYS))); @@ -247,7 +244,7 @@ public void test_minusDays(PaxDate pax, LocalDate iso) { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_until_DAYS(PaxDate pax, LocalDate iso) { assertEquals(0, pax.until(iso.plusDays(0), DAYS)); assertEquals(1, pax.until(iso.plusDays(1), DAYS)); @@ -255,7 +252,6 @@ public void test_until_DAYS(PaxDate pax, LocalDate iso) { assertEquals(-40, pax.until(iso.minusDays(40), DAYS)); } - @DataProvider public static Object[][] data_badDates() { return new Object[][] { {1900, 0, 0}, @@ -303,7 +299,7 @@ public static Object[][] data_badDates() { } @ParameterizedTest - @UseDataProvider("data_badDates") + @MethodSource("data_badDates") public void test_badDates(int year, int month, int dom) { assertThrows(DateTimeException.class, () -> PaxDate.of(year, month, dom)); } @@ -353,7 +349,6 @@ public void test_isLeapYear_specific() { assertEquals(false, PaxChronology.INSTANCE.isLeapYear(-400)); } - @DataProvider public static Object[][] data_lengthOfMonth() { return new Object[][] { {1900, 1, 28}, @@ -383,7 +378,7 @@ public static Object[][] data_lengthOfMonth() { } @ParameterizedTest - @UseDataProvider("data_lengthOfMonth") + @MethodSource("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int length) { assertEquals(length, PaxDate.of(year, month, 1).lengthOfMonth()); } @@ -469,7 +464,6 @@ public void test_Chronology_range() { //----------------------------------------------------------------------- // PaxDate.range //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_ranges() { return new Object[][] { {2012, 1, 23, DAY_OF_MONTH, 1, 28}, @@ -502,7 +496,7 @@ public static Object[][] data_ranges() { } @ParameterizedTest - @UseDataProvider("data_ranges") + @MethodSource("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, int expectedMin, int expectedMax) { assertEquals(ValueRange.of(expectedMin, expectedMax), PaxDate.of(year, month, dom).range(field)); } @@ -515,7 +509,6 @@ public void test_range_unsupported() { //----------------------------------------------------------------------- // PaxDate.getLong //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_getLong() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 4}, @@ -537,7 +530,7 @@ public static Object[][] data_getLong() { } @ParameterizedTest - @UseDataProvider("data_getLong") + @MethodSource("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(expected, PaxDate.of(year, month, dom).getLong(field)); } @@ -550,7 +543,6 @@ public void test_getLong_unsupported() { //----------------------------------------------------------------------- // PaxDate.with //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_with() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 3, 2014, 5, 25}, @@ -588,7 +580,7 @@ public static Object[][] data_with() { } @ParameterizedTest - @UseDataProvider("data_with") + @MethodSource("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { @@ -653,7 +645,6 @@ public void test_LocalDateTime_adjustToPaxDate() { //----------------------------------------------------------------------- // PaxDate.plus //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_plus() { return new Object[][] { {2014, 5, 26, 0, DAYS, 2014, 5, 26}, @@ -691,7 +682,6 @@ public static Object[][] data_plus() { }; } - @DataProvider public static Object[][] data_plus_leap() { return new Object[][] { {2012, 12, 26, 1, MONTHS, 2012, 13, 7}, @@ -700,7 +690,6 @@ public static Object[][] data_plus_leap() { }; } - @DataProvider public static Object[][] data_minus_leap() { return new Object[][] { {2012, 13, 7, -1, MONTHS, 2012, 12, 26}, @@ -710,7 +699,7 @@ public static Object[][] data_minus_leap() { } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { @@ -718,7 +707,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, } @ParameterizedTest - @UseDataProvider("data_plus_leap") + @MethodSource("data_plus_leap") public void test_plus_leap_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { @@ -726,7 +715,7 @@ public void test_plus_leap_TemporalUnit(int year, int month, int dom, } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -735,7 +724,7 @@ public void test_minus_TemporalUnit( } @ParameterizedTest - @UseDataProvider("data_minus_leap") + @MethodSource("data_minus_leap") public void test_minus_leap_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { @@ -750,7 +739,6 @@ public void test_plus_TemporalUnit_unsupported() { //----------------------------------------------------------------------- // PaxDate.until //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_until() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, DAYS, 0}, @@ -792,7 +780,6 @@ public static Object[][] data_until() { }; } - @DataProvider public static Object[][] data_until_period() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, 0, 0, 0}, @@ -821,7 +808,7 @@ public static Object[][] data_until_period() { } @ParameterizedTest - @UseDataProvider("data_until") + @MethodSource("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -832,7 +819,7 @@ public void test_until_TemporalUnit( } @ParameterizedTest - @UseDataProvider("data_until_period") + @MethodSource("data_until_period") public void test_until_end( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -897,7 +884,6 @@ public void test_equals() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_toString() { return new Object[][] { {PaxDate.of(1, 1, 1), "Pax CE 1-01-01"}, @@ -906,7 +892,7 @@ public static Object[][] data_toString() { } @ParameterizedTest - @UseDataProvider("data_toString") + @MethodSource("data_toString") public void test_toString(PaxDate pax, String expected) { assertEquals(expected, pax.toString()); } diff --git a/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java b/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java index cf2e9b2b..cd6c49ec 100644 --- a/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java @@ -83,9 +83,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test. @@ -108,7 +106,6 @@ public void test_chronology() { //----------------------------------------------------------------------- // Symmetry010Date.of //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_samples() { return new Object[][] { { Symmetry010Date.of( 1, 1, 1), LocalDate.of( 1, 1, 1) }, @@ -146,55 +143,55 @@ public static Object[][] data_samples() { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_LocalDate_from_Symmetry010Date(Symmetry010Date sym010, LocalDate iso) { assertEquals(iso, LocalDate.from(sym010)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_Symmetry010Date_from_LocalDate(Symmetry010Date sym010, LocalDate iso) { assertEquals(sym010, Symmetry010Date.from(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_Symmetry010Date_chronology_dateEpochDay(Symmetry010Date sym010, LocalDate iso) { assertEquals(sym010, Symmetry010Chronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_Symmetry010Date_toEpochDay(Symmetry010Date sym010, LocalDate iso) { assertEquals(iso.toEpochDay(), sym010.toEpochDay()); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_Symmetry010Date_until_Symmetry010Date(Symmetry010Date sym010, LocalDate iso) { assertEquals(Symmetry010Chronology.INSTANCE.period(0, 0, 0), sym010.until(sym010)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_Symmetry010Date_until_LocalDate(Symmetry010Date sym010, LocalDate iso) { assertEquals(Symmetry010Chronology.INSTANCE.period(0, 0, 0), sym010.until(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_Chronology_date_Temporal(Symmetry010Date sym010, LocalDate iso) { assertEquals(sym010, Symmetry010Chronology.INSTANCE.date(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_LocalDate_until_Symmetry010Date(Symmetry010Date sym010, LocalDate iso) { assertEquals(Period.ZERO, iso.until(sym010)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_plusDays(Symmetry010Date sym010, LocalDate iso) { assertEquals(iso, LocalDate.from(sym010.plus(0, DAYS))); assertEquals(iso.plusDays(1), LocalDate.from(sym010.plus(1, DAYS))); @@ -204,7 +201,7 @@ public void test_plusDays(Symmetry010Date sym010, LocalDate iso) { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_minusDays(Symmetry010Date sym010, LocalDate iso) { assertEquals(iso, LocalDate.from(sym010.minus(0, DAYS))); assertEquals(iso.minusDays(1), LocalDate.from(sym010.minus(1, DAYS))); @@ -214,7 +211,7 @@ public void test_minusDays(Symmetry010Date sym010, LocalDate iso) { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_until_DAYS(Symmetry010Date sym010, LocalDate iso) { assertEquals(0, sym010.until(iso.plusDays(0), DAYS)); assertEquals(1, sym010.until(iso.plusDays(1), DAYS)); @@ -222,7 +219,6 @@ public void test_until_DAYS(Symmetry010Date sym010, LocalDate iso) { assertEquals(-40, sym010.until(iso.minusDays(40), DAYS)); } - @DataProvider public static Object[][] data_badDates() { return new Object[][] { {-1, 13, 28}, @@ -256,12 +252,11 @@ public static Object[][] data_badDates() { } @ParameterizedTest - @UseDataProvider("data_badDates") + @MethodSource("data_badDates") public void test_badDates(int year, int month, int dom) { assertThrows(DateTimeException.class, () -> Symmetry010Date.of(year, month, dom)); } - @DataProvider public static Object[][] data_badLeapDates() { return new Object[][] { {1}, @@ -272,7 +267,7 @@ public static Object[][] data_badLeapDates() { } @ParameterizedTest - @UseDataProvider("data_badLeapDates") + @MethodSource("data_badLeapDates") public void badLeapDayDates(int year) { assertThrows(DateTimeException.class, () -> Symmetry010Date.of(year, 12, 37)); } @@ -306,7 +301,6 @@ public void test_leapWeek() { //----------------------------------------------------------------------- // Symmetry010Date.lengthOfMonth //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_lengthOfMonth() { return new Object[][] { {2000, 1, 28, 30}, @@ -326,13 +320,13 @@ public static Object[][] data_lengthOfMonth() { } @ParameterizedTest - @UseDataProvider("data_lengthOfMonth") + @MethodSource("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int day, int length) { assertEquals(length, Symmetry010Date.of(year, month, day).lengthOfMonth()); } @ParameterizedTest - @UseDataProvider("data_lengthOfMonth") + @MethodSource("data_lengthOfMonth") public void test_lengthOfMonthFirst(int year, int month, int day, int length) { assertEquals(length, Symmetry010Date.of(year, month, 1).lengthOfMonth()); } @@ -394,7 +388,6 @@ public void test_prolepticYear_specific() { assertEquals(1582, Symmetry010Chronology.INSTANCE.prolepticYear(IsoEra.CE, 1582)); } - @DataProvider public static Object[][] data_prolepticYear_badEra() { return new Era[][] { { AccountingEra.BCE }, @@ -422,7 +415,7 @@ public static Object[][] data_prolepticYear_badEra() { } @ParameterizedTest - @UseDataProvider("data_prolepticYear_badEra") + @MethodSource("data_prolepticYear_badEra") public void test_prolepticYear_badEra(Era era) { assertThrows(ClassCastException.class, () -> Symmetry010Chronology.INSTANCE.prolepticYear(era, 4)); } @@ -469,7 +462,6 @@ public void test_Chronology_range() { //----------------------------------------------------------------------- // Symmetry010Date.range //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_ranges() { return new Object[][] { // Leap Day and Year Day are members of months @@ -516,7 +508,7 @@ public static Object[][] data_ranges() { } @ParameterizedTest - @UseDataProvider("data_ranges") + @MethodSource("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, ValueRange range) { assertEquals(range, Symmetry010Date.of(year, month, dom).range(field)); } @@ -529,7 +521,6 @@ public void test_range_unsupported() { //----------------------------------------------------------------------- // Symmetry010Date.getLong //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_getLong() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 2}, @@ -565,7 +556,7 @@ public static Object[][] data_getLong() { } @ParameterizedTest - @UseDataProvider("data_getLong") + @MethodSource("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(expected, Symmetry010Date.of(year, month, dom).getLong(field)); } @@ -578,7 +569,6 @@ public void test_getLong_unsupported() { //----------------------------------------------------------------------- // Symmetry010Date.with //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_with() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 1, 2014, 5, 20}, @@ -655,14 +645,13 @@ public static Object[][] data_with() { } @ParameterizedTest - @UseDataProvider("data_with") + @MethodSource("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(Symmetry010Date.of(expectedYear, expectedMonth, expectedDom), Symmetry010Date.of(year, month, dom).with(field, value)); } - @DataProvider public static Object[][] data_with_bad() { return new Object[][] { {2013, 1, 1, ALIGNED_DAY_OF_WEEK_IN_MONTH, -1}, @@ -702,7 +691,7 @@ public static Object[][] data_with_bad() { } @ParameterizedTest - @UseDataProvider("data_with_bad") + @MethodSource("data_with_bad") public void test_with_TemporalField_badValue(int year, int month, int dom, TemporalField field, long value) { assertThrows(DateTimeException.class, () -> Symmetry010Date.of(year, month, dom).with(field, value)); } @@ -715,7 +704,6 @@ public void test_with_TemporalField_unsupported() { //----------------------------------------------------------------------- // Symmetry010Date.with(TemporalAdjuster) //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_temporalAdjusters_lastDayOfMonth() { return new Object[][] { {2012, 1, 23, 2012, 1, 30}, @@ -735,7 +723,7 @@ public static Object[][] data_temporalAdjusters_lastDayOfMonth() { } @ParameterizedTest - @UseDataProvider("data_temporalAdjusters_lastDayOfMonth") + @MethodSource("data_temporalAdjusters_lastDayOfMonth") public void test_temporalAdjusters_LastDayOfMonth(int year, int month, int day, int expectedYear, int expectedMonth, int expectedDay) { Symmetry010Date base = Symmetry010Date.of(year, month, day); Symmetry010Date expected = Symmetry010Date.of(expectedYear, expectedMonth, expectedDay); @@ -780,7 +768,6 @@ public void test_LocalDateTime_adjustToSymmetry010Date() { // Symmetry010Date.plus // Symmetry010Date.minus //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_plus() { return new Object[][] { {2014, 5, 26, 0, DAYS, 2014, 5, 26}, @@ -816,7 +803,6 @@ public static Object[][] data_plus() { }; } - @DataProvider public static Object[][] data_plus_leapWeek() { return new Object[][] { {2015, 12, 28, 0, DAYS, 2015, 12, 28}, @@ -837,7 +823,7 @@ public static Object[][] data_plus_leapWeek() { } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { @@ -845,7 +831,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, } @ParameterizedTest - @UseDataProvider("data_plus_leapWeek") + @MethodSource("data_plus_leapWeek") public void test_plus_leapWeek_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { @@ -853,7 +839,7 @@ public void test_plus_leapWeek_TemporalUnit(int year, int month, int dom, } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -862,7 +848,7 @@ public void test_minus_TemporalUnit( } @ParameterizedTest - @UseDataProvider("data_plus_leapWeek") + @MethodSource("data_plus_leapWeek") public void test_minus_leapWeek_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -878,7 +864,6 @@ public void test_plus_TemporalUnit_unsupported() { //----------------------------------------------------------------------- // Symmetry010Date.until //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_until() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, DAYS, 0}, @@ -906,7 +891,6 @@ public static Object[][] data_until() { }; } - @DataProvider public static Object[][] data_until_period() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, 0, 0, 0}, @@ -922,7 +906,7 @@ public static Object[][] data_until_period() { } @ParameterizedTest - @UseDataProvider("data_until") + @MethodSource("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -933,7 +917,7 @@ public void test_until_TemporalUnit( } @ParameterizedTest - @UseDataProvider("data_until_period") + @MethodSource("data_until_period") public void test_until_end( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -979,7 +963,6 @@ public void test_minus_Period_ISO() { //----------------------------------------------------------------------- // Symmetry010Date.equals //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_equals() { return new Object[][] { {Symmetry010Date.of(2000, 1, 3), Symmetry010Date.of(2000, 1, 4), Symmetry010Date.of(2000, 2, 3), Symmetry010Date.of(2001, 1, 3)}, @@ -989,7 +972,7 @@ public static Object[][] data_equals() { } @ParameterizedTest - @UseDataProvider("data_equals") + @MethodSource("data_equals") public void test_equals(Symmetry010Date a1, Symmetry010Date b, Symmetry010Date c, Symmetry010Date d) { assertTrue(a1.equals(a1)); assertFalse(a1.equals(b)); @@ -1003,7 +986,6 @@ public void test_equals(Symmetry010Date a1, Symmetry010Date b, Symmetry010Date c //----------------------------------------------------------------------- // Symmetry010Date.toString //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_toString() { return new Object[][] { {Symmetry010Date.of( 1, 1, 1), "Sym010 CE 1/01/01"}, @@ -1014,7 +996,7 @@ public static Object[][] data_toString() { } @ParameterizedTest - @UseDataProvider("data_toString") + @MethodSource("data_toString") public void test_toString(Symmetry010Date date, String expected) { assertEquals(expected, date.toString()); } diff --git a/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java b/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java index c47c3305..e18d79cd 100644 --- a/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java @@ -83,9 +83,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test. @@ -108,7 +106,6 @@ public void test_chronology() { //----------------------------------------------------------------------- // Symmetry454Date.of //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_samples() { return new Object[][] { { Symmetry454Date.of( 1, 1, 1), LocalDate.of( 1, 1, 1) }, @@ -146,55 +143,55 @@ public static Object[][] data_samples() { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_LocalDate_from_Symmetry454Date(Symmetry454Date sym454, LocalDate iso) { assertEquals(iso, LocalDate.from(sym454)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_Symmetry454Date_from_LocalDate(Symmetry454Date sym454, LocalDate iso) { assertEquals(sym454, Symmetry454Date.from(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_Symmetry454Date_chronology_dateEpochDay(Symmetry454Date sym454, LocalDate iso) { assertEquals(sym454, Symmetry454Chronology.INSTANCE.dateEpochDay(iso.toEpochDay())); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_Symmetry454Date_toEpochDay(Symmetry454Date sym454, LocalDate iso) { assertEquals(iso.toEpochDay(), sym454.toEpochDay()); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_Symmetry454Date_until_Symmetry454Date(Symmetry454Date sym454, LocalDate iso) { assertEquals(Symmetry454Chronology.INSTANCE.period(0, 0, 0), sym454.until(sym454)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_Symmetry454Date_until_LocalDate(Symmetry454Date sym454, LocalDate iso) { assertEquals(Symmetry454Chronology.INSTANCE.period(0, 0, 0), sym454.until(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_Chronology_date_Temporal(Symmetry454Date sym454, LocalDate iso) { assertEquals(sym454, Symmetry454Chronology.INSTANCE.date(iso)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_LocalDate_until_Symmetry454Date(Symmetry454Date sym454, LocalDate iso) { assertEquals(Period.ZERO, iso.until(sym454)); } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_plusDays(Symmetry454Date sym454, LocalDate iso) { assertEquals(iso, LocalDate.from(sym454.plus(0, DAYS))); assertEquals(iso.plusDays(1), LocalDate.from(sym454.plus(1, DAYS))); @@ -204,7 +201,7 @@ public void test_plusDays(Symmetry454Date sym454, LocalDate iso) { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_minusDays(Symmetry454Date sym454, LocalDate iso) { assertEquals(iso, LocalDate.from(sym454.minus(0, DAYS))); assertEquals(iso.minusDays(1), LocalDate.from(sym454.minus(1, DAYS))); @@ -214,7 +211,7 @@ public void test_minusDays(Symmetry454Date sym454, LocalDate iso) { } @ParameterizedTest - @UseDataProvider("data_samples") + @MethodSource("data_samples") public void test_until_DAYS(Symmetry454Date sym454, LocalDate iso) { assertEquals(0, sym454.until(iso.plusDays(0), DAYS)); assertEquals(1, sym454.until(iso.plusDays(1), DAYS)); @@ -222,7 +219,6 @@ public void test_until_DAYS(Symmetry454Date sym454, LocalDate iso) { assertEquals(-40, sym454.until(iso.minusDays(40), DAYS)); } - @DataProvider public static Object[][] data_badDates() { return new Object[][] { {-1, 13, 28}, @@ -256,12 +252,11 @@ public static Object[][] data_badDates() { } @ParameterizedTest - @UseDataProvider("data_badDates") + @MethodSource("data_badDates") public void test_badDates(int year, int month, int dom) { assertThrows(DateTimeException.class, () -> Symmetry454Date.of(year, month, dom)); } - @DataProvider public static Object[][] data_badLeapDates() { return new Object[][] { {1}, @@ -272,7 +267,7 @@ public static Object[][] data_badLeapDates() { } @ParameterizedTest - @UseDataProvider("data_badLeapDates") + @MethodSource("data_badLeapDates") public void test_badLeapDayDates(int year) { assertThrows(DateTimeException.class, () -> Symmetry454Date.of(year, 12, 29)); } @@ -311,7 +306,6 @@ public void test_leapWeek() { //----------------------------------------------------------------------- // Symmetry454Date.lengthOfMonth //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_lengthOfMonth() { return new Object[][] { {2000, 1, 28, 28}, @@ -331,13 +325,13 @@ public static Object[][] data_lengthOfMonth() { } @ParameterizedTest - @UseDataProvider("data_lengthOfMonth") + @MethodSource("data_lengthOfMonth") public void test_lengthOfMonth(int year, int month, int day, int length) { assertEquals(length, Symmetry454Date.of(year, month, day).lengthOfMonth()); } @ParameterizedTest - @UseDataProvider("data_lengthOfMonth") + @MethodSource("data_lengthOfMonth") public void test_lengthOfMonthFirst(int year, int month, int day, int length) { assertEquals(length, Symmetry454Date.of(year, month, 1).lengthOfMonth()); } @@ -400,7 +394,6 @@ public void test_prolepticYear_specific() { assertEquals(1582, Symmetry454Chronology.INSTANCE.prolepticYear(IsoEra.CE, 1582)); } - @DataProvider public static Object[][] data_prolepticYear_badEra() { return new Era[][] { { AccountingEra.BCE }, @@ -428,7 +421,7 @@ public static Object[][] data_prolepticYear_badEra() { } @ParameterizedTest - @UseDataProvider("data_prolepticYear_badEra") + @MethodSource("data_prolepticYear_badEra") public void test_prolepticYear_badEra(Era era) { assertThrows(ClassCastException.class, () -> Symmetry454Chronology.INSTANCE.prolepticYear(era, 4)); } @@ -475,7 +468,6 @@ public void test_Chronology_range() { //----------------------------------------------------------------------- // Symmetry454Date.range //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_ranges() { return new Object[][] { // Leap Day and Year Day are members of months @@ -522,7 +514,7 @@ public static Object[][] data_ranges() { } @ParameterizedTest - @UseDataProvider("data_ranges") + @MethodSource("data_ranges") public void test_range(int year, int month, int dom, TemporalField field, ValueRange range) { assertEquals(range, Symmetry454Date.of(year, month, dom).range(field)); } @@ -535,7 +527,6 @@ public void test_range_unsupported() { //----------------------------------------------------------------------- // Symmetry454Date.getLong //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_getLong() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 5}, @@ -571,7 +562,7 @@ public static Object[][] data_getLong() { } @ParameterizedTest - @UseDataProvider("data_getLong") + @MethodSource("data_getLong") public void test_getLong(int year, int month, int dom, TemporalField field, long expected) { assertEquals(expected, Symmetry454Date.of(year, month, dom).getLong(field)); } @@ -584,7 +575,6 @@ public void test_getLong_unsupported() { //----------------------------------------------------------------------- // Symmetry454Date.with //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_with() { return new Object[][] { {2014, 5, 26, DAY_OF_WEEK, 1, 2014, 5, 22}, @@ -661,14 +651,13 @@ public static Object[][] data_with() { } @ParameterizedTest - @UseDataProvider("data_with") + @MethodSource("data_with") public void test_with_TemporalField(int year, int month, int dom, TemporalField field, long value, int expectedYear, int expectedMonth, int expectedDom) { assertEquals(Symmetry454Date.of(expectedYear, expectedMonth, expectedDom), Symmetry454Date.of(year, month, dom).with(field, value)); } - @DataProvider public static Object[][] data_with_bad() { return new Object[][] { {2013, 1, 1, ALIGNED_DAY_OF_WEEK_IN_MONTH, -1}, @@ -710,7 +699,7 @@ public static Object[][] data_with_bad() { } @ParameterizedTest - @UseDataProvider("data_with_bad") + @MethodSource("data_with_bad") public void test_with_TemporalField_badValue(int year, int month, int dom, TemporalField field, long value) { assertThrows(DateTimeException.class, () -> Symmetry454Date.of(year, month, dom).with(field, value)); } @@ -723,7 +712,6 @@ public void test_with_TemporalField_unsupported() { //----------------------------------------------------------------------- // Symmetry454Date.with(TemporalAdjuster) //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_temporalAdjusters_lastDayOfMonth() { return new Object[][] { {2012, 1, 23, 2012, 1, 28}, @@ -743,7 +731,7 @@ public static Object[][] data_temporalAdjusters_lastDayOfMonth() { } @ParameterizedTest - @UseDataProvider("data_temporalAdjusters_lastDayOfMonth") + @MethodSource("data_temporalAdjusters_lastDayOfMonth") public void test_temporalAdjusters_LastDayOfMonth(int year, int month, int day, int expectedYear, int expectedMonth, int expectedDay) { Symmetry454Date base = Symmetry454Date.of(year, month, day); Symmetry454Date expected = Symmetry454Date.of(expectedYear, expectedMonth, expectedDay); @@ -788,7 +776,6 @@ public void test_LocalDateTime_adjustToSymmetry454Date() { // Symmetry454Date.plus // Symmetry454Date.minus //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_plus() { return new Object[][] { {2014, 5, 26, 0, DAYS, 2014, 5, 26}, @@ -824,7 +811,6 @@ public static Object[][] data_plus() { }; } - @DataProvider public static Object[][] data_plus_leapWeek() { return new Object[][] { {2015, 12, 28, 0, DAYS, 2015, 12, 28}, @@ -845,7 +831,7 @@ public static Object[][] data_plus_leapWeek() { } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_plus_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { @@ -853,7 +839,7 @@ public void test_plus_TemporalUnit(int year, int month, int dom, } @ParameterizedTest - @UseDataProvider("data_plus_leapWeek") + @MethodSource("data_plus_leapWeek") public void test_plus_leapWeek_TemporalUnit(int year, int month, int dom, long amount, TemporalUnit unit, int expectedYear, int expectedMonth, int expectedDom) { @@ -861,7 +847,7 @@ public void test_plus_leapWeek_TemporalUnit(int year, int month, int dom, } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_minus_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -870,7 +856,7 @@ public void test_minus_TemporalUnit( } @ParameterizedTest - @UseDataProvider("data_plus_leapWeek") + @MethodSource("data_plus_leapWeek") public void test_minus_leapWeek_TemporalUnit( int expectedYear, int expectedMonth, int expectedDom, long amount, TemporalUnit unit, @@ -886,7 +872,6 @@ public void test_plus_TemporalUnit_unsupported() { //----------------------------------------------------------------------- // Symmetry454Date.until //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_until() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, DAYS, 0}, @@ -914,7 +899,6 @@ public static Object[][] data_until() { }; } - @DataProvider public static Object[][] data_until_period() { return new Object[][] { {2014, 5, 26, 2014, 5, 26, 0, 0, 0}, @@ -930,7 +914,7 @@ public static Object[][] data_until_period() { } @ParameterizedTest - @UseDataProvider("data_until") + @MethodSource("data_until") public void test_until_TemporalUnit( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -941,7 +925,7 @@ public void test_until_TemporalUnit( } @ParameterizedTest - @UseDataProvider("data_until_period") + @MethodSource("data_until_period") public void test_until_end( int year1, int month1, int dom1, int year2, int month2, int dom2, @@ -987,7 +971,6 @@ public void test_minus_Period_ISO() { //----------------------------------------------------------------------- // Symmetry454Date.equals //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_equals() { return new Object[][] { {Symmetry454Date.of(2000, 1, 3), Symmetry454Date.of(2000, 1, 4), Symmetry454Date.of(2000, 2, 3), Symmetry454Date.of(2001, 1, 3)}, @@ -997,7 +980,7 @@ public static Object[][] data_equals() { } @ParameterizedTest - @UseDataProvider("data_equals") + @MethodSource("data_equals") public void test_equals(Symmetry454Date a1, Symmetry454Date b, Symmetry454Date c, Symmetry454Date d) { assertTrue(a1.equals(a1)); assertFalse(a1.equals(b)); @@ -1011,7 +994,6 @@ public void test_equals(Symmetry454Date a1, Symmetry454Date b, Symmetry454Date c //----------------------------------------------------------------------- // Symmetry454Date.toString //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_toString() { return new Object[][] { {Symmetry454Date.of(1, 1, 1), "Sym454 CE 1/01/01"}, @@ -1022,7 +1004,7 @@ public static Object[][] data_toString() { } @ParameterizedTest - @UseDataProvider("data_toString") + @MethodSource("data_toString") public void test_toString(Symmetry454Date date, String expected) { assertEquals(expected, date.toString()); } diff --git a/src/test/java/org/threeten/extra/scale/TestTaiInstant.java b/src/test/java/org/threeten/extra/scale/TestTaiInstant.java index ae8647da..ec0ea717 100644 --- a/src/test/java/org/threeten/extra/scale/TestTaiInstant.java +++ b/src/test/java/org/threeten/extra/scale/TestTaiInstant.java @@ -47,9 +47,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test TaiInstant. @@ -163,7 +161,6 @@ public void factory_parse_CharSequence() { } } - @DataProvider public static Object[][] data_badParse() { return new Object[][] { {"A.123456789s(TAI)"}, @@ -176,7 +173,7 @@ public static Object[][] data_badParse() { } @ParameterizedTest - @UseDataProvider("data_badParse") + @MethodSource("data_badParse") public void factory_parse_CharSequence_invalid(String str) { assertThrows(DateTimeParseException.class, () -> TaiInstant.parse(str)); } @@ -189,7 +186,6 @@ public void factory_parse_CharSequence_null() { //----------------------------------------------------------------------- // withTAISeconds() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_withTAISeconds() { return new Object[][] { {0L, 12345L, 1L, 1L, 12345L}, @@ -202,7 +198,7 @@ public static Object[][] data_withTAISeconds() { } @ParameterizedTest - @UseDataProvider("data_withTAISeconds") + @MethodSource("data_withTAISeconds") public void test_withTAISeconds(long tai, long nanos, long newTai, Long expectedTai, Long expectedNanos) { TaiInstant i = TaiInstant.ofTaiSeconds(tai, nanos).withTaiSeconds(newTai); assertEquals(expectedTai.longValue(), i.getTaiSeconds()); @@ -212,7 +208,6 @@ public void test_withTAISeconds(long tai, long nanos, long newTai, Long expected //----------------------------------------------------------------------- // withNano() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_withNano() { return new Object[][] { {0L, 12345L, 1, 0L, 1L}, @@ -225,7 +220,7 @@ public static Object[][] data_withNano() { } @ParameterizedTest - @UseDataProvider("data_withNano") + @MethodSource("data_withNano") public void test_withNano(long tai, long nanos, int newNano, Long expectedTai, Long expectedNanos) { TaiInstant i = TaiInstant.ofTaiSeconds(tai, nanos); if (expectedTai != null) { @@ -240,7 +235,6 @@ public void test_withNano(long tai, long nanos, int newNano, Long expectedTai, L //----------------------------------------------------------------------- // plus(Duration) //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_plus() { return new Object[][] { {Long.MIN_VALUE, 0, Long.MAX_VALUE, 0, -1, 0}, @@ -426,7 +420,7 @@ public static Object[][] data_plus() { } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_plus(long seconds, int nanos, long plusSeconds, int plusNanos, long expectedSeconds, int expectedNanoOfSecond) { TaiInstant i = TaiInstant.ofTaiSeconds(seconds, nanos).plus(Duration.ofSeconds(plusSeconds, plusNanos)); assertEquals(expectedSeconds, i.getTaiSeconds()); @@ -448,7 +442,6 @@ public void test_plus_overflowTooSmall() { //----------------------------------------------------------------------- // minus(Duration) //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_minus() { return new Object[][] { {Long.MIN_VALUE, 0, Long.MIN_VALUE + 1, 0, -1, 0}, @@ -634,7 +627,7 @@ public static Object[][] data_minus() { } @ParameterizedTest - @UseDataProvider("data_minus") + @MethodSource("data_minus") public void test_minus(long seconds, int nanos, long minusSeconds, int minusNanos, long expectedSeconds, int expectedNanoOfSecond) { TaiInstant i = TaiInstant.ofTaiSeconds(seconds, nanos).minus(Duration.ofSeconds(minusSeconds, minusNanos)); assertEquals(expectedSeconds, i.getTaiSeconds()); diff --git a/src/test/java/org/threeten/extra/scale/TestUtcInstant.java b/src/test/java/org/threeten/extra/scale/TestUtcInstant.java index a7d72382..67c700bd 100644 --- a/src/test/java/org/threeten/extra/scale/TestUtcInstant.java +++ b/src/test/java/org/threeten/extra/scale/TestUtcInstant.java @@ -47,9 +47,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test UtcInstant. @@ -187,7 +185,6 @@ public void factory_parse_CharSequence() { assertEquals(UtcInstant.ofModifiedJulianDay(MJD_1972_12_31_LEAP, NANOS_PER_DAY), UtcInstant.parse("1972-12-31T23:59:60Z")); } - @DataProvider public static Object[][] data_badParse() { return new Object[][] { {""}, @@ -197,7 +194,7 @@ public static Object[][] data_badParse() { } @ParameterizedTest - @UseDataProvider("data_badParse") + @MethodSource("data_badParse") public void factory_parse_CharSequence_invalid(String str) { assertThrows(DateTimeException.class, () -> UtcInstant.parse(str)); } @@ -215,7 +212,6 @@ public void factory_parse_CharSequence_null() { //----------------------------------------------------------------------- // withModifiedJulianDay() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_withModifiedJulianDay() { return new Object[][] { {0L, 12345L, 1L, 1L, 12345L}, @@ -232,7 +228,7 @@ public static Object[][] data_withModifiedJulianDay() { } @ParameterizedTest - @UseDataProvider("data_withModifiedJulianDay") + @MethodSource("data_withModifiedJulianDay") public void test_withModifiedJulianDay(long mjd, long nanos, long newMjd, Long expectedMjd, Long expectedNanos) { UtcInstant i = UtcInstant.ofModifiedJulianDay(mjd, nanos); if (expectedMjd != null) { @@ -247,7 +243,6 @@ public void test_withModifiedJulianDay(long mjd, long nanos, long newMjd, Long e //----------------------------------------------------------------------- // withNanoOfDay() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_withNanoOfDay() { return new Object[][] { {0L, 12345L, 1L, 0L, 1L}, @@ -270,7 +265,7 @@ public static Object[][] data_withNanoOfDay() { } @ParameterizedTest - @UseDataProvider("data_withNanoOfDay") + @MethodSource("data_withNanoOfDay") public void test_withNanoOfDay(long mjd, long nanos, long newNanoOfDay, Long expectedMjd, Long expectedNanos) { UtcInstant i = UtcInstant.ofModifiedJulianDay(mjd, nanos); if (expectedMjd != null) { @@ -285,7 +280,6 @@ public void test_withNanoOfDay(long mjd, long nanos, long newNanoOfDay, Long exp //----------------------------------------------------------------------- // plus(Duration) //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_plus() { return new Object[][] { {0, 0, -2 * SECS_PER_DAY, 5, -2, 5}, @@ -321,7 +315,7 @@ public static Object[][] data_plus() { } @ParameterizedTest - @UseDataProvider("data_plus") + @MethodSource("data_plus") public void test_plus(long mjd, long nanos, long plusSeconds, int plusNanos, long expectedMjd, long expectedNanos) { UtcInstant i = UtcInstant.ofModifiedJulianDay(mjd, nanos).plus(Duration.ofSeconds(plusSeconds, plusNanos)); assertEquals(expectedMjd, i.getModifiedJulianDay()); @@ -343,7 +337,6 @@ public void test_plus_overflowTooSmall() { //----------------------------------------------------------------------- // minus(Duration) //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_minus() { return new Object[][] { {0, 0, 2 * SECS_PER_DAY, -5, -2, 5}, @@ -379,7 +372,7 @@ public static Object[][] data_minus() { } @ParameterizedTest - @UseDataProvider("data_minus") + @MethodSource("data_minus") public void test_minus(long mjd, long nanos, long minusSeconds, int minusNanos, long expectedMjd, long expectedNanos) { UtcInstant i = UtcInstant.ofModifiedJulianDay(mjd, nanos).minus(Duration.ofSeconds(minusSeconds, minusNanos)); assertEquals(expectedMjd, i.getModifiedJulianDay()); @@ -587,7 +580,6 @@ public void test_hashCode() { //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_toString() { return new Object[][] { {40587, 0, "1970-01-01T00:00:00Z"}, @@ -607,13 +599,13 @@ public static Object[][] data_toString() { } @ParameterizedTest - @UseDataProvider("data_toString") + @MethodSource("data_toString") public void test_toString(long mjd, long nod, String expected) { assertEquals(expected, UtcInstant.ofModifiedJulianDay(mjd, nod).toString()); } @ParameterizedTest - @UseDataProvider("data_toString") + @MethodSource("data_toString") public void test_toString_parse(long mjd, long nod, String str) { assertEquals(UtcInstant.ofModifiedJulianDay(mjd, nod), UtcInstant.parse(str)); } diff --git a/src/test/java/org/threeten/extra/scale/TestUtcRules.java b/src/test/java/org/threeten/extra/scale/TestUtcRules.java index fe84bda8..4eab852e 100644 --- a/src/test/java/org/threeten/extra/scale/TestUtcRules.java +++ b/src/test/java/org/threeten/extra/scale/TestUtcRules.java @@ -53,9 +53,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; - -import com.tngtech.junit.dataprovider.DataProvider; -import com.tngtech.junit.dataprovider.UseDataProvider; +import org.junit.jupiter.params.provider.MethodSource; /** * Test SystemLeapSecondRules. @@ -103,7 +101,6 @@ public void test_getName() { //----------------------------------------------------------------------- // getLeapSecond() //----------------------------------------------------------------------- - @DataProvider public static Object[][] data_leapSeconds() { return new Object[][] { {-1, 0, 10, "1858-11-16"}, @@ -237,7 +234,7 @@ public static Object[][] data_leapSeconds() { } @ParameterizedTest - @UseDataProvider("data_leapSeconds") + @MethodSource("data_leapSeconds") public void test_leapSeconds(long mjd, int adjust, int offset, String checkDate) { assertEquals(LocalDate.parse(checkDate).getLong(JulianFields.MODIFIED_JULIAN_DAY), mjd); From 58c9c6d96ff0eb9028859a45fa07385d5d00c8d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sobkiewicz?= Date: Wed, 15 Jun 2022 12:36:35 +0200 Subject: [PATCH 231/279] Simplify Temporals.durationFromBigDecimalSeconds (#202) * Simplify Temporals.durationFromBigDecimalSeconds * Pull out min and max into constants * Avoid octal integer --- .../java/org/threeten/extra/Temporals.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/threeten/extra/Temporals.java b/src/main/java/org/threeten/extra/Temporals.java index 7edbaadc..0b856bc5 100644 --- a/src/main/java/org/threeten/extra/Temporals.java +++ b/src/main/java/org/threeten/extra/Temporals.java @@ -412,16 +412,9 @@ public static BigDecimal durationToBigDecimalSeconds(Duration duration) { * @return a {@code Duration}, not null */ public static Duration durationFromBigDecimalSeconds(BigDecimal seconds) { - BigInteger nanos = seconds.setScale(9, RoundingMode.UP).movePointRight(9).toBigIntegerExact(); - BigInteger[] divRem = nanos.divideAndRemainder(BigInteger.valueOf(1_000_000_000)); - if (divRem[0].bitLength() > 63) { - if (divRem[0].signum() >= 1) { - return Duration.ofSeconds(Long.MAX_VALUE, 999_999_999); - } else { - return Duration.ofSeconds(Long.MIN_VALUE); - } - } - return Duration.ofSeconds(divRem[0].longValue(), divRem[1].intValue()); + BigInteger nanos = seconds.setScale(9, RoundingMode.UP).max(BigDecimalSeconds.MIN).min(BigDecimalSeconds.MAX).unscaledValue(); + BigInteger[] secondsNanos = nanos.divideAndRemainder(BigInteger.valueOf(1_000_000_000)); + return Duration.ofSeconds(secondsNanos[0].longValue(), secondsNanos[1].intValue()); } /** @@ -474,4 +467,14 @@ public static Duration multiply(Duration duration, double multiplicand) { return durationFromBigDecimalSeconds(amount); } + /** + * Useful Duration constants expressed as BigDecimal seconds with a scale of 9. + */ + private static final class BigDecimalSeconds { + public static final BigDecimal MIN = BigDecimal.valueOf(Long.MIN_VALUE).add(BigDecimal.valueOf(0, 9)); + public static final BigDecimal MAX = BigDecimal.valueOf(Long.MAX_VALUE).add(BigDecimal.valueOf(999_999_999, 9)); + + private BigDecimalSeconds() { + } + } } From 8a52854f8a987cfe4f7ddd673ff9fffc500bf4e0 Mon Sep 17 00:00:00 2001 From: catull Date: Tue, 2 Aug 2022 16:28:17 +0200 Subject: [PATCH 232/279] InternationalFixedEra.CE#getValue returns incorrect value (#205) There is but one era in the InternationalFixed chronology, documented to have the value 1. This PR corrects the incorrect behaviour. Co-authored-by: Carlo Dapor --- .../extra/chrono/InternationalFixedEra.java | 4 ++-- .../TestInternationalFixedChronology.java | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/threeten/extra/chrono/InternationalFixedEra.java b/src/main/java/org/threeten/extra/chrono/InternationalFixedEra.java index b851c056..a8accea1 100644 --- a/src/main/java/org/threeten/extra/chrono/InternationalFixedEra.java +++ b/src/main/java/org/threeten/extra/chrono/InternationalFixedEra.java @@ -37,7 +37,7 @@ /** * An era in the International Fixed calendar system. *

        - * The International Fixed calendar system only has one era. + * The International Fixed calendar system officially only has one era. * The current era, for years from 1 onwards, is known as 'Current Era'. * All previous years are invalid. *

        @@ -85,7 +85,7 @@ public static InternationalFixedEra of(final int era) { */ @Override public int getValue() { - return ordinal(); + return 1; } } diff --git a/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java b/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java index 6559e26a..810abfc5 100644 --- a/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java @@ -367,6 +367,30 @@ public void test_lengthOfMonth_specific() { assertEquals(29, InternationalFixedDate.of(2000, 6, 29).lengthOfMonth()); } + @Test + public void test_era_valid() { + Era era = InternationalFixedChronology.INSTANCE.eraOf(1); + assertNotNull(era); + assertEquals(1, era.getValue()); + } + + //----------------------------------------------------------------------- + // data_invalidEraValues() + //----------------------------------------------------------------------- + public static Object[][] data_invalidEraValues() { + return new Object[][] { + {-1}, + {0}, + {2}, + }; + } + + @ParameterizedTest + @MethodSource("data_invalidEraValues") + public void test_era_invalid(int eraValue) { + assertThrows(DateTimeException.class, () -> InternationalFixedChronology.INSTANCE.eraOf(eraValue)); + } + //----------------------------------------------------------------------- // era, prolepticYear and dateYearDay //----------------------------------------------------------------------- From 9862c9ea5839d7439d150dbd1f727dba5d97bbfe Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 2 Aug 2022 17:16:26 +0100 Subject: [PATCH 233/279] Update dependencies (#207) --- pom.xml | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index e3334968..b9693baa 100644 --- a/pom.xml +++ b/pom.xml @@ -898,37 +898,37 @@ - 5.8.2 + 5.9.0 - 3.1.1 - 5.1.4 + 3.4.2 + 5.1.8 2.12.1 3.1.2 - 3.1.0 - 3.8.0 - 3.0.0-M1 - 3.1.1 - 3.0.0-M2 - 1.6 - 3.0.0-M1 - 3.1.1 - 3.0.1 - 3.0.0 - 3.6.0 - 3.11.0 - 3.0.0 + 3.2.0 + 3.10.1 + 3.0.0 + 3.3.0 + 3.1.0 + 3.0.1 + 3.0.1 + 3.2.2 + 3.4.0 + 3.2.0 + 3.6.4 + 3.17.0 + 3.4.0 2.5.3 2.4 - 3.1.0 - 3.7.1 - 3.0.1 - 3.0.0-M3 - 3.0.0-M3 - 1.1 - 0.8.7 + 3.3.0 + 3.12.0 + 3.2.1 + 3.0.0-M7 + 3.0.0-M7 + 3.1.0 + 0.8.8 1.6.8 - 3.1.11 + 4.7.1.1 1.8 1.8 From 8a1729871fdf601c32f59ef14aaf3c14863480c7 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 2 Aug 2022 17:29:12 +0100 Subject: [PATCH 234/279] Add dependabot (#208) --- .github/dependabot.yml | 10 ++++++++++ .github/workflows/build.yml | 22 ++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..26aa42f9 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +# Dependabot config + +version: 2 +updates: +- package-ecosystem: "maven" + directory: "/" + schedule: + interval: weekly + time: "02:30" + open-pull-requests-limit: 20 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 53ba05ad..c2f7ac4f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,32 +16,30 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - java: [1.8, 11] + java: [8, 11] steps: + - name: Checkout + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b #v3.0.2 + - name: Set up JDK - uses: actions/setup-java@v1 + uses: actions/setup-java@2c7a4878f5d120bd643426d54ae1209b29cc01a3 #v3.4.1 with: java-version: ${{ matrix.java }} - - name: Checkout - uses: actions/checkout@v2 - - name: Maven cache - uses: actions/cache@v1 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ matrix.java }}-${{ hashFiles('**/pom.xml') }}-${{ hashFiles('.github/workflows/build.yml') }} - restore-keys: | - ${{ runner.os }}-maven- + distribution: 'temurin' + cache: 'maven' + - name: Maven version run: | mkdir -p ./.mvn echo '-e -B -DtrimStackTrace=false' > ./.mvn/maven.config mvn --version mkdir -p target + - name: Maven build run: | mvn install site - + - name: Website if: matrix.java == '11' && github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/website') || startsWith(github.ref, 'refs/tags/v')) env: From 5877b7e3a2d6b901c00e9241a9108e7e099c8e0f Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 2 Aug 2022 18:27:39 +0100 Subject: [PATCH 235/279] Update dependencies (#214) --- pom.xml | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index b9693baa..01d76c0b 100644 --- a/pom.xml +++ b/pom.xml @@ -387,7 +387,7 @@ org.kohsuke github-api - 1.301 + ${github-api.version} @@ -455,7 +455,7 @@ org.joda.external reflow-velocity-tools - 1.2 + ${reflow-velocity-tools.version} @@ -494,7 +494,7 @@ org.junit junit-bom - 5.8.2 + ${junit.version} pom import @@ -504,14 +504,14 @@ org.joda joda-convert - 2.2.2 + ${joda-convert.version} compile true com.google.guava guava - 31.0.1-jre + ${guava.version} test @@ -535,7 +535,6 @@ org.junit.jupiter junit-jupiter - ${junit.version} test @@ -859,7 +858,7 @@ de.jutzig github-release-plugin - 1.4.0 + ${github-release-plugin.version} Release v${project.version} See the [change notes](https://www.threeten.org/threeten-extra/changes-report.html) for more information. @@ -897,13 +896,14 @@ - + + 2.2.2 5.9.0 + 31.1-jre 3.4.2 5.1.8 2.12.1 - 3.1.2 3.2.0 3.10.1 @@ -926,8 +926,12 @@ 3.0.0-M7 3.0.0-M7 3.1.0 + + 1.307 + 1.4.0 0.8.8 - 1.6.8 + 1.6.13 + 1.2 4.7.1.1 1.8 From e6c990a731955ba505ced7c91d3e31c4f1a9caf5 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 2 Aug 2022 15:40:43 +0100 Subject: [PATCH 236/279] Prepare for release --- README.md | 4 ++-- src/changes/changes.xml | 15 +++++++++++++++ src/site/markdown/index.md | 4 ++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 37ee5074..98c19bb0 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Various documentation is available: ### Releases -Release 1.7.0 is the current release. +Release 1.7.1 is the current release. This release is considered stable and worthy of the 1.x tag as per [SemVer](https://semver.org/spec/v2.0.0.html). ThreeTen-Extra requires Java SE 8 or later and has no dependencies. @@ -28,7 +28,7 @@ Available in the [Maven Central repository](https://search.maven.org/search?q=g: org.threeten threeten-extra - 1.7.0 + 1.7.1 ``` diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 70059403..f12a0a12 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -6,6 +6,21 @@ + + + + Add utilities to work with durations as numbers. + Fixes #147. + + + Fix YearWeek.isSupported. + Fixes #192. + + + Fix InternationalFixedEra era value. + Fixes #205. + + diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index faf94004..3d0a23f6 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -52,7 +52,7 @@ Various documentation is available: ## Releases -Release 1.7.0 is the current release. +Release 1.7.1 is the current release. This release is considered stable and worthy of the 1.x tag as per [SemVer](https://semver.org/spec/v2.0.0.html). ThreeTen-Extra requires Java SE 8 or later and has no [dependencies](dependencies.html). @@ -63,7 +63,7 @@ Available in [Maven Central](https://search.maven.org/search?q=g:org.threeten%20 org.threeten threeten-extra - 1.7.0 + 1.7.1 ``` From 3dbe255b813755f482f2c6fb4ddf31e1973c2f9e Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 2 Aug 2022 18:34:25 +0100 Subject: [PATCH 237/279] [maven-release-plugin] prepare release v1.7.1 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 01d76c0b..77473541 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.7.1-SNAPSHOT + 1.7.1 Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later https://www.threeten.org/threeten-extra @@ -160,7 +160,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git https://github.com/ThreeTen/threeten-extra - HEAD + v1.7.1 ThreeTen.org From e1f06f4af2d9d5f1cfbd5bd269353a400ede2255 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 2 Aug 2022 18:34:29 +0100 Subject: [PATCH 238/279] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 77473541..ce38f69e 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.7.1 + 1.7.2-SNAPSHOT Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later https://www.threeten.org/threeten-extra @@ -160,7 +160,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git https://github.com/ThreeTen/threeten-extra - v1.7.1 + HEAD ThreeTen.org From c7ef3cb9bce1145913d57016537918860f53963e Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 2 Aug 2022 19:39:39 +0100 Subject: [PATCH 239/279] Fix Javadoc for Java 11 build (#215) --- pom.xml | 4 ++-- src/main/java/org/threeten/extra/scale/TaiInstant.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index ce38f69e..3968c7a8 100644 --- a/pom.xml +++ b/pom.xml @@ -758,7 +758,7 @@ - + org.apache.maven.plugins maven-javadoc-plugin @@ -772,7 +772,7 @@ - --module-path ${project.build.directory}/dependencies + 11 diff --git a/src/main/java/org/threeten/extra/scale/TaiInstant.java b/src/main/java/org/threeten/extra/scale/TaiInstant.java index ec771ecd..125d43d7 100644 --- a/src/main/java/org/threeten/extra/scale/TaiInstant.java +++ b/src/main/java/org/threeten/extra/scale/TaiInstant.java @@ -192,7 +192,7 @@ public static TaiInstant of(UtcInstant instant) { * The seconds part must contain only numbers and a possible leading negative sign. * The nanoseconds part must contain exactly nine digits. * The trailing literal must be exactly specified. - * This format parses the {@link toString} format. + * This format parses the {@link #toString()} format. * * @param text the text to parse such as "12345.123456789s(TAI)", not null * @return the parsed instant, not null @@ -233,7 +233,7 @@ private TaiInstant(long taiSeconds, int nanoOfSecond) { *

        * The TAI second count is a simple incrementing count of seconds where * second 0 is 1958-01-01T00:00:00(TAI). - * The nanosecond part of the second is returned by {@link getNano}. + * The nanosecond part of the second is returned by {@link #getNano()}. * * @return the seconds from the epoch of 1958-01-01T00:00:00(TAI) */ From ce39acae88f960b7a161c44ba178144933061bdb Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 2 Aug 2022 22:36:56 +0100 Subject: [PATCH 240/279] Fix Javadoc for Java 11 --- pom.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pom.xml b/pom.xml index 3968c7a8..48ed58c3 100644 --- a/pom.xml +++ b/pom.xml @@ -807,6 +807,18 @@ + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + 11 + + + + From 5dbe475e59c9561510c438a83b647c13d37ebdf9 Mon Sep 17 00:00:00 2001 From: "Stephen A. Imhoff" Date: Sun, 4 Sep 2022 13:38:20 -0700 Subject: [PATCH 241/279] Add offset for AccountingChronology (#223) * Switch chronology builder to use streamed arguments * Flow offset through. * Pass in chrono as parameter for yearEnding-related tests. * Parameterize chono for data_range tests. * More parameterization/assertAll for tests. * Add start/end style for current behavior * Format file. * Add offset. * Correct pattern test bug. * Add year offset for weeksInMonth for leap-year testing. * Add year starts method to builder. * Add year start to test_range tests. * Change elapsed weeks tests to stream-based. * Switch to passing offset year end function for test. * Add offset year for iso year start/end Co-authored-by: Stephen A. Imhoff --- .../extra/chrono/AccountingChronology.java | 52 +- .../chrono/AccountingChronologyBuilder.java | 60 +- .../chrono/TestAccountingChronology.java | 26 +- .../TestAccountingChronologyBuilder.java | 673 +++++++++--------- 4 files changed, 429 insertions(+), 382 deletions(-) diff --git a/src/main/java/org/threeten/extra/chrono/AccountingChronology.java b/src/main/java/org/threeten/extra/chrono/AccountingChronology.java index d9985772..fafcda3d 100644 --- a/src/main/java/org/threeten/extra/chrono/AccountingChronology.java +++ b/src/main/java/org/threeten/extra/chrono/AccountingChronology.java @@ -113,7 +113,7 @@ public final class AccountingChronology extends AbstractChronology implements Se */ private final DayOfWeek endsOn; /** - * Whether the calendar ends in the last week of a given Gregorian/ISO month, + * Whether the calendar ends in the last week of a given Gregorian/ISO month, * or nearest to the last day of the month (will sometimes be in the next month). */ private final boolean inLastWeek; @@ -129,12 +129,16 @@ public final class AccountingChronology extends AbstractChronology implements Se * The month which will have the leap-week added. */ private final int leapWeekInMonth; + /** + * The year offset. + */ + private final int yearOffset; /** * Difference in days between accounting year end and ISO month end, in ISO year 0. */ private final transient int yearZeroDifference; - /** + /** * Number of weeks in a month range. */ private final transient ValueRange alignedWeekOfMonthRange; @@ -151,7 +155,7 @@ public final class AccountingChronology extends AbstractChronology implements Se /** * Creates an {@code AccountingChronology} validating the input. * Package private as only meant to be called from the builder. - * + * * @param endsOn The day-of-week a given year ends on. * @param end The month-end the year is based on. * @param inLastWeek Whether the year ends in the last week of the month, or nearest the end-of-month. @@ -160,7 +164,8 @@ public final class AccountingChronology extends AbstractChronology implements Se * @return The created Chronology, not null. * @throws DateTimeException if the chronology cannot be built. */ - static AccountingChronology create(DayOfWeek endsOn, Month end, boolean inLastWeek, AccountingYearDivision division, int leapWeekInMonth) { + static AccountingChronology create(DayOfWeek endsOn, Month end, boolean inLastWeek, AccountingYearDivision division, + int leapWeekInMonth, int yearOffset) { if (endsOn == null || end == null || division == null || leapWeekInMonth == 0) { throw new IllegalStateException("AccountingCronology cannot be built: " + (endsOn == null ? "| ending day-of-week |" : "") @@ -175,8 +180,8 @@ static AccountingChronology create(DayOfWeek endsOn, Month end, boolean inLastWe } // Derive cached information. - LocalDate endingLimit = inLastWeek ? LocalDate.of(0, end, 1).with(TemporalAdjusters.lastDayOfMonth()) : - LocalDate.of(0, end, 1).with(TemporalAdjusters.lastDayOfMonth()).plusDays(3); + LocalDate endingLimit = inLastWeek ? LocalDate.of(0 + yearOffset, end, 1).with(TemporalAdjusters.lastDayOfMonth()) : + LocalDate.of(0 + yearOffset, end, 1).with(TemporalAdjusters.lastDayOfMonth()).plusDays(3); LocalDate yearZeroEnd = endingLimit.with(TemporalAdjusters.previousOrSame(endsOn)); int yearZeroDifference = (int) yearZeroEnd.until(endingLimit, ChronoUnit.DAYS); // Longest/shortest month lengths and related @@ -191,13 +196,14 @@ static AccountingChronology create(DayOfWeek endsOn, Month end, boolean inLastWe ValueRange dayOfMonthRange = ValueRange.of(1, shortestMonthLength * 7, longestMonthLength * 7); int daysToEpoch = Math.toIntExact(0 - yearZeroEnd.plusDays(1).toEpochDay()); - return new AccountingChronology(endsOn, end, inLastWeek, division, leapWeekInMonth, yearZeroDifference, alignedWeekOfMonthRange, dayOfMonthRange, daysToEpoch); + return new AccountingChronology(endsOn, end, inLastWeek, division, leapWeekInMonth, yearZeroDifference, + alignedWeekOfMonthRange, dayOfMonthRange, daysToEpoch, yearOffset); } //----------------------------------------------------------------------- /** * Creates an instance from validated data, and cached data. - * + * * @param endsOn The day-of-week a given year ends on. * @param end The month-end the year is based on. * @param inLastWeek Whether the year ends in the last week of the month, or nearest the end-of-month. @@ -209,7 +215,7 @@ static AccountingChronology create(DayOfWeek endsOn, Month end, boolean inLastWe * @param daysToEpoch The number of days between the start of Accounting 1 and ISO 1970. */ private AccountingChronology(DayOfWeek endsOn, Month end, boolean inLastWeek, AccountingYearDivision division, int leapWeekInMonth, int yearZeroDifference, ValueRange alignedWeekOfMonthRange, - ValueRange dayOfMonthRange, int daysToEpoch) { + ValueRange dayOfMonthRange, int daysToEpoch, int yearOffset) { this.endsOn = endsOn; this.end = end; this.inLastWeek = inLastWeek; @@ -219,6 +225,7 @@ private AccountingChronology(DayOfWeek endsOn, Month end, boolean inLastWeek, Ac this.alignedWeekOfMonthRange = alignedWeekOfMonthRange; this.dayOfMonthRange = dayOfMonthRange; this.days0001ToIso1970 = daysToEpoch; + this.yearOffset = yearOffset; } /** @@ -227,7 +234,7 @@ private AccountingChronology(DayOfWeek endsOn, Month end, boolean inLastWeek, Ac * @return a built, validated instance. */ private Object readResolve() { - return AccountingChronology.create(endsOn, end, inLastWeek, getDivision(), leapWeekInMonth); + return AccountingChronology.create(endsOn, end, inLastWeek, getDivision(), leapWeekInMonth, yearOffset); } //----------------------------------------------------------------------- @@ -247,7 +254,7 @@ int getDays0001ToIso1970() { /** * Gets the ID of the chronology - 'Accounting'. *

        - * The ID uniquely identifies the {@code Chronology}, + * The ID uniquely identifies the {@code Chronology}, * but does not differentiate between instances of {@code AccountingChronology}. * It cannot be used to lookup the {@code Chronology} using {@link Chronology#of(String)}, * because each instance requires setup. @@ -265,7 +272,7 @@ public String getId() { *

        * The Unicode Locale Data Markup Language (LDML) specification * does not define an identifier for 52/53 week calendars used for accounting purposes, - * and given that setup required is unlikely to do so. + * and given that setup required is unlikely to do so. * For this reason, the calendar type is null. * * @return null, as the calendar is unlikely to be specified in LDML @@ -460,7 +467,7 @@ public ChronoZonedDateTime zonedDateTime(Instant instant, ZoneId /** * Checks if the specified year is a leap year. *

        - * An Accounting proleptic-year is leap if the time between the end of the previous year + * An Accounting proleptic-year is leap if the time between the end of the previous year * and the end of the current year is 371 days. * This method does not validate the year passed in, and only has a * well-defined result for years in the supported range. @@ -478,26 +485,26 @@ public boolean isLeapYear(long prolepticYear) { * Return the number of ISO Leap Years since Accounting Year 1. *

        * This method calculates how many ISO leap years have passed since year 1. - * The count returned will be negative for years before 1. + * The count returned may be negative for years before 1. * This method does not validate the year passed in, and only has a * well-defined result for years in the supported range. - * + * * @param prolepticYear the proleptic-year to check, not validated for range * @return the count of leap years since year 1. */ private long getISOLeapYearCount(long prolepticYear) { - long offsetYear = prolepticYear - (end == Month.JANUARY ? 1 : 0) - 1; - return Math.floorDiv(offsetYear, 4) - Math.floorDiv(offsetYear, 100) + Math.floorDiv(offsetYear, 400) + (end == Month.JANUARY ? 1 : 0); + long offsetYear = prolepticYear - (end == Month.JANUARY? 1 : 0) - 1 + yearOffset; + return Math.floorDiv(offsetYear, 4) - Math.floorDiv(offsetYear, 100) + Math.floorDiv(offsetYear, 400) + (end == Month.JANUARY && yearOffset == 0 ? 1 : 0); } /** * Returns the count of leap years since year 1. *

        * This method calculates how many Accounting leap years have passed since year 1. - * The count returned will be negative for years before 1. + * The count returned may be negative for years before 1. * This method does not validate the year passed in, and only has a * well-defined result for years in the supported range. - * + * * @param prolepticYear the proleptic-year to check, not validated for range * @return the count of leap years since year 1. */ @@ -557,7 +564,8 @@ public boolean equals(Object obj) { this.inLastWeek == other.inLastWeek && this.end == other.end && this.getDivision() == other.getDivision() && - this.leapWeekInMonth == other.leapWeekInMonth; + this.leapWeekInMonth == other.leapWeekInMonth && + this.yearOffset == other.yearOffset; } return false; } @@ -571,6 +579,7 @@ public int hashCode() { result = prime * result + end.hashCode(); result = prime * result + leapWeekInMonth; result = prime * result + getDivision().hashCode(); + result = prime * result + yearOffset; return result; } @@ -585,7 +594,8 @@ public String toString() { .append(", year divided in ") .append(getDivision()) .append(" with leap-week in month ") - .append(leapWeekInMonth); + .append(leapWeekInMonth) + .append(yearOffset == 0 ? " ending in the given ISO year" : " starting in the given ISO year"); return bld.toString(); } diff --git a/src/main/java/org/threeten/extra/chrono/AccountingChronologyBuilder.java b/src/main/java/org/threeten/extra/chrono/AccountingChronologyBuilder.java index 9016e8de..28ecd608 100644 --- a/src/main/java/org/threeten/extra/chrono/AccountingChronologyBuilder.java +++ b/src/main/java/org/threeten/extra/chrono/AccountingChronologyBuilder.java @@ -45,13 +45,15 @@ *

      • last-in-month vs. nearest-end-of-month - Whether the ending day-of-week is the last in the month, * or the nearest to the end of the month (will sometimes be in the next month. *
      • month end - Which Gregorian/ISO end-of-month the year ends in/is nearest to. - *
      • year division - How many 'months' (periods) to divide the accounting year into, + *
      • year division - How many 'months' (periods) to divide the accounting year into, * and how many weeks are in each. - *
      • leap-week month - Which month will have the leap 'week' added to it. + *
      • leap-week month - Which month will have the leap 'week' added to it. * In practice this is probably the last one, but this does not seem to be required. + *
      • year start/end offset - Whether the fiscal year starts or ends in the similarly numbered ISO year. + * If nearest-end-of-month is set and the ending month is December, the effective offset will shift over time. *
      *

      - * There are approximately 7 x 2 x 12 x 4 x 12/13 = 4032 combinations. + * There are approximately 7 x 2 x 12 x 4 x 12/13 x 2 = 8064 combinations. * *

      Implementation Requirements

      * This class is a mutable builder suitable for use from a single thread. @@ -63,7 +65,7 @@ public final class AccountingChronologyBuilder { */ private DayOfWeek endsOn; /** - * Whether the calendar ends in the last week of a given Gregorian/ISO month, + * Whether the calendar ends in the last week of a given Gregorian/ISO month, * or nearest to the last day of the month (will sometimes be in the next month). */ private boolean inLastWeek; @@ -80,6 +82,11 @@ public final class AccountingChronologyBuilder { */ private int leapWeekInMonth; + /** + * The offset to apply to the year. + */ + private int yearOffset; + /** * Constructs a new instance of the builder. */ @@ -89,9 +96,9 @@ public AccountingChronologyBuilder() { /** * Sets the day-of-week on which a given Accounting calendar year ends. - * + * * @param endsOn The day-of-week on which a given Accounting calendar year ends. - * + * * @return this, for chaining, not null. */ public AccountingChronologyBuilder endsOn(DayOfWeek endsOn) { @@ -103,9 +110,9 @@ public AccountingChronologyBuilder endsOn(DayOfWeek endsOn) { * Sets the Gregorian/ISO month-end which a given Accounting calendar year ends nearest to. * Calendars setup this way will occasionally end in the start of the next month. * For example, for July, the month ends on any day from July 28th to August 3rd. - * + * * @param end The Gregorian/ISO month-end a given Accounting calendar year ends nearest to. - * + * * @return this, for chaining, not null. */ public AccountingChronologyBuilder nearestEndOf(Month end) { @@ -118,9 +125,9 @@ public AccountingChronologyBuilder nearestEndOf(Month end) { * Sets the Gregorian/ISO month-end in which a given Accounting calendar year ends. * Calendars setup this way will always end in the last week of the given month. * For example, for July, the month ends on any day from July 25th to July 31st. - * + * * @param end The Gregorian/ISO month-end a given Accounting calendar year ends in the last week of. - * + * * @return this, for chaining, not null. */ public AccountingChronologyBuilder inLastWeekOf(Month end) { @@ -131,9 +138,9 @@ public AccountingChronologyBuilder inLastWeekOf(Month end) { /** * Sets how a given Accounting year will be divided. - * + * * @param division How to divide a given calendar year. - * + * * @return this, for chaining, not null. */ public AccountingChronologyBuilder withDivision(AccountingYearDivision division) { @@ -143,9 +150,9 @@ public AccountingChronologyBuilder withDivision(AccountingYearDivision division) /** * Sets the month in which the leap-week occurs. - * + * * @param leapWeekInMonth The month in which the leap-week occurs. - * + * * @return this, for chaining, not null. */ public AccountingChronologyBuilder leapWeekInMonth(int leapWeekInMonth) { @@ -153,14 +160,35 @@ public AccountingChronologyBuilder leapWeekInMonth(int leapWeekInMonth) { return this; } + /** + * Sets the proleptic accounting year to end in the matching Iso year. + * + * @return this, for chaining, not null. + */ + public AccountingChronologyBuilder accountingYearEndsInIsoYear() { + this.yearOffset = 0; + return this; + } + + + /** + * Sets the proleptic accounting year to start in the matching Iso year. + * + * @return this, for chaining, not null. + */ + public AccountingChronologyBuilder accountingYearStartsInIsoYear() { + this.yearOffset = 1; + return this; + } + /** * Completes this builder by creating the {@code AccountingChronology}. - * + * * @return the created chronology, not null. * @throws DateTimeException if the chronology cannot be built. */ public AccountingChronology toChronology() { - return AccountingChronology.create(endsOn, end, inLastWeek, division, leapWeekInMonth); + return AccountingChronology.create(endsOn, end, inLastWeek, division, leapWeekInMonth, yearOffset); } } diff --git a/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java b/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java index 8254a2db..0ccec2ef 100644 --- a/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java @@ -755,6 +755,7 @@ public void test_equals() { AccountingDate other = new AccountingChronologyBuilder().endsOn(DayOfWeek.WEDNESDAY) .nearestEndOf(Month.AUGUST).leapWeekInMonth(13) .withDivision(AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS) + .accountingYearEndsInIsoYear() .toChronology().date(2000, 1, 3); assertEquals(true, a1.equals(a1)); @@ -769,15 +770,36 @@ public void test_equals() { assertEquals(false, a1.equals(other)); assertTrue(a1.hashCode() == a1.hashCode()); + + AccountingDate startChronologyDate = new AccountingChronologyBuilder().endsOn(DayOfWeek.WEDNESDAY) + .nearestEndOf(Month.AUGUST).leapWeekInMonth(13) + .withDivision(AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS) + .accountingYearStartsInIsoYear() + .toChronology().date(2000, 1, 3); + + + assertEquals(false, a1.getChronology().equals(startChronologyDate.getChronology())); + assertEquals(false, a1.equals(startChronologyDate)); + assertEquals(false, other.getChronology().equals(startChronologyDate.getChronology())); + assertEquals(false, other.equals(startChronologyDate)); } //----------------------------------------------------------------------- // toString() //----------------------------------------------------------------------- public static Object[][] data_toString() { + AccountingChronology other = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST). + withDivision(AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS).leapWeekInMonth(13).accountingYearStartsInIsoYear().toChronology(); + return new Object[][] { - {INSTANCE.date(1, 1, 1), "Accounting calendar ends on SUNDAY nearest end of AUGUST, year divided in THIRTEEN_EVEN_MONTHS_OF_4_WEEKS with leap-week in month 13 CE 1-01-01"}, - {INSTANCE.date(2012, 6, 23), "Accounting calendar ends on SUNDAY nearest end of AUGUST, year divided in THIRTEEN_EVEN_MONTHS_OF_4_WEEKS with leap-week in month 13 CE 2012-06-23"}, + { INSTANCE.date(1, 1, 1), + "Accounting calendar ends on SUNDAY nearest end of AUGUST, year divided in THIRTEEN_EVEN_MONTHS_OF_4_WEEKS with leap-week in month 13 ending in the given ISO year CE 1-01-01" }, + { INSTANCE.date(2012, 6, 23), + "Accounting calendar ends on SUNDAY nearest end of AUGUST, year divided in THIRTEEN_EVEN_MONTHS_OF_4_WEEKS with leap-week in month 13 ending in the given ISO year CE 2012-06-23" }, + { other.date(1, 1, 1), + "Accounting calendar ends on SUNDAY nearest end of AUGUST, year divided in THIRTEEN_EVEN_MONTHS_OF_4_WEEKS with leap-week in month 13 starting in the given ISO year CE 1-01-01" }, + { other.date(2012, 6, 23), + "Accounting calendar ends on SUNDAY nearest end of AUGUST, year divided in THIRTEEN_EVEN_MONTHS_OF_4_WEEKS with leap-week in month 13 starting in the given ISO year CE 2012-06-23" }, }; } diff --git a/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java b/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java index 4d381f79..ffe08ce9 100644 --- a/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java +++ b/src/test/java/org/threeten/extra/chrono/TestAccountingChronologyBuilder.java @@ -32,8 +32,10 @@ package org.threeten.extra.chrono; import static java.time.temporal.ChronoUnit.DAYS; +import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.params.provider.Arguments.arguments; import java.time.DateTimeException; import java.time.DayOfWeek; @@ -42,437 +44,422 @@ import java.time.temporal.ChronoField; import java.time.temporal.TemporalAdjusters; import java.time.temporal.ValueRange; +import java.util.Arrays; +import java.util.function.BiFunction; +import java.util.function.IntBinaryOperator; import java.util.function.IntFunction; import java.util.function.IntPredicate; +import java.util.function.UnaryOperator; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.collect.Lists; +import com.google.common.collect.Streams; + /** * Test. */ public class TestAccountingChronologyBuilder { - - //----------------------------------------------------------------------- - // isLeapYear(), date(int, int, int) - //----------------------------------------------------------------------- - public static Object[][] data_yearEnding() { - return new Object[][] { - {DayOfWeek.MONDAY, Month.JANUARY}, - {DayOfWeek.TUESDAY, Month.MARCH}, - {DayOfWeek.WEDNESDAY, Month.APRIL}, - {DayOfWeek.THURSDAY, Month.MAY}, - {DayOfWeek.FRIDAY, Month.JUNE}, - {DayOfWeek.SATURDAY, Month.JULY}, - {DayOfWeek.SUNDAY, Month.AUGUST}, - {DayOfWeek.MONDAY, Month.SEPTEMBER}, - {DayOfWeek.TUESDAY, Month.OCTOBER}, - {DayOfWeek.WEDNESDAY, Month.NOVEMBER}, - {DayOfWeek.THURSDAY, Month.DECEMBER}, - - {DayOfWeek.MONDAY, Month.FEBRUARY}, - {DayOfWeek.TUESDAY, Month.FEBRUARY}, - {DayOfWeek.WEDNESDAY, Month.FEBRUARY}, - {DayOfWeek.THURSDAY, Month.FEBRUARY}, - {DayOfWeek.FRIDAY, Month.FEBRUARY}, - {DayOfWeek.SATURDAY, Month.FEBRUARY}, - {DayOfWeek.SUNDAY, Month.FEBRUARY}, - }; + @FunctionalInterface + private interface GetYearEnd { + LocalDate apply(int year, Month ending, DayOfWeek dayOfWeek); } - @ParameterizedTest - @MethodSource("data_yearEnding") - public void test_isLeapYear_inLastWeekOf(DayOfWeek dayOfWeek, Month ending) { - AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) - .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) - .toChronology(); - - IntFunction getYearEnd = year -> { - return LocalDate.of(year, ending, 1).with(TemporalAdjusters.lastDayOfMonth()).with(TemporalAdjusters.previousOrSame(dayOfWeek)); - }; - IntPredicate isLeapYear = year -> { - LocalDate currentYearEnd = getYearEnd.apply(year); - LocalDate prevYearEnd = getYearEnd.apply(year - 1); - return prevYearEnd.until(currentYearEnd, DAYS) == 371; - }; - - for (int year = -200; year < 600; year++) { - assertEquals(isLeapYear.test(year), chronology.isLeapYear(year)); - } + // ----------------------------------------------------------------------- + // isLeapYear(), date(int, int, int) + // ----------------------------------------------------------------------- + public static Stream data_yearEnding() { + return Lists.cartesianProduct( + Lists.newArrayList(DayOfWeek.values()), + Lists.newArrayList(Month.values()), + Lists.newArrayList(new Object[] { + (BiFunction) AccountingChronologyBuilder::inLastWeekOf, + (GetYearEnd) ((year, ending, dayOfWeek) -> LocalDate.of(year, ending, 1) + .with(TemporalAdjusters.lastDayOfMonth()) + .with(TemporalAdjusters.previousOrSame(dayOfWeek))) + }, new Object[] { + (BiFunction) AccountingChronologyBuilder::nearestEndOf, + (GetYearEnd) ((year, ending, dayOfWeek) -> LocalDate.of(year, ending, 3).plusMonths(1) + .with(TemporalAdjusters.previousOrSame(dayOfWeek))) + }), + Lists.newArrayList( + (Object) new Object[] { (UnaryOperator) AccountingChronologyBuilder::accountingYearEndsInIsoYear, 0}, + (Object) new Object[] { (UnaryOperator) AccountingChronologyBuilder::accountingYearStartsInIsoYear, 1} + )) + .stream().map( + (args) -> { + DayOfWeek dayOfWeek = (DayOfWeek) args.get(0); + Month ending = (Month) args.get(1); + BiFunction endingType = + (BiFunction) ((Object[]) args.get(2))[0]; + GetYearEnd getYearEnd = (GetYearEnd) ((Object[]) args.get(2))[1]; + UnaryOperator startOrEnd = (UnaryOperator) ((Object[]) args.get(3))[0]; + int offset = (int) ((Object[]) args.get(3))[1]; + + AccountingChronology chrono = endingType.andThen(startOrEnd).apply(new AccountingChronologyBuilder(), ending) + .endsOn(dayOfWeek) + .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS) + .leapWeekInMonth(12) + .toChronology(); + + IntFunction offsetYearEnd = (int year) -> getYearEnd.apply(year + offset, ending, dayOfWeek); + + IntPredicate isLeapYear = year -> { + LocalDate currentYearEnd = offsetYearEnd.apply(year); + LocalDate prevYearEnd = offsetYearEnd.apply(year - 1); + return prevYearEnd.until(currentYearEnd, DAYS) == 371; + }; + + return arguments(chrono, offsetYearEnd, isLeapYear); + + }); } @ParameterizedTest @MethodSource("data_yearEnding") - public void test_isLeapYear_nearestEndOf(DayOfWeek dayOfWeek, Month ending) { - AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) - .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) - .toChronology(); - - IntFunction getYearEnd = year -> { - return LocalDate.of(year, ending, 3).plusMonths(1).with(TemporalAdjusters.previousOrSame(dayOfWeek)); - }; - IntPredicate isLeapYear = year -> { - LocalDate currentYearEnd = getYearEnd.apply(year); - LocalDate prevYearEnd = getYearEnd.apply(year - 1); - return prevYearEnd.until(currentYearEnd, DAYS) == 371; - }; - - for (int year = -200; year < 600; year++) { - assertEquals(isLeapYear.test(year), chronology.isLeapYear(year)); - } + public void test_isLeapYear(AccountingChronology chronology, IntFunction _getYearEnd, IntPredicate isLeapYear) { + assertAll(IntStream.range(-200, 600).mapToObj( + year -> () -> assertEquals(isLeapYear.test(year), chronology.isLeapYear(year), + () -> String.format("for year %d ", year)))); } @ParameterizedTest @MethodSource("data_yearEnding") - public void test_previousLeapYears_inLastWeekOf(DayOfWeek dayOfWeek, Month ending) { - AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) - .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) - .toChronology(); - - IntFunction getYearEnd = year -> { - return LocalDate.of(year, ending, 1).with(TemporalAdjusters.lastDayOfMonth()).with(TemporalAdjusters.previousOrSame(dayOfWeek)); - }; - IntPredicate isLeapYear = year -> { - LocalDate currentYearEnd = getYearEnd.apply(year); - LocalDate prevYearEnd = getYearEnd.apply(year - 1); - return prevYearEnd.until(currentYearEnd, DAYS) == 371; - }; - + public void test_previousLeapYears(AccountingChronology chronology, IntFunction _getYearEnd, IntPredicate isLeapYear) { for (int year = 1, leapYears = 0; year < 600; year++) { if (year != 1 && isLeapYear.test(year - 1)) { leapYears++; } - assertEquals(leapYears, chronology.previousLeapYears(year)); + final int loopYear = year; + assertEquals(leapYears, chronology.previousLeapYears(year), () -> String.format("for year %d ", loopYear)); } for (int year = 1, leapYears = 0; year >= -200; year--) { if (year != 1 && isLeapYear.test(year)) { leapYears--; } - assertEquals(leapYears, chronology.previousLeapYears(year)); - } - } - - @ParameterizedTest - @MethodSource("data_yearEnding") - public void test_previousLeapYears_nearestEndOf(DayOfWeek dayOfWeek, Month ending) { - AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) - .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) - .toChronology(); - - IntFunction getYearEnd = year -> { - return LocalDate.of(year, ending, 3).plusMonths(1).with(TemporalAdjusters.previousOrSame(dayOfWeek)); - }; - IntPredicate isLeapYear = year -> { - LocalDate currentYearEnd = getYearEnd.apply(year); - LocalDate prevYearEnd = getYearEnd.apply(year - 1); - return prevYearEnd.until(currentYearEnd, DAYS) == 371; - }; - - for (int year = 1, leapYears = 0; year < 600; year++) { - if (year != 1 && isLeapYear.test(year - 1)) { - leapYears++; - } - assertEquals(leapYears, chronology.previousLeapYears(year)); - } - for (int year = 1, leapYears = 0; year >= -200; year--) { - if (year != 1 && isLeapYear.test(year)) { - leapYears--; - } - assertEquals(leapYears, chronology.previousLeapYears(year)); - } - } - - @ParameterizedTest - @MethodSource("data_yearEnding") - public void test_date_int_int_int_inLastWeekOf(DayOfWeek dayOfWeek, Month ending) { - AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) - .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) - .toChronology(); - - IntFunction getYearEnd = year -> { - return LocalDate.of(year, ending, 1).with(TemporalAdjusters.lastDayOfMonth()).with(TemporalAdjusters.previousOrSame(dayOfWeek)); - }; - - for (int year = -200; year < 600; year++) { - assertEquals(getYearEnd.apply(year - 1).plusDays(1).toEpochDay(), chronology.date(year, 1, 1).toEpochDay()); + final int loopYear = year; + assertEquals(leapYears, chronology.previousLeapYears(year), () -> String.format("for year %d ", loopYear)); } } @ParameterizedTest @MethodSource("data_yearEnding") - public void test_date_int_int_int_nearestEndOf(DayOfWeek dayOfWeek, Month ending) { - AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) - .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) - .toChronology(); - - IntFunction getYearEnd = year -> { - return LocalDate.of(year, ending, 3).plusMonths(1).with(TemporalAdjusters.previousOrSame(dayOfWeek)); - }; - - for (int year = -200; year < 600; year++) { - assertEquals(getYearEnd.apply(year - 1).plusDays(1).toEpochDay(), chronology.date(year, 1, 1).toEpochDay()); - } + public void test_date_int_int_int(AccountingChronology chronology, IntFunction getYearEnd, IntPredicate isLeapYear) { + assertAll(IntStream.range(-200, 600).mapToObj( + year -> () -> assertEquals(getYearEnd.apply(year - 1).plusDays(1).toEpochDay(), + chronology.date(year, 1, 1).toEpochDay(), + () -> String.format("for year %d ", year)))); } - //----------------------------------------------------------------------- + // ----------------------------------------------------------------------- // range(MONTH_OF_YEAR), range(DAY_OF_MONTH) - //----------------------------------------------------------------------- - public static Object[][] data_range() { - return new Object[][] { - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, 1, - ValueRange.of(1, 4, 5), ValueRange.of(1, 28, 35), ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11)}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, 2, - ValueRange.of(1, 4, 5), ValueRange.of(1, 28, 35), ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11)}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, 3, - ValueRange.of(1, 4, 6), ValueRange.of(1, 28, 42), ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11)}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, 4, - ValueRange.of(1, 4, 5), ValueRange.of(1, 28, 35), ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11)}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, 5, - ValueRange.of(1, 4, 5), ValueRange.of(1, 28, 35), ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11)}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, 6, - ValueRange.of(1, 4, 6), ValueRange.of(1, 28, 42), ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11)}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, 7, - ValueRange.of(1, 4, 5), ValueRange.of(1, 28, 35), ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11)}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, 8, - ValueRange.of(1, 4, 5), ValueRange.of(1, 28, 35), ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11)}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, 9, - ValueRange.of(1, 4, 6), ValueRange.of(1, 28, 42), ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11)}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, 10, - ValueRange.of(1, 4, 5), ValueRange.of(1, 28, 35), ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11)}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, 11, - ValueRange.of(1, 4, 5), ValueRange.of(1, 28, 35), ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11)}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, 12, - ValueRange.of(1, 4, 6), ValueRange.of(1, 28, 42), ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11)}, - - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_5_4_WEEKS, 1, - ValueRange.of(1, 4, 5), ValueRange.of(1, 28, 35), ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11)}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_5_4_WEEKS, 2, - ValueRange.of(1, 4, 6), ValueRange.of(1, 28, 42), ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11)}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_5_4_WEEKS, 3, - ValueRange.of(1, 4, 5), ValueRange.of(1, 28, 35), ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11)}, - - {AccountingYearDivision.QUARTERS_OF_PATTERN_5_4_4_WEEKS, 1, - ValueRange.of(1, 4, 6), ValueRange.of(1, 28, 42), ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11)}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_5_4_4_WEEKS, 2, - ValueRange.of(1, 4, 5), ValueRange.of(1, 28, 35), ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11)}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_5_4_4_WEEKS, 3, - ValueRange.of(1, 4, 5), ValueRange.of(1, 28, 35), ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11)}, - - {AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS, 1, - ValueRange.of(1, 4, 5), ValueRange.of(1, 28, 35), ValueRange.of(1, 13), ValueRange.of(-999_999 * 13L, 999_999 * 13L + 12)}, - }; + // ----------------------------------------------------------------------- + public static Stream data_range() { + IntBinaryOperator weeksInMonth = (leapWeekInMonth, offset) -> (leapWeekInMonth + offset) % 3 == 0 ? 6 : 5; + + Stream pattern_4_4_5 = IntStream.range(1, 13) + .mapToObj((leapWeekInMonth) -> new Object[] { + AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, + leapWeekInMonth, + ValueRange.of(1, 4, weeksInMonth.applyAsInt(leapWeekInMonth, 0)), + ValueRange.of(1, 7 * 4, 7 * weeksInMonth.applyAsInt(leapWeekInMonth, 0)), + ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11) }); + + Stream pattern_4_5_4 = IntStream.range(1, 13) + .mapToObj((leapWeekInMonth) -> new Object[] { + AccountingYearDivision.QUARTERS_OF_PATTERN_4_5_4_WEEKS, + leapWeekInMonth, + ValueRange.of(1, 4, weeksInMonth.applyAsInt(leapWeekInMonth, 1)), + ValueRange.of(1, 7 * 4, 7 * weeksInMonth.applyAsInt(leapWeekInMonth, 1)), + ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11) }); + + Stream pattern_5_4_4 = IntStream.range(1, 13) + .mapToObj((leapWeekInMonth) -> new Object[] { + AccountingYearDivision.QUARTERS_OF_PATTERN_5_4_4_WEEKS, + leapWeekInMonth, + ValueRange.of(1, 4, weeksInMonth.applyAsInt(leapWeekInMonth, 2)), + ValueRange.of(1, 7 * 4, 7 * weeksInMonth.applyAsInt(leapWeekInMonth, 2)), + ValueRange.of(1, 12), ValueRange.of(-999_999 * 12L, 999_999 * 12L + 11) }); + + Stream pattern_even_13 = IntStream.range(1, 14) + .mapToObj((leapWeekInMonth) -> new Object[] { + AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS, + leapWeekInMonth, + ValueRange.of(1, 4, 5), + ValueRange.of(1, 7 * 4, 7 * 5), + ValueRange.of(1, 13), ValueRange.of(-999_999 * 13L, 999_999 * 13L + 12) }); + + return Lists.cartesianProduct( + Streams.concat(pattern_4_4_5, pattern_4_5_4, pattern_5_4_4, pattern_even_13) + .collect(Collectors.toList()), + Lists.newArrayList( + (UnaryOperator) AccountingChronologyBuilder::accountingYearEndsInIsoYear, + (UnaryOperator) AccountingChronologyBuilder::accountingYearStartsInIsoYear + )) + .stream().map(args -> { + AccountingYearDivision division = (AccountingYearDivision) ((Object[]) args.get(0))[0]; + int leapWeekInMonth = (int) ((Object[]) args.get(0))[1]; + ValueRange expectedWeekOfMonthRange = (ValueRange) ((Object[]) args.get(0))[2]; + ValueRange expectedDayOfMonthRange = (ValueRange) ((Object[]) args.get(0))[3]; + ValueRange expectedMonthRange = (ValueRange) ((Object[]) args.get(0))[4]; + ValueRange expectedProlepticMonthRange = (ValueRange) ((Object[]) args.get(0))[5]; + UnaryOperator startOrEnd = (UnaryOperator) args.get(1); + + AccountingChronologyBuilder builder = startOrEnd.apply(new AccountingChronologyBuilder()) + .nearestEndOf(Month.AUGUST).endsOn(DayOfWeek.SUNDAY) + .withDivision(division).leapWeekInMonth(leapWeekInMonth); + + return arguments(builder.toChronology(), expectedWeekOfMonthRange, expectedDayOfMonthRange, + expectedMonthRange, expectedProlepticMonthRange); + }); } @ParameterizedTest @MethodSource("data_range") - public void test_range(AccountingYearDivision division, int leapWeekInMonth, - ValueRange expectedWeekOfMonthRange, ValueRange expectedDayOfMonthRange, ValueRange expectedMonthRange, ValueRange expectedProlepticMonthRange) { - AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST) - .withDivision(division).leapWeekInMonth(leapWeekInMonth) - .toChronology(); - - assertEquals(expectedWeekOfMonthRange, chronology.range(ChronoField.ALIGNED_WEEK_OF_MONTH)); - assertEquals(expectedDayOfMonthRange, chronology.range(ChronoField.DAY_OF_MONTH)); - assertEquals(ValueRange.of(1, 364, 371), chronology.range(ChronoField.DAY_OF_YEAR)); - assertEquals(expectedMonthRange, chronology.range(ChronoField.MONTH_OF_YEAR)); - assertEquals(expectedProlepticMonthRange, chronology.range(ChronoField.PROLEPTIC_MONTH)); + public void test_range(AccountingChronology chronology, ValueRange expectedWeekOfMonthRange, + ValueRange expectedDayOfMonthRange, ValueRange expectedMonthRange, ValueRange expectedProlepticMonthRange) { + assertAll( + () -> assertEquals(expectedWeekOfMonthRange, chronology.range(ChronoField.ALIGNED_WEEK_OF_MONTH)), + () -> assertEquals(expectedDayOfMonthRange, chronology.range(ChronoField.DAY_OF_MONTH)), + () -> assertEquals(ValueRange.of(1, 364, 371), chronology.range(ChronoField.DAY_OF_YEAR)), + () -> assertEquals(expectedMonthRange, chronology.range(ChronoField.MONTH_OF_YEAR)), + () -> assertEquals(expectedProlepticMonthRange, chronology.range(ChronoField.PROLEPTIC_MONTH))); } @ParameterizedTest @MethodSource("data_weeksInMonth") - public void test_date_dayOfMonth_range(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { - AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST) - .withDivision(division).leapWeekInMonth(leapWeekInMonth) - .toChronology(); - - for (int month = 1; month <= weeksInMonth.length; month++) { - assertEquals(ValueRange.of(1, weeksInMonth[month - 1] * 7), AccountingDate.of(chronology, 2011, month, 15).range(ChronoField.DAY_OF_MONTH)); - assertEquals(ValueRange.of(1, weeksInMonth[month - 1] * 7 + (month == leapWeekInMonth ? 7 : 0)), AccountingDate.of(chronology, 2012, month, 15).range(ChronoField.DAY_OF_MONTH)); - assertEquals(ValueRange.of(1, weeksInMonth[month - 1]), AccountingDate.of(chronology, 2011, month, 15).range(ChronoField.ALIGNED_WEEK_OF_MONTH)); - assertEquals(ValueRange.of(1, weeksInMonth[month - 1] + (month == leapWeekInMonth ? 1 : 0)), AccountingDate.of(chronology, 2012, month, 15).range(ChronoField.ALIGNED_WEEK_OF_MONTH)); - } + public void test_date_dayOfMonth_range(AccountingChronology chronology, int[] weeksInMonth, int[] _elapsedWeeksInMonth, int leapWeekInMonth, int yearOffset) { + assertAll(IntStream.range(1, weeksInMonth.length).mapToObj( + month -> () -> assertAll( + () -> assertEquals(ValueRange.of(1, weeksInMonth[month - 1] * 7), + AccountingDate.of(chronology, 2011 - yearOffset, month, 15).range(ChronoField.DAY_OF_MONTH), + () -> String.format("day of month for month %d ", month)), + () -> assertEquals( + ValueRange.of(1, weeksInMonth[month - 1] * 7 + (month == leapWeekInMonth ? 7 : 0)), + AccountingDate.of(chronology, 2012 - yearOffset, month, 15).range(ChronoField.DAY_OF_MONTH), + () -> String.format("leap year day of month for month %d ", month)), + () -> assertEquals(ValueRange.of(1, weeksInMonth[month - 1]), + AccountingDate.of(chronology, 2011 - yearOffset, month, 15) + .range(ChronoField.ALIGNED_WEEK_OF_MONTH), + () -> String.format("week of month for month %d ", month)), + () -> assertEquals( + ValueRange.of(1, weeksInMonth[month - 1] + (month == leapWeekInMonth ? 1 : 0)), + AccountingDate.of(chronology, 2012 - yearOffset, month, 15) + .range(ChronoField.ALIGNED_WEEK_OF_MONTH)), + () -> String.format("leap year week of month for month %d ", month)))); } @ParameterizedTest @MethodSource("data_yearEnding") - public void test_date_dayOfYear_inLastWeekOf_range(DayOfWeek dayOfWeek, Month ending) { - AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) - .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) - .toChronology(); - - IntFunction getYearEnd = year -> { - return LocalDate.of(year, ending, 1).with(TemporalAdjusters.lastDayOfMonth()).with(TemporalAdjusters.previousOrSame(dayOfWeek)); - }; - IntPredicate isLeapYear = year -> { - LocalDate currentYearEnd = getYearEnd.apply(year); - LocalDate prevYearEnd = getYearEnd.apply(year - 1); - return prevYearEnd.until(currentYearEnd, DAYS) == 371; - }; - - for (int year = 2007; year < 2015; year++) { - assertEquals(ValueRange.of(1, isLeapYear.test(year) ? 371 : 364), AccountingDate.of(chronology, year, 3, 5).range(ChronoField.DAY_OF_YEAR)); - } + public void test_date_dayOfYear_range(AccountingChronology chronology, IntFunction _getYearEnd, IntPredicate isLeapYear) { + assertAll(IntStream.range(2007, 2015).mapToObj( + year -> () -> assertEquals(ValueRange.of(1, isLeapYear.test(year) ? 371 : 364), + AccountingDate.of(chronology, year, 3, 5).range(ChronoField.DAY_OF_YEAR), + () -> String.format("for year %d ", year)))); } - @ParameterizedTest - @MethodSource("data_yearEnding") - public void test_date_dayOfYear_nearestEndOf_range(DayOfWeek dayOfWeek, Month ending) { - AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) - .withDivision(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS).leapWeekInMonth(12) - .toChronology(); - - IntFunction getYearEnd = year -> { - return LocalDate.of(year, ending, 3).plusMonths(1).with(TemporalAdjusters.previousOrSame(dayOfWeek)); - }; - IntPredicate isLeapYear = year -> { - LocalDate currentYearEnd = getYearEnd.apply(year); - LocalDate prevYearEnd = getYearEnd.apply(year - 1); - return prevYearEnd.until(currentYearEnd, DAYS) == 371; - }; - - for (int year = 2007; year < 2015; year++) { - assertEquals(ValueRange.of(1, isLeapYear.test(year) ? 371 : 364), AccountingDate.of(chronology, year, 3, 5).range(ChronoField.DAY_OF_YEAR)); - } - } - - //----------------------------------------------------------------------- + // ----------------------------------------------------------------------- // getWeeksInMonth(month), // getWeeksAtStartOfMonth(weeks), getMonthFromElapsedWeeks(weeks) - //----------------------------------------------------------------------- - public static Object[][] data_weeksInMonth() { - return new Object[][] { - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, new int[] {4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5}, 1}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, new int[] {4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5}, 2}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, new int[] {4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5}, 3}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, new int[] {4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5}, 4}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, new int[] {4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5}, 5}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, new int[] {4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5}, 6}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, new int[] {4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5}, 7}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, new int[] {4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5}, 8}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, new int[] {4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5}, 9}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, new int[] {4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5}, 10}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, new int[] {4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5}, 11}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, new int[] {4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5}, 12}, - - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_5_4_WEEKS, new int[] {4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5, 4}, 1}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_5_4_WEEKS, new int[] {4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5, 4}, 2}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_4_5_4_WEEKS, new int[] {4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5, 4}, 3}, - - {AccountingYearDivision.QUARTERS_OF_PATTERN_5_4_4_WEEKS, new int[] {5, 4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4}, 1}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_5_4_4_WEEKS, new int[] {5, 4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4}, 2}, - {AccountingYearDivision.QUARTERS_OF_PATTERN_5_4_4_WEEKS, new int[] {5, 4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4}, 3}, - - {AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS, new int[] {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4}, 13}, - }; + // ----------------------------------------------------------------------- + public static Stream data_weeksInMonth() { + Stream pattern_4_4_5 = IntStream.range(1, 13) + .mapToObj((leapWeekInMonth) -> new Object[] { AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, + new int[] { 4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5 }, leapWeekInMonth }); + + Stream pattern_4_5_4 = IntStream.range(1, 13) + .mapToObj((leapWeekInMonth) -> new Object[] { AccountingYearDivision.QUARTERS_OF_PATTERN_4_5_4_WEEKS, + new int[] { 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5, 4 }, leapWeekInMonth }); + + Stream pattern_5_4_4 = IntStream.range(1, 13) + .mapToObj((leapWeekInMonth) -> new Object[] { AccountingYearDivision.QUARTERS_OF_PATTERN_5_4_4_WEEKS, + new int[] { 5, 4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4 }, leapWeekInMonth }); + + Stream pattern_even_13 = IntStream.range(1, 14) + .mapToObj((leapWeekInMonth) -> new Object[] { AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS, + new int[] { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }, leapWeekInMonth }); + + return Lists.cartesianProduct( + Streams.concat(pattern_4_4_5, pattern_4_5_4, pattern_5_4_4, pattern_even_13).collect(Collectors.toList()), + Lists.newArrayList((Object) new Object[] { + (UnaryOperator) AccountingChronologyBuilder::accountingYearEndsInIsoYear, 0 + })) + .stream().map(args -> { + AccountingYearDivision division = (AccountingYearDivision) ((Object[]) args.get(0))[0]; + int[] expectedWeeksInMonth = (int[]) ((Object[]) args.get(0))[1]; + int leapWeekInMonth = (int) ((Object[]) args.get(0))[2]; + UnaryOperator startOrEnd = (UnaryOperator) ((Object[]) args.get(1))[0]; + int offset = (int) ((Object[]) args.get(1))[1]; + + AccountingChronologyBuilder builder = startOrEnd.apply(new AccountingChronologyBuilder()) + .endsOn(DayOfWeek.SUNDAY) + .nearestEndOf(Month.AUGUST) + .withDivision(division).leapWeekInMonth(leapWeekInMonth); + + int[] elapsedWeeksInMonth = new int[expectedWeeksInMonth.length]; + for (int month = 1, elapsedWeeks = 0; month <= elapsedWeeksInMonth.length; elapsedWeeks += expectedWeeksInMonth[month - 1], month++) { + elapsedWeeksInMonth[month - 1] = elapsedWeeks; + } + + return arguments(builder.toChronology(), expectedWeeksInMonth, elapsedWeeksInMonth, leapWeekInMonth, offset); + }); } @ParameterizedTest @MethodSource("data_weeksInMonth") - public void test_getWeeksInMonth(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { - AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST) - .withDivision(division).leapWeekInMonth(leapWeekInMonth) - .toChronology(); - - for (int month = 1; month <= weeksInMonth.length; month++) { - assertEquals(weeksInMonth[month - 1], chronology.getDivision().getWeeksInMonth(month)); - assertEquals(weeksInMonth[month - 1] + (month == leapWeekInMonth ? 1 : 0), chronology.getDivision().getWeeksInMonth(month, leapWeekInMonth)); - } + public void test_getWeeksInMonth(AccountingChronology chronology, int[] weeksInMonth, int[] _elapsedWeeksInMonth, int leapWeekInMonth, int _yearOffset) { + assertAll( + IntStream.range(1, weeksInMonth.length) + .mapToObj(month -> () -> assertAll( + () -> assertEquals(weeksInMonth[month - 1], + chronology.getDivision().getWeeksInMonth(month), + () -> String.format("weeks in month mismatch for month %d ", month)), + () -> assertEquals(weeksInMonth[month - 1] + (month == leapWeekInMonth ? 1 : 0), + chronology.getDivision().getWeeksInMonth(month, leapWeekInMonth), + () -> String.format("weeks in month mismatch with leap week for month %d ", + month))))); } @ParameterizedTest @MethodSource("data_weeksInMonth") - public void test_getWeeksAtStartOf(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { - AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST) - .withDivision(division).leapWeekInMonth(leapWeekInMonth) - .toChronology(); - - for (int month = 1, elapsedWeeks = 0; month <= weeksInMonth.length; elapsedWeeks += weeksInMonth[month - 1], month++) { - assertEquals(elapsedWeeks, chronology.getDivision().getWeeksAtStartOfMonth(month)); - assertEquals(elapsedWeeks + (month > leapWeekInMonth ? 1 : 0), chronology.getDivision().getWeeksAtStartOfMonth(month, leapWeekInMonth)); - } + public void test_getWeeksAtStartOf(AccountingChronology chronology, int[] weeksInMonth, int[] elapsedWeeksInMonth, int leapWeekInMonth, int _yearOffset) { + assertAll( + IntStream.range(1, weeksInMonth.length) + .mapToObj(month -> () -> assertAll( + () -> assertEquals(elapsedWeeksInMonth[month - 1], + chronology.getDivision().getWeeksAtStartOfMonth(month), + () -> String.format("weeks in month mismatch for month %d ", month)), + () -> assertEquals(elapsedWeeksInMonth[month - 1] + (month > leapWeekInMonth ? 1 : 0), + chronology.getDivision().getWeeksAtStartOfMonth(month, leapWeekInMonth), + () -> String.format("weeks in month mismatch with leap week for month %d ", month))))); } @ParameterizedTest @MethodSource("data_weeksInMonth") - public void test_getMonthFromElapsedWeeks(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { - AccountingChronology chronology = new AccountingChronologyBuilder().endsOn(DayOfWeek.SUNDAY).nearestEndOf(Month.AUGUST) - .withDivision(division).leapWeekInMonth(leapWeekInMonth) - .toChronology(); - - for (int month = 1, elapsedWeeks = 0; month <= weeksInMonth.length; elapsedWeeks += weeksInMonth[month - 1], month++) { - for (int i = 0; i < weeksInMonth[month - 1]; i++) { - assertEquals(month, chronology.getDivision().getMonthFromElapsedWeeks(elapsedWeeks + i)); - assertEquals(month, chronology.getDivision().getMonthFromElapsedWeeks(elapsedWeeks + i + (month > leapWeekInMonth ? 1 : 0), leapWeekInMonth)); - if (month == leapWeekInMonth && i == weeksInMonth[month - 1] - 1) { - assertEquals(month, chronology.getDivision().getMonthFromElapsedWeeks(elapsedWeeks + i + 1, leapWeekInMonth)); - } - } - } + public void test_getMonthFromElapsedWeeks(AccountingChronology chronology, int[] weeksInMonth, int[] elapsedWeeksInMonths, int leapWeekInMonth, int _yearOffset) { + assertAll( + IntStream.range(0, weeksInMonth.length).boxed() + .flatMap(i -> IntStream.range(elapsedWeeksInMonths[i], elapsedWeeksInMonths[i] + weeksInMonth[i]).mapToObj(week -> new int[] { i + 1, week })) + .map(args -> { + int month = args[0]; + int week = args[1]; + + return () -> assertAll( + () -> assertEquals(month, chronology.getDivision().getMonthFromElapsedWeeks(week), + () -> String.format("weeks in month mismatch for month %d ", month)), + () -> assertEquals(month, + chronology.getDivision().getMonthFromElapsedWeeks(week + (month > leapWeekInMonth ? 1 : 0), leapWeekInMonth), + () -> String.format("weeks in month mismatch with leap week for month %d ",month)), + month == leapWeekInMonth && week == weeksInMonth[month - 1] - 1 + ? () -> assertEquals(month, + chronology.getDivision().getMonthFromElapsedWeeks(week + 1, leapWeekInMonth), + () -> String.format("leap week in month for month %d ", month)) + : () -> {}); + })); } @ParameterizedTest - @MethodSource("data_weeksInMonth") - public void test_negativeWeeks_getMonthFromElapsedWeekspublic(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { - assertEquals(1, division.getMonthFromElapsedWeeks(0)); - assertThrows(DateTimeException.class, () -> division.getMonthFromElapsedWeeks(-1)); + @EnumSource + public void test_negativeWeeks_getMonthFromElapsedWeekspublic(AccountingYearDivision division) { + assertAll( + () -> assertEquals(1, division.getMonthFromElapsedWeeks(0)), + () -> assertThrows(DateTimeException.class, () -> division.getMonthFromElapsedWeeks(-1))); + } + + public static Stream data_weeksInMonth_noChronology() { + return Stream.of( + arguments(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, + new int[] { 4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5 }), + arguments(AccountingYearDivision.QUARTERS_OF_PATTERN_4_5_4_WEEKS, + new int[] { 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5, 4 }), + arguments(AccountingYearDivision.QUARTERS_OF_PATTERN_5_4_4_WEEKS, + new int[] { 5, 4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4 }), + arguments(AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS, + new int[] { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 })); } @ParameterizedTest - @MethodSource("data_weeksInMonth") - public void test_extraWeeks_getMonthFromElapsedWeekspublic(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { - int elapsedWeeks = 0; - for (int month = 1; month <= weeksInMonth.length; month++) { - elapsedWeeks += weeksInMonth[month - 1]; - } - int finalElapsedWeeks = elapsedWeeks; - assertThrows(DateTimeException.class, () -> division.getMonthFromElapsedWeeks(finalElapsedWeeks)); - assertThrows(DateTimeException.class, () -> division.getMonthFromElapsedWeeks(finalElapsedWeeks + 1)); + @MethodSource("data_weeksInMonth_noChronology") + public void test_extraWeeks_getMonthFromElapsedWeekspublic(AccountingYearDivision division, int[] weeksInMonth) { + final int elapsedWeeks = Arrays.stream(weeksInMonth).sum(); + assertAll( + () -> assertThrows(DateTimeException.class, () -> division.getMonthFromElapsedWeeks(elapsedWeeks), + "For elapsed weeks on border"), + () -> assertThrows(DateTimeException.class, () -> division.getMonthFromElapsedWeeks(elapsedWeeks + 1), + "For elapsed weeks beyond border")); + } + + public static Stream data_weeksInMonth_weekInMonth_noChronology() { + Stream pattern_4_4_5 = IntStream.range(1, 13) + .mapToObj((leapWeekInMonth) -> arguments(AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, + new int[] { 4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5 }, leapWeekInMonth)); + + Stream pattern_4_5_4 = IntStream.range(1, 13) + .mapToObj((leapWeekInMonth) -> arguments(AccountingYearDivision.QUARTERS_OF_PATTERN_4_5_4_WEEKS, + new int[] { 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5, 4 }, leapWeekInMonth)); + + Stream pattern_5_4_4 = IntStream.range(1, 13) + .mapToObj((leapWeekInMonth) -> arguments(AccountingYearDivision.QUARTERS_OF_PATTERN_5_4_4_WEEKS, + new int[] { 5, 4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4 }, leapWeekInMonth)); + + Stream pattern_even_13 = IntStream.range(1, 14) + .mapToObj((leapWeekInMonth) -> arguments(AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS, + new int[] { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }, leapWeekInMonth)); + + return Streams.concat(pattern_4_4_5, pattern_4_5_4, pattern_5_4_4, pattern_even_13); } @ParameterizedTest - @MethodSource("data_weeksInMonth") + @MethodSource("data_weeksInMonth_weekInMonth_noChronology") public void test_extraWeeksLeap_getMonthFromElapsedWeekspublic(AccountingYearDivision division, int[] weeksInMonth, int leapWeekInMonth) { - int elapsedWeeks = 1; - for (int month = 1; month <= weeksInMonth.length; month++) { - elapsedWeeks += weeksInMonth[month - 1]; - } - int finalElapsedWeeks = elapsedWeeks; - assertThrows(DateTimeException.class, () -> division.getMonthFromElapsedWeeks(finalElapsedWeeks, leapWeekInMonth)); - assertThrows(DateTimeException.class, () -> division.getMonthFromElapsedWeeks(finalElapsedWeeks + 1, leapWeekInMonth)); + final int elapsedWeeks = Arrays.stream(weeksInMonth).sum() + 1; + assertAll( + () -> assertThrows(DateTimeException.class, + () -> division.getMonthFromElapsedWeeks(elapsedWeeks, leapWeekInMonth), + "For elapsed weeks on border"), + () -> assertThrows(DateTimeException.class, + () -> division.getMonthFromElapsedWeeks(elapsedWeeks + 1, leapWeekInMonth), + "For elapsed weeks beyond border")); } - //----------------------------------------------------------------------- + // ----------------------------------------------------------------------- // toChronology() failures. - //----------------------------------------------------------------------- - public static Object[][] data_badChronology() { - return new Object[][] { - {DayOfWeek.MONDAY, Month.JANUARY, AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS, 0}, - {DayOfWeek.MONDAY, Month.JANUARY, AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS, -1}, - {DayOfWeek.MONDAY, Month.JANUARY, AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS, 14}, - {DayOfWeek.MONDAY, Month.JANUARY, AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, 13}, - {DayOfWeek.MONDAY, Month.JANUARY, AccountingYearDivision.QUARTERS_OF_PATTERN_4_5_4_WEEKS, 13}, - {DayOfWeek.MONDAY, Month.JANUARY, AccountingYearDivision.QUARTERS_OF_PATTERN_5_4_4_WEEKS, 13}, - {DayOfWeek.MONDAY, Month.JANUARY, null, 13}, - {DayOfWeek.MONDAY, null, AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS, 13}, - {null, Month.JANUARY, AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS, 13}, - - }; + // ----------------------------------------------------------------------- + public static Stream data_badChronology() { + return Stream.of( + arguments(DayOfWeek.MONDAY, Month.JANUARY, AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS, 0), + arguments(DayOfWeek.MONDAY, Month.JANUARY, AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS, -1), + arguments(DayOfWeek.MONDAY, Month.JANUARY, AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS, 14), + arguments(DayOfWeek.MONDAY, Month.JANUARY, AccountingYearDivision.QUARTERS_OF_PATTERN_4_4_5_WEEKS, 13), + arguments(DayOfWeek.MONDAY, Month.JANUARY, AccountingYearDivision.QUARTERS_OF_PATTERN_4_5_4_WEEKS, 13), + arguments(DayOfWeek.MONDAY, Month.JANUARY, AccountingYearDivision.QUARTERS_OF_PATTERN_5_4_4_WEEKS, 13), + arguments(DayOfWeek.MONDAY, Month.JANUARY, null, 13), + arguments(DayOfWeek.MONDAY, null, AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS, 13), + arguments(null, Month.JANUARY, AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS, 13)); } @ParameterizedTest @MethodSource("data_badChronology") public void test_badChronology_nearestEndOf(DayOfWeek dayOfWeek, Month ending, AccountingYearDivision division, int leapWeekInMonth) { - assertThrows(IllegalStateException.class, () -> new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) - .withDivision(division).leapWeekInMonth(leapWeekInMonth) - .toChronology()); + assertThrows(IllegalStateException.class, + () -> new AccountingChronologyBuilder().endsOn(dayOfWeek).nearestEndOf(ending) + .withDivision(division).leapWeekInMonth(leapWeekInMonth) + .toChronology()); } @ParameterizedTest @MethodSource("data_badChronology") public void test_badChronology_inLastWeekOf(DayOfWeek dayOfWeek, Month ending, AccountingYearDivision division, int leapWeekInMonth) { - assertThrows(IllegalStateException.class, () -> new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) - .withDivision(division).leapWeekInMonth(leapWeekInMonth) - .toChronology()); + assertThrows(IllegalStateException.class, + () -> new AccountingChronologyBuilder().endsOn(dayOfWeek).inLastWeekOf(ending) + .withDivision(division).leapWeekInMonth(leapWeekInMonth) + .toChronology()); } } From 1b4d604cf68ccb83a4e25752a3dc34b96312d10f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sobkiewicz?= Date: Sun, 4 Sep 2022 22:49:40 +0200 Subject: [PATCH 242/279] Fix test_now*() in TestDayOfMonth and TestDayOfYear (#218) * Use ValueRange.checkValidIntValue return value * Fix naming * Split test_equals_incorrectType and consistently use assertEquals * Retry declaratively in now*() tests Co-authored-by: Stephen Colebourne --- pom.xml | 7 ++++ .../chrono/InternationalFixedChronology.java | 3 +- .../extra/chrono/Symmetry010Chronology.java | 5 +-- .../extra/chrono/Symmetry454Chronology.java | 5 +-- .../org/threeten/extra/TestDayOfMonth.java | 25 +++++--------- .../org/threeten/extra/TestDayOfYear.java | 17 +++------- .../org/threeten/extra/TestOffsetDate.java | 14 ++------ .../java/org/threeten/extra/TestYearWeek.java | 33 ++++++------------- 8 files changed, 37 insertions(+), 72 deletions(-) diff --git a/pom.xml b/pom.xml index 48ed58c3..da4a9b46 100644 --- a/pom.xml +++ b/pom.xml @@ -537,6 +537,12 @@ junit-jupiter test + + org.junit-pioneer + junit-pioneer + ${pioneer.version} + test + @@ -911,6 +917,7 @@ 2.2.2 5.9.0 + 1.7.1 31.1-jre 3.4.2 diff --git a/src/main/java/org/threeten/extra/chrono/InternationalFixedChronology.java b/src/main/java/org/threeten/extra/chrono/InternationalFixedChronology.java index b080c895..fdef876a 100644 --- a/src/main/java/org/threeten/extra/chrono/InternationalFixedChronology.java +++ b/src/main/java/org/threeten/extra/chrono/InternationalFixedChronology.java @@ -467,8 +467,7 @@ public int prolepticYear(Era era, int yearOfEra) { if (!(era instanceof InternationalFixedEra)) { throw new ClassCastException("Invalid era: " + era); } - YEAR_RANGE.checkValidIntValue(yearOfEra, ChronoField.YEAR_OF_ERA); - return yearOfEra; + return YEAR_RANGE.checkValidIntValue(yearOfEra, ChronoField.YEAR_OF_ERA); } /** diff --git a/src/main/java/org/threeten/extra/chrono/Symmetry010Chronology.java b/src/main/java/org/threeten/extra/chrono/Symmetry010Chronology.java index e6985c1d..e1dd3ade 100644 --- a/src/main/java/org/threeten/extra/chrono/Symmetry010Chronology.java +++ b/src/main/java/org/threeten/extra/chrono/Symmetry010Chronology.java @@ -497,10 +497,7 @@ public int prolepticYear(Era era, int yearOfEra) { if (!(era instanceof IsoEra)) { throw new ClassCastException("Invalid era: " + era); } - - YEAR_RANGE.checkValidIntValue(yearOfEra, ChronoField.YEAR_OF_ERA); - - return yearOfEra; + return YEAR_RANGE.checkValidIntValue(yearOfEra, ChronoField.YEAR_OF_ERA); } /** diff --git a/src/main/java/org/threeten/extra/chrono/Symmetry454Chronology.java b/src/main/java/org/threeten/extra/chrono/Symmetry454Chronology.java index e00eac16..75e87c0b 100644 --- a/src/main/java/org/threeten/extra/chrono/Symmetry454Chronology.java +++ b/src/main/java/org/threeten/extra/chrono/Symmetry454Chronology.java @@ -490,10 +490,7 @@ public int prolepticYear(Era era, int yearOfEra) { if (!(era instanceof IsoEra)) { throw new ClassCastException("Invalid era: " + era); } - - YEAR_RANGE.checkValidIntValue(yearOfEra, ChronoField.YEAR_OF_ERA); - - return yearOfEra; + return YEAR_RANGE.checkValidIntValue(yearOfEra, ChronoField.YEAR_OF_ERA); } /** diff --git a/src/test/java/org/threeten/extra/TestDayOfMonth.java b/src/test/java/org/threeten/extra/TestDayOfMonth.java index 940d32c0..861d15aa 100644 --- a/src/test/java/org/threeten/extra/TestDayOfMonth.java +++ b/src/test/java/org/threeten/extra/TestDayOfMonth.java @@ -109,6 +109,7 @@ import java.time.temporal.ValueRange; import org.junit.jupiter.api.Test; +import org.junitpioneer.jupiter.RetryingTest; /** * Test DayOfMonth. @@ -194,26 +195,18 @@ public void test_serialization() throws IOException, ClassNotFoundException { //----------------------------------------------------------------------- // now() //----------------------------------------------------------------------- - @Test + @RetryingTest(100) public void test_now() { - DayOfMonth test = DayOfMonth.now(); - if (LocalDate.now().getDayOfMonth() != test.getValue()) { - test = DayOfMonth.now(); - } - assertEquals(LocalDate.now().getDayOfMonth(), test.getValue()); + assertEquals(LocalDate.now().getDayOfMonth(), DayOfMonth.now().getValue()); } //----------------------------------------------------------------------- // now(ZoneId) //----------------------------------------------------------------------- - @Test + @RetryingTest(100) public void test_now_ZoneId() { ZoneId zone = ZoneId.of("Asia/Tokyo"); - DayOfMonth test = DayOfMonth.now(zone); - if (LocalDate.now(zone).getDayOfMonth() != test.getValue()) { - test = DayOfMonth.now(zone); - } - assertEquals(LocalDate.now(zone).getDayOfMonth(), test.getValue()); + assertEquals(LocalDate.now(zone).getDayOfMonth(), DayOfMonth.now(zone).getValue()); } //----------------------------------------------------------------------- @@ -729,9 +722,9 @@ public void test_compareTo() { @Test public void test_compareTo_nullDayOfMonth() { - DayOfMonth doy = null; + DayOfMonth dom = null; DayOfMonth test = DayOfMonth.of(1); - assertThrows(NullPointerException.class, () -> test.compareTo(doy)); + assertThrows(NullPointerException.class, () -> test.compareTo(dom)); } //----------------------------------------------------------------------- @@ -751,9 +744,9 @@ public void test_equals() { @Test public void test_equals_nullDayOfMonth() { - DayOfMonth doy = null; + DayOfMonth dom = null; DayOfMonth test = DayOfMonth.of(1); - assertEquals(false, test.equals(doy)); + assertEquals(false, test.equals(dom)); } @Test diff --git a/src/test/java/org/threeten/extra/TestDayOfYear.java b/src/test/java/org/threeten/extra/TestDayOfYear.java index 90735b94..454b7e4e 100644 --- a/src/test/java/org/threeten/extra/TestDayOfYear.java +++ b/src/test/java/org/threeten/extra/TestDayOfYear.java @@ -93,6 +93,7 @@ import java.time.temporal.ValueRange; import org.junit.jupiter.api.Test; +import org.junitpioneer.jupiter.RetryingTest; /** * Test DayOfYear. @@ -181,26 +182,18 @@ public void test_serialization() throws IOException, ClassNotFoundException { //----------------------------------------------------------------------- // now() //----------------------------------------------------------------------- - @Test + @RetryingTest(100) public void test_now() { - DayOfYear test = DayOfYear.now(); - if (LocalDate.now().getDayOfYear() != test.getValue()) { - test = DayOfYear.now(); - } - assertEquals(LocalDate.now().getDayOfYear(), test.getValue()); + assertEquals(LocalDate.now().getDayOfYear(), DayOfYear.now().getValue()); } //----------------------------------------------------------------------- // now(ZoneId) //----------------------------------------------------------------------- - @Test + @RetryingTest(100) public void test_now_ZoneId() { ZoneId zone = ZoneId.of("Asia/Tokyo"); - DayOfYear test = DayOfYear.now(zone); - if (LocalDate.now(zone).getDayOfYear() != test.getValue()) { - test = DayOfYear.now(zone); - } - assertEquals(LocalDate.now(zone).getDayOfYear(), test.getValue()); + assertEquals(LocalDate.now(zone).getDayOfYear(), DayOfYear.now(zone).getValue()); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestOffsetDate.java b/src/test/java/org/threeten/extra/TestOffsetDate.java index a5e6331d..b5334949 100644 --- a/src/test/java/org/threeten/extra/TestOffsetDate.java +++ b/src/test/java/org/threeten/extra/TestOffsetDate.java @@ -88,6 +88,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import org.junitpioneer.jupiter.RetryingTest; /** * Test OffsetDate. @@ -157,18 +158,9 @@ public void constant_MAX() { //----------------------------------------------------------------------- // now() //----------------------------------------------------------------------- - @Test + @RetryingTest(100) public void now() { - OffsetDate expected = OffsetDate.now(Clock.systemDefaultZone()); - OffsetDate test = OffsetDate.now(); - for (int i = 0; i < 100; i++) { - if (expected.equals(test)) { - return; - } - expected = OffsetDate.now(Clock.systemDefaultZone()); - test = OffsetDate.now(); - } - assertEquals(expected, test); + assertEquals(OffsetDate.now(Clock.systemDefaultZone()), OffsetDate.now()); } @Test diff --git a/src/test/java/org/threeten/extra/TestYearWeek.java b/src/test/java/org/threeten/extra/TestYearWeek.java index f9ece612..7236c621 100644 --- a/src/test/java/org/threeten/extra/TestYearWeek.java +++ b/src/test/java/org/threeten/extra/TestYearWeek.java @@ -127,6 +127,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import org.junitpioneer.jupiter.RetryingTest; public class TestYearWeek { @@ -335,18 +336,9 @@ public void test_serialization() throws IOException, ClassNotFoundException { //----------------------------------------------------------------------- // now() //----------------------------------------------------------------------- - @Test + @RetryingTest(100) public void test_now() { - YearWeek expected = YearWeek.now(Clock.systemDefaultZone()); - YearWeek test = YearWeek.now(); - for (int i = 0; i < 100; i++) { - if (expected.equals(test)) { - return; - } - expected = YearWeek.now(Clock.systemDefaultZone()); - test = YearWeek.now(); - } - assertEquals(expected, test); + assertEquals(YearWeek.now(Clock.systemDefaultZone()), YearWeek.now()); } //----------------------------------------------------------------------- @@ -357,19 +349,10 @@ public void now_ZoneId_nullZoneId() { assertThrows(NullPointerException.class, () -> YearWeek.now((ZoneId) null)); } - @Test + @RetryingTest(100) public void now_ZoneId() { ZoneId zone = ZoneId.of("UTC+01:02:03"); - YearWeek expected = YearWeek.now(Clock.system(zone)); - YearWeek test = YearWeek.now(zone); - for (int i = 0; i < 100; i++) { - if (expected.equals(test)) { - return; - } - expected = YearWeek.now(Clock.system(zone)); - test = YearWeek.now(zone); - } - assertEquals(expected, test); + assertEquals(YearWeek.now(Clock.system(zone)), YearWeek.now(zone)); } //----------------------------------------------------------------------- @@ -1106,9 +1089,13 @@ public void test_equals() { assertFalse(c.equals(b)); } + @Test + public void test_equals_null() { + assertEquals(false, TEST.equals(null)); + } + @Test public void test_equals_incorrectType() { - assertTrue(TEST.equals(null) == false); assertEquals(false, TEST.equals((Object) "Incorrect type")); } From 2e4aaf954fc20e5b4603352738f4a242dd15dd0e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Sep 2022 02:07:33 +0000 Subject: [PATCH 243/279] Bump maven-pmd-plugin from 3.17.0 to 3.18.0 (#224) Bumps [maven-pmd-plugin](https://github.com/apache/maven-pmd-plugin) from 3.17.0 to 3.18.0. - [Release notes](https://github.com/apache/maven-pmd-plugin/releases) - [Commits](https://github.com/apache/maven-pmd-plugin/compare/maven-pmd-plugin-3.17.0...maven-pmd-plugin-3.18.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-pmd-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index da4a9b46..20d3b186 100644 --- a/pom.xml +++ b/pom.xml @@ -935,7 +935,7 @@ 3.4.0 3.2.0 3.6.4 - 3.17.0 + 3.18.0 3.4.0 2.5.3 2.4 From 2d6ddcfd9fa4012c5250143ec12355c6c306809c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Sep 2022 02:10:32 +0000 Subject: [PATCH 244/279] Bump maven-jxr-plugin from 3.2.0 to 3.3.0 (#221) Bumps [maven-jxr-plugin](https://github.com/apache/maven-jxr) from 3.2.0 to 3.3.0. - [Release notes](https://github.com/apache/maven-jxr/releases) - [Commits](https://github.com/apache/maven-jxr/compare/jxr-3.2.0...jxr-3.3.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-jxr-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 20d3b186..a31c58d6 100644 --- a/pom.xml +++ b/pom.xml @@ -933,7 +933,7 @@ 3.0.1 3.2.2 3.4.0 - 3.2.0 + 3.3.0 3.6.4 3.18.0 3.4.0 From d713199c7097056bc5a4ba5903047d300ac1bdab Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Sep 2022 02:31:57 +0000 Subject: [PATCH 245/279] Bump maven-javadoc-plugin from 3.4.0 to 3.4.1 (#219) Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.4.0 to 3.4.1. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.4.0...maven-javadoc-plugin-3.4.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a31c58d6..7fdac284 100644 --- a/pom.xml +++ b/pom.xml @@ -932,7 +932,7 @@ 3.0.1 3.0.1 3.2.2 - 3.4.0 + 3.4.1 3.3.0 3.6.4 3.18.0 From 3d41ce3b0f5010358c3e2ed8fa496ec9f148a2b2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Sep 2022 12:59:05 +0000 Subject: [PATCH 246/279] Bump maven-site-plugin from 3.12.0 to 3.12.1 (#216) Bumps [maven-site-plugin](https://github.com/apache/maven-site-plugin) from 3.12.0 to 3.12.1. - [Release notes](https://github.com/apache/maven-site-plugin/releases) - [Commits](https://github.com/apache/maven-site-plugin/compare/maven-site-plugin-3.12.0...maven-site-plugin-3.12.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-site-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7fdac284..b12e588e 100644 --- a/pom.xml +++ b/pom.xml @@ -940,7 +940,7 @@ 2.5.3 2.4 3.3.0 - 3.12.0 + 3.12.1 3.2.1 3.0.0-M7 3.0.0-M7 From 2acee9d98e9abae8ab251a0c8f0fe1d75e691c02 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Sep 2022 13:10:38 +0000 Subject: [PATCH 247/279] Bump github-api from 1.307 to 1.308 (#222) Bumps [github-api](https://github.com/hub4j/github-api) from 1.307 to 1.308. - [Release notes](https://github.com/hub4j/github-api/releases) - [Changelog](https://github.com/hub4j/github-api/blob/main/CHANGELOG.md) - [Commits](https://github.com/hub4j/github-api/compare/github-api-1.307...github-api-1.308) --- updated-dependencies: - dependency-name: org.kohsuke:github-api dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b12e588e..0a138f8b 100644 --- a/pom.xml +++ b/pom.xml @@ -946,7 +946,7 @@ 3.0.0-M7 3.1.0 - 1.307 + 1.308 1.4.0 0.8.8 1.6.13 From fef0da768e370c4387fbb364fe92010a67e22d43 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 5 Sep 2022 16:08:45 +0000 Subject: [PATCH 248/279] Bump maven-project-info-reports-plugin from 3.4.0 to 3.4.1 (#220) Bumps [maven-project-info-reports-plugin](https://github.com/apache/maven-project-info-reports-plugin) from 3.4.0 to 3.4.1. - [Release notes](https://github.com/apache/maven-project-info-reports-plugin/releases) - [Commits](https://github.com/apache/maven-project-info-reports-plugin/compare/maven-project-info-reports-plugin-3.4.0...maven-project-info-reports-plugin-3.4.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-project-info-reports-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0a138f8b..bf7e1ea1 100644 --- a/pom.xml +++ b/pom.xml @@ -936,7 +936,7 @@ 3.3.0 3.6.4 3.18.0 - 3.4.0 + 3.4.1 2.5.3 2.4 3.3.0 From f372a7b195553fd1525421288a11beecb361c45e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Sep 2022 07:05:04 +0100 Subject: [PATCH 249/279] Bump maven-pmd-plugin from 3.18.0 to 3.19.0 (#228) Bumps [maven-pmd-plugin](https://github.com/apache/maven-pmd-plugin) from 3.18.0 to 3.19.0. - [Release notes](https://github.com/apache/maven-pmd-plugin/releases) - [Commits](https://github.com/apache/maven-pmd-plugin/compare/maven-pmd-plugin-3.18.0...maven-pmd-plugin-3.19.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-pmd-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bf7e1ea1..b527b373 100644 --- a/pom.xml +++ b/pom.xml @@ -935,7 +935,7 @@ 3.4.1 3.3.0 3.6.4 - 3.18.0 + 3.19.0 3.4.1 2.5.3 2.4 From 8615af67b14eed5a306616bed55df0c053f2344c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Sep 2022 07:29:09 +0100 Subject: [PATCH 250/279] Bump spotbugs-maven-plugin from 4.7.1.1 to 4.7.2.0 (#227) Bumps [spotbugs-maven-plugin](https://github.com/spotbugs/spotbugs-maven-plugin) from 4.7.1.1 to 4.7.2.0. - [Release notes](https://github.com/spotbugs/spotbugs-maven-plugin/releases) - [Commits](https://github.com/spotbugs/spotbugs-maven-plugin/compare/spotbugs-maven-plugin-4.7.1.1...spotbugs-maven-plugin-4.7.2.0) --- updated-dependencies: - dependency-name: com.github.spotbugs:spotbugs-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b527b373..29c965d6 100644 --- a/pom.xml +++ b/pom.xml @@ -951,7 +951,7 @@ 0.8.8 1.6.13 1.2 - 4.7.1.1 + 4.7.2.0 1.8 1.8 From d15e20b97e9a7caf58292437d734871b3e2bcf82 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 26 Sep 2022 08:40:49 +0100 Subject: [PATCH 251/279] Bump junit-bom from 5.9.0 to 5.9.1 (#230) Bumps [junit-bom](https://github.com/junit-team/junit5) from 5.9.0 to 5.9.1. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.9.0...r5.9.1) --- updated-dependencies: - dependency-name: org.junit:junit-bom dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 29c965d6..b6944c21 100644 --- a/pom.xml +++ b/pom.xml @@ -916,7 +916,7 @@ 2.2.2 - 5.9.0 + 5.9.1 1.7.1 31.1-jre From 67e23a87b2c9c2c9ff3663349e74b66d47d36d02 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 26 Sep 2022 08:44:59 +0100 Subject: [PATCH 252/279] Bump maven-jar-plugin from 3.2.2 to 3.3.0 (#229) Bumps [maven-jar-plugin](https://github.com/apache/maven-jar-plugin) from 3.2.2 to 3.3.0. - [Release notes](https://github.com/apache/maven-jar-plugin/releases) - [Commits](https://github.com/apache/maven-jar-plugin/compare/maven-jar-plugin-3.2.2...maven-jar-plugin-3.3.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-jar-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b6944c21..dd951272 100644 --- a/pom.xml +++ b/pom.xml @@ -931,7 +931,7 @@ 3.1.0 3.0.1 3.0.1 - 3.2.2 + 3.3.0 3.4.1 3.3.0 3.6.4 From c5a8fb35d32bc03959766f42f6587f10a7e2a5e8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 26 Sep 2022 07:48:23 +0000 Subject: [PATCH 253/279] Bump maven-checkstyle-plugin from 3.1.2 to 3.2.0 (#225) Bumps [maven-checkstyle-plugin](https://github.com/apache/maven-checkstyle-plugin) from 3.1.2 to 3.2.0. - [Release notes](https://github.com/apache/maven-checkstyle-plugin/releases) - [Commits](https://github.com/apache/maven-checkstyle-plugin/compare/maven-checkstyle-plugin-3.1.2...maven-checkstyle-plugin-3.2.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-checkstyle-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index dd951272..6dc4cd8b 100644 --- a/pom.xml +++ b/pom.xml @@ -923,7 +923,7 @@ 3.4.2 5.1.8 2.12.1 - 3.1.2 + 3.2.0 3.2.0 3.10.1 3.0.0 From d84cfcbc66686a092ec630448e27c79950106e52 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Mon, 26 Sep 2022 17:57:05 +0100 Subject: [PATCH 254/279] Switch website from master to main (#231) --- .github/website.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/website.sh b/.github/website.sh index ffb57f74..d112a446 100644 --- a/.github/website.sh +++ b/.github/website.sh @@ -19,6 +19,6 @@ git status git commit --message "Update threeten-extra from Travis: Build $TRAVIS_BUILD_NUMBER" echo "## push..." -git push origin master +git push origin main echo "## done" From 1b318c139b9f3d128d3166332120fb64746b92e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sobkiewicz?= Date: Sun, 18 Dec 2022 00:24:14 +0100 Subject: [PATCH 255/279] Fix assertions (#243) --- .../threeten/extra/AbstractDateTimeTest.java | 7 +- .../org/threeten/extra/TestDayOfYear.java | 5 +- .../java/org/threeten/extra/TestDays.java | 8 +-- .../java/org/threeten/extra/TestHours.java | 4 +- .../java/org/threeten/extra/TestMinutes.java | 4 +- .../java/org/threeten/extra/TestMonths.java | 8 +-- .../org/threeten/extra/TestOffsetDate.java | 5 +- .../java/org/threeten/extra/TestSeconds.java | 4 +- .../org/threeten/extra/TestTemporals.java | 64 +++++++++---------- .../java/org/threeten/extra/TestWeeks.java | 8 +-- .../java/org/threeten/extra/TestYears.java | 8 +-- 11 files changed, 64 insertions(+), 61 deletions(-) diff --git a/src/test/java/org/threeten/extra/AbstractDateTimeTest.java b/src/test/java/org/threeten/extra/AbstractDateTimeTest.java index ab270eb4..f6265a1b 100644 --- a/src/test/java/org/threeten/extra/AbstractDateTimeTest.java +++ b/src/test/java/org/threeten/extra/AbstractDateTimeTest.java @@ -31,6 +31,7 @@ */ package org.threeten.extra; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -101,7 +102,7 @@ public void basicTest_isSupported_TemporalField_null() { public void basicTest_range_TemporalField_supported() { for (TemporalAccessor sample : samples()) { for (TemporalField field : validFields()) { - sample.range(field); // no exception + assertDoesNotThrow(() -> sample.range(field)); } } } @@ -130,7 +131,7 @@ public void basicTest_get_TemporalField_supported() { for (TemporalAccessor sample : samples()) { for (TemporalField field : validFields()) { if (sample.range(field).isIntValue()) { - sample.get(field); // no exception + assertDoesNotThrow(() -> sample.get(field)); } else { assertThrows(DateTimeException.class, () -> sample.get(field), "Failed on " + sample + " " + field); } @@ -161,7 +162,7 @@ public void basicTest_get_TemporalField_null() { public void basicTest_getLong_TemporalField_supported() { for (TemporalAccessor sample : samples()) { for (TemporalField field : validFields()) { - sample.getLong(field); // no exception + assertDoesNotThrow(() -> sample.getLong(field)); } } } diff --git a/src/test/java/org/threeten/extra/TestDayOfYear.java b/src/test/java/org/threeten/extra/TestDayOfYear.java index 454b7e4e..2aa8575b 100644 --- a/src/test/java/org/threeten/extra/TestDayOfYear.java +++ b/src/test/java/org/threeten/extra/TestDayOfYear.java @@ -62,6 +62,7 @@ import static java.time.temporal.ChronoField.YEAR; import static java.time.temporal.ChronoField.YEAR_OF_ERA; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -175,7 +176,7 @@ public void test_serialization() throws IOException, ClassNotFoundException { oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertEquals(test, ois.readObject()); + assertSame(test, ois.readObject()); } } @@ -204,7 +205,7 @@ public void test_of_int() { for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) { DayOfYear test = DayOfYear.of(i); assertEquals(i, test.getValue()); - assertEquals(test, DayOfYear.of(i)); + assertSame(test, DayOfYear.of(i)); } } diff --git a/src/test/java/org/threeten/extra/TestDays.java b/src/test/java/org/threeten/extra/TestDays.java index 1c0a8d27..defeaaf8 100644 --- a/src/test/java/org/threeten/extra/TestDays.java +++ b/src/test/java/org/threeten/extra/TestDays.java @@ -83,8 +83,8 @@ public void test_deserializationSingleton() throws Exception { //----------------------------------------------------------------------- @Test public void test_ZERO() { - assertSame(Days.of(0), Days.ZERO); - assertEquals(Days.of(0), Days.ZERO); + assertSame(Days.ZERO, Days.of(0)); + assertEquals(Days.ZERO, Days.of(0)); assertEquals(0, Days.ZERO.getAmount()); assertFalse(Days.ZERO.isNegative()); assertTrue(Days.ZERO.isZero()); @@ -93,8 +93,8 @@ public void test_ZERO() { @Test public void test_ONE() { - assertSame(Days.of(1), Days.ONE); - assertEquals(Days.of(1), Days.ONE); + assertSame(Days.ONE, Days.of(1)); + assertEquals(Days.ONE, Days.of(1)); assertEquals(1, Days.ONE.getAmount()); assertFalse(Days.ONE.isNegative()); assertFalse(Days.ONE.isZero()); diff --git a/src/test/java/org/threeten/extra/TestHours.java b/src/test/java/org/threeten/extra/TestHours.java index 8c0af9c2..008b3231 100644 --- a/src/test/java/org/threeten/extra/TestHours.java +++ b/src/test/java/org/threeten/extra/TestHours.java @@ -77,8 +77,8 @@ public void test_deserializationSingleton() throws Exception { //----------------------------------------------------------------------- @Test public void test_ZERO() { - assertSame(Hours.of(0), Hours.ZERO); - assertEquals(Hours.of(0), Hours.ZERO); + assertSame(Hours.ZERO, Hours.of(0)); + assertEquals(Hours.ZERO, Hours.of(0)); assertEquals(0, Hours.ZERO.getAmount()); assertFalse(Hours.ZERO.isNegative()); assertTrue(Hours.ZERO.isZero()); diff --git a/src/test/java/org/threeten/extra/TestMinutes.java b/src/test/java/org/threeten/extra/TestMinutes.java index d8e92e8a..e88e1717 100644 --- a/src/test/java/org/threeten/extra/TestMinutes.java +++ b/src/test/java/org/threeten/extra/TestMinutes.java @@ -77,8 +77,8 @@ public void test_deserializationSingleton() throws Exception { //----------------------------------------------------------------------- @Test public void test_ZERO() { - assertSame(Minutes.of(0), Minutes.ZERO); - assertEquals(Minutes.of(0), Minutes.ZERO); + assertSame(Minutes.ZERO, Minutes.of(0)); + assertEquals(Minutes.ZERO, Minutes.of(0)); assertEquals(0, Minutes.ZERO.getAmount()); assertFalse(Minutes.ZERO.isNegative()); assertTrue(Minutes.ZERO.isZero()); diff --git a/src/test/java/org/threeten/extra/TestMonths.java b/src/test/java/org/threeten/extra/TestMonths.java index 2e91fa41..5b39c30a 100644 --- a/src/test/java/org/threeten/extra/TestMonths.java +++ b/src/test/java/org/threeten/extra/TestMonths.java @@ -83,8 +83,8 @@ public void test_deserializationSingleton() throws Exception { //----------------------------------------------------------------------- @Test public void test_ZERO() { - assertSame(Months.of(0), Months.ZERO); - assertEquals(Months.of(0), Months.ZERO); + assertSame(Months.ZERO, Months.of(0)); + assertEquals(Months.ZERO, Months.of(0)); assertEquals(0, Months.ZERO.getAmount()); assertFalse(Months.ZERO.isNegative()); assertTrue(Months.ZERO.isZero()); @@ -93,8 +93,8 @@ public void test_ZERO() { @Test public void test_ONE() { - assertSame(Months.of(1), Months.ONE); - assertEquals(Months.of(1), Months.ONE); + assertSame(Months.ONE, Months.of(1)); + assertEquals(Months.ONE, Months.of(1)); assertEquals(1, Months.ONE.getAmount()); assertFalse(Months.ONE.isNegative()); assertFalse(Months.ONE.isZero()); diff --git a/src/test/java/org/threeten/extra/TestOffsetDate.java b/src/test/java/org/threeten/extra/TestOffsetDate.java index b5334949..c0c46ee6 100644 --- a/src/test/java/org/threeten/extra/TestOffsetDate.java +++ b/src/test/java/org/threeten/extra/TestOffsetDate.java @@ -48,6 +48,7 @@ import static java.time.temporal.ChronoField.YEAR_OF_ERA; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -386,7 +387,7 @@ public void constructor_nullDate() throws Throwable { Constructor con = OffsetDate.class.getDeclaredConstructor(LocalDate.class, ZoneOffset.class); con.setAccessible(true); InvocationTargetException thrown = assertThrows(InvocationTargetException.class, () -> con.newInstance(null, OFFSET_PONE)); - assertTrue(thrown.getCause() instanceof NullPointerException); + assertInstanceOf(NullPointerException.class, thrown.getCause()); } @Test @@ -394,7 +395,7 @@ public void constructor_nullOffset() throws Throwable { Constructor con = OffsetDate.class.getDeclaredConstructor(LocalDate.class, ZoneOffset.class); con.setAccessible(true); InvocationTargetException thrown = assertThrows(InvocationTargetException.class, () -> con.newInstance(LocalDate.of(2008, 6, 30), null)); - assertTrue(thrown.getCause() instanceof NullPointerException); + assertInstanceOf(NullPointerException.class, thrown.getCause()); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestSeconds.java b/src/test/java/org/threeten/extra/TestSeconds.java index e1188334..7cd71851 100644 --- a/src/test/java/org/threeten/extra/TestSeconds.java +++ b/src/test/java/org/threeten/extra/TestSeconds.java @@ -77,8 +77,8 @@ public void test_deserializationSingleton() throws Exception { //----------------------------------------------------------------------- @Test public void test_ZERO() { - assertSame(Seconds.of(0), Seconds.ZERO); - assertEquals(Seconds.of(0), Seconds.ZERO); + assertSame(Seconds.ZERO, Seconds.of(0)); + assertEquals(Seconds.ZERO, Seconds.of(0)); assertEquals(0, Seconds.ZERO.getAmount()); assertFalse(Seconds.ZERO.isNegative()); assertTrue(Seconds.ZERO.isZero()); diff --git a/src/test/java/org/threeten/extra/TestTemporals.java b/src/test/java/org/threeten/extra/TestTemporals.java index 7eaa1463..7fb4744a 100644 --- a/src/test/java/org/threeten/extra/TestTemporals.java +++ b/src/test/java/org/threeten/extra/TestTemporals.java @@ -53,7 +53,8 @@ import static java.time.temporal.ChronoUnit.YEARS; import static java.time.temporal.IsoFields.QUARTER_YEARS; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -93,7 +94,7 @@ public class TestTemporals { @Test public void test_nextWorkingDay_serialization() throws IOException, ClassNotFoundException { TemporalAdjuster test = Temporals.nextWorkingDay(); - assertTrue(test instanceof Serializable); + assertInstanceOf(Serializable.class, test); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { oos.writeObject(test); @@ -110,8 +111,8 @@ public void test_nextWorkingDay() { LocalDate date = LocalDate.of(2007, month, i); LocalDate test = (LocalDate) Temporals.nextWorkingDay().adjustInto(date); assertTrue(test.isAfter(date)); - assertFalse(test.getDayOfWeek().equals(SATURDAY)); - assertFalse(test.getDayOfWeek().equals(SUNDAY)); + assertNotEquals(SATURDAY, test.getDayOfWeek()); + assertNotEquals(SUNDAY, test.getDayOfWeek()); switch (date.getDayOfWeek()) { case FRIDAY: @@ -160,13 +161,13 @@ public void test_nextWorkingDay_yearChange() { @Test public void test_nextWorkingDayOrSame_serialization() throws IOException, ClassNotFoundException { TemporalAdjuster test = Temporals.nextWorkingDayOrSame(); - assertTrue(test instanceof Serializable); + assertInstanceOf(Serializable.class, test); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertSame(ois.readObject(), test); + assertSame(test, ois.readObject()); } } @@ -176,13 +177,13 @@ public void test_nextWorkingDayOrSame() { for (int i = 1; i <= month.length(false); i++) { LocalDate date = LocalDate.of(2007, month, i); LocalDate test = (LocalDate) Temporals.nextWorkingDayOrSame().adjustInto(date); - assertFalse(test.getDayOfWeek().equals(SATURDAY)); - assertFalse(test.getDayOfWeek().equals(SUNDAY)); + assertNotEquals(SATURDAY, test.getDayOfWeek()); + assertNotEquals(SUNDAY, test.getDayOfWeek()); switch (date.getDayOfWeek()) { case SATURDAY: case SUNDAY: - assertEquals(test.getDayOfWeek(), MONDAY); + assertEquals(MONDAY, test.getDayOfWeek()); break; default: assertEquals(date.getDayOfWeek(), test.getDayOfWeek()); @@ -192,18 +193,18 @@ public void test_nextWorkingDayOrSame() { int dayDiff = test.getDayOfYear() - date.getDayOfYear(); switch (date.getDayOfWeek()) { case SATURDAY: - assertEquals(dayDiff, 2); + assertEquals(2, dayDiff); break; case SUNDAY: - assertEquals(dayDiff, 1); + assertEquals(1, dayDiff); break; default: - assertEquals(dayDiff, 0); + assertEquals(0, dayDiff); } } else { - assertEquals(test.getYear(), 2008); - assertEquals(test.getMonth(), JANUARY); - assertEquals(test.getDayOfMonth(), 1); + assertEquals(2008, test.getYear()); + assertEquals(JANUARY, test.getMonth()); + assertEquals(1, test.getDayOfMonth()); } } } @@ -226,7 +227,7 @@ public void test_nextWorkingDayOrSame_yearChange() { @Test public void test_previousWorkingDay_serialization() throws IOException, ClassNotFoundException { TemporalAdjuster test = Temporals.previousWorkingDay(); - assertTrue(test instanceof Serializable); + assertInstanceOf(Serializable.class, test); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { oos.writeObject(test); @@ -243,8 +244,8 @@ public void test_previousWorkingDay() { LocalDate date = LocalDate.of(2007, month, i); LocalDate test = (LocalDate) Temporals.previousWorkingDay().adjustInto(date); assertTrue(test.isBefore(date)); - assertFalse(test.getDayOfWeek().equals(SATURDAY)); - assertFalse(test.getDayOfWeek().equals(SUNDAY)); + assertNotEquals(SATURDAY, test.getDayOfWeek()); + assertNotEquals(SUNDAY, test.getDayOfWeek()); switch (date.getDayOfWeek()) { case MONDAY: @@ -293,13 +294,13 @@ public void test_previousWorkingDay_yearChange() { @Test public void test_previousWorkingDayOrSame_serialization() throws IOException, ClassNotFoundException { TemporalAdjuster test = Temporals.previousWorkingDayOrSame(); - assertTrue(test instanceof Serializable); + assertInstanceOf(Serializable.class, test); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { oos.writeObject(test); } try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { - assertSame(ois.readObject(), test); + assertSame(test, ois.readObject()); } } @@ -309,13 +310,13 @@ public void test_previousWorkingDayOrSame() { for (int i = 1; i <= month.length(false); i++) { LocalDate date = LocalDate.of(2007, month, i); LocalDate test = (LocalDate) Temporals.previousWorkingDayOrSame().adjustInto(date); - assertFalse(test.getDayOfWeek().equals(SATURDAY)); - assertFalse(test.getDayOfWeek().equals(SUNDAY)); + assertNotEquals(SATURDAY, test.getDayOfWeek()); + assertNotEquals(SUNDAY, test.getDayOfWeek()); switch (date.getDayOfWeek()) { case SATURDAY: case SUNDAY: - assertEquals(test.getDayOfWeek(), FRIDAY); + assertEquals(FRIDAY, test.getDayOfWeek()); break; default: assertEquals(date.getDayOfWeek(), test.getDayOfWeek()); @@ -325,18 +326,18 @@ public void test_previousWorkingDayOrSame() { int dayDiff = test.getDayOfYear() - date.getDayOfYear(); switch (date.getDayOfWeek()) { case SATURDAY: - assertEquals(dayDiff, -1); + assertEquals(-1, dayDiff); break; case SUNDAY: - assertEquals(dayDiff, -2); + assertEquals(-2, dayDiff); break; default: - assertEquals(dayDiff, 0); + assertEquals(0, dayDiff); } } else { - assertEquals(test.getYear(), 2006); - assertEquals(test.getMonth(), DECEMBER); - assertEquals(test.getDayOfMonth(), 29); + assertEquals(2006, test.getYear()); + assertEquals(DECEMBER, test.getMonth()); + assertEquals(29, test.getDayOfMonth()); } } } @@ -347,11 +348,11 @@ public void test_previousWorkingDayOrSame_yearChange() { LocalDate sunday = LocalDate.of(2011, JANUARY, 2); Temporal test = Temporals.previousWorkingDayOrSame().adjustInto(sunday); - assertEquals(test, LocalDate.of(2010, DECEMBER, 31)); + assertEquals(LocalDate.of(2010, DECEMBER, 31), test); LocalDate saturday = LocalDate.of(2011, JANUARY, 1); test = Temporals.previousWorkingDayOrSame().adjustInto(saturday); - assertEquals(test, LocalDate.of(2010, DECEMBER, 31)); + assertEquals(LocalDate.of(2010, DECEMBER, 31), test); } //----------------------------------------------------------------------- @@ -682,7 +683,6 @@ public static Object[][] data_durationConversions() { public void test_durationToBigDecimalSeconds(Duration input, BigDecimal expected, double ignored) { BigDecimal test = Temporals.durationToBigDecimalSeconds(input); assertEquals(expected, test); - assertEquals(9, test.scale()); } @ParameterizedTest diff --git a/src/test/java/org/threeten/extra/TestWeeks.java b/src/test/java/org/threeten/extra/TestWeeks.java index 13174605..efb459a6 100644 --- a/src/test/java/org/threeten/extra/TestWeeks.java +++ b/src/test/java/org/threeten/extra/TestWeeks.java @@ -83,8 +83,8 @@ public void test_deserializationSingleton() throws Exception { //----------------------------------------------------------------------- @Test public void test_ZERO() { - assertSame(Weeks.of(0), Weeks.ZERO); - assertEquals(Weeks.of(0), Weeks.ZERO); + assertSame(Weeks.ZERO, Weeks.of(0)); + assertEquals(Weeks.ZERO, Weeks.of(0)); assertEquals(0, Weeks.ZERO.getAmount()); assertFalse(Weeks.ZERO.isNegative()); assertTrue(Weeks.ZERO.isZero()); @@ -93,8 +93,8 @@ public void test_ZERO() { @Test public void test_ONE() { - assertSame(Weeks.of(1), Weeks.ONE); - assertEquals(Weeks.of(1), Weeks.ONE); + assertSame(Weeks.ONE, Weeks.of(1)); + assertEquals(Weeks.ONE, Weeks.of(1)); assertEquals(1, Weeks.ONE.getAmount()); assertFalse(Weeks.ONE.isNegative()); assertFalse(Weeks.ONE.isZero()); diff --git a/src/test/java/org/threeten/extra/TestYears.java b/src/test/java/org/threeten/extra/TestYears.java index 6f49e9bf..1138ba61 100644 --- a/src/test/java/org/threeten/extra/TestYears.java +++ b/src/test/java/org/threeten/extra/TestYears.java @@ -83,8 +83,8 @@ public void test_deserializationSingleton() throws Exception { //----------------------------------------------------------------------- @Test public void test_ZERO() { - assertSame(Years.of(0), Years.ZERO); - assertEquals(Years.of(0), Years.ZERO); + assertSame(Years.ZERO, Years.of(0)); + assertEquals(Years.ZERO, Years.of(0)); assertEquals(0, Years.ZERO.getAmount()); assertFalse(Years.ZERO.isNegative()); assertTrue(Years.ZERO.isZero()); @@ -93,8 +93,8 @@ public void test_ZERO() { @Test public void test_ONE() { - assertSame(Years.of(1), Years.ONE); - assertEquals(Years.of(1), Years.ONE); + assertSame(Years.ONE, Years.of(1)); + assertEquals(Years.ONE, Years.of(1)); assertEquals(1, Years.ONE.getAmount()); assertFalse(Years.ONE.isNegative()); assertFalse(Years.ONE.isZero()); From 71bfb4a9d5f9ae41ddd225139ff6b7aa8ee85f67 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sat, 17 Dec 2022 23:39:18 +0000 Subject: [PATCH 256/279] Switch master to main (#244) --- .github/workflows/build.yml | 2 +- .github/workflows/codeql-analysis.yml | 4 ++-- pom.xml | 2 +- src/changes/changes.xml | 5 +++++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c2f7ac4f..4529bb84 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,7 @@ on: - 'website*' pull_request: branches: - - 'master' + - 'main' jobs: build: diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index b95a95bc..4314f3f6 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -13,10 +13,10 @@ name: "CodeQL" on: push: - branches: [ master ] + branches: [ main ] pull_request: # The branches below must be a subset of the branches above - branches: [ master ] + branches: [ main ] schedule: - cron: '41 10 * * 3' diff --git a/pom.xml b/pom.xml index 6dc4cd8b..7f427990 100644 --- a/pom.xml +++ b/pom.xml @@ -152,7 +152,7 @@ BSD 3-clause - https://raw.githubusercontent.com/ThreeTen/threeten-extra/master/LICENSE.txt + https://raw.githubusercontent.com/ThreeTen/threeten-extra/main/LICENSE.txt repo diff --git a/src/changes/changes.xml b/src/changes/changes.xml index f12a0a12..47e058a3 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,6 +7,11 @@ + + + Switch master to main. + + Add utilities to work with durations as numbers. From dee0fed1363981c8657c2e0863717283a6f6010e Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sat, 17 Dec 2022 23:44:52 +0000 Subject: [PATCH 257/279] Integrate CodeQl into main build (#245) --- .github/workflows/build.yml | 21 ++++++++- .github/workflows/codeql-analysis.yml | 67 --------------------------- src/changes/changes.xml | 7 +++ 3 files changed, 26 insertions(+), 69 deletions(-) delete mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4529bb84..5eb595c8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,9 +10,16 @@ on: pull_request: branches: - 'main' + schedule: + - cron: '41 19 * * 2' + +permissions: + contents: read jobs: build: + permissions: + security-events: write # for github/codeql-action runs-on: ubuntu-latest strategy: matrix: @@ -20,10 +27,10 @@ jobs: steps: - name: Checkout - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b #v3.0.2 + uses: actions/checkout@v3 - name: Set up JDK - uses: actions/setup-java@2c7a4878f5d120bd643426d54ae1209b29cc01a3 #v3.4.1 + uses: actions/setup-java@v3 with: java-version: ${{ matrix.java }} distribution: 'temurin' @@ -36,10 +43,20 @@ jobs: mvn --version mkdir -p target + - name: Initialize CodeQL + if: matrix.java == '11' + uses: github/codeql-action/init@v2 + with: + languages: java + - name: Maven build run: | mvn install site + - name: Perform CodeQL Analysis + if: matrix.java == '11' + uses: github/codeql-action/analyze@v2 + - name: Website if: matrix.java == '11' && github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/website') || startsWith(github.ref, 'refs/tags/v')) env: diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 4314f3f6..00000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: [ main ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ main ] - schedule: - - cron: '41 10 * * 3' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - language: [ 'java' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] - # Learn more: - # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v2 - - # â„¹ï¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # âœï¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 47e058a3..9671bca8 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -8,6 +8,13 @@ + + Adds offset for AccountingChronology, which is essential for some retail calendars, particularly the NRF. + Fixes #223, #201. + + + Update CodeQL. + Switch master to main. From d0acb6eb637bb97b3f72bb24bca1ad42facf5881 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sat, 17 Dec 2022 23:54:53 +0000 Subject: [PATCH 258/279] Dependency version update (#246) * Bump github-api from 1.308 to 1.313 Bumps [github-api](https://github.com/hub4j/github-api) from 1.308 to 1.313. - [Release notes](https://github.com/hub4j/github-api/releases) - [Changelog](https://github.com/hub4j/github-api/blob/main/CHANGELOG.md) - [Commits](https://github.com/hub4j/github-api/compare/github-api-1.308...github-api-1.313) --- updated-dependencies: - dependency-name: org.kohsuke:github-api dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Bump spotbugs-maven-plugin from 4.7.2.0 to 4.7.3.0 Bumps [spotbugs-maven-plugin](https://github.com/spotbugs/spotbugs-maven-plugin) from 4.7.2.0 to 4.7.3.0. - [Release notes](https://github.com/spotbugs/spotbugs-maven-plugin/releases) - [Commits](https://github.com/spotbugs/spotbugs-maven-plugin/compare/spotbugs-maven-plugin-4.7.2.0...spotbugs-maven-plugin-4.7.3.0) --- updated-dependencies: - dependency-name: com.github.spotbugs:spotbugs-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] * Bump maven-plugin-plugin from 3.6.4 to 3.7.0 Bumps [maven-plugin-plugin](https://github.com/apache/maven-plugin-tools) from 3.6.4 to 3.7.0. - [Release notes](https://github.com/apache/maven-plugin-tools/releases) - [Commits](https://github.com/apache/maven-plugin-tools/compare/maven-plugin-tools-3.6.4...maven-plugin-tools-3.7.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-plugin-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Bump maven-install-plugin from 3.0.1 to 3.1.0 Bumps [maven-install-plugin](https://github.com/apache/maven-install-plugin) from 3.0.1 to 3.1.0. - [Release notes](https://github.com/apache/maven-install-plugin/releases) - [Commits](https://github.com/apache/maven-install-plugin/compare/maven-install-plugin-3.0.1...maven-install-plugin-3.1.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-install-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Bump junit-pioneer from 1.7.1 to 1.9.1 Bumps [junit-pioneer](https://github.com/junit-pioneer/junit-pioneer) from 1.7.1 to 1.9.1. - [Release notes](https://github.com/junit-pioneer/junit-pioneer/releases) - [Commits](https://github.com/junit-pioneer/junit-pioneer/compare/v1.7.1...v1.9.1) --- updated-dependencies: - dependency-name: org.junit-pioneer:junit-pioneer dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Bump maven-dependency-plugin from 3.3.0 to 3.4.0 Bumps [maven-dependency-plugin](https://github.com/apache/maven-dependency-plugin) from 3.3.0 to 3.4.0. - [Release notes](https://github.com/apache/maven-dependency-plugin/releases) - [Commits](https://github.com/apache/maven-dependency-plugin/compare/maven-dependency-plugin-3.3.0...maven-dependency-plugin-3.4.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-dependency-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 7f427990..e01cc8d9 100644 --- a/pom.xml +++ b/pom.xml @@ -917,7 +917,7 @@ 2.2.2 5.9.1 - 1.7.1 + 1.9.1 31.1-jre 3.4.2 @@ -927,14 +927,14 @@ 3.2.0 3.10.1 3.0.0 - 3.3.0 + 3.4.0 3.1.0 3.0.1 - 3.0.1 + 3.1.0 3.3.0 3.4.1 3.3.0 - 3.6.4 + 3.7.0 3.19.0 3.4.1 2.5.3 @@ -946,12 +946,12 @@ 3.0.0-M7 3.1.0 - 1.308 + 1.313 1.4.0 0.8.8 1.6.13 1.2 - 4.7.2.0 + 4.7.3.0 1.8 1.8 From 3ccca7af1535855a1a29ea084b6916b02839a5ab Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 18 Dec 2022 00:18:06 +0000 Subject: [PATCH 259/279] Prepare for release --- README.md | 4 ++-- src/changes/changes.xml | 2 +- src/site/markdown/index.md | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 98c19bb0..c286bae8 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Various documentation is available: ### Releases -Release 1.7.1 is the current release. +Release 1.7.2 is the current release. This release is considered stable and worthy of the 1.x tag as per [SemVer](https://semver.org/spec/v2.0.0.html). ThreeTen-Extra requires Java SE 8 or later and has no dependencies. @@ -28,7 +28,7 @@ Available in the [Maven Central repository](https://search.maven.org/search?q=g: org.threeten threeten-extra - 1.7.1 + 1.7.2 ``` diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 9671bca8..dab6a9b5 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,7 +7,7 @@ - + Adds offset for AccountingChronology, which is essential for some retail calendars, particularly the NRF. Fixes #223, #201. diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index 3d0a23f6..bc23ba3f 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -52,7 +52,7 @@ Various documentation is available: ## Releases -Release 1.7.1 is the current release. +Release 1.7.2 is the current release. This release is considered stable and worthy of the 1.x tag as per [SemVer](https://semver.org/spec/v2.0.0.html). ThreeTen-Extra requires Java SE 8 or later and has no [dependencies](dependencies.html). @@ -63,7 +63,7 @@ Available in [Maven Central](https://search.maven.org/search?q=g:org.threeten%20 org.threeten threeten-extra - 1.7.1 + 1.7.2 ``` From 8cfa5305f2e4327558159494308a92c9ec10b56b Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 18 Dec 2022 00:20:05 +0000 Subject: [PATCH 260/279] [maven-release-plugin] prepare release v1.7.2 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e01cc8d9..2f90a885 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.7.2-SNAPSHOT + 1.7.2 Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later https://www.threeten.org/threeten-extra @@ -160,7 +160,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git https://github.com/ThreeTen/threeten-extra - HEAD + v1.7.2 ThreeTen.org From dae68616d7fc6b17877cd672899b56a48a1d359d Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 18 Dec 2022 00:20:10 +0000 Subject: [PATCH 261/279] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 2f90a885..553ca442 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.7.2 + 1.7.3-SNAPSHOT Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later https://www.threeten.org/threeten-extra @@ -160,7 +160,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git https://github.com/ThreeTen/threeten-extra - v1.7.2 + HEAD ThreeTen.org From cf068d0e4482375fd6ccb678558c543513fdd431 Mon Sep 17 00:00:00 2001 From: cxzl25 Date: Wed, 15 Feb 2023 19:01:42 +0800 Subject: [PATCH 262/279] maven-compiler-plugin set createMissingPackageInfoClass to false (#260) --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 553ca442..79cdf000 100644 --- a/pom.xml +++ b/pom.xml @@ -809,6 +809,7 @@ 8 + false From 57e478945f9cfb099b982bc93bc1b0c27bf35bb8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 9 Jul 2023 10:07:20 +0100 Subject: [PATCH 263/279] Bump github-api from 1.313 to 1.314 (#266) Bumps [github-api](https://github.com/hub4j/github-api) from 1.313 to 1.314. - [Release notes](https://github.com/hub4j/github-api/releases) - [Changelog](https://github.com/hub4j/github-api/blob/main/CHANGELOG.md) - [Commits](https://github.com/hub4j/github-api/compare/github-api-1.313...github-api-1.314) --- updated-dependencies: - dependency-name: org.kohsuke:github-api dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 79cdf000..53d12ef3 100644 --- a/pom.xml +++ b/pom.xml @@ -947,7 +947,7 @@ 3.0.0-M7 3.1.0 - 1.313 + 1.314 1.4.0 0.8.8 1.6.13 From a214f26f1a306cd7b60e0b9c723a57a5d49c0224 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Aug 2023 09:13:45 +0100 Subject: [PATCH 264/279] Bump com.google.guava:guava from 31.1-jre to 32.1.2-jre (#287) Bumps [com.google.guava:guava](https://github.com/google/guava) from 31.1-jre to 32.1.2-jre. - [Release notes](https://github.com/google/guava/releases) - [Commits](https://github.com/google/guava/commits) --- updated-dependencies: - dependency-name: com.google.guava:guava dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 53d12ef3..721251df 100644 --- a/pom.xml +++ b/pom.xml @@ -919,7 +919,7 @@ 2.2.2 5.9.1 1.9.1 - 31.1-jre + 32.1.2-jre 3.4.2 5.1.8 From 5c05605d0af9de866c68ca4976c0cf5961efd615 Mon Sep 17 00:00:00 2001 From: Roberto Tyley Date: Sat, 23 Sep 2023 22:15:47 +0100 Subject: [PATCH 265/279] Add `Interval.of(duration, end)` (#294) This is the mirror of the existing method: ``` Interval.of(start, duration) ``` ...but for easily getting an `Interval` that ends at a known instant, with a known duration! This kind of interval is quite often handy in realtime analytics ("give me the last 30 minutes of results"). --- .../java/org/threeten/extra/Interval.java | 22 +++++++++++++ .../java/org/threeten/extra/TestInterval.java | 32 ++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/threeten/extra/Interval.java b/src/main/java/org/threeten/extra/Interval.java index f7b2a8cf..3b50b7c4 100644 --- a/src/main/java/org/threeten/extra/Interval.java +++ b/src/main/java/org/threeten/extra/Interval.java @@ -129,6 +129,28 @@ public static Interval of(Instant startInclusive, Duration duration) { return new Interval(startInclusive, startInclusive.plus(duration)); } + /** + * Obtains an instance of {@code Interval} from the duration and the end. + *

      + * The start instant is calculated as the end minus the duration. + * The duration must not be negative. + * + * @param duration the duration from the start to the end, not null + * @param endExclusive the end instant, exclusive, not null + * @return the interval, not null + * @throws DateTimeException if the end is before the start, + * or if the duration addition cannot be made + * @throws ArithmeticException if numeric overflow occurs when subtracting the duration + */ + public static Interval of(Duration duration, Instant endExclusive) { + Objects.requireNonNull(duration, "duration"); + Objects.requireNonNull(endExclusive, "endExclusive"); + if (duration.isNegative()) { + throw new DateTimeException("Duration must not be negative"); + } + return new Interval(endExclusive.minus(duration), endExclusive); + } + /** * Obtains an instance of {@code Interval} with the specified start instant and unbounded end. * diff --git a/src/test/java/org/threeten/extra/TestInterval.java b/src/test/java/org/threeten/extra/TestInterval.java index d7b698cd..7eaaba60 100644 --- a/src/test/java/org/threeten/extra/TestInterval.java +++ b/src/test/java/org/threeten/extra/TestInterval.java @@ -129,7 +129,7 @@ public void test_of_Instant_Instant_badOrder() { @Test public void test_of_Instant_Instant_nullStart() { - assertThrows(NullPointerException.class, () -> Interval.of(null, NOW2)); + assertThrows(NullPointerException.class, () -> Interval.of((Instant) null, NOW2)); } @Test @@ -167,6 +167,36 @@ public void test_of_Instant_Duration_nullDuration() { assertThrows(NullPointerException.class, () -> Interval.of(NOW1, (Duration) null)); } + //----------------------------------------------------------------------- + @Test + public void test_of_Duration_Instant() { + Interval test = Interval.of(Duration.ofSeconds(60), NOW2); + assertEquals(NOW1, test.getStart()); + assertEquals(NOW2, test.getEnd()); + } + + @Test + public void test_of_Duration_Instant_zero() { + Interval test = Interval.of(Duration.ZERO, NOW1); + assertEquals(NOW1, test.getStart()); + assertEquals(NOW1, test.getEnd()); + } + + @Test + public void test_of_Duration_Instant_negative() { + assertThrows(DateTimeException.class, () -> Interval.of(Duration.ofSeconds(-1), NOW2)); + } + + @Test + public void test_of_Duration_Instant_nullInstant() { + assertThrows(NullPointerException.class, () -> Interval.of(Duration.ZERO, null)); + } + + @Test + public void test_of_Duration_Instant_nullDuration() { + assertThrows(NullPointerException.class, () -> Interval.of((Duration) null, NOW1)); + } + //----------------------------------------------------------------------- @Test public void test_startingAt_Instant_createsUnboundedEnd() { From 8b419fd11687500551c1d54623948c9fb3d0dd0e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 23 Sep 2023 21:37:53 +0000 Subject: [PATCH 266/279] Bump joda-convert from 2.2.2 to 2.2.3 (#248) Bumps [joda-convert](https://github.com/JodaOrg/joda-convert) from 2.2.2 to 2.2.3. - [Release notes](https://github.com/JodaOrg/joda-convert/releases) - [Changelog](https://github.com/JodaOrg/joda-convert/blob/main/RELEASE-NOTES.txt) - [Commits](https://github.com/JodaOrg/joda-convert/compare/v2.2.2...v2.2.3) --- updated-dependencies: - dependency-name: org.joda:joda-convert dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 721251df..775024e9 100644 --- a/pom.xml +++ b/pom.xml @@ -916,7 +916,7 @@ - 2.2.2 + 2.2.3 5.9.1 1.9.1 32.1.2-jre From 6d506d4f50195d6752223d99f7f19bd53e3c5f6b Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Thu, 2 Nov 2023 11:58:02 +0000 Subject: [PATCH 267/279] Update FUNDING.yml --- .github/FUNDING.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index a7e0ee6f..ff30e87e 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,7 +1,5 @@ +github: jodastephen open_collective: joda tidelift: maven/org.threeten:threeten-extra -# github: [jodastephen] -# patreon: # Replace with a single Patreon username -# ko_fi: # Replace with a single Ko-fi username -# custom: # Replace with a single custom sponsorship URL +# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/displaying-a-sponsor-button-in-your-repository From 54e3d4f61852bbfa4aa14f068cef6aceb55a7c5f Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Sun, 12 Nov 2023 19:45:14 +0000 Subject: [PATCH 268/279] Half years (#303) * Add support for half-years Fixes #200 --- src/main/java/org/threeten/extra/Half.java | 454 ++++++ src/main/java/org/threeten/extra/Quarter.java | 12 +- .../org/threeten/extra/TemporalFields.java | 376 +++++ .../java/org/threeten/extra/YearHalf.java | 1288 +++++++++++++++++ .../java/org/threeten/extra/YearQuarter.java | 18 +- .../java/org/threeten/extra/TestHalf.java | 405 ++++++ .../threeten/extra/TestTemporalFields.java | 268 ++++ .../java/org/threeten/extra/TestYearHalf.java | 999 +++++++++++++ 8 files changed, 3804 insertions(+), 16 deletions(-) create mode 100644 src/main/java/org/threeten/extra/Half.java create mode 100644 src/main/java/org/threeten/extra/TemporalFields.java create mode 100644 src/main/java/org/threeten/extra/YearHalf.java create mode 100644 src/test/java/org/threeten/extra/TestHalf.java create mode 100644 src/test/java/org/threeten/extra/TestTemporalFields.java create mode 100644 src/test/java/org/threeten/extra/TestYearHalf.java diff --git a/src/main/java/org/threeten/extra/Half.java b/src/main/java/org/threeten/extra/Half.java new file mode 100644 index 00000000..99d63561 --- /dev/null +++ b/src/main/java/org/threeten/extra/Half.java @@ -0,0 +1,454 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.extra; + +import static java.time.temporal.ChronoField.MONTH_OF_YEAR; +import static org.threeten.extra.TemporalFields.HALF_OF_YEAR; +import static org.threeten.extra.TemporalFields.HALF_YEARS; + +import java.time.DateTimeException; +import java.time.LocalDate; +import java.time.Month; +import java.time.chrono.Chronology; +import java.time.chrono.IsoChronology; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.TextStyle; +import java.time.temporal.ChronoField; +import java.time.temporal.Temporal; +import java.time.temporal.TemporalAccessor; +import java.time.temporal.TemporalAdjuster; +import java.time.temporal.TemporalField; +import java.time.temporal.TemporalQueries; +import java.time.temporal.TemporalQuery; +import java.time.temporal.UnsupportedTemporalTypeException; +import java.time.temporal.ValueRange; +import java.util.Locale; + +/** + * A half-of-year, such as 'H2'. + *

      + * {@code Half} is an enum representing the 2 halves of the year - H1 and H2. + * These are defined as January to June and July to December. + *

      + * The {@code int} value follows the half, from 1 (H1) to 2 (H2). + * It is recommended that applications use the enum rather than the {@code int} value + * to ensure code clarity. + *

      + * Do not use {@code ordinal()} to obtain the numeric representation of {@code Half}. + * Use {@code getValue()} instead. + * + *

      Implementation Requirements:

      + * This is an immutable and thread-safe enum. + */ +public enum Half implements TemporalAccessor, TemporalAdjuster { + + /** + * The singleton instance for the first half-of-year, from January to June. + * This has the numeric value of {@code 1}. + */ + H1, + /** + * The singleton instance for the second half-of-year, from July to December. + * This has the numeric value of {@code 2}. + */ + H2; + + //----------------------------------------------------------------------- + /** + * Obtains an instance of {@code Half} from an {@code int} value. + *

      + * {@code Half} is an enum representing the 2 halves of the year. + * This factory allows the enum to be obtained from the {@code int} value. + * The {@code int} value follows the half, from 1 (H1) to 2 (H2). + * + * @param halfOfYear the half-of-year to represent, from 1 (H1) to 2 (H2) + * @return the half-of-year, not null + * @throws DateTimeException if the half-of-year is invalid + */ + public static Half of(int halfOfYear) { + switch (halfOfYear) { + case 1: + return H1; + case 2: + return H2; + default: + throw new DateTimeException("Invalid value for Half: " + halfOfYear); + } + } + + /** + * Obtains an instance of {@code Half} from a month-of-year. + *

      + * {@code Half} is an enum representing the 2 halves of the year. + * This factory allows the enum to be obtained from the {@code Month} value. + *

      + * January to June are H1 and July to December are H2. + * + * @param monthOfYear the month-of-year to convert from, from 1 to 12 + * @return the half-of-year, not null + * @throws DateTimeException if the month-of-year is invalid + */ + public static Half ofMonth(int monthOfYear) { + MONTH_OF_YEAR.range().checkValidValue(monthOfYear, MONTH_OF_YEAR); + return of(monthOfYear <= 6 ? 1 : 2); + } + + //----------------------------------------------------------------------- + /** + * Obtains an instance of {@code Half} from a temporal object. + *

      + * This obtains a half based on the specified temporal. + * A {@code TemporalAccessor} represents an arbitrary set of date and time information, + * which this factory converts to an instance of {@code Half}. + *

      + * The conversion extracts the {@link TemporalFields#HALF_OF_YEAR HALF_OF_YEAR} field. + * The extraction is only permitted if the temporal object has an ISO + * chronology, or can be converted to a {@code LocalDate}. + *

      + * This method matches the signature of the functional interface {@link TemporalQuery} + * allowing it to be used in queries via method reference, {@code Half::from}. + * + * @param temporal the temporal-time object to convert, not null + * @return the half-of-year, not null + * @throws DateTimeException if unable to convert to a {@code Half} + */ + public static Half from(TemporalAccessor temporal) { + if (temporal instanceof Half) { + return (Half) temporal; + } else if (temporal instanceof Month) { + Month month = (Month) temporal; + return of(month.ordinal() / 6 + 1); + } + try { + TemporalAccessor adjusted = + !IsoChronology.INSTANCE.equals(Chronology.from(temporal)) ? LocalDate.from(temporal) : temporal; + // need to use getLong() as JDK Parsed class get() doesn't work properly + int qoy = Math.toIntExact(adjusted.getLong(HALF_OF_YEAR)); + return of(qoy); + } catch (DateTimeException ex) { + throw new DateTimeException("Unable to obtain Half from TemporalAccessor: " + + temporal + " of type " + temporal.getClass().getName(), ex); + } + } + + //----------------------------------------------------------------------- + /** + * Gets the half-of-year {@code int} value. + *

      + * The values are numbered following the ISO-8601 standard, + * from 1 (H1) to 2 (H2). + * + * @return the half-of-year, from 1 (H1) to 2 (H2) + */ + public int getValue() { + return ordinal() + 1; + } + + //----------------------------------------------------------------------- + /** + * Gets the textual representation, such as 'H1' or '4th half'. + *

      + * This returns the textual name used to identify the half-of-year, + * suitable for presentation to the user. + * The parameters control the style of the returned text and the locale. + *

      + * If no textual mapping is found then the {@link #getValue() numeric value} is returned. + * + * @param style the length of the text required, not null + * @param locale the locale to use, not null + * @return the text value of the half-of-year, not null + */ + public String getDisplayName(TextStyle style, Locale locale) { + return new DateTimeFormatterBuilder().appendText(HALF_OF_YEAR, style).toFormatter(locale).format(this); + } + + //----------------------------------------------------------------------- + /** + * Checks if the specified field is supported. + *

      + * This checks if this half-of-year can be queried for the specified field. + * If false, then calling the {@link #range(TemporalField) range} and + * {@link #get(TemporalField) get} methods will throw an exception. + *

      + * If the field is {@link TemporalFields#HALF_OF_YEAR HALF_OF_YEAR} then + * this method returns true. + * All {@code ChronoField} instances will return false. + *

      + * If the field is not a {@code ChronoField}, then the result of this method + * is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)} + * passing {@code this} as the argument. + * Whether the field is supported is determined by the field. + * + * @param field the field to check, null returns false + * @return true if the field is supported on this half-of-year, false if not + */ + @Override + public boolean isSupported(TemporalField field) { + if (field == HALF_OF_YEAR) { + return true; + } else if (field instanceof ChronoField) { + return false; + } + return field != null && field.isSupportedBy(this); + } + + /** + * Gets the range of valid values for the specified field. + *

      + * The range object expresses the minimum and maximum valid values for a field. + * This half is used to enhance the accuracy of the returned range. + * If it is not possible to return the range, because the field is not supported + * or for some other reason, an exception is thrown. + *

      + * If the field is {@link TemporalFields#HALF_OF_YEAR HALF_OF_YEAR} then the + * range of the half-of-year, from 1 to 2, will be returned. + * All {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. + *

      + * If the field is not a {@code ChronoField}, then the result of this method + * is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessor)} + * passing {@code this} as the argument. + * Whether the range can be obtained is determined by the field. + * + * @param field the field to query the range for, not null + * @return the range of valid values for the field, not null + * @throws DateTimeException if the range for the field cannot be obtained + * @throws UnsupportedTemporalTypeException if the field is not supported + */ + @Override + public ValueRange range(TemporalField field) { + if (field == HALF_OF_YEAR) { + return field.range(); + } else if (field instanceof ChronoField) { + throw new UnsupportedTemporalTypeException("Unsupported field: " + field); + } + return TemporalAccessor.super.range(field); + } + + /** + * Gets the value of the specified field from this half-of-year as an {@code int}. + *

      + * This queries this half for the value for the specified field. + * The returned value will always be within the valid range of values for the field. + * If it is not possible to return the value, because the field is not supported + * or for some other reason, an exception is thrown. + *

      + * If the field is {@link TemporalFields#HALF_OF_YEAR HALF_OF_YEAR} then the + * value of the half-of-year, from 1 to 2, will be returned. + * All {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. + *

      + * If the field is not a {@code ChronoField}, then the result of this method + * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} + * passing {@code this} as the argument. Whether the value can be obtained, + * and what the value represents, is determined by the field. + * + * @param field the field to get, not null + * @return the value for the field, within the valid range of values + * @throws DateTimeException if a value for the field cannot be obtained or + * the value is outside the range of valid values for the field + * @throws UnsupportedTemporalTypeException if the field is not supported or + * the range of values exceeds an {@code int} + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public int get(TemporalField field) { + if (field == HALF_OF_YEAR) { + return getValue(); + } else if (field instanceof ChronoField) { + throw new UnsupportedTemporalTypeException("Unsupported field: " + field); + } + return TemporalAccessor.super.get(field); + } + + /** + * Gets the value of the specified field from this half-of-year as a {@code long}. + *

      + * This queries this half for the value for the specified field. + * If it is not possible to return the value, because the field is not supported + * or for some other reason, an exception is thrown. + *

      + * If the field is {@link TemporalFields#HALF_OF_YEAR HALF_OF_YEAR} then the + * value of the half-of-year, from 1 to 2, will be returned. + * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. + *

      + * If the field is not a {@code ChronoField}, then the result of this method + * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} + * passing {@code this} as the argument. Whether the value can be obtained, + * and what the value represents, is determined by the field. + * + * @param field the field to get, not null + * @return the value for the field + * @throws DateTimeException if a value for the field cannot be obtained + * @throws UnsupportedTemporalTypeException if the field is not supported + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public long getLong(TemporalField field) { + if (field == HALF_OF_YEAR) { + return getValue(); + } else if (field instanceof ChronoField) { + throw new UnsupportedTemporalTypeException("Unsupported field: " + field); + } + return field.getFrom(this); + } + + //----------------------------------------------------------------------- + /** + * Returns the half that is the specified number of halves after this one. + *

      + * The calculation rolls around the end of the year from H2 to H1. + * The specified period may be negative. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param halves the halves to add, positive or negative + * @return the resulting half, not null + */ + public Half plus(long halves) { + int amount = (int) halves % 2; + return values()[(ordinal() + (amount + 2)) % 2]; + } + + /** + * Returns the half that is the specified number of halves before this one. + *

      + * The calculation rolls around the start of the year from H1 to H2. + * The specified period may be negative. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param halves the halves to subtract, positive or negative + * @return the resulting half, not null + */ + public Half minus(long halves) { + return plus(-(halves % 2)); + } + + //----------------------------------------------------------------------- + /** + * Gets the length of this half in days. + *

      + * This takes a flag to determine whether to return the length for a leap year or not. + *

      + * H1 has 181 in a standard year and 182 days in a leap year. + * H2 has 184 days. + * + * @param leapYear true if the length is required for a leap year + * @return the length of this month in days, 181, 182 or 184 + */ + public int length(boolean leapYear) { + return this == H1 ? (leapYear ? 182 : 181) : 184; + } + + //----------------------------------------------------------------------- + /** + * Gets the first of the six months that this half refers to. + *

      + * H1 will return January.
      + * H2 will return July. + * + * @return the first month in the half, not null + */ + public Month firstMonth() { + return this == H1 ? Month.JANUARY : Month.JULY; + } + + //----------------------------------------------------------------------- + /** + * Queries this half-of-year using the specified query. + *

      + * This queries this half-of-year using the specified query strategy object. + * The {@code TemporalQuery} object defines the logic to be used to + * obtain the result. Read the documentation of the query to understand + * what the result of this method will be. + *

      + * The result of this method is obtained by invoking the + * {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the + * specified query passing {@code this} as the argument. + * + * @param the type of the result + * @param query the query to invoke, not null + * @return the query result, null may be returned (defined by the query) + * @throws DateTimeException if unable to query (defined by the query) + * @throws ArithmeticException if numeric overflow occurs (defined by the query) + */ + @SuppressWarnings("unchecked") + @Override + public R query(TemporalQuery query) { + if (query == TemporalQueries.chronology()) { + return (R) IsoChronology.INSTANCE; + } else if (query == TemporalQueries.precision()) { + return (R) HALF_YEARS; + } + return TemporalAccessor.super.query(query); + } + + /** + * Adjusts the specified temporal object to have this half-of-year. + *

      + * This returns a temporal object of the same observable type as the input + * with the half-of-year changed to be the same as this. + *

      + * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)} + * passing {@link TemporalFields#HALF_OF_YEAR} as the field. + * If the specified temporal object does not use the ISO calendar system then + * a {@code DateTimeException} is thrown. + *

      + * In most cases, it is clearer to reverse the calling pattern by using + * {@link Temporal#with(TemporalAdjuster)}: + *

      +     *   // these two lines are equivalent, but the second approach is recommended
      +     *   temporal = thisHalf.adjustInto(temporal);
      +     *   temporal = temporal.with(thisHalf);
      +     * 
      + *

      + * For example, given a date in May, the following are output: + *

      +     *   dateInMay.with(H1);    // no change
      +     *   dateInMay.with(H2);    // six months later
      +     * 
      + *

      + * This instance is immutable and unaffected by this method call. + * + * @param temporal the target object to be adjusted, not null + * @return the adjusted object, not null + * @throws DateTimeException if unable to make the adjustment + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public Temporal adjustInto(Temporal temporal) { + if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) { + throw new DateTimeException("Adjustment only supported on ISO date-time"); + } + return temporal.with(HALF_OF_YEAR, getValue()); + } + +} diff --git a/src/main/java/org/threeten/extra/Quarter.java b/src/main/java/org/threeten/extra/Quarter.java index 4d60561f..04265ce8 100644 --- a/src/main/java/org/threeten/extra/Quarter.java +++ b/src/main/java/org/threeten/extra/Quarter.java @@ -57,9 +57,8 @@ /** * A quarter-of-year, such as 'Q2'. *

      - * {@code Quarter} is an enum representing the 4 quarters of the year - - * Q1, Q2, Q3 and Q4. These are defined as January to March, April to June, - * July to September and October to December. + * {@code Quarter} is an enum representing the 4 quarters of the year - Q1, Q2, Q3 and Q4. + * These are defined as January to March, April to June, July to September and October to December. *

      * The {@code int} value follows the quarter, from 1 (Q1) to 4 (Q4). * It is recommended that applications use the enum rather than the {@code int} value @@ -170,11 +169,10 @@ public static Quarter from(TemporalAccessor temporal) { return of(month.ordinal() / 3 + 1); } try { - if (IsoChronology.INSTANCE.equals(Chronology.from(temporal)) == false) { - temporal = LocalDate.from(temporal); - } + TemporalAccessor adjusted = + !IsoChronology.INSTANCE.equals(Chronology.from(temporal)) ? LocalDate.from(temporal) : temporal; // need to use getLong() as JDK Parsed class get() doesn't work properly - int qoy = Math.toIntExact(temporal.getLong(QUARTER_OF_YEAR)); + int qoy = Math.toIntExact(adjusted.getLong(QUARTER_OF_YEAR)); return of(qoy); } catch (DateTimeException ex) { throw new DateTimeException("Unable to obtain Quarter from TemporalAccessor: " + diff --git a/src/main/java/org/threeten/extra/TemporalFields.java b/src/main/java/org/threeten/extra/TemporalFields.java new file mode 100644 index 00000000..d2d207ef --- /dev/null +++ b/src/main/java/org/threeten/extra/TemporalFields.java @@ -0,0 +1,376 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.extra; + +import static java.time.temporal.ChronoField.DAY_OF_YEAR; +import static java.time.temporal.ChronoField.MONTH_OF_YEAR; +import static java.time.temporal.ChronoField.YEAR; +import static java.time.temporal.ChronoUnit.DAYS; +import static java.time.temporal.ChronoUnit.YEARS; +import static java.time.temporal.IsoFields.QUARTER_OF_YEAR; +import static java.time.temporal.IsoFields.QUARTER_YEARS; + +import java.time.DateTimeException; +import java.time.Duration; +import java.time.LocalDate; +import java.time.chrono.ChronoLocalDate; +import java.time.chrono.IsoChronology; +import java.time.format.ResolverStyle; +import java.time.temporal.Temporal; +import java.time.temporal.TemporalAccessor; +import java.time.temporal.TemporalField; +import java.time.temporal.TemporalUnit; +import java.time.temporal.UnsupportedTemporalTypeException; +import java.time.temporal.ValueRange; +import java.util.Map; + +/** + * Additional Temporal fields. + *

      + * This provides additional fields and units not in the JDK. + */ +public final class TemporalFields { + + /** + * The field that represents the day-of-half. + *

      + * This field allows the day-of-half value to be queried and set. + * The day-of-half has values from 1 to 181 in H1 of a standard year, from 1 to 182 + * in H1 of a leap year and from 1 to 184 in H2. + *

      + * The day-of-half can only be calculated if the day-of-year, month-of-year and year + * are available. + *

      + * When setting this field, the value is allowed to be partially lenient, taking any + * value from 1 to 184. If the half has less than 184 days, then the day will end up + * in the following half-year. + *

      + * In the resolving phase of parsing, a date can be created from a year, + * half-of-year and day-of-half. + *

      + * In {@linkplain ResolverStyle#STRICT strict mode}, all three fields are + * validated against their range of valid values. The day-of-half field + * is validated from 1 to 181, 182 or 184 depending on the year and half. + *

      + * In {@linkplain ResolverStyle#SMART smart mode}, all three fields are + * validated against their range of valid values. The day-of-half field is + * validated between 1 and 184, ignoring the actual range based on the year and half. + * If the day-of-half exceeds the actual range, then the resulting date is in the next half-year. + *

      + * In {@linkplain ResolverStyle#LENIENT lenient mode}, only the year is validated + * against the range of valid values. The resulting date is calculated equivalent to + * the following three stage approach. First, create a date on the first of January + * in the requested year. Then take the half-of-year, subtract one, and add the + * amount in halves to the date. Finally, take the day-of-half, subtract one, + * and add the amount in days to the date. + *

      + * This unit is an immutable and thread-safe singleton. + */ + public static final TemporalField DAY_OF_HALF = DayOfHalfField.INSTANCE; + /** + * The field that represents the half-of-year. + *

      + * This field allows the half-of-year value to be queried and set. + * The half-of-year has values from 1 to 2. + *

      + * The half-of-year can only be calculated if the month-of-year is available. + *

      + * In the resolving phase of parsing, a date can be created from a year, + * half-of-year and day-of-half. + * See {@link #DAY_OF_HALF} for details. + *

      + * This unit is an immutable and thread-safe singleton. + */ + public static final TemporalField HALF_OF_YEAR = HalfOfYearField.INSTANCE; + /** + * Unit that represents the concept of a half-year. + * For the ISO calendar system, it is equal to 6 months. + * The estimated duration of a half-year is one half of {@code 365.2425 Days}. + *

      + * This unit is an immutable and thread-safe singleton. + */ + public static final TemporalUnit HALF_YEARS = HalfUnit.INSTANCE; + + /** + * Restricted constructor. + */ + private TemporalFields() { + } + + //------------------------------------------------------------------------- + /** + * Implementation of day-of-half. + */ + private static enum DayOfHalfField implements TemporalField { + INSTANCE; + + private static final ValueRange RANGE = ValueRange.of(1, 181, 184); + private static final long serialVersionUID = 262362728L; + + //----------------------------------------------------------------------- + @Override + public TemporalUnit getBaseUnit() { + return DAYS; + } + + @Override + public TemporalUnit getRangeUnit() { + return HALF_YEARS; + } + + @Override + public boolean isDateBased() { + return true; + } + + @Override + public boolean isTimeBased() { + return false; + } + + @Override + public ValueRange range() { + return RANGE; + } + + //----------------------------------------------------------------------- + @Override + public boolean isSupportedBy(TemporalAccessor temporal) { + return temporal.isSupported(DAY_OF_YEAR) && + temporal.isSupported(MONTH_OF_YEAR) && + temporal.isSupported(YEAR); + } + + @Override + public ValueRange rangeRefinedBy(TemporalAccessor temporal) { + if (!temporal.isSupported(this)) { + throw new DateTimeException("Unsupported field: DayOfHalf"); + } + long hoy = temporal.getLong(HALF_OF_YEAR); + if (hoy == 1) { + long year = temporal.getLong(YEAR); + return (IsoChronology.INSTANCE.isLeapYear(year) ? ValueRange.of(1, 182) : ValueRange.of(1, 181)); + } else if (hoy == 2) { + return ValueRange.of(1, 184); + } // else value not from 1 to 2, so drop through + return range(); + } + + @Override + public long getFrom(TemporalAccessor temporal) { + if (isSupportedBy(temporal) == false) { + throw new UnsupportedTemporalTypeException("Unsupported field: DayOfHalf"); + } + int doy = temporal.get(DAY_OF_YEAR); + int moy = temporal.get(MONTH_OF_YEAR); + long year = temporal.getLong(YEAR); + return moy <= 6 ? doy : doy - 181 - (IsoChronology.INSTANCE.isLeapYear(year) ? 1 : 0); + } + + @SuppressWarnings("unchecked") + @Override + public R adjustInto(R temporal, long newValue) { + // calls getFrom() to check if supported + long curValue = getFrom(temporal); + range().checkValidValue(newValue, this); // leniently check from 1 to 184 + return (R) temporal.with(DAY_OF_YEAR, temporal.getLong(DAY_OF_YEAR) + (newValue - curValue)); + } + + //----------------------------------------------------------------------- + @Override + public ChronoLocalDate resolve( + Map fieldValues, + TemporalAccessor partialTemporal, + ResolverStyle resolverStyle) { + + Long yearLong = fieldValues.get(YEAR); + Long hoyLong = fieldValues.get(HALF_OF_YEAR); + if (yearLong == null || hoyLong == null) { + return null; + } + int y = YEAR.checkValidIntValue(yearLong); // always validate + long doh = fieldValues.get(DAY_OF_HALF); + LocalDate date; + if (resolverStyle == ResolverStyle.LENIENT) { + date = LocalDate.of(y, 1, 1).plusMonths(Math.multiplyExact(Math.subtractExact(hoyLong, 1), 6)); + doh = Math.subtractExact(doh, 1); + } else { + int qoy = HALF_OF_YEAR.range().checkValidIntValue(hoyLong, HALF_OF_YEAR); // validated + date = LocalDate.of(y, ((qoy - 1) * 6) + 1, 1); + if (doh < 1 || doh > 181) { + if (resolverStyle == ResolverStyle.STRICT) { + rangeRefinedBy(date).checkValidValue(doh, this); // only allow exact range + } else { // SMART + range().checkValidValue(doh, this); // allow 1-184 rolling into next quarter + } + } + doh--; + } + fieldValues.remove(this); + fieldValues.remove(YEAR); + fieldValues.remove(HALF_OF_YEAR); + return date.plusDays(doh); + } + + //----------------------------------------------------------------------- + @Override + public String toString() { + return "DayOfHalf"; + } + } + + //------------------------------------------------------------------------- + /** + * Implementation of half-of-year. + */ + private static enum HalfOfYearField implements TemporalField { + INSTANCE; + + private static final long serialVersionUID = -29115701L; + + //----------------------------------------------------------------------- + @Override + public TemporalUnit getBaseUnit() { + return HALF_YEARS; + } + + @Override + public TemporalUnit getRangeUnit() { + return YEARS; + } + + @Override + public boolean isDateBased() { + return true; + } + + @Override + public boolean isTimeBased() { + return false; + } + + @Override + public ValueRange range() { + return ValueRange.of(1, 2); + } + + @Override + public boolean isSupportedBy(TemporalAccessor temporal) { + return temporal.isSupported(QUARTER_OF_YEAR); + } + + @Override + public ValueRange rangeRefinedBy(TemporalAccessor temporal) { + return range(); + } + + @Override + public long getFrom(TemporalAccessor temporal) { + if (isSupportedBy(temporal) == false) { + throw new UnsupportedTemporalTypeException("Unsupported field: HalfOfYear"); + } + long qoy = temporal.get(QUARTER_OF_YEAR); + return qoy <= 2 ? 1 : 2; + } + + @SuppressWarnings("unchecked") + @Override + public R adjustInto(R temporal, long newValue) { + // calls getFrom() to check if supported + long curValue = getFrom(temporal); + range().checkValidValue(newValue, this); // strictly check from 1 to 2 + return (R) temporal.with(MONTH_OF_YEAR, temporal.getLong(MONTH_OF_YEAR) + (newValue - curValue) * 6); + } + + @Override + public String toString() { + return "HalfOfYear"; + } + } + + //----------------------------------------------------------------------- + /** + * Implementation of the half-year unit. + */ + private static enum HalfUnit implements TemporalUnit { + + /** + * Unit that represents the concept of a week-based-year. + */ + INSTANCE; + + @Override + public Duration getDuration() { + return Duration.ofSeconds(31556952L / 2); + } + + @Override + public boolean isDurationEstimated() { + return true; + } + + @Override + public boolean isDateBased() { + return true; + } + + @Override + public boolean isTimeBased() { + return false; + } + + @Override + public boolean isSupportedBy(Temporal temporal) { + return temporal.isSupported(QUARTER_OF_YEAR); + } + + @SuppressWarnings("unchecked") + @Override + public R addTo(R temporal, long amount) { + return (R) temporal.plus(Math.multiplyExact(amount, 2), QUARTER_YEARS); + } + + @Override + public long between(Temporal temporal1Inclusive, Temporal temporal2Exclusive) { + if (temporal1Inclusive.getClass() != temporal2Exclusive.getClass()) { + return temporal1Inclusive.until(temporal2Exclusive, this); + } + return temporal1Inclusive.until(temporal2Exclusive, QUARTER_YEARS) / 2; + } + + @Override + public String toString() { + return "HalfYears"; + } + } + +} diff --git a/src/main/java/org/threeten/extra/YearHalf.java b/src/main/java/org/threeten/extra/YearHalf.java new file mode 100644 index 00000000..da889b95 --- /dev/null +++ b/src/main/java/org/threeten/extra/YearHalf.java @@ -0,0 +1,1288 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.extra; + +import static java.time.temporal.ChronoField.ERA; +import static java.time.temporal.ChronoField.YEAR; +import static java.time.temporal.ChronoField.YEAR_OF_ERA; +import static java.time.temporal.ChronoUnit.CENTURIES; +import static java.time.temporal.ChronoUnit.DECADES; +import static java.time.temporal.ChronoUnit.ERAS; +import static java.time.temporal.ChronoUnit.MILLENNIA; +import static java.time.temporal.ChronoUnit.YEARS; +import static org.threeten.extra.TemporalFields.DAY_OF_HALF; +import static org.threeten.extra.TemporalFields.HALF_OF_YEAR; +import static org.threeten.extra.TemporalFields.HALF_YEARS; + +import java.io.Serializable; +import java.time.Clock; +import java.time.DateTimeException; +import java.time.LocalDate; +import java.time.Month; +import java.time.Period; +import java.time.Year; +import java.time.ZoneId; +import java.time.chrono.Chronology; +import java.time.chrono.IsoChronology; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; +import java.time.format.SignStyle; +import java.time.temporal.ChronoField; +import java.time.temporal.ChronoUnit; +import java.time.temporal.Temporal; +import java.time.temporal.TemporalAccessor; +import java.time.temporal.TemporalAdjuster; +import java.time.temporal.TemporalAmount; +import java.time.temporal.TemporalField; +import java.time.temporal.TemporalQueries; +import java.time.temporal.TemporalQuery; +import java.time.temporal.TemporalUnit; +import java.time.temporal.UnsupportedTemporalTypeException; +import java.time.temporal.ValueRange; +import java.util.Objects; +import java.util.stream.LongStream; +import java.util.stream.Stream; + +import org.joda.convert.FromString; +import org.joda.convert.ToString; + +/** + * A year-half in the ISO-8601 calendar system, such as {@code 2007-H2}. + *

      + * {@code YearHalf} is an immutable date-time object that represents the combination + * of a year and a half-year. Any field that can be derived from a year and a half-year can be obtained. + * A half is defined by {@link Half} - H1 and H2. + * H1 is January to June, H2 is July to December. + *

      + * This class does not store or represent a day, time or time-zone. + * For example, the value "2nd half 2007" can be stored in a {@code YearHalf}. + *

      + * The ISO-8601 calendar system is the modern civil calendar system used today + * in most of the world. It is equivalent to the proleptic Gregorian calendar + * system, in which today's rules for leap years are applied for all time. + * For most applications written today, the ISO-8601 rules are entirely suitable. + * However, any application that makes use of historical dates, and requires them + * to be accurate will find the ISO-8601 approach unsuitable. + * Note that the ISO-8601 standard does not define or refer to halfs. + * + *

      Implementation Requirements:

      + * This class is immutable and thread-safe. + *

      + * This class must be treated as a value type. Do not synchronize, rely on the + * identity hash code or use the distinction between equals() and ==. + */ +public final class YearHalf + implements Temporal, TemporalAdjuster, Comparable, Serializable { + + /** + * Serialization version. + */ + private static final long serialVersionUID = 782467825761518L; + /** + * Parser. + */ + private static final DateTimeFormatter PARSER = new DateTimeFormatterBuilder() + .parseCaseInsensitive() + .appendValue(YEAR, 4, 10, SignStyle.EXCEEDS_PAD) + .appendLiteral('-') + .appendLiteral('H') + .appendValue(HALF_OF_YEAR, 1) + .toFormatter(); + + /** + * The year. + */ + private final int year; + /** + * The half-of-year, not null. + */ + private final Half half; + + //----------------------------------------------------------------------- + /** + * Obtains the current year-half from the system clock in the default time-zone. + *

      + * This will query the {@link java.time.Clock#systemDefaultZone() system clock} in the default + * time-zone to obtain the current year-half. + * The zone and offset will be set based on the time-zone in the clock. + *

      + * Using this method will prevent the ability to use an alternate clock for testing + * because the clock is hard-coded. + * + * @return the current year-half using the system clock and default time-zone, not null + */ + public static YearHalf now() { + return now(Clock.systemDefaultZone()); + } + + /** + * Obtains the current year-half from the system clock in the specified time-zone. + *

      + * This will query the {@link Clock#system(java.time.ZoneId) system clock} to obtain the current year-half. + * Specifying the time-zone avoids dependence on the default time-zone. + *

      + * Using this method will prevent the ability to use an alternate clock for testing + * because the clock is hard-coded. + * + * @param zone the zone ID to use, not null + * @return the current year-half using the system clock, not null + */ + public static YearHalf now(ZoneId zone) { + return now(Clock.system(zone)); + } + + /** + * Obtains the current year-half from the specified clock. + *

      + * This will query the specified clock to obtain the current year-half. + * Using this method allows the use of an alternate clock for testing. + * The alternate clock may be introduced using {@link Clock dependency injection}. + * + * @param clock the clock to use, not null + * @return the current year-half, not null + */ + public static YearHalf now(Clock clock) { + final LocalDate now = LocalDate.now(clock); // called once + return YearHalf.of(now.getYear(), Half.from(now.getMonth())); + } + + //----------------------------------------------------------------------- + /** + * Obtains an instance of {@code YearHalf} from a year and half. + * + * @param year the year to represent, not null + * @param half the half-of-year to represent, not null + * @return the year-half, not null + */ + public static YearHalf of(Year year, Half half) { + return of(year.getValue(), half); + } + + /** + * Obtains an instance of {@code YearHalf} from a year and half. + * + * @param year the year to represent, not null + * @param half the half-of-year to represent, from 1 to 2 + * @return the year-half, not null + * @throws DateTimeException if the half value is invalid + */ + public static YearHalf of(Year year, int half) { + return of(year.getValue(), Half.of(half)); + } + + /** + * Obtains an instance of {@code YearHalf} from a year and half. + * + * @param year the year to represent, from MIN_YEAR to MAX_YEAR + * @param half the half-of-year to represent, not null + * @return the year-half, not null + * @throws DateTimeException if the year value is invalid + */ + public static YearHalf of(int year, Half half) { + YEAR.checkValidValue(year); + Objects.requireNonNull(half, "half"); + return new YearHalf(year, half); + } + + /** + * Obtains an instance of {@code YearHalf} from a year and half. + * + * @param year the year to represent, from MIN_YEAR to MAX_YEAR + * @param half the half-of-year to represent, from 1 to 2 + * @return the year-half, not null + * @throws DateTimeException if either field value is invalid + */ + public static YearHalf of(int year, int half) { + YEAR.checkValidValue(year); + return new YearHalf(year, Half.of(half)); + } + + //----------------------------------------------------------------------- + /** + * Obtains an instance of {@code YearHalf} from a temporal object. + *

      + * This obtains a year-half based on the specified temporal. + * A {@code TemporalAccessor} represents an arbitrary set of date and time information, + * which this factory converts to an instance of {@code YearHalf}. + *

      + * The conversion extracts the {@link ChronoField#YEAR YEAR} and + * {@link TemporalFields#HALF_OF_YEAR HALF_OF_YEAR} fields. + * The extraction is only permitted if the temporal object has an ISO + * chronology, or can be converted to a {@code LocalDate}. + *

      + * This method matches the signature of the functional interface {@link TemporalQuery} + * allowing it to be used in queries via method reference, {@code YearHalf::from}. + * + * @param temporal the temporal object to convert, not null + * @return the year-half, not null + * @throws DateTimeException if unable to convert to a {@code YearHalf} + */ + public static YearHalf from(TemporalAccessor temporal) { + if (temporal instanceof YearHalf) { + return (YearHalf) temporal; + } + Objects.requireNonNull(temporal, "temporal"); + try { + TemporalAccessor adjusted = + !IsoChronology.INSTANCE.equals(Chronology.from(temporal)) ? LocalDate.from(temporal) : temporal; + // need to use getLong() as JDK Parsed class get() doesn't work properly + int year = Math.toIntExact(adjusted.getLong(YEAR)); + int hoy = Math.toIntExact(adjusted.getLong(HALF_OF_YEAR)); + return of(year, hoy); + } catch (DateTimeException ex) { + throw new DateTimeException("Unable to obtain YearHalf from TemporalAccessor: " + + temporal + " of type " + temporal.getClass().getName(), ex); + } + } + + //----------------------------------------------------------------------- + /** + * Obtains an instance of {@code YearHalf} from a text string such as {@code 2007-H2}. + *

      + * The string must represent a valid year-half. + * The format must be {@code uuuu-'Q'Q} where the 'Q' is case insensitive. + * Years outside the range 0000 to 9999 must be prefixed by the plus or minus symbol. + * + * @param text the text to parse such as "2007-H2", not null + * @return the parsed year-half, not null + * @throws DateTimeParseException if the text cannot be parsed + */ + @FromString + public static YearHalf parse(CharSequence text) { + return parse(text, PARSER); + } + + /** + * Obtains an instance of {@code YearHalf} from a text string using a specific formatter. + *

      + * The text is parsed using the formatter, returning a year-half. + * + * @param text the text to parse, not null + * @param formatter the formatter to use, not null + * @return the parsed year-half, not null + * @throws DateTimeParseException if the text cannot be parsed + */ + public static YearHalf parse(CharSequence text, DateTimeFormatter formatter) { + Objects.requireNonNull(formatter, "formatter"); + return formatter.parse(text, YearHalf::from); + } + + //----------------------------------------------------------------------- + /** + * Constructor. + * + * @param year the year to represent, validated from MIN_YEAR to MAX_YEAR + * @param half the half-of-year to represent, validated not null + */ + private YearHalf(int year, Half half) { + this.year = year; + this.half = half; + } + + /** + * Validates the input. + * + * @return the valid object, not null + */ + private Object readResolve() { + return of(year, half); + } + + /** + * Returns a copy of this year-half with the new year and half, checking + * to see if a new object is in fact required. + * + * @param newYear the year to represent, validated from MIN_YEAR to MAX_YEAR + * @param newHalf the half-of-year to represent, validated not null + * @return the year-half, not null + */ + private YearHalf with(int newYear, Half newHalf) { + if (year == newYear && half == newHalf) { + return this; + } + return new YearHalf(newYear, newHalf); + } + + //----------------------------------------------------------------------- + /** + * Checks if the specified field is supported. + *

      + * This checks if this year-half can be queried for the specified field. + * If false, then calling the {@link #range(TemporalField) range}, + * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)} + * methods will throw an exception. + *

      + * If the field is a {@link ChronoField} then the query is implemented here. + * The supported fields are: + *

        + *
      • {@code HALF_OF_YEAR} + *
      • {@code YEAR_OF_ERA} + *
      • {@code YEAR} + *
      • {@code ERA} + *
      + * All other {@code ChronoField} instances will return false. + *

      + * If the field is not a {@code ChronoField}, then the result of this method + * is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)} + * passing {@code this} as the argument. + * Whether the field is supported is determined by the field. + * + * @param field the field to check, null returns false + * @return true if the field is supported on this year-half, false if not + */ + @Override + public boolean isSupported(TemporalField field) { + if (field == HALF_OF_YEAR) { + return true; + } else if (field instanceof ChronoField) { + return field == YEAR || field == YEAR_OF_ERA || field == ERA; + } + return field != null && field.isSupportedBy(this); + } + + /** + * Checks if the specified unit is supported. + *

      + * This checks if the specified unit can be added to, or subtracted from, this year-half. + * If false, then calling the {@link #plus(long, TemporalUnit)} and + * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. + *

      + * If the unit is a {@link ChronoUnit} then the query is implemented here. + * The supported units are: + *

        + *
      • {@code HALF_YEARS} + *
      • {@code YEARS} + *
      • {@code DECADES} + *
      • {@code CENTURIES} + *
      • {@code MILLENNIA} + *
      • {@code ERAS} + *
      + * All other {@code ChronoUnit} instances will return false. + *

      + * If the unit is not a {@code ChronoUnit}, then the result of this method + * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} + * passing {@code this} as the argument. + * Whether the unit is supported is determined by the unit. + * + * @param unit the unit to check, null returns false + * @return true if the unit can be added/subtracted, false if not + */ + @Override + public boolean isSupported(TemporalUnit unit) { + if (unit == HALF_YEARS) { + return true; + } else if (unit instanceof ChronoUnit) { + return unit == YEARS || unit == DECADES || unit == CENTURIES || unit == MILLENNIA || unit == ERAS; + } + return unit != null && unit.isSupportedBy(this); + } + + //----------------------------------------------------------------------- + /** + * Gets the range of valid values for the specified field. + *

      + * The range object expresses the minimum and maximum valid values for a field. + * This year-half is used to enhance the accuracy of the returned range. + * If it is not possible to return the range, because the field is not supported + * or for some other reason, an exception is thrown. + *

      + * If the field is a {@link ChronoField} then the query is implemented here. + * The {@link #isSupported(TemporalField) supported fields} will return + * appropriate range instances. + * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. + *

      + * If the field is not a {@code ChronoField}, then the result of this method + * is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessor)} + * passing {@code this} as the argument. + * Whether the range can be obtained is determined by the field. + * + * @param field the field to query the range for, not null + * @return the range of valid values for the field, not null + * @throws DateTimeException if the range for the field cannot be obtained + * @throws UnsupportedTemporalTypeException if the field is not supported + */ + @Override + public ValueRange range(TemporalField field) { + if (field == HALF_OF_YEAR) { + return HALF_OF_YEAR.range(); + } + if (field == YEAR_OF_ERA) { + return (getYear() <= 0 ? ValueRange.of(1, Year.MAX_VALUE + 1) : ValueRange.of(1, Year.MAX_VALUE)); + } + return Temporal.super.range(field); + } + + /** + * Gets the value of the specified field from this year-half as an {@code int}. + *

      + * This queries this year-half for the value for the specified field. + * The returned value will always be within the valid range of values for the field. + * If it is not possible to return the value, because the field is not supported + * or for some other reason, an exception is thrown. + *

      + * If the field is a {@link ChronoField} then the query is implemented here. + * The {@link #isSupported(TemporalField) supported fields} will return valid + * values based on this year-half,. + * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. + *

      + * If the field is not a {@code ChronoField}, then the result of this method + * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} + * passing {@code this} as the argument. Whether the value can be obtained, + * and what the value represents, is determined by the field. + * + * @param field the field to get, not null + * @return the value for the field + * @throws DateTimeException if a value for the field cannot be obtained or + * the value is outside the range of valid values for the field + * @throws UnsupportedTemporalTypeException if the field is not supported or + * the range of values exceeds an {@code int} + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public int get(TemporalField field) { + if (field == HALF_OF_YEAR) { + return half.getValue(); + } else if (field instanceof ChronoField) { + switch ((ChronoField) field) { + case YEAR_OF_ERA: + return (year < 1 ? 1 - year : year); + case YEAR: + return year; + case ERA: + return (year < 1 ? 0 : 1); + default: + throw new UnsupportedTemporalTypeException("Unsupported field: " + field); + } + } + return Temporal.super.get(field); + } + + /** + * Gets the value of the specified field from this year-half as a {@code long}. + *

      + * This queries this year-half for the value for the specified field. + * If it is not possible to return the value, because the field is not supported + * or for some other reason, an exception is thrown. + *

      + * If the field is a {@link ChronoField} then the query is implemented here. + * The {@link #isSupported(TemporalField) supported fields} will return valid + * values based on this year-half. + * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. + *

      + * If the field is not a {@code ChronoField}, then the result of this method + * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} + * passing {@code this} as the argument. Whether the value can be obtained, + * and what the value represents, is determined by the field. + * + * @param field the field to get, not null + * @return the value for the field + * @throws DateTimeException if a value for the field cannot be obtained + * @throws UnsupportedTemporalTypeException if the field is not supported + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public long getLong(TemporalField field) { + if (field == HALF_OF_YEAR) { + return half.getValue(); + } else if (field instanceof ChronoField) { + switch ((ChronoField) field) { + case YEAR_OF_ERA: + return (year < 1 ? 1 - year : year); + case YEAR: + return year; + case ERA: + return (year < 1 ? 0 : 1); + default: + throw new UnsupportedTemporalTypeException("Unsupported field: " + field); + } + } + return field.getFrom(this); + } + + private long getProlepticHalf() { + return year * 2L + (half.getValue() - 1); + } + + //----------------------------------------------------------------------- + /** + * Gets the year field. + *

      + * This method returns the primitive {@code int} value for the year. + *

      + * The year returned by this method is proleptic as per {@code get(YEAR)}. + * + * @return the year, from MIN_YEAR to MAX_YEAR + */ + public int getYear() { + return year; + } + + /** + * Gets the half-of-year field from 1 to 2. + *

      + * This method returns the half as an {@code int} from 1 to 2. + * Application code is frequently clearer if the enum {@link Half} + * is used by calling {@link #getHalf()}. + * + * @return the half-of-year, from 1 to 2 + * @see #getHalf() + */ + public int getHalfValue() { + return half.getValue(); + } + + /** + * Gets the half-of-year field using the {@code Half} enum. + *

      + * This method returns the enum {@link Half} for the half. + * This avoids confusion as to what {@code int} values mean. + * If you need access to the primitive {@code int} value then the enum + * provides the {@link Half#getValue() int value}. + * + * @return the half-of-year, not null + * @see #getHalfValue() + */ + public Half getHalf() { + return half; + } + + //----------------------------------------------------------------------- + /** + * Checks if the year is a leap year, according to the ISO proleptic + * calendar system rules. + *

      + * This method applies the current rules for leap years across the whole time-line. + * In general, a year is a leap year if it is divisible by four without + * remainder. However, years divisible by 100, are not leap years, with + * the exception of years divisible by 400 which are. + *

      + * For example, 1904 is a leap year it is divisible by 4. + * 1900 was not a leap year as it is divisible by 100, however 2000 was a + * leap year as it is divisible by 400. + *

      + * The calculation is proleptic - applying the same rules into the far future and far past. + * This is historically inaccurate, but is correct for the ISO-8601 standard. + * + * @return true if the year is leap, false otherwise + */ + public boolean isLeapYear() { + return IsoChronology.INSTANCE.isLeapYear(year); + } + + /** + * Checks if the day-of-half is valid for this year-half. + *

      + * This method checks whether this year and half and the input day form + * a valid date. + * + * @param dayOfHalf the day-of-half to validate, from 1 to 181, 182 or 184, invalid value returns false + * @return true if the day is valid for this year-half + */ + public boolean isValidDay(int dayOfHalf) { + return dayOfHalf >= 1 && dayOfHalf <= lengthOfHalf(); + } + + /** + * Returns the length of the half, taking account of the year. + *

      + * This returns the length of the half in days. + * + * @return the length of the half in days, 181, 182 or 184 + */ + public int lengthOfHalf() { + return half.length(isLeapYear()); + } + + /** + * Returns the length of the year. + *

      + * This returns the length of the year in days, either 365 or 366. + * + * @return 366 if the year is leap, 365 otherwise + */ + public int lengthOfYear() { + return (isLeapYear() ? 366 : 365); + } + + //----------------------------------------------------------------------- + /** + * Returns an adjusted copy of this year-half. + *

      + * This returns a {@code YearHalf} based on this one, with the year-half adjusted. + * The adjustment takes place using the specified adjuster strategy object. + * Read the documentation of the adjuster to understand what adjustment will be made. + *

      + * A simple adjuster might simply set the one of the fields, such as the year field. + * A more complex adjuster might set the year-half to the next half that + * Halley's comet will pass the Earth. + *

      + * The result of this method is obtained by invoking the + * {@link TemporalAdjuster#adjustInto(Temporal)} method on the + * specified adjuster passing {@code this} as the argument. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param adjuster the adjuster to use, not null + * @return a {@code YearHalf} based on {@code this} with the adjustment made, not null + * @throws DateTimeException if the adjustment cannot be made + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public YearHalf with(TemporalAdjuster adjuster) { + return (YearHalf) adjuster.adjustInto(this); + } + + /** + * Returns a copy of this year-half with the specified field set to a new value. + *

      + * This returns a {@code YearHalf} based on this one, with the value + * for the specified field changed. + * This can be used to change any supported field, such as the year or half. + * If it is not possible to set the value, because the field is not supported or for + * some other reason, an exception is thrown. + *

      + * If the field is a {@link ChronoField} then the adjustment is implemented here. + * The supported fields behave as follows: + *

        + *
      • {@code HALF_OF_YEAR} - + * Returns a {@code YearHalf} with the specified half-of-year. + * The year will be unchanged. + *
      • {@code YEAR_OF_ERA} - + * Returns a {@code YearHalf} with the specified year-of-era + * The half and era will be unchanged. + *
      • {@code YEAR} - + * Returns a {@code YearHalf} with the specified year. + * The half will be unchanged. + *
      • {@code ERA} - + * Returns a {@code YearHalf} with the specified era. + * The half and year-of-era will be unchanged. + *
      + *

      + * In all cases, if the new value is outside the valid range of values for the field + * then a {@code DateTimeException} will be thrown. + *

      + * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. + *

      + * If the field is not a {@code ChronoField}, then the result of this method + * is obtained by invoking {@code TemporalField.adjustInto(Temporal, long)} + * passing {@code this} as the argument. In this case, the field determines + * whether and how to adjust the instant. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param field the field to set in the result, not null + * @param newValue the new value of the field in the result + * @return a {@code YearHalf} based on {@code this} with the specified field set, not null + * @throws DateTimeException if the field cannot be set + * @throws UnsupportedTemporalTypeException if the field is not supported + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public YearHalf with(TemporalField field, long newValue) { + if (field == HALF_OF_YEAR) { + return withHalf(HALF_OF_YEAR.range().checkValidIntValue(newValue, HALF_OF_YEAR)); + } else if (field instanceof ChronoField) { + ChronoField f = (ChronoField) field; + f.checkValidValue(newValue); + switch (f) { + case YEAR_OF_ERA: + return withYear((int) (year < 1 ? 1 - newValue : newValue)); + case YEAR: + return withYear((int) newValue); + case ERA: + return (getLong(ERA) == newValue ? this : withYear(1 - year)); + default: + throw new UnsupportedTemporalTypeException("Unsupported field: " + field); + } + } + return field.adjustInto(this, newValue); + } + + //----------------------------------------------------------------------- + /** + * Returns a copy of this {@code YearHalf} with the year altered. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param year the year to set in the returned year-half, from MIN_YEAR to MAX_YEAR + * @return a {@code YearHalf} based on this year-half with the requested year, not null + * @throws DateTimeException if the year value is invalid + */ + public YearHalf withYear(int year) { + YEAR.checkValidValue(year); + return with(year, half); + } + + /** + * Returns a copy of this {@code YearHalf} with the half-of-year altered. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param half the half-of-year to set in the returned year-half, from 1 to 2 + * @return a {@code YearHalf} based on this year-half with the requested half, not null + * @throws DateTimeException if the half-of-year value is invalid + */ + public YearHalf withHalf(int half) { + HALF_OF_YEAR.range().checkValidValue(half, HALF_OF_YEAR); + return with(year, Half.of(half)); + } + + //----------------------------------------------------------------------- + /** + * Returns a copy of this year-half with the specified amount added. + *

      + * This returns a {@code YearHalf} based on this one, with the specified amount added. + * The amount is typically {@link Period} but may be any other type implementing + * the {@link TemporalAmount} interface. + *

      + * The calculation is delegated to the amount object by calling + * {@link TemporalAmount#addTo(Temporal)}. The amount implementation is free + * to implement the addition in any way it wishes, however it typically + * calls back to {@link #plus(long, TemporalUnit)}. Consult the documentation + * of the amount implementation to determine if it can be successfully added. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param amountToAdd the amount to add, not null + * @return a {@code YearHalf} based on this year-half with the addition made, not null + * @throws DateTimeException if the addition cannot be made + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public YearHalf plus(TemporalAmount amountToAdd) { + return (YearHalf) amountToAdd.addTo(this); + } + + /** + * Returns a copy of this year-half with the specified amount added. + *

      + * This returns a {@code YearHalf} based on this one, with the amount + * in terms of the unit added. If it is not possible to add the amount, because the + * unit is not supported or for some other reason, an exception is thrown. + *

      + * If the field is a {@link ChronoUnit} then the addition is implemented here. + * The supported fields behave as follows: + *

        + *
      • {@code HALF_YEARS} - + * Returns a {@code YearHalf} with the specified number of halves added. + * This is equivalent to {@link #plusHalfs(long)}. + *
      • {@code YEARS} - + * Returns a {@code YearHalf} with the specified number of years added. + * This is equivalent to {@link #plusYears(long)}. + *
      • {@code DECADES} - + * Returns a {@code YearHalf} with the specified number of decades added. + * This is equivalent to calling {@link #plusYears(long)} with the amount + * multiplied by 10. + *
      • {@code CENTURIES} - + * Returns a {@code YearHalf} with the specified number of centuries added. + * This is equivalent to calling {@link #plusYears(long)} with the amount + * multiplied by 100. + *
      • {@code MILLENNIA} - + * Returns a {@code YearHalf} with the specified number of millennia added. + * This is equivalent to calling {@link #plusYears(long)} with the amount + * multiplied by 1,000. + *
      • {@code ERAS} - + * Returns a {@code YearHalf} with the specified number of eras added. + * Only two eras are supported so the amount must be one, zero or minus one. + * If the amount is non-zero then the year is changed such that the year-of-era + * is unchanged. + *
      + *

      + * All other {@code ChronoUnit} instances will throw an {@code UnsupportedTemporalTypeException}. + *

      + * If the field is not a {@code ChronoUnit}, then the result of this method + * is obtained by invoking {@code TemporalUnit.addTo(Temporal, long)} + * passing {@code this} as the argument. In this case, the unit determines + * whether and how to perform the addition. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param amountToAdd the amount of the unit to add to the result, may be negative + * @param unit the unit of the amount to add, not null + * @return a {@code YearHalf} based on this year-half with the specified amount added, not null + * @throws DateTimeException if the addition cannot be made + * @throws UnsupportedTemporalTypeException if the unit is not supported + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public YearHalf plus(long amountToAdd, TemporalUnit unit) { + if (unit == HALF_YEARS) { + return plusHalfs(amountToAdd); + } else if (unit instanceof ChronoUnit) { + switch ((ChronoUnit) unit) { + case YEARS: + return plusYears(amountToAdd); + case DECADES: + return plusYears(Math.multiplyExact(amountToAdd, 10)); + case CENTURIES: + return plusYears(Math.multiplyExact(amountToAdd, 100)); + case MILLENNIA: + return plusYears(Math.multiplyExact(amountToAdd, 1000)); + case ERAS: + return with(ERA, Math.addExact(getLong(ERA), amountToAdd)); + default: + throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); + } + } + return unit.addTo(this, amountToAdd); + } + + /** + * Returns a copy of this year-half with the specified period in years added. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param yearsToAdd the years to add, may be negative + * @return a {@code YearHalf} based on this year-half with the years added, not null + * @throws DateTimeException if the result exceeds the supported range + */ + public YearHalf plusYears(long yearsToAdd) { + if (yearsToAdd == 0) { + return this; + } + int newYear = YEAR.checkValidIntValue(year + yearsToAdd); // safe overflow + return with(newYear, half); + } + + /** + * Returns a copy of this year-half with the specified period in halves added. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param halvesToAdd the halves to add, may be negative + * @return a {@code YearHalf} based on this year-half with the halves added, not null + * @throws DateTimeException if the result exceeds the supported range + */ + public YearHalf plusHalfs(long halvesToAdd) { + if (halvesToAdd == 0) { + return this; + } + long halfCount = year * 2L + (half.getValue() - 1); + long calcHalfs = halfCount + halvesToAdd; // safe overflow + int newYear = YEAR.checkValidIntValue(Math.floorDiv(calcHalfs, 2)); + int newHalf = (int) Math.floorMod(calcHalfs, 2L) + 1; + return with(newYear, Half.of(newHalf)); + } + + //----------------------------------------------------------------------- + /** + * Returns a copy of this year-half with the specified amount subtracted. + *

      + * This returns a {@code YearHalf} based on this one, with the specified amount subtracted. + * The amount is typically {@link Period} but may be any other type implementing + * the {@link TemporalAmount} interface. + *

      + * The calculation is delegated to the amount object by calling + * {@link TemporalAmount#subtractFrom(Temporal)}. The amount implementation is free + * to implement the subtraction in any way it wishes, however it typically + * calls back to {@link #minus(long, TemporalUnit)}. Consult the documentation + * of the amount implementation to determine if it can be successfully subtracted. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param amountToSubtract the amount to subtract, not null + * @return a {@code YearHalf} based on this year-half with the subtraction made, not null + * @throws DateTimeException if the subtraction cannot be made + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public YearHalf minus(TemporalAmount amountToSubtract) { + return (YearHalf) amountToSubtract.subtractFrom(this); + } + + /** + * Returns a copy of this year-half with the specified amount subtracted. + *

      + * This returns a {@code YearHalf} based on this one, with the amount + * in terms of the unit subtracted. If it is not possible to subtract the amount, + * because the unit is not supported or for some other reason, an exception is thrown. + *

      + * This method is equivalent to {@link #plus(long, TemporalUnit)} with the amount negated. + * See that method for a full description of how addition, and thus subtraction, works. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param amountToSubtract the amount of the unit to subtract from the result, may be negative + * @param unit the unit of the amount to subtract, not null + * @return a {@code YearHalf} based on this year-half with the specified amount subtracted, not null + * @throws DateTimeException if the subtraction cannot be made + * @throws UnsupportedTemporalTypeException if the unit is not supported + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public YearHalf minus(long amountToSubtract, TemporalUnit unit) { + return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit)); + } + + /** + * Returns a copy of this year-half with the specified period in years subtracted. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param yearsToSubtract the years to subtract, may be negative + * @return a {@code YearHalf} based on this year-half with the years subtracted, not null + * @throws DateTimeException if the result exceeds the supported range + */ + public YearHalf minusYears(long yearsToSubtract) { + return (yearsToSubtract == Long.MIN_VALUE ? plusYears(Long.MAX_VALUE).plusYears(1) : plusYears(-yearsToSubtract)); + } + + /** + * Returns a copy of this year-half with the specified period in halves subtracted. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param halvesToSubtract the halves to subtract, may be negative + * @return a {@code YearHalf} based on this year-half with the halves subtracted, not null + * @throws DateTimeException if the result exceeds the supported range + */ + public YearHalf minusHalfs(long halvesToSubtract) { + return (halvesToSubtract == Long.MIN_VALUE ? plusHalfs(Long.MAX_VALUE).plusHalfs(1) : plusHalfs(-halvesToSubtract)); + } + + //----------------------------------------------------------------------- + /** + * Queries this year-half using the specified query. + *

      + * This queries this year-half using the specified query strategy object. + * The {@code TemporalQuery} object defines the logic to be used to + * obtain the result. Read the documentation of the query to understand + * what the result of this method will be. + *

      + * The result of this method is obtained by invoking the + * {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the + * specified query passing {@code this} as the argument. + * + * @param the type of the result + * @param query the query to invoke, not null + * @return the query result, null may be returned (defined by the query) + * @throws DateTimeException if unable to query (defined by the query) + * @throws ArithmeticException if numeric overflow occurs (defined by the query) + */ + @SuppressWarnings("unchecked") + @Override + public R query(TemporalQuery query) { + if (query == TemporalQueries.chronology()) { + return (R) IsoChronology.INSTANCE; + } else if (query == TemporalQueries.precision()) { + return (R) HALF_YEARS; + } + return Temporal.super.query(query); + } + + /** + * Adjusts the specified temporal object to have this year-half. + *

      + * This returns a temporal object of the same observable type as the input + * with the year and half changed to be the same as this. + *

      + * The adjustment is equivalent to using {@link Temporal#plus(long, TemporalUnit)} + * passing the number of halves to adjust by. + * If the specified temporal object does not use the ISO calendar system then + * a {@code DateTimeException} is thrown. + *

      + * In most cases, it is clearer to reverse the calling pattern by using + * {@link Temporal#with(TemporalAdjuster)}: + *

      +     *   // these two lines are equivalent, but the second approach is recommended
      +     *   temporal = thisYearHalf.adjustInto(temporal);
      +     *   temporal = temporal.with(thisYearHalf);
      +     * 
      + *

      + * This instance is immutable and unaffected by this method call. + * + * @param temporal the target object to be adjusted, not null + * @return the adjusted object, not null + * @throws DateTimeException if unable to make the adjustment + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public Temporal adjustInto(Temporal temporal) { + if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) { + throw new DateTimeException("Adjustment only supported on ISO date-time"); + } + long newProlepticHalf = getProlepticHalf(); + long oldProlepticHalf = temporal.get(YEAR) * 2L + (temporal.get(HALF_OF_YEAR) - 1); + return temporal.plus(newProlepticHalf - oldProlepticHalf, HALF_YEARS); + } + + /** + * Calculates the amount of time until another year-half in terms of the specified unit. + *

      + * This calculates the amount of time between two {@code YearHalf} + * objects in terms of a single {@code TemporalUnit}. + * The start and end points are {@code this} and the specified year-half. + * The result will be negative if the end is before the start. + * The {@code Temporal} passed to this method is converted to a + * {@code YearHalf} using {@link #from(TemporalAccessor)}. + * For example, the period in years between two year-halves can be calculated + * using {@code startYearHalf.until(endYearHalf, YEARS)}. + *

      + * The calculation returns a whole number, representing the number of + * complete units between the two year-halves. + * For example, the period in decades between 2012-H2 and 2032-H1 + * will only be one decade as it is one half short of two decades. + *

      + * There are two equivalent ways of using this method. + * The first is to invoke this method. + * The second is to use {@link TemporalUnit#between(Temporal, Temporal)}: + *

      +     *   // these two lines are equivalent
      +     *   amount = start.until(end, HALF_YEARS);
      +     *   amount = HALF_YEARS.between(start, end);
      +     * 
      + * The choice should be made based on which makes the code more readable. + *

      + * The calculation is implemented in this method for {@link ChronoUnit}. + * The units {@code HALF_YEARS}, {@code YEARS}, {@code DECADES}, + * {@code CENTURIES}, {@code MILLENNIA} and {@code ERAS} are supported. + * Other {@code ChronoUnit} values will throw an exception. + *

      + * If the unit is not a {@code ChronoUnit}, then the result of this method + * is obtained by invoking {@code TemporalUnit.between(Temporal, Temporal)} + * passing {@code this} as the first argument and the converted input temporal + * as the second argument. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param endExclusive the end date, exclusive, which is converted to a {@code YearHalf}, not null + * @param unit the unit to measure the amount in, not null + * @return the amount of time between this year-half and the end year-half + * @throws DateTimeException if the amount cannot be calculated, or the end + * temporal cannot be converted to a {@code YearHalf} + * @throws UnsupportedTemporalTypeException if the unit is not supported + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public long until(Temporal endExclusive, TemporalUnit unit) { + YearHalf end = YearHalf.from(endExclusive); + long halvesUntil = end.getProlepticHalf() - getProlepticHalf(); // no overflow + if (unit == HALF_YEARS) { + return halvesUntil; + } else if (unit instanceof ChronoUnit) { + switch ((ChronoUnit) unit) { + case YEARS: + return halvesUntil / 2; + case DECADES: + return halvesUntil / 20; + case CENTURIES: + return halvesUntil / 200; + case MILLENNIA: + return halvesUntil / 2000; + case ERAS: + return end.getLong(ERA) - getLong(ERA); + default: + throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); + } + } + return unit.between(this, end); + } + + /** + * Returns a sequential ordered stream of year-half. The returned stream starts from this year-half + * (inclusive) and goes to {@code endExclusive} (exclusive) by an incremental step of 1 {@code HALF_YEARS}. + *

      + * This instance is immutable and unaffected by this method call. + * + * @param endExclusive the end year-half, exclusive, not null + * @return a sequential {@code Stream} for the range of {@code YearHalf} values + * @throws IllegalArgumentException if end year-half is before this year-half + */ + public Stream halvesUntil(YearHalf endExclusive) { + if (endExclusive.isBefore(this)) { + throw new IllegalArgumentException(endExclusive + " < " + this); + } + long intervalLength = until(endExclusive, HALF_YEARS); + return LongStream.range(0, intervalLength).mapToObj(n -> plusHalfs(n)); + } + + /** + * Formats this year-half using the specified formatter. + *

      + * This year-half will be passed to the formatter to produce a string. + * + * @param formatter the formatter to use, not null + * @return the formatted year-half string, not null + * @throws DateTimeException if an error occurs during printing + */ + public String format(DateTimeFormatter formatter) { + Objects.requireNonNull(formatter, "formatter"); + return formatter.format(this); + } + + //----------------------------------------------------------------------- + /** + * Combines this year-half with a day-of-half to create a {@code LocalDate}. + *

      + * This returns a {@code LocalDate} formed from this year-half and the specified day-of-half. + *

      + * The day-of-half value must be valid for the year-half. + *

      + * This method can be used as part of a chain to produce a date: + *

      +     *  LocalDate date = yearHalf.atDay(day);
      +     * 
      + * + * @param dayOfHalf the day-of-half to use, from 1 to 184 + * @return the date formed from this year-half and the specified day, not null + * @throws DateTimeException if the day is invalid for the year-half + * @see #isValidDay(int) + */ + public LocalDate atDay(int dayOfHalf) { + ValueRange.of(1, lengthOfHalf()).checkValidValue(dayOfHalf, DAY_OF_HALF); + boolean leap = Year.isLeap(year); + Month month = half.firstMonth(); + int dom = dayOfHalf; + while (dom > month.length(leap)) { + dom -= month.length(leap); + month = month.plus(1); + } + return LocalDate.of(year, month, dom); + } + + /** + * Returns a {@code LocalDate} at the end of the half. + *

      + * This returns a {@code LocalDate} based on this year-half. + * The day-of-half is set to the last valid day of the half, taking + * into account leap years. + *

      + * This method can be used as part of a chain to produce a date: + *

      +     *  LocalDate date = year.atHalf(half).atEndOfHalf();
      +     * 
      + * + * @return the last valid date of this year-half, not null + */ + public LocalDate atEndOfHalf() { + Month month = half.firstMonth().plus(5); + return LocalDate.of(year, month, month.maxLength()); + } + + //----------------------------------------------------------------------- + /** + * Compares this year-half to another + *

      + * The comparison is based first on the value of the year, then on the value of the half. + * It is "consistent with equals", as defined by {@link Comparable}. + * + * @param other the other year-half to compare to, not null + * @return the comparator value, negative if less, positive if greater + */ + @Override + public int compareTo(YearHalf other) { + int cmp = (year - other.year); + if (cmp == 0) { + cmp = half.compareTo(other.half); + } + return cmp; + } + + /** + * Is this year-half after the specified year-half. + * + * @param other the other year-half to compare to, not null + * @return true if this is after the specified year-half + */ + public boolean isAfter(YearHalf other) { + return compareTo(other) > 0; + } + + /** + * Is this year-half before the specified year-half. + * + * @param other the other year-half to compare to, not null + * @return true if this point is before the specified year-half + */ + public boolean isBefore(YearHalf other) { + return compareTo(other) < 0; + } + + //----------------------------------------------------------------------- + /** + * Checks if this year-half is equal to another year-half. + *

      + * The comparison is based on the time-line position of the year-halves. + * + * @param obj the object to check, null returns false + * @return true if this is equal to the other year-half + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof YearHalf) { + YearHalf other = (YearHalf) obj; + return year == other.year && half == other.half; + } + return false; + } + + /** + * A hash code for this year-half. + * + * @return a suitable hash code + */ + @Override + public int hashCode() { + return year ^ (half.getValue() << 28); + } + + //----------------------------------------------------------------------- + /** + * Outputs this year-half as a {@code String}, such as {@code 2007-H2}. + * + * @return a string representation of this year-half, not null + */ + @Override + @ToString + public String toString() { + int absYear = Math.abs(year); + StringBuilder buf = new StringBuilder(10); + if (absYear < 1000) { + if (year < 0) { + buf.append(year - 10000).deleteCharAt(1); + } else { + buf.append(year + 10000).deleteCharAt(0); + } + } else { + if (year > 9999) { + buf.append('+'); + } + buf.append(year); + } + return buf.append('-').append(half).toString(); + } + +} diff --git a/src/main/java/org/threeten/extra/YearQuarter.java b/src/main/java/org/threeten/extra/YearQuarter.java index 80e899f4..5d455abc 100644 --- a/src/main/java/org/threeten/extra/YearQuarter.java +++ b/src/main/java/org/threeten/extra/YearQuarter.java @@ -254,12 +254,11 @@ public static YearQuarter from(TemporalAccessor temporal) { } Objects.requireNonNull(temporal, "temporal"); try { - if (IsoChronology.INSTANCE.equals(Chronology.from(temporal)) == false) { - temporal = LocalDate.from(temporal); - } + TemporalAccessor adjusted = + !IsoChronology.INSTANCE.equals(Chronology.from(temporal)) ? LocalDate.from(temporal) : temporal; // need to use getLong() as JDK Parsed class get() doesn't work properly - int year = Math.toIntExact(temporal.getLong(YEAR)); - int qoy = Math.toIntExact(temporal.getLong(QUARTER_OF_YEAR)); + int year = Math.toIntExact(adjusted.getLong(YEAR)); + int qoy = Math.toIntExact(adjusted.getLong(QUARTER_OF_YEAR)); return of(year, qoy); } catch (DateTimeException ex) { throw new DateTimeException("Unable to obtain YearQuarter from TemporalAccessor: " + @@ -892,7 +891,7 @@ public YearQuarter plusQuarters(long quartersToAdd) { long quarterCount = year * 4L + (quarter.getValue() - 1); long calcQuarters = quarterCount + quartersToAdd; // safe overflow int newYear = YEAR.checkValidIntValue(Math.floorDiv(calcQuarters, 4)); - int newQuarter = (int) Math.floorMod(calcQuarters, 4) + 1; + int newQuarter = (int) Math.floorMod(calcQuarters, 4L) + 1; return with(newYear, Quarter.of(newQuarter)); } @@ -1164,11 +1163,12 @@ public LocalDate atDay(int dayOfQuarter) { ValueRange.of(1, lengthOfQuarter()).checkValidValue(dayOfQuarter, DAY_OF_QUARTER); boolean leap = Year.isLeap(year); Month month = quarter.firstMonth(); - while (dayOfQuarter > month.length(leap)) { - dayOfQuarter -= month.length(leap); + int dom = dayOfQuarter; + while (dom > month.length(leap)) { + dom -= month.length(leap); month = month.plus(1); } - return LocalDate.of(year, month, dayOfQuarter); + return LocalDate.of(year, month, dom); } /** diff --git a/src/test/java/org/threeten/extra/TestHalf.java b/src/test/java/org/threeten/extra/TestHalf.java new file mode 100644 index 00000000..fa4c1259 --- /dev/null +++ b/src/test/java/org/threeten/extra/TestHalf.java @@ -0,0 +1,405 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.extra; + +import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH; +import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR; +import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH; +import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR; +import static java.time.temporal.ChronoField.AMPM_OF_DAY; +import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_AMPM; +import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_DAY; +import static java.time.temporal.ChronoField.DAY_OF_MONTH; +import static java.time.temporal.ChronoField.DAY_OF_WEEK; +import static java.time.temporal.ChronoField.DAY_OF_YEAR; +import static java.time.temporal.ChronoField.EPOCH_DAY; +import static java.time.temporal.ChronoField.ERA; +import static java.time.temporal.ChronoField.HOUR_OF_AMPM; +import static java.time.temporal.ChronoField.HOUR_OF_DAY; +import static java.time.temporal.ChronoField.INSTANT_SECONDS; +import static java.time.temporal.ChronoField.MICRO_OF_DAY; +import static java.time.temporal.ChronoField.MICRO_OF_SECOND; +import static java.time.temporal.ChronoField.MILLI_OF_DAY; +import static java.time.temporal.ChronoField.MILLI_OF_SECOND; +import static java.time.temporal.ChronoField.MINUTE_OF_DAY; +import static java.time.temporal.ChronoField.MINUTE_OF_HOUR; +import static java.time.temporal.ChronoField.MONTH_OF_YEAR; +import static java.time.temporal.ChronoField.NANO_OF_DAY; +import static java.time.temporal.ChronoField.NANO_OF_SECOND; +import static java.time.temporal.ChronoField.OFFSET_SECONDS; +import static java.time.temporal.ChronoField.PROLEPTIC_MONTH; +import static java.time.temporal.ChronoField.SECOND_OF_DAY; +import static java.time.temporal.ChronoField.SECOND_OF_MINUTE; +import static java.time.temporal.ChronoField.YEAR; +import static java.time.temporal.ChronoField.YEAR_OF_ERA; +import static java.time.temporal.IsoFields.QUARTER_OF_YEAR; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.threeten.extra.TemporalFields.HALF_OF_YEAR; +import static org.threeten.extra.TemporalFields.HALF_YEARS; + +import java.io.Serializable; +import java.time.DateTimeException; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.Month; +import java.time.chrono.IsoChronology; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.TextStyle; +import java.time.temporal.TemporalAccessor; +import java.time.temporal.TemporalQueries; +import java.time.temporal.UnsupportedTemporalTypeException; +import java.util.Locale; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +/** + * Test Half. + */ +public class TestHalf { + + //----------------------------------------------------------------------- + @Test + public void test_interfaces() { + assertTrue(Enum.class.isAssignableFrom(Half.class)); + assertTrue(Serializable.class.isAssignableFrom(Half.class)); + assertTrue(Comparable.class.isAssignableFrom(Half.class)); + assertTrue(TemporalAccessor.class.isAssignableFrom(Half.class)); + } + + //----------------------------------------------------------------------- + // of(int) + //----------------------------------------------------------------------- + @Test + public void test_of_int() { + assertEquals(1, Half.of(1).getValue()); + assertEquals(2, Half.of(2).getValue()); + assertThrows(DateTimeException.class, () -> Half.of(0)); + assertThrows(DateTimeException.class, () -> Half.of(3)); + } + + //----------------------------------------------------------------------- + // ofMonth(int) + //----------------------------------------------------------------------- + @Test + public void test_ofMonth_int_singleton() { + assertSame(Half.H1, Half.ofMonth(1)); + assertSame(Half.H1, Half.ofMonth(2)); + assertSame(Half.H1, Half.ofMonth(3)); + assertSame(Half.H1, Half.ofMonth(4)); + assertSame(Half.H1, Half.ofMonth(5)); + assertSame(Half.H1, Half.ofMonth(6)); + assertSame(Half.H2, Half.ofMonth(7)); + assertSame(Half.H2, Half.ofMonth(8)); + assertSame(Half.H2, Half.ofMonth(9)); + assertSame(Half.H2, Half.ofMonth(10)); + assertSame(Half.H2, Half.ofMonth(11)); + assertSame(Half.H2, Half.ofMonth(12)); + } + + @Test + public void test_ofMonth_int_valueTooLow() { + assertThrows(DateTimeException.class, () -> Half.ofMonth(0)); + } + + @Test + public void test_ofMonth_int_valueTooHigh() { + assertThrows(DateTimeException.class, () -> Half.ofMonth(13)); + } + + //----------------------------------------------------------------------- + // from(TemporalAccessor) + //----------------------------------------------------------------------- + @Test + public void test_from_TemporalAccessor() { + assertEquals(Half.H2, Half.from(LocalDate.of(2011, 7, 6))); + assertEquals(Half.H1, Half.from(LocalDateTime.of(2012, 2, 3, 12, 30))); + } + + @Test + public void test_from_TemporalAccessor_Month() { + assertEquals(Half.H1, Half.from(Month.JANUARY)); + assertEquals(Half.H1, Half.from(Month.FEBRUARY)); + assertEquals(Half.H1, Half.from(Month.MARCH)); + assertEquals(Half.H1, Half.from(Month.APRIL)); + assertEquals(Half.H1, Half.from(Month.MAY)); + assertEquals(Half.H1, Half.from(Month.JUNE)); + assertEquals(Half.H2, Half.from(Month.JULY)); + assertEquals(Half.H2, Half.from(Month.AUGUST)); + assertEquals(Half.H2, Half.from(Month.SEPTEMBER)); + assertEquals(Half.H2, Half.from(Month.OCTOBER)); + assertEquals(Half.H2, Half.from(Month.NOVEMBER)); + assertEquals(Half.H2, Half.from(Month.DECEMBER)); + + assertEquals(Half.H1, Half.from(Half.H1)); + assertEquals(Half.H2, Half.from(Half.H2)); + } + + @Test + public void test_from_TemporalAccessorl_invalid_noDerive() { + assertThrows(DateTimeException.class, () -> Half.from(LocalTime.of(12, 30))); + } + + @Test + public void test_from_TemporalAccessor_null() { + assertThrows(NullPointerException.class, () -> Half.from((TemporalAccessor) null)); + } + + @Test + public void test_from_parse_CharSequence() { + DateTimeFormatter formatter = new DateTimeFormatterBuilder() + .appendLiteral('H') + .appendValue(HALF_OF_YEAR, 1) + .toFormatter(); + assertEquals(Half.H2, formatter.parse("H2", Half::from)); + } + + //----------------------------------------------------------------------- + // getDisplayName() + //----------------------------------------------------------------------- + @Test + public void test_getDisplayName() { + assertTrue(Half.H1.getDisplayName(TextStyle.SHORT, Locale.US).contains("1")); + } + + @Test + public void test_getDisplayName_nullStyle() { + assertThrows(NullPointerException.class, () -> Half.H1.getDisplayName(null, Locale.US)); + } + + @Test + public void test_getDisplayName_nullLocale() { + assertThrows(NullPointerException.class, () -> Half.H1.getDisplayName(TextStyle.FULL, null)); + } + + //----------------------------------------------------------------------- + // isSupported() + //----------------------------------------------------------------------- + @Test + public void test_isSupported() { + Half test = Half.H1; + assertEquals(false, test.isSupported(null)); + assertEquals(false, test.isSupported(NANO_OF_SECOND)); + assertEquals(false, test.isSupported(NANO_OF_DAY)); + assertEquals(false, test.isSupported(MICRO_OF_SECOND)); + assertEquals(false, test.isSupported(MICRO_OF_DAY)); + assertEquals(false, test.isSupported(MILLI_OF_SECOND)); + assertEquals(false, test.isSupported(MILLI_OF_DAY)); + assertEquals(false, test.isSupported(SECOND_OF_MINUTE)); + assertEquals(false, test.isSupported(SECOND_OF_DAY)); + assertEquals(false, test.isSupported(MINUTE_OF_HOUR)); + assertEquals(false, test.isSupported(MINUTE_OF_DAY)); + assertEquals(false, test.isSupported(HOUR_OF_AMPM)); + assertEquals(false, test.isSupported(CLOCK_HOUR_OF_AMPM)); + assertEquals(false, test.isSupported(HOUR_OF_DAY)); + assertEquals(false, test.isSupported(CLOCK_HOUR_OF_DAY)); + assertEquals(false, test.isSupported(AMPM_OF_DAY)); + assertEquals(false, test.isSupported(DAY_OF_WEEK)); + assertEquals(false, test.isSupported(ALIGNED_DAY_OF_WEEK_IN_MONTH)); + assertEquals(false, test.isSupported(ALIGNED_DAY_OF_WEEK_IN_YEAR)); + assertEquals(false, test.isSupported(DAY_OF_MONTH)); + assertEquals(false, test.isSupported(DAY_OF_YEAR)); + assertEquals(false, test.isSupported(EPOCH_DAY)); + assertEquals(false, test.isSupported(ALIGNED_WEEK_OF_MONTH)); + assertEquals(false, test.isSupported(ALIGNED_WEEK_OF_YEAR)); + assertEquals(false, test.isSupported(MONTH_OF_YEAR)); + assertEquals(false, test.isSupported(PROLEPTIC_MONTH)); + assertEquals(false, test.isSupported(YEAR_OF_ERA)); + assertEquals(false, test.isSupported(YEAR)); + assertEquals(false, test.isSupported(ERA)); + assertEquals(false, test.isSupported(INSTANT_SECONDS)); + assertEquals(false, test.isSupported(OFFSET_SECONDS)); + assertEquals(false, test.isSupported(QUARTER_OF_YEAR)); + assertEquals(true, test.isSupported(HALF_OF_YEAR)); + } + + //----------------------------------------------------------------------- + // range() + //----------------------------------------------------------------------- + @Test + public void test_range() { + assertEquals(HALF_OF_YEAR.range(), Half.H1.range(HALF_OF_YEAR)); + } + + @Test + public void test_range_invalidField() { + assertThrows(UnsupportedTemporalTypeException.class, () -> Half.H1.range(MONTH_OF_YEAR)); + } + + @Test + public void test_range_null() { + assertThrows(NullPointerException.class, () -> Half.H1.range(null)); + } + + //----------------------------------------------------------------------- + // get() + //----------------------------------------------------------------------- + @Test + public void test_get() { + assertEquals(1, Half.H1.get(HALF_OF_YEAR)); + assertEquals(2, Half.H2.get(HALF_OF_YEAR)); + } + + @Test + public void test_get_invalidField() { + assertThrows(UnsupportedTemporalTypeException.class, () -> Half.H2.get(MONTH_OF_YEAR)); + } + + @Test + public void test_get_null() { + assertThrows(NullPointerException.class, () -> Half.H2.get(null)); + } + + //----------------------------------------------------------------------- + // getLong() + //----------------------------------------------------------------------- + @Test + public void test_getLong() { + assertEquals(1, Half.H1.getLong(HALF_OF_YEAR)); + assertEquals(2, Half.H2.getLong(HALF_OF_YEAR)); + } + + @Test + public void test_getLong_invalidField() { + assertThrows(UnsupportedTemporalTypeException.class, () -> Half.H2.getLong(MONTH_OF_YEAR)); + } + + @Test + public void test_getLong_null() { + assertThrows(NullPointerException.class, () -> Half.H2.getLong(null)); + } + + //----------------------------------------------------------------------- + // plus(long), plus(long,unit) + //----------------------------------------------------------------------- + public static Object[][] data_plus() { + return new Object[][] { + {1, -4, 1}, + {1, -3, 2}, + {1, -2, 1}, + {1, -1, 2}, + {1, 0, 1}, + {1, 1, 2}, + {1, 2, 1}, + {1, 3, 2}, + {1, 4, 1}, + }; + } + + @ParameterizedTest + @MethodSource("data_plus") + public void test_plus_long(int base, long amount, int expected) { + assertEquals(Half.of(expected), Half.of(base).plus(amount)); + } + + //----------------------------------------------------------------------- + // minus(long), minus(long,unit) + //----------------------------------------------------------------------- + public static Object[][] data_minus() { + return new Object[][] { + {1, -4, 1}, + {1, -3, 2}, + {1, -2, 1}, + {1, -1, 2}, + {1, 0, 1}, + {1, 1, 2}, + {1, 2, 1}, + {1, 3, 2}, + {1, 4, 1}, + }; + } + + @ParameterizedTest + @MethodSource("data_minus") + public void test_minus_long(int base, long amount, int expected) { + assertEquals(Half.of(expected), Half.of(base).minus(amount)); + } + + //----------------------------------------------------------------------- + // length(boolean) + //----------------------------------------------------------------------- + @Test + public void test_length_boolean() { + assertEquals(182, Half.H1.length(true)); + assertEquals(181, Half.H1.length(false)); + assertEquals(184, Half.H2.length(true)); + assertEquals(184, Half.H2.length(false)); + } + + //----------------------------------------------------------------------- + // firstMonth() + //----------------------------------------------------------------------- + @Test + public void test_firstMonth() { + assertEquals(Month.JANUARY, Half.H1.firstMonth()); + assertEquals(Month.JULY, Half.H2.firstMonth()); + } + + //----------------------------------------------------------------------- + // query() + //----------------------------------------------------------------------- + @Test + public void test_query() { + assertEquals(IsoChronology.INSTANCE, Half.H1.query(TemporalQueries.chronology())); + assertEquals(null, Half.H1.query(TemporalQueries.localDate())); + assertEquals(null, Half.H1.query(TemporalQueries.localTime())); + assertEquals(null, Half.H1.query(TemporalQueries.offset())); + assertEquals(HALF_YEARS, Half.H1.query(TemporalQueries.precision())); + assertEquals(null, Half.H1.query(TemporalQueries.zone())); + assertEquals(null, Half.H1.query(TemporalQueries.zoneId())); + } + + //----------------------------------------------------------------------- + // toString() + //----------------------------------------------------------------------- + @Test + public void test_toString() { + assertEquals("H1", Half.H1.toString()); + assertEquals("H2", Half.H2.toString()); + } + + //----------------------------------------------------------------------- + // generated methods + //----------------------------------------------------------------------- + @Test + public void test_enum() { + assertEquals(Half.H2, Half.valueOf("H2")); + assertEquals(Half.H1, Half.values()[0]); + } + +} diff --git a/src/test/java/org/threeten/extra/TestTemporalFields.java b/src/test/java/org/threeten/extra/TestTemporalFields.java new file mode 100644 index 00000000..d74f8972 --- /dev/null +++ b/src/test/java/org/threeten/extra/TestTemporalFields.java @@ -0,0 +1,268 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.extra; + +import static java.time.temporal.ChronoField.YEAR; +import static java.time.temporal.ChronoUnit.DAYS; +import static java.time.temporal.ChronoUnit.YEARS; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.threeten.extra.TemporalFields.DAY_OF_HALF; +import static org.threeten.extra.TemporalFields.HALF_OF_YEAR; +import static org.threeten.extra.TemporalFields.HALF_YEARS; + +import java.time.DateTimeException; +import java.time.LocalDate; +import java.time.YearMonth; +import java.time.format.ResolverStyle; +import java.time.temporal.TemporalAccessor; +import java.time.temporal.TemporalField; +import java.time.temporal.ValueRange; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +/** + * Test TemporalFields. + */ +public class TestTemporalFields { + + //----------------------------------------------------------------------- + // DAY_OF_HALF + //----------------------------------------------------------------------- + @Test + public void test_DAY_OF_HALF() { + assertEquals(DAYS, DAY_OF_HALF.getBaseUnit()); + assertEquals(HALF_YEARS, DAY_OF_HALF.getRangeUnit()); + assertEquals(true, DAY_OF_HALF.isDateBased()); + assertEquals(false, DAY_OF_HALF.isTimeBased()); + assertEquals("DayOfHalf", DAY_OF_HALF.toString()); + + assertEquals(true, DAY_OF_HALF.isSupportedBy(LocalDate.of(2023, 6, 30))); + assertEquals(false, DAY_OF_HALF.isSupportedBy(DayOfYear.of(32))); + assertEquals(false, DAY_OF_HALF.isSupportedBy(YearMonth.of(2023, 6))); + assertEquals(181, DAY_OF_HALF.getFrom(LocalDate.of(2023, 6, 30))); + assertEquals(184, DAY_OF_HALF.getFrom(LocalDate.of(2023, 12, 31))); + + assertEquals(ValueRange.of(1, 181, 184), DAY_OF_HALF.range()); + assertEquals(ValueRange.of(1, 181), DAY_OF_HALF.rangeRefinedBy(LocalDate.of(2023, 6, 30))); + assertEquals(ValueRange.of(1, 182), DAY_OF_HALF.rangeRefinedBy(LocalDate.of(2024, 6, 30))); + assertEquals(ValueRange.of(1, 184), DAY_OF_HALF.rangeRefinedBy(LocalDate.of(2023, 7, 30))); + + assertEquals(LocalDate.of(2023, 1, 20), DAY_OF_HALF.adjustInto(LocalDate.of(2023, 6, 30), 20)); + assertEquals(LocalDate.of(2023, 7, 20), DAY_OF_HALF.adjustInto(LocalDate.of(2023, 7, 1), 20)); + } + + //----------------------------------------------------------------------- + // HALF_OF_YEAR + //----------------------------------------------------------------------- + @Test + public void test_HALF_OF_YEAR() { + assertEquals(HALF_YEARS, HALF_OF_YEAR.getBaseUnit()); + assertEquals(YEARS, HALF_OF_YEAR.getRangeUnit()); + assertEquals(true, HALF_OF_YEAR.isDateBased()); + assertEquals(false, HALF_OF_YEAR.isTimeBased()); + assertEquals("HalfOfYear", HALF_OF_YEAR.toString()); + + assertEquals(true, HALF_OF_YEAR.isSupportedBy(LocalDate.of(2023, 6, 30))); + assertEquals(true, HALF_OF_YEAR.isSupportedBy(Quarter.Q2)); + assertEquals(false, HALF_OF_YEAR.isSupportedBy(DayOfYear.of(32))); + assertEquals(true, HALF_OF_YEAR.isSupportedBy(YearMonth.of(2023, 6))); + assertEquals(1, HALF_OF_YEAR.getFrom(LocalDate.of(2023, 6, 30))); + assertEquals(2, HALF_OF_YEAR.getFrom(LocalDate.of(2023, 12, 31))); + + assertEquals(ValueRange.of(1, 2), HALF_OF_YEAR.range()); + assertEquals(ValueRange.of(1, 2), HALF_OF_YEAR.rangeRefinedBy(LocalDate.of(2023, 6, 30))); + assertEquals(ValueRange.of(1, 2), HALF_OF_YEAR.rangeRefinedBy(LocalDate.of(2024, 6, 30))); + assertEquals(ValueRange.of(1, 2), HALF_OF_YEAR.rangeRefinedBy(LocalDate.of(2023, 7, 30))); + + assertEquals(LocalDate.of(2023, 12, 30), HALF_OF_YEAR.adjustInto(LocalDate.of(2023, 6, 30), 2)); + assertEquals(LocalDate.of(2023, 7, 1), HALF_OF_YEAR.adjustInto(LocalDate.of(2023, 7, 1), 2)); + + assertEquals(YearMonth.of(2023, 12), HALF_OF_YEAR.adjustInto(YearMonth.of(2023, 6), 2)); + } + + //----------------------------------------------------------------------- + // HALF_YEARS + //----------------------------------------------------------------------- + @Test + public void test_HALF_YEARS() { + assertEquals(true, HALF_YEARS.isDateBased()); + assertEquals(false, HALF_YEARS.isTimeBased()); + assertEquals("HalfYears", HALF_YEARS.toString()); + + assertEquals(true, HALF_YEARS.isSupportedBy(LocalDate.of(2023, 6, 30))); + assertEquals(true, HALF_YEARS.isSupportedBy(YearQuarter.of(2023, 2))); + assertEquals(true, HALF_YEARS.isSupportedBy(YearMonth.of(2023, 6))); + + assertEquals(LocalDate.of(2023, 12, 30), HALF_YEARS.addTo(LocalDate.of(2023, 6, 30), 1)); + assertEquals(YearQuarter.of(2023, 4), HALF_YEARS.addTo(YearQuarter.of(2023, 2), 1)); + assertEquals(YearMonth.of(2023, 12), HALF_YEARS.addTo(YearMonth.of(2023, 6), 1)); + + assertEquals(0, HALF_YEARS.between(LocalDate.of(2023, 6, 30), LocalDate.of(2023, 12, 29))); + assertEquals(1, HALF_YEARS.between(LocalDate.of(2023, 6, 30), LocalDate.of(2023, 12, 30))); + + assertEquals(0, HALF_YEARS.between(YearQuarter.of(2023, 2), YearQuarter.of(2023, 3))); + assertEquals(1, HALF_YEARS.between(YearQuarter.of(2023, 2), YearQuarter.of(2023, 4))); + + assertEquals(0, HALF_YEARS.between(YearMonth.of(2023, 2), YearMonth.of(2023, 7))); + assertEquals(1, HALF_YEARS.between(YearMonth.of(2023, 2), YearMonth.of(2023, 8))); + } + + //------------------------------------------------------------------------- + @Test + public void test_resolveStrict() { + Map values = new HashMap<>(); + values.put(DAY_OF_HALF, 20L); + values.put(HALF_OF_YEAR, 2L); + values.put(YEAR, 2023L); + TemporalAccessor resolved = DAY_OF_HALF.resolve(values, LocalDate.of(1, 1, 1), ResolverStyle.STRICT); + assertEquals(LocalDate.of(2023, 7, 20), resolved.query(LocalDate::from)); + } + + @Test + public void test_resolveStrict_noYear() { + Map values = new HashMap<>(); + values.put(DAY_OF_HALF, 20L); + values.put(HALF_OF_YEAR, 1L); + assertNull(DAY_OF_HALF.resolve(values, LocalDate.of(1, 1, 1), ResolverStyle.STRICT)); + } + + @Test + public void test_resolveStrict_halfOfYear() { + Map values = new HashMap<>(); + values.put(DAY_OF_HALF, 20L); + values.put(YEAR, 2023L); + assertNull(DAY_OF_HALF.resolve(values, LocalDate.of(1, 1, 1), ResolverStyle.STRICT)); + } + + @Test + public void test_resolveStrict_badHalfOfYear() { + Map values = new HashMap<>(); + values.put(DAY_OF_HALF, 20L); + values.put(HALF_OF_YEAR, 3L); + values.put(YEAR, 2023L); + assertThrows(DateTimeException.class, () -> DAY_OF_HALF.resolve(values, LocalDate.of(1, 1, 1), ResolverStyle.STRICT)); + } + + @Test + public void test_resolveStrict_day0() { + Map values = new HashMap<>(); + values.put(DAY_OF_HALF, 0L); + values.put(HALF_OF_YEAR, 1L); + values.put(YEAR, 2023L); + assertThrows(DateTimeException.class, () -> DAY_OF_HALF.resolve(values, LocalDate.of(1, 1, 1), ResolverStyle.STRICT)); + } + + @Test + public void test_resolveStrict_day182_notLeap() { + Map values = new HashMap<>(); + values.put(DAY_OF_HALF, 182L); + values.put(HALF_OF_YEAR, 1L); + values.put(YEAR, 2023L); + assertThrows(DateTimeException.class, () -> DAY_OF_HALF.resolve(values, LocalDate.of(1, 1, 1), ResolverStyle.STRICT)); + } + + @Test + public void test_resolveStrict_day182_leap() { + Map values = new HashMap<>(); + values.put(DAY_OF_HALF, 182L); + values.put(HALF_OF_YEAR, 1L); + values.put(YEAR, 2024L); + TemporalAccessor resolved = DAY_OF_HALF.resolve(values, LocalDate.of(1, 1, 1), ResolverStyle.STRICT); + assertEquals(LocalDate.of(2024, 6, 30), resolved.query(LocalDate::from)); + } + + //------------------------------------------------------------------------- + @Test + public void test_resolveSmart_day181_notLeap() { + Map values = new HashMap<>(); + values.put(DAY_OF_HALF, 181L); + values.put(HALF_OF_YEAR, 1L); + values.put(YEAR, 2023L); + TemporalAccessor resolved = DAY_OF_HALF.resolve(values, LocalDate.of(1, 1, 1), ResolverStyle.SMART); + assertEquals(LocalDate.of(2023, 6, 30), resolved.query(LocalDate::from)); + } + + @Test + public void test_resolveSmart_day184() { + Map values = new HashMap<>(); + values.put(DAY_OF_HALF, 184L); + values.put(HALF_OF_YEAR, 1L); + values.put(YEAR, 2023L); + TemporalAccessor resolved = DAY_OF_HALF.resolve(values, LocalDate.of(1, 1, 1), ResolverStyle.SMART); + assertEquals(LocalDate.of(2023, 7, 3), resolved.query(LocalDate::from)); + } + + @Test + public void test_resolve_day185() { + Map values = new HashMap<>(); + values.put(DAY_OF_HALF, 185L); + values.put(HALF_OF_YEAR, 1L); + values.put(YEAR, 2023L); + assertThrows(DateTimeException.class, () -> DAY_OF_HALF.resolve(values, LocalDate.of(1, 1, 1), ResolverStyle.STRICT)); + } + + //------------------------------------------------------------------------- + @Test + public void test_resolveLenient_day181_notLeap() { + Map values = new HashMap<>(); + values.put(DAY_OF_HALF, 181L); + values.put(HALF_OF_YEAR, 1L); + values.put(YEAR, 2023L); + TemporalAccessor resolved = DAY_OF_HALF.resolve(values, LocalDate.of(1, 1, 1), ResolverStyle.LENIENT); + assertEquals(LocalDate.of(2023, 6, 30), resolved.query(LocalDate::from)); + } + + @Test + public void test_resolveLenient_day0() { + Map values = new HashMap<>(); + values.put(DAY_OF_HALF, 0L); + values.put(HALF_OF_YEAR, 1L); + values.put(YEAR, 2023L); + TemporalAccessor resolved = DAY_OF_HALF.resolve(values, LocalDate.of(1, 1, 1), ResolverStyle.LENIENT); + assertEquals(LocalDate.of(2022, 12, 31), resolved.query(LocalDate::from)); + } + + @Test + public void test_resolveLenient_day185() { + Map values = new HashMap<>(); + values.put(DAY_OF_HALF, 185L); + values.put(HALF_OF_YEAR, 1L); + values.put(YEAR, 2023L); + TemporalAccessor resolved = DAY_OF_HALF.resolve(values, LocalDate.of(1, 1, 1), ResolverStyle.LENIENT); + assertEquals(LocalDate.of(2023, 7, 4), resolved.query(LocalDate::from)); + } + +} diff --git a/src/test/java/org/threeten/extra/TestYearHalf.java b/src/test/java/org/threeten/extra/TestYearHalf.java new file mode 100644 index 00000000..c4d5953e --- /dev/null +++ b/src/test/java/org/threeten/extra/TestYearHalf.java @@ -0,0 +1,999 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.extra; + +import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH; +import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR; +import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH; +import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR; +import static java.time.temporal.ChronoField.AMPM_OF_DAY; +import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_AMPM; +import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_DAY; +import static java.time.temporal.ChronoField.DAY_OF_MONTH; +import static java.time.temporal.ChronoField.DAY_OF_WEEK; +import static java.time.temporal.ChronoField.DAY_OF_YEAR; +import static java.time.temporal.ChronoField.EPOCH_DAY; +import static java.time.temporal.ChronoField.ERA; +import static java.time.temporal.ChronoField.HOUR_OF_AMPM; +import static java.time.temporal.ChronoField.HOUR_OF_DAY; +import static java.time.temporal.ChronoField.INSTANT_SECONDS; +import static java.time.temporal.ChronoField.MICRO_OF_DAY; +import static java.time.temporal.ChronoField.MICRO_OF_SECOND; +import static java.time.temporal.ChronoField.MILLI_OF_DAY; +import static java.time.temporal.ChronoField.MILLI_OF_SECOND; +import static java.time.temporal.ChronoField.MINUTE_OF_DAY; +import static java.time.temporal.ChronoField.MINUTE_OF_HOUR; +import static java.time.temporal.ChronoField.MONTH_OF_YEAR; +import static java.time.temporal.ChronoField.NANO_OF_DAY; +import static java.time.temporal.ChronoField.NANO_OF_SECOND; +import static java.time.temporal.ChronoField.OFFSET_SECONDS; +import static java.time.temporal.ChronoField.PROLEPTIC_MONTH; +import static java.time.temporal.ChronoField.SECOND_OF_DAY; +import static java.time.temporal.ChronoField.SECOND_OF_MINUTE; +import static java.time.temporal.ChronoField.YEAR; +import static java.time.temporal.ChronoField.YEAR_OF_ERA; +import static java.time.temporal.ChronoUnit.CENTURIES; +import static java.time.temporal.ChronoUnit.DAYS; +import static java.time.temporal.ChronoUnit.DECADES; +import static java.time.temporal.ChronoUnit.FOREVER; +import static java.time.temporal.ChronoUnit.HOURS; +import static java.time.temporal.ChronoUnit.MICROS; +import static java.time.temporal.ChronoUnit.MILLENNIA; +import static java.time.temporal.ChronoUnit.MILLIS; +import static java.time.temporal.ChronoUnit.MINUTES; +import static java.time.temporal.ChronoUnit.MONTHS; +import static java.time.temporal.ChronoUnit.NANOS; +import static java.time.temporal.ChronoUnit.SECONDS; +import static java.time.temporal.ChronoUnit.WEEKS; +import static java.time.temporal.ChronoUnit.YEARS; +import static java.time.temporal.IsoFields.DAY_OF_QUARTER; +import static java.time.temporal.IsoFields.QUARTER_OF_YEAR; +import static java.time.temporal.IsoFields.QUARTER_YEARS; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.threeten.extra.Half.H1; +import static org.threeten.extra.Half.H2; +import static org.threeten.extra.TemporalFields.DAY_OF_HALF; +import static org.threeten.extra.TemporalFields.HALF_OF_YEAR; +import static org.threeten.extra.TemporalFields.HALF_YEARS; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.time.DateTimeException; +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.Year; +import java.time.chrono.IsoChronology; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; +import java.time.temporal.Temporal; +import java.time.temporal.TemporalAccessor; +import java.time.temporal.TemporalAdjuster; +import java.time.temporal.TemporalField; +import java.time.temporal.TemporalQueries; +import java.time.temporal.TemporalUnit; +import java.time.temporal.UnsupportedTemporalTypeException; +import java.time.temporal.ValueRange; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.junit.jupiter.api.Test; + +/** + * Test YearHalf. + */ +public class TestYearHalf { + + private static final YearHalf TEST = YearHalf.of(2012, H2); + private static final int STANDARD_YEAR_LENGTH = 365; + private static final int LEAP_YEAR_LENGTH = 366; + + //----------------------------------------------------------------------- + @Test + public void test_interfaces() { + assertTrue(Serializable.class.isAssignableFrom(YearHalf.class)); + assertTrue(Comparable.class.isAssignableFrom(YearHalf.class)); + assertTrue(TemporalAdjuster.class.isAssignableFrom(YearHalf.class)); + assertTrue(TemporalAccessor.class.isAssignableFrom(YearHalf.class)); + } + + @Test + public void test_serialization() throws IOException, ClassNotFoundException { + YearHalf test = YearHalf.of(2012, 1); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertEquals(test, ois.readObject()); + } + } + + //----------------------------------------------------------------------- + // of(Year,Half) + //----------------------------------------------------------------------- + @Test + public void test_of_Year_Half() { + for (int year = -100; year <= 100; year++) { + for (Half half : Half.values()) { + YearHalf test = YearHalf.of(Year.of(year), half); + assertEquals(year, test.getYear()); + assertEquals(half.getValue(), test.getHalfValue()); + assertEquals(half, test.getHalf()); + } + } + } + + @Test + public void test_of_Year_Half_nullHalf() { + assertThrows(NullPointerException.class, () -> YearHalf.of(Year.of(2012), (Half) null)); + } + + @Test + public void test_of_Year_Half_nullYear() { + assertThrows(NullPointerException.class, () -> YearHalf.of((Year) null, Half.H2)); + } + + @Test + public void test_of_Year_Half_nullBoth() { + assertThrows(NullPointerException.class, () -> YearHalf.of((Year) null, (Half) null)); + } + + //----------------------------------------------------------------------- + // of(Year,int) + //----------------------------------------------------------------------- + @Test + public void test_of_Year_int() { + for (int year = -100; year <= 100; year++) { + for (Half half : Half.values()) { + YearHalf test = YearHalf.of(Year.of(year), half.getValue()); + assertEquals(year, test.getYear()); + assertEquals(half.getValue(), test.getHalfValue()); + assertEquals(half, test.getHalf()); + } + } + } + + @Test + public void test_of_Year_int_null() { + assertThrows(NullPointerException.class, () -> YearHalf.of((Year) null, 2)); + } + + //----------------------------------------------------------------------- + // of(int,Half) + //----------------------------------------------------------------------- + @Test + public void test_of_int_Half() { + for (int year = -100; year <= 100; year++) { + for (Half half : Half.values()) { + YearHalf test = YearHalf.of(year, half); + assertEquals(year, test.getYear()); + assertEquals(half.getValue(), test.getHalfValue()); + assertEquals(half, test.getHalf()); + } + } + } + + @Test + public void test_of_int_Half_yearTooLow() { + assertThrows(DateTimeException.class, () -> YearHalf.of(Year.MIN_VALUE - 1, Half.H2)); + } + + @Test + public void test_of_int_Half_yearTooHigh() { + assertThrows(DateTimeException.class, () -> YearHalf.of(Year.MAX_VALUE + 1, Half.H2)); + } + + @Test + public void test_of_int_Half_null() { + assertThrows(NullPointerException.class, () -> YearHalf.of(2012, (Half) null)); + } + + //----------------------------------------------------------------------- + // of(int,int) + //----------------------------------------------------------------------- + @Test + public void test_of_int_int() { + for (int year = -100; year <= 100; year++) { + for (int half = 1; half <= 2; half++) { + YearHalf test = YearHalf.of(year, half); + assertEquals(year, test.getYear()); + assertEquals(half, test.getHalfValue()); + assertEquals(Half.of(half), test.getHalf()); + assertEquals(test, YearHalf.of(year, half)); + assertEquals(test.hashCode(), YearHalf.of(year, half).hashCode()); + } + } + } + + @Test + public void test_of_int_int_yearTooLow() { + assertThrows(DateTimeException.class, () -> YearHalf.of(Year.MIN_VALUE - 1, 1)); + } + + @Test + public void test_of_int_int_yearTooHigh() { + assertThrows(DateTimeException.class, () -> YearHalf.of(Year.MAX_VALUE + 1, 1)); + } + + @Test + public void test_of_int_int_halfTooLow() { + assertThrows(DateTimeException.class, () -> YearHalf.of(2012, 0)); + } + + @Test + public void test_of_int_int_halfTooHigh() { + assertThrows(DateTimeException.class, () -> YearHalf.of(2012, 3)); + } + + //----------------------------------------------------------------------- + // from(TemporalAccessor) + //----------------------------------------------------------------------- + @Test + public void test_from_TemporalAccessor_notLeapYear() { + LocalDate date = LocalDate.of(2007, 1, 1); + for (int i = 1; i <= STANDARD_YEAR_LENGTH; i++) { + YearHalf test = YearHalf.from(date); + int expected = ((date.getMonthValue() - 1) / 6) + 1; + assertEquals(YearHalf.of(2007, expected), test); + date = date.plusDays(1); + } + } + + @Test + public void test_from_TemporalAccessor_leapYear() { + LocalDate date = LocalDate.of(2008, 1, 1); + for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) { + YearHalf test = YearHalf.from(date); + int expected = ((date.getMonthValue() - 1) / 6) + 1; + assertEquals(YearHalf.of(2008, expected), test); + date = date.plusDays(1); + } + } + + @Test + public void test_from_TemporalAccessor_noDerive() { + assertThrows(DateTimeException.class, () -> YearHalf.from(LocalTime.NOON)); + } + + @Test + public void test_from_TemporalAccessor_null() { + assertThrows(NullPointerException.class, () -> YearHalf.from((TemporalAccessor) null)); + } + + //----------------------------------------------------------------------- + // parse(CharSequence) + //----------------------------------------------------------------------- + @Test + public void test_parse_CharSequence() { + assertEquals(YearHalf.of(2012, H2), YearHalf.parse("2012-H2")); + } + + @Test + public void test_parse_CharSequence_caseInsensitive() { + assertEquals(YearHalf.of(2012, H1), YearHalf.parse("2012-h1")); + } + + @Test + public void test_parse_CharSequenceDate_invalidYear() { + assertThrows(DateTimeParseException.class, () -> YearHalf.parse("12345-H1")); + } + + @Test + public void test_parse_CharSequenceDate_invalidHalf() { + assertThrows(DateTimeParseException.class, () -> YearHalf.parse("2012-H0")); + } + + @Test + public void test_parse_CharSequenceDate_nullCharSequence() { + assertThrows(NullPointerException.class, () -> YearHalf.parse((CharSequence) null)); + } + + //----------------------------------------------------------------------- + // parse(CharSequence,DateTimeFormatter) + //----------------------------------------------------------------------- + @Test + public void test_parse_CharSequenceDateTimeFormatter() { + DateTimeFormatter f = new DateTimeFormatterBuilder() + .appendLiteral('H') + .appendValue(HALF_OF_YEAR, 1) + .appendLiteral(' ') + .appendValue(YEAR) + .toFormatter(); + assertEquals(YearHalf.of(2012, H1), YearHalf.parse("H1 2012", f)); + } + + @Test + public void test_parse_CharSequenceDateDateTimeFormatter_invalidHalf() { + DateTimeFormatter f = new DateTimeFormatterBuilder() + .appendLiteral('H') + .appendValue(HALF_OF_YEAR, 1) + .appendLiteral(' ') + .appendValue(YEAR) + .toFormatter(); + assertThrows(DateTimeParseException.class, () -> YearHalf.parse("H0 2012", f)); + } + + @Test + public void test_parse_CharSequenceDateTimeFormatter_nullCharSequence() { + DateTimeFormatter f = new DateTimeFormatterBuilder() + .appendLiteral('H') + .appendValue(HALF_OF_YEAR, 1) + .appendLiteral(' ') + .appendValue(YEAR) + .toFormatter(); + assertThrows(NullPointerException.class, () -> YearHalf.parse((CharSequence) null, f)); + } + + @Test + public void test_parse_CharSequenceDateTimeFormatter_nullDateTimeFormatter() { + assertThrows(NullPointerException.class, () -> YearHalf.parse("", (DateTimeFormatter) null)); + } + + //----------------------------------------------------------------------- + // isSupported(TemporalField) + //----------------------------------------------------------------------- + @Test + public void test_isSupported_TemporalField() { + assertEquals(false, TEST.isSupported((TemporalField) null)); + assertEquals(false, TEST.isSupported(NANO_OF_SECOND)); + assertEquals(false, TEST.isSupported(NANO_OF_DAY)); + assertEquals(false, TEST.isSupported(MICRO_OF_SECOND)); + assertEquals(false, TEST.isSupported(MICRO_OF_DAY)); + assertEquals(false, TEST.isSupported(MILLI_OF_SECOND)); + assertEquals(false, TEST.isSupported(MILLI_OF_DAY)); + assertEquals(false, TEST.isSupported(SECOND_OF_MINUTE)); + assertEquals(false, TEST.isSupported(SECOND_OF_DAY)); + assertEquals(false, TEST.isSupported(MINUTE_OF_HOUR)); + assertEquals(false, TEST.isSupported(MINUTE_OF_DAY)); + assertEquals(false, TEST.isSupported(HOUR_OF_AMPM)); + assertEquals(false, TEST.isSupported(CLOCK_HOUR_OF_AMPM)); + assertEquals(false, TEST.isSupported(HOUR_OF_DAY)); + assertEquals(false, TEST.isSupported(CLOCK_HOUR_OF_DAY)); + assertEquals(false, TEST.isSupported(AMPM_OF_DAY)); + assertEquals(false, TEST.isSupported(DAY_OF_WEEK)); + assertEquals(false, TEST.isSupported(ALIGNED_DAY_OF_WEEK_IN_MONTH)); + assertEquals(false, TEST.isSupported(ALIGNED_DAY_OF_WEEK_IN_YEAR)); + assertEquals(false, TEST.isSupported(DAY_OF_MONTH)); + assertEquals(false, TEST.isSupported(DAY_OF_YEAR)); + assertEquals(false, TEST.isSupported(EPOCH_DAY)); + assertEquals(false, TEST.isSupported(ALIGNED_WEEK_OF_MONTH)); + assertEquals(false, TEST.isSupported(ALIGNED_WEEK_OF_YEAR)); + assertEquals(false, TEST.isSupported(MONTH_OF_YEAR)); + assertEquals(false, TEST.isSupported(PROLEPTIC_MONTH)); + assertEquals(true, TEST.isSupported(YEAR_OF_ERA)); + assertEquals(true, TEST.isSupported(YEAR)); + assertEquals(true, TEST.isSupported(ERA)); + assertEquals(false, TEST.isSupported(INSTANT_SECONDS)); + assertEquals(false, TEST.isSupported(OFFSET_SECONDS)); + assertEquals(false, TEST.isSupported(QUARTER_OF_YEAR)); + assertEquals(false, TEST.isSupported(DAY_OF_QUARTER)); + assertEquals(true, TEST.isSupported(HALF_OF_YEAR)); + assertEquals(false, TEST.isSupported(DAY_OF_HALF)); + } + + //----------------------------------------------------------------------- + // isSupported(TemporalUnit) + //----------------------------------------------------------------------- + @Test + public void test_isSupported_TemporalUnit() { + assertEquals(false, TEST.isSupported((TemporalUnit) null)); + assertEquals(false, TEST.isSupported(NANOS)); + assertEquals(false, TEST.isSupported(MICROS)); + assertEquals(false, TEST.isSupported(MILLIS)); + assertEquals(false, TEST.isSupported(SECONDS)); + assertEquals(false, TEST.isSupported(MINUTES)); + assertEquals(false, TEST.isSupported(HOURS)); + assertEquals(false, TEST.isSupported(DAYS)); + assertEquals(false, TEST.isSupported(WEEKS)); + assertEquals(false, TEST.isSupported(MONTHS)); + assertEquals(true, TEST.isSupported(YEARS)); + assertEquals(true, TEST.isSupported(DECADES)); + assertEquals(true, TEST.isSupported(CENTURIES)); + assertEquals(true, TEST.isSupported(MILLENNIA)); + assertEquals(true, TEST.isSupported(ERA)); + assertEquals(false, TEST.isSupported(FOREVER)); + assertEquals(false, TEST.isSupported(QUARTER_YEARS)); + assertEquals(true, TEST.isSupported(HALF_YEARS)); + } + + //----------------------------------------------------------------------- + // range(TemporalField) + //----------------------------------------------------------------------- + @Test + public void test_range() { + assertEquals(HALF_OF_YEAR.range(), TEST.range(HALF_OF_YEAR)); + assertEquals(YEAR.range(), TEST.range(YEAR)); + assertEquals(ValueRange.of(1, Year.MAX_VALUE), TEST.range(YEAR_OF_ERA)); + assertEquals(ERA.range(), TEST.range(ERA)); + } + + @Test + public void test_range_invalidField() { + assertThrows(UnsupportedTemporalTypeException.class, () -> TEST.range(MONTH_OF_YEAR)); + } + + @Test + public void test_range_null() { + assertThrows(NullPointerException.class, () -> TEST.range((TemporalField) null)); + } + + //----------------------------------------------------------------------- + // get(TemporalField) + //----------------------------------------------------------------------- + @Test + public void test_get() { + assertEquals(2, TEST.get(HALF_OF_YEAR)); + assertEquals(2012, TEST.get(YEAR)); + assertEquals(2012, TEST.get(YEAR_OF_ERA)); + assertEquals(1, TEST.get(ERA)); + } + + @Test + public void test_get_invalidField() { + assertThrows(UnsupportedTemporalTypeException.class, () -> TEST.get(MONTH_OF_YEAR)); + } + + @Test + public void test_get_null() { + assertThrows(NullPointerException.class, () -> TEST.get((TemporalField) null)); + } + + //----------------------------------------------------------------------- + // getLong(TemporalField) + //----------------------------------------------------------------------- + @Test + public void test_getLong() { + assertEquals(2L, TEST.getLong(HALF_OF_YEAR)); + assertEquals(2012L, TEST.getLong(YEAR)); + assertEquals(2012L, TEST.getLong(YEAR_OF_ERA)); + assertEquals(1L, TEST.getLong(ERA)); + } + + @Test + public void test_getLong_invalidField() { + assertThrows(UnsupportedTemporalTypeException.class, () -> TEST.getLong(MONTH_OF_YEAR)); + } + + @Test + public void test_getLong_null() { + assertThrows(NullPointerException.class, () -> TEST.getLong((TemporalField) null)); + } + + //----------------------------------------------------------------------- + // isLeapYear(int) + //----------------------------------------------------------------------- + @Test + public void test_isLeapYear_int() { + for (int year = -500; year <= 500; year++) { + for (Half half : Half.values()) { + YearHalf test = YearHalf.of(year, half); + assertEquals(Year.isLeap(year), test.isLeapYear()); + } + } + } + + //----------------------------------------------------------------------- + // isValidDay(int) + //----------------------------------------------------------------------- + @Test + public void test_isValidDay_int_nonLeap() { + assertEquals(true, YearHalf.of(2011, H1).isValidDay(181)); + assertEquals(false, YearHalf.of(2011, H1).isValidDay(182)); + assertEquals(false, YearHalf.of(2011, H1).isValidDay(183)); + + assertEquals(true, YearHalf.of(2011, H2).isValidDay(183)); + assertEquals(true, YearHalf.of(2011, H2).isValidDay(184)); + assertEquals(false, YearHalf.of(2011, H2).isValidDay(185)); + } + + @Test + public void test_isValidDay_int_leap() { + assertEquals(true, YearHalf.of(2012, H1).isValidDay(181)); + assertEquals(true, YearHalf.of(2012, H1).isValidDay(182)); + assertEquals(false, YearHalf.of(2012, H1).isValidDay(183)); + + assertEquals(true, YearHalf.of(2012, H2).isValidDay(183)); + assertEquals(true, YearHalf.of(2012, H2).isValidDay(184)); + assertEquals(false, YearHalf.of(2012, H2).isValidDay(185)); + } + + @Test + public void test_isValidDay_int_outOfRange() { + assertEquals(false, YearHalf.of(2011, H1).isValidDay(185)); + assertEquals(false, YearHalf.of(2011, H2).isValidDay(185)); + + assertEquals(false, YearHalf.of(2011, H1).isValidDay(0)); + assertEquals(false, YearHalf.of(2011, H2).isValidDay(0)); + } + + //----------------------------------------------------------------------- + // lengthOfHalf() + //----------------------------------------------------------------------- + @Test + public void test_lengthOfHalf() { + for (int year = -500; year <= 500; year++) { + assertEquals(Year.isLeap(year) ? 182 : 181, YearHalf.of(year, H1).lengthOfHalf()); + assertEquals(184, YearHalf.of(year, H2).lengthOfHalf()); + } + } + + //----------------------------------------------------------------------- + // with(TemporalAdjuster) + //----------------------------------------------------------------------- + @Test + public void test_with_TemporalAdjuster_Half() { + assertEquals(YearHalf.of(2007, H1), YearHalf.of(2007, H2).with(H1)); + } + + @Test + public void test_with_TemporalAdjuster_Year() { + assertEquals(YearHalf.of(2012, H2), YearHalf.of(2007, H2).with(Year.of(2012))); + } + + @Test + public void test_with_TemporalAdjuster_YearHalf() { + assertEquals(YearHalf.of(2012, H1), YearHalf.of(2007, H2).with(YearHalf.of(2012, H1))); + } + + @Test + public void test_with_TemporalAdjuster_LocalDate() { + assertThrows(DateTimeException.class, () -> YearHalf.of(2007, H2).with(LocalDate.of(2012, 6, 30))); + } + + @Test + public void test_with_TemporalAdjuster_null() { + assertThrows(NullPointerException.class, () -> YearHalf.of(2007, H2).with((TemporalAdjuster) null)); + } + + //----------------------------------------------------------------------- + // withYear(int) + //----------------------------------------------------------------------- + @Test + public void test_withYear() { + assertEquals(YearHalf.of(2012, H2), YearHalf.of(2007, H2).withYear(2012)); + } + + @Test + public void test_withYear_int_halfTooLow() { + assertThrows(DateTimeException.class, () -> TEST.withYear(Year.MIN_VALUE - 1)); + } + + @Test + public void test_withYear_int_halfTooHigh() { + assertThrows(DateTimeException.class, () -> TEST.withYear(Year.MAX_VALUE + 1)); + } + + //----------------------------------------------------------------------- + // withHalf(int) + //----------------------------------------------------------------------- + @Test + public void test_withHalf_int() { + assertEquals(YearHalf.of(2007, H1), YearHalf.of(2007, H2).withHalf(1)); + } + + @Test + public void test_withHalf_int_halfTooLow() { + assertThrows(DateTimeException.class, () -> TEST.withHalf(0)); + } + + @Test + public void test_withHalf_int_halfTooHigh() { + assertThrows(DateTimeException.class, () -> TEST.withHalf(3)); + } + + //----------------------------------------------------------------------- + // plus(long,TemporalUnit) + //----------------------------------------------------------------------- + @Test + public void test_plus_longTemporalUnit() { + assertEquals(YearHalf.of(2012, H2), YearHalf.of(2007, H2).plus(5, YEARS)); + assertEquals(YearHalf.of(2007, H2), YearHalf.of(2007, H2).plus(0, YEARS)); + assertEquals(YearHalf.of(2002, H2), YearHalf.of(2007, H2).plus(-5, YEARS)); + assertEquals(YearHalf.of(2010, H1), YearHalf.of(2007, H2).plus(5, HALF_YEARS)); + assertEquals(YearHalf.of(2007, H2), YearHalf.of(2007, H2).plus(0, HALF_YEARS)); + assertEquals(YearHalf.of(2005, H1), YearHalf.of(2007, H2).plus(-5, HALF_YEARS)); + } + + //----------------------------------------------------------------------- + // plusYears(int) + //----------------------------------------------------------------------- + @Test + public void test_plusYears() { + assertEquals(YearHalf.of(2012, H2), YearHalf.of(2007, H2).plusYears(5)); + assertEquals(YearHalf.of(2007, H2), YearHalf.of(2007, H2).plusYears(0)); + assertEquals(YearHalf.of(2002, H2), YearHalf.of(2007, H2).plusYears(-5)); + } + + //----------------------------------------------------------------------- + // plusHalfs(int) + //----------------------------------------------------------------------- + @Test + public void test_plusHalfs() { + assertEquals(YearHalf.of(2010, H1), YearHalf.of(2007, H2).plusHalfs(5)); + assertEquals(YearHalf.of(2007, H2), YearHalf.of(2007, H2).plusHalfs(0)); + assertEquals(YearHalf.of(2005, H1), YearHalf.of(2007, H2).plusHalfs(-5)); + } + + //----------------------------------------------------------------------- + // minus(long,TemporalUnit) + //----------------------------------------------------------------------- + @Test + public void test_minus_longTemporalUnit() { + assertEquals(YearHalf.of(2002, H2), YearHalf.of(2007, H2).minus(5, YEARS)); + assertEquals(YearHalf.of(2007, H2), YearHalf.of(2007, H2).minus(0, YEARS)); + assertEquals(YearHalf.of(2012, H2), YearHalf.of(2007, H2).minus(-5, YEARS)); + assertEquals(YearHalf.of(2005, H1), YearHalf.of(2007, H2).minus(5, HALF_YEARS)); + assertEquals(YearHalf.of(2007, H2), YearHalf.of(2007, H2).minus(0, HALF_YEARS)); + assertEquals(YearHalf.of(2010, H1), YearHalf.of(2007, H2).minus(-5, HALF_YEARS)); + } + + //----------------------------------------------------------------------- + // minusYears(int) + //----------------------------------------------------------------------- + @Test + public void test_minusYears() { + assertEquals(YearHalf.of(2002, H2), YearHalf.of(2007, H2).minusYears(5)); + assertEquals(YearHalf.of(2007, H2), YearHalf.of(2007, H2).minusYears(0)); + assertEquals(YearHalf.of(2012, H2), YearHalf.of(2007, H2).minusYears(-5)); + } + + //----------------------------------------------------------------------- + // minusHalfs(int) + //----------------------------------------------------------------------- + @Test + public void test_minusHalfs() { + assertEquals(YearHalf.of(2005, H1), YearHalf.of(2007, H2).minusHalfs(5)); + assertEquals(YearHalf.of(2007, H2), YearHalf.of(2007, H2).minusHalfs(0)); + assertEquals(YearHalf.of(2010, H1), YearHalf.of(2007, H2).minusHalfs(-5)); + } + + //----------------------------------------------------------------------- + // lengthOfYear() + //----------------------------------------------------------------------- + @Test + public void test_lengthOfYear() { + for (int year = -500; year <= 500; year++) { + for (Half half : Half.values()) { + YearHalf test = YearHalf.of(year, half); + assertEquals(Year.isLeap(year) ? 366 : 365, test.lengthOfYear()); + } + } + } + + //----------------------------------------------------------------------- + // query(TemporalQuery) + //----------------------------------------------------------------------- + @Test + public void test_query() { + assertEquals(IsoChronology.INSTANCE, TEST.query(TemporalQueries.chronology())); + assertEquals(null, TEST.query(TemporalQueries.localDate())); + assertEquals(null, TEST.query(TemporalQueries.localTime())); + assertEquals(null, TEST.query(TemporalQueries.offset())); + assertEquals(HALF_YEARS, TEST.query(TemporalQueries.precision())); + assertEquals(null, TEST.query(TemporalQueries.zone())); + assertEquals(null, TEST.query(TemporalQueries.zoneId())); + } + + //----------------------------------------------------------------------- + // adjustInto(Temporal) + //----------------------------------------------------------------------- + @Test + public void test_adjustInto_Temporal() { + for (int month = 1; month < 12; month++) { + for (int dom = 1; dom < 28; dom++) { + LocalDate base = LocalDate.of(2007, month, dom); + LocalDate expected = LocalDate.of(2012, 7 + ((month - 1) % 6), dom); + assertEquals(expected, YearHalf.of(2012, H2).adjustInto(base)); + } + } + } + + @Test + public void test_adjustInto_Temporal_lastValidDay_nonLeap() { + LocalDate base = LocalDate.of(2007, 8, 31); + LocalDate expected = LocalDate.of(2011, 2, 28); + assertEquals(expected, YearHalf.of(2011, H1).adjustInto(base)); + } + + @Test + public void test_adjustInto_Temporal_lastValidDay_leap() { + LocalDate base = LocalDate.of(2007, 8, 31); + LocalDate expected = LocalDate.of(2012, 2, 29); + assertEquals(expected, YearHalf.of(2012, H1).adjustInto(base)); + } + + @Test + public void test_adjustInto_Temporal_null() { + assertThrows(NullPointerException.class, () -> TEST.adjustInto((Temporal) null)); + } + + //----------------------------------------------------------------------- + // until(Temporal,TemporalUnit) + //----------------------------------------------------------------------- + @Test + public void test_until_TemporalTemporalUnit_HALF_YEARS() { + assertEquals(-2, YearHalf.of(2012, H2).until(YearHalf.of(2011, H2), HALF_YEARS)); + assertEquals(-1, YearHalf.of(2012, H2).until(YearHalf.of(2012, H1), HALF_YEARS)); + assertEquals(0, YearHalf.of(2012, H2).until(YearHalf.of(2012, H2), HALF_YEARS)); + assertEquals(1, YearHalf.of(2012, H2).until(YearHalf.of(2013, H1), HALF_YEARS)); + assertEquals(2, YearHalf.of(2012, H2).until(YearHalf.of(2013, H2), HALF_YEARS)); + assertEquals(3, YearHalf.of(2012, H2).until(YearHalf.of(2014, H1), HALF_YEARS)); + } + + @Test + public void test_until_TemporalTemporalUnit_YEARS() { + assertEquals(-2, YearHalf.of(2012, H2).until(YearHalf.of(2010, H2), YEARS)); + assertEquals(-1, YearHalf.of(2012, H2).until(YearHalf.of(2011, H1), YEARS)); + assertEquals(-1, YearHalf.of(2012, H2).until(YearHalf.of(2011, H2), YEARS)); + assertEquals(0, YearHalf.of(2012, H2).until(YearHalf.of(2012, H1), YEARS)); + assertEquals(0, YearHalf.of(2012, H2).until(YearHalf.of(2012, H2), YEARS)); + assertEquals(0, YearHalf.of(2012, H2).until(YearHalf.of(2013, H1), YEARS)); + assertEquals(1, YearHalf.of(2012, H2).until(YearHalf.of(2013, H2), YEARS)); + assertEquals(1, YearHalf.of(2012, H2).until(YearHalf.of(2014, H1), YEARS)); + assertEquals(2, YearHalf.of(2012, H2).until(YearHalf.of(2014, H2), YEARS)); + } + + @Test + public void test_until_TemporalTemporalUnit_nullTemporal() { + assertThrows(NullPointerException.class, () -> YearHalf.of(2012, H2).until(null, HALF_YEARS)); + } + + @Test + public void test_until_TemporalTemporalUnit_nullTemporalUnit() { + assertThrows(NullPointerException.class, () -> YearHalf.of(2012, H2).until(YearHalf.of(2012, H1), null)); + } + + //----------------------------------------------------------------------- + // halvesUntil(YearHalf) + //----------------------------------------------------------------------- + @Test + public void test_halvesUntil_null() { + assertThrows(NullPointerException.class, () -> YearHalf.of(2012, H2).halvesUntil(null)); + } + + @Test + public void test_halvesUntil_IllegalArgument() { + assertThrows(IllegalArgumentException.class, () -> YearHalf.of(2012, H2).halvesUntil(YearHalf.of(2012, H1))); + } + + @Test + public void test_halvesUntil() { + assertEquals(1, YearHalf.of(2012, H1).halvesUntil(YearHalf.of(2012, H2)).count()); + assertEquals(4, YearHalf.of(2012, H2).halvesUntil(YearHalf.of(2014, H2)).count()); + + YearHalf start = YearHalf.of(2012, H1); + YearHalf end = YearHalf.of(2013, H2); + Stream stream = start.halvesUntil(end); + + List expects = Arrays.asList( + YearHalf.of(start.getYear(), H1), + YearHalf.of(start.getYear(), H2), + YearHalf.of(end.getYear(), H1)); + assertEquals(expects, stream.collect(Collectors.toList())); + } + + //----------------------------------------------------------------------- + // format(DateTimeFormatter) + //----------------------------------------------------------------------- + @Test + public void test_format() { + DateTimeFormatter f = new DateTimeFormatterBuilder() + .appendLiteral('H') + .appendValue(HALF_OF_YEAR, 1) + .appendLiteral(' ') + .appendValue(YEAR) + .toFormatter(); + assertEquals("H1 2012", YearHalf.of(2012, H1).format(f)); + } + + @Test + public void test_format_null() { + assertThrows(NullPointerException.class, () -> TEST.format((DateTimeFormatter) null)); + } + + //----------------------------------------------------------------------- + // atDay(int) + //----------------------------------------------------------------------- + @Test + public void test_atDay() { + for (int i = 1; i <= 182; i++) { + LocalDate expected = LocalDate.of(2012, 1, 1).plusDays(i - 1); + assertEquals(expected, YearHalf.of(2012, H1).atDay(i)); + } + for (int i = 1; i <= 184; i++) { + LocalDate expected = LocalDate.of(2012, 7, 1).plusDays(i - 1); + assertEquals(expected, YearHalf.of(2012, H2).atDay(i)); + } + } + + @Test + public void test_atDay_H1_181_leap() { + assertEquals(LocalDate.of(2012, 6, 30), YearHalf.of(2012, H1).atDay(182)); + } + + @Test + public void test_atDay_H1_182_notLeap() { + assertThrows(DateTimeException.class, () -> YearHalf.of(2011, H1).atDay(182)); + } + + @Test + public void test_atDay_H1_183() { + assertThrows(DateTimeException.class, () -> YearHalf.of(2012, H1).atDay(183)); + } + + @Test + public void test_atDay_tooLow() { + assertThrows(DateTimeException.class, () -> TEST.atDay(0)); + } + + @Test + public void test_atDay_tooHigh() { + assertThrows(DateTimeException.class, () -> TEST.atDay(185)); + } + + //----------------------------------------------------------------------- + // atEndOfHalf(int) + //----------------------------------------------------------------------- + @Test + public void test_atEndOfHalf() { + assertEquals(LocalDate.of(2011, 6, 30), YearHalf.of(2011, H1).atEndOfHalf()); + assertEquals(LocalDate.of(2011, 12, 31), YearHalf.of(2011, H2).atEndOfHalf()); + + assertEquals(LocalDate.of(2012, 6, 30), YearHalf.of(2012, H1).atEndOfHalf()); + assertEquals(LocalDate.of(2012, 12, 31), YearHalf.of(2012, H2).atEndOfHalf()); + } + + //----------------------------------------------------------------------- + // compareTo() + //----------------------------------------------------------------------- + @Test + public void test_compareTo() { + for (int year1 = -100; year1 < 100; year1++) { + for (Half half1 : Half.values()) { + YearHalf a = YearHalf.of(year1, half1); + for (int year2 = -100; year2 < 100; year2++) { + for (Half half2 : Half.values()) { + YearHalf b = YearHalf.of(year2, half2); + if (year1 < year2) { + assertEquals(true, a.compareTo(b) < 0); + assertEquals(true, b.compareTo(a) > 0); + assertEquals(false, a.isAfter(b)); + assertEquals(false, b.isBefore(a)); + assertEquals(true, b.isAfter(a)); + assertEquals(true, a.isBefore(b)); + } else if (year1 > year2) { + assertEquals(true, a.compareTo(b) > 0); + assertEquals(true, b.compareTo(a) < 0); + assertEquals(true, a.isAfter(b)); + assertEquals(true, b.isBefore(a)); + assertEquals(false, b.isAfter(a)); + assertEquals(false, a.isBefore(b)); + } else { + if (half1.getValue() < half2.getValue()) { + assertEquals(true, a.compareTo(b) < 0); + assertEquals(true, b.compareTo(a) > 0); + assertEquals(false, a.isAfter(b)); + assertEquals(false, b.isBefore(a)); + assertEquals(true, b.isAfter(a)); + assertEquals(true, a.isBefore(b)); + } else if (half1.getValue() > half2.getValue()) { + assertEquals(true, a.compareTo(b) > 0); + assertEquals(true, b.compareTo(a) < 0); + assertEquals(true, a.isAfter(b)); + assertEquals(true, b.isBefore(a)); + assertEquals(false, b.isAfter(a)); + assertEquals(false, a.isBefore(b)); + } else { + assertEquals(0, a.compareTo(b)); + assertEquals(0, b.compareTo(a)); + assertEquals(false, a.isAfter(b)); + assertEquals(false, b.isBefore(a)); + assertEquals(false, b.isAfter(a)); + assertEquals(false, a.isBefore(b)); + } + } + } + } + } + } + } + + @Test + public void test_compareTo_nullYearHalf() { + assertThrows(NullPointerException.class, () -> TEST.compareTo(null)); + } + + //----------------------------------------------------------------------- + // equals() / hashCode() + //----------------------------------------------------------------------- + @Test + public void test_equals() { + for (int year1 = -100; year1 < 100; year1++) { + for (Half half1 : Half.values()) { + YearHalf a = YearHalf.of(year1, half1); + for (int year2 = -100; year2 < 100; year2++) { + for (Half half2 : Half.values()) { + YearHalf b = YearHalf.of(year2, half2); + if (year1 == year2 && half1 == half2) { + assertEquals(a, b); + assertEquals(a.hashCode(), b.hashCode()); + } + } + } + } + } + } + + @Test + public void test_equals_nullYearHalf() { + assertEquals(false, TEST.equals(null)); + } + + @Test + public void test_equals_incorrectType() { + Object obj = "Incorrect type"; + assertEquals(false, TEST.equals(obj)); + } + + //----------------------------------------------------------------------- + // toString() + //----------------------------------------------------------------------- + @Test + public void test_toString() { + assertEquals("2012-H2", YearHalf.of(2012, H2).toString()); + } + + @Test + public void test_toString_bigYear() { + assertEquals("+10000-H2", YearHalf.of(10000, H2).toString()); + } + + @Test + public void test_toString_negativeYear() { + assertEquals("-0001-H2", YearHalf.of(-1, H2).toString()); + } + + @Test + public void test_toString_negativeBigYear() { + assertEquals("-10000-H2", YearHalf.of(-10000, H2).toString()); + } + +} From 111501c6ca854005dd1b7c160f84627d185f6696 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 12 Nov 2023 19:51:10 +0000 Subject: [PATCH 269/279] Bump org.junit:junit-bom from 5.9.1 to 5.10.1 (#305) Bumps [org.junit:junit-bom](https://github.com/junit-team/junit5) from 5.9.1 to 5.10.1. - [Release notes](https://github.com/junit-team/junit5/releases) - [Commits](https://github.com/junit-team/junit5/compare/r5.9.1...r5.10.1) --- updated-dependencies: - dependency-name: org.junit:junit-bom dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 775024e9..3ab3b769 100644 --- a/pom.xml +++ b/pom.xml @@ -917,7 +917,7 @@ 2.2.3 - 5.9.1 + 5.10.1 1.9.1 32.1.2-jre From 4525d7455d417697f69a75e536e3efc056298c80 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 2 Dec 2023 16:26:47 +0000 Subject: [PATCH 270/279] Bump com.google.guava:guava from 32.1.2-jre to 32.1.3-jre (#310) Bumps [com.google.guava:guava](https://github.com/google/guava) from 32.1.2-jre to 32.1.3-jre. - [Release notes](https://github.com/google/guava/releases) - [Commits](https://github.com/google/guava/commits) --- updated-dependencies: - dependency-name: com.google.guava:guava dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3ab3b769..89ec7400 100644 --- a/pom.xml +++ b/pom.xml @@ -919,7 +919,7 @@ 2.2.3 5.10.1 1.9.1 - 32.1.2-jre + 32.1.3-jre 3.4.2 5.1.8 From 1860c5e7b06af4f6adceb4ed897397d95f0dd533 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Wed, 6 Dec 2023 15:29:45 +0000 Subject: [PATCH 271/279] Fix half year method names (#315) Also adjust test methods See #200 --- .../java/org/threeten/extra/YearHalf.java | 20 ++++++------- .../java/org/threeten/extra/TestYearHalf.java | 29 ++++++++++--------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/threeten/extra/YearHalf.java b/src/main/java/org/threeten/extra/YearHalf.java index da889b95..49436413 100644 --- a/src/main/java/org/threeten/extra/YearHalf.java +++ b/src/main/java/org/threeten/extra/YearHalf.java @@ -93,7 +93,7 @@ * For most applications written today, the ISO-8601 rules are entirely suitable. * However, any application that makes use of historical dates, and requires them * to be accurate will find the ISO-8601 approach unsuitable. - * Note that the ISO-8601 standard does not define or refer to halfs. + * Note that the ISO-8601 standard does not define or refer to halves. * *

      Implementation Requirements:

      * This class is immutable and thread-safe. @@ -795,7 +795,7 @@ public YearHalf plus(TemporalAmount amountToAdd) { *
        *
      • {@code HALF_YEARS} - * Returns a {@code YearHalf} with the specified number of halves added. - * This is equivalent to {@link #plusHalfs(long)}. + * This is equivalent to {@link #plusHalves(long)}. *
      • {@code YEARS} - * Returns a {@code YearHalf} with the specified number of years added. * This is equivalent to {@link #plusYears(long)}. @@ -837,7 +837,7 @@ public YearHalf plus(TemporalAmount amountToAdd) { @Override public YearHalf plus(long amountToAdd, TemporalUnit unit) { if (unit == HALF_YEARS) { - return plusHalfs(amountToAdd); + return plusHalves(amountToAdd); } else if (unit instanceof ChronoUnit) { switch ((ChronoUnit) unit) { case YEARS: @@ -883,14 +883,14 @@ public YearHalf plusYears(long yearsToAdd) { * @return a {@code YearHalf} based on this year-half with the halves added, not null * @throws DateTimeException if the result exceeds the supported range */ - public YearHalf plusHalfs(long halvesToAdd) { + public YearHalf plusHalves(long halvesToAdd) { if (halvesToAdd == 0) { return this; } long halfCount = year * 2L + (half.getValue() - 1); - long calcHalfs = halfCount + halvesToAdd; // safe overflow - int newYear = YEAR.checkValidIntValue(Math.floorDiv(calcHalfs, 2)); - int newHalf = (int) Math.floorMod(calcHalfs, 2L) + 1; + long calcHalves = halfCount + halvesToAdd; // safe overflow + int newYear = YEAR.checkValidIntValue(Math.floorDiv(calcHalves, 2)); + int newHalf = (int) Math.floorMod(calcHalves, 2L) + 1; return with(newYear, Half.of(newHalf)); } @@ -966,8 +966,8 @@ public YearHalf minusYears(long yearsToSubtract) { * @return a {@code YearHalf} based on this year-half with the halves subtracted, not null * @throws DateTimeException if the result exceeds the supported range */ - public YearHalf minusHalfs(long halvesToSubtract) { - return (halvesToSubtract == Long.MIN_VALUE ? plusHalfs(Long.MAX_VALUE).plusHalfs(1) : plusHalfs(-halvesToSubtract)); + public YearHalf minusHalves(long halvesToSubtract) { + return (halvesToSubtract == Long.MIN_VALUE ? plusHalves(Long.MAX_VALUE).plusHalves(1) : plusHalves(-halvesToSubtract)); } //----------------------------------------------------------------------- @@ -1123,7 +1123,7 @@ public Stream halvesUntil(YearHalf endExclusive) { throw new IllegalArgumentException(endExclusive + " < " + this); } long intervalLength = until(endExclusive, HALF_YEARS); - return LongStream.range(0, intervalLength).mapToObj(n -> plusHalfs(n)); + return LongStream.range(0, intervalLength).mapToObj(n -> plusHalves(n)); } /** diff --git a/src/test/java/org/threeten/extra/TestYearHalf.java b/src/test/java/org/threeten/extra/TestYearHalf.java index c4d5953e..72fe2bb8 100644 --- a/src/test/java/org/threeten/extra/TestYearHalf.java +++ b/src/test/java/org/threeten/extra/TestYearHalf.java @@ -79,6 +79,7 @@ import static java.time.temporal.IsoFields.QUARTER_OF_YEAR; import static java.time.temporal.IsoFields.QUARTER_YEARS; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.threeten.extra.Half.H1; @@ -643,13 +644,13 @@ public void test_plusYears() { } //----------------------------------------------------------------------- - // plusHalfs(int) + // plusHalves(int) //----------------------------------------------------------------------- @Test - public void test_plusHalfs() { - assertEquals(YearHalf.of(2010, H1), YearHalf.of(2007, H2).plusHalfs(5)); - assertEquals(YearHalf.of(2007, H2), YearHalf.of(2007, H2).plusHalfs(0)); - assertEquals(YearHalf.of(2005, H1), YearHalf.of(2007, H2).plusHalfs(-5)); + public void test_plusHalves() { + assertEquals(YearHalf.of(2010, H1), YearHalf.of(2007, H2).plusHalves(5)); + assertEquals(YearHalf.of(2007, H2), YearHalf.of(2007, H2).plusHalves(0)); + assertEquals(YearHalf.of(2005, H1), YearHalf.of(2007, H2).plusHalves(-5)); } //----------------------------------------------------------------------- @@ -676,13 +677,13 @@ public void test_minusYears() { } //----------------------------------------------------------------------- - // minusHalfs(int) + // minusHalves(int) //----------------------------------------------------------------------- @Test - public void test_minusHalfs() { - assertEquals(YearHalf.of(2005, H1), YearHalf.of(2007, H2).minusHalfs(5)); - assertEquals(YearHalf.of(2007, H2), YearHalf.of(2007, H2).minusHalfs(0)); - assertEquals(YearHalf.of(2010, H1), YearHalf.of(2007, H2).minusHalfs(-5)); + public void test_minusHalves() { + assertEquals(YearHalf.of(2005, H1), YearHalf.of(2007, H2).minusHalves(5)); + assertEquals(YearHalf.of(2007, H2), YearHalf.of(2007, H2).minusHalves(0)); + assertEquals(YearHalf.of(2010, H1), YearHalf.of(2007, H2).minusHalves(-5)); } //----------------------------------------------------------------------- @@ -953,8 +954,10 @@ public void test_equals() { for (Half half2 : Half.values()) { YearHalf b = YearHalf.of(year2, half2); if (year1 == year2 && half1 == half2) { - assertEquals(a, b); + assertTrue(a.equals(b)); assertEquals(a.hashCode(), b.hashCode()); + } else { + assertFalse(a.equals(b)); } } } @@ -964,13 +967,13 @@ public void test_equals() { @Test public void test_equals_nullYearHalf() { - assertEquals(false, TEST.equals(null)); + assertFalse(TEST.equals(null)); } @Test public void test_equals_incorrectType() { Object obj = "Incorrect type"; - assertEquals(false, TEST.equals(obj)); + assertFalse(TEST.equals(obj)); } //----------------------------------------------------------------------- From f665c2f463f35f15b0e901d8dc1c4698af6e62f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Sobkiewicz?= Date: Wed, 6 Dec 2023 19:15:58 +0100 Subject: [PATCH 272/279] test_equals_and_hashCode (#316) --- pom.xml | 6 ++ .../org/threeten/extra/TestDayOfMonth.java | 27 ++------ .../org/threeten/extra/TestDayOfYear.java | 27 ++------ .../java/org/threeten/extra/TestDays.java | 35 ++-------- .../java/org/threeten/extra/TestHours.java | 34 ++------- .../java/org/threeten/extra/TestInterval.java | 20 +++--- .../threeten/extra/TestLocalDateRange.java | 19 ++--- .../java/org/threeten/extra/TestMinutes.java | 34 ++------- .../java/org/threeten/extra/TestMonths.java | 35 ++-------- .../org/threeten/extra/TestMutableClock.java | 13 ++-- .../org/threeten/extra/TestOffsetDate.java | 69 +++++-------------- .../threeten/extra/TestPeriodDuration.java | 34 ++------- .../java/org/threeten/extra/TestSeconds.java | 34 ++------- .../java/org/threeten/extra/TestWeeks.java | 35 ++-------- .../java/org/threeten/extra/TestYearHalf.java | 37 +++------- .../org/threeten/extra/TestYearQuarter.java | 33 +++------ .../java/org/threeten/extra/TestYearWeek.java | 39 +++-------- .../java/org/threeten/extra/TestYears.java | 35 ++-------- .../chrono/TestAccountingChronology.java | 58 +++++----------- .../chrono/TestBritishCutoverChronology.java | 30 +++----- .../extra/chrono/TestCopticChronology.java | 30 +++----- .../chrono/TestDiscordianChronology.java | 30 +++----- .../extra/chrono/TestEthiopicChronology.java | 30 +++----- .../TestInternationalFixedChronology.java | 39 +++++------ .../extra/chrono/TestJulianChronology.java | 30 +++----- .../extra/chrono/TestPaxChronology.java | 30 +++----- .../chrono/TestSymmetry010Chronology.java | 38 +++++----- .../chrono/TestSymmetry454Chronology.java | 38 +++++----- .../threeten/extra/scale/TestTaiInstant.java | 65 +++-------------- .../threeten/extra/scale/TestUtcInstant.java | 65 +++-------------- 30 files changed, 292 insertions(+), 757 deletions(-) diff --git a/pom.xml b/pom.xml index 89ec7400..036ba5c9 100644 --- a/pom.xml +++ b/pom.xml @@ -532,6 +532,12 @@ + + com.google.guava + guava-testlib + ${guava.version} + test + org.junit.jupiter junit-jupiter diff --git a/src/test/java/org/threeten/extra/TestDayOfMonth.java b/src/test/java/org/threeten/extra/TestDayOfMonth.java index 861d15aa..fa1f7e24 100644 --- a/src/test/java/org/threeten/extra/TestDayOfMonth.java +++ b/src/test/java/org/threeten/extra/TestDayOfMonth.java @@ -111,6 +111,8 @@ import org.junit.jupiter.api.Test; import org.junitpioneer.jupiter.RetryingTest; +import com.google.common.testing.EqualsTester; + /** * Test DayOfMonth. */ @@ -731,29 +733,12 @@ public void test_compareTo_nullDayOfMonth() { // equals() / hashCode() //----------------------------------------------------------------------- @Test - public void test_equals() { + public void test_equals_and_hashCode() { + EqualsTester equalsTester = new EqualsTester(); for (int i = 1; i <= MAX_LENGTH; i++) { - DayOfMonth a = DayOfMonth.of(i); - for (int j = 1; j <= MAX_LENGTH; j++) { - DayOfMonth b = DayOfMonth.of(j); - assertEquals(i == j, a.equals(b)); - assertEquals(i == j, a.hashCode() == b.hashCode()); - } + equalsTester.addEqualityGroup(DayOfMonth.of(i), DayOfMonth.of(i)); } - } - - @Test - public void test_equals_nullDayOfMonth() { - DayOfMonth dom = null; - DayOfMonth test = DayOfMonth.of(1); - assertEquals(false, test.equals(dom)); - } - - @Test - public void test_equals_incorrectType() { - DayOfMonth test = DayOfMonth.of(1); - Object obj = "Incorrect type"; - assertEquals(false, test.equals(obj)); + equalsTester.testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestDayOfYear.java b/src/test/java/org/threeten/extra/TestDayOfYear.java index 2aa8575b..24952ae0 100644 --- a/src/test/java/org/threeten/extra/TestDayOfYear.java +++ b/src/test/java/org/threeten/extra/TestDayOfYear.java @@ -96,6 +96,8 @@ import org.junit.jupiter.api.Test; import org.junitpioneer.jupiter.RetryingTest; +import com.google.common.testing.EqualsTester; + /** * Test DayOfYear. */ @@ -581,29 +583,12 @@ public void test_compareTo_nullDayOfYear() { // equals() / hashCode() //----------------------------------------------------------------------- @Test - public void test_equals() { + public void test_equals_and_hashCode() { + EqualsTester equalsTester = new EqualsTester(); for (int i = 1; i <= LEAP_YEAR_LENGTH; i++) { - DayOfYear a = DayOfYear.of(i); - for (int j = 1; j <= LEAP_YEAR_LENGTH; j++) { - DayOfYear b = DayOfYear.of(j); - assertEquals(i == j, a.equals(b)); - assertEquals(i == j, a.hashCode() == b.hashCode()); - } + equalsTester.addEqualityGroup(DayOfYear.of(i), DayOfYear.of(i)); } - } - - @Test - public void test_equals_nullDayOfYear() { - DayOfYear doy = null; - DayOfYear test = DayOfYear.of(1); - assertEquals(false, test.equals(doy)); - } - - @Test - public void test_equals_incorrectType() { - DayOfYear test = DayOfYear.of(1); - Object obj = "Incorrect type"; - assertEquals(false, test.equals(obj)); + equalsTester.testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestDays.java b/src/test/java/org/threeten/extra/TestDays.java index defeaaf8..a64416b8 100644 --- a/src/test/java/org/threeten/extra/TestDays.java +++ b/src/test/java/org/threeten/extra/TestDays.java @@ -56,6 +56,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test class. */ @@ -538,34 +540,11 @@ public void test_compareTo_null() { //----------------------------------------------------------------------- @Test - public void test_equals() { - Days test5 = Days.of(5); - Days test6 = Days.of(6); - assertEquals(true, test5.equals(test5)); - assertEquals(false, test5.equals(test6)); - assertEquals(false, test6.equals(test5)); - } - - @Test - public void test_equals_null() { - Days test5 = Days.of(5); - assertEquals(false, test5.equals(null)); - } - - @Test - public void test_equals_otherClass() { - Days test5 = Days.of(5); - Object obj = ""; - assertEquals(false, test5.equals(obj)); - } - - //----------------------------------------------------------------------- - @Test - public void test_hashCode() { - Days test5 = Days.of(5); - Days test6 = Days.of(6); - assertEquals(true, test5.hashCode() == test5.hashCode()); - assertEquals(false, test5.hashCode() == test6.hashCode()); + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(Days.of(5), Days.of(5)) + .addEqualityGroup(Days.of(6), Days.of(6)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestHours.java b/src/test/java/org/threeten/extra/TestHours.java index 008b3231..05c3ab8b 100644 --- a/src/test/java/org/threeten/extra/TestHours.java +++ b/src/test/java/org/threeten/extra/TestHours.java @@ -50,6 +50,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test class. */ @@ -425,33 +427,11 @@ public void test_compareTo_null() { //----------------------------------------------------------------------- @Test - public void test_equals() { - Hours test5 = Hours.of(5); - Hours test6 = Hours.of(6); - assertEquals(true, test5.equals(test5)); - assertEquals(false, test5.equals(test6)); - assertEquals(false, test6.equals(test5)); - } - - @Test - public void test_equals_null() { - Hours test5 = Hours.of(5); - assertEquals(false, test5.equals(null)); - } - - @Test - public void test_equals_otherClass() { - Hours test5 = Hours.of(5); - assertEquals(false, test5.equals((Object) "")); - } - - //----------------------------------------------------------------------- - @Test - public void test_hashCode() { - Hours test5 = Hours.of(5); - Hours test6 = Hours.of(6); - assertEquals(true, test5.hashCode() == test5.hashCode()); - assertEquals(false, test5.hashCode() == test6.hashCode()); + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(Hours.of(5), Hours.of(5)) + .addEqualityGroup(Hours.of(6), Hours.of(6)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestInterval.java b/src/test/java/org/threeten/extra/TestInterval.java index 7eaaba60..49685714 100644 --- a/src/test/java/org/threeten/extra/TestInterval.java +++ b/src/test/java/org/threeten/extra/TestInterval.java @@ -55,6 +55,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test class. */ @@ -916,18 +918,12 @@ public void test_toDuration() { //----------------------------------------------------------------------- @Test - public void test_equals() { - Interval a = Interval.of(NOW1, NOW2); - Interval a2 = Interval.of(NOW1, NOW2); - Interval b = Interval.of(NOW1, NOW3); - Interval c = Interval.of(NOW2, NOW2); - assertEquals(true, a.equals(a)); - assertEquals(true, a.equals(a2)); - assertEquals(false, a.equals(b)); - assertEquals(false, a.equals(c)); - assertEquals(false, a.equals(null)); - assertEquals(false, a.equals((Object) "")); - assertEquals(true, a.hashCode() == a2.hashCode()); + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(Interval.of(NOW1, NOW2), Interval.of(NOW1, NOW2)) + .addEqualityGroup(Interval.of(NOW1, NOW3), Interval.of(NOW1, NOW3)) + .addEqualityGroup(Interval.of(NOW2, NOW2), Interval.of(NOW2, NOW2)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestLocalDateRange.java b/src/test/java/org/threeten/extra/TestLocalDateRange.java index 9f81fc1e..865f3faf 100644 --- a/src/test/java/org/threeten/extra/TestLocalDateRange.java +++ b/src/test/java/org/threeten/extra/TestLocalDateRange.java @@ -57,6 +57,7 @@ import org.junit.jupiter.params.provider.MethodSource; import com.google.common.collect.Range; +import com.google.common.testing.EqualsTester; /** * Test date range. @@ -1190,18 +1191,12 @@ public void test_toPeriod_unbounded_MAX() { //----------------------------------------------------------------------- @Test - public void test_equals() { - LocalDateRange a = LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_29); - LocalDateRange a2 = LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_29); - LocalDateRange b = LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_30); - LocalDateRange c = LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_29); - assertEquals(true, a.equals(a)); - assertEquals(true, a.equals(a2)); - assertEquals(false, a.equals(b)); - assertEquals(false, a.equals(c)); - assertEquals(false, a.equals(null)); - assertEquals(false, a.equals((Object) "")); - assertEquals(true, a.hashCode() == a2.hashCode()); + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_29), LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_29)) + .addEqualityGroup(LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_30), LocalDateRange.of(DATE_2012_07_27, DATE_2012_07_30)) + .addEqualityGroup(LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_29), LocalDateRange.of(DATE_2012_07_28, DATE_2012_07_29)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestMinutes.java b/src/test/java/org/threeten/extra/TestMinutes.java index e88e1717..2bc1c327 100644 --- a/src/test/java/org/threeten/extra/TestMinutes.java +++ b/src/test/java/org/threeten/extra/TestMinutes.java @@ -50,6 +50,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test class. */ @@ -439,33 +441,11 @@ public void test_compareTo_null() { //----------------------------------------------------------------------- @Test - public void test_equals() { - Minutes test5 = Minutes.of(5); - Minutes test6 = Minutes.of(6); - assertEquals(true, test5.equals(test5)); - assertEquals(false, test5.equals(test6)); - assertEquals(false, test6.equals(test5)); - } - - @Test - public void test_equals_null() { - Minutes test5 = Minutes.of(5); - assertEquals(false, test5.equals(null)); - } - - @Test - public void test_equals_otherClass() { - Minutes test5 = Minutes.of(5); - assertEquals(false, test5.equals((Object) "")); - } - - //----------------------------------------------------------------------- - @Test - public void test_hashCode() { - Minutes test5 = Minutes.of(5); - Minutes test6 = Minutes.of(6); - assertEquals(true, test5.hashCode() == test5.hashCode()); - assertEquals(false, test5.hashCode() == test6.hashCode()); + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(Minutes.of(5), Minutes.of(5)) + .addEqualityGroup(Minutes.of(6), Minutes.of(6)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestMonths.java b/src/test/java/org/threeten/extra/TestMonths.java index 5b39c30a..a43c6f0a 100644 --- a/src/test/java/org/threeten/extra/TestMonths.java +++ b/src/test/java/org/threeten/extra/TestMonths.java @@ -56,6 +56,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test class. */ @@ -531,34 +533,11 @@ public void test_compareTo_null() { //----------------------------------------------------------------------- @Test - public void test_equals() { - Months test5 = Months.of(5); - Months test6 = Months.of(6); - assertEquals(true, test5.equals(test5)); - assertEquals(false, test5.equals(test6)); - assertEquals(false, test6.equals(test5)); - } - - @Test - public void test_equals_null() { - Months test5 = Months.of(5); - assertEquals(false, test5.equals(null)); - } - - @Test - public void test_equals_otherClass() { - Months test5 = Months.of(5); - Object obj = ""; - assertEquals(false, test5.equals(obj)); - } - - //----------------------------------------------------------------------- - @Test - public void test_hashCode() { - Months test5 = Months.of(5); - Months test6 = Months.of(6); - assertEquals(true, test5.hashCode() == test5.hashCode()); - assertEquals(false, test5.hashCode() == test6.hashCode()); + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(Months.of(5), Months.of(5)) + .addEqualityGroup(Months.of(6), Months.of(6)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestMutableClock.java b/src/test/java/org/threeten/extra/TestMutableClock.java index ed20ca92..f4b01e95 100644 --- a/src/test/java/org/threeten/extra/TestMutableClock.java +++ b/src/test/java/org/threeten/extra/TestMutableClock.java @@ -63,6 +63,8 @@ import org.junit.jupiter.api.Test; +import com.google.common.testing.EqualsTester; + /** * Test class. */ @@ -262,12 +264,11 @@ public void test_equals() { MutableClock withOtherZone = clock.withZone(ZoneOffset.MIN); MutableClock withSameZone = withOtherZone.withZone(ZoneOffset.UTC); MutableClock independent = MutableClock.epochUTC(); - assertEquals(clock, clock); - assertNotEquals(null, clock); - assertNotEquals("", clock); - assertNotEquals(withOtherZone, clock); - assertEquals(clock, withSameZone); - assertNotEquals(clock, independent); + new EqualsTester() + .addEqualityGroup(clock, clock, withSameZone) + .addEqualityGroup(withOtherZone) + .addEqualityGroup(independent) + .testEquals(); } @Test diff --git a/src/test/java/org/threeten/extra/TestOffsetDate.java b/src/test/java/org/threeten/extra/TestOffsetDate.java index c0c46ee6..7095e3f5 100644 --- a/src/test/java/org/threeten/extra/TestOffsetDate.java +++ b/src/test/java/org/threeten/extra/TestOffsetDate.java @@ -91,6 +91,8 @@ import org.junit.jupiter.params.provider.MethodSource; import org.junitpioneer.jupiter.RetryingTest; +import com.google.common.testing.EqualsTester; + /** * Test OffsetDate. */ @@ -403,11 +405,14 @@ public void constructor_nullOffset() throws Throwable { //----------------------------------------------------------------------- public static Object[][] data_sampleDates() { return new Object[][] { + {2008, 7, 5, OFFSET_PONE}, {2008, 7, 5, OFFSET_PTWO}, {2007, 7, 5, OFFSET_PONE}, - {2006, 7, 5, OFFSET_PTWO}, - {2005, 7, 5, OFFSET_PONE}, - {2004, 1, 1, OFFSET_PTWO}, + {2007, 7, 5, OFFSET_PTWO}, + {2007, 6, 5, OFFSET_PONE}, + {2007, 6, 5, OFFSET_PTWO}, + {2007, 6, 4, OFFSET_PONE}, + {2007, 6, 4, OFFSET_PTWO}, {-1, 1, 2, OFFSET_PONE}, {999999, 11, 20, ZoneOffset.ofHoursMinutesSeconds(6, 9, 12)}, }; @@ -1814,55 +1819,17 @@ public void test_isEqual_null() { //----------------------------------------------------------------------- // equals() / hashCode() //----------------------------------------------------------------------- - @ParameterizedTest - @MethodSource("data_sampleDates") - public void test_equals_true(int y, int m, int d, ZoneOffset offset) { - OffsetDate a = OffsetDate.of(y, m, d, offset); - OffsetDate b = OffsetDate.of(y, m, d, offset); - assertTrue(a.equals(b)); - assertTrue(a.hashCode() == b.hashCode()); - } - - @ParameterizedTest - @MethodSource("data_sampleDates") - public void test_equals_false_year_differs(int y, int m, int d, ZoneOffset offset) { - OffsetDate a = OffsetDate.of(y, m, d, offset); - OffsetDate b = OffsetDate.of(y + 1, m, d, offset); - assertFalse(a.equals(b)); - } - - @ParameterizedTest - @MethodSource("data_sampleDates") - public void test_equals_false_month_differs(int y, int m, int d, ZoneOffset offset) { - OffsetDate a = OffsetDate.of(y, m, d, offset); - OffsetDate b = OffsetDate.of(y, m + 1, d, offset); - assertFalse(a.equals(b)); - } - - @ParameterizedTest - @MethodSource("data_sampleDates") - public void test_equals_false_day_differs(int y, int m, int d, ZoneOffset offset) { - OffsetDate a = OffsetDate.of(y, m, d, offset); - OffsetDate b = OffsetDate.of(y, m, d + 1, offset); - assertFalse(a.equals(b)); - } - - @ParameterizedTest - @MethodSource("data_sampleDates") - public void test_equals_false_offset_differs(int y, int m, int d, ZoneOffset ignored) { - OffsetDate a = OffsetDate.of(y, m, d, OFFSET_PONE); - OffsetDate b = OffsetDate.of(y, m, d, OFFSET_PTWO); - assertFalse(a.equals(b)); - } - - @Test - public void test_equals_itself_true() { - assertTrue(TEST_2007_07_15_PONE.equals(TEST_2007_07_15_PONE)); - } - @Test - public void test_equals_string_false() { - assertFalse(TEST_2007_07_15_PONE.equals((Object) "2007-07-15")); + public void test_equals_and_hashCode() { + EqualsTester equalsTester = new EqualsTester(); + for (Object[] sample : data_sampleDates()) { + int y = (int) sample[0]; + int m = (int) sample[1]; + int d = (int) sample[2]; + ZoneOffset offset = (ZoneOffset) sample[3]; + equalsTester.addEqualityGroup(OffsetDate.of(y, m, d, offset), OffsetDate.of(y, m, d, offset)); + } + equalsTester.testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestPeriodDuration.java b/src/test/java/org/threeten/extra/TestPeriodDuration.java index 55514a61..d1d04aa5 100644 --- a/src/test/java/org/threeten/extra/TestPeriodDuration.java +++ b/src/test/java/org/threeten/extra/TestPeriodDuration.java @@ -59,6 +59,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test class. */ @@ -380,33 +382,11 @@ public void test_subtractFrom() { //----------------------------------------------------------------------- @Test - public void test_equals() { - PeriodDuration test5 = PeriodDuration.of(P1Y2M3D, DUR_5); - PeriodDuration test6 = PeriodDuration.of(P1Y2M3D, DUR_6); - assertEquals(true, test5.equals(test5)); - assertEquals(false, test5.equals(test6)); - assertEquals(false, test6.equals(test5)); - } - - @Test - public void test_equals_null() { - PeriodDuration test = PeriodDuration.of(P1Y2M3D, DUR_5); - assertEquals(false, test.equals(null)); - } - - @Test - public void test_equals_otherClass() { - PeriodDuration test = PeriodDuration.of(P1Y2M3D, DUR_5); - assertEquals(false, test.equals((Object) "")); - } - - //----------------------------------------------------------------------- - @Test - public void test_hashCode() { - PeriodDuration test5 = PeriodDuration.of(P1Y2M3D, DUR_5); - PeriodDuration test6 = PeriodDuration.of(P1Y2M3D, DUR_6); - assertEquals(true, test5.hashCode() == test5.hashCode()); - assertEquals(false, test5.hashCode() == test6.hashCode()); + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(PeriodDuration.of(P1Y2M3D, DUR_5), PeriodDuration.of(P1Y2M3D, DUR_5)) + .addEqualityGroup(PeriodDuration.of(P1Y2M3D, DUR_6), PeriodDuration.of(P1Y2M3D, DUR_6)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestSeconds.java b/src/test/java/org/threeten/extra/TestSeconds.java index 7cd71851..cec47027 100644 --- a/src/test/java/org/threeten/extra/TestSeconds.java +++ b/src/test/java/org/threeten/extra/TestSeconds.java @@ -50,6 +50,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test class. */ @@ -471,33 +473,11 @@ public void test_compareTo_null() { //----------------------------------------------------------------------- @Test - public void test_equals() { - Seconds test5 = Seconds.of(5); - Seconds test6 = Seconds.of(6); - assertEquals(true, test5.equals(test5)); - assertEquals(false, test5.equals(test6)); - assertEquals(false, test6.equals(test5)); - } - - @Test - public void test_equals_null() { - Seconds test5 = Seconds.of(5); - assertEquals(false, test5.equals(null)); - } - - @Test - public void test_equals_otherClass() { - Seconds test5 = Seconds.of(5); - assertEquals(false, test5.equals((Object) "")); - } - - //----------------------------------------------------------------------- - @Test - public void test_hashCode() { - Seconds test5 = Seconds.of(5); - Seconds test6 = Seconds.of(6); - assertEquals(true, test5.hashCode() == test5.hashCode()); - assertEquals(false, test5.hashCode() == test6.hashCode()); + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(Seconds.of(5), Seconds.of(5)) + .addEqualityGroup(Seconds.of(6), Seconds.of(6)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestWeeks.java b/src/test/java/org/threeten/extra/TestWeeks.java index efb459a6..668d33c4 100644 --- a/src/test/java/org/threeten/extra/TestWeeks.java +++ b/src/test/java/org/threeten/extra/TestWeeks.java @@ -56,6 +56,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test class. */ @@ -475,34 +477,11 @@ public void test_compareTo_null() { //----------------------------------------------------------------------- @Test - public void test_equals() { - Weeks test5 = Weeks.of(5); - Weeks test6 = Weeks.of(6); - assertEquals(true, test5.equals(test5)); - assertEquals(false, test5.equals(test6)); - assertEquals(false, test6.equals(test5)); - } - - @Test - public void test_equals_null() { - Weeks test5 = Weeks.of(5); - assertEquals(false, test5.equals(null)); - } - - @Test - public void test_equals_otherClass() { - Weeks test5 = Weeks.of(5); - Object obj = ""; - assertEquals(false, test5.equals(obj)); - } - - //----------------------------------------------------------------------- - @Test - public void test_hashCode() { - Weeks test5 = Weeks.of(5); - Weeks test6 = Weeks.of(6); - assertEquals(true, test5.hashCode() == test5.hashCode()); - assertEquals(false, test5.hashCode() == test6.hashCode()); + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(Weeks.of(5), Weeks.of(5)) + .addEqualityGroup(Weeks.of(6), Weeks.of(6)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestYearHalf.java b/src/test/java/org/threeten/extra/TestYearHalf.java index 72fe2bb8..dc99eb89 100644 --- a/src/test/java/org/threeten/extra/TestYearHalf.java +++ b/src/test/java/org/threeten/extra/TestYearHalf.java @@ -79,7 +79,6 @@ import static java.time.temporal.IsoFields.QUARTER_OF_YEAR; import static java.time.temporal.IsoFields.QUARTER_YEARS; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.threeten.extra.Half.H1; @@ -117,6 +116,8 @@ import org.junit.jupiter.api.Test; +import com.google.common.testing.EqualsTester; + /** * Test YearHalf. */ @@ -946,34 +947,16 @@ public void test_compareTo_nullYearHalf() { // equals() / hashCode() //----------------------------------------------------------------------- @Test - public void test_equals() { - for (int year1 = -100; year1 < 100; year1++) { - for (Half half1 : Half.values()) { - YearHalf a = YearHalf.of(year1, half1); - for (int year2 = -100; year2 < 100; year2++) { - for (Half half2 : Half.values()) { - YearHalf b = YearHalf.of(year2, half2); - if (year1 == year2 && half1 == half2) { - assertTrue(a.equals(b)); - assertEquals(a.hashCode(), b.hashCode()); - } else { - assertFalse(a.equals(b)); - } - } - } + public void test_equals_and_hashCode() { + EqualsTester tester = new EqualsTester(); + for (int year = -100; year <= 100; year++) { + for (Half half : Half.values()) { + YearHalf instance1 = YearHalf.of(year, half); + YearHalf instance2 = YearHalf.of(year, half); + tester.addEqualityGroup(instance1, instance2); } } - } - - @Test - public void test_equals_nullYearHalf() { - assertFalse(TEST.equals(null)); - } - - @Test - public void test_equals_incorrectType() { - Object obj = "Incorrect type"; - assertFalse(TEST.equals(obj)); + tester.testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestYearQuarter.java b/src/test/java/org/threeten/extra/TestYearQuarter.java index 90e777b2..c1e13544 100644 --- a/src/test/java/org/threeten/extra/TestYearQuarter.java +++ b/src/test/java/org/threeten/extra/TestYearQuarter.java @@ -114,6 +114,8 @@ import org.junit.jupiter.api.Test; +import com.google.common.testing.EqualsTester; + /** * Test YearQuarter. */ @@ -972,31 +974,16 @@ public void test_compareTo_nullYearQuarter() { // equals() / hashCode() //----------------------------------------------------------------------- @Test - public void test_equals() { - for (int year1 = -100; year1 < 100; year1++) { - for (Quarter quarter1 : Quarter.values()) { - YearQuarter a = YearQuarter.of(year1, quarter1); - for (int year2 = -100; year2 < 100; year2++) { - for (Quarter quarter2 : Quarter.values()) { - YearQuarter b = YearQuarter.of(year2, quarter2); - if (year1 == year2 && quarter1 == quarter2) { - assertEquals(a, b); - assertEquals(a.hashCode(), b.hashCode()); - } - } - } + public void test_equals_and_hashCode() { + EqualsTester tester = new EqualsTester(); + for (int year = -100; year <= 100; year++) { + for (Quarter quarter : Quarter.values()) { + YearQuarter instance1 = YearQuarter.of(year, quarter); + YearQuarter instance2 = YearQuarter.of(year, quarter); + tester.addEqualityGroup(instance1, instance2); } } - } - - @Test - public void test_equals_nullYearQuarter() { - assertEquals(false, TEST.equals(null)); - } - - @Test - public void test_equals_incorrectType() { - assertEquals(false, TEST.equals((Object) "Incorrect type")); + tester.testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestYearWeek.java b/src/test/java/org/threeten/extra/TestYearWeek.java index 7236c621..77a21d39 100644 --- a/src/test/java/org/threeten/extra/TestYearWeek.java +++ b/src/test/java/org/threeten/extra/TestYearWeek.java @@ -86,7 +86,6 @@ import static java.time.temporal.IsoFields.WEEK_BASED_YEARS; import static java.time.temporal.IsoFields.WEEK_OF_WEEK_BASED_YEAR; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -129,6 +128,8 @@ import org.junit.jupiter.params.provider.MethodSource; import org.junitpioneer.jupiter.RetryingTest; +import com.google.common.testing.EqualsTester; + public class TestYearWeek { private static final YearWeek TEST_NON_LEAP = YearWeek.of(2014, 1); @@ -1066,37 +1067,13 @@ public void test_query() { //----------------------------------------------------------------------- // equals() / hashCode() //----------------------------------------------------------------------- - @ParameterizedTest - @MethodSource("data_sampleYearWeeks") - public void test_equalsAndHashCodeContract(int year, int week) { - YearWeek a = YearWeek.of(year, week); - YearWeek b = YearWeek.of(year, week); - assertTrue(a.equals(b)); - assertTrue(b.equals(a)); - assertTrue(a.hashCode() == b.hashCode()); - } - - @Test - public void test_equals() { - YearWeek a = YearWeek.of(2015, 4); - YearWeek b = YearWeek.of(2015, 6); - YearWeek c = YearWeek.of(2016, 6); - assertFalse(a.equals(b)); - assertFalse(a.equals(c)); - assertFalse(b.equals(a)); - assertFalse(b.equals(c)); - assertFalse(c.equals(a)); - assertFalse(c.equals(b)); - } - - @Test - public void test_equals_null() { - assertEquals(false, TEST.equals(null)); - } - @Test - public void test_equals_incorrectType() { - assertEquals(false, TEST.equals((Object) "Incorrect type")); + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(YearWeek.of(2015, 4), YearWeek.of(2015, 4)) + .addEqualityGroup(YearWeek.of(2015, 6), YearWeek.of(2015, 6)) + .addEqualityGroup(YearWeek.of(2016, 6), YearWeek.of(2016, 6)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/TestYears.java b/src/test/java/org/threeten/extra/TestYears.java index 1138ba61..5a324447 100644 --- a/src/test/java/org/threeten/extra/TestYears.java +++ b/src/test/java/org/threeten/extra/TestYears.java @@ -56,6 +56,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test class. */ @@ -480,34 +482,11 @@ public void test_compareTo_null() { //----------------------------------------------------------------------- @Test - public void test_equals() { - Years test5 = Years.of(5); - Years test6 = Years.of(6); - assertEquals(true, test5.equals(test5)); - assertEquals(false, test5.equals(test6)); - assertEquals(false, test6.equals(test5)); - } - - @Test - public void test_equals_null() { - Years test5 = Years.of(5); - assertEquals(false, test5.equals(null)); - } - - @Test - public void test_equals_otherClass() { - Years test5 = Years.of(5); - Object obj = ""; - assertEquals(false, test5.equals(obj)); - } - - //----------------------------------------------------------------------- - @Test - public void test_hashCode() { - Years test5 = Years.of(5); - Years test6 = Years.of(6); - assertEquals(true, test5.hashCode() == test5.hashCode()); - assertEquals(false, test5.hashCode() == test6.hashCode()); + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(Years.of(0), Years.of(0)) + .addEqualityGroup(Years.of(1), Years.of(1)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java b/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java index 0ccec2ef..6fb07d47 100644 --- a/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestAccountingChronology.java @@ -54,9 +54,7 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.DateTimeException; import java.time.DayOfWeek; @@ -79,6 +77,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test. */ @@ -742,46 +742,24 @@ public void test_minus_Period_ISO() { } //----------------------------------------------------------------------- - // equals() + // equals() / hashCode() //----------------------------------------------------------------------- @Test - public void test_equals() { - AccountingDate a1 = INSTANCE.date(2000, 1, 3); - AccountingDate a2 = INSTANCE.date(2000, 1, 3); - AccountingDate b = INSTANCE.date(2000, 1, 4); - AccountingDate c = INSTANCE.date(2000, 2, 3); - AccountingDate d = INSTANCE.date(2001, 1, 3); - - AccountingDate other = new AccountingChronologyBuilder().endsOn(DayOfWeek.WEDNESDAY) - .nearestEndOf(Month.AUGUST).leapWeekInMonth(13) - .withDivision(AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS) - .accountingYearEndsInIsoYear() - .toChronology().date(2000, 1, 3); - - assertEquals(true, a1.equals(a1)); - assertEquals(true, a1.equals(a2)); - assertEquals(false, a1.equals(b)); - assertEquals(false, a1.equals(c)); - assertEquals(false, a1.equals(d)); - - assertFalse(a1.equals(null)); - assertFalse(a1.equals((Object) "")); - assertEquals(false, a1.getChronology().equals(other.getChronology())); - assertEquals(false, a1.equals(other)); - - assertTrue(a1.hashCode() == a1.hashCode()); - - AccountingDate startChronologyDate = new AccountingChronologyBuilder().endsOn(DayOfWeek.WEDNESDAY) - .nearestEndOf(Month.AUGUST).leapWeekInMonth(13) - .withDivision(AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS) - .accountingYearStartsInIsoYear() - .toChronology().date(2000, 1, 3); - - - assertEquals(false, a1.getChronology().equals(startChronologyDate.getChronology())); - assertEquals(false, a1.equals(startChronologyDate)); - assertEquals(false, other.getChronology().equals(startChronologyDate.getChronology())); - assertEquals(false, other.equals(startChronologyDate)); + public void test_equals_and_hashCode() { + AccountingChronology other = new AccountingChronologyBuilder() + .endsOn(DayOfWeek.WEDNESDAY) + .nearestEndOf(Month.AUGUST) + .leapWeekInMonth(13) + .withDivision(AccountingYearDivision.THIRTEEN_EVEN_MONTHS_OF_4_WEEKS) + .accountingYearEndsInIsoYear() + .toChronology(); + new EqualsTester() + .addEqualityGroup(INSTANCE.date(2000, 1, 3), INSTANCE.date(2000, 1, 3)) + .addEqualityGroup(INSTANCE.date(2000, 1, 4), INSTANCE.date(2000, 1, 4)) + .addEqualityGroup(INSTANCE.date(2000, 2, 3), INSTANCE.date(2000, 2, 3)) + .addEqualityGroup(INSTANCE.date(2001, 1, 3), INSTANCE.date(2001, 1, 3)) + .addEqualityGroup(other.date(2000, 1, 3), other.date(2000, 1, 3)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java b/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java index 36bf1a58..dd6fe3b4 100644 --- a/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestBritishCutoverChronology.java @@ -54,10 +54,8 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.DateTimeException; import java.time.Instant; @@ -89,6 +87,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test. */ @@ -1273,26 +1273,16 @@ public void test_crossCheck() { } //----------------------------------------------------------------------- - // equals() + // equals() / hashCode() //----------------------------------------------------------------------- @Test - public void test_equals() { - BritishCutoverDate a1 = BritishCutoverDate.of(2000, 1, 3); - BritishCutoverDate a2 = BritishCutoverDate.of(2000, 1, 3); - BritishCutoverDate b = BritishCutoverDate.of(2000, 1, 4); - BritishCutoverDate c = BritishCutoverDate.of(2000, 2, 3); - BritishCutoverDate d = BritishCutoverDate.of(2001, 1, 3); - - assertEquals(true, a1.equals(a1)); - assertEquals(true, a1.equals(a2)); - assertEquals(false, a1.equals(b)); - assertEquals(false, a1.equals(c)); - assertEquals(false, a1.equals(d)); - - assertFalse(a1.equals(null)); - assertFalse(a1.equals((Object) "")); - - assertTrue(a1.hashCode() == a2.hashCode()); + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(BritishCutoverDate.of(2000, 1, 3), BritishCutoverDate.of(2000, 1, 3)) + .addEqualityGroup(BritishCutoverDate.of(2000, 1, 4), BritishCutoverDate.of(2000, 1, 4)) + .addEqualityGroup(BritishCutoverDate.of(2000, 2, 3), BritishCutoverDate.of(2000, 2, 3)) + .addEqualityGroup(BritishCutoverDate.of(2001, 1, 3), BritishCutoverDate.of(2001, 1, 3)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java b/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java index 61c02cf2..edaa6507 100644 --- a/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestCopticChronology.java @@ -54,10 +54,8 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; @@ -78,6 +76,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test. */ @@ -680,26 +680,16 @@ public void test_until_TemporalUnit_unsupported() { } //----------------------------------------------------------------------- - // equals() + // equals() / hashCode() //----------------------------------------------------------------------- @Test - public void test_equals() { - CopticDate a1 = CopticDate.of(1728, 1, 3); - CopticDate a2 = CopticDate.of(1728, 1, 3); - CopticDate b = CopticDate.of(1728, 1, 4); - CopticDate c = CopticDate.of(1728, 2, 3); - CopticDate d = CopticDate.of(1729, 1, 3); - - assertEquals(true, a1.equals(a1)); - assertEquals(true, a1.equals(a2)); - assertEquals(false, a1.equals(b)); - assertEquals(false, a1.equals(c)); - assertEquals(false, a1.equals(d)); - - assertFalse(a1.equals(null)); - assertFalse(a1.equals((Object) "")); - - assertTrue(a1.hashCode() == a2.hashCode()); + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(CopticDate.of(1728, 1, 3), CopticDate.of(1728, 1, 3)) + .addEqualityGroup(CopticDate.of(1728, 1, 4), CopticDate.of(1728, 1, 4)) + .addEqualityGroup(CopticDate.of(1728, 2, 3), CopticDate.of(1728, 2, 3)) + .addEqualityGroup(CopticDate.of(1729, 1, 3), CopticDate.of(1729, 1, 3)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java b/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java index 69b65be6..ab5763ea 100644 --- a/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestDiscordianChronology.java @@ -55,10 +55,8 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; @@ -81,6 +79,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test. */ @@ -957,26 +957,16 @@ public void test_minus_Period_ISO() { } //----------------------------------------------------------------------- - // equals() + // equals() / hashCode() //----------------------------------------------------------------------- @Test - public void test_equals() { - DiscordianDate a1 = DiscordianDate.of(2000, 1, 3); - DiscordianDate a2 = DiscordianDate.of(2000, 1, 3); - DiscordianDate b = DiscordianDate.of(2000, 1, 4); - DiscordianDate c = DiscordianDate.of(2000, 2, 3); - DiscordianDate d = DiscordianDate.of(2001, 1, 3); - - assertEquals(true, a1.equals(a1)); - assertEquals(true, a1.equals(a2)); - assertEquals(false, a1.equals(b)); - assertEquals(false, a1.equals(c)); - assertEquals(false, a1.equals(d)); - - assertFalse(a1.equals(null)); - assertFalse(a1.equals((Object) "")); - - assertTrue(a1.hashCode() == a2.hashCode()); + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(DiscordianDate.of(2000, 1, 3), DiscordianDate.of(2000, 1, 3)) + .addEqualityGroup(DiscordianDate.of(2000, 1, 4), DiscordianDate.of(2000, 1, 4)) + .addEqualityGroup(DiscordianDate.of(2000, 2, 3), DiscordianDate.of(2000, 2, 3)) + .addEqualityGroup(DiscordianDate.of(2001, 1, 3), DiscordianDate.of(2001, 1, 3)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java b/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java index 33f48b48..6be2f05a 100644 --- a/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestEthiopicChronology.java @@ -54,10 +54,8 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; @@ -78,6 +76,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test. */ @@ -704,26 +704,16 @@ public void test_until_TemporalUnit_unsupported() { } //----------------------------------------------------------------------- - // equals() + // equals() / hashCode() //----------------------------------------------------------------------- @Test - public void test_equals() { - EthiopicDate a1 = EthiopicDate.of(2004, 1, 3); - EthiopicDate a2 = EthiopicDate.of(2004, 1, 3); - EthiopicDate b = EthiopicDate.of(2004, 1, 4); - EthiopicDate c = EthiopicDate.of(2004, 2, 3); - EthiopicDate d = EthiopicDate.of(2005, 1, 3); - - assertEquals(true, a1.equals(a1)); - assertEquals(true, a1.equals(a2)); - assertEquals(false, a1.equals(b)); - assertEquals(false, a1.equals(c)); - assertEquals(false, a1.equals(d)); - - assertFalse(a1.equals(null)); - assertFalse(a1.equals((Object) "")); - - assertTrue(a1.hashCode() == a2.hashCode()); + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(EthiopicDate.of(2004, 1, 3), EthiopicDate.of(2004, 1, 3)) + .addEqualityGroup(EthiopicDate.of(2004, 1, 4), EthiopicDate.of(2004, 1, 4)) + .addEqualityGroup(EthiopicDate.of(2004, 2, 3), EthiopicDate.of(2004, 2, 3)) + .addEqualityGroup(EthiopicDate.of(2005, 1, 3), EthiopicDate.of(2005, 1, 3)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java b/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java index 810abfc5..92d8f33b 100644 --- a/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestInternationalFixedChronology.java @@ -81,6 +81,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test. */ @@ -1332,30 +1334,21 @@ public void test_minus_Period_ISO() { } //----------------------------------------------------------------------- - // equals() + // equals() / hashCode() //----------------------------------------------------------------------- - public static Object[][] data_equals() { - return new Object[][] { - {InternationalFixedDate.of(2000, 1, 3), - InternationalFixedDate.of(2000, 1, 4), InternationalFixedDate.of(2000, 2, 3), InternationalFixedDate.of(2001, 1, 3)}, - {InternationalFixedDate.of(2000, 13, 29), - InternationalFixedDate.of(2000, 13, 28), InternationalFixedDate.of(2001, 1, 1), InternationalFixedDate.of(2001, 13, 29)}, - {InternationalFixedDate.of(2000, 6, 29), - InternationalFixedDate.of(2000, 6, 28), InternationalFixedDate.of(2000, 7, 1), InternationalFixedDate.of(2004, 6, 29)}, - }; - } - - @ParameterizedTest - @MethodSource("data_equals") - public void test_equals(InternationalFixedDate a1, InternationalFixedDate b, InternationalFixedDate c, - InternationalFixedDate d) { - assertTrue(a1.equals(a1)); - assertFalse(a1.equals(b)); - assertFalse(a1.equals(c)); - assertFalse(a1.equals(d)); - - assertFalse(a1.equals(null)); - assertFalse(a1.equals((Object) "")); + @Test + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(InternationalFixedDate.of(2000, 1, 3), InternationalFixedDate.of(2000, 1, 3)) + .addEqualityGroup(InternationalFixedDate.of(2000, 1, 4), InternationalFixedDate.of(2000, 1, 4)) + .addEqualityGroup(InternationalFixedDate.of(2000, 2, 3), InternationalFixedDate.of(2000, 2, 3)) + .addEqualityGroup(InternationalFixedDate.of(2000, 6, 28), InternationalFixedDate.of(2000, 6, 28)) + .addEqualityGroup(InternationalFixedDate.of(2000, 6, 29), InternationalFixedDate.of(2000, 6, 29)) + .addEqualityGroup(InternationalFixedDate.of(2000, 13, 28), InternationalFixedDate.of(2000, 13, 28)) + .addEqualityGroup(InternationalFixedDate.of(2001, 1, 1), InternationalFixedDate.of(2001, 1, 1)) + .addEqualityGroup(InternationalFixedDate.of(2001, 13, 29), InternationalFixedDate.of(2001, 13, 29)) + .addEqualityGroup(InternationalFixedDate.of(2004, 6, 29), InternationalFixedDate.of(2004, 6, 29)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java b/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java index d9c77347..599b3482 100644 --- a/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestJulianChronology.java @@ -54,10 +54,8 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; @@ -79,6 +77,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test. */ @@ -710,26 +710,16 @@ public void test_minus_Period_ISO() { } //----------------------------------------------------------------------- - // equals() + // equals() / hashCode() //----------------------------------------------------------------------- @Test - public void test_equals() { - JulianDate a1 = JulianDate.of(2000, 1, 3); - JulianDate a2 = JulianDate.of(2000, 1, 3); - JulianDate b = JulianDate.of(2000, 1, 4); - JulianDate c = JulianDate.of(2000, 2, 3); - JulianDate d = JulianDate.of(2001, 1, 3); - - assertEquals(true, a1.equals(a1)); - assertEquals(true, a1.equals(a2)); - assertEquals(false, a1.equals(b)); - assertEquals(false, a1.equals(c)); - assertEquals(false, a1.equals(d)); - - assertFalse(a1.equals(null)); - assertFalse(a1.equals((Object) "")); - - assertTrue(a1.hashCode() == a2.hashCode()); + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(JulianDate.of(2000, 1, 3), JulianDate.of(2000, 1, 3)) + .addEqualityGroup(JulianDate.of(2000, 1, 4), JulianDate.of(2000, 1, 4)) + .addEqualityGroup(JulianDate.of(2000, 2, 3), JulianDate.of(2000, 2, 3)) + .addEqualityGroup(JulianDate.of(2001, 1, 3), JulianDate.of(2001, 1, 3)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java b/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java index 3deca728..3f474cbf 100644 --- a/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestPaxChronology.java @@ -54,10 +54,8 @@ import static java.time.temporal.ChronoUnit.WEEKS; import static java.time.temporal.ChronoUnit.YEARS; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.DateTimeException; import java.time.LocalDate; @@ -81,6 +79,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test. */ @@ -859,26 +859,16 @@ public void test_minus_Period_ISO() { } //----------------------------------------------------------------------- - // equals() + // equals() / hashCode() //----------------------------------------------------------------------- @Test - public void test_equals() { - PaxDate a1 = PaxDate.of(2000, 1, 3); - PaxDate a2 = PaxDate.of(2000, 1, 3); - PaxDate b = PaxDate.of(2000, 1, 4); - PaxDate c = PaxDate.of(2000, 2, 3); - PaxDate d = PaxDate.of(2001, 1, 3); - - assertEquals(true, a1.equals(a1)); - assertEquals(true, a1.equals(a2)); - assertEquals(false, a1.equals(b)); - assertEquals(false, a1.equals(c)); - assertEquals(false, a1.equals(d)); - - assertFalse(a1.equals(null)); - assertFalse(a1.equals((Object) "")); - - assertTrue(a1.hashCode() == a2.hashCode()); + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(PaxDate.of(2000, 1, 3), PaxDate.of(2000, 1, 3)) + .addEqualityGroup(PaxDate.of(2000, 1, 4), PaxDate.of(2000, 1, 4)) + .addEqualityGroup(PaxDate.of(2000, 2, 3), PaxDate.of(2000, 2, 3)) + .addEqualityGroup(PaxDate.of(2001, 1, 3), PaxDate.of(2001, 1, 3)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java b/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java index cd6c49ec..97921a58 100644 --- a/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestSymmetry010Chronology.java @@ -85,6 +85,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test. */ @@ -961,26 +963,24 @@ public void test_minus_Period_ISO() { } //----------------------------------------------------------------------- - // Symmetry010Date.equals + // equals() / hashCode() //----------------------------------------------------------------------- - public static Object[][] data_equals() { - return new Object[][] { - {Symmetry010Date.of(2000, 1, 3), Symmetry010Date.of(2000, 1, 4), Symmetry010Date.of(2000, 2, 3), Symmetry010Date.of(2001, 1, 3)}, - {Symmetry010Date.of(2000, 12, 28), Symmetry010Date.of(2000, 12, 25), Symmetry010Date.of(2001, 1, 1), Symmetry010Date.of(2001, 12, 28)}, - {Symmetry010Date.of(2000, 6, 28), Symmetry010Date.of(2000, 6, 23), Symmetry010Date.of(2000, 7, 1), Symmetry010Date.of(2004, 6, 28)}, - }; - } - - @ParameterizedTest - @MethodSource("data_equals") - public void test_equals(Symmetry010Date a1, Symmetry010Date b, Symmetry010Date c, Symmetry010Date d) { - assertTrue(a1.equals(a1)); - assertFalse(a1.equals(b)); - assertFalse(a1.equals(c)); - assertFalse(a1.equals(d)); - - assertFalse(a1.equals(null)); - assertFalse(a1.equals((Object) "")); + @Test + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(Symmetry010Date.of(2000, 1, 3), Symmetry010Date.of(2000, 1, 3)) + .addEqualityGroup(Symmetry010Date.of(2000, 1, 4), Symmetry010Date.of(2000, 1, 4)) + .addEqualityGroup(Symmetry010Date.of(2000, 2, 3), Symmetry010Date.of(2000, 2, 3)) + .addEqualityGroup(Symmetry010Date.of(2000, 6, 23), Symmetry010Date.of(2000, 6, 23)) + .addEqualityGroup(Symmetry010Date.of(2000, 6, 28), Symmetry010Date.of(2000, 6, 28)) + .addEqualityGroup(Symmetry010Date.of(2000, 7, 1), Symmetry010Date.of(2000, 7, 1)) + .addEqualityGroup(Symmetry010Date.of(2000, 12, 25), Symmetry010Date.of(2000, 12, 25)) + .addEqualityGroup(Symmetry010Date.of(2000, 12, 28), Symmetry010Date.of(2000, 12, 28)) + .addEqualityGroup(Symmetry010Date.of(2001, 1, 1), Symmetry010Date.of(2001, 1, 1)) + .addEqualityGroup(Symmetry010Date.of(2001, 1, 3), Symmetry010Date.of(2001, 1, 3)) + .addEqualityGroup(Symmetry010Date.of(2001, 12, 28), Symmetry010Date.of(2001, 12, 28)) + .addEqualityGroup(Symmetry010Date.of(2004, 6, 28), Symmetry010Date.of(2004, 6, 28)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java b/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java index e18d79cd..34cdcf45 100644 --- a/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java +++ b/src/test/java/org/threeten/extra/chrono/TestSymmetry454Chronology.java @@ -85,6 +85,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test. */ @@ -969,26 +971,24 @@ public void test_minus_Period_ISO() { } //----------------------------------------------------------------------- - // Symmetry454Date.equals + // equals() / hashCode() //----------------------------------------------------------------------- - public static Object[][] data_equals() { - return new Object[][] { - {Symmetry454Date.of(2000, 1, 3), Symmetry454Date.of(2000, 1, 4), Symmetry454Date.of(2000, 2, 3), Symmetry454Date.of(2001, 1, 3)}, - {Symmetry454Date.of(2000, 12, 28), Symmetry454Date.of(2000, 12, 25), Symmetry454Date.of(2001, 1, 1), Symmetry454Date.of(2001, 12, 28)}, - {Symmetry454Date.of(2000, 6, 28), Symmetry454Date.of(2000, 6, 23), Symmetry454Date.of(2000, 7, 1), Symmetry454Date.of(2004, 6, 28)}, - }; - } - - @ParameterizedTest - @MethodSource("data_equals") - public void test_equals(Symmetry454Date a1, Symmetry454Date b, Symmetry454Date c, Symmetry454Date d) { - assertTrue(a1.equals(a1)); - assertFalse(a1.equals(b)); - assertFalse(a1.equals(c)); - assertFalse(a1.equals(d)); - - assertFalse(a1.equals(null)); - assertFalse(a1.equals((Object) "")); + @Test + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(Symmetry454Date.of(2000, 1, 3), Symmetry454Date.of(2000, 1, 3)) + .addEqualityGroup(Symmetry454Date.of(2000, 1, 4), Symmetry454Date.of(2000, 1, 4)) + .addEqualityGroup(Symmetry454Date.of(2000, 2, 3), Symmetry454Date.of(2000, 2, 3)) + .addEqualityGroup(Symmetry454Date.of(2001, 1, 3), Symmetry454Date.of(2001, 1, 3)) + .addEqualityGroup(Symmetry454Date.of(2000, 12, 28), Symmetry454Date.of(2000, 12, 28)) + .addEqualityGroup(Symmetry454Date.of(2000, 12, 25), Symmetry454Date.of(2000, 12, 25)) + .addEqualityGroup(Symmetry454Date.of(2001, 1, 1), Symmetry454Date.of(2001, 1, 1)) + .addEqualityGroup(Symmetry454Date.of(2001, 12, 28), Symmetry454Date.of(2001, 12, 28)) + .addEqualityGroup(Symmetry454Date.of(2000, 6, 28), Symmetry454Date.of(2000, 6, 28)) + .addEqualityGroup(Symmetry454Date.of(2000, 6, 23), Symmetry454Date.of(2000, 6, 23)) + .addEqualityGroup(Symmetry454Date.of(2000, 7, 1), Symmetry454Date.of(2000, 7, 1)) + .addEqualityGroup(Symmetry454Date.of(2004, 6, 28), Symmetry454Date.of(2004, 6, 28)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/scale/TestTaiInstant.java b/src/test/java/org/threeten/extra/scale/TestTaiInstant.java index ec0ea717..be2b2ccb 100644 --- a/src/test/java/org/threeten/extra/scale/TestTaiInstant.java +++ b/src/test/java/org/threeten/extra/scale/TestTaiInstant.java @@ -49,6 +49,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test TaiInstant. */ @@ -765,64 +767,15 @@ public void test_compareToNonTaiInstant() { } //----------------------------------------------------------------------- - // equals() - //----------------------------------------------------------------------- - @Test - public void test_equals() { - TaiInstant test5a = TaiInstant.ofTaiSeconds(5L, 20); - TaiInstant test5b = TaiInstant.ofTaiSeconds(5L, 20); - TaiInstant test5n = TaiInstant.ofTaiSeconds(5L, 30); - TaiInstant test6 = TaiInstant.ofTaiSeconds(6L, 20); - - assertEquals(true, test5a.equals(test5a)); - assertEquals(true, test5a.equals(test5b)); - assertEquals(false, test5a.equals(test5n)); - assertEquals(false, test5a.equals(test6)); - - assertEquals(true, test5b.equals(test5a)); - assertEquals(true, test5b.equals(test5b)); - assertEquals(false, test5b.equals(test5n)); - assertEquals(false, test5b.equals(test6)); - - assertEquals(false, test5n.equals(test5a)); - assertEquals(false, test5n.equals(test5b)); - assertEquals(true, test5n.equals(test5n)); - assertEquals(false, test5n.equals(test6)); - - assertEquals(false, test6.equals(test5a)); - assertEquals(false, test6.equals(test5b)); - assertEquals(false, test6.equals(test5n)); - assertEquals(true, test6.equals(test6)); - } - - @Test - public void test_equals_null() { - TaiInstant test5 = TaiInstant.ofTaiSeconds(5L, 20); - assertEquals(false, test5.equals(null)); - } - - @Test - public void test_equals_otherClass() { - TaiInstant test5 = TaiInstant.ofTaiSeconds(5L, 20); - assertEquals(false, test5.equals((Object) "")); - } - - //----------------------------------------------------------------------- - // hashCode() + // equals() / hashCode() //----------------------------------------------------------------------- @Test - public void test_hashCode() { - TaiInstant test5a = TaiInstant.ofTaiSeconds(5L, 20); - TaiInstant test5b = TaiInstant.ofTaiSeconds(5L, 20); - TaiInstant test5n = TaiInstant.ofTaiSeconds(5L, 30); - TaiInstant test6 = TaiInstant.ofTaiSeconds(6L, 20); - - assertEquals(true, test5a.hashCode() == test5a.hashCode()); - assertEquals(true, test5a.hashCode() == test5b.hashCode()); - assertEquals(true, test5b.hashCode() == test5b.hashCode()); - - assertEquals(false, test5a.hashCode() == test5n.hashCode()); - assertEquals(false, test5a.hashCode() == test6.hashCode()); + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(TaiInstant.ofTaiSeconds(5L, 20), TaiInstant.ofTaiSeconds(5L, 20)) + .addEqualityGroup(TaiInstant.ofTaiSeconds(5L, 30), TaiInstant.ofTaiSeconds(5L, 30)) + .addEqualityGroup(TaiInstant.ofTaiSeconds(6L, 20), TaiInstant.ofTaiSeconds(6L, 20)) + .testEquals(); } //----------------------------------------------------------------------- diff --git a/src/test/java/org/threeten/extra/scale/TestUtcInstant.java b/src/test/java/org/threeten/extra/scale/TestUtcInstant.java index 67c700bd..5757e1cf 100644 --- a/src/test/java/org/threeten/extra/scale/TestUtcInstant.java +++ b/src/test/java/org/threeten/extra/scale/TestUtcInstant.java @@ -49,6 +49,8 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import com.google.common.testing.EqualsTester; + /** * Test UtcInstant. */ @@ -517,64 +519,15 @@ public void test_compareToNonUtcInstant() { } //----------------------------------------------------------------------- - // equals() - //----------------------------------------------------------------------- - @Test - public void test_equals() { - UtcInstant test5a = UtcInstant.ofModifiedJulianDay(5L, 20); - UtcInstant test5b = UtcInstant.ofModifiedJulianDay(5L, 20); - UtcInstant test5n = UtcInstant.ofModifiedJulianDay(5L, 30); - UtcInstant test6 = UtcInstant.ofModifiedJulianDay(6L, 20); - - assertEquals(true, test5a.equals(test5a)); - assertEquals(true, test5a.equals(test5b)); - assertEquals(false, test5a.equals(test5n)); - assertEquals(false, test5a.equals(test6)); - - assertEquals(true, test5b.equals(test5a)); - assertEquals(true, test5b.equals(test5b)); - assertEquals(false, test5b.equals(test5n)); - assertEquals(false, test5b.equals(test6)); - - assertEquals(false, test5n.equals(test5a)); - assertEquals(false, test5n.equals(test5b)); - assertEquals(true, test5n.equals(test5n)); - assertEquals(false, test5n.equals(test6)); - - assertEquals(false, test6.equals(test5a)); - assertEquals(false, test6.equals(test5b)); - assertEquals(false, test6.equals(test5n)); - assertEquals(true, test6.equals(test6)); - } - - @Test - public void test_equals_null() { - UtcInstant test5 = UtcInstant.ofModifiedJulianDay(5L, 20); - assertEquals(false, test5.equals(null)); - } - - @Test - public void test_equals_otherClass() { - UtcInstant test5 = UtcInstant.ofModifiedJulianDay(5L, 20); - assertEquals(false, test5.equals((Object) "")); - } - - //----------------------------------------------------------------------- - // hashCode() + // equals() / hashCode() //----------------------------------------------------------------------- @Test - public void test_hashCode() { - UtcInstant test5a = UtcInstant.ofModifiedJulianDay(5L, 20); - UtcInstant test5b = UtcInstant.ofModifiedJulianDay(5L, 20); - UtcInstant test5n = UtcInstant.ofModifiedJulianDay(5L, 30); - UtcInstant test6 = UtcInstant.ofModifiedJulianDay(6L, 20); - - assertEquals(true, test5a.hashCode() == test5a.hashCode()); - assertEquals(true, test5a.hashCode() == test5b.hashCode()); - assertEquals(true, test5b.hashCode() == test5b.hashCode()); - - assertEquals(false, test5a.hashCode() == test5n.hashCode()); - assertEquals(false, test5a.hashCode() == test6.hashCode()); + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(UtcInstant.ofModifiedJulianDay(5L, 20), UtcInstant.ofModifiedJulianDay(5L, 20)) + .addEqualityGroup(UtcInstant.ofModifiedJulianDay(5L, 30), UtcInstant.ofModifiedJulianDay(5L, 30)) + .addEqualityGroup(UtcInstant.ofModifiedJulianDay(6L, 20), UtcInstant.ofModifiedJulianDay(6L, 20)) + .testEquals(); } //----------------------------------------------------------------------- From d989a4ac5945f564c9a098e50e6d343e42312330 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 16 Apr 2024 22:15:18 +0100 Subject: [PATCH 273/279] Add `HourMinute` (#322) * New time-only class that only holds hours and minutes * Supports domains where a more precise time is not helpful --- pom.xml | 7 + .../java/org/threeten/extra/HourMinute.java | 1090 +++++++++++++++++ .../org/threeten/extra/TestHourMinute.java | 677 ++++++++++ 3 files changed, 1774 insertions(+) create mode 100644 src/main/java/org/threeten/extra/HourMinute.java create mode 100644 src/test/java/org/threeten/extra/TestHourMinute.java diff --git a/pom.xml b/pom.xml index 036ba5c9..646798b9 100644 --- a/pom.xml +++ b/pom.xml @@ -549,6 +549,12 @@ ${pioneer.version} test + + org.assertj + assertj-core + ${assertj.version} + test + @@ -922,6 +928,7 @@ + 3.24.2 2.2.3 5.10.1 1.9.1 diff --git a/src/main/java/org/threeten/extra/HourMinute.java b/src/main/java/org/threeten/extra/HourMinute.java new file mode 100644 index 00000000..d91de31b --- /dev/null +++ b/src/main/java/org/threeten/extra/HourMinute.java @@ -0,0 +1,1090 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.extra; + +import static java.time.temporal.ChronoField.AMPM_OF_DAY; +import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_AMPM; +import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_DAY; +import static java.time.temporal.ChronoField.HOUR_OF_AMPM; +import static java.time.temporal.ChronoField.HOUR_OF_DAY; +import static java.time.temporal.ChronoField.MINUTE_OF_DAY; +import static java.time.temporal.ChronoField.MINUTE_OF_HOUR; +import static java.time.temporal.ChronoUnit.HALF_DAYS; +import static java.time.temporal.ChronoUnit.HOURS; +import static java.time.temporal.ChronoUnit.MINUTES; + +import java.io.Serializable; +import java.time.Clock; +import java.time.DateTimeException; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetTime; +import java.time.Period; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; +import java.time.temporal.ChronoField; +import java.time.temporal.ChronoUnit; +import java.time.temporal.Temporal; +import java.time.temporal.TemporalAccessor; +import java.time.temporal.TemporalAdjuster; +import java.time.temporal.TemporalAmount; +import java.time.temporal.TemporalField; +import java.time.temporal.TemporalQueries; +import java.time.temporal.TemporalQuery; +import java.time.temporal.TemporalUnit; +import java.time.temporal.UnsupportedTemporalTypeException; +import java.time.temporal.ValueRange; +import java.util.Objects; + +import org.joda.convert.FromString; +import org.joda.convert.ToString; + +/** + * An hour-minute, such as {@code 12:31}. + *

        + * This class is similar to {@link LocalTime} but has a precision of minutes. + * Seconds and nanoseconds cannot be represented by this class. + * + *

        Implementation Requirements:

        + * This class is immutable and thread-safe. + *

        + * This class must be treated as a value type. Do not synchronize, rely on the + * identity hash code or use the distinction between equals() and ==. + */ +public final class HourMinute + implements Temporal, TemporalAdjuster, Comparable, Serializable { + + /** + * The time of midnight at the start of the day, '00:00'. + */ + public static final HourMinute MIDNIGHT = new HourMinute(0, 0); + + /** + * Serialization version. + */ + private static final long serialVersionUID = -2532872925L; + /** + * Parser. + */ + private static final DateTimeFormatter PARSER = new DateTimeFormatterBuilder() + .appendValue(HOUR_OF_DAY, 2) + .appendLiteral(':') + .appendValue(MINUTE_OF_HOUR, 2) + .toFormatter(); + /** + * Hours per day. + */ + private static final int HOURS_PER_DAY = 24; + /** + * Minutes per hour. + */ + private static final int MINUTES_PER_HOUR = 60; + /** + * Minutes per day. + */ + private static final int MINUTES_PER_DAY = MINUTES_PER_HOUR * HOURS_PER_DAY; + + /** + * The hour-of-day. + */ + private final int hour; + /** + * The minute-of-hour. + */ + private final int minute; + + //----------------------------------------------------------------------- + /** + * Obtains the current hour-minute from the system clock in the default time-zone. + *

        + * This will query the {@link java.time.Clock#systemDefaultZone() system clock} in the default + * time-zone to obtain the current hour-minute. + * The zone and offset will be set based on the time-zone in the clock. + *

        + * Using this method will prevent the ability to use an alternate clock for testing + * because the clock is hard-coded. + * + * @return the current hour-minute using the system clock and default time-zone, not null + */ + public static HourMinute now() { + return now(Clock.systemDefaultZone()); + } + + /** + * Obtains the current hour-minute from the system clock in the specified time-zone. + *

        + * This will query the {@link Clock#system(java.time.ZoneId) system clock} to obtain the current hour-minute. + * Specifying the time-zone avoids dependence on the default time-zone. + *

        + * Using this method will prevent the ability to use an alternate clock for testing + * because the clock is hard-coded. + * + * @param zone the zone ID to use, not null + * @return the current hour-minute using the system clock, not null + */ + public static HourMinute now(ZoneId zone) { + return now(Clock.system(zone)); + } + + /** + * Obtains the current hour-minute from the specified clock. + *

        + * This will query the specified clock to obtain the current hour-minute. + * Using this method allows the use of an alternate clock for testing. + * The alternate clock may be introduced using {@link Clock dependency injection}. + * + * @param clock the clock to use, not null + * @return the current hour-minute, not null + */ + public static HourMinute now(Clock clock) { + final LocalTime now = LocalTime.now(clock); // called once + return HourMinute.of(now.getHour(), now.getMinute()); + } + + //----------------------------------------------------------------------- + /** + * Obtains an instance of {@code HourMinute} from a hour and minute. + * + * @param hour the hour to represent, from 0 to 23 + * @param minute the minute-of-hour to represent, from 0 to 59 + * @return the hour-minute, not null + * @throws DateTimeException if either field value is invalid + */ + public static HourMinute of(int hour, int minute) { + HOUR_OF_DAY.checkValidValue(hour); + MINUTE_OF_HOUR.checkValidValue(minute); + return new HourMinute(hour, minute); + } + + //----------------------------------------------------------------------- + /** + * Obtains an instance of {@code HourMinute} from a temporal object. + *

        + * This obtains a hour-minute based on the specified temporal. + * A {@code TemporalAccessor} represents an arbitrary set of date and time information, + * which this factory converts to an instance of {@code HourMinute}. + *

        + * The conversion extracts the {@link ChronoField#HOUR_OF_DAY HOUR_OF_DAY} and + * {@link ChronoField#MINUTE_OF_HOUR MINUTE_OF_HOUR} fields. + *

        + * This method matches the signature of the functional interface {@link TemporalQuery} + * allowing it to be used in queries via method reference, {@code HourMinute::from}. + * + * @param temporal the temporal object to convert, not null + * @return the hour-minute, not null + * @throws DateTimeException if unable to convert to a {@code HourMinute} + */ + public static HourMinute from(TemporalAccessor temporal) { + if (temporal instanceof HourMinute) { + return (HourMinute) temporal; + } + Objects.requireNonNull(temporal, "temporal"); + try { + // need to use getLong() as JDK Parsed class get() doesn't work properly + int hour = Math.toIntExact(temporal.getLong(HOUR_OF_DAY)); + int minute = Math.toIntExact(temporal.getLong(MINUTE_OF_HOUR)); + return of(hour, minute); + } catch (DateTimeException ex) { + throw new DateTimeException("Unable to obtain HourMinute from TemporalAccessor: " + + temporal + " of type " + temporal.getClass().getName(), ex); + } + } + + //----------------------------------------------------------------------- + /** + * Obtains an instance of {@code HourMinute} from a text string such as {@code 12:31}. + *

        + * The string must represent a valid hour-minute. + * The format must be {@code HH:mm}. + * + * @param text the text to parse such as "12:31", not null + * @return the parsed hour-minute, not null + * @throws DateTimeParseException if the text cannot be parsed + */ + @FromString + public static HourMinute parse(CharSequence text) { + return parse(text, PARSER); + } + + /** + * Obtains an instance of {@code HourMinute} from a text string using a specific formatter. + *

        + * The text is parsed using the formatter, returning a hour-minute. + * + * @param text the text to parse, not null + * @param formatter the formatter to use, not null + * @return the parsed hour-minute, not null + * @throws DateTimeParseException if the text cannot be parsed + */ + public static HourMinute parse(CharSequence text, DateTimeFormatter formatter) { + Objects.requireNonNull(formatter, "formatter"); + return formatter.parse(text, HourMinute::from); + } + + //----------------------------------------------------------------------- + /** + * Constructor. + * + * @param hour the hour to represent, validated from 0 to 23 + * @param minute the minute-of-hour to represent, validated from 0 to 59 + */ + private HourMinute(int hour, int minute) { + this.hour = hour; + this.minute = minute; + } + + /** + * Validates the input. + * + * @return the valid object, not null + */ + private Object readResolve() { + return of(hour, minute); + } + + /** + * Returns a copy of this hour-minute with the new hour and minute, checking + * to see if a new object is in fact required. + * + * @param newYear the hour to represent, validated from 0 to 23 + * @param newMinute the minute-of-hour to represent, validated from 0 to 59 + * @return the hour-minute, not null + */ + private HourMinute with(int newYear, int newMinute) { + if (hour == newYear && minute == newMinute) { + return this; + } + return new HourMinute(newYear, newMinute); + } + + //----------------------------------------------------------------------- + /** + * Checks if the specified field is supported. + *

        + * This checks if this hour-minute can be queried for the specified field. + * If false, then calling the {@link #range(TemporalField) range}, + * {@link #get(TemporalField) get} and {@link #with(TemporalField, long)} + * methods will throw an exception. + *

        + * If the field is a {@link ChronoField} then the query is implemented here. + * The supported fields are: + *

          + *
        • {@code MINUTE_OF_HOUR} + *
        • {@code MINUTE_OF_DAY} + *
        • {@code HOUR_OF_AMPM} + *
        • {@code CLOCK_HOUR_OF_AMPM} + *
        • {@code HOUR_OF_DAY} + *
        • {@code CLOCK_HOUR_OF_DAY} + *
        • {@code AMPM_OF_DAY} + *
        + * All other {@code ChronoField} instances will return false. + *

        + * If the field is not a {@code ChronoField}, then the result of this method + * is obtained by invoking {@code TemporalField.isSupportedBy(TemporalAccessor)} + * passing {@code this} as the argument. + * Whether the field is supported is determined by the field. + * + * @param field the field to check, null returns false + * @return true if the field is supported on this hour-minute, false if not + */ + @Override + public boolean isSupported(TemporalField field) { + if (field instanceof ChronoField) { + return field == MINUTE_OF_HOUR || + field == MINUTE_OF_DAY || + field == HOUR_OF_AMPM || + field == CLOCK_HOUR_OF_AMPM || + field == HOUR_OF_DAY || + field == CLOCK_HOUR_OF_DAY || + field == AMPM_OF_DAY; + } + return field != null && field.isSupportedBy(this); + } + + /** + * Checks if the specified unit is supported. + *

        + * This checks if the specified unit can be added to, or subtracted from, this hour-minute. + * If false, then calling the {@link #plus(long, TemporalUnit)} and + * {@link #minus(long, TemporalUnit) minus} methods will throw an exception. + *

        + * If the unit is a {@link ChronoUnit} then the query is implemented here. + * The supported units are: + *

          + *
        • {@code MINUTES} + *
        • {@code HOURS} + *
        • {@code HALF_DAYS} + *
        + * All other {@code ChronoUnit} instances will return false. + *

        + * If the unit is not a {@code ChronoUnit}, then the result of this method + * is obtained by invoking {@code TemporalUnit.isSupportedBy(Temporal)} + * passing {@code this} as the argument. + * Whether the unit is supported is determined by the unit. + * + * @param unit the unit to check, null returns false + * @return true if the unit can be added/subtracted, false if not + */ + @Override + public boolean isSupported(TemporalUnit unit) { + if (unit instanceof ChronoUnit) { + return unit == MINUTES || unit == HOURS || unit == HALF_DAYS; + } + return unit != null && unit.isSupportedBy(this); + } + + //----------------------------------------------------------------------- + /** + * Gets the range of valid values for the specified field. + *

        + * The range object expresses the minimum and maximum valid values for a field. + * If it is not possible to return the range, because the field is not supported + * or for some other reason, an exception is thrown. + *

        + * If the field is a {@link ChronoField} then the query is implemented here. + * The {@link #isSupported(TemporalField) supported fields} will return + * appropriate range instances. + * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. + *

        + * If the field is not a {@code ChronoField}, then the result of this method + * is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessor)} + * passing {@code this} as the argument. + * Whether the range can be obtained is determined by the field. + * + * @param field the field to query the range for, not null + * @return the range of valid values for the field, not null + * @throws DateTimeException if the range for the field cannot be obtained + * @throws UnsupportedTemporalTypeException if the field is not supported + */ + @Override + public ValueRange range(TemporalField field) { + return Temporal.super.range(field); + } + + /** + * Gets the value of the specified field from this hour-minute as an {@code int}. + *

        + * This queries this hour-minute for the value for the specified field. + * The returned value will always be within the valid range of values for the field. + * If it is not possible to return the value, because the field is not supported + * or for some other reason, an exception is thrown. + *

        + * If the field is a {@link ChronoField} then the query is implemented here. + * The {@link #isSupported(TemporalField) supported fields} will return valid + * values based on this hour-minute,. + * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. + *

        + * If the field is not a {@code ChronoField}, then the result of this method + * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} + * passing {@code this} as the argument. Whether the value can be obtained, + * and what the value represents, is determined by the field. + * + * @param field the field to get, not null + * @return the value for the field + * @throws DateTimeException if a value for the field cannot be obtained or + * the value is outside the range of valid values for the field + * @throws UnsupportedTemporalTypeException if the field is not supported or + * the range of values exceeds an {@code int} + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public int get(TemporalField field) { + if (field instanceof ChronoField) { + return get0(field); + } + return Temporal.super.get(field); + } + + /** + * Gets the value of the specified field from this hour-minute as a {@code long}. + *

        + * This queries this hour-minute for the value for the specified field. + * If it is not possible to return the value, because the field is not supported + * or for some other reason, an exception is thrown. + *

        + * If the field is a {@link ChronoField} then the query is implemented here. + * The {@link #isSupported(TemporalField) supported fields} will return valid + * values based on this hour-minute. + * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. + *

        + * If the field is not a {@code ChronoField}, then the result of this method + * is obtained by invoking {@code TemporalField.getFrom(TemporalAccessor)} + * passing {@code this} as the argument. Whether the value can be obtained, + * and what the value represents, is determined by the field. + * + * @param field the field to get, not null + * @return the value for the field + * @throws DateTimeException if a value for the field cannot be obtained + * @throws UnsupportedTemporalTypeException if the field is not supported + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public long getLong(TemporalField field) { + if (field instanceof ChronoField) { + return get0(field); + } + return field.getFrom(this); + } + + private int get0(TemporalField field) { + switch ((ChronoField) field) { + case MINUTE_OF_HOUR: + return minute; + case MINUTE_OF_DAY: + return hour * 60 + minute; + case HOUR_OF_AMPM: + return hour % 12; + case CLOCK_HOUR_OF_AMPM: + int ham = hour % 12; + return (ham % 12 == 0 ? 12 : ham); + case HOUR_OF_DAY: + return hour; + case CLOCK_HOUR_OF_DAY: + return (hour == 0 ? 24 : hour); + case AMPM_OF_DAY: + return hour / 12; + default: + throw new UnsupportedTemporalTypeException("Unsupported field: " + field); + } + } + + //----------------------------------------------------------------------- + /** + * Gets the hour field, from 0 to 23. + *

        + * This method returns the hour as an {@code int} from 0 to 23. + * + * @return the hour, from 0 to 23 + */ + public int getHour() { + return hour; + } + + /** + * Gets the minute-of-hour field from 0 to 59. + *

        + * This method returns the minute as an {@code int} from 0 to 59. + * + * @return the minute-of-hour, from 0 to 59 + */ + public int getMinute() { + return minute; + } + + //----------------------------------------------------------------------- + /** + * Returns an adjusted copy of this hour-minute. + *

        + * This returns a {@code HourMinute} based on this one, with the hour-minute adjusted. + * The adjustment takes place using the specified adjuster strategy object. + * Read the documentation of the adjuster to understand what adjustment will be made. + *

        + * The result of this method is obtained by invoking the + * {@link TemporalAdjuster#adjustInto(Temporal)} method on the + * specified adjuster passing {@code this} as the argument. + *

        + * This instance is immutable and unaffected by this method call. + * + * @param adjuster the adjuster to use, not null + * @return a {@code HourMinute} based on {@code this} with the adjustment made, not null + * @throws DateTimeException if the adjustment cannot be made + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public HourMinute with(TemporalAdjuster adjuster) { + return (HourMinute) adjuster.adjustInto(this); + } + + /** + * Returns a copy of this hour-minute with the specified field set to a new value. + *

        + * This returns a {@code HourMinute} based on this one, with the value + * for the specified field changed. + * This can be used to change any supported field, such as the hour or minute. + * If it is not possible to set the value, because the field is not supported or for + * some other reason, an exception is thrown. + *

        + * If the field is a {@link ChronoField} then the adjustment is implemented here. + * The supported fields behave as follows: + *

          + *
        • {@code MINUTE_OF_HOUR} - + * Returns a {@code HourMinute} with the specified minute-of-hour. + * The hour will be unchanged. + *
        • {@code MINUTE_OF_DAY} - + * Returns a {@code HourMinute} with the specified minute-of-day. + *
        • {@code HOUR_OF_AMPM} - + * Returns a {@code HourMinute} with the specified hour-of-am-pm. + * The AM/PM and minute-of-hour will be unchanged. + *
        • {@code CLOCK_HOUR_OF_AMPM} - + * Returns a {@code HourMinute} with the specified clock-hour-of-am-pm. + * The AM/PM and minute-of-hour will be unchanged. + *
        • {@code HOUR_OF_DAY} - + * Returns a {@code HourMinute} with the specified hour-of-day. + * The minute-of-hour will be unchanged. + *
        • {@code CLOCK_HOUR_OF_DAY} - + * Returns a {@code HourMinute} with the specified clock-hour-of-day. + * The minute-of-hour will be unchanged. + *
        • {@code AMPM_OF_DAY} - + * Returns a {@code HourMinute} with the specified AM/PM. + * The hour-of-am-pm and minute-of-hour will be unchanged. + *
        + *

        + * In all cases, if the new value is outside the valid range of values for the field + * then a {@code DateTimeException} will be thrown. + *

        + * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}. + *

        + * If the field is not a {@code ChronoField}, then the result of this method + * is obtained by invoking {@code TemporalField.adjustInto(Temporal, long)} + * passing {@code this} as the argument. In this case, the field determines + * whether and how to adjust the instant. + *

        + * This instance is immutable and unaffected by this method call. + * + * @param field the field to set in the result, not null + * @param newValue the new value of the field in the result + * @return a {@code HourMinute} based on {@code this} with the specified field set, not null + * @throws DateTimeException if the field cannot be set + * @throws UnsupportedTemporalTypeException if the field is not supported + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public HourMinute with(TemporalField field, long newValue) { + if (field instanceof ChronoField) { + ChronoField f = (ChronoField) field; + f.checkValidValue(newValue); + switch (f) { + case MINUTE_OF_HOUR: + return withMinute((int) newValue); + case MINUTE_OF_DAY: + return plusMinutes(newValue - (hour * MINUTES_PER_HOUR + minute)); + case HOUR_OF_AMPM: + return plusHours(newValue - (hour % 12)); + case CLOCK_HOUR_OF_AMPM: + return plusHours((newValue == 12 ? 0 : newValue) - (hour % 12)); + case HOUR_OF_DAY: + return withHour((int) newValue); + case CLOCK_HOUR_OF_DAY: + return withHour((int) (newValue == 24 ? 0 : newValue)); + case AMPM_OF_DAY: + return plusHours((newValue - (hour / 12)) * 12); + default: + throw new UnsupportedTemporalTypeException("Unsupported field: " + field); + } + } + return field.adjustInto(this, newValue); + } + + //----------------------------------------------------------------------- + /** + * Returns a copy of this {@code HourMinute} with the hour altered. + *

        + * This instance is immutable and unaffected by this method call. + * + * @param hour the hour to set in the returned hour-minute, from 0 to 23 + * @return a {@code HourMinute} based on this hour-minute with the requested hour, not null + * @throws DateTimeException if the hour value is invalid + */ + public HourMinute withHour(int hour) { + HOUR_OF_DAY.checkValidValue(hour); + return with(hour, minute); + } + + /** + * Returns a copy of this {@code HourMinute} with the minute-of-hour altered. + *

        + * This instance is immutable and unaffected by this method call. + * + * @param minute the minute-of-hour to set in the returned hour-minute, from 0 to 59 + * @return a {@code HourMinute} based on this hour-minute with the requested minute, not null + * @throws DateTimeException if the minute-of-hour value is invalid + */ + public HourMinute withMinute(int minute) { + MINUTE_OF_HOUR.checkValidValue(minute); + return with(hour, minute); + } + + //----------------------------------------------------------------------- + /** + * Returns a copy of this hour-minute with the specified amount added. + *

        + * This returns a {@code HourMinute} based on this one, with the specified amount added. + * The amount is typically {@link Period} but may be any other type implementing + * the {@link TemporalAmount} interface. + *

        + * The calculation is delegated to the amount object by calling + * {@link TemporalAmount#addTo(Temporal)}. The amount implementation is free + * to implement the addition in any way it wishes, however it typically + * calls back to {@link #plus(long, TemporalUnit)}. Consult the documentation + * of the amount implementation to determine if it can be successfully added. + *

        + * This instance is immutable and unaffected by this method call. + * + * @param amountToAdd the amount to add, not null + * @return a {@code HourMinute} based on this hour-minute with the addition made, not null + * @throws DateTimeException if the addition cannot be made + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public HourMinute plus(TemporalAmount amountToAdd) { + return (HourMinute) amountToAdd.addTo(this); + } + + /** + * Returns a copy of this hour-minute with the specified amount added. + *

        + * This returns a {@code HourMinute} based on this one, with the amount + * in terms of the unit added. If it is not possible to add the amount, because the + * unit is not supported or for some other reason, an exception is thrown. + *

        + * If the field is a {@link ChronoUnit} then the addition is implemented here. + * The supported fields behave as follows: + *

          + *
        • {@code MINUTES} - + * Returns a {@code LocalTime} with the specified number of minutes added. + * This is equivalent to {@link #plusMinutes(long)}. + *
        • {@code HOURS} - + * Returns a {@code LocalTime} with the specified number of hours added. + * This is equivalent to {@link #plusHours(long)}. + *
        • {@code HALF_DAYS} - + * Returns a {@code LocalTime} with the specified number of half-days added. + * This is equivalent to {@link #plusHours(long)} with the amount + * multiplied by 12. + *
        + *

        + * All other {@code ChronoUnit} instances will throw an {@code UnsupportedTemporalTypeException}. + *

        + * If the field is not a {@code ChronoUnit}, then the result of this method + * is obtained by invoking {@code TemporalUnit.addTo(Temporal, long)} + * passing {@code this} as the argument. In this case, the unit determines + * whether and how to perform the addition. + *

        + * This instance is immutable and unaffected by this method call. + * + * @param amountToAdd the amount of the unit to add to the result, may be negative + * @param unit the unit of the amount to add, not null + * @return a {@code HourMinute} based on this hour-minute with the specified amount added, not null + * @throws DateTimeException if the addition cannot be made + * @throws UnsupportedTemporalTypeException if the unit is not supported + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public HourMinute plus(long amountToAdd, TemporalUnit unit) { + if (unit instanceof ChronoUnit) { + switch ((ChronoUnit) unit) { + case MINUTES: + return plusMinutes(amountToAdd); + case HOURS: + return plusHours(amountToAdd); + case HALF_DAYS: + return plusHours((amountToAdd % 2) * 12); + default: + throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); + } + } + return unit.addTo(this, amountToAdd); + } + + /** + * Returns a copy of this {@code HourMinute} with the specified number of hours added. + *

        + * This adds the specified number of hours to this time, returning a new time. + * The calculation wraps around midnight. + *

        + * This instance is immutable and unaffected by this method call. + * + * @param hoursToAdd the hours to add, may be negative + * @return an {@code HourMinute} based on this time with the hours added, not null + */ + public HourMinute plusHours(long hoursToAdd) { + if (hoursToAdd == 0) { + return this; + } + int newHour = ((int) (hoursToAdd % HOURS_PER_DAY) + hour + HOURS_PER_DAY) % HOURS_PER_DAY; + return with(newHour, minute); + } + + /** + * Returns a copy of this {@code HourMinute} with the specified number of minutes added. + *

        + * This adds the specified number of minutes to this time, returning a new time. + * The calculation wraps around midnight. + *

        + * This instance is immutable and unaffected by this method call. + * + * @param minutesToAdd the minutes to add, may be negative + * @return an {@code HourMinute} based on this time with the minutes added, not null + */ + public HourMinute plusMinutes(long minutesToAdd) { + if (minutesToAdd == 0) { + return this; + } + int mofd = hour * MINUTES_PER_HOUR + minute; + int newMofd = ((int) (minutesToAdd % MINUTES_PER_DAY) + mofd + MINUTES_PER_DAY) % MINUTES_PER_DAY; + if (mofd == newMofd) { + return this; + } + int newHour = newMofd / MINUTES_PER_HOUR; + int newMinute = newMofd % MINUTES_PER_HOUR; + return with(newHour, newMinute); + } + + //----------------------------------------------------------------------- + /** + * Returns a copy of this hour-minute with the specified amount subtracted. + *

        + * This returns a {@code HourMinute} based on this one, with the specified amount subtracted. + * The amount is typically {@link Period} but may be any other type implementing + * the {@link TemporalAmount} interface. + *

        + * The calculation is delegated to the amount object by calling + * {@link TemporalAmount#subtractFrom(Temporal)}. The amount implementation is free + * to implement the subtraction in any way it wishes, however it typically + * calls back to {@link #minus(long, TemporalUnit)}. Consult the documentation + * of the amount implementation to determine if it can be successfully subtracted. + *

        + * This instance is immutable and unaffected by this method call. + * + * @param amountToSubtract the amount to subtract, not null + * @return a {@code HourMinute} based on this hour-minute with the subtraction made, not null + * @throws DateTimeException if the subtraction cannot be made + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public HourMinute minus(TemporalAmount amountToSubtract) { + return (HourMinute) amountToSubtract.subtractFrom(this); + } + + /** + * Returns a copy of this hour-minute with the specified amount subtracted. + *

        + * This returns a {@code HourMinute} based on this one, with the amount + * in terms of the unit subtracted. If it is not possible to subtract the amount, + * because the unit is not supported or for some other reason, an exception is thrown. + *

        + * This method is equivalent to {@link #plus(long, TemporalUnit)} with the amount negated. + * See that method for a full description of how addition, and thus subtraction, works. + *

        + * This instance is immutable and unaffected by this method call. + * + * @param amountToSubtract the amount of the unit to subtract from the result, may be negative + * @param unit the unit of the amount to subtract, not null + * @return a {@code HourMinute} based on this hour-minute with the specified amount subtracted, not null + * @throws DateTimeException if the subtraction cannot be made + * @throws UnsupportedTemporalTypeException if the unit is not supported + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public HourMinute minus(long amountToSubtract, TemporalUnit unit) { + return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit)); + } + + /** + * Returns a copy of this hour-minute with the specified period in hours subtracted. + *

        + * This instance is immutable and unaffected by this method call. + * + * @param hoursToSubtract the hours to subtract, may be negative + * @return a {@code HourMinute} based on this hour-minute with the hours subtracted, not null + * @throws DateTimeException if the result exceeds the supported range + */ + public HourMinute minusHours(long hoursToSubtract) { + return (hoursToSubtract == Long.MIN_VALUE ? plusHours(Long.MAX_VALUE).plusHours(1) : plusHours(-hoursToSubtract)); + } + + /** + * Returns a copy of this hour-minute with the specified period in minutes subtracted. + *

        + * This instance is immutable and unaffected by this method call. + * + * @param minutesToSubtract the minutes to subtract, may be negative + * @return a {@code HourMinute} based on this hour-minute with the minutes subtracted, not null + * @throws DateTimeException if the result exceeds the supported range + */ + public HourMinute minusMinutes(long minutesToSubtract) { + return (minutesToSubtract == Long.MIN_VALUE ? plusMinutes(Long.MAX_VALUE).plusMinutes(1) : plusMinutes(-minutesToSubtract)); + } + + //----------------------------------------------------------------------- + /** + * Queries this hour-minute using the specified query. + *

        + * This queries this hour-minute using the specified query strategy object. + * The {@code TemporalQuery} object defines the logic to be used to + * obtain the result. Read the documentation of the query to understand + * what the result of this method will be. + *

        + * The result of this method is obtained by invoking the + * {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the + * specified query passing {@code this} as the argument. + * + * @param the type of the result + * @param query the query to invoke, not null + * @return the query result, null may be returned (defined by the query) + * @throws DateTimeException if unable to query (defined by the query) + * @throws ArithmeticException if numeric overflow occurs (defined by the query) + */ + @SuppressWarnings("unchecked") + @Override + public R query(TemporalQuery query) { + if (query == TemporalQueries.localTime()) { + return (R) toLocalTime(); + } else if (query == TemporalQueries.precision()) { + return (R) MINUTES; + } + return Temporal.super.query(query); + } + + /** + * Adjusts the specified temporal object to have this hour-minute. + * Note that if the target has a second or nanosecond field, that is not altered by this method. + *

        + * This returns a temporal object of the same observable type as the input + * with the hour and minute changed to be the same as this. + *

        + * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)} + * passing {@link ChronoField#MINUTE_OF_DAY} as the field. + * Note that this does not affect any second/nanosecond field in the target. + *

        + * In most cases, it is clearer to reverse the calling pattern by using + * {@link Temporal#with(TemporalAdjuster)}: + *

        +     *   // these two lines are equivalent, but the second approach is recommended
        +     *   temporal = thisHourMinute.adjustInto(temporal);
        +     *   temporal = temporal.with(thisHourMinute);
        +     * 
        + *

        + * This instance is immutable and unaffected by this method call. + * + * @param temporal the target object to be adjusted, not null + * @return the adjusted object, not null + * @throws DateTimeException if unable to make the adjustment + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public Temporal adjustInto(Temporal temporal) { + return temporal.with(MINUTE_OF_DAY, hour * MINUTES_PER_HOUR + minute); + } + + /** + * Calculates the amount of time until another hour-minute in terms of the specified unit. + *

        + * This calculates the amount of time between two {@code HourMinute} + * objects in terms of a single {@code TemporalUnit}. + * The start and end points are {@code this} and the specified hour-minute. + * The result will be negative if the end is before the start. + * The {@code Temporal} passed to this method is converted to a + * {@code HourMinute} using {@link #from(TemporalAccessor)}. + * For example, the period in hours between two hour-minutes can be calculated + * using {@code startHourMinute.until(endHourMinute, YEARS)}. + *

        + * The calculation is implemented in this method for {@link ChronoUnit}. + * The units {@code MINUTES}, {@code HOURS} and {@code HALF_DAYS} are supported. + * Other {@code ChronoUnit} values will throw an exception. + *

        + * If the unit is not a {@code ChronoUnit}, then the result of this method + * is obtained by invoking {@code TemporalUnit.between(Temporal, Temporal)} + * passing {@code this} as the first argument and the converted input temporal + * as the second argument. + *

        + * This instance is immutable and unaffected by this method call. + * + * @param endExclusive the end date, exclusive, which is converted to a {@code HourMinute}, not null + * @param unit the unit to measure the amount in, not null + * @return the amount of time between this hour-minute and the end hour-minute + * @throws DateTimeException if the amount cannot be calculated, or the end + * temporal cannot be converted to a {@code HourMinute} + * @throws UnsupportedTemporalTypeException if the unit is not supported + * @throws ArithmeticException if numeric overflow occurs + */ + @Override + public long until(Temporal endExclusive, TemporalUnit unit) { + HourMinute end = HourMinute.from(endExclusive); + long minutesUntil = (end.hour * MINUTES_PER_HOUR + end.minute) - (hour * MINUTES_PER_HOUR + minute); // no overflow + if (unit instanceof ChronoUnit) { + switch ((ChronoUnit) unit) { + case MINUTES: + return minutesUntil; + case HOURS: + return minutesUntil / MINUTES_PER_HOUR; + case HALF_DAYS: + return minutesUntil / (12 * MINUTES_PER_HOUR); + default: + throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); + } + } + return unit.between(this, end); + } + + /** + * Formats this hour-minute using the specified formatter. + *

        + * This hour-minute will be passed to the formatter to produce a string. + * + * @param formatter the formatter to use, not null + * @return the formatted hour-minute string, not null + * @throws DateTimeException if an error occurs during printing + */ + public String format(DateTimeFormatter formatter) { + Objects.requireNonNull(formatter, "formatter"); + return formatter.format(this); + } + + //----------------------------------------------------------------------- + /** + * Combines this time with a date to create a {@code LocalDateTime}. + *

        + * This returns a {@code LocalDateTime} formed from this time at the specified date. + * All possible combinations of date and time are valid. + * + * @param date the date to combine with, not null + * @return the local date-time formed from this time and the specified date, not null + */ + public LocalDateTime atDate(LocalDate date) { + return LocalDateTime.of(date, toLocalTime()); + } + + /** + * Combines this time with an offset to create an {@code OffsetTime}. + *

        + * This returns an {@code OffsetTime} formed from this time at the specified offset. + * All possible combinations of time and offset are valid. + * + * @param offset the offset to combine with, not null + * @return the offset time formed from this time and the specified offset, not null + */ + public OffsetTime atOffset(ZoneOffset offset) { + return OffsetTime.of(toLocalTime(), offset); + } + + //----------------------------------------------------------------------- + /** + * Returns the equivalent {@code LocalTime}. + *

        + * This returns a {@code LocalTime} formed from this hour and minute. + * + * @return the equivalent local time, not null + */ + public LocalTime toLocalTime() { + return LocalTime.of(hour, minute); + } + + //------------------------------------------------------------------------- + /** + * Compares this hour-minute to another + *

        + * The comparison is based first on the value of the hour, then on the value of the minute. + * It is "consistent with equals", as defined by {@link Comparable}. + * + * @param other the other hour-minute to compare to, not null + * @return the comparator value, negative if less, positive if greater + */ + @Override + public int compareTo(HourMinute other) { + int cmp = (hour - other.hour); + if (cmp == 0) { + cmp = (minute - other.minute); + } + return cmp; + } + + /** + * Is this hour-minute after the specified hour-minute. + * + * @param other the other hour-minute to compare to, not null + * @return true if this is after the specified hour-minute + */ + public boolean isAfter(HourMinute other) { + return compareTo(other) > 0; + } + + /** + * Is this hour-minute before the specified hour-minute. + * + * @param other the other hour-minute to compare to, not null + * @return true if this point is before the specified hour-minute + */ + public boolean isBefore(HourMinute other) { + return compareTo(other) < 0; + } + + //----------------------------------------------------------------------- + /** + * Checks if this hour-minute is equal to another hour-minute. + *

        + * The comparison is based on the time-line position of the hour-minute. + * + * @param obj the object to check, null returns false + * @return true if this is equal to the other hour-minute + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof HourMinute) { + HourMinute other = (HourMinute) obj; + return hour == other.hour && minute == other.minute; + } + return false; + } + + /** + * A hash code for this hour-minute. + * + * @return a suitable hash code + */ + @Override + public int hashCode() { + return hour * MINUTES_PER_HOUR + minute; + } + + //----------------------------------------------------------------------- + /** + * Outputs this hour-minute as a {@code String}, such as {@code 12:31}. + * + * @return a string representation of this hour-minute, not null + */ + @Override + @ToString + public String toString() { + return new StringBuilder(5) + .append(hour < 10 ? "0" : "").append(hour) + .append(minute < 10 ? ":0" : ":").append(minute) + .toString(); + } + +} diff --git a/src/test/java/org/threeten/extra/TestHourMinute.java b/src/test/java/org/threeten/extra/TestHourMinute.java new file mode 100644 index 00000000..e3376b1a --- /dev/null +++ b/src/test/java/org/threeten/extra/TestHourMinute.java @@ -0,0 +1,677 @@ +/* + * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of JSR-310 nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.threeten.extra; + +import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH; +import static java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR; +import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_MONTH; +import static java.time.temporal.ChronoField.ALIGNED_WEEK_OF_YEAR; +import static java.time.temporal.ChronoField.AMPM_OF_DAY; +import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_AMPM; +import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_DAY; +import static java.time.temporal.ChronoField.DAY_OF_MONTH; +import static java.time.temporal.ChronoField.DAY_OF_WEEK; +import static java.time.temporal.ChronoField.DAY_OF_YEAR; +import static java.time.temporal.ChronoField.EPOCH_DAY; +import static java.time.temporal.ChronoField.ERA; +import static java.time.temporal.ChronoField.HOUR_OF_AMPM; +import static java.time.temporal.ChronoField.HOUR_OF_DAY; +import static java.time.temporal.ChronoField.INSTANT_SECONDS; +import static java.time.temporal.ChronoField.MICRO_OF_DAY; +import static java.time.temporal.ChronoField.MICRO_OF_SECOND; +import static java.time.temporal.ChronoField.MILLI_OF_DAY; +import static java.time.temporal.ChronoField.MILLI_OF_SECOND; +import static java.time.temporal.ChronoField.MINUTE_OF_DAY; +import static java.time.temporal.ChronoField.MINUTE_OF_HOUR; +import static java.time.temporal.ChronoField.MONTH_OF_YEAR; +import static java.time.temporal.ChronoField.NANO_OF_DAY; +import static java.time.temporal.ChronoField.NANO_OF_SECOND; +import static java.time.temporal.ChronoField.OFFSET_SECONDS; +import static java.time.temporal.ChronoField.PROLEPTIC_MONTH; +import static java.time.temporal.ChronoField.SECOND_OF_DAY; +import static java.time.temporal.ChronoField.SECOND_OF_MINUTE; +import static java.time.temporal.ChronoField.YEAR; +import static java.time.temporal.ChronoField.YEAR_OF_ERA; +import static java.time.temporal.ChronoUnit.CENTURIES; +import static java.time.temporal.ChronoUnit.DAYS; +import static java.time.temporal.ChronoUnit.DECADES; +import static java.time.temporal.ChronoUnit.FOREVER; +import static java.time.temporal.ChronoUnit.HALF_DAYS; +import static java.time.temporal.ChronoUnit.HOURS; +import static java.time.temporal.ChronoUnit.MICROS; +import static java.time.temporal.ChronoUnit.MILLENNIA; +import static java.time.temporal.ChronoUnit.MILLIS; +import static java.time.temporal.ChronoUnit.MINUTES; +import static java.time.temporal.ChronoUnit.MONTHS; +import static java.time.temporal.ChronoUnit.NANOS; +import static java.time.temporal.ChronoUnit.SECONDS; +import static java.time.temporal.ChronoUnit.WEEKS; +import static java.time.temporal.ChronoUnit.YEARS; +import static java.time.temporal.IsoFields.DAY_OF_QUARTER; +import static java.time.temporal.IsoFields.QUARTER_OF_YEAR; +import static java.time.temporal.IsoFields.QUARTER_YEARS; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatNullPointerException; +import static org.threeten.extra.TemporalFields.DAY_OF_HALF; +import static org.threeten.extra.TemporalFields.HALF_OF_YEAR; +import static org.threeten.extra.TemporalFields.HALF_YEARS; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.time.DateTimeException; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetTime; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.temporal.Temporal; +import java.time.temporal.TemporalAccessor; +import java.time.temporal.TemporalAdjuster; +import java.time.temporal.TemporalField; +import java.time.temporal.TemporalQueries; +import java.time.temporal.TemporalUnit; +import java.time.temporal.UnsupportedTemporalTypeException; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import com.google.common.testing.EqualsTester; + +/** + * Test HourMinute. + */ +public class TestHourMinute { + + private static final HourMinute TEST = HourMinute.of(12, 31); + + //----------------------------------------------------------------------- + @Test + public void test_interfaces() { + assertThat(HourMinute.class) + .isAssignableTo(Serializable.class) + .isAssignableTo(Comparable.class) + .isAssignableTo(TemporalAdjuster.class) + .isAssignableTo(TemporalAccessor.class); + } + + @Test + public void test_serialization() throws IOException, ClassNotFoundException { + HourMinute test = HourMinute.of(12, 31); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { + oos.writeObject(test); + } + try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) { + assertThat(ois.readObject()).isEqualTo(test); + } + } + + //----------------------------------------------------------------------- + // of(int,int) / getters + //----------------------------------------------------------------------- + @Test + public void test_of_int_int() { + for (int hour = 0; hour <= 23; hour++) { + for (int minute = 0; minute <= 59; minute++) { + HourMinute test = HourMinute.of(hour, minute); + assertThat(test.getHour()).isEqualTo(hour); + assertThat(test.getMinute()).isEqualTo(minute); + assertThat(test) + .isEqualTo(HourMinute.of(hour, minute)) + .hasSameHashCodeAs(HourMinute.of(hour, minute)); + } + } + } + + @Test + public void test_of_int_int_invalid() { + assertThatExceptionOfType(DateTimeException.class).isThrownBy(() -> HourMinute.of(-1, 0)); + assertThatExceptionOfType(DateTimeException.class).isThrownBy(() -> HourMinute.of(24, 0)); + assertThatExceptionOfType(DateTimeException.class).isThrownBy(() -> HourMinute.of(1, -1)); + assertThatExceptionOfType(DateTimeException.class).isThrownBy(() -> HourMinute.of(1, 60)); + } + + //----------------------------------------------------------------------- + // from(TemporalAccessor) + //----------------------------------------------------------------------- + @Test + public void test_from_TemporalAccessor() { + for (int hour = 0; hour <= 23; hour++) { + for (int minute = 0; minute <= 59; minute++) { + HourMinute expected = HourMinute.of(hour, minute); + assertThat(HourMinute.from(expected)).isEqualTo(expected); + assertThat(HourMinute.from(LocalTime.of(hour, minute))).isEqualTo(expected); + assertThat(HourMinute.from(LocalDateTime.of(2020, 6, 3, hour, minute))).isEqualTo(expected); + } + } + assertThatExceptionOfType(DateTimeException.class).isThrownBy(() -> HourMinute.from(LocalDate.of(2020, 6, 3))); + assertThatNullPointerException().isThrownBy(() -> HourMinute.from((TemporalAccessor) null)); + } + + //----------------------------------------------------------------------- + // parse(CharSequence) + //----------------------------------------------------------------------- + static Object[][] data_parse_CharSequence() { + return new Object[][] { + {HourMinute.of(0, 0), "00:00"}, + {HourMinute.of(9, 9), "09:09"}, + {HourMinute.of(10, 10), "10:10"}, + {HourMinute.of(19, 59), "19:59"}, + {HourMinute.of(23, 59), "23:59"}, + }; + } + + @ParameterizedTest + @MethodSource("data_parse_CharSequence") + public void test_parse_CharSequence(HourMinute hourMin, String str) { + assertThat(HourMinute.parse(str)).isEqualTo(hourMin); + assertThat(hourMin).hasToString(str); + } + + @Test + public void test_parse_CharSequence_invalid() { + assertThatNullPointerException().isThrownBy(() -> HourMinute.parse((CharSequence) null)); + } + + //----------------------------------------------------------------------- + // parse(CharSequence,DateTimeFormatter) + //----------------------------------------------------------------------- + @Test + public void test_parse_CharSequenceDateTimeFormatter() { + assertThat(HourMinute.parse("23:30+01:00", DateTimeFormatter.ISO_OFFSET_TIME)).isEqualTo(HourMinute.of(23, 30)); + } + + @Test + public void test_parse_CharSequenceDateTimeFormatter_invalid() { + assertThatNullPointerException().isThrownBy(() -> HourMinute.parse((CharSequence) null, DateTimeFormatter.ISO_OFFSET_TIME)); + assertThatNullPointerException().isThrownBy(() -> HourMinute.parse("23:59", (DateTimeFormatter) null)); + } + + //----------------------------------------------------------------------- + // isSupported(TemporalField) + //----------------------------------------------------------------------- + @Test + public void test_isSupported_TemporalField() { + assertThat(TEST.isSupported((TemporalField) null)).isFalse(); + assertThat(TEST.isSupported(NANO_OF_SECOND)).isFalse(); + assertThat(TEST.isSupported(NANO_OF_DAY)).isFalse(); + assertThat(TEST.isSupported(MICRO_OF_SECOND)).isFalse(); + assertThat(TEST.isSupported(MICRO_OF_DAY)).isFalse(); + assertThat(TEST.isSupported(MILLI_OF_SECOND)).isFalse(); + assertThat(TEST.isSupported(MILLI_OF_DAY)).isFalse(); + assertThat(TEST.isSupported(SECOND_OF_MINUTE)).isFalse(); + assertThat(TEST.isSupported(SECOND_OF_DAY)).isFalse(); + assertThat(TEST.isSupported(MINUTE_OF_HOUR)).isTrue(); + assertThat(TEST.isSupported(MINUTE_OF_DAY)).isTrue(); + assertThat(TEST.isSupported(HOUR_OF_AMPM)).isTrue(); + assertThat(TEST.isSupported(CLOCK_HOUR_OF_AMPM)).isTrue(); + assertThat(TEST.isSupported(HOUR_OF_DAY)).isTrue(); + assertThat(TEST.isSupported(CLOCK_HOUR_OF_DAY)).isTrue(); + assertThat(TEST.isSupported(AMPM_OF_DAY)).isTrue(); + assertThat(TEST.isSupported(DAY_OF_WEEK)).isFalse(); + assertThat(TEST.isSupported(ALIGNED_DAY_OF_WEEK_IN_MONTH)).isFalse(); + assertThat(TEST.isSupported(ALIGNED_DAY_OF_WEEK_IN_YEAR)).isFalse(); + assertThat(TEST.isSupported(DAY_OF_MONTH)).isFalse(); + assertThat(TEST.isSupported(DAY_OF_YEAR)).isFalse(); + assertThat(TEST.isSupported(EPOCH_DAY)).isFalse(); + assertThat(TEST.isSupported(ALIGNED_WEEK_OF_MONTH)).isFalse(); + assertThat(TEST.isSupported(ALIGNED_WEEK_OF_YEAR)).isFalse(); + assertThat(TEST.isSupported(MONTH_OF_YEAR)).isFalse(); + assertThat(TEST.isSupported(PROLEPTIC_MONTH)).isFalse(); + assertThat(TEST.isSupported(YEAR_OF_ERA)).isFalse(); + assertThat(TEST.isSupported(YEAR)).isFalse(); + assertThat(TEST.isSupported(ERA)).isFalse(); + assertThat(TEST.isSupported(INSTANT_SECONDS)).isFalse(); + assertThat(TEST.isSupported(OFFSET_SECONDS)).isFalse(); + assertThat(TEST.isSupported(QUARTER_OF_YEAR)).isFalse(); + assertThat(TEST.isSupported(DAY_OF_QUARTER)).isFalse(); + assertThat(TEST.isSupported(HALF_OF_YEAR)).isFalse(); + assertThat(TEST.isSupported(DAY_OF_HALF)).isFalse(); + } + + //----------------------------------------------------------------------- + // isSupported(TemporalUnit) + //----------------------------------------------------------------------- + @Test + public void test_isSupported_TemporalUnit() { + assertThat(TEST.isSupported((TemporalUnit) null)).isFalse(); + assertThat(TEST.isSupported(NANOS)).isFalse(); + assertThat(TEST.isSupported(MICROS)).isFalse(); + assertThat(TEST.isSupported(MILLIS)).isFalse(); + assertThat(TEST.isSupported(SECONDS)).isFalse(); + assertThat(TEST.isSupported(MINUTES)).isTrue(); + assertThat(TEST.isSupported(HOURS)).isTrue(); + assertThat(TEST.isSupported(HALF_DAYS)).isTrue(); + assertThat(TEST.isSupported(DAYS)).isFalse(); + assertThat(TEST.isSupported(WEEKS)).isFalse(); + assertThat(TEST.isSupported(MONTHS)).isFalse(); + assertThat(TEST.isSupported(YEARS)).isFalse(); + assertThat(TEST.isSupported(DECADES)).isFalse(); + assertThat(TEST.isSupported(CENTURIES)).isFalse(); + assertThat(TEST.isSupported(MILLENNIA)).isFalse(); + assertThat(TEST.isSupported(ERA)).isFalse(); + assertThat(TEST.isSupported(FOREVER)).isFalse(); + assertThat(TEST.isSupported(QUARTER_YEARS)).isFalse(); + assertThat(TEST.isSupported(HALF_YEARS)).isFalse(); + } + + //----------------------------------------------------------------------- + // range(TemporalField) + //----------------------------------------------------------------------- + @Test + public void test_range() { + assertThat(TEST.range(MINUTE_OF_HOUR)).isEqualTo(MINUTE_OF_HOUR.range()); + assertThat(TEST.range(MINUTE_OF_DAY)).isEqualTo(MINUTE_OF_DAY.range()); + assertThat(TEST.range(HOUR_OF_DAY)).isEqualTo(HOUR_OF_DAY.range()); + assertThat(TEST.range(CLOCK_HOUR_OF_DAY)).isEqualTo(CLOCK_HOUR_OF_DAY.range()); + assertThat(TEST.range(HOUR_OF_AMPM)).isEqualTo(HOUR_OF_AMPM.range()); + assertThat(TEST.range(CLOCK_HOUR_OF_AMPM)).isEqualTo(CLOCK_HOUR_OF_AMPM.range()); + assertThat(TEST.range(AMPM_OF_DAY)).isEqualTo(AMPM_OF_DAY.range()); + } + + @Test + public void test_range_invalid() { + assertThatExceptionOfType(UnsupportedTemporalTypeException.class).isThrownBy(() -> TEST.range(SECOND_OF_MINUTE)); + assertThatExceptionOfType(UnsupportedTemporalTypeException.class).isThrownBy(() -> TEST.range(NANO_OF_SECOND)); + assertThatNullPointerException().isThrownBy(() -> TEST.range((TemporalField) null)); + } + + //----------------------------------------------------------------------- + // get(TemporalField) + //----------------------------------------------------------------------- + @Test + public void test_get() { + assertThat(TEST.get(MINUTE_OF_HOUR)).isEqualTo(31); + assertThat(TEST.get(MINUTE_OF_DAY)).isEqualTo(12 * 60 + 31); + assertThat(TEST.get(HOUR_OF_DAY)).isEqualTo(12); + assertThat(TEST.get(CLOCK_HOUR_OF_DAY)).isEqualTo(12); + assertThat(TEST.get(HOUR_OF_AMPM)).isEqualTo(0); + assertThat(TEST.get(CLOCK_HOUR_OF_AMPM)).isEqualTo(12); + assertThat(TEST.get(AMPM_OF_DAY)).isEqualTo(1); + } + + @Test + public void test_get_invalid() { + assertThatExceptionOfType(UnsupportedTemporalTypeException.class).isThrownBy(() -> TEST.get(SECOND_OF_MINUTE)); + assertThatExceptionOfType(UnsupportedTemporalTypeException.class).isThrownBy(() -> TEST.get(NANO_OF_SECOND)); + assertThatNullPointerException().isThrownBy(() -> TEST.get((TemporalField) null)); + } + + //----------------------------------------------------------------------- + // getLong(TemporalField) + //----------------------------------------------------------------------- + @Test + public void test_getLong() { + assertThat(TEST.getLong(MINUTE_OF_HOUR)).isEqualTo(31); + assertThat(TEST.getLong(MINUTE_OF_DAY)).isEqualTo(12 * 60 + 31); + assertThat(TEST.getLong(HOUR_OF_DAY)).isEqualTo(12); + assertThat(TEST.getLong(CLOCK_HOUR_OF_DAY)).isEqualTo(12); + assertThat(TEST.getLong(HOUR_OF_AMPM)).isEqualTo(0); + assertThat(TEST.getLong(CLOCK_HOUR_OF_AMPM)).isEqualTo(12); + assertThat(TEST.getLong(AMPM_OF_DAY)).isEqualTo(1); + } + + @Test + public void test_getLong_invalid() { + assertThatExceptionOfType(UnsupportedTemporalTypeException.class).isThrownBy(() -> TEST.getLong(SECOND_OF_MINUTE)); + assertThatExceptionOfType(UnsupportedTemporalTypeException.class).isThrownBy(() -> TEST.getLong(NANO_OF_SECOND)); + assertThatNullPointerException().isThrownBy(() -> TEST.getLong((TemporalField) null)); + } + + //----------------------------------------------------------------------- + // with(TemporalAdjuster) + //----------------------------------------------------------------------- + @Test + public void test_with_TemporalAdjuster() { + assertThat(TEST.with(HourMinute.of(9, 10))).isEqualTo(HourMinute.of(9, 10)); + assertThat(TEST.with(AmPm.AM)).isEqualTo(HourMinute.of(0, 31)); + } + + @Test + public void test_with_TemporalAdjuster_invalid() { + assertThatExceptionOfType(UnsupportedTemporalTypeException.class).isThrownBy(() -> TEST.with(LocalTime.of(9, 10, 11))); + assertThatNullPointerException().isThrownBy(() -> TEST.with((TemporalAdjuster) null)); + } + + //----------------------------------------------------------------------- + // with(TemporalField, long) + //----------------------------------------------------------------------- + @Test + public void test_with_TemporalFieldlong() { + assertThat(TEST.with(MINUTE_OF_HOUR, 2)).isEqualTo(HourMinute.of(12, 2)); + assertThat(TEST.with(MINUTE_OF_DAY, 2)).isEqualTo(HourMinute.of(0, 2)); + assertThat(TEST.with(HOUR_OF_DAY, 2)).isEqualTo(HourMinute.of(2, 31)); + assertThat(TEST.with(CLOCK_HOUR_OF_DAY, 2)).isEqualTo(HourMinute.of(2, 31)); + assertThat(TEST.with(HOUR_OF_AMPM, 2)).isEqualTo(HourMinute.of(14, 31)); + assertThat(TEST.with(CLOCK_HOUR_OF_AMPM, 2)).isEqualTo(HourMinute.of(14, 31)); + assertThat(TEST.with(AMPM_OF_DAY, 0)).isEqualTo(HourMinute.of(0, 31)); + } + + @Test + public void test_with_TemporalFieldlong_invalid() { + assertThatExceptionOfType(UnsupportedTemporalTypeException.class).isThrownBy(() -> TEST.with(SECOND_OF_MINUTE, 1)); + assertThatExceptionOfType(UnsupportedTemporalTypeException.class).isThrownBy(() -> TEST.with(NANO_OF_SECOND, 1)); + assertThatNullPointerException().isThrownBy(() -> TEST.with((TemporalField) null, 1)); + } + + //----------------------------------------------------------------------- + // withHour(int) / withMinute(int) + //----------------------------------------------------------------------- + @Test + public void test_with_int() { + assertThat(TEST.withHour(9)).isEqualTo(HourMinute.of(9, 31)); + assertThat(TEST.withMinute(9)).isEqualTo(HourMinute.of(12, 9)); + } + + @Test + public void test_with_int_invalid() { + assertThatExceptionOfType(DateTimeException.class).isThrownBy(() -> TEST.withHour(-1)); + assertThatExceptionOfType(DateTimeException.class).isThrownBy(() -> TEST.withHour(24)); + assertThatExceptionOfType(DateTimeException.class).isThrownBy(() -> TEST.withMinute(-1)); + assertThatExceptionOfType(DateTimeException.class).isThrownBy(() -> TEST.withMinute(60)); + } + + //----------------------------------------------------------------------- + // plus(TemporalAmount) + //----------------------------------------------------------------------- + @Test + public void test_plus_TemporalAmount() { + assertThat(TEST.plus(Hours.of(3))).isEqualTo(HourMinute.of(15, 31)); + assertThat(TEST.plus(Minutes.of(3))).isEqualTo(HourMinute.of(12, 34)); + } + + @Test + public void test_plus_TemporalAmount_invalid() { + assertThatExceptionOfType(DateTimeException.class).isThrownBy(() -> TEST.plus(Days.of(1))); + assertThatExceptionOfType(DateTimeException.class).isThrownBy(() -> TEST.plus(Seconds.of(3))); + assertThatNullPointerException().isThrownBy(() -> TEST.plus(null)); + } + + //----------------------------------------------------------------------- + // plus(long,TemporalUnit) + //----------------------------------------------------------------------- + @Test + public void test_plus_longTemporalUnit() { + assertThat(TEST.plus(3, HOURS)).isEqualTo(HourMinute.of(15, 31)); + assertThat(TEST.plus(3, MINUTES)).isEqualTo(HourMinute.of(12, 34)); + assertThat(TEST.plus(1, HALF_DAYS)).isEqualTo(HourMinute.of(0, 31)); + } + + @Test + public void test_plus_longTemporalUnit_invalid() { + assertThatExceptionOfType(DateTimeException.class).isThrownBy(() -> TEST.plus(1, DAYS)); + assertThatExceptionOfType(DateTimeException.class).isThrownBy(() -> TEST.plus(1, SECONDS)); + assertThatNullPointerException().isThrownBy(() -> TEST.plus(1, null)); + } + + //----------------------------------------------------------------------- + // plusHours(int) / plusMinutes(int) + //----------------------------------------------------------------------- + @Test + public void test_plus_int() { + assertThat(TEST.plusHours(3)).isEqualTo(HourMinute.of(15, 31)); + assertThat(TEST.plusMinutes(3)).isEqualTo(HourMinute.of(12, 34)); + assertThat(TEST.plusHours(-15)).isEqualTo(HourMinute.of(21, 31)); + assertThat(TEST.plusHours(25)).isEqualTo(HourMinute.of(13, 31)); + } + + //----------------------------------------------------------------------- + // minus(TemporalAmount) + //----------------------------------------------------------------------- + @Test + public void test_minus_TemporalAmount() { + assertThat(TEST.minus(Hours.of(3))).isEqualTo(HourMinute.of(9, 31)); + assertThat(TEST.minus(Minutes.of(3))).isEqualTo(HourMinute.of(12, 28)); + } + + @Test + public void test_minus_TemporalAmount_invalid() { + assertThatExceptionOfType(DateTimeException.class).isThrownBy(() -> TEST.minus(Days.of(1))); + assertThatExceptionOfType(DateTimeException.class).isThrownBy(() -> TEST.minus(Seconds.of(3))); + assertThatNullPointerException().isThrownBy(() -> TEST.minus(null)); + } + + //----------------------------------------------------------------------- + // minus(long,TemporalUnit) + //----------------------------------------------------------------------- + @Test + public void test_minus_longTemporalUnit() { + assertThat(TEST.minus(3, HOURS)).isEqualTo(HourMinute.of(9, 31)); + assertThat(TEST.minus(3, MINUTES)).isEqualTo(HourMinute.of(12, 28)); + assertThat(TEST.minus(1, HALF_DAYS)).isEqualTo(HourMinute.of(0, 31)); + } + + @Test + public void test_minus_longTemporalUnit_invalid() { + assertThatExceptionOfType(DateTimeException.class).isThrownBy(() -> TEST.minus(1, DAYS)); + assertThatExceptionOfType(DateTimeException.class).isThrownBy(() -> TEST.minus(1, SECONDS)); + assertThatNullPointerException().isThrownBy(() -> TEST.minus(1, null)); + } + + //----------------------------------------------------------------------- + // minusHours(int) / minusMinutes(int) + //----------------------------------------------------------------------- + @Test + public void test_minus_int() { + assertThat(TEST.minusHours(3)).isEqualTo(HourMinute.of(9, 31)); + assertThat(TEST.minusMinutes(3)).isEqualTo(HourMinute.of(12, 28)); + assertThat(TEST.minusHours(-15)).isEqualTo(HourMinute.of(3, 31)); + assertThat(TEST.minusHours(25)).isEqualTo(HourMinute.of(11, 31)); + } + + //----------------------------------------------------------------------- + // query(TemporalQuery) + //----------------------------------------------------------------------- + @Test + public void test_query() { + assertThat(TEST.query(TemporalQueries.chronology())).isNull(); + assertThat(TEST.query(TemporalQueries.localDate())).isNull(); + assertThat(TEST.query(TemporalQueries.localTime())).isEqualTo(LocalTime.of(12, 31)); + assertThat(TEST.query(TemporalQueries.offset())).isNull(); + assertThat(TEST.query(TemporalQueries.precision())).isEqualTo(MINUTES); + assertThat(TEST.query(TemporalQueries.zone())).isNull(); + assertThat(TEST.query(TemporalQueries.zoneId())).isNull(); + } + + //----------------------------------------------------------------------- + // adjustInto(Temporal) + //----------------------------------------------------------------------- + @Test + public void test_adjustInto_Temporal() { + assertThat(TEST.adjustInto(LocalDateTime.of(2020, 6, 3, 2, 4, 6))).isEqualTo(LocalDateTime.of(2020, 6, 3, 12, 31, 6)); + } + + @Test + public void test_adjustInto_Temporal_invalid() { + assertThatNullPointerException().isThrownBy(() -> TEST.adjustInto((Temporal) null)); + } + + //----------------------------------------------------------------------- + // until(Temporal,TemporalUnit) + //----------------------------------------------------------------------- + static Object[][] data_until_TemporalTemporalUnit() { + return new Object[][] { + {HourMinute.of(12, 31), 0, 0}, + {HourMinute.of(12, 32), 0, 1}, + {HourMinute.of(13, 30), 0, 59}, + {HourMinute.of(13, 31), 1, 60}, + {HourMinute.of(13, 32), 1, 61}, + {HourMinute.of(12, 30), 0, -1}, + {HourMinute.of(11, 31), -1, -60}, + }; + } + + @ParameterizedTest + @MethodSource("data_until_TemporalTemporalUnit") + public void test_until_TemporalTemporalUnit(HourMinute target, int expectedHours, int expectedMins) { + assertThat(TEST.until(target, HOURS)).isEqualTo(expectedHours); + assertThat(TEST.until(target, MINUTES)).isEqualTo(expectedMins); + } + + @Test + public void test_until_TemporalTemporalUnit_invalid() { + assertThatExceptionOfType(DateTimeException.class).isThrownBy(() -> TEST.until(HourMinute.of(0, 0), DAYS)); + assertThatExceptionOfType(DateTimeException.class).isThrownBy(() -> TEST.until(HourMinute.of(0, 0), SECONDS)); + assertThatNullPointerException().isThrownBy(() -> TEST.until(null, HOURS)); + assertThatNullPointerException().isThrownBy(() -> TEST.until(HourMinute.of(0, 0), null)); + } + + //----------------------------------------------------------------------- + // format(DateTimeFormatter) + //----------------------------------------------------------------------- + @Test + public void test_format() { + DateTimeFormatter f = new DateTimeFormatterBuilder() + .appendLiteral("Hour ") + .appendValue(HOUR_OF_DAY) + .appendLiteral(" Minute ") + .appendValue(MINUTE_OF_HOUR) + .toFormatter(); + assertThat(TEST.format(f)).isEqualTo("Hour 12 Minute 31"); + } + + @Test + public void test_format_null() { + assertThatNullPointerException().isThrownBy(() -> TEST.format(null)); + } + + //----------------------------------------------------------------------- + // atDate(LocalDate) + //----------------------------------------------------------------------- + @Test + public void test_atDate_LocalDate() { + LocalDate date = LocalDate.of(2020, 6, 3); + assertThat(TEST.atDate(date)).isEqualTo(LocalDateTime.of(date, LocalTime.of(12, 31))); + } + + @Test + public void test_atDate_LocalDate_invalid() { + assertThatNullPointerException().isThrownBy(() -> TEST.atDate(null)); + } + + //----------------------------------------------------------------------- + // atOffset(ZoneOffset) + //----------------------------------------------------------------------- + @Test + public void test_atOffset_ZoneOffset() { + ZoneOffset offset = ZoneOffset.ofHours(2); + assertThat(TEST.atOffset(offset)).isEqualTo(OffsetTime.of(LocalTime.of(12, 31), offset)); + } + + @Test + public void test_atOffset_ZoneOffset_invalid() { + assertThatNullPointerException().isThrownBy(() -> TEST.atOffset(null)); + } + + //----------------------------------------------------------------------- + // toLocalTime() + //----------------------------------------------------------------------- + @Test + public void test_toLocalTime() { + assertThat(TEST.toLocalTime()).isEqualTo(LocalTime.of(12, 31)); + } + + //----------------------------------------------------------------------- + // compareTo() + //----------------------------------------------------------------------- + @Test + public void test_compareTo() { + for (int hour1 = 0; hour1 <= 23; hour1++) { + for (int minute1 = 0; minute1 <= 59; minute1++) { + HourMinute a = HourMinute.of(hour1, minute1); + for (int hour2 = 0; hour2 <= 23; hour2++) { + for (int minute2 = 0; minute2 <= 59; minute2++) { + HourMinute b = HourMinute.of(hour2, minute2); + if (hour1 < hour2 || (hour1 == hour2 && minute1 < minute2)) { + assertThat(a).isLessThan(b); + assertThat(b).isGreaterThan(a); + assertThat(a.isAfter(b)).isFalse(); + assertThat(a.isBefore(b)).isTrue(); + assertThat(b.isAfter(a)).isTrue(); + assertThat(b.isBefore(a)).isFalse(); + } else if (hour1 > hour2 || (hour1 == hour2 && minute1 > minute2)) { + assertThat(a).isGreaterThan(b); + assertThat(b).isLessThan(a); + assertThat(a.isAfter(b)).isTrue(); + assertThat(a.isBefore(b)).isFalse(); + assertThat(b.isAfter(a)).isFalse(); + assertThat(b.isBefore(a)).isTrue(); + } else { + assertThat(a).isEqualByComparingTo(b); + assertThat(b).isEqualByComparingTo(a); + assertThat(a.isAfter(b)).isFalse(); + assertThat(a.isBefore(b)).isFalse(); + assertThat(b.isAfter(a)).isFalse(); + assertThat(b.isBefore(a)).isFalse(); + } + } + } + } + } + } + + @Test + public void test_compareTo_nullHourMinute() { + assertThatNullPointerException().isThrownBy(() -> TEST.compareTo(null)); + } + + //----------------------------------------------------------------------- + // equals() / hashCode() + //----------------------------------------------------------------------- + @Test + public void test_equals_and_hashCode() { + new EqualsTester() + .addEqualityGroup(HourMinute.of(1, 5), HourMinute.of(1, 5)) + .addEqualityGroup(HourMinute.of(14, 43), HourMinute.of(14, 43)) + .testEquals(); + } + + //----------------------------------------------------------------------- + // toString() + //----------------------------------------------------------------------- + @Test + public void test_toString() { + assertThat(HourMinute.of(0, 0)).hasToString("00:00"); + assertThat(HourMinute.of(0, 5)).hasToString("00:05"); + assertThat(HourMinute.of(9, 0)).hasToString("09:00"); + assertThat(HourMinute.of(23, 59)).hasToString("23:59"); + } + +} From 9d82587d2e51ebbf1e4d03c71e0562eefd7d122d Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Wed, 20 Dec 2023 11:05:09 +0000 Subject: [PATCH 274/279] Update docs for release --- pom.xml | 4 ++++ src/changes/changes.xml | 11 +++++++++++ src/site/markdown/index.md | 2 ++ 3 files changed, 17 insertions(+) diff --git a/pom.xml b/pom.xml index 646798b9..af3dd813 100644 --- a/pom.xml +++ b/pom.xml @@ -142,6 +142,10 @@ Tristan Swadell https://github.com/TristonianJones + + Roberto Tyley + https://github.com/rtyley + Dimo Velev https://github.com/dimovelev diff --git a/src/changes/changes.xml b/src/changes/changes.xml index dab6a9b5..c0398c7d 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,6 +7,17 @@ + + + Add HourMinute. New class representing time but constrained to hours and minutes only. + + + Add YearHalf. New class representing a half-year, such as 2024-H1. + + + Add Interval.of(duration, end), providing another way to create an interval. + + Adds offset for AccountingChronology, which is essential for some retail calendars, particularly the NRF. diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index bc23ba3f..b273cdb3 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -21,7 +21,9 @@ The following features are included: * [`Quarter`](apidocs/org.threeten.extra/org/threeten/extra/Quarter.html) - the four quarters, Q1, Q2, Q3 and Q4 * [`YearQuarter`](apidocs/org.threeten.extra/org/threeten/extra/YearQuarter.html) - combines year and quarter, 2014-Q4 * [`YearWeek`](apidocs/org.threeten.extra/org/threeten/extra/YearWeek.html) - a week in a week-based-year, 2014-W06 +* [`YearHalf`](apidocs/org.threeten.extra/org/threeten/extra/YearHalf.html) - a half-year, 2014-H1 * [`OffsetDate`](apidocs/org.threeten.extra/org/threeten/extra/OffsetDate.html) - combines `LocalDate` and `ZoneOffset` +* [`HourMinute`](apidocs/org.threeten.extra/org/threeten/extra/HourMinute.html) - time to minute precision, 10:24 * [`Seconds`](apidocs/org.threeten.extra/org/threeten/extra/Seconds.html), [`Minutes`](apidocs/org.threeten.extra/org/threeten/extra/Minutes.html), [`Hours`](apidocs/org.threeten.extra/org/threeten/extra/Hours.html), From 8dbbfab69b41bcc8db6ef9d8b3b165d62c2a6533 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 16 Apr 2024 22:37:40 +0100 Subject: [PATCH 275/279] Update dependency versions and pom.xml --- pom.xml | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index af3dd813..534e4efb 100644 --- a/pom.xml +++ b/pom.xml @@ -197,7 +197,7 @@ org.jacoco jacoco-maven-plugin - + org.apache.maven.plugins maven-enforcer-plugin @@ -210,7 +210,7 @@ - 3.5.0 + 3.6.0 @@ -919,9 +919,9 @@ https://oss.sonatype.org/ sonatype-joda-staging - Releasing ${project.groupId}:${project.artifactId}:${project.version} true true + 20 @@ -938,38 +938,38 @@ 1.9.1 32.1.3-jre - 3.4.2 + 3.7.1 5.1.8 2.12.1 3.2.0 - 3.2.0 - 3.10.1 - 3.0.0 - 3.4.0 - 3.1.0 - 3.0.1 + 3.3.2 + 3.13.0 + 3.1.1 + 3.6.1 + 3.4.1 + 3.2.3 3.1.0 3.3.0 - 3.4.1 + 3.6.3 3.3.0 - 3.7.0 - 3.19.0 - 3.4.1 - 2.5.3 + 3.12.0 + 3.21.2 + 3.5.0 + 3.0.1 2.4 - 3.3.0 + 3.3.1 3.12.1 3.2.1 - 3.0.0-M7 - 3.0.0-M7 + 3.2.5 + 3.2.5 3.1.0 - 1.314 + 1.321 1.4.0 - 0.8.8 + 0.8.12 1.6.13 1.2 - 4.7.3.0 + 4.8.4.0 1.8 1.8 From eebb5cbab7cbdd287fab30315284b55691c970b8 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 16 Apr 2024 22:39:09 +0100 Subject: [PATCH 276/279] Prepare for release --- README.md | 4 ++-- pom.xml | 2 +- src/changes/changes.xml | 2 +- src/site/markdown/index.md | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c286bae8..12a4219b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Various documentation is available: ### Releases -Release 1.7.2 is the current release. +Release 1.8.0 is the current release. This release is considered stable and worthy of the 1.x tag as per [SemVer](https://semver.org/spec/v2.0.0.html). ThreeTen-Extra requires Java SE 8 or later and has no dependencies. @@ -28,7 +28,7 @@ Available in the [Maven Central repository](https://search.maven.org/search?q=g: org.threeten threeten-extra - 1.7.2 + 1.8.0 ``` diff --git a/pom.xml b/pom.xml index 534e4efb..ea4ca6c8 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.7.3-SNAPSHOT + 1.8.0-SNAPSHOT Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later https://www.threeten.org/threeten-extra diff --git a/src/changes/changes.xml b/src/changes/changes.xml index c0398c7d..359abbc3 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,7 +7,7 @@ - + Add HourMinute. New class representing time but constrained to hours and minutes only. diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index b273cdb3..f77158c0 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -54,7 +54,7 @@ Various documentation is available: ## Releases -Release 1.7.2 is the current release. +Release 1.8.0 is the current release. This release is considered stable and worthy of the 1.x tag as per [SemVer](https://semver.org/spec/v2.0.0.html). ThreeTen-Extra requires Java SE 8 or later and has no [dependencies](dependencies.html). @@ -65,7 +65,7 @@ Available in [Maven Central](https://search.maven.org/search?q=g:org.threeten%20 org.threeten threeten-extra - 1.7.2 + 1.8.0 ``` From 583ef319e8ee09c0799b9d5cac4a779fd7f9fd99 Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 16 Apr 2024 22:49:16 +0100 Subject: [PATCH 277/279] [maven-release-plugin] prepare release v1.8.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index ea4ca6c8..4ec652f6 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.8.0-SNAPSHOT + 1.8.0 Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later https://www.threeten.org/threeten-extra @@ -164,7 +164,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git https://github.com/ThreeTen/threeten-extra - HEAD + v1.8.0 ThreeTen.org From 51679d62e430bffca7c2e47e33a7f5abd098003c Mon Sep 17 00:00:00 2001 From: Stephen Colebourne Date: Tue, 16 Apr 2024 22:49:21 +0100 Subject: [PATCH 278/279] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 4ec652f6..d1212e81 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ threeten-extra jar ThreeTen-Extra - 1.8.0 + 1.8.1-SNAPSHOT Additional functionality that enhances JSR-310 dates and times in Java SE 8 and later https://www.threeten.org/threeten-extra @@ -164,7 +164,7 @@ scm:git:https://github.com/ThreeTen/threeten-extra.git scm:git:https://github.com/ThreeTen/threeten-extra.git https://github.com/ThreeTen/threeten-extra - v1.8.0 + HEAD ThreeTen.org From 4e016340b97cab604114d10e02a672c1e94c6be5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 18 Apr 2024 10:09:36 +0100 Subject: [PATCH 279/279] Bump org.apache.maven.plugins:maven-jar-plugin from 3.3.0 to 3.4.0 (#344) Bumps [org.apache.maven.plugins:maven-jar-plugin](https://github.com/apache/maven-jar-plugin) from 3.3.0 to 3.4.0. - [Release notes](https://github.com/apache/maven-jar-plugin/releases) - [Commits](https://github.com/apache/maven-jar-plugin/compare/maven-jar-plugin-3.3.0...maven-jar-plugin-3.4.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-jar-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d1212e81..84075d26 100644 --- a/pom.xml +++ b/pom.xml @@ -949,7 +949,7 @@ 3.4.1 3.2.3 3.1.0 - 3.3.0 + 3.4.0 3.6.3 3.3.0 3.12.0