### Question:
Requester { public JsonValue create(String location, String resourceId, JsonValue payload, Context context) throws ResourceException { Reject.ifTrue(StringUtils.isEmpty(location), "The endpoint destination may not be null or empty."); Reject.ifNull(payload, "The payload object to create must not be null."); final Router rootRouter = router.get(); final CreateRequest createRequest = Requests.newCreateRequest(location, payload); if (resourceId != null) { createRequest.setNewResourceId(resourceId); } return rootRouter.handleCreate(context, createRequest).getOrThrowUninterruptibly().getContent(); } @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 emptyLocationBreaksCreate() throws ResourceException { String location = ""; String resourceId = "resourceId"; JsonValue payload = JsonValueBuilder.jsonValue().build(); requester.create(location, resourceId, payload, mockServerContext); }
@Test(expectedExceptions = IllegalArgumentException.class) public void nullLocationBreaksCreate() throws ResourceException { String location = null; String resourceId = "resourceId"; JsonValue payload = JsonValueBuilder.jsonValue().build(); requester.create(location, resourceId, payload, mockServerContext); }
@Test(expectedExceptions = NullPointerException.class) public void nullPayloadBreaksCreate() throws ResourceException { String location = "location"; String resourceId = "resourceId"; JsonValue payload = null; requester.create(location, resourceId, payload, mockServerContext); }
@Test public void shouldExecuteCreateRequest() throws ResourceException { String location = "location"; String resourceId = "resourceId"; JsonValue payload = JsonValueBuilder.jsonValue().build(); JsonValue expectedResult = JsonValueBuilder.toJsonValue("{ \"lemon\" : \"custard\" } "); Promise<ResourceResponse, ResourceException> mockResponse = mock(Promise.class); ResourceResponse mockResourceResponse = mock(ResourceResponse.class); ; given(mockRealmRouterProvider.get()).willReturn(mockRouter); given(mockRouter.handleCreate(any(Context.class), any(CreateRequest.class))).willReturn(mockResponse); given(mockResponse.getOrThrowUninterruptibly()).willReturn(mockResourceResponse); given(mockResourceResponse.getContent()).willReturn(expectedResult); JsonValue actualResult = requester.create(location, resourceId, payload, mockServerContext); verify(mockRealmRouterProvider, times(1)).get(); verifyNoMoreInteractions(mockRealmRouterProvider); verify(mockRouter, times(1)).handleCreate(any(Context.class), any(CreateRequest.class)); verifyNoMoreInteractions(mockRouter); verify(mockResponse, times(1)).getOrThrowUninterruptibly(); verifyNoMoreInteractions(mockResponse); verify(mockResourceResponse, times(1)).getContent(); verifyNoMoreInteractions(mockResourceResponse); assertThat(actualResult).isEqualTo(expectedResult); }