### Question:
ServiceModel { public static List<ServiceModel> services(BundleContext context) { List<ServiceModel> services = new ArrayList<>(); try { ServiceReference[] references = context.getAllServiceReferences(null, null); if (references != null) { for (ServiceReference ref : references) { services.add(new ServiceModel(ref)); } } } catch (InvalidSyntaxException e) { } return services; } ServiceModel(ServiceReference reference); static List<ServiceModel> services(BundleContext context); String getInterfaces(); long getId(); String getProvidingBundle(); Map<String, String> getProperties();  }### Answer:
@Test public void testServices() throws Exception { ServiceReference reference1 = mock(ServiceReference.class); ServiceReference reference2 = mock(ServiceReference.class); BundleContext context = mock(BundleContext.class); when(context.getAllServiceReferences(null, null)).thenReturn(null); assertThat(ServiceModel.services(context)).isEmpty(); when(context.getAllServiceReferences(null, null)).thenReturn(new ServiceReference[] {reference1}); assertThat(ServiceModel.services(context)).hasSize(1); when(context.getAllServiceReferences(null, null)).thenReturn(new ServiceReference[] {reference1, reference2}); assertThat(ServiceModel.services(context)).hasSize(2); }