public static LeaderInformationRegister merge(
            @Nullable LeaderInformationRegister leaderInformationRegister,
            String componentId,
            LeaderInformation leaderInformation) {
        final Map<String, LeaderInformation> existingLeaderInformation =
                new HashMap<>(
                        leaderInformationRegister == null
                                ? Collections.emptyMap()
                                : leaderInformationRegister.leaderInformationPerComponentId);
        if (leaderInformation.isEmpty()) {
            existingLeaderInformation.remove(componentId);
        } else {
            existingLeaderInformation.put(componentId, leaderInformation);
        }

        return new LeaderInformationRegister(existingLeaderInformation);
    }
@Test
    void testMerge() {
        final String componentId = "component-id";
        final LeaderInformation leaderInformation =
                LeaderInformation.known(UUID.randomUUID(), "address");

        final String newComponentId = "new-component-id";
        final LeaderInformation newLeaderInformation =
                LeaderInformation.known(UUID.randomUUID(), "new-address");

        final LeaderInformationRegister initialRegister =
                LeaderInformationRegister.of(componentId, leaderInformation);

        final LeaderInformationRegister newRegister =
                LeaderInformationRegister.merge(
                        initialRegister, newComponentId, newLeaderInformation);

        assertThat(newRegister).isNotSameAs(initialRegister);
        assertThat(newRegister.getRegisteredComponentIds())
                .containsExactlyInAnyOrder(componentId, newComponentId);
        assertThat(newRegister.forComponentId(componentId)).hasValue(leaderInformation);
        assertThat(newRegister.forComponentId(newComponentId)).hasValue(newLeaderInformation);
    }