@Test @SuppressWarnings("unchecked") public void testSweepLocksForClient() { LockManagerImpl lockManager = new LockManagerImpl(); ClientDescriptor clientDescriptor1 = new TestClientDescriptor(); ClientDescriptor clientDescriptor2 = new TestClientDescriptor(); assertThat(lockManager.lock(1L, clientDescriptor1), is(true)); assertThat(lockManager.lock(2L, clientDescriptor1), is(true)); assertThat(lockManager.lock(3L, clientDescriptor1), is(true)); assertThat(lockManager.lock(4L, clientDescriptor1), is(true)); assertThat(lockManager.lock(5L, clientDescriptor2), is(true)); assertThat(lockManager.lock(6L, clientDescriptor2), is(true)); AtomicInteger counter = new AtomicInteger(); Consumer<List<Long>> consumer = mock(Consumer.class); ArgumentCaptor<List<Long>> argumentCaptor = ArgumentCaptor.forClass(List.class); doAnswer(invocation -> counter.incrementAndGet()).when(consumer).accept(argumentCaptor.capture()); lockManager.sweepLocksForClient(clientDescriptor2, consumer); assertThat(counter.get(), is(1)); assertThat(argumentCaptor.getValue().size(), is(2)); assertThat(argumentCaptor.getValue(), containsInAnyOrder(5L, 6L)); assertThat(lockManager.lock(5L, clientDescriptor2), is(true)); assertThat(lockManager.lock(6L, clientDescriptor2), is(true)); assertThat(lockManager.lock(1L, clientDescriptor1), is(false)); assertThat(lockManager.lock(2L, clientDescriptor1), is(false)); assertThat(lockManager.lock(3L, clientDescriptor1), is(false)); assertThat(lockManager.lock(4L, clientDescriptor1), is(false)); }