### Question:
HighAvailabilityModeSwitcher implements HighAvailabilityMemberListener, BindingListener, Lifecycle { @Override public void masterIsElected( HighAvailabilityMemberChangeEvent event ) { if ( event.getNewState() == event.getOldState() && event.getOldState() == HighAvailabilityMemberState.MASTER ) { clusterMemberAvailability.memberIsAvailable( MASTER, masterHaURI, storeIdSupplier.get() ); } else { stateChanged( event ); } } HighAvailabilityModeSwitcher( SwitchToSlave switchToSlave,
                                         SwitchToMaster switchToMaster,
                                         Election election,
                                         ClusterMemberAvailability clusterMemberAvailability,
                                         ClusterClient clusterClient,
                                         Supplier<StoreId> storeIdSupplier,
                                         InstanceId instanceId,
                                         ComponentSwitcher componentSwitcher,
                                         DataSourceManager neoStoreDataSourceSupplier,
                                         LogService logService ); static InstanceId getServerId( URI haUri ); @Override void listeningAt( URI myUri ); @Override synchronized void init(); @Override synchronized void start(); @Override synchronized void stop(); @Override synchronized void shutdown(); @Override void masterIsElected( HighAvailabilityMemberChangeEvent event ); @Override void masterIsAvailable( HighAvailabilityMemberChangeEvent event ); @Override void slaveIsAvailable( HighAvailabilityMemberChangeEvent event ); @Override void instanceStops( HighAvailabilityMemberChangeEvent event ); @Override void instanceDetached( HighAvailabilityMemberChangeEvent event ); void forceElections(); static final String MASTER; static final String SLAVE; static final String UNKNOWN; static final String INADDR_ANY; }### Answer:
@Test public void shouldBroadcastMasterIsAvailableIfMasterAndReceiveMasterIsElected() { ClusterMemberAvailability availability = mock( ClusterMemberAvailability.class ); HighAvailabilityModeSwitcher toTest = createModeSwitcher( availability ); toTest.masterIsElected( new HighAvailabilityMemberChangeEvent( HighAvailabilityMemberState.MASTER, HighAvailabilityMemberState.MASTER, new InstanceId( 2 ), URI.create( "ha: verify( availability ).memberIsAvailable( HighAvailabilityModeSwitcher.MASTER, null, StoreId.DEFAULT ); }
@Test public void shouldNotBroadcastIfSlaveAndReceivesMasterIsElected() { ClusterMemberAvailability availability = mock( ClusterMemberAvailability.class ); HighAvailabilityModeSwitcher toTest = createModeSwitcher( availability ); toTest.masterIsElected( new HighAvailabilityMemberChangeEvent( HighAvailabilityMemberState.SLAVE, HighAvailabilityMemberState.SLAVE, new InstanceId( 2 ), URI.create( "ha: verifyZeroInteractions( availability ); }