### Question:
NamedServiceRetrieverImpl implements NamedServiceRetriever { @Override public <Service extends HasName> Service getNamedService(final Class<Service> clazz, final String name) { try { for (final ServiceReference<Service> reference : context.getServiceReferences(clazz, null)) { final Service service = context.getService(reference); if (StringUtils.equals(name, service.getName())) { return service; } else { context.ungetService(reference); } } } catch (final InvalidSyntaxException e) { return null; } return null; }  @Activate void activate(final BundleContext context); @Override Service getNamedService(final Class<Service> clazz, final String name);  }### Answer:
@SuppressWarnings("unchecked") @Test public void handleInvalidSyntaxException() throws InvalidSyntaxException { when(context.getServiceReferences(any(Class.class), any())).thenThrow(InvalidSyntaxException.class); assertNull(model.getNamedService(HasName.class, NAME)); }
@Test public void getNamedService() { assertNull(model.getNamedService(HasName.class, NAME)); services.add(neededServiceRef); assertEquals(neededService, model.getNamedService(HasName.class, NAME)); }