### Question:
LockCollection implements LockFactory.DistributedLock { @Override public void close() { for (LockFactory.DistributedLock lock : myLocks) { try { lock.close(); } catch (Exception e) { LOG.warn("Unable to release lock {} ", lock, e); } } } LockCollection(Collection<? extends LockFactory.DistributedLock> locks); @Override void close();  }### Answer:
@Test public void testCloseAllLocks() { List<DummyLock> locks = new ArrayList<>(); for (int i = 0; i < 10; i++) { locks.add(new DummyLock()); } new LockCollection(locks).close(); for (DummyLock lock : locks) { assertThat(lock.closed).isTrue(); } }
@Test public void testCloseAllLocksOneThrowing() { List<DistributedLock> locks = new ArrayList<>(); for (int i = 0; i < 4; i++) { locks.add(new DummyLock()); } locks.add(new ThrowingLock()); for (int i = 0; i < 5; i++) { locks.add(new DummyLock()); } new LockCollection(locks).close(); for (DistributedLock lock : locks) { if (lock instanceof DummyLock) { assertThat(((DummyLock) lock).closed).isTrue(); } } }