Wrapped the system clock in an interface so it can be replaced in tests.

This commit is contained in:
akwizgran
2012-09-06 17:21:03 +01:00
parent 67eb9d6f93
commit 960ead0247
26 changed files with 115 additions and 53 deletions

View File

@@ -2,8 +2,10 @@ package net.sf.briar.api.plugins.duplex;
import java.util.concurrent.Executor;
import net.sf.briar.clock.Clock;
public interface DuplexPluginFactory {
DuplexPlugin createPlugin(Executor pluginExecutor,
DuplexPlugin createPlugin(Executor pluginExecutor, Clock clock,
DuplexPluginCallback callback);
}

View File

@@ -2,8 +2,10 @@ package net.sf.briar.api.plugins.simplex;
import java.util.concurrent.Executor;
import net.sf.briar.clock.Clock;
public interface SimplexPluginFactory {
SimplexPlugin createPlugin(Executor pluginExecutor,
SimplexPlugin createPlugin(Executor pluginExecutor, Clock clock,
SimplexPluginCallback callback);
}

View File

@@ -0,0 +1,11 @@
package net.sf.briar.clock;
/**
* An interface for time-related system functions that allows them to be
* replaced for testing.
*/
public interface Clock {
/** @see {@link java.lang.System#currentTimeMillis()} */
long currentTimeMillis();
}

View File

@@ -0,0 +1,9 @@
package net.sf.briar.clock;
/** Default clock implementation. */
public class SystemClock implements Clock {
public long currentTimeMillis() {
return System.currentTimeMillis();
}
}