OsgiUtil { public static String lookup(ComponentContext context, String name) { return asString(checkNotNull(context).getProperties().get(checkNotNull(name))); } private  OsgiUtil(); static String lookup(ComponentContext context, String name); static String lookup(BundleContext context, String name); static String lookupConfigurationThenFramework(ComponentContext context, String name); static String lookupConfigurationThenFramework(ComponentContext context, String nameInComponent, String nameInFramework); static String lookupFrameworkThenConfiguration(ComponentContext context, String name); static String lookupFrameworkThenConfiguration(ComponentContext context, String nameInComponent, String nameInFramework); static Filter getFilter(Class<?> clazz, Map<String, String> attributes);  }
@Test(expected = NullPointerException.class) public void testComponentLookupWithNullContext() { lookup((ComponentContext) null, "name"); }
@Test(expected = NullPointerException.class) public void testComponentLookupWithNullName() { lookup(mock(ComponentContext.class), null); }
@Test public void testComponentLookupWithNotFoundValue() { Dictionary properties = mock(Dictionary.class); doReturn(null).when(properties).get("name"); ComponentContext context = mock(ComponentContext.class); doReturn(properties).when(context).getProperties(); assertNull(lookup(context, "name")); }
@Test public void testComponentLookupWithEmptyString() { Dictionary properties = mock(Dictionary.class); doReturn("").when(properties).get("name"); ComponentContext context = mock(ComponentContext.class); doReturn(properties).when(context).getProperties(); assertNull(lookup(context, "name")); }
@Test public void testComponentLookupWithNonTrimmedString() { Dictionary properties = mock(Dictionary.class); doReturn(" ").when(properties).get("name"); ComponentContext context = mock(ComponentContext.class); doReturn(properties).when(context).getProperties(); assertNull(lookup(context, "name")); }
@Test public void testComponentLookupWithNonStringValue() { Dictionary properties = mock(Dictionary.class); doReturn(42).when(properties).get("name"); ComponentContext context = mock(ComponentContext.class); doReturn(properties).when(context).getProperties(); assertEquals("42", lookup(context, "name")); }
@Test public void testComponentLookupWithStringValue() { Dictionary properties = mock(Dictionary.class); doReturn(" value ").when(properties).get("name"); ComponentContext context = mock(ComponentContext.class); doReturn(properties).when(context).getProperties(); assertEquals("value", lookup(context, "name")); }
@Test(expected = NullPointerException.class) public void testFrameworkLookupWithNullContext() { lookup((BundleContext) null, "name"); }
@Test(expected = NullPointerException.class) public void testFrameworkLookupWithNullName() { lookup(mock(BundleContext.class), null); }
@Test public void testFrameworkLookupWithNotFoundValue() { BundleContext context = mock(BundleContext.class); doReturn(null).when(context).getProperty("name"); assertNull(lookup(context, "name")); }
@Test public void testFrameworkLookupWithEmptyString() { BundleContext context = mock(BundleContext.class); doReturn("").when(context).getProperty("name"); assertNull(lookup(context, "name")); }
@Test public void testFrameworkLookupWithNonTrimmedString() { BundleContext context = mock(BundleContext.class); doReturn(" ").when(context).getProperty("name"); assertNull(lookup(context, "name")); }
@Test public void testFrameworkLookupWith() { BundleContext context = mock(BundleContext.class); doReturn(" value ").when(context).getProperty("name"); assertEquals("value", lookup(context, "name")); }