private void assertOnlyOneSucceeds( Runnable lockAction1, Runnable lockAction2 ) throws Throwable { assertUU(); Race race = new Race(); LockContestant c1 = new LockContestant( lockAction1 ); LockContestant c2 = new LockContestant( lockAction2 ); // when race.addContestant( c1 ); race.addContestant( c2 ); race.goAsync(); while ( !(c1.lockAcquired() || c2.lockAcquired()) || !(c1.started() && c2.started()) ) { LockSupport.parkNanos( TimeUnit.MILLISECONDS.toNanos( 1 ) ); } // then Pair<Boolean,Boolean> c1State = c1.state(); Pair<Boolean,Boolean> c2State = c2.state(); assertNotEquals( withState( "Expected exactly one to acquire lock.", c1State, c2State ), c1State.first(), c2State.first() ); assertTrue( withState( "Expected both to be started.", c1State, c2State ), c1State.other() && c2State.other() ); }