http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/management/server/src/test/java/org/apache/karaf/management/KarafMBeanServerGuardTest.java ---------------------------------------------------------------------- diff --git a/management/server/src/test/java/org/apache/karaf/management/KarafMBeanServerGuardTest.java b/management/server/src/test/java/org/apache/karaf/management/KarafMBeanServerGuardTest.java index 3f69158..882c048 100644 --- a/management/server/src/test/java/org/apache/karaf/management/KarafMBeanServerGuardTest.java +++ b/management/server/src/test/java/org/apache/karaf/management/KarafMBeanServerGuardTest.java @@ -39,7 +39,7 @@ import java.util.*; public class KarafMBeanServerGuardTest extends TestCase { public void testRequiredRolesMethodNameOnly() throws Exception { - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("doit", "master"); configuration.put("fryit", "editor,viewer"); ConfigurationAdmin ca = getMockConfigAdmin(configuration); @@ -56,11 +56,11 @@ public class KarafMBeanServerGuardTest extends TestCase { @SuppressWarnings("unchecked") public void testRequiredRolesMethodNameEmpty() throws Exception { - Dictionary<String, Object> conf1 = new Hashtable<String, Object>(); + Dictionary<String, Object> conf1 = new Hashtable<>(); conf1.put("doit", ""); conf1.put("fryit", "editor, viewer"); conf1.put(Constants.SERVICE_PID, "jmx.acl.foo.bar.Test"); - Dictionary<String, Object> conf2 = new Hashtable<String, Object>(); + Dictionary<String, Object> conf2 = new Hashtable<>(); conf2.put("doit", "editor"); conf2.put(Constants.SERVICE_PID, "jmx.acl.foo.bar"); ConfigurationAdmin ca = getMockConfigAdmin2(conf1, conf2); @@ -75,7 +75,7 @@ public class KarafMBeanServerGuardTest extends TestCase { } public void testRequiredRolesSignature() throws Exception { - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("testit", "master"); configuration.put("testit(java.lang.String)", "viewer"); configuration.put("testit(java.lang.String, java.lang.String)", "editor"); @@ -90,7 +90,7 @@ public class KarafMBeanServerGuardTest extends TestCase { } public void testRequiredRolesSignatureEmpty() throws Exception { - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("testit", "master"); configuration.put("testit(java.lang.String)", "viewer"); configuration.put("testit(java.lang.String, java.lang.String)", ""); @@ -105,7 +105,7 @@ public class KarafMBeanServerGuardTest extends TestCase { } public void testRequiredRolesExact() throws Exception { - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("testit", "master"); configuration.put("testit(java.lang.String)", "viewer"); configuration.put("testit(java.lang.String, java.lang.String)", "editor"); @@ -136,7 +136,7 @@ public class KarafMBeanServerGuardTest extends TestCase { } public void testRequiredRolesExact2() throws Exception { - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("foo(java.lang.String,java.lang.String)[\"a\",\",\"]", "editor #this is the editor rule"); configuration.put("foo(java.lang.String,java.lang.String)[\",\" , \"a\"]", "viewer"); ConfigurationAdmin ca = getMockConfigAdmin(configuration); @@ -154,7 +154,7 @@ public class KarafMBeanServerGuardTest extends TestCase { } public void testRequiredRolesNumeric() throws Exception { - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("bar(int)[\"17\"]", "editor #this is the editor rule"); configuration.put("bar", "viewer"); ConfigurationAdmin ca = getMockConfigAdmin(configuration); @@ -170,7 +170,7 @@ public class KarafMBeanServerGuardTest extends TestCase { } public void testRequiredRolesExactNobody() throws Exception { - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("foo(java.lang.String)[\"a\"]", ""); configuration.put("foo(java.lang.String)[\"aa\"]", "#hello"); configuration.put("foo", "test"); @@ -187,7 +187,7 @@ public class KarafMBeanServerGuardTest extends TestCase { } public void testRequiredRolesRegExp() throws Exception { - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put(" testit (java.lang.String) [ /ab/]", "manager"); configuration.put("testit(java.lang.String)[/c\"d/]", "tester"); ConfigurationAdmin ca = getMockConfigAdmin(configuration); @@ -208,7 +208,7 @@ public class KarafMBeanServerGuardTest extends TestCase { } public void testRequiredRolesRegExpNobody() throws Exception { - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("testit(java.lang.String)[/ab/]", ""); configuration.put("test*", "tester"); ConfigurationAdmin ca = getMockConfigAdmin(configuration); @@ -222,7 +222,7 @@ public class KarafMBeanServerGuardTest extends TestCase { } public void testRequiredRolesRegExp2() throws Exception { - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("foo(java.lang.String,java.lang.String)[/a/,/b/]", "editor"); configuration.put("foo(java.lang.String,java.lang.String)[/[bc]/ , /[^b]/]", "viewer"); ConfigurationAdmin ca = getMockConfigAdmin(configuration); @@ -243,17 +243,17 @@ public class KarafMBeanServerGuardTest extends TestCase { @SuppressWarnings("unchecked") public void testRequiredRolesHierarchy() throws Exception { - Dictionary<String, Object> conf1 = new Hashtable<String, Object>(); + Dictionary<String, Object> conf1 = new Hashtable<>(); conf1.put("foo", "editor"); conf1.put(Constants.SERVICE_PID, "jmx.acl.foo.bar.Test"); - Dictionary<String, Object> conf2 = new Hashtable<String, Object>(); + Dictionary<String, Object> conf2 = new Hashtable<>(); conf2.put("bar", "viewer"); conf2.put("foo", "viewer"); conf2.put(Constants.SERVICE_PID, "jmx.acl.foo.bar"); - Dictionary<String, Object> conf3 = new Hashtable<String, Object>(); + Dictionary<String, Object> conf3 = new Hashtable<>(); conf3.put("tar", "admin"); conf3.put(Constants.SERVICE_PID, "jmx.acl.foo"); - Dictionary<String, Object> conf4 = new Hashtable<String, Object>(); + Dictionary<String, Object> conf4 = new Hashtable<>(); conf4.put("zar", "visitor"); conf4.put(Constants.SERVICE_PID, "jmx.acl"); @@ -278,10 +278,10 @@ public class KarafMBeanServerGuardTest extends TestCase { @SuppressWarnings("unchecked") public void testRequiredRolesHierarchyWildcard1() throws Exception { - Dictionary<String, Object> conf1 = new Hashtable<String, Object>(); + Dictionary<String, Object> conf1 = new Hashtable<>(); conf1.put("foo", "viewer"); conf1.put(Constants.SERVICE_PID, "jmx.acl._.bar.Test"); - Dictionary<String, Object> conf2 = new Hashtable<String, Object>(); + Dictionary<String, Object> conf2 = new Hashtable<>(); conf2.put("foo", "editor"); conf2.put(Constants.SERVICE_PID, "jmx.acl.foo.bar.Test"); @@ -303,10 +303,10 @@ public class KarafMBeanServerGuardTest extends TestCase { @SuppressWarnings("unchecked") public void testRequiredRolesHierarchyWildcard2() throws Exception { - Dictionary<String, Object> conf1 = new Hashtable<String, Object>(); + Dictionary<String, Object> conf1 = new Hashtable<>(); conf1.put("foo", "viewer"); conf1.put(Constants.SERVICE_PID, "jmx.acl.foo.bar.Test"); - Dictionary<String, Object> conf2 = new Hashtable<String, Object>(); + Dictionary<String, Object> conf2 = new Hashtable<>(); conf2.put("foo", "editor"); conf2.put(Constants.SERVICE_PID, "jmx.acl._.bar.Test"); @@ -328,10 +328,10 @@ public class KarafMBeanServerGuardTest extends TestCase { @SuppressWarnings("unchecked") public void testRequiredRolesHierarchyWildcard3() throws Exception { - Dictionary<String, Object> conf1 = new Hashtable<String, Object>(); + Dictionary<String, Object> conf1 = new Hashtable<>(); conf1.put("foo", "viewer"); conf1.put(Constants.SERVICE_PID, "jmx.acl._.bar.Test"); - Dictionary<String, Object> conf2 = new Hashtable<String, Object>(); + Dictionary<String, Object> conf2 = new Hashtable<>(); conf2.put("foo", "editor"); conf2.put(Constants.SERVICE_PID, "jmx.acl.foo._.Test"); @@ -354,7 +354,7 @@ public class KarafMBeanServerGuardTest extends TestCase { } public void testRequiredRolesMethodNameWildcard() throws Exception { - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("getFoo", "viewer"); configuration.put("get*", " tester , editor,manager"); configuration.put("*", "admin"); @@ -373,7 +373,7 @@ public class KarafMBeanServerGuardTest extends TestCase { } public void testRequiredRolesMethodNameWildcard2() throws Exception { - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("ge", "janitor"); configuration.put("get", "admin"); configuration.put("get*", "viewer"); @@ -393,7 +393,7 @@ public class KarafMBeanServerGuardTest extends TestCase { } public void testRequiredRolesMethodNameWildcard3() throws Exception { - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("get*", "viewer"); configuration.put("*", "admin"); ConfigurationAdmin ca = getMockConfigAdmin(configuration); @@ -412,11 +412,11 @@ public class KarafMBeanServerGuardTest extends TestCase { @SuppressWarnings("unchecked") public void testRequiredRolesMethodNameWildcardEmpty() throws Exception { - Dictionary<String, Object> conf1 = new Hashtable<String, Object>(); + Dictionary<String, Object> conf1 = new Hashtable<>(); conf1.put("get*", " "); conf1.put("*", "admin"); conf1.put(Constants.SERVICE_PID, "jmx.acl.foo.bar.Test"); - Dictionary<String, Object> conf2 = new Hashtable<String, Object>(); + Dictionary<String, Object> conf2 = new Hashtable<>(); conf2.put("get*", "viewer"); conf2.put(Constants.SERVICE_PID, "jmx.acl"); ConfigurationAdmin ca = getMockConfigAdmin2(conf1, conf2); @@ -438,7 +438,7 @@ public class KarafMBeanServerGuardTest extends TestCase { } private ConfigurationAdmin getMockConfigAdmin2(Dictionary<String, Object>... configurations) throws IOException, InvalidSyntaxException { - List<Configuration> allConfigs = new ArrayList<Configuration>(); + List<Configuration> allConfigs = new ArrayList<>(); for (Dictionary<String, Object> configuration : configurations) { Configuration conf = EasyMock.createMock(Configuration.class); EasyMock.expect(conf.getPid()).andReturn((String) configuration.get(Constants.SERVICE_PID)).anyTimes(); @@ -488,7 +488,7 @@ public class KarafMBeanServerGuardTest extends TestCase { } public void testInvoke() throws Throwable { - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("someMethod", "editor"); configuration.put("someOtherMethod", "viewer"); ConfigurationAdmin ca = getMockConfigAdmin(configuration); @@ -543,7 +543,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(mbeanInfo).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("getToast", "admin"); configuration.put("isToast", "editor"); configuration.put("getTest*", "admin"); @@ -592,7 +592,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(mbeanInfo).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("getToast", "editor"); configuration.put("getTest*", "admin"); ConfigurationAdmin ca = getMockConfigAdmin(configuration); @@ -640,7 +640,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(mbeanInfo).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("isT*", "editor"); configuration.put("getToast", "admin"); configuration.put("getButter", "editor"); @@ -691,7 +691,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(mbeanInfo).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("setSomething", "editor"); configuration.put("setValue*", "admin"); ConfigurationAdmin ca = getMockConfigAdmin(configuration); @@ -747,7 +747,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(mbeanInfo).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("setSomething", "editor"); configuration.put("setValue*", "admin"); ConfigurationAdmin ca = getMockConfigAdmin(configuration); @@ -812,7 +812,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on2)).andReturn(info2).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("doit(java.lang.String)[/11/]", "admin"); configuration.put("doit(java.lang.String)", "viewer"); configuration.put("doit(java.lang.String,java.lang.String)", "viewer"); @@ -855,7 +855,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(info).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("doit(java.lang.String)[/11/]", "admin"); configuration.put("doit(java.lang.String)", "admin"); configuration.put("doit(java.lang.String,java.lang.String)", "admin"); @@ -900,7 +900,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(info).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("doit(java.lang.String)", "admin"); configuration.put("doit(java.lang.String,java.lang.String)", "viewer"); ConfigurationAdmin ca = getMockConfigAdmin(configuration); @@ -941,7 +941,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(info).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("foit(java.lang.String)", "viewer"); configuration.put("doit(java.lang.String,java.lang.String)", "admin"); ConfigurationAdmin ca = getMockConfigAdmin(configuration); @@ -975,7 +975,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(info).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("doit(java.lang.String)", "admin"); configuration.put("doit(java.lang.String,java.lang.String)", "viewer"); ConfigurationAdmin ca = getMockConfigAdmin(configuration); @@ -1011,7 +1011,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(info).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("getFoo(java.lang.String)", "admin"); configuration.put("getFoo()", "viewer"); ConfigurationAdmin ca = getMockConfigAdmin(configuration); @@ -1047,7 +1047,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(info).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("getFoo(java.lang.String)", "viewer"); configuration.put("getFoo()", "admin"); ConfigurationAdmin ca = getMockConfigAdmin(configuration); @@ -1083,7 +1083,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(info).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("getFoo(java.lang.String)", "admin"); configuration.put("getFoo()", "admin"); configuration.put("isFoo()", "viewer"); @@ -1120,7 +1120,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(info).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("getFoo(java.lang.String)", "viewer"); configuration.put("getFoo()", "viewer"); configuration.put("isFoo()", "admin"); @@ -1157,7 +1157,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(info).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("setFoo(java.lang.String)", "admin"); configuration.put("setFoo(boolean)", "viewer"); ConfigurationAdmin ca = getMockConfigAdmin(configuration); @@ -1193,7 +1193,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(info).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("setFoo(java.lang.String)", "viewer"); configuration.put("setFoo(boolean)", "admin"); ConfigurationAdmin ca = getMockConfigAdmin(configuration); @@ -1229,7 +1229,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(info).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("get*", "admin"); configuration.put("is*", "viewer"); configuration.put("*", "admin"); @@ -1267,7 +1267,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(info).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("get*", "admin"); configuration.put("is*", "viewer"); configuration.put("*", "admin"); @@ -1305,7 +1305,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(info).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("getA1", "viewer"); configuration.put("is*", "admin"); configuration.put("*", "admin"); @@ -1343,7 +1343,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(info).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("get*", "admin"); configuration.put("setA2", "viewer"); configuration.put("*", "admin"); @@ -1381,7 +1381,7 @@ public class KarafMBeanServerGuardTest extends TestCase { EasyMock.expect(mbs.getMBeanInfo(on)).andReturn(info).anyTimes(); EasyMock.replay(mbs); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("get*", "admin"); configuration.put("setA2", "admin"); configuration.put("*", "admin"); @@ -1408,7 +1408,7 @@ public class KarafMBeanServerGuardTest extends TestCase { public void testCanInvokeMethod() throws Exception { final ObjectName on = ObjectName.getInstance("foo.bar:type=Test"); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("doit(java.lang.String)[/11/]", "admin"); configuration.put("doit(java.lang.String)", "viewer"); configuration.put("doit(java.lang.String,java.lang.String)", "viewer"); @@ -1443,7 +1443,7 @@ public class KarafMBeanServerGuardTest extends TestCase { public void testCanInvokeMethod2() throws Exception { final ObjectName on = ObjectName.getInstance("foo.bar:type=Test"); - Dictionary<String, Object> configuration = new Hashtable<String, Object>(); + Dictionary<String, Object> configuration = new Hashtable<>(); configuration.put("doit(java.lang.String)[/11/]", "viewer"); configuration.put("doit(java.lang.String)", "admin"); configuration.put("doit(java.lang.String,java.lang.String)", "admin"); @@ -1489,7 +1489,7 @@ public class KarafMBeanServerGuardTest extends TestCase { private Subject subject; private static Principal[] getPrincipals(String... roles) { - List<Principal> principals = new ArrayList<Principal>(); + List<Principal> principals = new ArrayList<>(); for (String role : roles) { principals.add(new RolePrincipal(role)); }
http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/management/server/src/test/java/org/apache/karaf/management/internal/JMXSecurityMBeanImplTestCase.java ---------------------------------------------------------------------- diff --git a/management/server/src/test/java/org/apache/karaf/management/internal/JMXSecurityMBeanImplTestCase.java b/management/server/src/test/java/org/apache/karaf/management/internal/JMXSecurityMBeanImplTestCase.java index 6530156..c4e2819 100644 --- a/management/server/src/test/java/org/apache/karaf/management/internal/JMXSecurityMBeanImplTestCase.java +++ b/management/server/src/test/java/org/apache/karaf/management/internal/JMXSecurityMBeanImplTestCase.java @@ -171,10 +171,10 @@ public class JMXSecurityMBeanImplTestCase extends TestCase { JMXSecurityMBeanImpl mb = new JMXSecurityMBeanImpl(); mb.setMBeanServer(mbs); mb.setGuard(testGuard); - Map<String, List<String>> query = new HashMap<String, List<String>>(); + Map<String, List<String>> query = new HashMap<>(); query.put(objectName, Arrays.asList("otherMethod", "testMethod(long)", "testMethod(java.lang.String)")); - query.put(objectName2, Collections.<String>emptyList()); - query.put(objectName3, Collections.<String>emptyList()); + query.put(objectName2, Collections.emptyList()); + query.put(objectName3, Collections.emptyList()); TabularData result = mb.canInvoke(query); assertEquals(5, result.size()); @@ -224,7 +224,7 @@ public class JMXSecurityMBeanImplTestCase extends TestCase { JMXSecurityMBeanImpl mb = new JMXSecurityMBeanImpl(); mb.setMBeanServer(mbs); mb.setGuard(testGuard); - Map<String, List<String>> query = new HashMap<String, List<String>>(); + Map<String, List<String>> query = new HashMap<>(); query.put(objectName, Arrays.asList("duplicateMethod1(long)", "duplicateMethod1(java.lang.String)", "duplicateMethod1(long)", "duplicateMethod2", "duplicateMethod2")); TabularData result = mb.canInvoke(query); assertEquals(3, result.size()); @@ -278,7 +278,7 @@ public class JMXSecurityMBeanImplTestCase extends TestCase { JMXSecurityMBeanImpl mb = new JMXSecurityMBeanImpl(); mb.setMBeanServer(mbs); mb.setGuard(guard); - Map<String, List<String>> query = new HashMap<String, List<String>>(); + Map<String, List<String>> query = new HashMap<>(); query.put(objectName, Collections.singletonList("testMethod(java.lang.String)")); query.put(objectName2, Collections.singletonList("testMethod(long)")); TabularData result = mb.canInvoke(query); http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/obr/src/main/java/org/apache/karaf/obr/command/ResolveCommand.java ---------------------------------------------------------------------- diff --git a/obr/src/main/java/org/apache/karaf/obr/command/ResolveCommand.java b/obr/src/main/java/org/apache/karaf/obr/command/ResolveCommand.java index ccf7614..358ef1e 100644 --- a/obr/src/main/java/org/apache/karaf/obr/command/ResolveCommand.java +++ b/obr/src/main/java/org/apache/karaf/obr/command/ResolveCommand.java @@ -57,7 +57,7 @@ public class ResolveCommand extends ObrCommandSupport { List<String> requirements; protected void doExecute(RepositoryAdmin admin) throws Exception { - List<Repository> repositories = new ArrayList<Repository>(); + List<Repository> repositories = new ArrayList<>(); repositories.add(admin.getSystemRepository()); if (!noLocal) { repositories.add(admin.getLocalRepository()); http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/package/src/main/java/org/apache/karaf/packages/command/Exports.java ---------------------------------------------------------------------- diff --git a/package/src/main/java/org/apache/karaf/packages/command/Exports.java b/package/src/main/java/org/apache/karaf/packages/command/Exports.java index e4867da..67d5289 100644 --- a/package/src/main/java/org/apache/karaf/packages/command/Exports.java +++ b/package/src/main/java/org/apache/karaf/packages/command/Exports.java @@ -130,7 +130,7 @@ public class Exports implements Action { } private SortedMap<String, PackageVersion> getDuplicatePackages(Bundle[] bundles) { - SortedMap<String, PackageVersion> packageVersionMap = new TreeMap<String, PackageVersion>(); + SortedMap<String, PackageVersion> packageVersionMap = new TreeMap<>(); for (Bundle bundle : bundles) { BundleRevision rev = bundle.adapt(BundleRevision.class); if (rev != null) { http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/package/src/main/java/org/apache/karaf/packages/core/PackageVersion.java ---------------------------------------------------------------------- diff --git a/package/src/main/java/org/apache/karaf/packages/core/PackageVersion.java b/package/src/main/java/org/apache/karaf/packages/core/PackageVersion.java index aed0c48..a30ed11 100644 --- a/package/src/main/java/org/apache/karaf/packages/core/PackageVersion.java +++ b/package/src/main/java/org/apache/karaf/packages/core/PackageVersion.java @@ -26,7 +26,7 @@ public class PackageVersion { private String packageName; private Version version; - private Set<Bundle> bundles = new HashSet<Bundle>(); + private Set<Bundle> bundles = new HashSet<>(); public PackageVersion(String packageName, Version version) { this.packageName = packageName; http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/package/src/main/java/org/apache/karaf/packages/core/internal/PackageServiceImpl.java ---------------------------------------------------------------------- diff --git a/package/src/main/java/org/apache/karaf/packages/core/internal/PackageServiceImpl.java b/package/src/main/java/org/apache/karaf/packages/core/internal/PackageServiceImpl.java index 5defe67..ce80ffa 100644 --- a/package/src/main/java/org/apache/karaf/packages/core/internal/PackageServiceImpl.java +++ b/package/src/main/java/org/apache/karaf/packages/core/internal/PackageServiceImpl.java @@ -44,7 +44,7 @@ public class PackageServiceImpl implements PackageService { public List<PackageVersion> getExports() { Bundle[] bundles = bundleContext.getBundles(); - SortedMap<String, PackageVersion> packageVersionMap = new TreeMap<String, PackageVersion>(); + SortedMap<String, PackageVersion> packageVersionMap = new TreeMap<>(); for (Bundle bundle : bundles) { BundleRevision rev = bundle.adapt(BundleRevision.class); if (rev != null) { @@ -101,7 +101,7 @@ public class PackageServiceImpl implements PackageService { Bundle bundle = bundleContext.getBundle(bundleId); BundleRevision rev = bundle.adapt(BundleRevision.class); List<BundleCapability> caps = rev.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE); - List<String> exports = new ArrayList<String>(); + List<String> exports = new ArrayList<>(); for (BundleCapability cap : caps) { Map<String, Object> attr = cap.getAttributes(); String packageName = (String)attr.get(BundleRevision.PACKAGE_NAMESPACE); @@ -115,7 +115,7 @@ public class PackageServiceImpl implements PackageService { Bundle bundle = bundleContext.getBundle(bundleId); BundleRevision rev = bundle.adapt(BundleRevision.class); List<BundleRequirement> reqs = rev.getDeclaredRequirements(BundleRevision.PACKAGE_NAMESPACE); - List<String> imports = new ArrayList<String>(); + List<String> imports = new ArrayList<>(); for (BundleRequirement req : reqs) { PackageRequirement packageReq = create(req, bundle); imports.add(packageReq.getPackageName()); http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/package/src/main/java/org/apache/karaf/packages/core/internal/filter/ExprTokenizer.java ---------------------------------------------------------------------- diff --git a/package/src/main/java/org/apache/karaf/packages/core/internal/filter/ExprTokenizer.java b/package/src/main/java/org/apache/karaf/packages/core/internal/filter/ExprTokenizer.java index cd18faf..c6e070a 100644 --- a/package/src/main/java/org/apache/karaf/packages/core/internal/filter/ExprTokenizer.java +++ b/package/src/main/java/org/apache/karaf/packages/core/internal/filter/ExprTokenizer.java @@ -28,7 +28,7 @@ public class ExprTokenizer { public ExprTokenizer(String expr) { this.expr = expr; this.currentPos = 0; - operatorMap = new HashMap<Character, String>(); + operatorMap = new HashMap<>(); for (String operator : operators) { operatorMap.put(operator.charAt(0), operator); } http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/package/src/main/java/org/apache/karaf/packages/core/internal/filter/FilterParser.java ---------------------------------------------------------------------- diff --git a/package/src/main/java/org/apache/karaf/packages/core/internal/filter/FilterParser.java b/package/src/main/java/org/apache/karaf/packages/core/internal/filter/FilterParser.java index f2b80d1..1674207 100644 --- a/package/src/main/java/org/apache/karaf/packages/core/internal/filter/FilterParser.java +++ b/package/src/main/java/org/apache/karaf/packages/core/internal/filter/FilterParser.java @@ -45,7 +45,7 @@ public class FilterParser { } private Expression[] parseFilterList(ExprTokenizer tokenizer) { - List<Expression> exprList = new ArrayList<Expression>(); + List<Expression> exprList = new ArrayList<>(); while ("(".equals(tokenizer.peekNextToken())) { tokenizer.nextToken(); exprList.add(parseFilterComp(tokenizer)); http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/profile/src/main/java/org/apache/karaf/profile/command/ProfileDisplay.java ---------------------------------------------------------------------- diff --git a/profile/src/main/java/org/apache/karaf/profile/command/ProfileDisplay.java b/profile/src/main/java/org/apache/karaf/profile/command/ProfileDisplay.java index fcd8145..9e54cef 100644 --- a/profile/src/main/java/org/apache/karaf/profile/command/ProfileDisplay.java +++ b/profile/src/main/java/org/apache/karaf/profile/command/ProfileDisplay.java @@ -88,10 +88,10 @@ public class ProfileDisplay implements Action { Map<String, Map<String, Object>> configuration = new HashMap<>(profile.getConfigurations()); Map<String, byte[]> resources = profile.getFileConfigurations(); Map<String,Object> agentConfiguration = profile.getConfiguration(Profile.INTERNAL_PID); - List<String> agentProperties = new ArrayList<String>(); - List<String> systemProperties = new ArrayList<String>(); - List<String> configProperties = new ArrayList<String>(); - List<String> otherResources = new ArrayList<String>(); + List<String> agentProperties = new ArrayList<>(); + List<String> systemProperties = new ArrayList<>(); + List<String> configProperties = new ArrayList<>(); + List<String> otherResources = new ArrayList<>(); for (Map.Entry<String, Object> entry : agentConfiguration.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/scheduler/src/main/java/org/apache/karaf/scheduler/command/support/ScriptJob.java ---------------------------------------------------------------------- diff --git a/scheduler/src/main/java/org/apache/karaf/scheduler/command/support/ScriptJob.java b/scheduler/src/main/java/org/apache/karaf/scheduler/command/support/ScriptJob.java index 47bd176..b0f3341 100644 --- a/scheduler/src/main/java/org/apache/karaf/scheduler/command/support/ScriptJob.java +++ b/scheduler/src/main/java/org/apache/karaf/scheduler/command/support/ScriptJob.java @@ -40,7 +40,7 @@ public class ScriptJob implements Job { @Override public void execute(JobContext context) { try { - script.execute(session, Collections.<Object>singletonList(context)); + script.execute(session, Collections.singletonList(context)); } catch (Exception e) { LOGGER.warn("Error executing script", e); } http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java ---------------------------------------------------------------------- diff --git a/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java b/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java index cffe7ac..47315db 100644 --- a/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java +++ b/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java @@ -74,7 +74,7 @@ public class ScrServiceMBeanImpl extends StandardMBean implements ScrServiceMBea @Activate public void activate() throws Exception { LOGGER.info("Activating the " + COMPONENT_LABEL); - Map<Object, String> mbeans = new HashMap<Object, String>(); + Map<Object, String> mbeans = new HashMap<>(); mbeans.put(this, "org.apache.karaf:type=scr,name=${karaf.name}"); try { lock.writeLock().lock(); http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/service/core/src/main/java/org/apache/karaf/service/command/ListServices.java ---------------------------------------------------------------------- diff --git a/service/core/src/main/java/org/apache/karaf/service/command/ListServices.java b/service/core/src/main/java/org/apache/karaf/service/command/ListServices.java index 00002d4..46e5a5d 100644 --- a/service/core/src/main/java/org/apache/karaf/service/command/ListServices.java +++ b/service/core/src/main/java/org/apache/karaf/service/command/ListServices.java @@ -60,7 +60,7 @@ public class ListServices implements Action { listNames(); return null; } - List<ServiceReference<?>> serviceRefs = new ArrayList<ServiceReference<?>>(); + List<ServiceReference<?>> serviceRefs = new ArrayList<>(); Bundle[] bundles = bundleContext.getBundles(); for (Bundle bundle : bundles) { ServiceReference<?>[] services = bundle.getRegisteredServices(); @@ -86,7 +86,7 @@ public class ListServices implements Action { private void listNames() { Map<String, Integer> serviceNames = getServiceNamesMap(bundleContext); - ArrayList<String> serviceNamesList = new ArrayList<String>(serviceNames.keySet()); + ArrayList<String> serviceNamesList = new ArrayList<>(serviceNames.keySet()); Collections.sort(serviceNamesList); for (String name : serviceNamesList) { System.out.println(name + " (" + serviceNames.get(name) + ")"); @@ -94,7 +94,7 @@ public class ListServices implements Action { } public static Map<String, Integer> getServiceNamesMap(BundleContext bundleContext) { - Map<String, Integer> serviceNames = new HashMap<String, Integer>(); + Map<String, Integer> serviceNames = new HashMap<>(); Bundle[] bundles = bundleContext.getBundles(); for (Bundle bundle : bundles) { ServiceReference<?>[] services = bundle.getRegisteredServices(); http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/service/core/src/main/java/org/apache/karaf/service/command/ObjectClassCompleter.java ---------------------------------------------------------------------- diff --git a/service/core/src/main/java/org/apache/karaf/service/command/ObjectClassCompleter.java b/service/core/src/main/java/org/apache/karaf/service/command/ObjectClassCompleter.java index 6b62b0c..31a7a76 100644 --- a/service/core/src/main/java/org/apache/karaf/service/command/ObjectClassCompleter.java +++ b/service/core/src/main/java/org/apache/karaf/service/command/ObjectClassCompleter.java @@ -47,7 +47,7 @@ public class ObjectClassCompleter implements Completer { public int complete(final Session session, final CommandLine commandLine, final List<String> candidates) { Map<String, Integer> serviceNamesMap = ListServices.getServiceNamesMap(context); Set<String> serviceNames = serviceNamesMap.keySet(); - List<String> strings = new ArrayList<String>(); + List<String> strings = new ArrayList<>(); for (String name : serviceNames) { strings.add(ObjectClassMatcher.getShortName(name)); } http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/service/core/src/main/java/org/apache/karaf/service/command/Wait.java ---------------------------------------------------------------------- diff --git a/service/core/src/main/java/org/apache/karaf/service/command/Wait.java b/service/core/src/main/java/org/apache/karaf/service/command/Wait.java index 9a0d286..ded27de 100644 --- a/service/core/src/main/java/org/apache/karaf/service/command/Wait.java +++ b/service/core/src/main/java/org/apache/karaf/service/command/Wait.java @@ -62,7 +62,7 @@ public class Wait implements Action { filter = "(" + filter + ")"; } Filter osgiFilter = FrameworkUtil.createFilter(filter); - tracker = new ServiceTracker<Object, Object>(bundleContext, osgiFilter, null); + tracker = new ServiceTracker<>(bundleContext, osgiFilter, null); tracker.open(true); Object svc = tracker.getService(); if (timeout >= 0) { http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/service/core/src/main/java/org/apache/karaf/service/core/internal/ServicesMBeanImpl.java ---------------------------------------------------------------------- diff --git a/service/core/src/main/java/org/apache/karaf/service/core/internal/ServicesMBeanImpl.java b/service/core/src/main/java/org/apache/karaf/service/core/internal/ServicesMBeanImpl.java index 97ea0aa..2ed92cb 100644 --- a/service/core/src/main/java/org/apache/karaf/service/core/internal/ServicesMBeanImpl.java +++ b/service/core/src/main/java/org/apache/karaf/service/core/internal/ServicesMBeanImpl.java @@ -99,7 +99,7 @@ public class ServicesMBeanImpl extends StandardMBean implements ServicesMBean { if (serviceReferences != null) { for (ServiceReference reference : serviceReferences) { String[] interfaces = (String[]) reference.getProperty("objectClass"); - List<String> properties = new ArrayList<String>(); + List<String> properties = new ArrayList<>(); for (String key : reference.getPropertyKeys()) { properties.add(key + " = " + reference.getProperty(key)); } http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/service/core/src/test/java/org/apache/karaf/service/command/TestBundleFactory.java ---------------------------------------------------------------------- diff --git a/service/core/src/test/java/org/apache/karaf/service/command/TestBundleFactory.java b/service/core/src/test/java/org/apache/karaf/service/command/TestBundleFactory.java index 66e86dc..85e682d 100644 --- a/service/core/src/test/java/org/apache/karaf/service/command/TestBundleFactory.java +++ b/service/core/src/test/java/org/apache/karaf/service/command/TestBundleFactory.java @@ -35,11 +35,11 @@ public class TestBundleFactory { if (keyProp.length % 2 != 0) { throw new IllegalArgumentException(""); } - Hashtable<String, Object> keyPropMap = new Hashtable<String, Object>(); + Hashtable<String, Object> keyPropMap = new Hashtable<>(); int c = 0; while (c < keyProp.length) { String key = (String)keyProp[c++]; - Object value = (Object)keyProp[c++]; + Object value = keyProp[c++]; keyPropMap.put(key, value); expect(serviceRef.getProperty(key)).andReturn(value).anyTimes(); } @@ -50,7 +50,7 @@ public class TestBundleFactory { Bundle createBundle(long id, String name) { Bundle bundle = createMock(Bundle.class); expect(bundle.getBundleId()).andReturn(id).anyTimes(); - Dictionary<String, String> headers = new Hashtable<String, String>(); + Dictionary<String, String> headers = new Hashtable<>(); headers.put(Constants.BUNDLE_NAME, name); expect(bundle.getHeaders()).andReturn(headers).anyTimes(); return bundle; http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardProxyCatalog.java ---------------------------------------------------------------------- diff --git a/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardProxyCatalog.java b/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardProxyCatalog.java index b64451a..4dbb1a8 100644 --- a/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardProxyCatalog.java +++ b/service/guard/src/main/java/org/apache/karaf/service/guard/impl/GuardProxyCatalog.java @@ -74,12 +74,12 @@ public class GuardProxyCatalog implements ServiceListener { private static final String ROLE_WILDCARD = "*"; private final BundleContext myBundleContext; - private final Map<String, Filter> filters = new ConcurrentHashMap<String, Filter>(); + private final Map<String, Filter> filters = new ConcurrentHashMap<>(); final ServiceTracker<ConfigurationAdmin, ConfigurationAdmin> configAdminTracker; final ServiceTracker<ProxyManager, ProxyManager> proxyManagerTracker; - final ConcurrentMap<Long, ServiceRegistrationHolder> proxyMap = new ConcurrentHashMap<Long, ServiceRegistrationHolder>(); - final BlockingQueue<CreateProxyRunnable> createProxyQueue = new LinkedBlockingQueue<CreateProxyRunnable>(); + final ConcurrentMap<Long, ServiceRegistrationHolder> proxyMap = new ConcurrentHashMap<>(); + final BlockingQueue<CreateProxyRunnable> createProxyQueue = new LinkedBlockingQueue<>(); final String compulsoryRoles; // These two variables control the proxy creator thread, which is started as soon as a ProxyManager Service @@ -104,12 +104,12 @@ public class GuardProxyCatalog implements ServiceListener { Filter caFilter = getNonProxyFilter(bc, ConfigurationAdmin.class); LOG.trace("Creating Config Admin Tracker using filter {}", caFilter); - configAdminTracker = new ServiceTracker<ConfigurationAdmin, ConfigurationAdmin>(bc, caFilter, null); + configAdminTracker = new ServiceTracker<>(bc, caFilter, null); configAdminTracker.open(); Filter pmFilter = getNonProxyFilter(bc, ProxyManager.class); LOG.trace("Creating Proxy Manager Tracker using filter {}", pmFilter); - proxyManagerTracker = new ServiceTracker<ProxyManager, ProxyManager>(bc, pmFilter, new ServiceProxyCreatorCustomizer()); + proxyManagerTracker = new ServiceTracker<>(bc, pmFilter, new ServiceProxyCreatorCustomizer()); proxyManagerTracker.open(); } @@ -294,7 +294,7 @@ public class GuardProxyCatalog implements ServiceListener { } private static Dictionary<String, Object> copyProperties(ServiceReference<?> sr) { - Dictionary<String, Object> p = new Hashtable<String, Object>(); + Dictionary<String, Object> p = new Hashtable<>(); for (String key : sr.getPropertyKeys()) { p.put(key, sr.getProperty(key)); @@ -306,7 +306,7 @@ public class GuardProxyCatalog implements ServiceListener { // as there can be different roles for different methods and also roles based on arguments passed in. Set<String> getServiceInvocationRoles(ServiceReference<?> serviceReference) throws Exception { boolean definitionFound = false; - Set<String> allRoles = new HashSet<String>(); + Set<String> allRoles = new HashSet<>(); // This can probably be optimized. Maybe we can cache the config object relevant instead of // walking through all of the ones that have 'service.guard'. @@ -407,7 +407,7 @@ public class GuardProxyCatalog implements ServiceListener { @Override public Object getService(Bundle bundle, ServiceRegistration<Object> registration) { - Set<Class<?>> allClasses = new HashSet<Class<?>>(); + Set<Class<?>> allClasses = new HashSet<>(); // This needs to be done on the Client BundleContext since the bundle might be backed by a Service Factory // in which case it needs to be given a chance to produce the right service for this client. @@ -466,7 +466,7 @@ public class GuardProxyCatalog implements ServiceListener { } // The ordering of the keys is important because the first value when iterating has the highest specificity - TreeMap<Specificity, List<String>> roleMappings = new TreeMap<ACLConfigurationParser.Specificity, List<String>>(); + TreeMap<Specificity, List<String>> roleMappings = new TreeMap<>(); boolean foundMatchingConfig = false; // This can probably be optimized. Maybe we can cache the config object relevant instead of @@ -478,7 +478,7 @@ public class GuardProxyCatalog implements ServiceListener { Filter filter = myBundleContext.createFilter((String) guardFilter); if (filter.match(serviceReference)) { foundMatchingConfig = true; - List<String> roles = new ArrayList<String>(); + List<String> roles = new ArrayList<>(); Specificity s = ACLConfigurationParser. getRolesForInvocation(m.getName(), args, sig, config.getProperties(), roles); if (s != Specificity.NO_MATCH) { http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/service/guard/src/main/java/org/apache/karaf/service/guard/tools/ACLConfigurationParser.java ---------------------------------------------------------------------- diff --git a/service/guard/src/main/java/org/apache/karaf/service/guard/tools/ACLConfigurationParser.java b/service/guard/src/main/java/org/apache/karaf/service/guard/tools/ACLConfigurationParser.java index a5812b9..55e4577 100644 --- a/service/guard/src/main/java/org/apache/karaf/service/guard/tools/ACLConfigurationParser.java +++ b/service/guard/src/main/java/org/apache/karaf/service/guard/tools/ACLConfigurationParser.java @@ -150,7 +150,7 @@ public class ACLConfigurationParser { } private static Dictionary<String, Object> trimKeys(Dictionary<String, Object> properties) { - Dictionary<String, Object> d = new Hashtable<String, Object>(); + Dictionary<String, Object> d = new Hashtable<>(); for (Enumeration<String> e = properties.keys(); e.hasMoreElements(); ) { String key = e.nextElement(); Object value = properties.get(key); @@ -194,7 +194,7 @@ public class ACLConfigurationParser { roleStr = roleStr.substring(0, hashIdx); } - List<String> roles = new ArrayList<String>(); + List<String> roles = new ArrayList<>(); for (String role : roleStr.split("[,]")) { String trimmed = role.trim(); if (trimmed.length() > 0) { @@ -242,7 +242,7 @@ public class ACLConfigurationParser { } private static List<String> getRegexRoles(Dictionary<String, Object> properties, String methodName, String[] signature, Object[] params) { - List<String> roles = new ArrayList<String>(); + List<String> roles = new ArrayList<>(); boolean matchFound = false; String methodSig = getSignature(methodName, signature); String prefix = methodSig + "[/"; @@ -263,7 +263,7 @@ public class ACLConfigurationParser { } private static List<String> getExactArgOrRegexRoles(Dictionary<String, Object> properties, String methodName, String[] signature) { - List<String> roles = new ArrayList<String>(); + List<String> roles = new ArrayList<>(); boolean matchFound = false; String methodSig = getSignature(methodName, signature); String prefix = methodSig + "["; @@ -281,7 +281,7 @@ public class ACLConfigurationParser { } private static List<String> getMethodNameWildcardRoles(Dictionary<String, Object> properties, String methodName) { - SortedMap<String, String> wildcardRules = new TreeMap<String, String>(new Comparator<String>() { + SortedMap<String, String> wildcardRules = new TreeMap<>(new Comparator<String>() { public int compare(String s1, String s2) { // returns longer entries before shorter ones... return s2.length() - s1.length(); @@ -333,7 +333,7 @@ public class ACLConfigurationParser { } private static List<String> getRegexDecl(String key) { - List<String> l = new ArrayList<String>(); + List<String> l = new ArrayList<>(); boolean inRegex = false; StringBuilder curRegex = new StringBuilder(); http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/service/guard/src/test/java/org/apache/karaf/service/guard/impl/GuardProxyCatalogTest.java ---------------------------------------------------------------------- diff --git a/service/guard/src/test/java/org/apache/karaf/service/guard/impl/GuardProxyCatalogTest.java b/service/guard/src/test/java/org/apache/karaf/service/guard/impl/GuardProxyCatalogTest.java index 010bc29..64e51ec 100644 --- a/service/guard/src/test/java/org/apache/karaf/service/guard/impl/GuardProxyCatalogTest.java +++ b/service/guard/src/test/java/org/apache/karaf/service/guard/impl/GuardProxyCatalogTest.java @@ -111,22 +111,22 @@ public class GuardProxyCatalogTest { GuardProxyCatalog gpc = new GuardProxyCatalog(bc); - Dictionary<String, Object> props = new Hashtable<String, Object>(); + Dictionary<String, Object> props = new Hashtable<>(); props.put(GuardProxyCatalog.PROXY_SERVICE_KEY, Boolean.TRUE); assertTrue(gpc.isProxy(mockServiceReference(props))); - assertFalse(gpc.isProxy(mockServiceReference(new Hashtable<String, Object>()))); + assertFalse(gpc.isProxy(mockServiceReference(new Hashtable<>()))); } @SuppressWarnings("unchecked") @Test public void testHandleProxificationForHook() throws Exception { - Dictionary<String, Object> config = new Hashtable<String, Object>(); + Dictionary<String, Object> config = new Hashtable<>(); config.put(Constants.SERVICE_PID, GuardProxyCatalog.SERVICE_ACL_PREFIX + "foo"); config.put(GuardProxyCatalog.SERVICE_GUARD_KEY, "(a>=5)"); BundleContext bc = mockConfigAdminBundleContext(config); GuardProxyCatalog gpc = new GuardProxyCatalog(bc); - Dictionary<String, Object> props = new Hashtable<String, Object>(); + Dictionary<String, Object> props = new Hashtable<>(); props.put(Constants.SERVICE_ID, 13L); props.put("a", "6"); props.put(GuardProxyCatalog.PROXY_SERVICE_KEY, Boolean.TRUE); @@ -135,7 +135,7 @@ public class GuardProxyCatalogTest { gpc.handleProxificationForHook(sref2)); assertEquals("No proxy should have been created", 0, gpc.proxyMap.size()); - Dictionary<String, Object> props4 = new Hashtable<String, Object>(); + Dictionary<String, Object> props4 = new Hashtable<>(); props4.put(Constants.SERVICE_ID, 15L); props4.put("a", "7"); ServiceReference<?> sref4 = mockServiceReference(props4); @@ -152,13 +152,13 @@ public class GuardProxyCatalogTest { EasyMock.replay(clientBC); EasyMock.replay(client2BC); - Hashtable<String, Object> props = new Hashtable<String, Object>(); + Hashtable<String, Object> props = new Hashtable<>(); long originalServiceID = 12345678901234L; props.put(Constants.SERVICE_ID, new Long(originalServiceID)); props.put("foo", "bar"); ServiceReference<?> originalRef = mockServiceReference(props); - Hashtable<String, Object> props2 = new Hashtable<String, Object>(); + Hashtable<String, Object> props2 = new Hashtable<>(); long anotherServiceID = 5123456789012345L; props2.put(Constants.SERVICE_ID, anotherServiceID); ServiceReference<?> anotherRef = mockServiceReference(props2); @@ -191,7 +191,7 @@ public class GuardProxyCatalogTest { assertEquals("Registered events should be ignored", 2, gpc.proxyMap.size()); assertEquals("Registered events should be ignored", 2, gpc.createProxyQueue.size()); - Hashtable<String, Object> proxyProps = new Hashtable<String, Object>(props); + Hashtable<String, Object> proxyProps = new Hashtable<>(props); proxyProps.put(GuardProxyCatalog.PROXY_SERVICE_KEY, Boolean.TRUE); ServiceReference<?> proxyRef = mockServiceReference(proxyProps); gpc.serviceChanged(new ServiceEvent(ServiceEvent.UNREGISTERING, proxyRef)); @@ -245,7 +245,7 @@ public class GuardProxyCatalogTest { @SuppressWarnings("unchecked") @Test public void testAssignRoles() throws Exception { - Dictionary<String, Object> config = new Hashtable<String, Object>(); + Dictionary<String, Object> config = new Hashtable<>(); config.put(Constants.SERVICE_PID, "foobar"); config.put("service.guard", "(objectClass=" + TestServiceAPI.class.getName() + ")"); config.put("somemethod", "a,b"); @@ -258,14 +258,14 @@ public class GuardProxyCatalogTest { BundleContext bc = mockConfigAdminBundleContext(config); Dictionary<String, Object> proxyProps = testCreateProxy(bc, TestServiceAPI.class, new TestService()); - assertEquals(new HashSet<String>(Arrays.asList("a", "b", "c", "d", "e", "f", "g")), - new HashSet<String>((Collection<String>) proxyProps.get(GuardProxyCatalog.SERVICE_GUARD_ROLES_PROPERTY))); + assertEquals(new HashSet<>(Arrays.asList("a", "b", "c", "d", "e", "f", "g")), + new HashSet<>((Collection<String>) proxyProps.get(GuardProxyCatalog.SERVICE_GUARD_ROLES_PROPERTY))); } @SuppressWarnings("unchecked") @Test public void testAssignRoles2() throws Exception { - Dictionary<String, Object> config = new Hashtable<String, Object>(); + Dictionary<String, Object> config = new Hashtable<>(); config.put(Constants.SERVICE_PID, "foobar"); config.put("service.guard", "(objectClass=" + TestServiceAPI2.class.getName() + ")"); config.put("doit", "X"); @@ -282,14 +282,14 @@ public class GuardProxyCatalogTest { public void testAssignRoles3() throws Exception { abstract class MyAbstractClass implements TestServiceAPI, TestServiceAPI2 {}; - Dictionary<String, Object> config = new Hashtable<String, Object>(); + Dictionary<String, Object> config = new Hashtable<>(); config.put(Constants.SERVICE_PID, "foobar"); config.put("service.guard", "(objectClass=" + TestServiceAPI2.class.getName() + ")"); config.put("doit", "X"); BundleContext bc = mockConfigAdminBundleContext(config); - Map<ServiceReference, Object> serviceMap = new HashMap<ServiceReference, Object>(); + Map<ServiceReference, Object> serviceMap = new HashMap<>(); testCreateProxy(bc, new Class [] {TestServiceAPI.class, TestServiceAPI2.class}, new MyAbstractClass() { @Override public String doit() { @@ -309,7 +309,7 @@ public class GuardProxyCatalogTest { @SuppressWarnings("unchecked") @Test public void testAssignRoles4() throws Exception { - Dictionary<String, Object> config = new Hashtable<String, Object>(); + Dictionary<String, Object> config = new Hashtable<>(); config.put(Constants.SERVICE_PID, "foobar"); config.put("service.guard", "(objectClass=" + TestServiceAPI.class.getName() + ")"); config.put("somemethod", "b"); @@ -327,11 +327,11 @@ public class GuardProxyCatalogTest { @SuppressWarnings("unchecked") @Test public void testInvocationBlocking1() throws Exception { - Dictionary<String, Object> c1 = new Hashtable<String, Object>(); + Dictionary<String, Object> c1 = new Hashtable<>(); c1.put(Constants.SERVICE_PID, "foobar"); c1.put("service.guard", "(objectClass=" + TestServiceAPI.class.getName() + ")"); c1.put("doit", "a,b"); - Dictionary<String, Object> c2 = new Hashtable<String, Object>(); + Dictionary<String, Object> c2 = new Hashtable<>(); c2.put(Constants.SERVICE_PID, "barfoobar"); c2.put("service.guard", "(objectClass=" + TestObjectWithoutInterface.class.getName() + ")"); c2.put("compute", "c"); @@ -364,7 +364,7 @@ public class GuardProxyCatalogTest { @SuppressWarnings("unchecked") @Test public void testInvocationBlocking2() throws Exception { - Dictionary<String, Object> config = new Hashtable<String, Object>(); + Dictionary<String, Object> config = new Hashtable<>(); config.put(Constants.SERVICE_PID, "barfoobar"); config.put("service.guard", "(objectClass=" + TestObjectWithoutInterface.class.getName() + ")"); config.put("compute(long)[\"42\"]", "b"); @@ -408,11 +408,11 @@ public class GuardProxyCatalogTest { } }; - Dictionary<String, Object> c1 = new Hashtable<String, Object>(); + Dictionary<String, Object> c1 = new Hashtable<>(); c1.put(Constants.SERVICE_PID, "foobar"); c1.put("service.guard", "(objectClass=" + TestServiceAPI.class.getName() + ")"); c1.put("do*", "c"); - Dictionary<String, Object> c2 = new Hashtable<String, Object>(); + Dictionary<String, Object> c2 = new Hashtable<>(); c2.put(Constants.SERVICE_PID, "foobar2"); c2.put("service.guard", "(objectClass=" + TestServiceAPI2.class.getName() + ")"); c2.put("doit(java.lang.String)[/[tT][a]+/]", "b,d # a regex rule"); @@ -485,7 +485,7 @@ public class GuardProxyCatalogTest { @SuppressWarnings("unchecked") @Test public void testInvocationBlocking5() throws Exception { - Dictionary<String, Object> c1 = new Hashtable<String, Object>(); + Dictionary<String, Object> c1 = new Hashtable<>(); c1.put(Constants.SERVICE_PID, "foobar"); c1.put("service.guard", "(objectClass=" + TestServiceAPI.class.getName() + ")"); c1.put("doit", "a,b"); @@ -515,11 +515,11 @@ public class GuardProxyCatalogTest { @SuppressWarnings("unchecked") @Test public void testInvocationBlocking6() throws Exception { - Dictionary<String, Object> c1 = new Hashtable<String, Object>(); + Dictionary<String, Object> c1 = new Hashtable<>(); c1.put(Constants.SERVICE_PID, "foobar"); c1.put("service.guard", "(objectClass=" + TestServiceAPI.class.getName() + ")"); c1.put("doit", "a,b"); - Dictionary<String, Object> c2 = new Hashtable<String, Object>(); + Dictionary<String, Object> c2 = new Hashtable<>(); c2.put(Constants.SERVICE_PID, "foobar2"); c2.put("service.guard", "(objectClass=" + TestServiceAPI2.class.getName() + ")"); c2.put("bar", "c"); @@ -555,7 +555,7 @@ public class GuardProxyCatalogTest { @SuppressWarnings("unchecked") @Test public void testInvocationBlocking7() throws Exception { - Dictionary<String, Object> c1 = new Hashtable<String, Object>(); + Dictionary<String, Object> c1 = new Hashtable<>(); c1.put(Constants.SERVICE_PID, "foobar"); c1.put("service.guard", "(objectClass=" + TestServiceAPI3.class.getName() + ")"); c1.put("foo()", "a"); @@ -615,7 +615,7 @@ public class GuardProxyCatalogTest { } }; - Dictionary<String, Object> c1 = new Hashtable<String, Object>(); + Dictionary<String, Object> c1 = new Hashtable<>(); c1.put(Constants.SERVICE_PID, "foobar"); c1.put("service.guard", "(objectClass=" + TestServiceAPI.class.getName() + ")"); c1.put("doit", MyRolePrincipal.class.getName() + ":role1"); @@ -711,16 +711,16 @@ public class GuardProxyCatalogTest { GuardProxyCatalog gpc = new GuardProxyCatalog(bc); // The service being proxied has these properties - final Hashtable<String, Object> serviceProps = new Hashtable<String, Object>(); + final Hashtable<String, Object> serviceProps = new Hashtable<>(); serviceProps.put(Constants.OBJECTCLASS, new String [] {TestServiceAPI.class.getName()}); serviceProps.put(Constants.SERVICE_ID, 162L); - final Map<ServiceReference<?>, Object> serviceMap = new HashMap<ServiceReference<?>, Object>(); + final Map<ServiceReference<?>, Object> serviceMap = new HashMap<>(); // The mock bundle context for the bundle providing the service is set up here BundleContext providerBC = EasyMock.createMock(BundleContext.class); // These are the expected service properties of the proxy registration. Note the proxy marker... - final Hashtable<String, Object> expectedProxyProps = new Hashtable<String, Object>(serviceProps); + final Hashtable<String, Object> expectedProxyProps = new Hashtable<>(serviceProps); expectedProxyProps.put(GuardProxyCatalog.PROXY_SERVICE_KEY, Boolean.TRUE); EasyMock.expect(providerBC.registerService( EasyMock.isA(String[].class), @@ -834,11 +834,11 @@ public class GuardProxyCatalogTest { @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testHandleServiceModified() throws Exception { - Dictionary<String, Object> config = new Hashtable<String, Object>(); + Dictionary<String, Object> config = new Hashtable<>(); config.put(Constants.SERVICE_PID, "test.1.2.3"); config.put("service.guard", "(objectClass=" + TestServiceAPI.class.getName() + ")"); config.put("doit", "role.1"); - Dictionary<String, Object> config2 = new Hashtable<String, Object>(); + Dictionary<String, Object> config2 = new Hashtable<>(); config2.put(Constants.SERVICE_PID, "test.1.2.4"); config2.put("service.guard", "(objectClass=" + TestServiceAPI2.class.getName() + ")"); config2.put("doit", "role.2"); @@ -847,7 +847,7 @@ public class GuardProxyCatalogTest { GuardProxyCatalog gpc = new GuardProxyCatalog(bc); // The service being proxied has these properties long serviceID = 1L; - final Hashtable<String, Object> serviceProps = new Hashtable<String, Object>(); + final Hashtable<String, Object> serviceProps = new Hashtable<>(); serviceProps.put(Constants.OBJECTCLASS, new String [] {TestServiceAPI.class.getName(), TestServiceAPI2.class.getName()}); serviceProps.put(Constants.SERVICE_ID, serviceID); serviceProps.put(GuardProxyCatalog.SERVICE_GUARD_ROLES_PROPERTY, Arrays.asList("someone")); // will be overwritten @@ -948,7 +948,7 @@ public class GuardProxyCatalogTest { // The service being proxied has these properties long serviceID = 1L; - final Hashtable<String, Object> serviceProps = new Hashtable<String, Object>(); + final Hashtable<String, Object> serviceProps = new Hashtable<>(); serviceProps.put(Constants.OBJECTCLASS, new String [] {TestServiceAPI.class.getName()}); serviceProps.put(Constants.SERVICE_ID, serviceID); @@ -1033,7 +1033,7 @@ public class GuardProxyCatalogTest { @Test @SuppressWarnings({ "unchecked", "rawtypes" }) public void testServiceFactoryBehaviour() throws Exception { - final Map<ServiceReference, Object> serviceMap = new HashMap<ServiceReference, Object>(); + final Map<ServiceReference, Object> serviceMap = new HashMap<>(); TestServiceAPI testService = new TestService(); BundleContext bc = mockConfigAdminBundleContext(); @@ -1041,7 +1041,7 @@ public class GuardProxyCatalogTest { // The service being proxied has these properties long serviceID = 117L; - final Hashtable<String, Object> serviceProps = new Hashtable<String, Object>(); + final Hashtable<String, Object> serviceProps = new Hashtable<>(); serviceProps.put(Constants.OBJECTCLASS, new String [] {TestServiceAPI.class.getName()}); serviceProps.put(Constants.SERVICE_ID, serviceID); serviceProps.put("bar", 42L); @@ -1145,17 +1145,17 @@ public class GuardProxyCatalogTest { // The service being proxied has these properties long serviceID = 456L; - final Hashtable<String, Object> serviceProps = new Hashtable<String, Object>(); + final Hashtable<String, Object> serviceProps = new Hashtable<>(); serviceProps.put(Constants.OBJECTCLASS, new String [] {intf.getName()}); serviceProps.put(Constants.SERVICE_ID, serviceID); serviceProps.put(".foo", 123L); - final Map<ServiceReference<?>, Object> serviceMap = new HashMap<ServiceReference<?>, Object>(); + final Map<ServiceReference<?>, Object> serviceMap = new HashMap<>(); // The mock bundle context for the bundle providing the service is set up here BundleContext providerBC = EasyMock.createMock(BundleContext.class); // These are the expected service properties of the proxy registration. Note the proxy marker... - final Hashtable<String, Object> expectedProxyProps = new Hashtable<String, Object>(serviceProps); + final Hashtable<String, Object> expectedProxyProps = new Hashtable<>(serviceProps); expectedProxyProps.put(GuardProxyCatalog.PROXY_SERVICE_KEY, Boolean.TRUE); // This will check that the right proxy is being registered. EasyMock.expect(providerBC.registerService( @@ -1258,12 +1258,12 @@ public class GuardProxyCatalogTest { @SuppressWarnings({ "unchecked", "rawtypes" }) public Object testCreateProxy(Class<?> [] objectClasses, Object testService) throws Exception { - return testCreateProxy(mockConfigAdminBundleContext(), objectClasses, objectClasses, testService, new HashMap<ServiceReference, Object>()); + return testCreateProxy(mockConfigAdminBundleContext(), objectClasses, objectClasses, testService, new HashMap<>()); } @SuppressWarnings("rawtypes") public Object testCreateProxy(BundleContext bc, Class<?> [] objectClasses, Object testService) throws Exception { - return testCreateProxy(bc, objectClasses, objectClasses, testService, new HashMap<ServiceReference, Object>()); + return testCreateProxy(bc, objectClasses, objectClasses, testService, new HashMap<>()); } @SuppressWarnings("rawtypes") @@ -1274,13 +1274,13 @@ public class GuardProxyCatalogTest { @SuppressWarnings({ "unchecked", "rawtypes" }) public Object testCreateProxy(BundleContext bc, Class [] objectClasses, final Class [] proxyRegClasses, Object testService, final Map<ServiceReference, Object> serviceMap) throws Exception { // A linked hash map to keep iteration order over the keys predictable - final LinkedHashMap<String, Class> objClsMap = new LinkedHashMap<String, Class>(); + final LinkedHashMap<String, Class> objClsMap = new LinkedHashMap<>(); for (Class cls : objectClasses) { objClsMap.put(cls.getName(), cls); } // A linked hash map to keep iteration order over the keys predictable - final LinkedHashMap<String, Class> proxyRegClsMap = new LinkedHashMap<String, Class>(); + final LinkedHashMap<String, Class> proxyRegClsMap = new LinkedHashMap<>(); for (Class cls : proxyRegClasses) { proxyRegClsMap.put(cls.getName(), cls); } @@ -1290,7 +1290,7 @@ public class GuardProxyCatalogTest { // The service being proxied has these properties long serviceID = Long.MAX_VALUE; - final Hashtable<String, Object> serviceProps = new Hashtable<String, Object>(); + final Hashtable<String, Object> serviceProps = new Hashtable<>(); serviceProps.put(Constants.OBJECTCLASS, objClsMap.keySet().toArray(new String [] {})); serviceProps.put(Constants.SERVICE_ID, serviceID); serviceProps.put(GuardProxyCatalog.SERVICE_GUARD_ROLES_PROPERTY, Arrays.asList("everyone")); // will be overwritten @@ -1299,7 +1299,7 @@ public class GuardProxyCatalogTest { // The mock bundle context for the bundle providing the service is set up here BundleContext providerBC = EasyMock.createMock(BundleContext.class); // These are the expected service properties of the proxy registration. Note the proxy marker... - final Hashtable<String, Object> expectedProxyProps = new Hashtable<String, Object>(serviceProps); + final Hashtable<String, Object> expectedProxyProps = new Hashtable<>(serviceProps); expectedProxyProps.put(GuardProxyCatalog.PROXY_SERVICE_KEY, Boolean.TRUE); // This will check that the right proxy is being registered. EasyMock.expect(providerBC.registerService( @@ -1421,7 +1421,7 @@ public class GuardProxyCatalogTest { } private Dictionary<String, Object> getServiceReferenceProperties(ServiceReference<?> sr) { - Dictionary<String, Object> dict = new Hashtable<String, Object>(); + Dictionary<String, Object> dict = new Hashtable<>(); for (String key : sr.getPropertyKeys()) { dict.put(key, sr.getProperty(key)); http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/service/guard/src/test/java/org/apache/karaf/service/guard/impl/GuardingEventHookTest.java ---------------------------------------------------------------------- diff --git a/service/guard/src/test/java/org/apache/karaf/service/guard/impl/GuardingEventHookTest.java b/service/guard/src/test/java/org/apache/karaf/service/guard/impl/GuardingEventHookTest.java index 9b96cd0..f026cf6 100644 --- a/service/guard/src/test/java/org/apache/karaf/service/guard/impl/GuardingEventHookTest.java +++ b/service/guard/src/test/java/org/apache/karaf/service/guard/impl/GuardingEventHookTest.java @@ -49,7 +49,7 @@ public class GuardingEventHookTest { public void testEventHookEvents() throws Exception { BundleContext frameworkBC = mockBundleContext(0L); - Dictionary<String, Object> config = new Hashtable<String, Object>(); + Dictionary<String, Object> config = new Hashtable<>(); config.put("service.guard", "(service.id=*)"); BundleContext hookBC = mockConfigAdminBundleContext(frameworkBC, config); GuardProxyCatalog gpc = new GuardProxyCatalog(hookBC); @@ -57,13 +57,13 @@ public class GuardingEventHookTest { Filter serviceFilter = FrameworkUtil.createFilter("(foo=bar)"); GuardingEventHook geh = new GuardingEventHook(hookBC, gpc, serviceFilter); - Dictionary<String, Object> props = new Hashtable<String, Object>(); + Dictionary<String, Object> props = new Hashtable<>(); props.put(Constants.SERVICE_ID, 13L); ServiceReference<?> sref = mockServiceReference(props); BundleContext client1BC = mockBundleContext(123L); - Map<BundleContext, Collection<ListenerInfo>> listeners = new HashMap<BundleContext, Collection<ListenerInfo>>(); - listeners.put(client1BC, Collections.<ListenerInfo>emptyList()); + Map<BundleContext, Collection<ListenerInfo>> listeners = new HashMap<>(); + listeners.put(client1BC, Collections.emptyList()); // Send the event. It should have no effect because the service doens't match the filter assertEquals("Precondition", 0, gpc.proxyMap.size()); @@ -72,7 +72,7 @@ public class GuardingEventHookTest { assertEquals("Nothing should have been removed from the listeners", 1, listeners.size()); long service2ID = 887L; - Dictionary<String, Object> props2 = new Hashtable<String, Object>(); + Dictionary<String, Object> props2 = new Hashtable<>(); props2.put(Constants.SERVICE_ID, service2ID); props2.put("a", "b"); props2.put("foo", "bar"); @@ -80,16 +80,16 @@ public class GuardingEventHookTest { ServiceEvent se2 = new ServiceEvent(ServiceEvent.REGISTERED, sref2); // Send the event to the system bundle and the bundle that contains the hook, should have no effect - Map<BundleContext, Collection<ListenerInfo>> listeners2 = new Hashtable<BundleContext, Collection<ListenerInfo>>(); - listeners2.put(frameworkBC, Collections.<ListenerInfo>emptyList()); - listeners2.put(hookBC, Collections.<ListenerInfo>emptyList()); + Map<BundleContext, Collection<ListenerInfo>> listeners2 = new Hashtable<>(); + listeners2.put(frameworkBC, Collections.emptyList()); + listeners2.put(hookBC, Collections.emptyList()); geh.event(se2, listeners2); assertEquals("No proxies to be created for the hook bundle or the system bundle", 0, gpc.proxyMap.size()); assertEquals("Nothing should have been removed from the listeners", 2, listeners2.size()); // This is the first time that a proxy actually does get created - Map<BundleContext, Collection<ListenerInfo>> listeners3 = new HashMap<BundleContext, Collection<ListenerInfo>>(); - listeners3.put(client1BC, Collections.<ListenerInfo>emptyList()); + Map<BundleContext, Collection<ListenerInfo>> listeners3 = new HashMap<>(); + listeners3.put(client1BC, Collections.emptyList()); geh.event(se2, listeners3); assertEquals("The service should be hidden from these listeners", 0, listeners3.size()); assertEquals("Proxy should have been created for this client", 1, gpc.proxyMap.size()); @@ -97,26 +97,26 @@ public class GuardingEventHookTest { // Update the service, now an additional client is interested props2.put("a", "c"); // Will change the properties of sref - Map<BundleContext, Collection<ListenerInfo>> listeners4 = new HashMap<BundleContext, Collection<ListenerInfo>>(); + Map<BundleContext, Collection<ListenerInfo>> listeners4 = new HashMap<>(); BundleContext client2BC = mockBundleContext(11); - listeners4.put(client2BC, Collections.<ListenerInfo>emptyList()); - listeners4.put(client1BC, Collections.<ListenerInfo>emptyList()); + listeners4.put(client2BC, Collections.emptyList()); + listeners4.put(client1BC, Collections.emptyList()); geh.event(new ServiceEvent(ServiceEvent.MODIFIED, sref2), listeners4); assertEquals("The service should be hidden from these listeners", 0, listeners4.size()); assertEquals("There should not be an additional proxy for client 2", 1, gpc.proxyMap.size()); assertNotNull(gpc.proxyMap.get(service2ID)); long service3ID = 1L; - Dictionary<String, Object> props3 = new Hashtable<String, Object>(); + Dictionary<String, Object> props3 = new Hashtable<>(); props3.put(Constants.SERVICE_ID, service3ID); props3.put("foo", "bar"); ServiceReference<?> sref3 = mockServiceReference(props3); // An event for a new service - Map<BundleContext, Collection<ListenerInfo>> listeners5 = new HashMap<BundleContext, Collection<ListenerInfo>>(); - listeners5.put(client1BC, Collections.<ListenerInfo>emptyList()); - listeners5.put(client1BC, Collections.<ListenerInfo>emptyList()); // Should be ignored + Map<BundleContext, Collection<ListenerInfo>> listeners5 = new HashMap<>(); + listeners5.put(client1BC, Collections.emptyList()); + listeners5.put(client1BC, Collections.emptyList()); // Should be ignored geh.event(new ServiceEvent(ServiceEvent.REGISTERED, sref3), listeners5); assertEquals("There should be an additional procy for client1 to the new service", 2, gpc.proxyMap.size()); assertEquals("The service should be hidden from these listeners", 0, listeners5.size()); @@ -129,7 +129,7 @@ public class GuardingEventHookTest { public void testEventHookProxyEvents() throws Exception { BundleContext frameworkBC = mockBundleContext(0L); - Dictionary<String, Object> config = new Hashtable<String, Object>(); + Dictionary<String, Object> config = new Hashtable<>(); config.put("service.guard", "(service.id=*)"); BundleContext hookBC = mockConfigAdminBundleContext(frameworkBC, config); GuardProxyCatalog gpc = new GuardProxyCatalog(hookBC); @@ -140,12 +140,12 @@ public class GuardingEventHookTest { BundleContext client1BC = mockBundleContext(123L); // Create a proxy service mock - Dictionary<String, Object> props = new Hashtable<String, Object>(); + Dictionary<String, Object> props = new Hashtable<>(); props.put(Constants.SERVICE_ID, 13L); props.put(GuardProxyCatalog.PROXY_SERVICE_KEY, Boolean.TRUE); ServiceReference<?> sref = mockServiceReference(props); - Map<BundleContext, Collection<ListenerInfo>> listeners = new HashMap<BundleContext, Collection<ListenerInfo>>(); - listeners.put(client1BC, Collections.<ListenerInfo>emptyList()); + Map<BundleContext, Collection<ListenerInfo>> listeners = new HashMap<>(); + listeners.put(client1BC, Collections.emptyList()); // Send the event. It should have no effect because the service is already a proxy for the client assertEquals("Precondition", 0, gpc.proxyMap.size()); @@ -154,8 +154,8 @@ public class GuardingEventHookTest { assertEquals("The event should be delivered to the client", 1, listeners.size()); // send the event to a different client, this client should also see the event as the proxy Service Factory is shared - Map<BundleContext, Collection<ListenerInfo>> listeners2 = new HashMap<BundleContext, Collection<ListenerInfo>>(); - listeners2.put(mockBundleContext(51L), Collections.<ListenerInfo>emptyList()); + Map<BundleContext, Collection<ListenerInfo>> listeners2 = new HashMap<>(); + listeners2.put(mockBundleContext(51L), Collections.emptyList()); geh.event(new ServiceEvent(ServiceEvent.REGISTERED, sref), listeners2); assertEquals("No changes expected for the proxy map.", 0, gpc.proxyMap.size()); assertEquals("The event should be delivered to the client", 1, listeners2.size()); http://git-wip-us.apache.org/repos/asf/karaf/blob/67232b63/service/guard/src/test/java/org/apache/karaf/service/guard/impl/GuardingFindHookTest.java ---------------------------------------------------------------------- diff --git a/service/guard/src/test/java/org/apache/karaf/service/guard/impl/GuardingFindHookTest.java b/service/guard/src/test/java/org/apache/karaf/service/guard/impl/GuardingFindHookTest.java index 69df8e8..a8fedf3 100644 --- a/service/guard/src/test/java/org/apache/karaf/service/guard/impl/GuardingFindHookTest.java +++ b/service/guard/src/test/java/org/apache/karaf/service/guard/impl/GuardingFindHookTest.java @@ -43,7 +43,7 @@ public class GuardingFindHookTest { @SuppressWarnings("unchecked") @Test public void testFindHook() throws Exception { - Dictionary<String, Object> config = new Hashtable<String, Object>(); + Dictionary<String, Object> config = new Hashtable<>(); config.put("service.guard", "(|(moo=foo)(foo=*))"); BundleContext hookBC = mockConfigAdminBundleContext(config); @@ -54,12 +54,12 @@ public class GuardingFindHookTest { BundleContext clientBC = mockBundleContext(31L); - Dictionary<String, Object> props = new Hashtable<String, Object>(); + Dictionary<String, Object> props = new Hashtable<>(); props.put(Constants.SERVICE_ID, 16L); props.put("moo", "foo"); ServiceReference<?> sref = mockServiceReference(props); - Collection<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>(); + Collection<ServiceReference<?>> refs = new ArrayList<>(); refs.add(sref); assertEquals("Precondition", 0, gpc.proxyMap.size()); @@ -69,12 +69,12 @@ public class GuardingFindHookTest { Collections.singletonList(sref), refs); long service2ID = 17L; - Dictionary<String, Object> props2 = new Hashtable<String, Object>(); + Dictionary<String, Object> props2 = new Hashtable<>(); props2.put(Constants.SERVICE_ID, service2ID); props2.put("foo", new Object()); ServiceReference<?> sref2 = mockServiceReference(props2); - Collection<ServiceReference<?>> refs2 = new ArrayList<ServiceReference<?>>(); + Collection<ServiceReference<?>> refs2 = new ArrayList<>(); refs2.add(sref2); gfh.find(clientBC, null, null, true, refs2); @@ -83,7 +83,7 @@ public class GuardingFindHookTest { assertEquals("A proxy creation job should have been created", 1, gpc.createProxyQueue.size()); assertEquals(sref2.getProperty(Constants.SERVICE_ID), gpc.proxyMap.keySet().iterator().next()); - Collection<ServiceReference<?>> refs3 = new ArrayList<ServiceReference<?>>(); + Collection<ServiceReference<?>> refs3 = new ArrayList<>(); refs3.add(sref2); // Ensure that the hook bundle has nothing hidden @@ -106,7 +106,7 @@ public class GuardingFindHookTest { assertEquals("No additional jobs should have been scheduled", 0, gpc.createProxyQueue.size()); assertEquals("No change expected", sref2.getProperty(Constants.SERVICE_ID), gpc.proxyMap.keySet().iterator().next()); - Collection<ServiceReference<?>> refs4 = new ArrayList<ServiceReference<?>>(); + Collection<ServiceReference<?>> refs4 = new ArrayList<>(); refs4.add(sref2); // another client should not get another proxy @@ -121,7 +121,7 @@ public class GuardingFindHookTest { @SuppressWarnings("unchecked") @Test public void testFindHookProxyServices() throws Exception { - Dictionary<String, Object> config = new Hashtable<String, Object>(); + Dictionary<String, Object> config = new Hashtable<>(); config.put("service.guard", "(service.id=*)"); BundleContext hookBC = mockConfigAdminBundleContext(config); @@ -132,12 +132,12 @@ public class GuardingFindHookTest { BundleContext clientBC = mockBundleContext(31L); - Dictionary<String, Object> props = new Hashtable<String, Object>(); + Dictionary<String, Object> props = new Hashtable<>(); props.put(Constants.SERVICE_ID, 16L); props.put(GuardProxyCatalog.PROXY_SERVICE_KEY, Boolean.TRUE); ServiceReference<?> sref = mockServiceReference(props); - Collection<ServiceReference<?>> refs = new ArrayList<ServiceReference<?>>(); + Collection<ServiceReference<?>> refs = new ArrayList<>(); refs.add(sref); gfh.find(clientBC, null, null, false, refs); assertEquals("No proxy should have been created for the proxy find", 0, gpc.proxyMap.size());
