Search in sources :

Example 1 with PredicateDescription

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

the class Iterables_assertAnyMatch_Test method should_fail_with_custom_description_if_predicate_is_met_by_no_element.

@Test
public void should_fail_with_custom_description_if_predicate_is_met_by_no_element() {
    List<String> actual = newArrayList("Luke", "Leia", "Yoda");
    Predicate<String> startsWithM = s -> s.startsWith("M");
    try {
        iterables.assertAnyMatch(info, actual, startsWithM, new PredicateDescription("custom"));
    } catch (AssertionError e) {
        verify(failures).failure(info, anyElementShouldMatch(actual, new PredicateDescription("custom")));
        return;
    }
    failBecauseExpectedAssertionErrorWasNotThrown();
}
Also used : TestFailures.failBecauseExpectedAssertionErrorWasNotThrown(org.assertj.core.test.TestFailures.failBecauseExpectedAssertionErrorWasNotThrown) List(java.util.List) AnyElementShouldMatch.anyElementShouldMatch(org.assertj.core.error.AnyElementShouldMatch.anyElementShouldMatch) IterablesBaseTest(org.assertj.core.internal.IterablesBaseTest) Predicate(java.util.function.Predicate) PredicateDescription(org.assertj.core.presentation.PredicateDescription) FailureMessages.actualIsNull(org.assertj.core.util.FailureMessages.actualIsNull) 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 2 with PredicateDescription

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

the class ShouldNotMatch_create_Test method should_create_error_message_with_predicate_description.

@Test
public void should_create_error_message_with_predicate_description() {
    ErrorMessageFactory factory = shouldNotMatch("Yoda", (String color) -> color.equals("green"), new PredicateDescription("green light saber"));
    String message = factory.create(new TextDescription("Test"), new StandardRepresentation());
    assertThat(message).isEqualTo(format("[Test] %nExpecting:%n  <\"Yoda\">%nnot to match 'green light saber' predicate."));
}
Also used : PredicateDescription(org.assertj.core.presentation.PredicateDescription) TextDescription(org.assertj.core.description.TextDescription) StandardRepresentation(org.assertj.core.presentation.StandardRepresentation) Test(org.junit.Test) BaseTest(org.assertj.core.api.BaseTest)

Example 3 with PredicateDescription

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

the class ShouldMatch_create_Test method should_create_error_message_with_predicate_description.

@Test
public void should_create_error_message_with_predicate_description() {
    ErrorMessageFactory factory = shouldMatch("Yoda", (String color) -> color.equals("green"), new PredicateDescription("green light saber"));
    String message = factory.create(new TextDescription("Test"), new StandardRepresentation());
    assertThat(message).isEqualTo(format("[Test] %nExpecting:%n  <\"Yoda\">%nto match 'green light saber' predicate."));
}
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 4 with PredicateDescription

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

the class ShouldAccept_create_Test method should_create_error_message_with_predicate_description.

@Test
public void should_create_error_message_with_predicate_description() {
    ErrorMessageFactory factory = shouldAccept((String color) -> color.equals("green"), "Yoda", new PredicateDescription("green light saber"));
    String message = factory.create(new TextDescription("Test"), new StandardRepresentation());
    assertThat(message).isEqualTo(format("[Test] %nExpecting:%n  <'green light saber' predicate>%nto accept <\"Yoda\"> but it did not."));
}
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 5 with PredicateDescription

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

the class ShouldNotAccept_create_Test method should_create_error_message_with_predicate_description.

@Test
public void should_create_error_message_with_predicate_description() {
    ErrorMessageFactory factory = shouldNotAccept((String color) -> color.equals("red"), "Yoda", new PredicateDescription("red light saber"));
    String message = factory.create(new TextDescription("Test"), new StandardRepresentation());
    assertThat(message).isEqualTo(format("[Test] %nExpecting:%n  <'red light saber' predicate>%nnot to accept <\"Yoda\"> but it 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)

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