Initial commit for BAEL-1515

This commit is contained in:
Nam Thai Nguyen
2018-01-31 16:32:21 +07:00
parent be90e9870c
commit eb99ad5753
9 changed files with 220 additions and 0 deletions
@@ -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");
}
}
@@ -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();
}
}
@@ -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();
}
}