GatewayReceiverCreateFunction implements InternalFunction<Object[]> { @Override public void execute(FunctionContext<Object[]> context) { ResultSender<Object> resultSender = context.getResultSender(); Cache cache = context.getCache(); String memberNameOrId = context.getMemberName(); Object[] gatewayReceiverCreateArgs = context.getArguments(); GatewayReceiverConfig gatewayReceiverConfig = (GatewayReceiverConfig) gatewayReceiverCreateArgs[0]; Boolean ifNotExist = (Boolean) gatewayReceiverCreateArgs[1]; if (gatewayReceiverExists(cache)) { CliFunctionResult result; if (ifNotExist) { result = new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.OK, "Skipping: " + A_GATEWAY_RECEIVER_ALREADY_EXISTS_ON_THIS_MEMBER); } else { Exception illegalState = new IllegalStateException(A_GATEWAY_RECEIVER_ALREADY_EXISTS_ON_THIS_MEMBER); result = new CliFunctionResult(memberNameOrId, illegalState, illegalState.getMessage()); } resultSender.lastResult(result); return; } try { GatewayReceiver createdGatewayReceiver = createGatewayReceiver(cache, gatewayReceiverConfig); resultSender.lastResult(new CliFunctionResult(memberNameOrId, CliFunctionResult.StatusState.OK, CliStrings.format( CliStrings.CREATE_GATEWAYRECEIVER__MSG__GATEWAYRECEIVER_CREATED_ON_0_ONPORT_1, memberNameOrId, Integer.toString(createdGatewayReceiver.getPort())))); } catch (IllegalStateException e) { resultSender.lastResult(new CliFunctionResult(memberNameOrId, e, e.getMessage())); } catch (Exception e) { logger.error(e.getMessage(), e); resultSender.lastResult(new CliFunctionResult(memberNameOrId, e, e.getMessage())); } }  @Override void execute(FunctionContext<Object[]> context); @Override String getId(); @Immutable
  static final GatewayReceiverCreateFunction INSTANCE; }
@Test public void testFunctionSuccessResult() { function.execute(context); ArgumentCaptor<Object> resultObject = ArgumentCaptor.forClass(Object.class); verify(resultSender, times(1)).lastResult(resultObject.capture()); CliFunctionResult result = (CliFunctionResult) resultObject.getValue(); assertThat(result.getStatusMessage()).contains("5555"); }