michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: package org.mozilla.gecko.background.sync.helpers; michael@0: michael@0: import java.util.concurrent.ExecutorService; michael@0: michael@0: import junit.framework.AssertionFailedError; michael@0: michael@0: import org.mozilla.gecko.background.testhelpers.WaitHelper; michael@0: michael@0: public abstract class DefaultDelegate { michael@0: protected ExecutorService executor; michael@0: michael@0: protected final WaitHelper waitHelper; michael@0: michael@0: public DefaultDelegate() { michael@0: waitHelper = WaitHelper.getTestWaiter(); michael@0: } michael@0: michael@0: public DefaultDelegate(WaitHelper waitHelper) { michael@0: this.waitHelper = waitHelper; michael@0: } michael@0: michael@0: protected WaitHelper getTestWaiter() { michael@0: return waitHelper; michael@0: } michael@0: michael@0: public void performWait(Runnable runnable) throws AssertionFailedError { michael@0: getTestWaiter().performWait(runnable); michael@0: } michael@0: michael@0: public void performNotify() { michael@0: getTestWaiter().performNotify(); michael@0: } michael@0: michael@0: public void performNotify(Throwable e) { michael@0: getTestWaiter().performNotify(e); michael@0: } michael@0: michael@0: public void performNotify(String reason, Throwable e) { michael@0: String message = reason; michael@0: if (e != null) { michael@0: message += ": " + e.getMessage(); michael@0: } michael@0: AssertionFailedError ex = new AssertionFailedError(message); michael@0: if (e != null) { michael@0: ex.initCause(e); michael@0: } michael@0: getTestWaiter().performNotify(ex); michael@0: } michael@0: }