Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to lock the resource named "database" for the test method.
JUnit
@Test
@ResourceLock(value = [1])
void testDatabaseAccess() {
// test code here
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the resource name in quotes.
Using an incorrect resource name.
✗ Incorrect
The @ResourceLock annotation requires the resource name as a string. Here, "database" is the resource to lock.
2fill in blank
mediumComplete the code to lock the resource "configFile" with a read lock.
JUnit
@Test @ResourceLock(value = "configFile", mode = [1]) void testReadConfig() { // test code here }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using WRITE mode when only reading is needed.
Omitting the mode attribute.
✗ Incorrect
To lock a resource for reading, use ResourceAccessMode.READ in the mode attribute.
3fill in blank
hardFix the error in the annotation to lock resource "service" with write access.
JUnit
@Test @ResourceLock(value = "service", mode = [1]) void testServiceUpdate() { // test code here }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using READ mode instead of WRITE for updates.
Using an invalid mode value.
✗ Incorrect
Write access requires ResourceAccessMode.WRITE to prevent other tests from reading or writing simultaneously.
4fill in blank
hardFill both blanks to lock resource "cache" with write access and resource "log" with read access.
JUnit
@Test @ResourceLock(value = [1], mode = ResourceAccessMode.WRITE) @ResourceLock(value = [2], mode = ResourceAccessMode.READ) void testCacheAndLog() { // test code here }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping resource names between the two annotations.
Using incorrect resource names.
✗ Incorrect
The first @ResourceLock locks "cache" with write access, the second locks "log" with read access.
5fill in blank
hardFill all three blanks to lock resource "session" with write access, resource "userData" with read access, and resource "metrics" with write access.
JUnit
@Test @ResourceLock(value = [1], mode = ResourceAccessMode.WRITE) @ResourceLock(value = [2], mode = ResourceAccessMode.READ) @ResourceLock(value = [3], mode = ResourceAccessMode.WRITE) void testMultipleResources() { // test code here }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up resource names and lock modes.
Using resource names not listed in options.
✗ Incorrect
The first locks "session" with write, second locks "userData" with read, third locks "metrics" with write access.