### Question:
Requester { public JsonValue action(String location, String resourceId, String actionId, JsonValue payload, Context context) throws ResourceException { Reject.ifTrue(StringUtils.isEmpty(location), "The endpoint destination may not be null or empty."); Reject.ifTrue(StringUtils.isEmpty(actionId), "The specific action to perform may not be null or empty."); final Router rootRouter = router.get(); final ActionRequest actionRequest = Requests.newActionRequest(location, actionId); if (payload != null) { actionRequest.setContent(payload); } if (resourceId != null) { actionRequest.setResourcePath(resourceId); } return rootRouter.handleAction(context, actionRequest).getOrThrowUninterruptibly().getJsonContent(); } @Inject  Requester(@Named("CrestRootRouter") Provider<Router> router); JsonValue create(String location, String resourceId, JsonValue payload, Context context); JsonValue read(String location, String resourceId, Context context); JsonValue update(String location, String resourceId, JsonValue payload, Context context); JsonValue delete(String location, String resourceId, Context context); JsonValue action(String location, String resourceId, String actionId, JsonValue payload,
                                    Context context); JsonValue query(String location, String queryId, Context context);  }### Answer:
@Test(expectedExceptions = IllegalArgumentException.class) public void nullActionIdBreaksAction() throws ResourceException { String location = "location"; String actionId = null; String resourceId = "resourceId"; JsonValue payload = JsonValueBuilder.jsonValue().build(); requester.action(location, resourceId, actionId, payload, mockServerContext); }
@Test(expectedExceptions = IllegalArgumentException.class) public void emptyActionIdBreaksAction() throws ResourceException { String location = "location"; String actionId = ""; String resourceId = "resourceId"; JsonValue payload = JsonValueBuilder.jsonValue().build(); requester.action(location, resourceId, actionId, payload, mockServerContext); }
@Test(expectedExceptions = IllegalArgumentException.class) public void nullLocationBreaksAction() throws ResourceException { String location = null; String actionId = "actionId"; String resourceId = "resourceId"; JsonValue payload = JsonValueBuilder.jsonValue().build(); requester.action(location, resourceId, actionId, payload, mockServerContext); }
@Test(expectedExceptions = IllegalArgumentException.class) public void emptyLocationBreaksAction() throws ResourceException { String location = ""; String actionId = "actionId"; String resourceId = "resourceId"; JsonValue payload = JsonValueBuilder.jsonValue().build(); requester.action(location, resourceId, actionId, payload, mockServerContext); }
@Test public void shouldExecuteActionOperation() throws ResourceException { String location = "location"; String resourceId = "resourceId"; String actionId = "actionId"; JsonValue payload = JsonValueBuilder.jsonValue().build(); JsonValue expectedResult = JsonValueBuilder.toJsonValue("{ \"lemon\" : \"custard\" } "); Promise<ActionResponse, ResourceException> mockResponse = mock(Promise.class); ActionResponse mockResourceResponse = mock(ActionResponse.class); given(mockRealmRouterProvider.get()).willReturn(mockRouter); given(mockRouter.handleAction(any(Context.class), any(ActionRequest.class))).willReturn(mockResponse); given(mockResponse.getOrThrowUninterruptibly()).willReturn(mockResourceResponse); given(mockResourceResponse.getJsonContent()).willReturn(expectedResult); JsonValue actualResult = requester.action(location, resourceId, actionId, payload, mockServerContext); verify(mockRealmRouterProvider, times(1)).get(); verifyNoMoreInteractions(mockRealmRouterProvider); verify(mockRouter, times(1)).handleAction(any(Context.class), any(ActionRequest.class)); verifyNoMoreInteractions(mockRouter); verify(mockResponse, times(1)).getOrThrowUninterruptibly(); verifyNoMoreInteractions(mockResponse); verify(mockResourceResponse, times(1)).getJsonContent(); verifyNoMoreInteractions(mockResourceResponse); assertThat(actualResult).isEqualTo(expectedResult); }