### Question:
ShowContactsController extends HttpServlet { @Override public void init(ServletConfig config) throws ServletException { super.init(config); addressBook = (GlobalAddressBook) config.getServletContext().getAttribute("globalAddressBook"); viewPath = config.getInitParameter("view"); }  @Override void init(ServletConfig config); GlobalAddressBook getAddressBook(); void setAddressBook(GlobalAddressBook addressBook); String getViewPath();  }### Answer:
@Test public void testInit() throws ServletException { ServletConfig config = mock(ServletConfig.class); when(config.getInitParameter("view")).thenReturn("viewPathValue"); ServletContext context = mock(ServletContext.class); when(config.getServletContext()).thenReturn(context); when(context.getAttribute("globalAddressBook")).thenReturn(mockAddressbook); ShowContactsController notInitController = new ShowContactsController(); notInitController.init(config); assertTrue("init addressbook failed", notInitController.getAddressBook() instanceof GlobalAddressBook); assertEquals("viewPathValue", notInitController.getViewPath()); }