LockedRepository implements ILockedRepository { static LockedRepository lockProjectCentral(String projectName, LockManager lockManager) { ILock lock = lockManager.lockProjectCentral(projectName); return new LockedRepository(lock, lockManager); } private  LockedRepository(ILock lock, LockManager lockManager); @Override Repository r(); @Override void close();  }
@Test public void lockAndUnlockProjectCentral() { Lock lock = new Lock(Thread.currentThread()); when(lockManager.lockProjectCentral("project")).thenReturn(lock); ILockedRepository repo = LockedRepository.lockProjectCentral("project", lockManager); Util.closeQuietly(repo); verify(lockManager).unlock(lock); }