Пример #1
0
  @Test
  public void testPutAndGet() throws ServletException, IOException {
    MovieServlet movieServlet = new MovieServlet();
    movieServlet.init();

    long movieId = testPut(movieServlet);
    testGet(movieServlet, movieId);
  }
Пример #2
0
  @Test
  public void testGetWithNotExistingId() throws ServletException, IOException {
    MovieServlet movieServlet = new MovieServlet();
    movieServlet.init();

    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);

    when(request.getPathInfo()).thenReturn("/333");
    movieServlet.doGet(request, response);

    verify(response, atLeastOnce()).setStatus(404); // not found
  }
Пример #3
0
  @Test
  public void testGetWithBadId() throws ServletException, IOException {
    MovieServlet movieServlet = new MovieServlet();
    movieServlet.init();

    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);

    when(request.getPathInfo()).thenReturn("/some_string");
    movieServlet.doGet(request, response);

    verify(response, atLeastOnce()).setStatus(400); // bad request
  }