All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.junit.internal.requests.MemoizingRequest Maven / Gradle / Ivy

Go to download

JUnit is a unit testing framework for Java, created by Erich Gamma and Kent Beck.

There is a newer version: 4.13.2
Show newest version
package org.junit.internal.requests;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.junit.runner.Request;
import org.junit.runner.Runner;

abstract class MemoizingRequest extends Request {
    private final Lock runnerLock = new ReentrantLock();
    private volatile Runner runner;

    @Override
    public final Runner getRunner() {
        if (runner == null) {
            runnerLock.lock();
            try {
                if (runner == null) {
                    runner = createRunner();
                }
            } finally {
                runnerLock.unlock();
            }
        }
        return runner;
    }

    /** Creates the {@link Runner} to return from {@link #getRunner()}. Called at most once. */
    protected abstract Runner createRunner();
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy