felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1705686 - in /felix/trunk/resolver/src: main/java/org/apache/felix/resolver/ResolverImpl.java test/java/org/apache/felix/resolver/test/ResolverTest.java
Date Mon, 28 Sep 2015 13:16:45 GMT
Author: davidb
Date: Mon Sep 28 13:16:45 2015
New Revision: 1705686

URL: http://svn.apache.org/viewvc?rev=1705686&view=rev
Log:
FELIX-5015 Unit tests (for NPE in ResolverImpl)

Modified:
    felix/trunk/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java
    felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/ResolverTest.java

Modified: felix/trunk/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java?rev=1705686&r1=1705685&r2=1705686&view=diff
==============================================================================
--- felix/trunk/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java (original)
+++ felix/trunk/resolver/src/main/java/org/apache/felix/resolver/ResolverImpl.java Mon Sep
28 13:16:45 2015
@@ -40,7 +40,6 @@ import java.util.concurrent.atomic.Atomi
 
 import org.apache.felix.resolver.util.ArrayMap;
 import org.apache.felix.resolver.util.OpenHashMap;
-
 import org.osgi.framework.namespace.BundleNamespace;
 import org.osgi.framework.namespace.ExecutionEnvironmentNamespace;
 import org.osgi.framework.namespace.HostNamespace;
@@ -1730,12 +1729,12 @@ public class ResolverImpl implements Res
         }
 
         Set<Capability> packageSources = sources.get(cap);
-        if(packageSources == null) 
+        if(packageSources == null)
         {
             return new HashSet<Capability>();
         }
 
-        return packageSources;  
+        return packageSources;
     }
 
     private static void getPackageSourcesInternal(
@@ -2074,7 +2073,7 @@ public class ResolverImpl implements Res
         }
     }
 
-    private static class Packages
+    public static class Packages
     {
         public final OpenHashMap<String, Blame> m_exportedPkgs;
         public final OpenHashMap<String, List<Blame>> m_importedPkgs;

Modified: felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/ResolverTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/ResolverTest.java?rev=1705686&r1=1705685&r2=1705686&view=diff
==============================================================================
--- felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/ResolverTest.java (original)
+++ felix/trunk/resolver/src/test/java/org/apache/felix/resolver/test/ResolverTest.java Mon
Sep 28 13:16:45 2015
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -30,6 +31,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.felix.resolver.Logger;
 import org.apache.felix.resolver.ResolverImpl;
@@ -42,6 +44,7 @@ import org.apache.felix.resolver.test.ut
 import org.apache.felix.resolver.test.util.ResolveContextImpl;
 import org.apache.felix.resolver.test.util.ResourceImpl;
 import org.junit.Test;
+import org.mockito.Mockito;
 import org.osgi.framework.Constants;
 import org.osgi.framework.namespace.BundleNamespace;
 import org.osgi.framework.namespace.HostNamespace;
@@ -577,6 +580,37 @@ public class ResolverTest
         assertEquals(0, wireMap.size());
     }
 
+    @Test
+    public void testPackageSources() throws Exception {
+        Method m = ResolverImpl.class.getDeclaredMethod("getPackageSources",
+                Capability.class, Map.class);
+        m.setAccessible(true);
+
+        Capability cap = Mockito.mock(Capability.class);
+        assertEquals(Collections.emptySet(),
+                m.invoke(null, cap, new HashMap<Resource, ResolverImpl.Packages>()));
+
+        Capability cap2 = Mockito.mock(Capability.class);
+        Resource res2 = Mockito.mock(Resource.class);
+        Mockito.when(cap2.getResource()).thenReturn(res2);
+        Map<Resource, ResolverImpl.Packages> map2 = new HashMap<Resource, ResolverImpl.Packages>();
+        map2.put(res2, new ResolverImpl.Packages(res2));
+        assertEquals(Collections.emptySet(), m.invoke(null, cap2, map2));
+
+        Capability cap3 = Mockito.mock(Capability.class);
+        Resource res3 = Mockito.mock(Resource.class);
+        Mockito.when(cap3.getResource()).thenReturn(res3);
+        Map<Resource, ResolverImpl.Packages> map3 = new HashMap<Resource, ResolverImpl.Packages>();
+        ResolverImpl.Packages pkgs3 = new ResolverImpl.Packages(res3);
+        Set<Capability> srcCaps3 = Collections.singleton(Mockito.mock(Capability.class));
+        Map<Capability, Set<Capability>> srcMap3 = Collections.singletonMap(
+                cap3, srcCaps3);
+        pkgs3.m_sources.putAll(srcMap3);
+        map3.put(res3, pkgs3);
+        assertEquals(srcCaps3, m.invoke(null, cap3, map3));
+
+    }
+
     private static String getResourceName(Resource r)
     {
         return r.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).get(0).getAttributes()



Mime
View raw message