com.softicar.platform.common.testing.AbstractTest Maven / Gradle / Ivy
Show all versions of platform-common Show documentation
package com.softicar.platform.common.testing;
import com.softicar.platform.common.core.clock.CurrentClock;
import com.softicar.platform.common.core.clock.TestClock;
import com.softicar.platform.common.core.interfaces.ITestMarker;
import com.softicar.platform.common.core.thread.sleeper.CurrentSleeper;
import com.softicar.platform.common.core.thread.sleeper.TestSleeper;
import com.softicar.platform.common.date.ISOCalendar;
import org.junit.Rule;
/**
* Recommended base class for all unit tests.
*
* This class employs the {@link SingletonTestWatcher} as Junit {@link Rule}.
*
* @author Oliver Richers
*/
public abstract class AbstractTest extends Asserts {
@Rule public SingletonTestWatcher SingletonTestWatcher = new SingletonTestWatcher();
protected final TestClock testClock;
public AbstractTest() {
this.testClock = new TestClock();
CurrentClock.set(testClock);
ISOCalendar.setDefaultTimeZone();
}
/**
* Creates a new {@link ITestMarker} instance that can be used as test
* marker.
*
* @return a new instance of {@link ITestMarker} (never null)
*/
public static ITestMarker newMarker() {
return new ITestMarker() { /* nothing to add */ };
}
/**
* Creates a new {@link TestSleeper} and sets it as the
* {@link CurrentSleeper}.
*
* @return the {@link TestSleeper} (never null)
*/
protected TestSleeper setupTestSleeper() {
TestSleeper sleeper = new TestSleeper(testClock);
CurrentSleeper.set(sleeper);
return sleeper;
}
}