Search in sources :

Example 76 with Predicate

use of java.util.function.Predicate in project junit5 by junit-team.

the class ParameterResolverTests method executeTestsForPotentiallyIncompatibleTypeMethodInjectionCases.

@Test
void executeTestsForPotentiallyIncompatibleTypeMethodInjectionCases() {
    ExecutionEventRecorder eventRecorder = executeTestsForClass(PotentiallyIncompatibleTypeMethodInjectionTestCase.class);
    assertEquals(3, eventRecorder.getTestStartedCount(), "# tests started");
    assertEquals(2, eventRecorder.getTestSuccessfulCount(), "# tests succeeded");
    assertEquals(1, eventRecorder.getTestFailedCount(), "# tests failed");
    // @formatter:off
    Predicate<String> expectations = s -> s.contains("NumberParameterResolver") && s.contains("resolved a value of type [java.lang.Integer]") && s.contains("but a value assignment compatible with [java.lang.Double] is required");
    assertRecordedExecutionEventsContainsExactly(eventRecorder.getFailedTestFinishedEvents(), event(test("doubleParameterInjection"), finishedWithFailure(allOf(isA(ParameterResolutionException.class), message(expectations)))));
// @formatter:on
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) DiscoverySelectors.selectMethod(org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod) BeforeEach(org.junit.jupiter.api.BeforeEach) CustomTypeParameterResolver(org.junit.jupiter.engine.execution.injection.sample.CustomTypeParameterResolver) ExecutionEventConditions.assertRecordedExecutionEventsContainsExactly(org.junit.platform.engine.test.event.ExecutionEventConditions.assertRecordedExecutionEventsContainsExactly) Assertions.allOf(org.assertj.core.api.Assertions.allOf) ExecutionEventConditions.test(org.junit.platform.engine.test.event.ExecutionEventConditions.test) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) CustomType(org.junit.jupiter.engine.execution.injection.sample.CustomType) NumberParameterResolver(org.junit.jupiter.engine.execution.injection.sample.NumberParameterResolver) Disabled(org.junit.jupiter.api.Disabled) TestExecutionResultConditions.isA(org.junit.platform.engine.test.event.TestExecutionResultConditions.isA) Nested(org.junit.jupiter.api.Nested) JupiterTestEngine(org.junit.jupiter.engine.JupiterTestEngine) AfterAll(org.junit.jupiter.api.AfterAll) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) CustomAnnotationParameterResolver(org.junit.jupiter.engine.execution.injection.sample.CustomAnnotationParameterResolver) BeforeAll(org.junit.jupiter.api.BeforeAll) AbstractJupiterTestEngineTests(org.junit.jupiter.engine.AbstractJupiterTestEngineTests) PrimitiveArrayParameterResolver(org.junit.jupiter.engine.execution.injection.sample.PrimitiveArrayParameterResolver) Map(java.util.Map) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) JAVA_8(org.junit.jupiter.api.condition.JRE.JAVA_8) DisabledOnJre(org.junit.jupiter.api.condition.DisabledOnJre) Method(java.lang.reflect.Method) LauncherDiscoveryRequestBuilder.request(org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request) ExecutionEventConditions.event(org.junit.platform.engine.test.event.ExecutionEventConditions.event) MapOfStringsParameterResolver(org.junit.jupiter.engine.execution.injection.sample.MapOfStringsParameterResolver) Predicate(java.util.function.Predicate) ParameterResolutionException(org.junit.jupiter.api.extension.ParameterResolutionException) ExecutionEventConditions.finishedWithFailure(org.junit.platform.engine.test.event.ExecutionEventConditions.finishedWithFailure) PrimitiveIntegerParameterResolver(org.junit.jupiter.engine.execution.injection.sample.PrimitiveIntegerParameterResolver) ReflectionUtils(org.junit.platform.commons.util.ReflectionUtils) TestExecutionResultConditions.message(org.junit.platform.engine.test.event.TestExecutionResultConditions.message) TestInfo(org.junit.jupiter.api.TestInfo) NullIntegerParameterResolver(org.junit.jupiter.engine.execution.injection.sample.NullIntegerParameterResolver) DisplayName(org.junit.jupiter.api.DisplayName) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CustomAnnotation(org.junit.jupiter.engine.execution.injection.sample.CustomAnnotation) ParameterResolver(org.junit.jupiter.api.extension.ParameterResolver) ExecutionEventRecorder(org.junit.platform.engine.test.event.ExecutionEventRecorder) Test(org.junit.jupiter.api.Test)

Example 77 with Predicate

use of java.util.function.Predicate in project data-prep by Talend.

the class NodeBuilderTest method should_create_filtered_node_as_source.

@Test
public void should_create_filtered_node_as_source() {
    // given
    final Predicate<DataSetRow> predicate = (dataSetRow) -> true;
    // when
    final Node node = NodeBuilder.filteredSource(predicate).build();
    // then
    assertThat(node, instanceOf(FilteredSourceNode.class));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Matchers.arrayContaining(org.hamcrest.Matchers.arrayContaining) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) Predicate(java.util.function.Predicate) FilteredSourceNode(org.talend.dataprep.transformation.pipeline.node.FilteredSourceNode) BasicLink(org.talend.dataprep.transformation.pipeline.link.BasicLink) Test(org.junit.Test) SourceNode(org.talend.dataprep.transformation.pipeline.node.SourceNode) TestLink(org.talend.dataprep.transformation.pipeline.TestLink) Node(org.talend.dataprep.transformation.pipeline.Node) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) CloneLink(org.talend.dataprep.transformation.pipeline.link.CloneLink) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) BasicNode(org.talend.dataprep.transformation.pipeline.node.BasicNode) ZipLink(org.talend.dataprep.transformation.pipeline.node.ZipLink) FilteredSourceNode(org.talend.dataprep.transformation.pipeline.node.FilteredSourceNode) SourceNode(org.talend.dataprep.transformation.pipeline.node.SourceNode) Node(org.talend.dataprep.transformation.pipeline.Node) BasicNode(org.talend.dataprep.transformation.pipeline.node.BasicNode) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) FilteredSourceNode(org.talend.dataprep.transformation.pipeline.node.FilteredSourceNode) Test(org.junit.Test)

Example 78 with Predicate

use of java.util.function.Predicate in project data-prep by Talend.

the class DummyCacheKey method getMatcher.

@Override
public Predicate<String> getMatcher() {
    final String regex = this.getClass().getSimpleName() + '_' + (name == null ? ".*" : name) + "_.*";
    final Pattern pattern = Pattern.compile(regex);
    return key -> pattern.matcher(key).matches();
}
Also used : Objects(java.util.Objects) ContentCacheKey(org.talend.dataprep.cache.ContentCacheKey) Predicate(java.util.function.Predicate) Random(java.util.Random) Pattern(java.util.regex.Pattern) Pattern(java.util.regex.Pattern)

Example 79 with Predicate

use of java.util.function.Predicate in project copybara by google.

the class GithubApiTest method getTransport.

@Override
public GitHubApiTransport getTransport() throws Exception {
    credentialsFile = Files.createTempFile("credentials", "test");
    Files.write(credentialsFile, "https://user:SECRET@github.com".getBytes(UTF_8));
    GitRepository repo = newBareRepo(Files.createTempDirectory("test_repo"), getGitEnv(), /*verbose=*/
    true).init().withCredentialHelper("store --file=" + credentialsFile);
    requestToResponse = new HashMap<>();
    requestValidators = new HashMap<>();
    httpTransport = new MockHttpTransport() {

        @Override
        public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
            String requestString = method + " " + url;
            MockLowLevelHttpRequest request = new MockLowLevelHttpRequest() {

                @Override
                public LowLevelHttpResponse execute() throws IOException {
                    Predicate<String> validator = requestValidators.get(method + " " + url);
                    if (validator != null) {
                        assertWithMessage("Request content did not match expected values.").that(validator.test(getContentAsString())).isTrue();
                    }
                    return super.execute();
                }
            };
            byte[] content = requestToResponse.get(requestString);
            MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
            if (content == null) {
                response.setContent(String.format("{ 'message' : 'This is not the repo you are looking for! %s %s'," + " 'documentation_url' : 'http://github.com/some_url'}", method, url));
                response.setStatusCode(404);
            } else {
                response.setContent(content);
            }
            request.setResponse(response);
            return request;
        }
    };
    return new GitHubApiTransportImpl(repo, httpTransport, "some_storage_file", new TestingConsole());
}
Also used : MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) MockLowLevelHttpResponse(com.google.api.client.testing.http.MockLowLevelHttpResponse) LowLevelHttpRequest(com.google.api.client.http.LowLevelHttpRequest) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest) IOException(java.io.IOException) MockLowLevelHttpRequest(com.google.api.client.testing.http.MockLowLevelHttpRequest) Predicate(java.util.function.Predicate) GitRepository(com.google.copybara.git.GitRepository) TestingConsole(com.google.copybara.util.console.testing.TestingConsole) MockLowLevelHttpResponse(com.google.api.client.testing.http.MockLowLevelHttpResponse) LowLevelHttpResponse(com.google.api.client.http.LowLevelHttpResponse)

Example 80 with Predicate

use of java.util.function.Predicate in project herddb by diennea.

the class ConcurrentMapKeyToPageIndex method scanner.

@Override
public Stream<Map.Entry<Bytes, Long>> scanner(IndexOperation operation, StatementEvaluationContext context, TableContext tableContext, herddb.core.AbstractIndexManager index) throws DataStorageManagerException {
    if (operation instanceof PrimaryIndexSeek) {
        PrimaryIndexSeek seek = (PrimaryIndexSeek) operation;
        byte[] seekValue = seek.value.computeNewValue(null, context, tableContext);
        if (seekValue == null) {
            return Stream.empty();
        }
        Bytes key = Bytes.from_array(seekValue);
        Long pageId = map.get(key);
        if (pageId == null) {
            return Stream.empty();
        }
        return Stream.of(new AbstractMap.SimpleImmutableEntry<>(key, pageId));
    }
    // every predicate (WHEREs...) will always be evaluated anyway on every record, in order to guarantee correctness
    if (index != null) {
        return index.recordSetScanner(operation, context, tableContext, this);
    }
    if (operation == null) {
        Stream<Map.Entry<Bytes, Long>> baseStream = map.entrySet().stream();
        return baseStream;
    } else if (operation instanceof PrimaryIndexPrefixScan) {
        PrimaryIndexPrefixScan scan = (PrimaryIndexPrefixScan) operation;
        byte[] prefix;
        try {
            prefix = scan.value.computeNewValue(null, context, tableContext);
        } catch (StatementExecutionException err) {
            throw new RuntimeException(err);
        }
        Predicate<Map.Entry<Bytes, Long>> predicate = (Map.Entry<Bytes, Long> t) -> {
            byte[] fullrecordKey = t.getKey().data;
            return Bytes.startsWith(fullrecordKey, prefix.length, prefix);
        };
        Stream<Map.Entry<Bytes, Long>> baseStream = map.entrySet().stream();
        return baseStream.filter(predicate);
    } else if (operation instanceof PrimaryIndexRangeScan) {
        byte[] refminvalue;
        PrimaryIndexRangeScan sis = (PrimaryIndexRangeScan) operation;
        SQLRecordKeyFunction minKey = sis.minValue;
        if (minKey != null) {
            refminvalue = minKey.computeNewValue(null, context, tableContext);
        } else {
            refminvalue = null;
        }
        byte[] refmaxvalue;
        SQLRecordKeyFunction maxKey = sis.maxValue;
        if (maxKey != null) {
            refmaxvalue = maxKey.computeNewValue(null, context, tableContext);
        } else {
            refmaxvalue = null;
        }
        Predicate<Map.Entry<Bytes, Long>> predicate;
        if (refminvalue != null && refmaxvalue == null) {
            predicate = (Map.Entry<Bytes, Long> entry) -> {
                byte[] datum = entry.getKey().data;
                return Bytes.compare(datum, refminvalue) >= 0;
            };
        } else if (refminvalue == null && refmaxvalue != null) {
            predicate = (Map.Entry<Bytes, Long> entry) -> {
                byte[] datum = entry.getKey().data;
                return Bytes.compare(datum, refmaxvalue) <= 0;
            };
        } else if (refminvalue != null && refmaxvalue != null) {
            predicate = (Map.Entry<Bytes, Long> entry) -> {
                byte[] datum = entry.getKey().data;
                return Bytes.compare(datum, refmaxvalue) <= 0 && Bytes.compare(datum, refminvalue) >= 0;
            };
        } else {
            predicate = (Map.Entry<Bytes, Long> entry) -> {
                return true;
            };
        }
        Stream<Map.Entry<Bytes, Long>> baseStream = map.entrySet().stream();
        return baseStream.filter(predicate);
    } else {
        throw new DataStorageManagerException("operation " + operation + " not implemented on " + this.getClass());
    }
}
Also used : DataStorageManagerException(herddb.storage.DataStorageManagerException) StatementExecutionException(herddb.model.StatementExecutionException) Predicate(java.util.function.Predicate) AbstractMap(java.util.AbstractMap) Bytes(herddb.utils.Bytes) AtomicLong(java.util.concurrent.atomic.AtomicLong) Stream(java.util.stream.Stream) SQLRecordKeyFunction(herddb.sql.SQLRecordKeyFunction) ConcurrentMap(java.util.concurrent.ConcurrentMap) AbstractMap(java.util.AbstractMap) Map(java.util.Map)

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