Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions assertions-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<neo4j.version>3.0.0</neo4j.version>
<assertj-core.version>3.19.0</assertj-core.version>
<assertj-core.version>3.27.7</assertj-core.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.7.0</version>
<version>5.14.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -143,7 +143,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.18.3</version>
<version>4.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -181,7 +181,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<version>3.1.2</version>
<configuration>
<includes>
<include>**/*Examples.java</include>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ public void array2D_assertions_examples() {
int[][] numbers = new int[][] { { 1, 2, 3 }, { 4, 5, 6 } };
// 2D generic array
assertThat(abc).hasDimensions(2, 3)
.isNotEmpty()
.contains(new String[] { "1", "2", "3" }, atIndex(1))
.isDeepEqualTo(new String[][] { { "a", "b", "c" }, { "1", "2", "3" } })
.hasSameDimensionsAs(numbers);
// 2D primtive arrays
assertThat(numbers).hasDimensions(2, 3)
.isNotEmpty()
.contains(new int[] { 1, 2, 3 }, atIndex(0))
.hasSameDimensionsAs(abc)
.isDeepEqualTo(new int[][] { { 1, 2, 3 }, { 4, 5, 6 } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void array_assertions_examples() {

String[] abc = { "a", "b", "c" };
assertThat(abc).containsExactly("a", "b", "c")
.containsAnyOf("b")
.contains("b")
.containsAnyOf("b", "c")
.containsAnyOf("a", "b", "c")
.containsAnyOf("a", "b", "c", "d")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static org.assertj.examples.data.Race.ORC;

import org.assertj.examples.data.TolkienCharacter;
import org.junit.AfterClass;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;

public class AssumptionExamples extends AbstractAssertionsExamples {
Expand All @@ -30,7 +30,7 @@ public class AssumptionExamples extends AbstractAssertionsExamples {

private static int ranTests = 0;

@AfterClass
@AfterAll
public static void afterClass() {
assertThat(ranTests).as("number of tests run").isEqualTo(2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void meaningful_error_with_test_description_example() {
assertThat(error).isInstanceOf(AssertionError.class)
.hasMessage(format("[check Frodo's age] %n" +
"expected: 33%n" +
"but was : 50"));
" but was: 50"));

// you can pass a Supplier<String> to avoid building the description if the assertion succeeds
assertThat(frodo.age).as(() -> "check Frodo's age").isEqualTo(50);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void date_assertions_comparison_with_precision_level() {
Date date5 = parseDatetimeWithMs("2003-01-01T05:55:55.555");

assertThat(date1)
.isEqualToIgnoringMillis(date2)
.isCloseTo(date2, 1000L)
.isInSameSecondAs(date2)
.isEqualToIgnoringSeconds(date3)
.isInSameMinuteAs(date3)
Expand All @@ -114,7 +114,7 @@ public void date_assertions_comparison_with_precision_level() {
.isInSameDayAs(date5);

try {
assertThat(date1).isEqualToIgnoringMillis(date3);
assertThat(date1).isCloseTo(date3, 1000L);
} catch (AssertionError e) {
logAssertionErrorMessage("isEqualToIgnoringMillis", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class GeneratedJunitSoftAssertionsExamples extends AbstractAssertionsExam

@Rule
public JUnitSoftAssertions softly = new JUnitSoftAssertions();

@Test
public void generated_soft_assertions_example() throws NameException {
// use the generated soft assertions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void iterable_basic_assertions_examples() {

List<String> abc = asList("a", "b", "c");
assertThat(abc).hasSize(3)
.containsAnyOf("b")
.contains("b")
.containsAnyOf("b", "c")
.containsAnyOf("a", "b", "c")
.containsAnyOf("a", "b", "c", "d")
Expand Down Expand Up @@ -145,7 +145,7 @@ public void iterable_basic_assertions_examples() {

List<Integer> testedList = list(1);
List<Integer> referenceList = list(1, 2, 3);
assertThat(referenceList).containsSequence(testedList.toArray(new Integer[testedList.size()]));
assertThat(referenceList).contains(testedList.toArray(new Integer[testedList.size()]));

List<String> options = list("--option", "a=b", "--option", "c=d");
assertThat(options).containsSequence("--option", "c=d");
Expand Down Expand Up @@ -655,7 +655,7 @@ public boolean matches(BasketBallPlayer player) {
}

@Test
public void test_issue_245() throws Exception {
public void issue_245() throws Exception {
Foo foo1 = new Foo("id", 1);
foo1._f2 = "foo1";
Foo foo2 = new Foo("id", 2);
Expand All @@ -673,7 +673,7 @@ public void test_issue_245() throws Exception {
}

@Test
public void test_issue_236() throws Exception {
public void issue_236() throws Exception {
List<Foo> list1 = list(new Foo("id", 1));
List<Foo> list2 = list(new Foo("id", 2));
assertThat(list1).usingElementComparatorOnFields("id").isEqualTo(list2);
Expand All @@ -695,7 +695,7 @@ public void display_collection_with_one_element_per_line() throws Exception {
}

@Test
public void test_issue_656() {
public void issue_656() {
Iterator<String> iterator = new ArrayList<String>().iterator();
assertThat(iterator).isSameAs(iterator);
}
Expand Down Expand Up @@ -727,15 +727,15 @@ public void navigation_with_iterable_examples() {
}

@Test
public void test_navigation_with_list() {
public void navigation_with_list() {
List<TolkienCharacter> hobbits = list(frodo, sam, pippin);
assertThat(hobbits).first().isEqualTo(frodo);
assertThat(hobbits).element(1).isEqualTo(sam);
assertThat(hobbits).last().isEqualTo(pippin);
}

@Test
public void test_navigable_size_assertions() {
public void navigable_size_assertions() {
Iterable<Ring> elvesRings = list(vilya, nenya, narya);

// assertion will pass:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Comparator;
import java.util.List;

import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;
import org.assertj.examples.comparator.AtPrecisionComparator;
import org.assertj.examples.data.Employee;
import org.assertj.examples.data.TolkienCharacter;
Expand Down Expand Up @@ -87,6 +88,14 @@ public void iterable_assertions_with_specific_comparator_by_element_field_or_typ

Comparator<Double> closeEnough = new AtPrecisionComparator<>(0.5);

// since 3.x the recursive element comparator takes its own configuration to register field/type comparators
RecursiveComparisonConfiguration heightFieldConfig = RecursiveComparisonConfiguration.builder()
.withComparatorForFields(closeEnough, "height")
.build();
RecursiveComparisonConfiguration doubleTypeConfig = RecursiveComparisonConfiguration.builder()
.withComparatorForType(closeEnough, Double.class)
.build();

Dude[] hobbits = new Dude[] { dude };

// assertions will pass
Expand All @@ -102,8 +111,7 @@ public void iterable_assertions_with_specific_comparator_by_element_field_or_typ
.usingElementComparatorIgnoringFields("name")
.contains(tallerDude);

assertThat(hobbits).usingComparatorForElementFieldsWithNames(closeEnough, "height")
.usingRecursiveFieldByFieldElementComparator()
assertThat(hobbits).usingRecursiveFieldByFieldElementComparator(heightFieldConfig)
.contains(tallerDude);

assertThat(asList(dude)).usingComparatorForElementFieldsWithNames(closeEnough, "height")
Expand All @@ -118,8 +126,7 @@ public void iterable_assertions_with_specific_comparator_by_element_field_or_typ
.usingElementComparatorIgnoringFields("name")
.contains(tallerDude);

assertThat(asList(dude)).usingComparatorForElementFieldsWithNames(closeEnough, "height")
.usingRecursiveFieldByFieldElementComparator()
assertThat(asList(dude)).usingRecursiveFieldByFieldElementComparator(heightFieldConfig)
.contains(tallerDude);

assertThat(hobbits).usingComparatorForElementFieldsWithType(closeEnough, Double.class)
Expand All @@ -134,8 +141,7 @@ public void iterable_assertions_with_specific_comparator_by_element_field_or_typ
.usingElementComparatorIgnoringFields("name")
.contains(tallerDude);

assertThat(hobbits).usingComparatorForElementFieldsWithType(closeEnough, Double.class)
.usingRecursiveFieldByFieldElementComparator()
assertThat(hobbits).usingRecursiveFieldByFieldElementComparator(doubleTypeConfig)
.contains(tallerDude);

assertThat(asList(dude)).usingComparatorForElementFieldsWithType(closeEnough, Double.class)
Expand All @@ -150,8 +156,7 @@ public void iterable_assertions_with_specific_comparator_by_element_field_or_typ
.usingElementComparatorIgnoringFields("name")
.contains(tallerDude);

assertThat(asList(dude)).usingComparatorForElementFieldsWithType(closeEnough, Double.class)
.usingRecursiveFieldByFieldElementComparator()
assertThat(asList(dude)).usingRecursiveFieldByFieldElementComparator(doubleTypeConfig)
.contains(tallerDude);

Dude reallyTallDude = new Dude("Frodo", 1.9);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import org.assertj.core.api.JUnitBDDSoftAssertions;
import org.assertj.examples.data.Mansion;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

public class JUnitBDDSoftAssertionsExamples extends AbstractAssertionsExamples {
Expand All @@ -26,7 +26,7 @@ public class JUnitBDDSoftAssertionsExamples extends AbstractAssertionsExamples {

// comment the @Ignore to see the test failing with all the assertion error and not only the first one.
@Test
@Ignore
@Disabled
public void failing_junit_soft_assertions_example() {
Mansion mansion = new Mansion();
mansion.hostPotentiallyMurderousDinnerParty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class MapAssertionsExamples extends AbstractAssertionsExamples {
private Condition<Map.Entry<TolkienCharacter, Ring>> oneRingManBearer = new Condition<>(entry -> entry.getKey().getRace() == MAN
&& entry.getValue() == oneRing,
"One ring man bearer");

// @format:on

@Test
Expand Down Expand Up @@ -178,15 +179,15 @@ public void display_sorted_maps_in_error_message() {
try {
Map<String, Integer> expected = ImmutableMap.<String, Integer> builder().put("a", 1).put("b", 2).build();
Map<String, Integer> actual = ImmutableMap.<String, Integer> builder().put("b", 1).put("a", 1).build();
assertThat(expected).isEqualTo(actual);
assertThat(expected).containsExactlyInAnyOrderEntriesOf(actual);
} catch (AssertionError e) {
logAssertionErrorMessage("display sorted maps in error message", e);
}
}

@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
@Test
public void test_bug_485() {
public void bug_485() {
// https://github.com/joel-costigliola/assertj-core/issues/485
Map map1 = new HashMap();
map1.put("Key1", "Value1");
Expand All @@ -196,7 +197,7 @@ public void test_bug_485() {
}

@Test
public void test_navigable_size_assertions() throws Exception {
public void navigable_size_assertions() throws Exception {
Map<Ring, TolkienCharacter> ringBearers = new HashMap<>();
ringBearers.put(nenya, galadriel);
ringBearers.put(narya, gandalf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void assertion_error_with_message_differentiating_double_and_float() {
// message)
assertThat(e).hasMessage(format("%n" +
"expected: 42.0%n" +
"but was : 42.0f"));
" but was: 42.0f"));
return;
}
}
Expand All @@ -129,10 +129,10 @@ public void big_decimals_assertions_examples() {

@Test
public void number_assertions_with_offset_examples() {
assertThat(8.1).isEqualTo(8.0, offset(0.1));
assertThat(8.1f).isEqualTo(8.2f, offset(0.1f));
assertThat(8.1).isCloseTo(8.0, offset(0.1));
assertThat(8.1f).isCloseTo(8.2f, offset(0.1f));
try {
assertThat(8.1f).isEqualTo(8.0f, offset(0.1f));
assertThat(8.1f).isCloseTo(8.0f, offset(0.1f));
} catch (AssertionError e) {
logAssertionErrorMessage("float isEqualTo with offset", e);
}
Expand Down Expand Up @@ -198,12 +198,12 @@ public void number_assertions_with_offset_examples() {
assertThat(8.1f)
.isEqualTo(8.0f, within(0.2f))
.isEqualTo(8.0f, offset(0.2f))
// alias of within
.isEqualTo(8.0f, byLessThan(0.2f)); assertThat(0.1f)
.isCloseTo(8.0f, byLessThan(0.2f));
assertThat(0.1f)
// strict
// assertions succeed when the difference == offset value ...
.isCloseTo(0.0f, within(0.1f))
.isEqualTo(0.0f, within(0.1f));
.isCloseTo(0.0f, within(0.1f));

assertThat(8.1f)
.isNotCloseTo(8.0f, byLessThan(0.01f))
Expand All @@ -215,23 +215,23 @@ public void number_assertions_with_offset_examples() {
assertThat(8.1f)
.isEqualTo(8.0f, within(0.2f))
.isEqualTo(8.0f, offset(0.2f))
// alias of within
.isEqualTo(8.0f, byLessThan(0.2f)); assertThat(0.1f)
.isCloseTo(8.0f, byLessThan(0.2f));
assertThat(0.1f)
// strict
// assertions succeed when the difference == offset value ...
.isEqualTo(0.0f, within(0.1f))
.isEqualTo(0.0f, offset(0.1f));
.isCloseTo(0.0f, offset(0.1f));
assertThat(8.1f)
// ... except when using byLessThan which implies a strict comparison
// assertThat(0.1f).isEqualTo(0.0f, byLessThan(0.1f)); // strict => fail
.isEqualTo(8.0f, within(0.2f))
.isEqualTo(8.0f, offset(0.2f))
// alias of within
.isEqualTo(8.0f, byLessThan(0.2f)); assertThat(0.1f)
.isCloseTo(8.0f, byLessThan(0.2f));
assertThat(0.1f)
// strict
// assertions succeed when the difference == offset value ...
.isEqualTo(0.0f, within(0.1f))
.isEqualTo(0.0f, offset(0.1f));
.isCloseTo(0.0f, offset(0.1f));

assertThat(5)
.isCloseTo(7, within(3))
Expand Down Expand Up @@ -298,7 +298,7 @@ public void isNotCloseTo_examples() {

@Test
public void number_assertions_with_binary_representation_examples() {
assertThat(1).inBinary().isEqualTo(1);
assertThat(1).inBinary().isOne();
try {
assertThat(1).inBinary().isEqualTo(2);
} catch (AssertionError e) {
Expand Down Expand Up @@ -358,7 +358,7 @@ public void should_consider_primitive_negative_zero_as_zero_fixing_issue_919() {

@Test
public void should_handle_NaN_and_infinity_correctly_fixing_issue_984() {
assertThat(Double.NaN == Double.NaN).isFalse();
assertThat(Double.NaN).isNotSameAs(Double.NaN);
// https://github.com/joel-costigliola/assertj-core/issues/1775
// assertThat(Double.NaN).isNotEqualTo(Double.NaN);
assertThat(Double.POSITIVE_INFINITY).isEqualTo(Double.POSITIVE_INFINITY);
Expand Down
Loading