DetectorMapperCache { public List<Detector> get(String key) { String detectorsString = cache.getIfPresent(key); if (detectorsString == null) { return Collections.emptyList(); } else { return CacheUtil.buildDetectors(detectorsString); } } DetectorMapperCache(MetricRegistry metricRegistry); List<Detector> get(String key); void put(String key, List<Detector> detectors); void removeDisabledDetectorMappings(List<DetectorMapping> disabledMappings); void invalidateMetricsWithOldDetectorMappings(List<DetectorMapping> detectorMappings);  }
@Test public void get() { val key = "metricKeyWithValue"; val key2 = "metricKeyWithOutValue"; detectors = Collections.singletonList(new Detector("cid", UUID.randomUUID())); detectorIds = CacheUtil.getDetectors(detectors); Mockito.when(cache.getIfPresent(key)).thenReturn(detectorIds); Assert.assertEquals(detectors, detectorMapperCache.get(key)); verify(cache, times(1)).getIfPresent(key); Assert.assertEquals(Collections.emptyList(), detectorMapperCache.get(key2)); verify(cache, times(1)).getIfPresent(key); }