SchemaProviderServlet extends HttpServlet { @Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { PrintWriter out = resp.getWriter(); resp.setContentType("application/xml"); writeSchemaFile(out); out.flush(); out.close(); } @Autowired  SchemaProviderServlet(String stubConfigSchemaLocation, BufferedReaderFactory bufferedReaderFactory);   }
@Test public void testDoGetShouldWriteSchemaFile() throws ServletException, IOException { String nullString = null; given(bufferedReaderFactory.createBufferedReader(SCHEMA)).willReturn(reader); given(reader.readLine()).willReturn("first line", nullString); underTest.doGet(request, response); verify(writer).write(Mockito.anyString()); }
@Test public void testDoGetShouldSetContentTypeToXml() throws ServletException, IOException { String nullString = null; given(bufferedReaderFactory.createBufferedReader(SCHEMA)).willReturn(reader); given(reader.readLine()).willReturn(nullString); underTest.doGet(request, response); verify(response).setContentType("application/xml"); }
@Test public void testDoGetShouldCloseWriter() throws ServletException, IOException { String nullString = null; given(bufferedReaderFactory.createBufferedReader(SCHEMA)).willReturn(reader); given(reader.readLine()).willReturn(nullString); underTest.doGet(request, response); verify(writer).close(); }
@Test public void testDoGetWhenIOExceptionShouldLogError() throws ServletException, IOException { given(bufferedReaderFactory.createBufferedReader(SCHEMA)).willReturn(reader); IOException exception = new IOException(); given(reader.readLine()).willThrow(exception); underTest.doGet(request, response); verify(logger).error(SCHEMA + " could not be read!", exception); }