@Test public void testFactories() throws Exception { Factory factory1 = mock(Factory.class); when(factory1.getName()).thenReturn("factory-1"); Factory factory2 = mock(Factory.class); when(factory2.getName()).thenReturn("factory-2"); HandlerFactory factory3 = mock(HandlerFactory.class); when(factory3.getName()).thenReturn("factory-3"); when(factory3.getHandlerName()).thenReturn("h:factory-3"); ServiceReference<Factory> ref1 = mock(ServiceReference.class); ServiceReference<Factory> ref2 = mock(ServiceReference.class); ServiceReference<HandlerFactory> ref3 = mock(ServiceReference.class); BundleContext context = mock(BundleContext.class); when(context.getServiceReferences(Factory.class, null)).thenReturn(ImmutableList.of(ref1, ref2)); when(context.getServiceReferences(HandlerFactory.class, null)).thenReturn(ImmutableList.of(ref3)); when(context.getService(ref1)).thenReturn(factory1); when(context.getService(ref2)).thenReturn(factory2); when(context.getService(ref3)).thenReturn(factory3); List<FactoryModel> models = FactoryModel.factories(context); assertThat(models).hasSize(3); }
public static List<FactoryModel> factories(BundleContext context) { List<FactoryModel> factories = new ArrayList<FactoryModel>(); try { for (ServiceReference ref : context.getServiceReferences(Factory.class, null)) { factories.add(new FactoryModel((Factory) context.getService(ref))); } for (ServiceReference ref : context.getServiceReferences(HandlerFactory.class, null)) { factories.add(new FactoryModel((Factory) context.getService(ref))); } } catch (InvalidSyntaxException e) { } return factories; }
FactoryModel { public static List<FactoryModel> factories(BundleContext context) { List<FactoryModel> factories = new ArrayList<FactoryModel>(); try { for (ServiceReference ref : context.getServiceReferences(Factory.class, null)) { factories.add(new FactoryModel((Factory) context.getService(ref))); } for (ServiceReference ref : context.getServiceReferences(HandlerFactory.class, null)) { factories.add(new FactoryModel((Factory) context.getService(ref))); } } catch (InvalidSyntaxException e) { } return factories; } }
FactoryModel { public static List<FactoryModel> factories(BundleContext context) { List<FactoryModel> factories = new ArrayList<FactoryModel>(); try { for (ServiceReference ref : context.getServiceReferences(Factory.class, null)) { factories.add(new FactoryModel((Factory) context.getService(ref))); } for (ServiceReference ref : context.getServiceReferences(HandlerFactory.class, null)) { factories.add(new FactoryModel((Factory) context.getService(ref))); } } catch (InvalidSyntaxException e) { } return factories; } protected  FactoryModel(Factory factory); }
FactoryModel { public static List<FactoryModel> factories(BundleContext context) { List<FactoryModel> factories = new ArrayList<FactoryModel>(); try { for (ServiceReference ref : context.getServiceReferences(Factory.class, null)) { factories.add(new FactoryModel((Factory) context.getService(ref))); } for (ServiceReference ref : context.getServiceReferences(HandlerFactory.class, null)) { factories.add(new FactoryModel((Factory) context.getService(ref))); } } catch (InvalidSyntaxException e) { } return factories; } protected  FactoryModel(Factory factory); static List<FactoryModel> factories(BundleContext context); String getName(); boolean isHandler(); String getArchitecture(); String getHandlerName(); String getState(); }
FactoryModel { public static List<FactoryModel> factories(BundleContext context) { List<FactoryModel> factories = new ArrayList<FactoryModel>(); try { for (ServiceReference ref : context.getServiceReferences(Factory.class, null)) { factories.add(new FactoryModel((Factory) context.getService(ref))); } for (ServiceReference ref : context.getServiceReferences(HandlerFactory.class, null)) { factories.add(new FactoryModel((Factory) context.getService(ref))); } } catch (InvalidSyntaxException e) { } return factories; } protected  FactoryModel(Factory factory); static List<FactoryModel> factories(BundleContext context); String getName(); boolean isHandler(); String getArchitecture(); String getHandlerName(); String getState();  }