DefaultKeeperContainerServiceFactory implements KeeperContainerServiceFactory { @Override public KeeperContainerService getOrCreateKeeperContainerService(KeeperContainerMeta keeperContainerMeta) { if (!services.containsKey(keeperContainerMeta)) { synchronized (this) { if (!services.containsKey(keeperContainerMeta)) { services.put(keeperContainerMeta, new DefaultKeeperContainerService(keeperContainerMeta, restTemplate)); } } } return services.get(keeperContainerMeta); }  @Override KeeperContainerService getOrCreateKeeperContainerService(KeeperContainerMeta keeperContainerMeta);  }
@Test public void getOrCreateKeeperContainerServiceMultipleTimes() throws Exception { KeeperContainerMeta someKeeperContainerMeta = mock(KeeperContainerMeta.class); KeeperContainerService someService = keeperContainerServiceFactory.getOrCreateKeeperContainerService (someKeeperContainerMeta); KeeperContainerService anotherService = keeperContainerServiceFactory.getOrCreateKeeperContainerService (someKeeperContainerMeta); assertEquals(someService, anotherService); }
@Test public void getOrCreateKeeperContainerServiceMultipleTimesWithDifferentMeta() throws Exception { KeeperContainerMeta someKeeperContainerMeta = mock(KeeperContainerMeta.class); KeeperContainerMeta anotherKeeperContainerMeta = mock(KeeperContainerMeta.class); KeeperContainerService someService = keeperContainerServiceFactory.getOrCreateKeeperContainerService (someKeeperContainerMeta); KeeperContainerService anotherService = keeperContainerServiceFactory.getOrCreateKeeperContainerService (anotherKeeperContainerMeta); assertNotEquals(someService, anotherService); }