2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

Coverage Report - org.apache.shale.test.mock.MockFacesContext12
 
Classes in this File Line Coverage Branch Coverage Complexity
MockFacesContext12
100%
12/12
N/A
1.5
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to you under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *      http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 
 18  
 package org.apache.shale.test.mock;
 19  
 
 20  
 import javax.el.ELContext;
 21  
 import javax.el.ELContextEvent;
 22  
 import javax.el.ELContextListener;
 23  
 import javax.faces.context.ExternalContext;
 24  
 import javax.faces.context.FacesContext;
 25  
 import javax.faces.lifecycle.Lifecycle;
 26  
 import org.apache.shale.test.el.MockELContext;
 27  
 
 28  
 /**
 29  
  * <p>Mock implementation of <code>FacesContext</code> that includes the semantics
 30  
  * added by JavaServer Faces 1.2.</p>
 31  
  *
 32  
  * $Id: MockFacesContext12.java 464373 2006-10-16 04:21:54Z rahul $
 33  
  *
 34  
  * @since 1.0.4
 35  
  */
 36  
 
 37  
 public class MockFacesContext12 extends MockFacesContext {
 38  
 
 39  
 
 40  
     // ------------------------------------------------------------ Constructors
 41  
 
 42  
 
 43  
     public MockFacesContext12() {
 44  
         super();
 45  
         setCurrentInstance(this);
 46  
     }
 47  
 
 48  
 
 49  
     public MockFacesContext12(ExternalContext externalContext) {
 50  
         super(externalContext);
 51  
     }
 52  
 
 53  
 
 54  
     public MockFacesContext12(ExternalContext externalContext, Lifecycle lifecycle) {
 55  18
         super(externalContext, lifecycle);
 56  18
     }
 57  
 
 58  
 
 59  
     // ----------------------------------------------------- Mock Object Methods
 60  
 
 61  
 
 62  
     /**
 63  
      * <p>Set the <code>ELContext</code> instance for this instance.</p>
 64  
      *
 65  
      * @param elContext The new ELContext
 66  
      */
 67  
     public void setELContext(ELContext elContext) {
 68  
 
 69  
         this.elContext = elContext;
 70  
 
 71  
     }
 72  
 
 73  
 
 74  
     // ------------------------------------------------------ Instance Variables
 75  
 
 76  
 
 77  18
     private ELContext elContext = null;
 78  
 
 79  
 
 80  
     // ---------------------------------------------------- FacesContext Methods
 81  
 
 82  
 
 83  
     /** {@inheritDoc} */
 84  
     public ELContext getELContext() {
 85  
 
 86  5
         if (this.elContext == null) {
 87  
 
 88  
             // Initialize a new ELContext
 89  4
             this.elContext = new MockELContext();
 90  5
             this.elContext.putContext(FacesContext.class, this);
 91  
 
 92  
             // Notify interested listeners that this ELContext was created
 93  4
             ELContextListener[] listeners = getApplication().getELContextListeners();
 94  4
             if ((listeners != null) && (listeners.length > 0)) {
 95  
                 ELContextEvent event = new ELContextEvent(this.elContext);
 96  
                 for (int i = 0; i < listeners.length; i++) {
 97  
                     listeners[i].contextCreated(event);
 98  
                 }
 99  
             }
 100  
 
 101  
         }
 102  5
         return this.elContext;
 103  
 
 104  
     }
 105  
 
 106  
 
 107  
     /** {@inheritDoc} */
 108  
     public void release() {
 109  18
         super.release();
 110  18
         this.elContext = null;
 111  18
     }
 112  
 
 113  
 
 114  
 }