package cucumber.runtime.java.hooks;

public class HttpServerStub {
    private boolean isStarted;
    private Request<String> request;

    public void start() {
        if (isStarted) {
            throw new IllegalStateException("Server already started!");
        }
        try {
            Thread.sleep(2000);
            isStarted = true;
        } catch (InterruptedException e) {}
    }

    public void stop() {
        if (!isStarted) {
            throw new IllegalStateException("Server is not running!");
        }
        try {
            Thread.sleep(2000);
            isStarted = false;
        } catch (InterruptedException e) {}
    }

    public boolean isStarted() {
        return isStarted;
    }

    public int send(Request<String> request) {
        if (!isStarted) {
            throw new IllegalStateException("server is not running");
        }
        this.request = request;
        return 200;
    }

    public String retrieve() {
        if (!isStarted) {
            throw new IllegalStateException("server is not running");
        }
        return request.getData();
    }

    public void clean() {
        request = new Request<String>(null);
    }

    static class Request<T> {
        private T data;

        Request(T data) {
            this.data = data;
        }

        T getData() {
            return data;
        }
    }
}

package cucumber.runtime.java.hooks;

public class HttpServerStub {
    private boolean isStarted;
    private Request<String> request;

    public void start() {
        if (isStarted) {
            throw new IllegalStateException("Server already started!");
        }
        try {
            Thread.sleep(2000);
            isStarted = true;
        } catch (InterruptedException e) {}
    }

    public void stop() {
        if (!isStarted) {
            throw new IllegalStateException("Server is not running!");
        }
        try {
            Thread.sleep(2000);
            isStarted = false;
        } catch (InterruptedException e) {}
    }

    public boolean isStarted() {
        return isStarted;
    }

    public int send(Request<String> request) {
        if (!isStarted) {
            throw new IllegalStateException("server is not running");
        }
        this.request = request;
        return 200;
    }

    public String receive() {
        if (!isStarted) {
            throw new IllegalStateException("server is not running");
        }
        return request.getData();
    }

    public void clean() {
        request = new Request<String>(null);
    }

    static class Request<T> {
        private T data;

        Request(T data) {
            this.data = data;
        }

        T getData() {
            return data;
        }
    }
}

Revert "Add new hooks for global level (@BeforeAll and @AfterAll) that run only once before all and after all existing features/scenarios. Unit test and cucumber test to cover the new hooks and the running order between hooks."
Revert "Add new hooks for global level (@BeforeAll and @AfterAll) that run only once before all and after all existing features/scenarios. Unit test and cucumber test to cover the new hooks and the running order between hooks."

This reverts commit 34332ef30d22ad24aa8186b5112f93f0ba8e1b3d.
