TargetedSweeperLock { public static Optional<TargetedSweeperLock> tryAcquire(int shard, SweeperStrategy strategy, TimelockService timeLock) { ShardAndStrategy shardStrategy = ShardAndStrategy.of(shard, strategy); LockRequest request = LockRequest.of(ImmutableSet.of(shardStrategy.toLockDescriptor()), 100L); return timeLock.lock(request) .getTokenOrEmpty() .map(lockToken -> new TargetedSweeperLock(shardStrategy, timeLock, lockToken)); } private  TargetedSweeperLock(ShardAndStrategy shardStrategy, TimelockService timeLock, LockToken lockToken); static Optional<TargetedSweeperLock> tryAcquire(int shard, SweeperStrategy strategy,
            TimelockService timeLock); ShardAndStrategy getShardAndStrategy(); void unlock();  }
@Test public void unsuccessfulLock() throws InterruptedException { when(mockLockService.lock(any())).thenReturn(() -> Optional.empty()); Optional<TargetedSweeperLock> maybeLock = TargetedSweeperLock .tryAcquire(2, SweeperStrategy.THOROUGH, mockLockService); assertThat(maybeLock).isNotPresent(); verify(mockLockService, times(1)).lock(any()); verifyNoMoreInteractions(mockLockService); }