CDSShardAccessImpl implements CDSShardAccess, LeaderLocationListener, AutoCloseable { @Override public LeaderLocation getLeaderLocation() { checkNotClosed(); return currentLeader; } CDSShardAccessImpl(final DOMDataTreeIdentifier prefix, final ActorUtils actorUtils); @Override DOMDataTreeIdentifier getShardIdentifier(); @Override LeaderLocation getLeaderLocation(); @Override CompletionStage<Void> makeLeaderLocal(); @Override LeaderLocationListenerRegistration<L> registerLeaderLocationListener(final L listener); @Override @SuppressWarnings("checkstyle:IllegalCatch") void onLeaderLocationChanged(final LeaderLocation location); @Override void close();  }
@Test @SuppressWarnings("checkstyle:IllegalCatch") public void testGetLeaderLocation() { assertEquals(shardAccess.getLeaderLocation(), LeaderLocation.UNKNOWN); shardAccess.onLeaderLocationChanged(LeaderLocation.LOCAL); assertEquals(shardAccess.getLeaderLocation(), LeaderLocation.LOCAL); shardAccess.onLeaderLocationChanged(LeaderLocation.REMOTE); shardAccess.onLeaderLocationChanged(LeaderLocation.UNKNOWN); assertEquals(shardAccess.getLeaderLocation(), LeaderLocation.UNKNOWN); shardAccess.close(); try { shardAccess.getLeaderLocation(); fail("Should have failed with IllegalStateEx"); } catch (Exception e) { assertTrue(e instanceof IllegalStateException); } }