diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2022-03-17 14:59:15 -0500 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-03-18 20:02:58 +0000 |
commit | 7aa77dfb2275f38de07c9d3b936e0eea43ac96af (patch) | |
tree | 0ff992bdb11f30f395243e86e1d3039847dd8231 /sonar-scanner-engine/src | |
parent | eb34454afc19f4994ae587b43ff2d0c79978de23 (diff) | |
download | sonarqube-7aa77dfb2275f38de07c9d3b936e0eea43ac96af.tar.gz sonarqube-7aa77dfb2275f38de07c9d3b936e0eea43ac96af.zip |
SONAR-16097 Apply feedback
Diffstat (limited to 'sonar-scanner-engine/src')
4 files changed, 9 insertions, 15 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheLoader.java index 420a5d5f852..f582e122079 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheLoader.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheLoader.java @@ -40,7 +40,7 @@ import org.sonarqube.ws.client.WsResponse; public class AnalysisCacheLoader { static final String CONTENT_ENCODING = "Content-Encoding"; static final String ACCEPT_ENCODING = "Accept-Encoding"; - private static final String URL = "api/scanner_cache/get"; + private static final String URL = "api/analysis_cache/get"; private final DefaultScannerWsClient wsClient; private final InputProject project; diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheMemoryStorage.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheMemoryStorage.java index 420bd1711a8..56596dedeb7 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheMemoryStorage.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheMemoryStorage.java @@ -20,7 +20,6 @@ package org.sonar.scanner.cache; import java.io.InputStream; -import javax.annotation.CheckForNull; import javax.annotation.Nullable; import org.sonar.scanner.protocol.internal.ScannerInternal.AnalysisCacheMsg; @@ -34,15 +33,11 @@ public class AnalysisCacheMemoryStorage implements AnalysisCacheStorage { } @Override - @CheckForNull public InputStream get(String key) { - if (cache == null) { - return null; - } - if (cache.containsMap(key)) { - return cache.getMapOrThrow(key).newInput(); + if (!contains(key)) { + throw new IllegalArgumentException("Key not found: " + key); } - return null; + return cache.getMapOrThrow(key).newInput(); } @Override diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheStorage.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheStorage.java index 5fb7765da38..9f58f3b3ad7 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheStorage.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cache/AnalysisCacheStorage.java @@ -20,10 +20,8 @@ package org.sonar.scanner.cache; import java.io.InputStream; -import javax.annotation.CheckForNull; public interface AnalysisCacheStorage { - @CheckForNull InputStream get(String key); boolean contains(String key); 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 index fb3a994cf57..528e9d6bd10 100644 --- 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 @@ -28,6 +28,7 @@ import org.junit.Test; import org.sonar.scanner.protocol.internal.ScannerInternal.AnalysisCacheMsg; 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.verify; import static org.mockito.Mockito.when; @@ -49,18 +50,18 @@ public class AnalysisCacheMemoryStorageTest { } @Test - public void get_returns_null_if_doesnt_contain_key() { + public void get_throws_IAE_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(); + assertThatThrownBy(() -> storage.get("key1")).isInstanceOf(IllegalArgumentException.class); } @Test - public void get_returns_null_if_no_cache() { + public void get_throws_IAE_if_no_cache() { when(loader.load()).thenReturn(Optional.empty()); storage.load(); assertThat(storage.contains("key1")).isFalse(); - assertThat(storage.get("key1")).isNull(); + assertThatThrownBy(() -> storage.get("key1")).isInstanceOf(IllegalArgumentException.class); } } |