Skip to content

Commit 6452e7a

Browse files
committed
lock manager related tests
1 parent 8cc31d8 commit 6452e7a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.iluwatar.implicitlock;
2+
3+
4+
import com.iluwatar.LockManager;
5+
import com.iluwatar.Resource;
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.Test;
8+
9+
import static org.junit.jupiter.api.Assertions.*;
10+
11+
class LockManagerTest {
12+
13+
private LockManager lockManager;
14+
private Resource resource1;
15+
16+
@BeforeEach
17+
void setUp() {
18+
lockManager = new LockManager();
19+
resource1 = new Resource("Resource1");
20+
}
21+
22+
@Test
23+
void testAcquireLockSuccessfully() {
24+
// Attempt to acquire the lock for resource1
25+
boolean result = lockManager.acquireLock(resource1);
26+
27+
// Assert that the lock was successfully acquired
28+
assertTrue(result, "Lock should be successfully acquired for Resource1");
29+
}
30+
31+
32+
33+
@Test
34+
void testReleaseLockWithoutHolding() {
35+
// Try to release the lock without acquiring it
36+
boolean releaseAttempt = lockManager.releaseLock(resource1);
37+
assertFalse(releaseAttempt, "Release attempt should fail as the lock was not acquired");
38+
}
39+
}

0 commit comments

Comments
 (0)