### Question:
ServiceLocator { public static Service getService(String serviceJndiName) { var serviceObj = serviceCache.getService(serviceJndiName); if (serviceObj != null) { return serviceObj; } else { var ctx = new InitContext(); serviceObj = (Service) ctx.lookup(serviceJndiName); if (serviceObj != null) { serviceCache.addService(serviceObj); } return serviceObj; } } private  ServiceLocator(); static Service getService(String serviceJndiName);  }### Answer:
@Test public void testGetNonExistentService() { assertNull(ServiceLocator.getService("fantastic/unicorn/service")); assertNull(ServiceLocator.getService("another/fantastic/unicorn/service")); }
@Test public void testServiceCache() { final var serviceNames = List.of("jndi/serviceA", "jndi/serviceB"); for (final var serviceName : serviceNames) { final var service = ServiceLocator.getService(serviceName); assertNotNull(service); assertEquals(serviceName, service.getName()); assertTrue(service.getId() > 0); assertSame(service, ServiceLocator.getService(serviceName)); } }