@Test public void testPutAndGet() throws ServletException, IOException { MovieServlet movieServlet = new MovieServlet(); movieServlet.init(); long movieId = testPut(movieServlet); testGet(movieServlet, movieId); }
@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 }
@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 }