### Question:
Requester { public JsonValue update(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.ifTrue(StringUtils.isEmpty(resourceId), "The resourceId to update may not be null or empty."); Reject.ifNull(payload, "The payload object to create must not be null."); final Router rootRouter = router.get(); final UpdateRequest updateRequest = Requests.newUpdateRequest(location, resourceId, payload); return rootRouter.handleUpdate(context, updateRequest).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 = NullPointerException.class) public void nullPayloadBreaksUpdate() throws ResourceException { String location = "location"; String resourceId = "resourceId"; JsonValue payload = null; requester.update(location, resourceId, payload, mockServerContext); }
@Test(expectedExceptions = IllegalArgumentException.class) public void emptyLocationBreaksUpdate() throws ResourceException { String location = ""; String resourceId = "resourceId"; JsonValue payload = JsonValueBuilder.jsonValue().build(); requester.update(location, resourceId, payload, mockServerContext); }
@Test(expectedExceptions = IllegalArgumentException.class) public void nullLocationBreaksUpdate() throws ResourceException { String location = null; String resourceId = "resourceId"; JsonValue payload = JsonValueBuilder.jsonValue().build(); requester.update(location, resourceId, payload, mockServerContext); }
@Test(expectedExceptions = IllegalArgumentException.class) public void emptyResourceIdBreaksUpdate() throws ResourceException { String location = "location"; String resourceId = ""; JsonValue payload = JsonValueBuilder.jsonValue().build(); requester.update(location, resourceId, payload, mockServerContext); }
@Test(expectedExceptions = IllegalArgumentException.class) public void nullResourceIdBreaksUpdate() throws ResourceException { String location = "location"; String resourceId = null; JsonValue payload = JsonValueBuilder.jsonValue().build(); requester.update(location, resourceId, payload, mockServerContext); }
@Test public void shouldExecuteUpdateOperation() 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.handleUpdate(any(Context.class), any(UpdateRequest.class))).willReturn(mockResponse); given(mockResponse.getOrThrowUninterruptibly()).willReturn(mockResourceResponse); given(mockResourceResponse.getContent()).willReturn(expectedResult); JsonValue actualResult = requester.update(location, resourceId, payload, mockServerContext); verify(mockRealmRouterProvider, times(1)).get(); verifyNoMoreInteractions(mockRealmRouterProvider); verify(mockRouter, times(1)).handleUpdate(any(Context.class), any(UpdateRequest.class)); verifyNoMoreInteractions(mockRouter); verify(mockResponse, times(1)).getOrThrowUninterruptibly(); verifyNoMoreInteractions(mockResponse); verify(mockResourceResponse, times(1)).getContent(); verifyNoMoreInteractions(mockResourceResponse); assertThat(actualResult).isEqualTo(expectedResult); }