Skip to content

Commit c057808

Browse files
Nam Thai NguyenNam Thai Nguyen
authored andcommitted
Modifies error messages
1 parent 63b8aa3 commit c057808

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

‎testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCustomAssertionsUnitTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void whenPersonAgeLessThanEighteen_thenNotAdult() {
2525
assertThat(person).isAdult();
2626
fail();
2727
} catch (AssertionError e) {
28-
org.assertj.core.api.Assertions.assertThat(e).hasMessage("Expected adult but was juvenile");
28+
org.assertj.core.api.Assertions.assertThat(e).hasMessage("Expected person to be adult");
2929
}
3030
}
3131

@@ -38,7 +38,7 @@ public void whenPersonDoesNotHaveAMatchingNickname_thenIncorrect() {
3838
assertThat(person).hasNickname("John");
3939
fail();
4040
} catch (AssertionError e) {
41-
org.assertj.core.api.Assertions.assertThat(e).hasMessage("Expected nickname John but did not have");
41+
org.assertj.core.api.Assertions.assertThat(e).hasMessage("Expected person to have nickname John");
4242
}
4343
}
4444
}

‎testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/PersonAssert.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@ public static PersonAssert assertThat(Person actual) {
1515
public PersonAssert hasFullName(String fullName) {
1616
isNotNull();
1717
if (!actual.getFullName().equals(fullName)) {
18-
failWithMessage("Expected full name %s but was %s", fullName, actual.getFullName());
18+
failWithMessage("Expected person to have full name %s but was %s", fullName, actual.getFullName());
1919
}
2020
return this;
2121
}
2222

2323
public PersonAssert isAdult() {
2424
isNotNull();
2525
if (actual.getAge() < 18) {
26-
failWithMessage("Expected adult but was juvenile");
26+
failWithMessage("Expected person to be adult");
2727
}
2828
return this;
2929
}
3030

3131
public PersonAssert hasNickname(String nickName) {
3232
isNotNull();
3333
if (!actual.getNicknames().contains(nickName)) {
34-
failWithMessage("Expected nickname %s but did not have", nickName);
34+
failWithMessage("Expected person to have nickname %s", nickName);
3535
}
3636
return this;
3737
}

0 commit comments

Comments
 (0)