static Optional<Long> determineReplayIdFor(final SalesforceEndpoint endpoint, final String topicName) {
        final String channelName = getChannelName(topicName);

        final Long replayId = endpoint.getReplayId();

        final SalesforceComponent component = endpoint.getComponent();

        final SalesforceEndpointConfig endpointConfiguration = endpoint.getConfiguration();
        final Map<String, Long> endpointInitialReplayIdMap = endpointConfiguration.getInitialReplayIdMap();
        final Long endpointReplayId
                = endpointInitialReplayIdMap.getOrDefault(topicName, endpointInitialReplayIdMap.get(channelName));
        final Long endpointDefaultReplayId = endpointConfiguration.getDefaultReplayId();

        final SalesforceEndpointConfig componentConfiguration = component.getConfig();
        final Map<String, Long> componentInitialReplayIdMap = componentConfiguration.getInitialReplayIdMap();
        final Long componentReplayId
                = componentInitialReplayIdMap.getOrDefault(topicName, componentInitialReplayIdMap.get(channelName));
        final Long componentDefaultReplayId = componentConfiguration.getDefaultReplayId();

        // the endpoint values have priority over component values, and the
        // default values priority
        // over give topic values
        return Stream.of(replayId, endpointReplayId, componentReplayId, endpointDefaultReplayId, componentDefaultReplayId)
                .filter(Objects::nonNull).findFirst();
    }
@Test
    public void precedenceShouldBeFollowed() {
        final SalesforceEndpointConfig componentConfig = new SalesforceEndpointConfig();
        componentConfig.setDefaultReplayId(1L);
        componentConfig.setInitialReplayIdMap(Collections.singletonMap("my-topic-1", 2L));
        componentConfig.setInitialReplayIdMap(Collections.singletonMap("my-topic-2", 3L));

        final SalesforceEndpointConfig endpointConfig = new SalesforceEndpointConfig();
        endpointConfig.setDefaultReplayId(4L);
        endpointConfig.setInitialReplayIdMap(Collections.singletonMap("my-topic-1", 5L));

        final SalesforceComponent component = mock(SalesforceComponent.class);
        when(component.getConfig()).thenReturn(componentConfig);

        final SalesforceEndpoint endpoint = mock(SalesforceEndpoint.class);
        when(endpoint.getReplayId()).thenReturn(null);
        when(endpoint.getComponent()).thenReturn(component);
        when(endpoint.getConfiguration()).thenReturn(endpointConfig);

        assertEquals(Optional.of(5L), determineReplayIdFor(endpoint, "my-topic-1"),
                "Expecting replayId for `my-topic-1` to be 5, as endpoint configuration has priority");

        assertEquals(Optional.of(3L), determineReplayIdFor(endpoint, "my-topic-2"),
                "Expecting replayId for `my-topic-2` to be 3, as endpoint does not configure it");

        assertEquals(Optional.of(4L), determineReplayIdFor(endpoint, "my-topic-3"),
                "Expecting replayId for `my-topic-3` to be 4, as it is endpoint's default");

        endpointConfig.setDefaultReplayId(null);

        assertEquals(Optional.of(1L), determineReplayIdFor(endpoint, "my-topic-3"),
                "Expecting replayId for `my-topic-3` to be 1, as it is component's default when endpoint does not have a default");

        when(endpoint.getReplayId()).thenReturn(6L);

        assertEquals(Optional.of(6L), determineReplayIdFor(endpoint, "my-topic-1"),
                "Expecting replayId for `my-topic-1` to be 6, as it is endpoint configured explicitly on the endpoint");
        assertEquals(Optional.of(6L), determineReplayIdFor(endpoint, "my-topic-2"),
                "Expecting replayId for `my-topic-2` to be 6, as it is endpoint configured explicitly on the endpoint");
        assertEquals(Optional.of(6L), determineReplayIdFor(endpoint, "my-topic-3"),
                "Expecting replayId for `my-topic-3` to be 6, as it is endpoint configured explicitly on the endpoint");
    }