@Test public void testAsyncResultMapEmpty() { Future<String> f = Future.future(); AsyncResult<String> res = asyncResult(f); AsyncResult<Integer> map = res.mapEmpty(); f.complete("foobar"); assertNull(null, map.result()); assertNull(map.cause()); }
@Test public void testFailedAsyncResultMap() { Future<String> f = Future.future(); AsyncResult<String> res = asyncResult(f); AsyncResult<Integer> map1 = res.map(String::length); AsyncResult<Integer> map2 = res.map(17); Throwable cause = new Throwable(); f.fail(cause); assertNull(map1.result()); assertSame(cause, map1.cause()); assertNull(map2.result()); assertSame(cause, map2.cause()); }
@Test public void testAsyncResultOtherwiseEmpty() { Future<String> f = Future.future(); AsyncResult<String> res = asyncResult(f); testOtherwiseEmpty(res, f); }
@Test public void testUncompletedAsyncResultOtherwise() { Future<String> f = Future.future(); AsyncResult<String> res = asyncResult(f); testUncompletedAsyncResultOtherwise(res); }
@Test public void testFailedAsyncResultOtherwise() { Future<String> f = Future.future(); AsyncResult<String> res = asyncResult(f); testFailedOtherwise(res, f); }
@Test public void testFailedAsyncResultOtherwiseApplyFunction() { Future<String> f = Future.future(); AsyncResult<String> res = asyncResult(f); testFailedOtherwiseApplyFunction(res, f); }
@Test public void testSucceededAsyncResultMap() { Future<String> f = Future.future(); AsyncResult<String> res = asyncResult(f); AsyncResult<Integer> map1 = res.map(String::length); AsyncResult<Integer> map2 = res.map(17); f.complete("foobar"); assertEquals(6, (int)map1.result()); assertNull(map1.cause()); assertEquals(17, (int)map2.result()); assertNull(map2.cause()); }
@Test public void testSucceededAsyncResultOtherwise() { Future<String> f = Future.future(); AsyncResult<String> res = asyncResult(f); testSucceededOtherwise(res, f); }
@Test public void testUncompletedAsyncResultOtherwiseApplyFunction() { Future<String> f = Future.future(); AsyncResult<String> res = asyncResult(f); testUncompletedOtherwiseApplyFunction(res); }
@Test public void testSucceededAsyncResultOtherwiseApplyFunction() { Future<String> f = Future.future(); AsyncResult<String> res = asyncResult(f); testSucceededOtherwiseApplyFunction(res, f); }
@Test public void testUncompletedAsyncResultMap() { Future<String> f = Future.future(); AsyncResult<String> res = asyncResult(f); AsyncResult<Integer> map1 = res.map(String::length); AsyncResult<Integer> map2 = res.map(17); assertNull(map1.result()); assertNull(map1.cause()); assertNull(map2.result()); assertNull(map2.cause()); }
@Test public void testMapWithNullFunction() { Future<Integer> fut = Future.future(); try { fut.map((Function<Integer, String>) null); fail(); } catch (NullPointerException ignore) { } try { asyncResult(fut).map((Function<Integer, String>) null); fail(); } catch (NullPointerException ignore) { } }
@Test public void testOtherwiseWithNullFunction() { Future<Integer> fut = Future.future(); try { fut.otherwise((Function<Throwable, Integer>) null); fail(); } catch (NullPointerException ignore) { } try { asyncResult(fut).otherwise((Function<Throwable, Integer>) null); fail(); } catch (NullPointerException ignore) { } }
@Test public void testAsyncResultMapEmpty() { Future<String> f = Future.future(); AsyncResult<String> res = asyncResult(f); AsyncResult<Integer> map = res.mapEmpty(); f.complete("foobar"); assertNull(null, map.result()); assertNull(map.cause()); }
@Test public void testAsyncResultOtherwiseEmpty() { Future<String> f = Future.future(); AsyncResult<String> res = asyncResult(f); testOtherwiseEmpty(res, f); }
@Test public void testUncompletedAsyncResultOtherwise() { Future<String> f = Future.future(); AsyncResult<String> res = asyncResult(f); testUncompletedAsyncResultOtherwise(res); }
@Test public void testSucceededAsyncResultOtherwise() { Future<String> f = Future.future(); AsyncResult<String> res = asyncResult(f); testSucceededOtherwise(res, f); }
@Test public void testSucceededAsyncResultMap() { Future<String> f = Future.future(); AsyncResult<String> res = asyncResult(f); AsyncResult<Integer> map1 = res.map(String::length); AsyncResult<Integer> map2 = res.map(17); f.complete("foobar"); assertEquals(6, (int)map1.result()); assertNull(map1.cause()); assertEquals(17, (int)map2.result()); assertNull(map2.cause()); }
@Test public void testSucceededAsyncResultOtherwiseApplyFunction() { Future<String> f = Future.future(); AsyncResult<String> res = asyncResult(f); testSucceededOtherwiseApplyFunction(res, f); }
@Test public void testUncompletedAsyncResultMap() { Future<String> f = Future.future(); AsyncResult<String> res = asyncResult(f); AsyncResult<Integer> map1 = res.map(String::length); AsyncResult<Integer> map2 = res.map(17); assertNull(map1.result()); assertNull(map1.cause()); assertNull(map2.result()); assertNull(map2.cause()); }