### Question:
BoonServiceMethodCallHandler implements ServiceMethodHandler { @Override public Response<Object> receiveMethodCall(MethodCall<Object> methodCall) { try { return invokeByName(methodCall); } catch (Exception ex) { if (ex.getCause() instanceof InvocationTargetException) { InvocationTargetException tex = (InvocationTargetException) ex.getCause(); return new ResponseImpl<>(methodCall, tex.getTargetException()); } return new ResponseImpl<>(methodCall, ex); } } BoonServiceMethodCallHandler(final boolean invokeDynamic); @Override Response<Object> receiveMethodCall(MethodCall<Object> methodCall); boolean couldHaveCallback(final String name); @Override void init(
            Object service,
            String rootAddress,
            String serviceAddress,
            SendQueue<Response<Object>> responseSendQueue); @Override void init(); @Override void startBatch(); @Override TreeSet<String> addresses(); @Override void handleEvent(Event<Object> event); @Override String address(); @Override String name(); @Override void receive(MethodCall<Object> item); @Override void empty(); @Override void limit(); @Override void shutdown(); @Override void idle();  }### Answer:
@Test public void testCallMethodWithCallback() { class MyServiceForInvoke { boolean called; public void method(Callback<Boolean> callback) { called = true; callback.resolve(true); } } MyServiceForInvoke myService = new MyServiceForInvoke(); final BoonServiceMethodCallHandler boonServiceMethodCallHandler = new BoonServiceMethodCallHandler(true); Promise<Boolean> promise = Promises.blockingPromiseBoolean(); initHandlerWithPromise(myService, boonServiceMethodCallHandler, promise); final MethodCall<Object> method = MethodCallBuilder.methodCallBuilder().setName("method").build(); final Response<Object> response = boonServiceMethodCallHandler.receiveMethodCall(method); assertFalse(response.wasErrors()); assertTrue(myService.called); assertTrue(promise.asHandler().success()); }
@Test public void testCallMethodWithPromise() { class MyServiceForInvokablePromise { boolean called; public Promise<Boolean> method() { return Promises.invokablePromise(promise -> { called = true; promise.resolve(true); }); } } MyServiceForInvokablePromise myService = new MyServiceForInvokablePromise(); final BoonServiceMethodCallHandler boonServiceMethodCallHandler = new BoonServiceMethodCallHandler(true); Promise<Boolean> promise = Promises.blockingPromiseBoolean(); initHandlerWithPromise(myService, boonServiceMethodCallHandler, promise); final MethodCall<Object> method = MethodCallBuilder.methodCallBuilder().setName("method").build(); final Response<Object> response = boonServiceMethodCallHandler.receiveMethodCall(method); assertFalse(response.wasErrors()); assertTrue(myService.called); assertTrue(promise.asHandler().success()); }
@Test public void testCallMethodWithPromiseNonDynamic() { class MyServiceForInvokablePromiseNonDynamic { boolean called; public Promise<Boolean> method() { return Promises.invokablePromise(promise -> { called = true; promise.resolve(true); }); } } MyServiceForInvokablePromiseNonDynamic myService = new MyServiceForInvokablePromiseNonDynamic(); final BoonServiceMethodCallHandler boonServiceMethodCallHandler = new BoonServiceMethodCallHandler(false); Promise<Boolean> promise = Promises.blockingPromiseBoolean(); initHandlerWithPromise(myService, boonServiceMethodCallHandler, promise); final MethodCall<Object> method = MethodCallBuilder.methodCallBuilder().setName("method").setBody(new Object[]{}).build(); final Response<Object> response = boonServiceMethodCallHandler.receiveMethodCall(method); assertFalse(response.wasErrors()); assertTrue(myService.called); assertTrue(promise.asHandler().success()); }