### Question:
AddContactController extends HttpServlet { @Override public void init(ServletConfig config) throws ServletException { super.init(config); addressBook = (GlobalAddressBook) config.getServletContext().getAttribute("globalAddressBook"); formView = config.getInitParameter("formView"); successedSubmitRedirect = config.getInitParameter("successedSubmitRedirect"); }  @Override void init(ServletConfig config); GlobalAddressBook getAddressBook(); void setAddressBook(GlobalAddressBook addressBook); String getSuccessedSubmitRedirect(); void setSuccessedSubmitRedirect(String successedSubmitRedirect); String getFormView(); void setFormView(String formView);  }### Answer:
@Test public void testInit() throws ServletException { ServletConfig config = mock(ServletConfig.class); when(config.getInitParameter("formView")).thenReturn("formViewValue"); when(config.getInitParameter("successedSubmitRedirect")).thenReturn("successedSubmitRedirectValue"); ServletContext context = mock(ServletContext.class); when(config.getServletContext()).thenReturn(context); when(context.getAttribute("globalAddressBook")).thenReturn(mockAddressbook); AddContactController notInitController = new AddContactController(); notInitController.init(config); assertTrue("init addressbook failed", notInitController.getAddressBook() instanceof GlobalAddressBook); assertEquals("formViewValue", notInitController.getFormView()); assertEquals("successedSubmitRedirectValue", notInitController.getSuccessedSubmitRedirect()); }