0
0
JUnittesting~10 mins

Resource locking with @ResourceLock in JUnit - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A"network"
B"database"
C"file"
D"cache"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the resource name in quotes.
Using an incorrect resource name.
2fill in blank
medium

Complete 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'
AResourceAccessMode.WRITE
BResourceAccessMode.NONE
CResourceAccessMode.READ
DResourceAccessMode.EXCLUSIVE
Attempts:
3 left
💡 Hint
Common Mistakes
Using WRITE mode when only reading is needed.
Omitting the mode attribute.
3fill in blank
hard

Fix 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'
AResourceAccessMode.WRITE
BResourceAccessMode.READ
CResourceAccessMode.READ_WRITE
DResourceAccessMode.NONE
Attempts:
3 left
💡 Hint
Common Mistakes
Using READ mode instead of WRITE for updates.
Using an invalid mode value.
4fill in blank
hard

Fill 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'
A"cache"
B"log"
C"database"
D"config"
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping resource names between the two annotations.
Using incorrect resource names.
5fill in blank
hard

Fill 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'
A"session"
B"userData"
C"metrics"
D"cache"
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up resource names and lock modes.
Using resource names not listed in options.