### Question:
AtomicBroadcastContextImpl extends AbstractContextImpl implements AtomicBroadcastContext { @Override public boolean hasQuorum() { int availableMembers = (int) Iterables.count( heartbeatContext.getAlive() ); int totalMembers = commonState.configuration().getMembers().size(); return Quorums.isQuorum( availableMembers, totalMembers ); } AtomicBroadcastContextImpl( org.neo4j.cluster.InstanceId me, CommonContextState commonState,
                                LogProvider logging,
                                Timeouts timeouts, Executor executor, HeartbeatContext heartbeatContext  ); @Override void addAtomicBroadcastListener( AtomicBroadcastListener listener ); @Override void removeAtomicBroadcastListener( AtomicBroadcastListener listener ); @Override void receive( Payload value ); AtomicBroadcastContextImpl snapshot( CommonContextState commonStateSnapshot, LogProvider logging,
                                                Timeouts timeouts, Executor executor, HeartbeatContext heartbeatContext ); @Override boolean equals( Object o ); @Override int hashCode(); @Override boolean hasQuorum();  }### Answer:
@Test public void shouldHasQuorumWhenTwoMachinesAliveInAClusterWithThreeMachines() { HeartbeatContext heartbeatContext = mock( HeartbeatContext.class ); CommonContextState commonState = mock( CommonContextState.class ); ClusterConfiguration configuration = mock(ClusterConfiguration.class); when( heartbeatContext.getAlive() ).thenReturn( ids( 2 ) ); when( commonState.configuration() ).thenReturn( configuration ); when( configuration.getMembers() ).thenReturn( members( 3 ) ); AtomicBroadcastContextImpl context = new AtomicBroadcastContextImpl( null, commonState, null, null, null, heartbeatContext ); boolean hasQuorum = context.hasQuorum(); assertTrue( hasQuorum ); }
@Test public void shouldHasNoQuorumWhenOneMachineAliveInAClusterWithThreeMachines() { HeartbeatContext heartbeatContext = mock( HeartbeatContext.class ); CommonContextState commonState = mock( CommonContextState.class ); ClusterConfiguration configuration = mock( ClusterConfiguration.class ); when( heartbeatContext.getAlive() ).thenReturn( ids( 1 ) ); when( commonState.configuration() ).thenReturn( configuration ); when( configuration.getMembers() ).thenReturn( members( 3 ) ); AtomicBroadcastContextImpl context = new AtomicBroadcastContextImpl( null, commonState, null, null, null, heartbeatContext ); boolean hasQuorum = context.hasQuorum(); assertFalse( hasQuorum ); }
@Test public void shouldHasQuorumWhenOneMachineAliveInAClusterWithOneMachine() { HeartbeatContext heartbeatContext = mock( HeartbeatContext.class ); CommonContextState commonState = mock( CommonContextState.class ); ClusterConfiguration configuration = mock( ClusterConfiguration.class ); when( heartbeatContext.getAlive() ).thenReturn( ids( 1 ) ); when( commonState.configuration() ).thenReturn( configuration ); when( configuration.getMembers() ).thenReturn( members( 1 ) ); AtomicBroadcastContextImpl context = new AtomicBroadcastContextImpl( null, commonState, null, null, null, heartbeatContext ); boolean hasQuorum = context.hasQuorum(); assertTrue( hasQuorum ); }