How do you test code that uses ReentrantLock?

This article discusses how to effectively test Java code that utilizes ReentrantLock for managing thread safety, ensuring that concurrent programming practices are verified correctly.
ReentrantLock, Java concurrency, multithreading, unit testing, synchronization
import java.util.concurrent.locks.ReentrantLock;

class SharedResource {
    private final ReentrantLock lock = new ReentrantLock();
    private int resource = 0;

    public void increment() {
        lock.lock();
        try {
            resource++;
        } finally {
            lock.unlock();
        }
    }

    public int getResource() {
        return resource;
    }
}

public class ReentrantLockTest {
    public static void main(String[] args) throws InterruptedException {
        SharedResource sharedResource = new SharedResource();
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 1000; i++) {
                sharedResource.increment();
            }
        });

        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 1000; i++) {
                sharedResource.increment();
            }
        });

        t1.start();
        t2.start();
        t1.join();
        t2.join();

        System.out.println("Final resource value: " + sharedResource.getResource());
    }
}

ReentrantLock Java concurrency multithreading unit testing synchronization