### Question:
HazelcastClusterTopology { public static Map<MemberId,RoleInfo> getCoreRoles( HazelcastInstance hazelcastInstance, Set<MemberId> coreMembers ) { Set<String> dbNames = getDBNames( hazelcastInstance ); Set<MemberId> allLeaders = dbNames.stream() .map( n -> getLeaderForDBName( hazelcastInstance, n ) ) .filter( Optional::isPresent ) .map( l -> l.get().memberId() ) .collect( Collectors.toSet() ); Function<MemberId,RoleInfo> roleMapper = m -> allLeaders.contains( m ) ? RoleInfo.LEADER : RoleInfo.FOLLOWER; return coreMembers.stream().collect( Collectors.toMap( Function.identity(), roleMapper ) ); } private  HazelcastClusterTopology(); static Map<MemberId,AdvertisedSocketAddress> extractCatchupAddressesMap( CoreTopology coreTopology,
            ReadReplicaTopology rrTopology ); static Map<MemberId,RoleInfo> getCoreRoles( HazelcastInstance hazelcastInstance, Set<MemberId> coreMembers );  }### Answer:
@Test public void shouldCorrectlyReturnCoreMemberRoles() { int numMembers = 3; List<MemberId> members = IntStream.range( 0, numMembers ) .mapToObj( ignored -> new MemberId( UUID.randomUUID() ) ).collect( Collectors.toList() ); @SuppressWarnings( "unchecked" ) IAtomicReference<LeaderInfo> leaderRef = mock( IAtomicReference.class ); MemberId chosenLeaderId = members.get( 0 ); when( leaderRef.get() ).thenReturn( new LeaderInfo( chosenLeaderId, 0L ) ); @SuppressWarnings( "unchecked" ) IMap<String,UUID> uuidDBMap = mock( IMap.class ); when( uuidDBMap.keySet() ).thenReturn( Collections.singleton( DEFAULT_DB_NAME ) ); when( hzInstance.<LeaderInfo>getAtomicReference( startsWith( DB_NAME_LEADER_TERM_PREFIX ) ) ).thenReturn( leaderRef ); when( hzInstance.<String,UUID>getMap( eq( CLUSTER_UUID_DB_NAME_MAP ) ) ).thenReturn( uuidDBMap ); Map<MemberId,RoleInfo> roleMap = HazelcastClusterTopology.getCoreRoles( hzInstance, new HashSet<>( members ) ); assertEquals( "First member was expected to be leader.", RoleInfo.LEADER, roleMap.get( chosenLeaderId ) ); }