Package net.jsunit

Source Code of net.jsunit.MockBrowserTestRunner

package net.jsunit;

import net.jsunit.configuration.ServerConfiguration;
import net.jsunit.model.Browser;
import net.jsunit.model.BrowserLaunchSpecification;
import net.jsunit.model.BrowserResult;
import net.jsunit.model.DummyBrowserResult;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MockBrowserTestRunner extends BrowserTestRunnerStub {

    public boolean disposeCalled;
    public BrowserResult acceptedResult;
    public BrowserResult resultToReturn;
    public boolean shouldSucceed;
    public String idPassed;
    public Integer browserIdPassed;
    public int timeoutSeconds;
    public List<String> logMessages = new ArrayList<String>();
    public List<BrowserLaunchSpecification> launchSpecs = new ArrayList<BrowserLaunchSpecification>();
    public ServerConfiguration configuration;
    private TestRunListener testRunManager;
    public boolean waitingForBrowser;

    public void launchBrowserTestRun(BrowserLaunchSpecification launchSpec) {
        launchSpecs.add(launchSpec);
        BrowserResult result = createResult();
        Browser browser = launchSpec.getBrowser();
        result.setBrowser(browser);
        accept(result);
    }

    public void addTestRunListener(TestRunListener listener) {
        if (listener instanceof TestRunManager)
            this.testRunManager = listener;
    }

    public void removeTestRunListener(TestRunListener listener) {
        if (listener instanceof TestRunManager)
            this.testRunManager = null;
    }

    public boolean isWaitingForBrowser(Browser browser) {
        return waitingForBrowser;
    }

    public void accept(BrowserResult result) {
        this.acceptedResult = result;
        if (testRunManager != null)
            testRunManager.browserTestRunFinished(result.getBrowser(), result);
    }

    public BrowserResult lastResult() {
        return createResult();
    }

    private DummyBrowserResult createResult() {
        return new DummyBrowserResult(shouldSucceed, shouldSucceed ? 0 : 1, 0);
    }

    public void dispose() {
        disposeCalled = true;
    }

    public BrowserResult findResultWithId(String id, int browserId) throws InvalidBrowserIdException {
        idPassed = id;
        browserIdPassed = browserId;
        return resultToReturn;
    }

    public List<Browser> getBrowsers() {
        return Arrays.asList(new Browser[]{new Browser("mybrowser1.exe", 0), new Browser("mybrowser2.exe", 1)});
    }

    public int timeoutSeconds() {
        return timeoutSeconds;
    }

    public boolean isAlive() {
        return true;
    }

    public ServerConfiguration getConfiguration() {
        return configuration;
    }

}
TOP

Related Classes of net.jsunit.MockBrowserTestRunner

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.