You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by da...@apache.org on 2014/06/16 17:50:13 UTC
svn commit: r1602905 - in /aries/trunk/subsystem/subsystem-core/src:
main/java/org/apache/aries/subsystem/core/internal/BundleRevisionResource.java
test/java/org/apache/aries/subsystem/core/internal/BundleRevisionResourceTest.java
Author: davidb
Date: Mon Jun 16 15:50:12 2014
New Revision: 1602905
URL: http://svn.apache.org/r1602905
Log:
Fix Null Pointer Exception.
Includes unit test.
Added:
aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/BundleRevisionResourceTest.java
Modified:
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleRevisionResource.java
Modified: aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleRevisionResource.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleRevisionResource.java?rev=1602905&r1=1602904&r2=1602905&view=diff
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleRevisionResource.java (original)
+++ aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleRevisionResource.java Mon Jun 16 15:50:12 2014
@@ -25,7 +25,7 @@ import org.osgi.resource.Resource;
public class BundleRevisionResource implements Resource {
private final BundleRevision revision;
-
+
public BundleRevisionResource(BundleRevision revision) {
if (revision == null)
throw new NullPointerException();
@@ -61,17 +61,17 @@ public class BundleRevisionResource impl
return Collections.unmodifiableList(computeServiceRequirements());
return revision.getRequirements(namespace);
}
-
+
private List<Capability> computeServiceCapabilities() {
Activator activator = Activator.getInstance();
ServiceModeller modeller = activator.getServiceModeller();
if (modeller == null)
- return null;
+ return Collections.emptyList();
ServiceModeller.ServiceModel model =
modeller.computeRequirementsAndCapabilities(this, new BundleDirectory(revision.getBundle()));
return model.getServiceCapabilities();
}
-
+
private List<Requirement> computeServiceRequirements() {
Activator activator = Activator.getInstance();
ServiceModeller modeller = activator.getServiceModeller();
Added: aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/BundleRevisionResourceTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/BundleRevisionResourceTest.java?rev=1602905&view=auto
==============================================================================
--- aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/BundleRevisionResourceTest.java (added)
+++ aries/trunk/subsystem/subsystem-core/src/test/java/org/apache/aries/subsystem/core/internal/BundleRevisionResourceTest.java Mon Jun 16 15:50:12 2014
@@ -0,0 +1,51 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aries.subsystem.core.internal;
+
+import static org.junit.Assert.assertEquals;
+
+import java.lang.reflect.Field;
+
+import org.easymock.EasyMock;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.wiring.BundleRevision;
+
+public class BundleRevisionResourceTest {
+ Activator storedActivator;
+
+ @Before
+ public void setUp() throws Exception {
+ Field field = Activator.class.getDeclaredField("instance");
+ field.setAccessible(true);
+ storedActivator = (Activator) field.get(null);
+ field.set(null, new Activator());
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ Field field = Activator.class.getDeclaredField("instance");
+ field.setAccessible(true);
+ field.set(null, storedActivator);
+ storedActivator = null;
+ }
+
+ @Test
+ public void testNoServiceCapabilities() {
+ BundleRevision br = EasyMock.createNiceMock(BundleRevision.class);
+ BundleRevisionResource brr = new BundleRevisionResource(br);
+ assertEquals(0, brr.getCapabilities("osgi.service").size());
+ }
+}