### Question:
CachingSubsystemRegistry implements SubsystemRegistry { @Override public Optional<SubsystemExecutor> loadByPlace(UUID placeId) { if(placeId == null) { return Optional.empty(); } try { SubsystemExecutor executor = executors.get(placeId, () -> doLoadByPlace(placeId)); return Optional.of(executor); } catch(Exception e) { logger.debug("Unable to load cache entry for placeId {}", placeId, e); return Optional.empty(); } } @Inject  CachingSubsystemRegistry(
         SubsystemFactory factory,
         PlaceDAO placeDao,
         ModelDao modelDao,
         PlacePopulationCacheManager populationCacheMgr,
         SubsystemConfig config
   ); @Override Optional<SubsystemExecutor> loadByPlace(UUID placeId); @Override Optional<SubsystemExecutor> loadByPlace(UUID placeId, UUID accountId); @Override void removeByPlace(UUID placeId); @Override void clear(); static final Set<String> TRACKED_TYPES; }### Answer:
@Test public void testFindByPlaceId() { expectPlaceFound(); expectListModels(); Capture<PlaceContext> contextRef = expectCreateContext(); expectExecutorStart(); replay(); SubsystemExecutor executor = registry.loadByPlace(placeId).get(); assertEquals(mockExecutor, executor); PlaceContext context = contextRef.getValue(); assertEquals(placeId, context.getPlaceId()); assertEquals(place.getAccount(), context.getAccountId()); assertEquals(models.size(), context.models().getModels().size()); for(Model model: models) { Fixtures.assertMapEquals(model.toMap(), context.models().getModelByAddress(model.getAddress()).toMap()); } assertNotNull(context.logger()); assertNotNull(context.getLocalTime()); verify(); }
@Test public void testFindByPlaceIdNotFound() { expectPlaceNotFound(); replay(); Optional<SubsystemExecutor> executor = registry.loadByPlace(placeId); assertFalse(executor.isPresent()); verify(); }
@Test public void testFindByPlaceIdModelDaoThrowsException() { expectPlaceFound(); expectListModelsAndThrow(); replay(); Optional<SubsystemExecutor> executor = registry.loadByPlace(placeId); assertFalse(executor.isPresent()); verify(); }