Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void date_assertions_comparison_with_precision_level() {
Date date5 = parseDatetimeWithMs("2003-01-01T05:55:55.555");

assertThat(date1)
.isEqualToIgnoringMillis(date2)
.isCloseTo(date2, 1000L)
.isInSameSecondAs(date2)
.isEqualToIgnoringSeconds(date3)
.isInSameMinuteAs(date3)
Expand All @@ -114,7 +114,7 @@ public void date_assertions_comparison_with_precision_level() {
.isInSameDayAs(date5);

try {
assertThat(date1).isEqualToIgnoringMillis(date3);
assertThat(date1).isCloseTo(date3, 1000L);
} catch (AssertionError e) {
logAssertionErrorMessage("isEqualToIgnoringMillis", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ public void big_decimals_assertions_examples() {

@Test
public void number_assertions_with_offset_examples() {
assertThat(8.1).isEqualTo(8.0, offset(0.1));
assertThat(8.1f).isEqualTo(8.2f, offset(0.1f));
assertThat(8.1).isCloseTo(8.0, offset(0.1));
assertThat(8.1f).isCloseTo(8.2f, offset(0.1f));
try {
assertThat(8.1f).isEqualTo(8.0f, offset(0.1f));
assertThat(8.1f).isCloseTo(8.0f, offset(0.1f));
} catch (AssertionError e) {
logAssertionErrorMessage("float isEqualTo with offset", e);
}
Expand Down Expand Up @@ -198,12 +198,12 @@ public void number_assertions_with_offset_examples() {
assertThat(8.1f)
.isEqualTo(8.0f, within(0.2f))
.isEqualTo(8.0f, offset(0.2f))
// alias of within
.isEqualTo(8.0f, byLessThan(0.2f)); assertThat(0.1f)
.isCloseTo(8.0f, byLessThan(0.2f));
assertThat(0.1f)
// strict
// assertions succeed when the difference == offset value ...
.isCloseTo(0.0f, within(0.1f))
.isEqualTo(0.0f, within(0.1f));
.isCloseTo(0.0f, within(0.1f));

assertThat(8.1f)
.isNotCloseTo(8.0f, byLessThan(0.01f))
Expand All @@ -215,23 +215,23 @@ public void number_assertions_with_offset_examples() {
assertThat(8.1f)
.isEqualTo(8.0f, within(0.2f))
.isEqualTo(8.0f, offset(0.2f))
// alias of within
.isEqualTo(8.0f, byLessThan(0.2f)); assertThat(0.1f)
.isCloseTo(8.0f, byLessThan(0.2f));
assertThat(0.1f)
// strict
// assertions succeed when the difference == offset value ...
.isEqualTo(0.0f, within(0.1f))
.isEqualTo(0.0f, offset(0.1f));
.isCloseTo(0.0f, offset(0.1f));
assertThat(8.1f)
// ... except when using byLessThan which implies a strict comparison
// assertThat(0.1f).isEqualTo(0.0f, byLessThan(0.1f)); // strict => fail
.isEqualTo(8.0f, within(0.2f))
.isEqualTo(8.0f, offset(0.2f))
// alias of within
.isEqualTo(8.0f, byLessThan(0.2f)); assertThat(0.1f)
.isCloseTo(8.0f, byLessThan(0.2f));
assertThat(0.1f)
// strict
// assertions succeed when the difference == offset value ...
.isEqualTo(0.0f, within(0.1f))
.isEqualTo(0.0f, offset(0.1f));
.isCloseTo(0.0f, offset(0.1f));

assertThat(5)
.isCloseTo(7, within(3))
Expand Down Expand Up @@ -298,7 +298,7 @@ public void isNotCloseTo_examples() {

@Test
public void number_assertions_with_binary_representation_examples() {
assertThat(1).inBinary().isEqualTo(1);
assertThat(1).inBinary().isOne();
try {
assertThat(1).inBinary().isEqualTo(2);
} catch (AssertionError e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ public void build_soft_assertions_errors_report_example() {
// let the assertions fail
catchThrowable(() -> softly.assertAll());
// check the built report
assertThat(reportBuilder.toString()).isEqualTo(format("Assertions report:%n" +
"------------------%n" +
"[check Frodo's race] %n" +
"expected: \"Orc\"%n" +
"but was : \"Hobbit\"%n" +
"------------------%n" +
"[check Aragorn's age] %n" +
"Expecting:%n" +
" 87%n" +
"to be greater than:%n" +
" 500%n%n"));
assertThat(reportBuilder).hasToString(format("Assertions report:%n" +
"------------------%n" +
"[check Frodo's race] %n" +
"expected: \"Orc\"%n" +
"but was : \"Hobbit\"%n" +
"------------------%n" +
"[check Aragorn's age] %n" +
"Expecting:%n" +
" 87%n" +
"to be greater than:%n" +
" 500%n%n"));
}

@Test
Expand Down