Search in sources :

Example 61 with Predicate

use of java.util.function.Predicate in project assertj-core by joel-costigliola.

the class IntPredicateAssert_rejects_Test method should_fail_when_predicate_accepts_some_value.

@Test
public void should_fail_when_predicate_accepts_some_value() {
    IntPredicate predicate = num -> num <= 2;
    int[] matchValues = new int[] { 1, 2, 3 };
    List<Integer> matchValuesList = IntStream.of(matchValues).boxed().collect(Collectors.toList());
    thrown.expectAssertionError(noElementsShouldMatch(matchValuesList, 1, PredicateDescription.GIVEN).create());
    assertThat(predicate).rejects(matchValues);
}
Also used : IntStream(java.util.stream.IntStream) IntPredicateAssert(org.assertj.core.api.IntPredicateAssert) NoElementsShouldMatch.noElementsShouldMatch(org.assertj.core.error.NoElementsShouldMatch.noElementsShouldMatch) Predicate(java.util.function.Predicate) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PredicateDescription(org.assertj.core.presentation.PredicateDescription) ShouldNotAccept.shouldNotAccept(org.assertj.core.error.ShouldNotAccept.shouldNotAccept) FailureMessages.actualIsNull(org.assertj.core.util.FailureMessages.actualIsNull) Test(org.junit.Test) IntPredicate(java.util.function.IntPredicate) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) IntPredicateAssertBaseTest(org.assertj.core.api.IntPredicateAssertBaseTest) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) IntPredicate(java.util.function.IntPredicate) Test(org.junit.Test) IntPredicateAssertBaseTest(org.assertj.core.api.IntPredicateAssertBaseTest)

Example 62 with Predicate

use of java.util.function.Predicate 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 63 with Predicate

use of java.util.function.Predicate in project assertj-core by joel-costigliola.

the class SoftAssertionsPerfTest method should_be_able_to_catch_exceptions_thrown_by_all_proxied_methods.

@SuppressWarnings("unchecked")
@Test
public void should_be_able_to_catch_exceptions_thrown_by_all_proxied_methods() throws URISyntaxException {
    try {
        softly.assertThat(BigDecimal.ZERO).isEqualTo(BigDecimal.ONE);
        softly.assertThat(Boolean.FALSE).isTrue();
        softly.assertThat(false).isTrue();
        softly.assertThat(new boolean[] { false }).isEqualTo(new boolean[] { true });
        softly.assertThat(new Byte((byte) 0)).isEqualTo((byte) 1);
        softly.assertThat((byte) 2).inHexadecimal().isEqualTo((byte) 3);
        softly.assertThat(new byte[] { 4 }).isEqualTo(new byte[] { 5 });
        softly.assertThat(new Character((char) 65)).isEqualTo(new Character((char) 66));
        softly.assertThat((char) 67).isEqualTo((char) 68);
        softly.assertThat(new char[] { 69 }).isEqualTo(new char[] { 70 });
        softly.assertThat(new StringBuilder("a")).isEqualTo(new StringBuilder("b"));
        softly.assertThat(Object.class).isEqualTo(String.class);
        softly.assertThat(parseDatetime("1999-12-31T23:59:59")).isEqualTo(parseDatetime("2000-01-01T00:00:01"));
        softly.assertThat(new Double(6.0d)).isEqualTo(new Double(7.0d));
        softly.assertThat(8.0d).isEqualTo(9.0d);
        softly.assertThat(new double[] { 10.0d }).isEqualTo(new double[] { 11.0d });
        softly.assertThat(new File("a")).overridingErrorMessage("expected:<File(b)> but was:<File(a)>").isEqualTo(new File("b"));
        softly.assertThat(new Float(12f)).isEqualTo(new Float(13f));
        softly.assertThat(14f).isEqualTo(15f);
        softly.assertThat(new float[] { 16f }).isEqualTo(new float[] { 17f });
        softly.assertThat(new ByteArrayInputStream(new byte[] { (byte) 65 })).hasSameContentAs(new ByteArrayInputStream(new byte[] { (byte) 66 }));
        softly.assertThat(new Integer(20)).isEqualTo(new Integer(21));
        softly.assertThat(22).isEqualTo(23);
        softly.assertThat(new int[] { 24 }).isEqualTo(new int[] { 25 });
        softly.assertThat((Iterable<String>) Lists.newArrayList("26")).isEqualTo(Lists.newArrayList("27"));
        softly.assertThat(Lists.newArrayList("28").iterator()).contains("29");
        softly.assertThat(Lists.newArrayList("30")).isEqualTo(Lists.newArrayList("31"));
        softly.assertThat(new Long(32L)).isEqualTo(new Long(33L));
        softly.assertThat(34L).isEqualTo(35L);
        softly.assertThat(new long[] { 36L }).isEqualTo(new long[] { 37L });
        softly.assertThat(mapOf(MapEntry.entry("38", "39"))).isEqualTo(mapOf(MapEntry.entry("40", "41")));
        softly.assertThat(new Short((short) 42)).isEqualTo(new Short((short) 43));
        softly.assertThat((short) 44).isEqualTo((short) 45);
        softly.assertThat(new short[] { (short) 46 }).isEqualTo(new short[] { (short) 47 });
        softly.assertThat("48").isEqualTo("49");
        softly.assertThat(new Object() {

            @Override
            public String toString() {
                return "50";
            }
        }).isEqualTo(new Object() {

            @Override
            public String toString() {
                return "51";
            }
        });
        softly.assertThat(new Object[] { new Object() {

            @Override
            public String toString() {
                return "52";
            }
        } }).isEqualTo(new Object[] { new Object() {

            @Override
            public String toString() {
                return "53";
            }
        } });
        final IllegalArgumentException illegalArgumentException = new IllegalArgumentException("IllegalArgumentException message");
        softly.assertThat(illegalArgumentException).hasMessage("NullPointerException message");
        softly.assertThatThrownBy(new ThrowingCallable() {

            @Override
            public void call() throws Exception {
                throw new Exception("something was wrong");
            }
        }).hasMessage("something was good");
        softly.assertThat(mapOf(MapEntry.entry("54", "55"))).contains(MapEntry.entry("1", "2"));
        softly.assertThat(LocalTime.of(12, 00)).isEqualTo(LocalTime.of(13, 00));
        softly.assertThat(OffsetTime.of(12, 0, 0, 0, ZoneOffset.UTC)).isEqualTo(OffsetTime.of(13, 0, 0, 0, ZoneOffset.UTC));
        softly.assertThat(Optional.of("not empty")).isEqualTo("empty");
        softly.assertThat(OptionalInt.of(0)).isEqualTo(1);
        softly.assertThat(OptionalDouble.of(0.0)).isEqualTo(1.0);
        softly.assertThat(OptionalLong.of(0L)).isEqualTo(1L);
        softly.assertThat(new URI("http://assertj.org")).hasPort(8888);
        softly.assertThat(CompletableFuture.completedFuture("done")).hasFailed();
        softly.assertThat((Predicate<String>) s -> s.equals("something")).accepts("something else");
        softly.assertThat((IntPredicate) s -> s == 1).accepts(2);
        softly.assertThat((LongPredicate) s -> s == 1).accepts(2);
        softly.assertThat((DoublePredicate) s -> s == 1).accepts(2);
        softly.assertAll();
        fail("Should not reach here");
    } catch (SoftAssertionError e) {
        List<String> errors = e.getErrors();
        assertThat(errors).hasSize(52);
        assertThat(errors.get(0)).startsWith("expected:<[1]> but was:<[0]>");
        assertThat(errors.get(1)).startsWith("expected:<[tru]e> but was:<[fals]e>");
        assertThat(errors.get(2)).startsWith("expected:<[tru]e> but was:<[fals]e>");
        assertThat(errors.get(3)).startsWith("expected:<[[tru]e]> but was:<[[fals]e]>");
        assertThat(errors.get(4)).startsWith("expected:<[1]> but was:<[0]>");
        assertThat(errors.get(5)).startsWith("expected:<0x0[3]> but was:<0x0[2]>");
        assertThat(errors.get(6)).startsWith("expected:<[[5]]> but was:<[[4]]>");
        assertThat(errors.get(7)).startsWith("expected:<'[B]'> but was:<'[A]'>");
        assertThat(errors.get(8)).startsWith("expected:<'[D]'> but was:<'[C]'>");
        assertThat(errors.get(9)).startsWith("expected:<['[F]']> but was:<['[E]']>");
        assertThat(errors.get(10)).startsWith("expected:<[b]> but was:<[a]>");
        assertThat(errors.get(11)).startsWith("expected:<java.lang.[String]> but was:<java.lang.[Object]>");
        assertThat(errors.get(12)).startsWith("expected:<[2000-01-01T00:00:01].000> but was:<[1999-12-31T23:59:59].000>");
        assertThat(errors.get(13)).startsWith("expected:<[7].0> but was:<[6].0>");
        assertThat(errors.get(14)).startsWith("expected:<[9].0> but was:<[8].0>");
        assertThat(errors.get(15)).startsWith("expected:<[1[1].0]> but was:<[1[0].0]>");
        assertThat(errors.get(16)).startsWith("expected:<File(b)> but was:<File(a)>");
        assertThat(errors.get(17)).startsWith("expected:<1[3].0f> but was:<1[2].0f>");
        assertThat(errors.get(18)).startsWith("expected:<1[5].0f> but was:<1[4].0f>");
        assertThat(errors.get(19)).startsWith("expected:<[1[7].0f]> but was:<[1[6].0f]>");
        assertThat(errors.get(20)).startsWith(format("%nInputStreams do not have same content:%n%n" + "Changed content at line 1:%n" + "expecting:%n" + "  [\"B\"]%n" + "but was:%n" + "  [\"A\"]%n"));
        assertThat(errors.get(21)).startsWith("expected:<2[1]> but was:<2[0]>");
        assertThat(errors.get(22)).startsWith("expected:<2[3]> but was:<2[2]>");
        assertThat(errors.get(23)).startsWith("expected:<[2[5]]> but was:<[2[4]]>");
        assertThat(errors.get(24)).startsWith("expected:<[\"2[7]\"]> but was:<[\"2[6]\"]>");
        assertThat(errors.get(25)).startsWith(format("%nExpecting:%n" + " <[\"28\"]>%n" + "to contain:%n" + " <[\"29\"]>%n" + "but could not find:%n" + " <[\"29\"]>%n"));
        assertThat(errors.get(26)).startsWith("expected:<[\"3[1]\"]> but was:<[\"3[0]\"]>");
        assertThat(errors.get(27)).startsWith("expected:<3[3]L> but was:<3[2]L>");
        assertThat(errors.get(28)).startsWith("expected:<3[5]L> but was:<3[4]L>");
        assertThat(errors.get(29)).startsWith("expected:<[3[7]L]> but was:<[3[6]L]>");
        assertThat(errors.get(30)).startsWith("expected:<{\"[40\"=\"41]\"}> but was:<{\"[38\"=\"39]\"}>");
        assertThat(errors.get(31)).startsWith("expected:<4[3]> but was:<4[2]>");
        assertThat(errors.get(32)).startsWith("expected:<4[5]> but was:<4[4]>");
        assertThat(errors.get(33)).startsWith("expected:<[4[7]]> but was:<[4[6]]>");
        assertThat(errors.get(34)).startsWith("expected:<\"4[9]\"> but was:<\"4[8]\">");
        assertThat(errors.get(35)).startsWith("expected:<5[1]> but was:<5[0]>");
        assertThat(errors.get(36)).startsWith("expected:<[5[3]]> but was:<[5[2]]>");
        assertThat(errors.get(37)).startsWith(format("%nExpecting message:%n" + " <\"NullPointerException message\">%n" + "but was:%n" + " <\"IllegalArgumentException message\">"));
        assertThat(errors.get(38)).startsWith(format("%nExpecting message:%n" + " <\"something was good\">%n" + "but was:%n" + " <\"something was wrong\">"));
        assertThat(errors.get(39)).startsWith(format("%nExpecting:%n" + " <{\"54\"=\"55\"}>%n" + "to contain:%n" + " <[MapEntry[key=\"1\", value=\"2\"]]>%n" + "but could not find:%n" + " <[MapEntry[key=\"1\", value=\"2\"]]>%n"));
        assertThat(errors.get(40)).startsWith("expected:<1[3]:00> but was:<1[2]:00>");
        assertThat(errors.get(41)).startsWith("expected:<1[3]:00Z> but was:<1[2]:00Z>");
        assertThat(errors.get(42)).startsWith("expected:<[\"empty\"]> but was:<[Optional[not empty]]>");
        assertThat(errors.get(43)).startsWith("expected:<[1]> but was:<[OptionalInt[0]]>");
        assertThat(errors.get(44)).startsWith("expected:<[1.0]> but was:<[OptionalDouble[0.0]]>");
        assertThat(errors.get(45)).startsWith("expected:<[1L]> but was:<[OptionalLong[0]]>");
        assertThat(errors.get(46)).contains("Expecting port of");
        assertThat(errors.get(47)).contains("to have failed");
        assertThat(errors.get(48)).startsWith(format("%nExpecting:%n  <given predicate>%n" + "to accept <\"something else\"> but it did not."));
        assertThat(errors.get(49)).startsWith(format("%nExpecting:%n  <given predicate>%n" + "to accept <2> but it did not."));
        assertThat(errors.get(50)).startsWith(format("%nExpecting:%n  <given predicate>%n" + "to accept <2L> but it did not."));
        assertThat(errors.get(51)).startsWith(format("%nExpecting:%n  <given predicate>%n" + "to accept <2.0> but it did not."));
    }
}
Also used : CartoonCharacter(org.assertj.core.test.CartoonCharacter) IntPredicate(java.util.function.IntPredicate) DoublePredicate(java.util.function.DoublePredicate) OptionalDouble(java.util.OptionalDouble) URI(java.net.URI) LongPredicate(java.util.function.LongPredicate) URISyntaxException(java.net.URISyntaxException) IntPredicate(java.util.function.IntPredicate) LongPredicate(java.util.function.LongPredicate) Predicate(java.util.function.Predicate) DoublePredicate(java.util.function.DoublePredicate) ByteArrayInputStream(java.io.ByteArrayInputStream) ThrowingCallable(org.assertj.core.api.ThrowableAssert.ThrowingCallable) OptionalLong(java.util.OptionalLong) Arrays.asList(java.util.Arrays.asList) List(java.util.List) File(java.io.File) SoftAssertionError(org.assertj.core.api.SoftAssertionError) BaseAssertionsTest(org.assertj.core.api.BaseAssertionsTest) Test(org.junit.Test)

Example 64 with Predicate

use of java.util.function.Predicate in project assertj-core by joel-costigliola.

the class BDDSoftAssertionsTest method should_be_able_to_catch_exceptions_thrown_by_all_proxied_methods.

@SuppressWarnings("unchecked")
@Test
public void should_be_able_to_catch_exceptions_thrown_by_all_proxied_methods() throws URISyntaxException {
    try {
        softly.then(BigDecimal.ZERO).isEqualTo(BigDecimal.ONE);
        softly.then(Boolean.FALSE).isTrue();
        softly.then(false).isTrue();
        softly.then(new boolean[] { false }).isEqualTo(new boolean[] { true });
        softly.then(new Byte((byte) 0)).isEqualTo((byte) 1);
        softly.then((byte) 2).inHexadecimal().isEqualTo((byte) 3);
        softly.then(new byte[] { 4 }).isEqualTo(new byte[] { 5 });
        softly.then(new Character((char) 65)).isEqualTo(new Character((char) 66));
        softly.then((char) 67).isEqualTo((char) 68);
        softly.then(new char[] { 69 }).isEqualTo(new char[] { 70 });
        softly.then(new StringBuilder("a")).isEqualTo(new StringBuilder("b"));
        softly.then(Object.class).isEqualTo(String.class);
        softly.then(parseDatetime("1999-12-31T23:59:59")).isEqualTo(parseDatetime("2000-01-01T00:00:01"));
        softly.then(new Double(6.0d)).isEqualTo(new Double(7.0d));
        softly.then(8.0d).isEqualTo(9.0d);
        softly.then(new double[] { 10.0d }).isEqualTo(new double[] { 11.0d });
        softly.then(new File("a")).overridingErrorMessage("expected:<File(b)> but was:<File(a)>").isEqualTo(new File("b"));
        softly.then(new Float(12f)).isEqualTo(new Float(13f));
        softly.then(14f).isEqualTo(15f);
        softly.then(new float[] { 16f }).isEqualTo(new float[] { 17f });
        softly.then(new ByteArrayInputStream(new byte[] { (byte) 65 })).hasSameContentAs(new ByteArrayInputStream(new byte[] { (byte) 66 }));
        softly.then(new Integer(20)).isEqualTo(new Integer(21));
        softly.then(22).isEqualTo(23);
        softly.then(new int[] { 24 }).isEqualTo(new int[] { 25 });
        softly.then((Iterable<String>) Lists.newArrayList("26")).isEqualTo(Lists.newArrayList("27"));
        softly.then(Lists.newArrayList("28").iterator()).contains("29");
        softly.then(Lists.newArrayList("30")).isEqualTo(Lists.newArrayList("31"));
        softly.then(new Long(32L)).isEqualTo(new Long(33L));
        softly.then(34L).isEqualTo(35L);
        softly.then(new long[] { 36L }).isEqualTo(new long[] { 37L });
        softly.then(mapOf(MapEntry.entry("38", "39"))).isEqualTo(mapOf(MapEntry.entry("40", "41")));
        softly.then(new Short((short) 42)).isEqualTo(new Short((short) 43));
        softly.then((short) 44).isEqualTo((short) 45);
        softly.then(new short[] { (short) 46 }).isEqualTo(new short[] { (short) 47 });
        softly.then("48").isEqualTo("49");
        softly.then(new Object() {

            @Override
            public String toString() {
                return "50";
            }
        }).isEqualTo(new Object() {

            @Override
            public String toString() {
                return "51";
            }
        });
        softly.then(new Object[] { new Object() {

            @Override
            public String toString() {
                return "52";
            }
        } }).isEqualTo(new Object[] { new Object() {

            @Override
            public String toString() {
                return "53";
            }
        } });
        final IllegalArgumentException illegalArgumentException = new IllegalArgumentException("IllegalArgumentException message");
        softly.then(illegalArgumentException).hasMessage("NullPointerException message");
        softly.thenThrownBy(new ThrowingCallable() {

            @Override
            public void call() throws Exception {
                throw new Exception("something was wrong");
            }
        }).hasMessage("something was good");
        softly.then(mapOf(MapEntry.entry("54", "55"))).contains(MapEntry.entry("1", "2"));
        softly.then(LocalTime.of(12, 00)).isEqualTo(LocalTime.of(13, 00));
        softly.then(OffsetTime.of(12, 0, 0, 0, ZoneOffset.UTC)).isEqualTo(OffsetTime.of(13, 0, 0, 0, ZoneOffset.UTC));
        softly.then(Optional.of("not empty")).isEqualTo("empty");
        softly.then(OptionalInt.of(0)).isEqualTo(1);
        softly.then(OptionalDouble.of(0.0)).isEqualTo(1.0);
        softly.then(OptionalLong.of(0L)).isEqualTo(1L);
        softly.then(new URI("http://assertj.org")).hasPort(8888);
        softly.then(CompletableFuture.completedFuture("done")).hasFailed();
        softly.then((Predicate<String>) s -> s.equals("something")).accepts("something else");
        softly.then((IntPredicate) s -> s == 1).accepts(2);
        softly.then((LongPredicate) s -> s == 1).accepts(2);
        softly.then((DoublePredicate) s -> s == 1).accepts(2);
        softly.assertAll();
        fail("Should not reach here");
    } catch (SoftAssertionError e) {
        List<String> errors = e.getErrors();
        assertThat(errors).hasSize(52);
        assertThat(errors.get(0)).startsWith("expected:<[1]> but was:<[0]>");
        assertThat(errors.get(1)).startsWith("expected:<[tru]e> but was:<[fals]e>");
        assertThat(errors.get(2)).startsWith("expected:<[tru]e> but was:<[fals]e>");
        assertThat(errors.get(3)).startsWith("expected:<[[tru]e]> but was:<[[fals]e]>");
        assertThat(errors.get(4)).startsWith("expected:<[1]> but was:<[0]>");
        assertThat(errors.get(5)).startsWith("expected:<0x0[3]> but was:<0x0[2]>");
        assertThat(errors.get(6)).startsWith("expected:<[[5]]> but was:<[[4]]>");
        assertThat(errors.get(7)).startsWith("expected:<'[B]'> but was:<'[A]'>");
        assertThat(errors.get(8)).startsWith("expected:<'[D]'> but was:<'[C]'>");
        assertThat(errors.get(9)).startsWith("expected:<['[F]']> but was:<['[E]']>");
        assertThat(errors.get(10)).startsWith("expected:<[b]> but was:<[a]>");
        assertThat(errors.get(11)).startsWith("expected:<java.lang.[String]> but was:<java.lang.[Object]>");
        assertThat(errors.get(12)).startsWith("expected:<[2000-01-01T00:00:01].000> but was:<[1999-12-31T23:59:59].000>");
        assertThat(errors.get(13)).startsWith("expected:<[7].0> but was:<[6].0>");
        assertThat(errors.get(14)).startsWith("expected:<[9].0> but was:<[8].0>");
        assertThat(errors.get(15)).startsWith("expected:<[1[1].0]> but was:<[1[0].0]>");
        assertThat(errors.get(16)).startsWith("expected:<File(b)> but was:<File(a)>");
        assertThat(errors.get(17)).startsWith("expected:<1[3].0f> but was:<1[2].0f>");
        assertThat(errors.get(18)).startsWith("expected:<1[5].0f> but was:<1[4].0f>");
        assertThat(errors.get(19)).startsWith("expected:<[1[7].0f]> but was:<[1[6].0f]>");
        assertThat(errors.get(20)).startsWith(format("%nInputStreams do not have same content:%n%n" + "Changed content at line 1:%n" + "expecting:%n" + "  [\"B\"]%n" + "but was:%n" + "  [\"A\"]%n"));
        assertThat(errors.get(21)).startsWith("expected:<2[1]> but was:<2[0]>");
        assertThat(errors.get(22)).startsWith("expected:<2[3]> but was:<2[2]>");
        assertThat(errors.get(23)).startsWith("expected:<[2[5]]> but was:<[2[4]]>");
        assertThat(errors.get(24)).startsWith("expected:<[\"2[7]\"]> but was:<[\"2[6]\"]>");
        assertThat(errors.get(25)).startsWith(format("%nExpecting:%n" + " <[\"28\"]>%n" + "to contain:%n" + " <[\"29\"]>%n" + "but could not find:%n" + " <[\"29\"]>%n"));
        assertThat(errors.get(26)).startsWith("expected:<[\"3[1]\"]> but was:<[\"3[0]\"]>");
        assertThat(errors.get(27)).startsWith("expected:<3[3]L> but was:<3[2]L>");
        assertThat(errors.get(28)).startsWith("expected:<3[5]L> but was:<3[4]L>");
        assertThat(errors.get(29)).startsWith("expected:<[3[7]L]> but was:<[3[6]L]>");
        assertThat(errors.get(30)).startsWith("expected:<{\"[40\"=\"41]\"}> but was:<{\"[38\"=\"39]\"}>");
        assertThat(errors.get(31)).startsWith("expected:<4[3]> but was:<4[2]>");
        assertThat(errors.get(32)).startsWith("expected:<4[5]> but was:<4[4]>");
        assertThat(errors.get(33)).startsWith("expected:<[4[7]]> but was:<[4[6]]>");
        assertThat(errors.get(34)).startsWith("expected:<\"4[9]\"> but was:<\"4[8]\">");
        assertThat(errors.get(35)).startsWith("expected:<5[1]> but was:<5[0]>");
        assertThat(errors.get(36)).startsWith("expected:<[5[3]]> but was:<[5[2]]>");
        assertThat(errors.get(37)).startsWith(format("%nExpecting message:%n" + " <\"NullPointerException message\">%n" + "but was:%n" + " <\"IllegalArgumentException message\">"));
        assertThat(errors.get(38)).startsWith(format("%nExpecting message:%n" + " <\"something was good\">%n" + "but was:%n" + " <\"something was wrong\">"));
        assertThat(errors.get(39)).startsWith(format("%nExpecting:%n" + " <{\"54\"=\"55\"}>%n" + "to contain:%n" + " <[MapEntry[key=\"1\", value=\"2\"]]>%n" + "but could not find:%n" + " <[MapEntry[key=\"1\", value=\"2\"]]>%n"));
        assertThat(errors.get(40)).startsWith("expected:<1[3]:00> but was:<1[2]:00>");
        assertThat(errors.get(41)).startsWith("expected:<1[3]:00Z> but was:<1[2]:00Z>");
        assertThat(errors.get(42)).startsWith("expected:<[\"empty\"]> but was:<[Optional[not empty]]>");
        assertThat(errors.get(43)).startsWith("expected:<[1]> but was:<[OptionalInt[0]]>");
        assertThat(errors.get(44)).startsWith("expected:<[1.0]> but was:<[OptionalDouble[0.0]]>");
        assertThat(errors.get(45)).startsWith("expected:<[1L]> but was:<[OptionalLong[0]]>");
        assertThat(errors.get(46)).contains("Expecting port of");
        assertThat(errors.get(47)).contains("to have failed");
        assertThat(errors.get(48)).startsWith(format("%nExpecting:%n  <given predicate>%n" + "to accept <\"something else\"> but it did not."));
        assertThat(errors.get(49)).startsWith(format("%nExpecting:%n  <given predicate>%n" + "to accept <2> but it did not."));
        assertThat(errors.get(50)).startsWith(format("%nExpecting:%n  <given predicate>%n" + "to accept <2L> but it did not."));
        assertThat(errors.get(51)).startsWith(format("%nExpecting:%n  <given predicate>%n" + "to accept <2.0> but it did not."));
    }
}
Also used : CartoonCharacter(org.assertj.core.test.CartoonCharacter) IntPredicate(java.util.function.IntPredicate) DoublePredicate(java.util.function.DoublePredicate) OptionalDouble(java.util.OptionalDouble) URI(java.net.URI) LongPredicate(java.util.function.LongPredicate) URISyntaxException(java.net.URISyntaxException) IntPredicate(java.util.function.IntPredicate) LongPredicate(java.util.function.LongPredicate) Predicate(java.util.function.Predicate) DoublePredicate(java.util.function.DoublePredicate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteArrayInputStream(java.io.ByteArrayInputStream) ThrowingCallable(org.assertj.core.api.ThrowableAssert.ThrowingCallable) OptionalLong(java.util.OptionalLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) Arrays.asList(java.util.Arrays.asList) List(java.util.List) File(java.io.File) Test(org.junit.Test)

Example 65 with Predicate

use of java.util.function.Predicate in project assertj-core by joel-costigliola.

the class WithAssertions_delegation_Test method withAssertions_assertThat_intPredicate_Test.

@Test
public void withAssertions_assertThat_intPredicate_Test() {
    IntPredicate predicate = i -> i == 0;
    assertThat(predicate).accepts(0);
}
Also used : Arrays(java.util.Arrays) BufferedInputStream(java.io.BufferedInputStream) URL(java.net.URL) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) ZonedDateTime(java.time.ZonedDateTime) LocalDateTime(java.time.LocalDateTime) OptionalDouble(java.util.OptionalDouble) HashMap(java.util.HashMap) OptionalInt(java.util.OptionalInt) IntPredicate(java.util.function.IntPredicate) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) OptionalLong(java.util.OptionalLong) URI(java.net.URI) LongPredicate(java.util.function.LongPredicate) DateFormat(java.text.DateFormat) AnyOf(org.assertj.core.condition.AnyOf) MalformedURLException(java.net.MalformedURLException) Predicate(java.util.function.Predicate) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) File(java.io.File) MapEntry(org.assertj.core.data.MapEntry) UncheckedIOException(java.io.UncheckedIOException) OffsetDateTime(java.time.OffsetDateTime) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) Sets.newLinkedHashSet(org.assertj.core.util.Sets.newLinkedHashSet) LocalDate(java.time.LocalDate) Optional(java.util.Optional) DoublePredicate(java.util.function.DoublePredicate) IntPredicate(java.util.function.IntPredicate) Test(org.junit.Test)

Aggregations

Predicate (java.util.function.Predicate)589 List (java.util.List)266 ArrayList (java.util.ArrayList)170 Collectors (java.util.stream.Collectors)167 Map (java.util.Map)164 Set (java.util.Set)137 Test (org.junit.Test)133 IOException (java.io.IOException)122 Collections (java.util.Collections)118 Arrays (java.util.Arrays)110 HashMap (java.util.HashMap)105 Collection (java.util.Collection)93 Optional (java.util.Optional)87 HashSet (java.util.HashSet)85 Stream (java.util.stream.Stream)69 Function (java.util.function.Function)61 File (java.io.File)60 Iterator (java.util.Iterator)55 Logger (org.slf4j.Logger)53 LoggerFactory (org.slf4j.LoggerFactory)52