Skip to content

Commit ba34900

Browse files
Changes for assertj sample
1 parent 85144ff commit ba34900

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

junit5-assertj-sample/src/main/java/com/sivalabs/jtme/Person.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public String toString() {
2525
'}';
2626
}
2727

28-
/*@Override
28+
@Override
2929
public boolean equals(Object o) {
3030
if (this == o) {
3131
return true;
@@ -42,7 +42,7 @@ public boolean equals(Object o) {
4242
@Override
4343
public int hashCode() {
4444
return id != null ? id.hashCode() : 0;
45-
}*/
45+
}
4646

4747
public Long getId() {
4848
return id;

junit5-assertj-sample/src/test/java/com/sivalabs/jtme/PersonServiceTest.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,12 @@ void showAssertjAwesomeness() {
5656
assertThat(name).containsIgnoringCase("pra");
5757
assertThat(age).isGreaterThan(30);
5858

59+
/* ================================================ */
5960
Person person1 = new Person(1L, "Siva", "siva@gmail.com");
6061
Person person2 = new Person(2L, "Prasad", "prasad@gmail.com");
61-
Person person3 = new Person(3L, "Siva", "sivalabs@gmail.com");
62+
Person person3 = new Person(1L, "Siva", "siva@gmail.com");
6263

63-
List<Person> personList = List.of(person1, person2, person3);
64-
Person person = new Person(2L, "Prasad", "prasad@gmail.com");
65-
66-
assertThat(personList).extracting("id").contains(2L, 3L);
67-
assertThat(personList).extracting("id").containsAll(List.of(1L, 2L, 3L));
68-
//using equals() and hashCode()
69-
//assertThat(personList).contains(person);
70-
71-
assertThat(person).usingRecursiveComparison().isEqualTo(person2);
64+
assertThat(person1).usingRecursiveComparison().isEqualTo(person3);
7265

7366
Person person4 = new Person(null, "Siva", "sivalabs@gmail.com");
7467
Person person5 = new Person(null, "Siva", "sivalabs@gmail.com");
@@ -81,5 +74,17 @@ void showAssertjAwesomeness() {
8174
.usingRecursiveComparison()
8275
.comparingOnlyFields("name", "email")
8376
.isEqualTo(person5);
77+
78+
/* ================================================ */
79+
List<Person> personList = List.of(person1, person2, person4);
80+
Person person = new Person(2L, "Prasad", "prasad@gmail.com");
81+
82+
assertThat(personList).contains(person);
83+
84+
assertThat(person)
85+
.usingRecursiveComparison()
86+
.comparingOnlyFields("id")
87+
.isIn(personList);
88+
8489
}
8590
}

0 commit comments

Comments
 (0)