aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/test/java/org/sonar/scanner
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-scanner-engine/src/test/java/org/sonar/scanner')
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/AnalysisCacheEnabledTest.java45
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/AnalysisCacheLoaderTest.java97
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/AnalysisCacheMemoryStorageTest.java66
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/AnalysisCacheProviderTest.java65
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/ReadCacheImplTest.java52
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/WriteCacheImplTest.java85
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/report/AnalysisCachePublisherTest.java (renamed from sonar-scanner-engine/src/test/java/org/sonar/scanner/report/PluginCachePublisherTest.java)18
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorContextTest.java18
8 files changed, 435 insertions, 11 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/AnalysisCacheEnabledTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/AnalysisCacheEnabledTest.java
new file mode 100644
index 00000000000..a4877298d3e
--- /dev/null
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/AnalysisCacheEnabledTest.java
@@ -0,0 +1,45 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.cache;
+
+import java.util.Optional;
+import org.junit.Test;
+import org.sonar.api.config.Configuration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.sonar.scanner.cache.AnalysisCacheEnabled.PROP_KEY;
+
+public class AnalysisCacheEnabledTest {
+ private final Configuration configuration = mock(Configuration.class);
+ private final AnalysisCacheEnabled analysisCacheEnabled = new AnalysisCacheEnabled(configuration);
+
+ @Test
+ public void disabled_unless_property_set() {
+ assertThat(analysisCacheEnabled.isEnabled()).isFalse();
+ }
+
+ @Test
+ public void enabled_if_property_set() {
+ when(configuration.getBoolean(PROP_KEY)).thenReturn(Optional.of(true));
+ assertThat(analysisCacheEnabled.isEnabled()).isTrue();
+ }
+}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/AnalysisCacheLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/AnalysisCacheLoaderTest.java
new file mode 100644
index 00000000000..8ccdcafdb2d
--- /dev/null
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/AnalysisCacheLoaderTest.java
@@ -0,0 +1,97 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.cache;
+
+import com.google.protobuf.ByteString;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Optional;
+import java.util.zip.DeflaterInputStream;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.scanner.fs.InputProject;
+import org.sonar.scanner.bootstrap.DefaultScannerWsClient;
+import org.sonar.scanner.protocol.internal.ScannerInternal;
+import org.sonar.scanner.protocol.internal.ScannerInternal.AnalysisCacheMsg;
+import org.sonar.scanner.scan.branch.BranchConfiguration;
+import org.sonarqube.ws.client.WsResponse;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.sonar.scanner.cache.AnalysisCacheLoader.CONTENT_ENCODING;
+
+public class AnalysisCacheLoaderTest {
+ private final WsResponse response = mock(WsResponse.class);
+ private final DefaultScannerWsClient wsClient = mock(DefaultScannerWsClient.class);
+ private final InputProject project = mock(InputProject.class);
+ private final BranchConfiguration branchConfiguration = mock(BranchConfiguration.class);
+ private final AnalysisCacheLoader loader = new AnalysisCacheLoader(wsClient, project, branchConfiguration);
+
+ @Before
+ public void before() {
+ when(wsClient.call(any())).thenReturn(response);
+ }
+
+ @Test
+ public void loads_content() throws IOException {
+ ScannerInternal.AnalysisCacheMsg expected = ScannerInternal.AnalysisCacheMsg.newBuilder()
+ .putMap("key", ByteString.copyFrom("value", StandardCharsets.UTF_8))
+ .build();
+ setResponse(expected);
+ AnalysisCacheMsg msg = loader.load().get();
+ assertThat(msg).isEqualTo(expected);
+ }
+
+ @Test
+ public void loads_compressed_content() throws IOException {
+ AnalysisCacheMsg expected = AnalysisCacheMsg.newBuilder()
+ .putMap("key", ByteString.copyFrom("value", StandardCharsets.UTF_8))
+ .build();
+ setCompressedResponse(expected);
+ AnalysisCacheMsg msg = loader.load().get();
+ assertThat(msg).isEqualTo(expected);
+ }
+
+ @Test
+ public void returns_empty_if_404() {
+ when(response.code()).thenReturn(404);
+ assertThat(loader.load()).isEmpty();
+ }
+
+ private void setResponse(AnalysisCacheMsg msg) throws IOException {
+ when(response.contentStream()).thenReturn(createInputStream(msg));
+ }
+
+ private void setCompressedResponse(AnalysisCacheMsg msg) throws IOException {
+ when(response.contentStream()).thenReturn(new DeflaterInputStream(createInputStream(msg)));
+ when(response.header(CONTENT_ENCODING)).thenReturn(Optional.of("gzip"));
+ }
+
+ private InputStream createInputStream(AnalysisCacheMsg analysisCacheMsg) throws IOException {
+ ByteArrayOutputStream serialized = new ByteArrayOutputStream(analysisCacheMsg.getSerializedSize());
+ analysisCacheMsg.writeTo(serialized);
+ return new ByteArrayInputStream(serialized.toByteArray());
+ }
+}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/AnalysisCacheMemoryStorageTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/AnalysisCacheMemoryStorageTest.java
new file mode 100644
index 00000000000..fb3a994cf57
--- /dev/null
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/AnalysisCacheMemoryStorageTest.java
@@ -0,0 +1,66 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.cache;
+
+import com.google.protobuf.ByteString;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Optional;
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+import org.sonar.scanner.protocol.internal.ScannerInternal.AnalysisCacheMsg;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class AnalysisCacheMemoryStorageTest {
+ private final AnalysisCacheLoader loader = mock(AnalysisCacheLoader.class);
+ private final AnalysisCacheMemoryStorage storage = new AnalysisCacheMemoryStorage(loader);
+
+ @Test
+ public void storage_loads_with_loader() throws IOException {
+ when(loader.load()).thenReturn(Optional.of(AnalysisCacheMsg.newBuilder()
+ .putMap("key1", ByteString.copyFrom("value1", StandardCharsets.UTF_8))
+ .build()));
+
+ storage.load();
+ verify(loader).load();
+ assertThat(IOUtils.toString(storage.get("key1"), StandardCharsets.UTF_8)).isEqualTo("value1");
+ assertThat(storage.contains("key1")).isTrue();
+ }
+
+ @Test
+ public void get_returns_null_if_doesnt_contain_key() {
+ when(loader.load()).thenReturn(Optional.of(AnalysisCacheMsg.newBuilder().build()));
+ storage.load();
+ assertThat(storage.contains("key1")).isFalse();
+ assertThat(storage.get("key1")).isNull();
+ }
+
+ @Test
+ public void get_returns_null_if_no_cache() {
+ when(loader.load()).thenReturn(Optional.empty());
+ storage.load();
+ assertThat(storage.contains("key1")).isFalse();
+ assertThat(storage.get("key1")).isNull();
+ }
+}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/AnalysisCacheProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/AnalysisCacheProviderTest.java
new file mode 100644
index 00000000000..5435e815c5f
--- /dev/null
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/AnalysisCacheProviderTest.java
@@ -0,0 +1,65 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.cache;
+
+import org.junit.Test;
+import org.sonar.api.batch.sensor.cache.ReadCache;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class AnalysisCacheProviderTest {
+
+ AnalysisCacheEnabled analysisCacheEnabled = mock(AnalysisCacheEnabled.class);
+ AnalysisCacheMemoryStorage storage = mock(AnalysisCacheMemoryStorage.class);
+ ReadCache readCache = mock(ReadCache.class);
+ AnalysisCacheProvider cacheProvider = new AnalysisCacheProvider();
+
+ @Test
+ public void provide_noop_reader_cache_when_disable() {
+ when(analysisCacheEnabled.isEnabled()).thenReturn(false);
+ var cache = cacheProvider.provideReader(analysisCacheEnabled, storage);
+ assertThat(cache).isInstanceOf(AnalysisCacheProvider.NoOpReadCache.class);
+ }
+
+ @Test
+ public void provide_noop_writer_cache_when_disable() {
+ when(analysisCacheEnabled.isEnabled()).thenReturn(false);
+ var cache = cacheProvider.provideWriter(analysisCacheEnabled, readCache);
+ assertThat(cache).isInstanceOf(AnalysisCacheProvider.NoOpWriteCache.class);
+ }
+
+ @Test
+ public void provide_real_reader_cache_when_enable() {
+ when(analysisCacheEnabled.isEnabled()).thenReturn(true);
+ var cache = cacheProvider.provideReader(analysisCacheEnabled, storage);
+ verify(storage).load();
+ assertThat(cache).isInstanceOf(ReadCacheImpl.class);
+ }
+
+ @Test
+ public void provide_real_writer_cache_when_enable() {
+ when(analysisCacheEnabled.isEnabled()).thenReturn(true);
+ var cache = cacheProvider.provideWriter(analysisCacheEnabled, readCache);
+ assertThat(cache).isInstanceOf(WriteCacheImpl.class);
+ }
+}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/ReadCacheImplTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/ReadCacheImplTest.java
new file mode 100644
index 00000000000..5ccf36e6cfc
--- /dev/null
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/ReadCacheImplTest.java
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.cache;
+
+import java.io.InputStream;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ReadCacheImplTest {
+ private final AnalysisCacheStorage storage = mock(AnalysisCacheStorage.class);
+ private final ReadCacheImpl readCache = new ReadCacheImpl(storage);
+
+ @Test
+ public void read_delegates_to_storage() {
+ InputStream is = mock(InputStream.class);
+ when(storage.get("key")).thenReturn(is);
+ when(storage.contains("key")).thenReturn(true);
+ assertThat(readCache.read("key")).isEqualTo(is);
+ }
+
+ @Test
+ public void read_fails_if_key_not_found() {
+ assertThatThrownBy(() -> readCache.read("unknown")).isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @Test
+ public void contains_delegates_to_storage() {
+ when(storage.contains("key")).thenReturn(true);
+ assertThat(readCache.contains("key")).isTrue();
+ }
+}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/WriteCacheImplTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/WriteCacheImplTest.java
new file mode 100644
index 00000000000..653ded84d72
--- /dev/null
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cache/WriteCacheImplTest.java
@@ -0,0 +1,85 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.scanner.cache;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.data.MapEntry.entry;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class WriteCacheImplTest {
+ private final ReadCacheImpl readCache = mock(ReadCacheImpl.class);
+ private final WriteCacheImpl writeCache = new WriteCacheImpl(readCache);
+
+ @Test
+ public void write_bytes_adds_entries() {
+ byte[] b1 = new byte[] {1, 2, 3};
+ byte[] b2 = new byte[] {3, 4};
+ writeCache.write("key", b1);
+ writeCache.write("key2", b2);
+
+ assertThat(writeCache.getCache()).containsOnly(entry("key", b1), entry("key2", b2));
+ }
+
+ @Test
+ public void write_inputStream_adds_entries() {
+ byte[] b1 = new byte[] {1, 2, 3};
+ byte[] b2 = new byte[] {3, 4};
+ writeCache.write("key", new ByteArrayInputStream(b1));
+ writeCache.write("key2", new ByteArrayInputStream(b2));
+
+ assertThat(writeCache.getCache()).containsOnly(entry("key", b1), entry("key2", b2));
+ }
+
+ @Test
+ public void write_throws_IAE_if_writing_same_key_twice() {
+ byte[] b1 = new byte[] {1};
+ byte[] b2 = new byte[] {2};
+
+
+ writeCache.write("key", b1);
+ assertThatThrownBy(() -> writeCache.write("key", b2))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("Cache already contains key 'key'");
+ }
+
+ @Test
+ public void copyFromPrevious_throws_IAE_if_read_cache_doesnt_contain_key() {
+ assertThatThrownBy(() -> writeCache.copyFromPrevious("key"))
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("Previous cache doesn't contain key 'key'");
+ }
+
+ @Test
+ public void copyFromPrevious_reads_from_readCache() {
+ byte[] b = new byte[] {1};
+ InputStream value = new ByteArrayInputStream(b);
+ when(readCache.contains("key")).thenReturn(true);
+ when(readCache.read("key")).thenReturn(value);
+ writeCache.copyFromPrevious("key");
+
+ assertThat(writeCache.getCache()).containsOnly(entry("key", b));
+ }
+}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/PluginCachePublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/AnalysisCachePublisherTest.java
index 5e23f6853f9..c79939c16af 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/PluginCachePublisherTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/AnalysisCachePublisherTest.java
@@ -26,7 +26,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.sonar.scanner.cache.PluginCacheEnabled;
+import org.sonar.scanner.cache.AnalysisCacheEnabled;
import org.sonar.scanner.cache.ScannerWriteCache;
import org.sonar.scanner.protocol.output.ScannerReportWriter;
@@ -38,13 +38,13 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
-public class PluginCachePublisherTest {
+public class AnalysisCachePublisherTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
private final ScannerWriteCache writeCache = mock(ScannerWriteCache.class);
- private final PluginCacheEnabled pluginCacheEnabled = mock(PluginCacheEnabled.class);
- private final PluginCachePublisher publisher = new PluginCachePublisher(pluginCacheEnabled, writeCache);
+ private final AnalysisCacheEnabled analysisCacheEnabled = mock(AnalysisCacheEnabled.class);
+ private final AnalysisCachePublisher publisher = new AnalysisCachePublisher(analysisCacheEnabled, writeCache);
private ScannerReportWriter scannerReportWriter;
@@ -55,7 +55,7 @@ public class PluginCachePublisherTest {
@Test
public void publish_does_nothing_if_cache_not_enabled() {
- when(pluginCacheEnabled.isEnabled()).thenReturn(false);
+ when(analysisCacheEnabled.isEnabled()).thenReturn(false);
publisher.publish(scannerReportWriter);
verifyNoInteractions(writeCache);
assertThat(scannerReportWriter.getFileStructure().root()).isEmptyDirectory();
@@ -64,18 +64,18 @@ public class PluginCachePublisherTest {
@Test
public void publish_cache() {
when(writeCache.getCache()).thenReturn(Map.of("key1", "value1".getBytes(StandardCharsets.UTF_8)));
- when(pluginCacheEnabled.isEnabled()).thenReturn(true);
+ when(analysisCacheEnabled.isEnabled()).thenReturn(true);
publisher.publish(scannerReportWriter);
verify(writeCache, times(2)).getCache();
- assertThat(scannerReportWriter.getFileStructure().pluginCache()).exists();
+ assertThat(scannerReportWriter.getFileStructure().analysisCache()).exists();
}
@Test
public void publish_empty_cache() {
when(writeCache.getCache()).thenReturn(emptyMap());
- when(pluginCacheEnabled.isEnabled()).thenReturn(true);
+ when(analysisCacheEnabled.isEnabled()).thenReturn(true);
publisher.publish(scannerReportWriter);
verify(writeCache).getCache();
- assertThat(scannerReportWriter.getFileStructure().pluginCache()).doesNotExist();
+ assertThat(scannerReportWriter.getFileStructure().analysisCache()).doesNotExist();
}
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorContextTest.java
index 5b886662ecf..1063283716e 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorContextTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorContextTest.java
@@ -37,6 +37,9 @@ import org.sonar.api.config.internal.MapSettings;
import org.sonar.api.internal.SonarRuntimeImpl;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.utils.Version;
+import org.sonar.scanner.cache.AnalysisCacheEnabled;
+import org.sonar.scanner.cache.ReadCacheImpl;
+import org.sonar.scanner.cache.WriteCacheImpl;
import org.sonar.scanner.scan.branch.BranchConfiguration;
import static org.assertj.core.api.Assertions.assertThat;
@@ -55,6 +58,9 @@ public class ModuleSensorContextTest {
private SensorStorage sensorStorage;
private SonarRuntime runtime;
private BranchConfiguration branchConfiguration;
+ private WriteCacheImpl writeCache;
+ private ReadCacheImpl readCache;
+ private AnalysisCacheEnabled analysisCacheEnabled;
@Before
public void prepare() throws Exception {
@@ -66,18 +72,25 @@ public class ModuleSensorContextTest {
settings = new MapSettings();
sensorStorage = mock(SensorStorage.class);
branchConfiguration = mock(BranchConfiguration.class);
+ writeCache = mock(WriteCacheImpl.class);
+ readCache = mock(ReadCacheImpl.class);
+ analysisCacheEnabled = mock(AnalysisCacheEnabled.class);
runtime = SonarRuntimeImpl.forSonarQube(Version.parse("5.5"), SonarQubeSide.SCANNER, SonarEdition.COMMUNITY);
}
@Test
public void shouldProvideComponents() {
- adaptor = new ModuleSensorContext(mock(DefaultInputProject.class), mock(InputModule.class), settings.asConfig(), settings, fs, activeRules, sensorStorage, runtime, branchConfiguration);
+ adaptor = new ModuleSensorContext(mock(DefaultInputProject.class), mock(InputModule.class), settings.asConfig(), settings, fs, activeRules, sensorStorage, runtime,
+ branchConfiguration, writeCache, readCache, analysisCacheEnabled);
assertThat(adaptor.activeRules()).isEqualTo(activeRules);
assertThat(adaptor.fileSystem()).isEqualTo(fs);
assertThat(adaptor.getSonarQubeVersion()).isEqualTo(Version.parse("5.5"));
assertThat(adaptor.runtime()).isEqualTo(runtime);
assertThat(adaptor.canSkipUnchangedFiles()).isFalse();
+ assertThat(adaptor.nextCache()).isEqualTo(writeCache);
+ assertThat(adaptor.previousAnalysisCache()).isEqualTo(readCache);
+
assertThat(adaptor.newIssue()).isNotNull();
assertThat(adaptor.newExternalIssue()).isNotNull();
assertThat(adaptor.newAdHocRule()).isNotNull();
@@ -90,7 +103,8 @@ public class ModuleSensorContextTest {
@Test
public void pull_request_can_skip_unchanged_files() {
when(branchConfiguration.isPullRequest()).thenReturn(true);
- adaptor = new ModuleSensorContext(mock(DefaultInputProject.class), mock(InputModule.class), settings.asConfig(), settings, fs, activeRules, sensorStorage, runtime, branchConfiguration);
+ adaptor = new ModuleSensorContext(mock(DefaultInputProject.class), mock(InputModule.class), settings.asConfig(), settings, fs, activeRules, sensorStorage, runtime,
+ branchConfiguration, writeCache, readCache, analysisCacheEnabled);
assertThat(adaptor.canSkipUnchangedFiles()).isTrue();
}