Source:
<code>public void testInstanceWithLowestIdFailedIsNotConsideredTheElector() { Set<InstanceId> failed = new HashSet<>(); failed.add( new InstanceId( 1 ) ); failed.add( new InstanceId( 2 ) ); Map<InstanceId, URI> members = new HashMap<>(); members.put( new InstanceId( 1 ), URI.create( "server1" ) ); members.put( new InstanceId( 2 ), URI.create( "server2" ) ); members.put( new InstanceId( 3 ), URI.create( "server3" ) ); members.put( new InstanceId( 4 ), URI.create( "server4" ) ); members.put( new InstanceId( 5 ), URI.create( "server5" ) ); Config config = mock( Config.class ); <START> when( config.get( ClusterSettings.max_acceptors ) ).thenReturn( 10 ); <END> ClusterConfiguration clusterConfiguration = mock( ClusterConfiguration.class ); when( clusterConfiguration.getMembers() ).thenReturn( members ); when( clusterConfiguration.getMemberIds() ).thenReturn( members.keySet() ); ClusterContext clusterContext = mock( ClusterContext.class ); when( clusterContext.getConfiguration() ).thenReturn( clusterConfiguration ); MultiPaxosContext context = new MultiPaxosContext( new InstanceId(3 ), Iterables.iterable( new ElectionRole( "coordinator" ) ), clusterConfiguration, mock( Executor.class ), NullLogProvider.getInstance(), mock( ObjectInputStreamFactory.class ), mock( ObjectOutputStreamFactory.class ), mock( AcceptorInstanceStore.class ), mock( Timeouts.class ), mock( ElectionCredentialsProvider.class), config ); context.getHeartbeatContext().getFailed().addAll( failed ); ElectionContext toTest = context.getElectionContext(); assertTrue( toTest.isElector() ); }</code><technical_language>I get this behaviour stably a mock</technical_language>

Target:
public void testInstanceWithLowestIdFailedIsNotConsideredTheElector() { Set<InstanceId> failed = new HashSet<>(); failed.add( new InstanceId( 1 ) ); failed.add( new InstanceId( 2 ) ); InstanceId lowestNonFailedInstanceId = new InstanceId( 3 ); Map<InstanceId, URI> members = new HashMap<>(); members.put( new InstanceId( 1 ), URI.create( "server1" ) ); members.put( new InstanceId( 2 ), URI.create( "server2" ) ); members.put( lowestNonFailedInstanceId, URI.create( "server3" ) ); members.put( new InstanceId( 4 ), URI.create( "server4" ) ); members.put( new InstanceId( 5 ), URI.create( "server5" ) ); Config config = Config.defaults(); ClusterConfiguration clusterConfiguration = mock( ClusterConfiguration.class ); when( clusterConfiguration.getMembers() ).thenReturn( members ); when( clusterConfiguration.getMemberIds() ).thenReturn( members.keySet() ); ClusterContext clusterContext = mock( ClusterContext.class ); when( clusterContext.getConfiguration() ).thenReturn( clusterConfiguration ); MultiPaxosContext context = new MultiPaxosContext( lowestNonFailedInstanceId, Iterables.iterable( new ElectionRole( "coordinator" ) ), clusterConfiguration, mock( Executor.class ), NullLogProvider.getInstance(), mock( ObjectInputStreamFactory.class ), mock( ObjectOutputStreamFactory.class ), mock( AcceptorInstanceStore.class ), mock( Timeouts.class ), mock( ElectionCredentialsProvider.class), config ); ElectionContext toTest = context.getElectionContext(); assertFalse( toTest.isElector() ); context.getHeartbeatContext().getFailed().addAll( failed ); assertTrue( toTest.isElector() ); }