use of org.osgi.util.function.Callback in project aries by apache.
the class ChainTest method testThenCallbackThrowsExceptionFail.
@Test
public void testThenCallbackThrowsExceptionFail() throws Exception {
Deferred<String> def = new Deferred<String>();
final Exception failure = new Exception("bang!");
Promise<String> chain = def.getPromise().then(new Callback() {
@Override
public void run() throws Exception {
throw failure;
}
});
assertFalse("chain should not be resolved", chain.isDone());
def.fail(new IllegalStateException());
assertTrue("chain resolved", chain.isDone());
assertSame("chain value matches", failure, chain.getFailure());
}
use of org.osgi.util.function.Callback in project aries by apache.
the class ChainTest method testThenCallbackSuccess.
@Test
public void testThenCallbackSuccess() throws Exception {
Deferred<String> def = new Deferred<String>();
final AtomicBoolean run = new AtomicBoolean(false);
Promise<String> chain = def.getPromise().then(new Callback() {
@Override
public void run() throws Exception {
run.set(true);
}
});
assertFalse("chain should not be resolved", chain.isDone());
assertFalse("callback should not have been run", run.get());
def.resolve("ok");
assertTrue("chain resolved", chain.isDone());
assertEquals("chain value matches", "ok", chain.getValue());
assertTrue("callback should have been run", run.get());
}
use of org.osgi.util.function.Callback in project aries by apache.
the class ChainTest method testThenCallbackThrowsExceptionSuccess.
@Test
public void testThenCallbackThrowsExceptionSuccess() throws Exception {
Deferred<String> def = new Deferred<String>();
final Exception failure = new Exception("bang!");
Promise<String> chain = def.getPromise().then(new Callback() {
@Override
public void run() throws Exception {
throw failure;
}
});
assertFalse("chain should not be resolved", chain.isDone());
def.resolve("ok");
assertTrue("chain resolved", chain.isDone());
assertSame("chain value matches", failure, chain.getFailure());
}
use of org.osgi.util.function.Callback in project aries by apache.
the class ChainTest method testThenCallbackFail.
@Test
public void testThenCallbackFail() throws Exception {
Deferred<String> def = new Deferred<String>();
final AtomicBoolean run = new AtomicBoolean(false);
Promise<String> chain = def.getPromise().then(new Callback() {
@Override
public void run() throws Exception {
run.set(true);
}
});
Exception failure = new Exception("bang!");
assertFalse("chain should not be resolved", chain.isDone());
assertFalse("callback should not have been run", run.get());
def.fail(failure);
assertTrue("chain resolved", chain.isDone());
assertSame("chain value matches", failure, chain.getFailure());
assertTrue("callback should have been run", run.get());
}
Aggregations