Skip to content

Commit

Permalink
rename within(Duration) to withMarginOf(Duration)
Browse files Browse the repository at this point in the history
  • Loading branch information
joel-costigliola committed Oct 20, 2020
1 parent 5e5c338 commit a8851f8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/main/java/org/assertj/core/api/AbstractDurationAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public SELF hasDays(long otherDays) {
* <p>
* This is equivalent of: {@code abs(actual - expected) <= allowed difference}.
* <p>
* For readability you can use {@link Assertions#within(java.math.BigDecimal)} to express the allowed difference.
* For readability you can use {@link Assertions#withMarginOf(Duration)} to express the allowed difference.
* <p>
* Examples:
* <pre><code class='java'> Duration twoMinutes = Duration.ofMinutes(2);
Expand All @@ -270,12 +270,12 @@ public SELF hasDays(long otherDays) {
* assertThat(twoMinutes).isCloseTo(Duration.ofMinutes(-3), Duration.ofMinutes(5));
*
* // assertions using within syntactic sugar
* assertThat(twoMinutes).isCloseTo(Duration.ofMinutes(3), within(Duration.ofMinutes(5)));
* assertThat(twoMinutes).isCloseTo(Duration.ofMinutes(3), within(Duration.ofMinutes(1)));
* assertThat(twoMinutes).isCloseTo(Duration.ofMinutes(3), withMarginOf(Duration.ofMinutes(5)));
* assertThat(twoMinutes).isCloseTo(Duration.ofMinutes(3), withMarginOf(Duration.ofMinutes(1)));
*
* // assertions fail
* assertThat(twoMinutes).isCloseTo(Duration.ofMinutes(5), within(Duration.ofMinutes(1)));
* assertThat(twoMinutes).isCloseTo(Duration.ofMinutes(-3), within(Duration.ofMinutes(4)));</code></pre>
* assertThat(twoMinutes).isCloseTo(Duration.ofMinutes(5), withMarginOf(Duration.ofMinutes(1)));
* assertThat(twoMinutes).isCloseTo(Duration.ofMinutes(-3), withMarginOf(Duration.ofMinutes(4)));</code></pre>
*
* @param expected the given {@link Duration} to compare to actual.
* @param allowedDifference a positive {@link Duration} to express the maximum allowed difference.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/assertj/core/api/Assertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1945,12 +1945,12 @@ public static TemporalUnitOffset within(long value, TemporalUnit unit) {
* Syntactic sugar method to use with {@link AbstractDurationAssert#isCloseTo(Duration, Duration)} assertion.
* <p>
* Example:
* <pre><code class='java'> assertThat(Duration.ofMinutes(2)).isCloseTo(Duration.ofMinutes(3), within(Duration.ofMinutes(1)));</code></pre>
* <pre><code class='java'> assertThat(Duration.ofMinutes(2)).isCloseTo(Duration.ofMinutes(3), withMarginOf(Duration.ofMinutes(1)));</code></pre>
*
* @param allowedDifference the allowed difference {@link Duration}.
* @return the given value.
*/
public static Duration within(Duration allowedDifference) {
public static Duration withMarginOf(Duration allowedDifference) {
return allowedDifference;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/assertj/core/api/WithAssertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -1546,12 +1546,12 @@ default TemporalUnitOffset within(long value, TemporalUnit unit) {
* Syntactic sugar method to use with {@link AbstractDurationAssert#isCloseTo(Duration, Duration)} assertion.
* <p>
* Example:
* <pre><code class='java'> assertThat(Duration.ofMinutes(2)).isCloseTo(Duration.ofMinutes(3), within(Duration.ofMinutes(1)));</code></pre>
* <pre><code class='java'> assertThat(Duration.ofMinutes(2)).isCloseTo(Duration.ofMinutes(3), withMarginOf(Duration.ofMinutes(1)));</code></pre>
*
* @param allowedDifference the allowed difference {@link Duration}.
* @return the given value.
*/
default Duration within(Duration allowedDifference) {
default Duration withMarginOf(Duration allowedDifference) {
return allowedDifference;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
package org.assertj.core.api.duration;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.within;
import static org.assertj.core.api.Assertions.withMarginOf;
import static org.assertj.core.api.BDDAssertions.then;
import static org.assertj.core.api.BDDAssertions.thenIllegalArgumentException;
import static org.assertj.core.error.ShouldBeCloseTo.shouldBeCloseTo;
Expand All @@ -31,7 +31,7 @@
@DisplayName("DurationAssert isCloseTo")
class DurationAssert_isCloseTo_Test {

@ParameterizedTest(name = "PT2M should close to {0} within {1}")
@ParameterizedTest(name = "PT2M should close to {0} withMarginOf {1}")
@CsvSource({
"PT1M, PT70S",
"PT70S, PT1M",
Expand All @@ -51,10 +51,10 @@ void should_pass_if_close_enough_to_the_given_duration(Duration expected, Durati
Duration actual = Duration.ofMinutes(2);
// WHEN/THEN
assertThat(actual).isCloseTo(expected, allowedDifference)
.isCloseTo(expected, within(allowedDifference));
.isCloseTo(expected, withMarginOf(allowedDifference));
}

@ParameterizedTest(name = "PT2M should not be close to {0} within {1}")
@ParameterizedTest(name = "PT2M should not be close to {0} withMarginOf {1}")
@CsvSource({
"PT1M, PT10S, PT1M",
"PT59S, PT1M, PT1M1S",
Expand Down

0 comments on commit a8851f8

Please sign in to comment.