@Test
public void testUpdateDestination() throws Exception {

    //Create Destination to update
    CreateDestinationRequest request = new CreateDestinationRequest();
    final String destination = "/foo/bar";
    final String email = "foo@bar.com";
    final int consumedRetention = new Random().nextInt();
    final int unconsumedRetention = new Random().nextInt();
    request.setPath(destination);
    request.setOwnerEmail(email);
    request.setType(DestinationType.PLAIN);
    request.setConsumedMessagesRetention(consumedRetention);
    request.setUnconsumedMessagesRetention(unconsumedRetention);
    client.createDestination(request);
    //Update the email of a Destination with path destination
    UpdateDestinationRequest updateRequest = new UpdateDestinationRequest();
    final String newEmail = "foo@uber.com";
    updateRequest.setPath(destination);
    updateRequest.setOwnerEmail(newEmail);
    updateRequest.setUnconsumedMessagesRetention(unconsumedRetention);
    updateRequest.setConsumedMessagesRetention(consumedRetention);
    updateRequest.setStatus(DestinationStatus.ENABLED);
    DestinationDescription response = client.updateDestination(updateRequest);
    // Simple case where updateDestination returns updated destination
    assert (response.getOwnerEmail().equals(newEmail));
    ReadDestinationRequest readRequest = new ReadDestinationRequest();
    readRequest.setPath(destination);
    DestinationDescription result = client.readDestination(readRequest);
    //Read Destination to make sure server actually updated
    assert (result.getPath().equals(destination));
    assert (result.getOwnerEmail().equals(newEmail));
    //Client should not be able to update a nonexistent Destination
    thrown.expect(EntityNotExistsError.class);
    updateRequest.setPath("/invalid/path");
    client.updateDestination(updateRequest);
}