### Question:
Reakt { public static <T> Callback<T> convertCallback(final io.advantageous.reakt.CallbackHandler<T> callback) { return convertReaktCallbackToQBitCallback(callback, CallbackBuilder.callbackBuilder()); }  static Callback<T> convertPromise(final Promise<T> promise); static Callback<T> convertPromise(final Reactor reactor, final Promise<T> promise); static Callback<T> convertCallback(final io.advantageous.reakt.CallbackHandler<T> callback); static io.advantageous.reakt.CallbackHandler<T> convertQBitCallback(final Callback<T> callback); static Callback<T> convertCallback(final Reactor reactor,
                                                  final io.advantageous.reakt.CallbackHandler<T> callback); Callback<T> callback(final Consumer<Promise<T>> promiseConsumer);  }### Answer:
@Test public void testConvertCallback() throws Exception { final AtomicReference<Result<Employee>> ref = new AtomicReference<>(); final io.advantageous.reakt.CallbackHandler<Employee> callback = ref::set; final Callback<Employee> employeeCallback = Reakt.convertCallback(callback); employeeCallback.resolve(new Employee("Rick")); final Result<Employee> result = ref.get(); assertNotNull(ref.get()); assertTrue(result.complete()); assertTrue(result.success()); assertFalse(result.failure()); assertTrue(result.expect().isPresent()); assertEquals("Rick", result.expect().get().name); }
@Test public void testConvertCallbackUsingReactor() throws Exception { final AtomicReference<Result<Employee>> ref = new AtomicReference<>(); final io.advantageous.reakt.CallbackHandler<Employee> callback = ref::set; final Reactor reactor = ReactorBuilder.reactorBuilder().build(); final Callback<Employee> employeeCallback = Reakt.convertCallback(reactor, callback); employeeCallback.resolve(new Employee("Rick")); reactor.process(); final Result<Employee> result = ref.get(); assertNotNull(ref.get()); assertTrue(result.complete()); assertTrue(result.success()); assertFalse(result.failure()); assertTrue(result.expect().isPresent()); assertEquals("Rick", result.expect().get().name); }
@Test public void testConvertCallbackFailure() throws Exception { final AtomicReference<Result<Employee>> ref = new AtomicReference<>(); final io.advantageous.reakt.CallbackHandler<Employee> callback = ref::set; final Callback<Employee> employeeCallback = Reakt.convertCallback(callback); employeeCallback.reject("NOT FOUND"); final Result<Employee> result = ref.get(); assertNotNull(ref.get()); assertTrue(result.complete()); assertFalse(result.success()); assertTrue(result.failure()); try { assertTrue(result.expect().isPresent()); fail(); } catch (Exception ex) { } assertNotNull(result.cause()); }
@Test public void testConvertCallbackFailureTimeout() throws Exception { final AtomicReference<Result<Employee>> ref = new AtomicReference<>(); final io.advantageous.reakt.CallbackHandler<Employee> callback = ref::set; final Callback<Employee> employeeCallback = Reakt.convertCallback(callback); employeeCallback.onTimeout(); final Result<Employee> result = ref.get(); assertNotNull(ref.get()); assertTrue(result.complete()); assertFalse(result.success()); assertTrue(result.failure()); try { assertTrue(result.expect().isPresent()); fail(); } catch (Exception ex) { } assertNotNull(result.cause()); }