View Javadoc

1   /*
2    * $Id: ServletContextHolderListenerTest.java 462530 2006-10-10 19:48:19Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.portlet.context;
19  
20  import javax.servlet.ServletContext;
21  import javax.servlet.ServletContextEvent;
22  
23  import junit.framework.TestCase;
24  
25  import org.easymock.MockControl;
26  
27  /***
28   */
29  public class ServletContextHolderListenerTest extends TestCase {
30  
31      public void testContextInitialized() {
32          MockControl mockContext = MockControl.createNiceControl(ServletContext.class);
33          ServletContext context = (ServletContext)mockContext.getMock();
34          ServletContextEvent event = new ServletContextEvent(context);
35          ServletContextHolderListener listener = new ServletContextHolderListener();
36          listener.contextInitialized(event);
37          assertSame(ServletContextHolderListener.getServletContext(), context);
38          
39          listener.contextDestroyed(event);
40          assertNull(ServletContextHolderListener.getServletContext());
41      }
42  
43  }