From eb99ad575377f17e81e0cb480bcd4d48e234204c Mon Sep 17 00:00:00 2001 From: Nam Thai Nguyen Date: Wed, 31 Jan 2018 16:32:21 +0700 Subject: [PATCH 1/6] Initial commit for BAEL-1515 --- testing-modules/testing/pom.xml | 12 ++++++ .../testing/assertj/custom/Assertions.java | 11 ++++++ .../baeldung/testing/assertj/custom/Car.java | 22 +++++++++++ .../testing/assertj/custom/CarAssert.java | 30 +++++++++++++++ .../testing/assertj/custom/Person.java | 32 ++++++++++++++++ .../testing/assertj/custom/PersonAssert.java | 38 +++++++++++++++++++ .../custom/AssertJCarAssertUnitTest.java | 20 ++++++++++ .../AssertJCustomAssertionsUnitTest.java | 29 ++++++++++++++ .../custom/AssertJPersonAssertUnitTest.java | 26 +++++++++++++ 9 files changed, 220 insertions(+) create mode 100644 testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/Assertions.java create mode 100644 testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/Car.java create mode 100644 testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/CarAssert.java create mode 100644 testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/Person.java create mode 100644 testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/PersonAssert.java create mode 100644 testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCarAssertUnitTest.java create mode 100644 testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCustomAssertionsUnitTest.java create mode 100644 testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJPersonAssertUnitTest.java diff --git a/testing-modules/testing/pom.xml b/testing-modules/testing/pom.xml index 1fd6357b87..6f185d3b4c 100644 --- a/testing-modules/testing/pom.xml +++ b/testing-modules/testing/pom.xml @@ -154,6 +154,17 @@ + + org.assertj + assertj-assertions-generator-maven-plugin + ${assertj-generator.version} + + + com.baeldung.testing.assertj.custom.Person + com.baeldung.testing.assertj.custom.Car + + + @@ -164,6 +175,7 @@ 21.0 3.1.0 3.6.1 + 2.1.0 0.32 1.1.0 0.12 diff --git a/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/Assertions.java b/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/Assertions.java new file mode 100644 index 0000000000..5c72eb6d05 --- /dev/null +++ b/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/Assertions.java @@ -0,0 +1,11 @@ +package com.baeldung.testing.assertj.custom; + +public class Assertions { + public static PersonAssert assertThat(Person actual) { + return new PersonAssert(actual); + } + + public static CarAssert assertThat(Car actual) { + return new CarAssert(actual); + } +} diff --git a/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/Car.java b/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/Car.java new file mode 100644 index 0000000000..e52ffee8e5 --- /dev/null +++ b/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/Car.java @@ -0,0 +1,22 @@ +package com.baeldung.testing.assertj.custom; + +public class Car { + private String type; + private Person owner; + + public Car(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + public Person getOwner() { + return owner; + } + + public void setOwner(Person owner) { + this.owner = owner; + } +} diff --git a/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/CarAssert.java b/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/CarAssert.java new file mode 100644 index 0000000000..413c2d3e12 --- /dev/null +++ b/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/CarAssert.java @@ -0,0 +1,30 @@ +package com.baeldung.testing.assertj.custom; + +import org.assertj.core.api.AbstractAssert; + +public class CarAssert extends AbstractAssert { + + public CarAssert(Car actual) { + super(actual, CarAssert.class); + } + + public static CarAssert assertThat(Car actual) { + return new CarAssert(actual); + } + + public CarAssert hasType(String type) { + isNotNull(); + if (!actual.getType().equals(type)) { + failWithMessage("Expected type %s but was %s", type, actual.getType()); + } + return this; + } + + public CarAssert isUsed() { + isNotNull(); + if (actual.getOwner() == null) { + failWithMessage("Expected old but was new"); + } + return this; + } +} diff --git a/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/Person.java b/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/Person.java new file mode 100644 index 0000000000..34afc480e4 --- /dev/null +++ b/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/Person.java @@ -0,0 +1,32 @@ +package com.baeldung.testing.assertj.custom; + +import java.util.ArrayList; +import java.util.List; + +public class Person { + private String fullName; + private int age; + private List nicknames; + + public Person(String fullName, int age) { + this.fullName = fullName; + this.age = age; + this.nicknames = new ArrayList<>(); + } + + public void addNickname(String nickname) { + nicknames.add(nickname); + } + + public String getFullName() { + return fullName; + } + + public int getAge() { + return age; + } + + public List getNicknames() { + return nicknames; + } +} diff --git a/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/PersonAssert.java b/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/PersonAssert.java new file mode 100644 index 0000000000..4c071660f3 --- /dev/null +++ b/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/PersonAssert.java @@ -0,0 +1,38 @@ +package com.baeldung.testing.assertj.custom; + +import org.assertj.core.api.AbstractAssert; + +public class PersonAssert extends AbstractAssert { + + public PersonAssert(Person actual) { + super(actual, PersonAssert.class); + } + + public static PersonAssert assertThat(Person actual) { + return new PersonAssert(actual); + } + + public PersonAssert hasFullName(String fullName) { + isNotNull(); + if (!actual.getFullName().equals(fullName)) { + failWithMessage("Expected full name %s but was %s", fullName, actual.getFullName()); + } + return this; + } + + public PersonAssert isAdult() { + isNotNull(); + if (actual.getAge() < 18) { + failWithMessage("Expected adult but was juvenile"); + } + return this; + } + + public PersonAssert hasNickname(String nickName) { + isNotNull(); + if (!actual.getNicknames().contains(nickName)) { + failWithMessage("Expected nickname %s but did not have", nickName); + } + return this; + } +} diff --git a/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCarAssertUnitTest.java b/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCarAssertUnitTest.java new file mode 100644 index 0000000000..d438cc42f6 --- /dev/null +++ b/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCarAssertUnitTest.java @@ -0,0 +1,20 @@ +package com.baeldung.testing.assertj.custom; + +import static com.baeldung.testing.assertj.custom.CarAssert.assertThat; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class AssertJCarAssertUnitTest { + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void whenCarTypeDoesNotMatch_thenIncorrect() { + thrown.expect(AssertionError.class); + thrown.expectMessage("Expected type SUV but was Sedan"); + Car car = new Car("Sedan"); + assertThat(car).hasType("SUV"); + } +} diff --git a/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCustomAssertionsUnitTest.java b/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCustomAssertionsUnitTest.java new file mode 100644 index 0000000000..8b800de3db --- /dev/null +++ b/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCustomAssertionsUnitTest.java @@ -0,0 +1,29 @@ +package com.baeldung.testing.assertj.custom; + +import static com.baeldung.testing.assertj.custom.Assertions.assertThat; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class AssertJCustomAssertionsUnitTest { + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void whenPersonDoesNotHaveAMatchingNickname_thenIncorrect() { + thrown.expect(AssertionError.class); + thrown.expectMessage("Expected nickname John but did not have"); + Person person = new Person("John Doe", 20); + person.addNickname("Nick"); + assertThat(person).hasNickname("John"); + } + + @Test + public void whenCarIsUsed_thenCorrect() { + Person person = new Person("Jane Roe", 16); + Car car = new Car("SUV"); + car.setOwner(person); + assertThat(car).isUsed(); + } +} diff --git a/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJPersonAssertUnitTest.java b/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJPersonAssertUnitTest.java new file mode 100644 index 0000000000..ab421915af --- /dev/null +++ b/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJPersonAssertUnitTest.java @@ -0,0 +1,26 @@ +package com.baeldung.testing.assertj.custom; + +import static com.baeldung.testing.assertj.custom.PersonAssert.assertThat; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class AssertJPersonAssertUnitTest { + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void whenPersonNameMatches_thenCorrect() { + Person person = new Person("John Doe", 20); + assertThat(person).hasFullName("John Doe"); + } + + @Test + public void whenPersonAgeLessThanEighteen_thenNotAdult() { + thrown.expect(AssertionError.class); + thrown.expectMessage("Expected adult but was juvenile"); + Person person = new Person("Jane Roe", 16); + assertThat(person).isAdult(); + } +} From 950434a87341b4a6f1085b8feb8bb33eb95447f2 Mon Sep 17 00:00:00 2001 From: Nam Thai Nguyen Date: Wed, 31 Jan 2018 16:46:19 +0700 Subject: [PATCH 2/6] Fix the scope of AssertJ core --- testing-modules/testing/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/testing-modules/testing/pom.xml b/testing-modules/testing/pom.xml index 6f185d3b4c..2804a94244 100644 --- a/testing-modules/testing/pom.xml +++ b/testing-modules/testing/pom.xml @@ -34,7 +34,6 @@ org.assertj assertj-core ${assertj-core.version} - test From 5f87ceb1ffcdaf64f9d4ecf8ee468511c22a9f92 Mon Sep 17 00:00:00 2001 From: Nam Thai Nguyen Date: Wed, 31 Jan 2018 18:34:09 +0700 Subject: [PATCH 3/6] Relocate custom assertion classes --- testing-modules/testing/pom.xml | 1 + .../java/com/baeldung/testing/assertj/custom/Assertions.java | 0 .../java/com/baeldung/testing/assertj/custom/CarAssert.java | 0 .../java/com/baeldung/testing/assertj/custom/PersonAssert.java | 0 4 files changed, 1 insertion(+) rename testing-modules/testing/src/{main => test}/java/com/baeldung/testing/assertj/custom/Assertions.java (100%) rename testing-modules/testing/src/{main => test}/java/com/baeldung/testing/assertj/custom/CarAssert.java (100%) rename testing-modules/testing/src/{main => test}/java/com/baeldung/testing/assertj/custom/PersonAssert.java (100%) diff --git a/testing-modules/testing/pom.xml b/testing-modules/testing/pom.xml index 2804a94244..6f185d3b4c 100644 --- a/testing-modules/testing/pom.xml +++ b/testing-modules/testing/pom.xml @@ -34,6 +34,7 @@ org.assertj assertj-core ${assertj-core.version} + test diff --git a/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/Assertions.java b/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/Assertions.java similarity index 100% rename from testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/Assertions.java rename to testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/Assertions.java diff --git a/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/CarAssert.java b/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/CarAssert.java similarity index 100% rename from testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/CarAssert.java rename to testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/CarAssert.java diff --git a/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/PersonAssert.java b/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/PersonAssert.java similarity index 100% rename from testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/PersonAssert.java rename to testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/PersonAssert.java From 63b8aa334f89ab042e4203f99d032b03a1dd8b60 Mon Sep 17 00:00:00 2001 From: Nam Thai Nguyen Date: Thu, 1 Feb 2018 11:00:51 +0700 Subject: [PATCH 4/6] Refactor BAEL-1515 --- testing-modules/testing/pom.xml | 1 - .../custom/AssertJCarAssertUnitTest.java | 20 ----------- .../AssertJCustomAssertionsUnitTest.java | 35 +++++++++++++------ .../custom/AssertJPersonAssertUnitTest.java | 26 -------------- .../testing/assertj/custom/Assertions.java | 4 +-- .../testing/assertj/custom/CarAssert.java | 30 ---------------- 6 files changed, 26 insertions(+), 90 deletions(-) delete mode 100644 testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCarAssertUnitTest.java delete mode 100644 testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJPersonAssertUnitTest.java delete mode 100644 testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/CarAssert.java diff --git a/testing-modules/testing/pom.xml b/testing-modules/testing/pom.xml index 6f185d3b4c..c76045380b 100644 --- a/testing-modules/testing/pom.xml +++ b/testing-modules/testing/pom.xml @@ -161,7 +161,6 @@ com.baeldung.testing.assertj.custom.Person - com.baeldung.testing.assertj.custom.Car diff --git a/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCarAssertUnitTest.java b/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCarAssertUnitTest.java deleted file mode 100644 index d438cc42f6..0000000000 --- a/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCarAssertUnitTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.testing.assertj.custom; - -import static com.baeldung.testing.assertj.custom.CarAssert.assertThat; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -public class AssertJCarAssertUnitTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void whenCarTypeDoesNotMatch_thenIncorrect() { - thrown.expect(AssertionError.class); - thrown.expectMessage("Expected type SUV but was Sedan"); - Car car = new Car("Sedan"); - assertThat(car).hasType("SUV"); - } -} diff --git a/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCustomAssertionsUnitTest.java b/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCustomAssertionsUnitTest.java index 8b800de3db..f9b5bad039 100644 --- a/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCustomAssertionsUnitTest.java +++ b/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCustomAssertionsUnitTest.java @@ -1,6 +1,7 @@ package com.baeldung.testing.assertj.custom; import static com.baeldung.testing.assertj.custom.Assertions.assertThat; +import static org.junit.Assert.fail; import org.junit.Rule; import org.junit.Test; @@ -9,21 +10,35 @@ import org.junit.rules.ExpectedException; public class AssertJCustomAssertionsUnitTest { @Rule public ExpectedException thrown = ExpectedException.none(); - + @Test - public void whenPersonDoesNotHaveAMatchingNickname_thenIncorrect() { - thrown.expect(AssertionError.class); - thrown.expectMessage("Expected nickname John but did not have"); + public void whenPersonNameMatches_thenCorrect() { Person person = new Person("John Doe", 20); - person.addNickname("Nick"); - assertThat(person).hasNickname("John"); + assertThat(person).hasFullName("John Doe"); } @Test - public void whenCarIsUsed_thenCorrect() { + public void whenPersonAgeLessThanEighteen_thenNotAdult() { Person person = new Person("Jane Roe", 16); - Car car = new Car("SUV"); - car.setOwner(person); - assertThat(car).isUsed(); + + try { + assertThat(person).isAdult(); + fail(); + } catch (AssertionError e) { + org.assertj.core.api.Assertions.assertThat(e).hasMessage("Expected adult but was juvenile"); + } + } + + @Test + public void whenPersonDoesNotHaveAMatchingNickname_thenIncorrect() { + Person person = new Person("John Doe", 20); + person.addNickname("Nick"); + + try { + assertThat(person).hasNickname("John"); + fail(); + } catch (AssertionError e) { + org.assertj.core.api.Assertions.assertThat(e).hasMessage("Expected nickname John but did not have"); + } } } diff --git a/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJPersonAssertUnitTest.java b/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJPersonAssertUnitTest.java deleted file mode 100644 index ab421915af..0000000000 --- a/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJPersonAssertUnitTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.baeldung.testing.assertj.custom; - -import static com.baeldung.testing.assertj.custom.PersonAssert.assertThat; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -public class AssertJPersonAssertUnitTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void whenPersonNameMatches_thenCorrect() { - Person person = new Person("John Doe", 20); - assertThat(person).hasFullName("John Doe"); - } - - @Test - public void whenPersonAgeLessThanEighteen_thenNotAdult() { - thrown.expect(AssertionError.class); - thrown.expectMessage("Expected adult but was juvenile"); - Person person = new Person("Jane Roe", 16); - assertThat(person).isAdult(); - } -} diff --git a/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/Assertions.java b/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/Assertions.java index 5c72eb6d05..fcffb8fc6c 100644 --- a/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/Assertions.java +++ b/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/Assertions.java @@ -5,7 +5,5 @@ public class Assertions { return new PersonAssert(actual); } - public static CarAssert assertThat(Car actual) { - return new CarAssert(actual); - } + // static factory methods of other assertion classes } diff --git a/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/CarAssert.java b/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/CarAssert.java deleted file mode 100644 index 413c2d3e12..0000000000 --- a/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/CarAssert.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.testing.assertj.custom; - -import org.assertj.core.api.AbstractAssert; - -public class CarAssert extends AbstractAssert { - - public CarAssert(Car actual) { - super(actual, CarAssert.class); - } - - public static CarAssert assertThat(Car actual) { - return new CarAssert(actual); - } - - public CarAssert hasType(String type) { - isNotNull(); - if (!actual.getType().equals(type)) { - failWithMessage("Expected type %s but was %s", type, actual.getType()); - } - return this; - } - - public CarAssert isUsed() { - isNotNull(); - if (actual.getOwner() == null) { - failWithMessage("Expected old but was new"); - } - return this; - } -} From c057808c6e9b86a97e1fbf5be8af050ed82a8f60 Mon Sep 17 00:00:00 2001 From: Nam Thai Nguyen Date: Fri, 2 Feb 2018 11:59:17 +0700 Subject: [PATCH 5/6] Modifies error messages --- .../assertj/custom/AssertJCustomAssertionsUnitTest.java | 4 ++-- .../com/baeldung/testing/assertj/custom/PersonAssert.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCustomAssertionsUnitTest.java b/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCustomAssertionsUnitTest.java index f9b5bad039..4c09311bac 100644 --- a/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCustomAssertionsUnitTest.java +++ b/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/AssertJCustomAssertionsUnitTest.java @@ -25,7 +25,7 @@ public class AssertJCustomAssertionsUnitTest { assertThat(person).isAdult(); fail(); } catch (AssertionError e) { - org.assertj.core.api.Assertions.assertThat(e).hasMessage("Expected adult but was juvenile"); + org.assertj.core.api.Assertions.assertThat(e).hasMessage("Expected person to be adult"); } } @@ -38,7 +38,7 @@ public class AssertJCustomAssertionsUnitTest { assertThat(person).hasNickname("John"); fail(); } catch (AssertionError e) { - org.assertj.core.api.Assertions.assertThat(e).hasMessage("Expected nickname John but did not have"); + org.assertj.core.api.Assertions.assertThat(e).hasMessage("Expected person to have nickname John"); } } } diff --git a/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/PersonAssert.java b/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/PersonAssert.java index 4c071660f3..d6cc585e96 100644 --- a/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/PersonAssert.java +++ b/testing-modules/testing/src/test/java/com/baeldung/testing/assertj/custom/PersonAssert.java @@ -15,7 +15,7 @@ public class PersonAssert extends AbstractAssert { public PersonAssert hasFullName(String fullName) { isNotNull(); if (!actual.getFullName().equals(fullName)) { - failWithMessage("Expected full name %s but was %s", fullName, actual.getFullName()); + failWithMessage("Expected person to have full name %s but was %s", fullName, actual.getFullName()); } return this; } @@ -23,7 +23,7 @@ public class PersonAssert extends AbstractAssert { public PersonAssert isAdult() { isNotNull(); if (actual.getAge() < 18) { - failWithMessage("Expected adult but was juvenile"); + failWithMessage("Expected person to be adult"); } return this; } @@ -31,7 +31,7 @@ public class PersonAssert extends AbstractAssert { public PersonAssert hasNickname(String nickName) { isNotNull(); if (!actual.getNicknames().contains(nickName)) { - failWithMessage("Expected nickname %s but did not have", nickName); + failWithMessage("Expected person to have nickname %s", nickName); } return this; } From fa906a2b59420fd29fca9fa93ae291771c84a8d4 Mon Sep 17 00:00:00 2001 From: Tom Hombergs Date: Fri, 2 Feb 2018 21:01:22 +0100 Subject: [PATCH 6/6] removed Car class --- .../baeldung/testing/assertj/custom/Car.java | 22 ------------------- 1 file changed, 22 deletions(-) delete mode 100644 testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/Car.java diff --git a/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/Car.java b/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/Car.java deleted file mode 100644 index e52ffee8e5..0000000000 --- a/testing-modules/testing/src/main/java/com/baeldung/testing/assertj/custom/Car.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.testing.assertj.custom; - -public class Car { - private String type; - private Person owner; - - public Car(String type) { - this.type = type; - } - - public String getType() { - return type; - } - - public Person getOwner() { - return owner; - } - - public void setOwner(Person owner) { - this.owner = owner; - } -}