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

com.dadrox.sbt.junit.Event Maven / Gradle / Ivy

package com.dadrox.sbt.junit;

import org.scalatools.testing.Result;

abstract class Option {
    public static  Option apply(B value) {
        if (value == null) return new None();
        return new Some(value);
    }

    abstract A get();

    abstract A getOrElse(A defaultValue);

    abstract boolean isDefined();
}

class None extends Option {
    @Override
    A getOrElse(A defaultValue) {
        return defaultValue;
    }

    @Override
    boolean isDefined() {
        return false;
    }

    @Override
    A get() {
        return null;
    }
}

class Some extends Option {
    private A value;

    public Some(A value) {
        this.value = value;
    }

    @Override
    A getOrElse(@SuppressWarnings("unused") A defaultValue) {
        return value;
    }

    @Override
    boolean isDefined() {
        return true;
    }

    @Override
    A get() {
        return value;
    }
}

class Event {
    public Name testName;
    public Option result;
    public Option description; // = none
    public Option error; // = None

    public Event(Name testName, Option result, Option description, Option error) {
        this.testName = testName;
        this.result = result;
        this.description = description;
        this.error = error;
    }
}

class SbtEvent implements org.scalatools.testing.Event {

    public String testName;
    public Result result;
    public String description = "";
    public Throwable error = null;

    public SbtEvent(String testName, Result result, String description, Throwable error) {
        this.testName = testName;
        this.result = result;
        this.description = description;
        this.error = error;
    }

    public static SbtEvent apply(Event event) {
        return new SbtEvent(
                        event.testName.fullyQualified(),
                        event.result.getOrElse(Result.Success),
                        event.description.getOrElse(""),
                        event.error.getOrElse(null));
    }

    @Override
    public String description() {
        return description;
    }

    @Override
    public Throwable error() {
        return error;
    }

    @Override
    public Result result() {
        return result;
    }

    @Override
    public String testName() {
        return testName;
    }
}