Relocate custom assertion classes

This commit is contained in:
Nam Thai Nguyen
2018-01-31 18:34:09 +07:00
parent 950434a873
commit 5f87ceb1ff
4 changed files with 1 additions and 0 deletions

View File

@@ -1,11 +0,0 @@
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);
}
}

View File

@@ -1,30 +0,0 @@
package com.baeldung.testing.assertj.custom;
import org.assertj.core.api.AbstractAssert;
public class CarAssert extends AbstractAssert<CarAssert, Car> {
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;
}
}

View File

@@ -1,38 +0,0 @@
package com.baeldung.testing.assertj.custom;
import org.assertj.core.api.AbstractAssert;
public class PersonAssert extends AbstractAssert<PersonAssert, Person> {
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;
}
}