BAEL-1517: Resolve merge conflicts
This commit is contained in:
@@ -17,3 +17,4 @@
|
||||
- [Introduction to Jukito](http://www.baeldung.com/jukito)
|
||||
- [Custom JUnit 4 Test Runners](http://www.baeldung.com/junit-4-custom-runners)
|
||||
- [Guide to JSpec](http://www.baeldung.com/jspec)
|
||||
- [Custom Assertions with AssertJ](http://www.baeldung.com/assertj-custom-assertion)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.baeldung.testing.assertj;
|
||||
|
||||
public class Member {
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
public Member(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package com.baeldung.testing.assertj;
|
||||
|
||||
import static org.assertj.core.api.Assertions.allOf;
|
||||
import static org.assertj.core.api.Assertions.anyOf;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.not;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.Test;
|
||||
|
||||
public class AssertJConditionUnitTest {
|
||||
private Condition<Member> senior = new Condition<>(m -> m.getAge() >= 60, "senior");
|
||||
private Condition<Member> nameJohn = new Condition<>(m -> m.getName().equalsIgnoreCase("John"), "name John");
|
||||
|
||||
@Test
|
||||
public void whenUsingMemberAgeCondition_thenCorrect() {
|
||||
Member member = new Member("John", 65);
|
||||
assertThat(member).is(senior);
|
||||
|
||||
try {
|
||||
assertThat(member).isNot(senior);
|
||||
fail();
|
||||
} catch (AssertionError e) {
|
||||
assertThat(e).hasMessageContaining("not to be <senior>");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingMemberNameCondition_thenCorrect() {
|
||||
Member member = new Member("Jane", 60);
|
||||
assertThat(member).doesNotHave(nameJohn);
|
||||
|
||||
try {
|
||||
assertThat(member).has(nameJohn);
|
||||
fail();
|
||||
} catch (AssertionError e) {
|
||||
assertThat(e).hasMessageContaining("to have:\n <name John>");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCollectionConditionsAreSatisfied_thenCorrect() {
|
||||
List<Member> members = new ArrayList<>();
|
||||
members.add(new Member("Alice", 50));
|
||||
members.add(new Member("Bob", 60));
|
||||
|
||||
assertThat(members).haveExactly(1, senior);
|
||||
assertThat(members).doNotHave(nameJohn);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCombiningAllOfConditions_thenCorrect() {
|
||||
Member john = new Member("John", 60);
|
||||
Member jane = new Member("Jane", 50);
|
||||
|
||||
assertThat(john).is(allOf(senior, nameJohn));
|
||||
assertThat(jane).is(allOf(not(nameJohn), not(senior)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCombiningAnyOfConditions_thenCorrect() {
|
||||
Member john = new Member("John", 50);
|
||||
Member jane = new Member("Jane", 60);
|
||||
|
||||
assertThat(john).is(anyOf(senior, nameJohn));
|
||||
assertThat(jane).is(anyOf(nameJohn, senior));
|
||||
}
|
||||
}
|
||||
-5
@@ -3,16 +3,11 @@ package com.baeldung.testing.assertj.exceptions;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIOException;
|
||||
import static org.assertj.core.api.Assertions.assertThatNullPointerException;
|
||||
import static org.assertj.core.api.Assertions.catchThrowable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class Java8StyleAssertions {
|
||||
|
||||
Reference in New Issue
Block a user