Coverage Report - org.seasar.uruma.rcp.unit.MockBundle
 
Classes in this File Line Coverage Branch Coverage Complexity
MockBundle
6%
2/33
0%
0/4
0
 
 1  
 /*
 2  
  * Copyright 2004-2008 the Seasar Foundation and the Others.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
 13  
  * either express or implied. See the License for the specific language
 14  
  * governing permissions and limitations under the License.
 15  
  */
 16  
 package org.seasar.uruma.rcp.unit;
 17  
 
 18  
 import java.io.IOException;
 19  
 import java.io.InputStream;
 20  
 import java.net.URL;
 21  
 import java.util.ArrayList;
 22  
 import java.util.Collections;
 23  
 import java.util.Dictionary;
 24  
 import java.util.Enumeration;
 25  
 import java.util.Properties;
 26  
 
 27  
 import org.osgi.framework.Bundle;
 28  
 import org.osgi.framework.BundleContext;
 29  
 import org.osgi.framework.BundleException;
 30  
 import org.osgi.framework.ServiceReference;
 31  
 
 32  
 /**
 33  
  * テスト用の {@link Bundle} オブジェクトです。<br />
 34  
  * 
 35  
  * @author y-komori
 36  
  */
 37  16
 public class MockBundle implements Bundle {
 38  
     static final String SYMBOLIC_NAME = "org.seasar.uruma.rcp.core";
 39  
 
 40  
     protected MockBundleContext context;
 41  
 
 42  
     public Enumeration<?> findEntries(final String path,
 43  
             final String filePattern, final boolean recurse) {
 44  0
         URL url = getClass().getClassLoader().getResource(
 45  
                 getClass().getName() + ".class");
 46  0
         if (url != null) {
 47  0
             ArrayList<URL> entries = new ArrayList<URL>();
 48  0
             entries.add(url);
 49  0
             return Collections.enumeration(entries);
 50  
         } else {
 51  0
             return getEmptyEnumeration();
 52  
         }
 53  
     }
 54  
 
 55  
     public BundleContext getBundleContext() {
 56  0
         if (context == null) {
 57  0
             context = new MockBundleContext(this);
 58  
         }
 59  0
         return context;
 60  
     }
 61  
 
 62  
     public long getBundleId() {
 63  0
         return 0;
 64  
     }
 65  
 
 66  
     public URL getEntry(final String path) {
 67  0
         return null;
 68  
     }
 69  
 
 70  
     public Enumeration<?> getEntryPaths(final String path) {
 71  0
         return getEmptyEnumeration();
 72  
     }
 73  
 
 74  
     public Dictionary<?, ?> getHeaders() {
 75  0
         return new Properties();
 76  
     }
 77  
 
 78  
     public Dictionary<?, ?> getHeaders(final String locale) {
 79  0
         return new Properties();
 80  
     }
 81  
 
 82  
     public long getLastModified() {
 83  0
         return 0;
 84  
     }
 85  
 
 86  
     public String getLocation() {
 87  0
         return null;
 88  
     }
 89  
 
 90  
     public ServiceReference[] getRegisteredServices() {
 91  0
         return null;
 92  
     }
 93  
 
 94  
     public URL getResource(final String name) {
 95  0
         return null;
 96  
     }
 97  
 
 98  
     public Enumeration<?> getResources(final String name) throws IOException {
 99  0
         return getEmptyEnumeration();
 100  
     }
 101  
 
 102  
     public ServiceReference[] getServicesInUse() {
 103  0
         return null;
 104  
     }
 105  
 
 106  
     public int getState() {
 107  0
         return 0;
 108  
     }
 109  
 
 110  
     public String getSymbolicName() {
 111  16
         return SYMBOLIC_NAME;
 112  
     }
 113  
 
 114  
     public boolean hasPermission(final Object permission) {
 115  0
         return true;
 116  
     }
 117  
 
 118  
     public Class<?> loadClass(final String name) throws ClassNotFoundException {
 119  0
         return Class.forName(name);
 120  
     }
 121  
 
 122  
     public void start() throws BundleException {
 123  
         // Do nothing.
 124  0
     }
 125  
 
 126  
     public void start(final int options) throws BundleException {
 127  
         // Do nothing.
 128  0
     }
 129  
 
 130  
     public void stop() throws BundleException {
 131  
         // Do nothing.
 132  0
     }
 133  
 
 134  
     public void stop(final int options) throws BundleException {
 135  
         // Do nothing.
 136  0
     }
 137  
 
 138  
     public void uninstall() throws BundleException {
 139  
         // Do nothing.
 140  0
     }
 141  
 
 142  
     public void update() throws BundleException {
 143  
         // Do nothing.
 144  0
     }
 145  
 
 146  
     public void update(final InputStream in) throws BundleException {
 147  
         // Do nothing.
 148  0
     }
 149  
 
 150  
     @SuppressWarnings("unchecked")
 151  
     protected Enumeration<?> getEmptyEnumeration() {
 152  0
         return Collections.enumeration(Collections.EMPTY_LIST);
 153  
     }
 154  
 }