@Test
  public void handle_only_diff_parameter() throws Exception {
    final String data = null;
    final String help = null;
    final String nnew = null;
    final String diff = "YES";
    final String redirect = null;
    final String source = "test";
    final String contentType = "UTF-8";

    final Response response =
        subject.doGet(request, source, data, help, nnew, diff, redirect, contentType);

    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_BAD_REQUEST));
    assertThat(response.getEntity().toString(), is("Invalid request"));
  }
  @Test
  public void handle_invalid_encoding() throws Exception {
    final String data = "person";
    final String help = null;
    final String nnew = null;
    final String diff = null;
    final String redirect = null;
    final String source = "test";
    final String contentType = "text/plain; charset=RGRFE";

    final Response response =
        subject.doGet(request, source, data, help, nnew, diff, redirect, contentType);

    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK));
    assertThat(response.getEntity().toString(), is("OK"));
  }
  @Test
  public void handle_redirect_not_allowed() throws Exception {
    final String data = "person";
    final String help = null;
    final String nnew = null;
    final String diff = null;
    final String redirect = "YES";
    final String source = "test";
    final String contentType = "UTF-8";

    final Response response =
        subject.doGet(request, source, data, help, nnew, diff, redirect, contentType);

    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_FORBIDDEN));
    assertThat(
        response.getEntity().toString(), is("Not allowed to disable notifications: 127.0.0.1"));
  }
  @Test
  public void handle_redirect_allowed() throws Exception {
    final String data = "person";
    final String help = null;
    final String nnew = null;
    final String diff = null;
    final String redirect = "YES";
    final String source = "test";
    final String contentType = "UTF-8";

    when(ipRanges.isTrusted(any(Interval.class))).thenReturn(true);
    final Response response =
        subject.doGet(request, source, data, help, nnew, diff, redirect, contentType);

    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK));
    assertThat(response.getEntity().toString(), is("OK"));
  }
  @Test
  public void handle_unauthorised() throws Exception {
    final String data = "person";
    final String help = null;
    final String nnew = null;
    final String diff = null;
    final String redirect = null;
    final String source = "test";
    final String contentType = "UTF-8";

    when(messageHandler.handle(any(UpdateRequest.class), any(UpdateContext.class)))
        .thenReturn(new UpdateResponse(UpdateStatus.FAILED_AUTHENTICATION, "FAILED"));
    final Response response =
        subject.doGet(request, source, data, help, nnew, diff, redirect, contentType);

    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_UNAUTHORIZED));
    assertThat(response.getEntity().toString(), is("FAILED"));
  }
  @Test
  public void handle_invalid_content_type() throws Exception {
    final String data = "person";
    final String help = null;
    final String nnew = null;
    final String diff = null;
    final String redirect = null;
    final String source = "test";
    final String contentType = "invalid";

    final Response response =
        subject.doGet(request, source, data, help, nnew, diff, redirect, contentType);

    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK));
    assertThat(response.getEntity().toString(), is("OK"));
    List<Object> contentLengthResponse = response.getMetadata().get(HttpHeaders.CONTENT_TYPE);
    assertThat(contentLengthResponse.size(), is(1));
    assertThat(contentLengthResponse.get(0).toString(), is("text/plain"));
  }
  @Test
  public void content_type_and_content_length_in_response() throws Exception {
    final String data = "person";
    final String help = null;
    final String nnew = null;
    final String diff = null;
    final String redirect = null;
    final String source = "test";
    final String contentType = "text/plain; charset=US-ASCII";

    final Response response =
        subject.doGet(request, source, data, help, nnew, diff, redirect, contentType);

    List<Object> contentLengthResponse = response.getMetadata().get(HttpHeaders.CONTENT_TYPE);
    assertThat(contentLengthResponse.size(), is(1));
    assertThat(contentLengthResponse.get(0).toString(), is("text/plain"));
    List<Object> contentTypeResponse = response.getMetadata().get(HttpHeaders.CONTENT_LENGTH);
    assertThat(contentTypeResponse.size(), is(1));
    assertThat(contentTypeResponse.get(0).toString(), is("2"));
  }
  @Test
  public void throw_runtime_exception() throws Exception {
    try {
      final String data = "person";
      final String help = null;
      final String nnew = null;
      final String diff = null;
      final String redirect = null;
      final String source = "test";
      final String contentType = "UTF-8";

      doThrow(new RuntimeException("some message", new IllegalStateException("some message")))
          .when(messageHandler)
          .handle(any(UpdateRequest.class), any(UpdateContext.class));

      subject.doGet(request, source, data, help, nnew, diff, redirect, contentType);
      fail();
    } catch (RuntimeException e) {
      assertThat(e.getMessage(), is("some message"));
    }
  }