From ded91a06f0646a7a8bd13a9010d8305b8050e3f7 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 14 Jun 2017 16:08:15 +0200 Subject: [PATCH] Improve the way web hash is retrieved --- .../java/it/serverSystem/HttpHeadersTest.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/it/it-tests/src/test/java/it/serverSystem/HttpHeadersTest.java b/it/it-tests/src/test/java/it/serverSystem/HttpHeadersTest.java index 1d11d0d896a..12fccdb9ed7 100644 --- a/it/it-tests/src/test/java/it/serverSystem/HttpHeadersTest.java +++ b/it/it-tests/src/test/java/it/serverSystem/HttpHeadersTest.java @@ -24,14 +24,13 @@ import it.Category4Suite; import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Optional; import okhttp3.CacheControl; import okhttp3.Response; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; +import static com.google.common.io.Files.getFileExtension; import static org.assertj.core.api.Assertions.assertThat; import static util.ItUtils.call; @@ -150,11 +149,11 @@ public class HttpHeadersTest { */ private static String getJsHash() throws IOException { File cssFolder = new File(orchestrator.getServer().getHome(), "web/css"); - Optional cssPath = Files.list(cssFolder.toPath()).map(Path::getFileName).findFirst(); - if (cssPath.isPresent()) { - String fileName = cssPath.get().toFile().getName(); - return fileName.replace("sonar.", "").replace(".css", ""); - } - throw new IllegalStateException("sonar.css hasn't been found"); + String fileName = Files.list(cssFolder.toPath()) + .map(path -> path.toFile().getName()) + .filter(name -> getFileExtension(name).equals("css")) + .findFirst() + .orElseThrow(() -> new IllegalStateException("sonar.css hasn't been found")); + return fileName.replace("sonar.", "").replace(".css", ""); } } -- 2.39.5