HsqldbStartupListener implements ServletContextListener { public void contextDestroyed( ServletContextEvent sce ) { ServletContext ctx = sce.getServletContext(); Object obj = ctx.getAttribute( "hsqldb-starter-bean" ); if ( obj != null ) { logger.debug( "Context listener stopping Embedded HSQLDB" ); HsqlDatabaseStarterBean starterBean = (HsqlDatabaseStarterBean) obj; starterBean.stop(); } }  void contextDestroyed( ServletContextEvent sce ); void contextInitialized( ServletContextEvent sce );  }
@Test public void testContextDestroyed_nullStarterBean() throws Exception { when( context.getAttribute( "hsqldb-starter-bean" ) ).thenReturn( null ); startupListener.contextDestroyed( contextEvent ); }
@Test public void testContextDestroyed() throws Exception { when( context.getAttribute( "hsqldb-starter-bean" ) ).thenReturn( starterBean ); startupListener.contextDestroyed( contextEvent ); verify( starterBean ).stop(); }