Search in sources :

Example 6 with PredicateDescription

use of org.assertj.core.presentation.PredicateDescription in project assertj-core by joel-costigliola.

the class Iterables_assertNoneMatch_Test method should_fail_with_custom_description_if_predicate_is_not_met.

@Test
public void should_fail_with_custom_description_if_predicate_is_not_met() {
    List<String> actual = newArrayList("Luke", "Leia", "Yoda");
    Predicate<? super String> predicate = s -> s.startsWith("L");
    try {
        iterables.assertNoneMatch(info, actual, predicate, new PredicateDescription("custom"));
    } catch (AssertionError e) {
        verify(failures).failure(info, noElementsShouldMatch(actual, "Luke", new PredicateDescription("custom")));
        return;
    }
    failBecauseExpectedAssertionErrorWasNotThrown();
}
Also used : TestFailures.failBecauseExpectedAssertionErrorWasNotThrown(org.assertj.core.test.TestFailures.failBecauseExpectedAssertionErrorWasNotThrown) List(java.util.List) IterablesBaseTest(org.assertj.core.internal.IterablesBaseTest) NoElementsShouldMatch.noElementsShouldMatch(org.assertj.core.error.NoElementsShouldMatch.noElementsShouldMatch) Predicate(java.util.function.Predicate) PredicateDescription(org.assertj.core.presentation.PredicateDescription) Test(org.junit.Test) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) TestData.someInfo(org.assertj.core.test.TestData.someInfo) Mockito.verify(org.mockito.Mockito.verify) PredicateDescription(org.assertj.core.presentation.PredicateDescription) IterablesBaseTest(org.assertj.core.internal.IterablesBaseTest) Test(org.junit.Test)

Example 7 with PredicateDescription

use of org.assertj.core.presentation.PredicateDescription in project assertj-core by joel-costigliola.

the class AnyElementsShouldMatch_create_Test method should_create_error_message.

@Test
public void should_create_error_message() {
    // GIVEN
    ErrorMessageFactory factory = anyElementShouldMatch(newArrayList("Luke", "Yoda"), new PredicateDescription("Yoda violates some restrictions"));
    // WHEN
    String message = factory.create(new TextDescription("Test"), new StandardRepresentation());
    // THEN
    assertThat(message).isEqualTo(format("[Test] %n" + "Expecting any elements of:%n" + "  <[\"Luke\", \"Yoda\"]>%n" + "to match 'Yoda violates some restrictions' predicate but none did."));
}
Also used : PredicateDescription(org.assertj.core.presentation.PredicateDescription) TextDescription(org.assertj.core.description.TextDescription) StandardRepresentation(org.assertj.core.presentation.StandardRepresentation) Test(org.junit.Test)

Example 8 with PredicateDescription

use of org.assertj.core.presentation.PredicateDescription in project assertj-core by joel-costigliola.

the class ElementsShouldMatch_create_Test method should_create_error_message_with_custom_description.

@Test
public void should_create_error_message_with_custom_description() {
    ErrorMessageFactory factory = elementsShouldMatch(newArrayList("Luke", "Yoda"), "Yoda", new PredicateDescription("custom"));
    String message = factory.create(new TextDescription("Test"), new StandardRepresentation());
    assertThat(message).isEqualTo(format("[Test] %n" + "Expecting all elements of:%n" + "  <[\"Luke\", \"Yoda\"]>%n" + "to match 'custom' predicate but this element did not:%n" + "  <\"Yoda\">"));
}
Also used : PredicateDescription(org.assertj.core.presentation.PredicateDescription) TextDescription(org.assertj.core.description.TextDescription) StandardRepresentation(org.assertj.core.presentation.StandardRepresentation) Test(org.junit.Test)

Example 9 with PredicateDescription

use of org.assertj.core.presentation.PredicateDescription in project assertj-core by joel-costigliola.

the class NoElementsShouldMatch_create_Test method should_create_error_message_with_custom_description.

@Test
public void should_create_error_message_with_custom_description() {
    ErrorMessageFactory factory = noElementsShouldMatch(newArrayList("Luke", "Yoda"), "Yoda", new PredicateDescription("custom"));
    String message = factory.create(new TextDescription("Test"), new StandardRepresentation());
    assertThat(message).isEqualTo(format("[Test] %n" + "Expecting no elements of:%n" + "  <[\"Luke\", \"Yoda\"]>%n" + "to match 'custom' predicate but this element did:%n" + "  <\"Yoda\">"));
}
Also used : PredicateDescription(org.assertj.core.presentation.PredicateDescription) TextDescription(org.assertj.core.description.TextDescription) StandardRepresentation(org.assertj.core.presentation.StandardRepresentation) Test(org.junit.Test)

Example 10 with PredicateDescription

use of org.assertj.core.presentation.PredicateDescription in project assertj-core by joel-costigliola.

the class Iterables_assertAllMatch_Test method should_fail_with_custom_description_if_predicate_is_not_met.

@Test
public void should_fail_with_custom_description_if_predicate_is_not_met() {
    List<String> actual = newArrayList("Luke", "Leia", "Yoda");
    Predicate<? super String> predicate = s -> s.startsWith("L");
    try {
        iterables.assertAllMatch(info, actual, predicate, new PredicateDescription("custom"));
    } catch (AssertionError e) {
        verify(failures).failure(info, elementsShouldMatch(actual, "Yoda", new PredicateDescription("custom")));
        return;
    }
    failBecauseExpectedAssertionErrorWasNotThrown();
}
Also used : TestFailures.failBecauseExpectedAssertionErrorWasNotThrown(org.assertj.core.test.TestFailures.failBecauseExpectedAssertionErrorWasNotThrown) List(java.util.List) IterablesBaseTest(org.assertj.core.internal.IterablesBaseTest) Predicate(java.util.function.Predicate) PredicateDescription(org.assertj.core.presentation.PredicateDescription) Test(org.junit.Test) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) ElementsShouldMatch.elementsShouldMatch(org.assertj.core.error.ElementsShouldMatch.elementsShouldMatch) TestData.someInfo(org.assertj.core.test.TestData.someInfo) Mockito.verify(org.mockito.Mockito.verify) PredicateDescription(org.assertj.core.presentation.PredicateDescription) IterablesBaseTest(org.assertj.core.internal.IterablesBaseTest) Test(org.junit.Test)

Aggregations

PredicateDescription (org.assertj.core.presentation.PredicateDescription)10 Test (org.junit.Test)10 TextDescription (org.assertj.core.description.TextDescription)7 StandardRepresentation (org.assertj.core.presentation.StandardRepresentation)7 List (java.util.List)3 Predicate (java.util.function.Predicate)3 IterablesBaseTest (org.assertj.core.internal.IterablesBaseTest)3 TestData.someInfo (org.assertj.core.test.TestData.someInfo)3 TestFailures.failBecauseExpectedAssertionErrorWasNotThrown (org.assertj.core.test.TestFailures.failBecauseExpectedAssertionErrorWasNotThrown)3 Lists.newArrayList (org.assertj.core.util.Lists.newArrayList)3 Mockito.verify (org.mockito.Mockito.verify)3 BaseTest (org.assertj.core.api.BaseTest)1 AnyElementShouldMatch.anyElementShouldMatch (org.assertj.core.error.AnyElementShouldMatch.anyElementShouldMatch)1 ElementsShouldMatch.elementsShouldMatch (org.assertj.core.error.ElementsShouldMatch.elementsShouldMatch)1 NoElementsShouldMatch.noElementsShouldMatch (org.assertj.core.error.NoElementsShouldMatch.noElementsShouldMatch)1 FailureMessages.actualIsNull (org.assertj.core.util.FailureMessages.actualIsNull)1