Coverage Report - org.apache.tapestry5.internal.test.PageTesterContext
 
Classes in this File Line Coverage Branch Coverage Complexity
PageTesterContext
53%
8/15
100%
4/4
0
 
 1  
 // Copyright 2007, 2008, 2009 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry5.internal.test;
 16  
 
 17  
 import org.apache.tapestry5.services.Context;
 18  
 import org.apache.tapestry5.test.TapestryTestConstants;
 19  
 
 20  
 import java.io.File;
 21  
 import java.net.MalformedURLException;
 22  
 import java.net.URL;
 23  
 import java.util.Collections;
 24  
 import java.util.List;
 25  
 
 26  
 public class PageTesterContext implements Context
 27  
 {
 28  
     private final File contextRoot;
 29  
 
 30  
     public PageTesterContext(String contextRoot)
 31  52
     {
 32  52
         this.contextRoot = new File(TapestryTestConstants.MODULE_BASE_DIR, contextRoot);
 33  52
     }
 34  
 
 35  
     public String getInitParameter(String name)
 36  
     {
 37  0
         return null;
 38  
     }
 39  
 
 40  
     public URL getResource(String path)
 41  
     {
 42  76
         File f = new File(contextRoot + path);
 43  
 
 44  76
         if (!f.exists() || !f.isFile())
 45  
         {
 46  42
             return null;
 47  
         }
 48  
         try
 49  
         {
 50  34
             return f.toURL();
 51  
         }
 52  0
         catch (MalformedURLException ex)
 53  
         {
 54  0
             throw new RuntimeException(ex);
 55  
         }
 56  
     }
 57  
 
 58  
     public List<String> getResourcePaths(String path)
 59  
     {
 60  0
         throw new UnsupportedOperationException("getResourcePaths() is not supported for ContextForPageTester.");
 61  
     }
 62  
 
 63  
     public Object getAttribute(String name)
 64  
     {
 65  0
         throw new UnsupportedOperationException("getAttribute() is not supported for ContextForPageTester.");
 66  
     }
 67  
 
 68  
     public List<String> getAttributeNames()
 69  
     {
 70  0
         return Collections.emptyList();
 71  
     }
 72  
 
 73  
     public String getMimeType(String file)
 74  
     {
 75  0
         return null;
 76  
     }
 77  
 
 78  
     /**
 79  
      * Always returns null.
 80  
      */
 81  
     public File getRealFile(String path)
 82  
     {
 83  60
         return null;
 84  
     }
 85  
 }