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