### Question:
ObservedClusterMembers { public ClusterMember getCurrentMember() { for ( ClusterMember clusterMember : getMembers() ) { if ( clusterMember.getInstanceId().equals( me ) ) { return clusterMember; } } return null; } ObservedClusterMembers( LogProvider logProvider, Cluster cluster, Heartbeat heartbeat,
            ClusterMemberEvents events, InstanceId me ); Iterable<ClusterMember> getMembers(); Iterable<ClusterMember> getAliveMembers(); ClusterMember getCurrentMember();  }### Answer:
@Test public void iCanGetToMyself() { Cluster cluster = mock( Cluster.class ); Heartbeat heartbeat = mock( Heartbeat.class ); ClusterMemberEvents memberEvents = mock( ClusterMemberEvents.class ); ObservedClusterMembers members = new ObservedClusterMembers( logProvider, cluster, heartbeat, memberEvents, clusterId1 ); ArgumentCaptor<ClusterListener> listener = ArgumentCaptor.forClass( ClusterListener.class ); verify( cluster ).addClusterListener( listener.capture() ); listener.getValue().enteredCluster( clusterConfiguration( clusterUri1, clusterUri2 ) ); ClusterMember me = members.getCurrentMember(); assertNotNull( me ); assertEquals( 1, me.getInstanceId().toIntegerIndex() ); assertEquals( clusterId1, me.getInstanceId() ); }
@Test public void missingMasterUnavailabilityEventDoesNotClobberState() { Cluster cluster = mock( Cluster.class ); Heartbeat heartbeat = mock( Heartbeat.class ); ClusterMemberEvents memberEvents = mock( ClusterMemberEvents.class ); ObservedClusterMembers members = new ObservedClusterMembers( logProvider, cluster, heartbeat, memberEvents, clusterId1 ); ArgumentCaptor<ClusterListener> listener = ArgumentCaptor.forClass( ClusterListener.class ); verify( cluster ).addClusterListener( listener.capture() ); listener.getValue().enteredCluster( clusterConfiguration( clusterUri1, clusterUri2, clusterUri3 ) ); ArgumentCaptor<ClusterMemberListener> memberListener = ArgumentCaptor.forClass( ClusterMemberListener.class ); verify( memberEvents ).addClusterMemberListener( memberListener.capture() ); memberListener.getValue().memberIsAvailable( SLAVE, clusterId1, haUri1, StoreId.DEFAULT ); memberListener.getValue().memberIsAvailable( MASTER, clusterId1, haUri1, StoreId.DEFAULT ); assertThat( members.getCurrentMember().getHARole(), equalTo( MASTER ) ); }
@Test public void missingSlaveUnavailabilityEventDoesNotClobberState() { Cluster cluster = mock( Cluster.class ); Heartbeat heartbeat = mock( Heartbeat.class ); ClusterMemberEvents memberEvents = mock( ClusterMemberEvents.class ); ObservedClusterMembers members = new ObservedClusterMembers( logProvider, cluster, heartbeat, memberEvents, clusterId1 ); ArgumentCaptor<ClusterListener> listener = ArgumentCaptor.forClass( ClusterListener.class ); verify( cluster ).addClusterListener( listener.capture() ); listener.getValue().enteredCluster( clusterConfiguration( clusterUri1, clusterUri2, clusterUri3 ) ); ArgumentCaptor<ClusterMemberListener> memberListener = ArgumentCaptor.forClass( ClusterMemberListener.class ); verify( memberEvents ).addClusterMemberListener( memberListener.capture() ); memberListener.getValue().memberIsAvailable( MASTER, clusterId1, haUri1, StoreId.DEFAULT ); memberListener.getValue().memberIsAvailable( SLAVE, clusterId1, haUri1, StoreId.DEFAULT ); assertThat( members.getCurrentMember().getHARole(), equalTo( SLAVE ) ); }