Exemplo n.º 1
0
  @Test
  public void returnsA404WhenNotFound() throws Exception {
    when(request.getMethod()).thenReturn("POST");
    when(request.getPathInfo()).thenReturn("/test");

    servlet.service(request, response);

    verify(response).sendError(404);
  }
Exemplo n.º 2
0
  @Test
  public void passesQueryStringParamsAlong() throws Exception {
    final PrintWriter output = mock(PrintWriter.class);

    when(request.getMethod()).thenReturn("POST");
    when(request.getPathInfo()).thenReturn("/gc");
    when(request.getParameterNames()).thenReturn(Collections.enumeration(ImmutableList.of("runs")));
    when(request.getParameterValues("runs")).thenReturn(new String[] {"1"});
    when(response.getWriter()).thenReturn(output);

    servlet.service(request, response);

    verify(gc).execute(ImmutableMultimap.of("runs", "1"), output);
  }
Exemplo n.º 3
0
  @Test
  public void runsATaskWhenFound() throws Exception {
    final PrintWriter output = mock(PrintWriter.class);

    when(request.getMethod()).thenReturn("POST");
    when(request.getPathInfo()).thenReturn("/gc");
    when(request.getParameterNames())
        .thenReturn(Collections.enumeration(ImmutableList.<String>of()));
    when(response.getWriter()).thenReturn(output);

    servlet.service(request, response);

    verify(gc).execute(ImmutableMultimap.<String, String>of(), output);
  }
Exemplo n.º 4
0
  @Test
  @SuppressWarnings("unchecked")
  public void returnsA500OnExceptions() throws Exception {
    when(request.getMethod()).thenReturn("POST");
    when(request.getPathInfo()).thenReturn("/gc");
    when(request.getParameterNames())
        .thenReturn(Collections.enumeration(ImmutableList.<String>of()));

    final PrintWriter output = mock(PrintWriter.class);
    when(response.getWriter()).thenReturn(output);

    final RuntimeException ex = new RuntimeException("whoops");

    doThrow(ex).when(gc).execute(any(ImmutableMultimap.class), any(PrintWriter.class));

    servlet.service(request, response);

    verify(response).setStatus(500);
  }