@Override public void storeProperty(String key, String value) { contextPropertiesCache.put(key, value); }
@Override public void publish(ScannerReportWriter writer) { MapEntryToContextPropertyFunction transformer = new MapEntryToContextPropertyFunction(); // properties defined programmatically by plugins Stream<ScannerReport.ContextProperty> fromCache = cache.getAll().entrySet().stream().map(transformer); // properties that are automatically included to report so that // they can be included to webhook payloads Stream<ScannerReport.ContextProperty> fromSettings = config.getProperties().entrySet().stream() .filter(e -> e.getKey().startsWith(CorePropertyDefinitions.SONAR_ANALYSIS)) .map(transformer); writer.writeContextProperties(Stream.concat(fromCache, fromSettings).collect(Collectors.toList())); }
@Test public void publish_writes_properties_to_report() { cache.put("foo1", "bar1"); cache.put("foo2", "bar2"); underTest.publish(writer); List<ScannerReport.ContextProperty> expected = Arrays.asList( newContextProperty("foo1", "bar1"), newContextProperty("foo2", "bar2")); expectWritten(expected); }
@Test public void shouldStoreContextProperty() { underTest.storeProperty("foo", "bar"); assertThat(contextPropertiesCache.getAll()).containsOnly(entry("foo", "bar")); }
@Test public void put_throws_IAE_if_key_is_null() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Key of context property must not be null"); underTest.put(null, "bar"); }
@Override public void publish(ScannerReportWriter writer) { MapEntryToContextPropertyFunction transformer = new MapEntryToContextPropertyFunction(); // properties defined programmatically by plugins Stream<ScannerReport.ContextProperty> fromCache = cache.getAll().entrySet().stream().map(transformer); // properties that are automatically included to report so that // they can be included to webhook payloads Stream<ScannerReport.ContextProperty> fromSettings = config.getProperties().entrySet().stream() .filter(e -> e.getKey().startsWith(CorePropertyDefinitions.SONAR_ANALYSIS)) .map(transformer); writer.writeContextProperties(Stream.concat(fromCache, fromSettings).collect(Collectors.toList())); }
@Test public void put_throws_IAE_if_value_is_null() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Value of context property must not be null"); underTest.put("foo", null); } }
@Override public void storeProperty(String key, String value) { contextPropertiesCache.put(key, value); }