LockFactory { public Lock newLock() { return newLock(getDefaultPrefix()); } @Inject  LockFactory(Configuration config); Lock newLock(); Lock newLock(String label); ReadWriteLock newReadWriteLock(); ReadWriteLock newReadWriteLock(String label); void debugDump(StringBuilder sb);  }
@Test public void createsRegularLockIfDebugIsDisabled() { Configuration config = createNiceMock(Configuration.class); expect(config.isServerLocksProfilingEnabled()).andReturn(false); replayAll(); LockFactory factory = new LockFactory(config); Lock lock = factory.newLock(); Assert.assertTrue(lock instanceof ReentrantLock); verifyAll(); }
@Test public void createsProfiledLockIfProfilingIsEnabled() { Configuration config = createNiceMock(Configuration.class); expect(config.isServerLocksProfilingEnabled()).andReturn(true); replayAll(); LockFactory factory = new LockFactory(config); Lock lock = factory.newLock(); Assert.assertTrue(lock instanceof ProfiledReentrantLock); String label = ((ProfiledLock) lock).getLabel(); Assert.assertTrue(label, label.contains("LockFactoryTest.java")); verifyAll(); }