Search in sources :

Example 11 with DoublePredicate

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

the class DoublePredicateAssert_rejects_Test method should_pass_when_predicate_does_not_accept_value.

@Test
public void should_pass_when_predicate_does_not_accept_value() {
    DoublePredicate predicate = val -> val <= 2;
    assertThat(predicate).rejects(3.0);
}
Also used : DoublePredicateAssert(org.assertj.core.api.DoublePredicateAssert) 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) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) DoubleStream(java.util.stream.DoubleStream) List(java.util.List) DoublePredicateAssertBaseTest(org.assertj.core.api.DoublePredicateAssertBaseTest) DoublePredicate(java.util.function.DoublePredicate) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) DoublePredicate(java.util.function.DoublePredicate) Test(org.junit.Test) DoublePredicateAssertBaseTest(org.assertj.core.api.DoublePredicateAssertBaseTest)

Example 12 with DoublePredicate

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

the class DoublePredicateAssert_rejects_Test method should_fail_when_predicate_accepts_some_value.

@Test
public void should_fail_when_predicate_accepts_some_value() {
    DoublePredicate predicate = num -> num <= 2;
    double[] matchValues = new double[] { 1.0, 2.0, 3.0 };
    List<Double> matchValuesList = DoubleStream.of(matchValues).boxed().collect(Collectors.toList());
    thrown.expectAssertionError(noElementsShouldMatch(matchValuesList, 1D, PredicateDescription.GIVEN).create());
    assertThat(predicate).rejects(matchValues);
}
Also used : DoublePredicateAssert(org.assertj.core.api.DoublePredicateAssert) 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) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) DoubleStream(java.util.stream.DoubleStream) List(java.util.List) DoublePredicateAssertBaseTest(org.assertj.core.api.DoublePredicateAssertBaseTest) DoublePredicate(java.util.function.DoublePredicate) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) DoublePredicate(java.util.function.DoublePredicate) Test(org.junit.Test) DoublePredicateAssertBaseTest(org.assertj.core.api.DoublePredicateAssertBaseTest)

Example 13 with DoublePredicate

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

the class DoublePredicateAssert_rejects_Test method should_fail_when_predicate_accepts_value.

@Test
public void should_fail_when_predicate_accepts_value() {
    DoublePredicate predicate = val -> val <= 2;
    Predicate<Double> wrapPredicate = predicate::test;
    double expectedValue = 2.0;
    thrown.expectAssertionError(shouldNotAccept(wrapPredicate, expectedValue, PredicateDescription.GIVEN).create());
    assertThat(predicate).rejects(expectedValue);
}
Also used : DoublePredicateAssert(org.assertj.core.api.DoublePredicateAssert) 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) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) DoubleStream(java.util.stream.DoubleStream) List(java.util.List) DoublePredicateAssertBaseTest(org.assertj.core.api.DoublePredicateAssertBaseTest) DoublePredicate(java.util.function.DoublePredicate) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) DoublePredicate(java.util.function.DoublePredicate) Test(org.junit.Test) DoublePredicateAssertBaseTest(org.assertj.core.api.DoublePredicateAssertBaseTest)

Example 14 with DoublePredicate

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

the class DoublePredicateAssert_accepts_Test method should_fail_when_predicate_does_not_accept_all_values.

@Test
public void should_fail_when_predicate_does_not_accept_all_values() {
    DoublePredicate predicate = val -> val <= 2;
    double[] matchValues = new double[] { 1.0, 2.0, 3.0 };
    thrown.expectAssertionError(elementsShouldMatch(matchValues, 3D, PredicateDescription.GIVEN).create());
    assertThat(predicate).accepts(matchValues);
}
Also used : DoublePredicateAssert(org.assertj.core.api.DoublePredicateAssert) DoublePredicateAssertBaseTest(org.assertj.core.api.DoublePredicateAssertBaseTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PredicateDescription(org.assertj.core.presentation.PredicateDescription) FailureMessages.actualIsNull(org.assertj.core.util.FailureMessages.actualIsNull) Test(org.junit.Test) DoublePredicate(java.util.function.DoublePredicate) Lists.newArrayList(org.assertj.core.util.Lists.newArrayList) ElementsShouldMatch.elementsShouldMatch(org.assertj.core.error.ElementsShouldMatch.elementsShouldMatch) Mockito.verify(org.mockito.Mockito.verify) DoublePredicate(java.util.function.DoublePredicate) DoublePredicateAssertBaseTest(org.assertj.core.api.DoublePredicateAssertBaseTest) Test(org.junit.Test)

Example 15 with DoublePredicate

use of java.util.function.DoublePredicate in project j2objc by google.

the class DoublePredicateTest method testNegate.

public void testNegate() throws Exception {
    double arg = 5.0d;
    DoublePredicate alwaysTrue = x -> {
        assertEquals(x, arg);
        return true;
    };
    assertFalse(alwaysTrue.negate().test(arg));
    DoublePredicate alwaysFalse = x -> {
        assertEquals(x, arg);
        return false;
    };
    assertTrue(alwaysFalse.negate().test(arg));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestCase(junit.framework.TestCase) DoublePredicate(java.util.function.DoublePredicate) DoublePredicate(java.util.function.DoublePredicate)

Aggregations

DoublePredicate (java.util.function.DoublePredicate)18 Test (org.junit.Test)11 Predicate (java.util.function.Predicate)9 List (java.util.List)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 DoublePredicateAssert (org.assertj.core.api.DoublePredicateAssert)7 DoublePredicateAssertBaseTest (org.assertj.core.api.DoublePredicateAssertBaseTest)7 PredicateDescription (org.assertj.core.presentation.PredicateDescription)7 FailureMessages.actualIsNull (org.assertj.core.util.FailureMessages.actualIsNull)7 Lists.newArrayList (org.assertj.core.util.Lists.newArrayList)7 Mockito.verify (org.mockito.Mockito.verify)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 IntPredicate (java.util.function.IntPredicate)5 Collectors (java.util.stream.Collectors)5 DoubleStream (java.util.stream.DoubleStream)5 TestCase (junit.framework.TestCase)5 NoElementsShouldMatch.noElementsShouldMatch (org.assertj.core.error.NoElementsShouldMatch.noElementsShouldMatch)5 ShouldNotAccept.shouldNotAccept (org.assertj.core.error.ShouldNotAccept.shouldNotAccept)5 File (java.io.File)4 URI (java.net.URI)4