### Question:
FileLocationContextListener implements ServletContextListener { public void contextInitialized(ServletContextEvent servletContextEvent) { String rootPath = System.getProperty("catalina.home"); ServletContext ctx = servletContextEvent.getServletContext(); String relativePath = ctx.getInitParameter("tempfile.dir"); File file = new File(rootPath + File.separator + relativePath); if(!file.exists()) file.mkdirs(); System.out.println("File Directory created to be used for storing files"); ctx.setAttribute("FILES_DIR_FILE", file); ctx.setAttribute("FILES_DIR", rootPath + File.separator + relativePath); }  void contextInitialized(ServletContextEvent servletContextEvent); void contextDestroyed(ServletContextEvent servletContextEvent);  }### Answer:
@Test public void testContextInitialized() { ServletContextEvent contextEvent = mock(ServletContextEvent.class); ServletContext context = mock(ServletContext.class); when(contextEvent.getServletContext()).thenReturn(context); when(context.getAttribute("tempfile.dir")).thenReturn("tmpfiles"); FileLocationContextListener instance = new FileLocationContextListener(); instance.contextInitialized(contextEvent); }