@Test public void testProcessMethodGet() throws IOException { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); when(request.getMethod()).thenReturn("GET"); PrintWriter printWriter = mock(PrintWriter.class); when(response.getWriter()).thenReturn(printWriter); headerHandler.process(request, response); verify(response).setHeader(ALLOW_ORIGIN, STAR); verify(response).setHeader(ALLOW_CREDENTIALS, TRUE); verify(response).setHeader(ALLOW_HEADERS, request.getHeader(REQUEST_HEADERS)); verify(printWriter, never()).print(OK); verify(printWriter, never()).flush(); }
public void process(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setHeader(ALLOW_ORIGIN, STAR); response.setHeader(ALLOW_CREDENTIALS, TRUE); response.setHeader(ALLOW_HEADERS, request.getHeader(REQUEST_HEADERS)); if (request.getMethod().equals(OPTIONS)) { response.getWriter().print(OK); response.getWriter().flush(); } }
HeaderHandler { public void process(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setHeader(ALLOW_ORIGIN, STAR); response.setHeader(ALLOW_CREDENTIALS, TRUE); response.setHeader(ALLOW_HEADERS, request.getHeader(REQUEST_HEADERS)); if (request.getMethod().equals(OPTIONS)) { response.getWriter().print(OK); response.getWriter().flush(); } } }
HeaderHandler { public void process(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setHeader(ALLOW_ORIGIN, STAR); response.setHeader(ALLOW_CREDENTIALS, TRUE); response.setHeader(ALLOW_HEADERS, request.getHeader(REQUEST_HEADERS)); if (request.getMethod().equals(OPTIONS)) { response.getWriter().print(OK); response.getWriter().flush(); } }  }
HeaderHandler { public void process(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setHeader(ALLOW_ORIGIN, STAR); response.setHeader(ALLOW_CREDENTIALS, TRUE); response.setHeader(ALLOW_HEADERS, request.getHeader(REQUEST_HEADERS)); if (request.getMethod().equals(OPTIONS)) { response.getWriter().print(OK); response.getWriter().flush(); } }  void process(HttpServletRequest request, HttpServletResponse response); }
HeaderHandler { public void process(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setHeader(ALLOW_ORIGIN, STAR); response.setHeader(ALLOW_CREDENTIALS, TRUE); response.setHeader(ALLOW_HEADERS, request.getHeader(REQUEST_HEADERS)); if (request.getMethod().equals(OPTIONS)) { response.getWriter().print(OK); response.getWriter().flush(); } }  void process(HttpServletRequest request, HttpServletResponse response);  }