File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
implicitlock/src/test/java/com/iluwatar/implicitlock Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments