コード例 #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);
  }
コード例 #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);
  }
コード例 #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);
  }
コード例 #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);
  }
コード例 #5
0
 @Before
 public void setUp() throws Exception {
   servlet.add(gc);
   servlet.add(clearCache);
 }