@VisibleForTesting
    @Nullable
    public UUID getLeaderSessionID(String componentId) {
        synchronized (lock) {
            return leaderContenderRegistry.containsKey(componentId)
                    ? confirmedLeaderInformation
                            .forComponentIdOrEmpty(componentId)
                            .getLeaderSessionID()
                    : null;
        }
    }
@Test
    void testOnGrantAndRevokeLeadership() throws Exception {
        final AtomicReference<LeaderInformationRegister> storedLeaderInformation =
                new AtomicReference<>(LeaderInformationRegister.empty());
        new Context(storedLeaderInformation) {
            {
                runTestWithSynchronousEventHandling(
                        () -> {
                            // grant leadership
                            final UUID leaderSessionID = UUID.randomUUID();
                            grantLeadership(leaderSessionID);

                            applyToBothContenderContexts(
                                    ctx -> {
                                        ctx.contender.waitForLeader();
                                        assertThat(ctx.contender.getLeaderSessionID())
                                                .isEqualTo(
                                                        leaderElectionService.getLeaderSessionID(
                                                                ctx.componentId))
                                                .isEqualTo(leaderSessionID);

                                        final LeaderInformation
                                                expectedLeaderInformationInHaBackend =
                                                        LeaderInformation.known(
                                                                leaderSessionID, ctx.address);
                                        assertThat(
                                                        storedLeaderInformation
                                                                .get()
                                                                .forComponentId(ctx.componentId))
                                                .as(
                                                        "The HA backend should have its leader information updated.")
                                                .hasValue(expectedLeaderInformationInHaBackend);
                                    });

                            revokeLeadership();

                            applyToBothContenderContexts(
                                    ctx -> {
                                        ctx.contender.waitForRevokeLeader();
                                        assertThat(ctx.contender.getLeaderSessionID()).isNull();
                                        assertThat(
                                                        leaderElectionService.getLeaderSessionID(
                                                                ctx.componentId))
                                                .isNull();

                                        final LeaderInformation
                                                expectedLeaderInformationInHaBackend =
                                                        LeaderInformation.known(
                                                                leaderSessionID, ctx.address);

                                        assertThat(
                                                        storedLeaderInformation
                                                                .get()
                                                                .forComponentId(ctx.componentId))
                                                .as(
                                                        "External storage is not touched by the leader session because the leadership is already lost.")
                                                .hasValue(expectedLeaderInformationInHaBackend);
                                    });
                        });
            }
        };
    }