Skip to content

Commit 63b8aa3

Browse files
Nam Thai NguyenNam Thai Nguyen
authored andcommitted
Refactor BAEL-1515
1 parent 5f87ceb commit 63b8aa3

6 files changed

Lines changed: 26 additions & 90 deletions

File tree

‎testing-modules/testing/pom.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@
161161
<configuration>
162162
<classes>
163163
<param>com.baeldung.testing.assertj.custom.Person</param>
164-
<param>com.baeldung.testing.assertj.custom.Car</param>
165164
</classes>
166165
</configuration>
167166
</plugin>

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

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.baeldung.testing.assertj.custom;
22

33
import static com.baeldung.testing.assertj.custom.Assertions.assertThat;
4+
import static org.junit.Assert.fail;
45

56
import org.junit.Rule;
67
import org.junit.Test;
@@ -9,21 +10,35 @@
910
public class AssertJCustomAssertionsUnitTest {
1011
@Rule
1112
public ExpectedException thrown = ExpectedException.none();
12-
13+
1314
@Test
14-
public void whenPersonDoesNotHaveAMatchingNickname_thenIncorrect() {
15-
thrown.expect(AssertionError.class);
16-
thrown.expectMessage("Expected nickname John but did not have");
15+
public void whenPersonNameMatches_thenCorrect() {
1716
Person person = new Person("John Doe", 20);
18-
person.addNickname("Nick");
19-
assertThat(person).hasNickname("John");
17+
assertThat(person).hasFullName("John Doe");
2018
}
2119

2220
@Test
23-
public void whenCarIsUsed_thenCorrect() {
21+
public void whenPersonAgeLessThanEighteen_thenNotAdult() {
2422
Person person = new Person("Jane Roe", 16);
25-
Car car = new Car("SUV");
26-
car.setOwner(person);
27-
assertThat(car).isUsed();
23+
24+
try {
25+
assertThat(person).isAdult();
26+
fail();
27+
} catch (AssertionError e) {
28+
org.assertj.core.api.Assertions.assertThat(e).hasMessage("Expected adult but was juvenile");
29+
}
30+
}
31+
32+
@Test
33+
public void whenPersonDoesNotHaveAMatchingNickname_thenIncorrect() {
34+
Person person = new Person("John Doe", 20);
35+
person.addNickname("Nick");
36+
37+
try {
38+
assertThat(person).hasNickname("John");
39+
fail();
40+
} catch (AssertionError e) {
41+
org.assertj.core.api.Assertions.assertThat(e).hasMessage("Expected nickname John but did not have");
42+
}
2843
}
2944
}

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

Lines changed: 0 additions & 26 deletions
This file was deleted.

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@ public static PersonAssert assertThat(Person actual) {
55
return new PersonAssert(actual);
66
}
77

8-
public static CarAssert assertThat(Car actual) {
9-
return new CarAssert(actual);
10-
}
8+
// static factory methods of other assertion classes
119
}

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

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)