From 66806f1abddb7ca4eb55431c632a6ce0a276250c Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Tue, 28 Feb 2023 11:37:15 -0800 Subject: [PATCH] Improve test coverage (#475) --- .../tools/test/PluginCompatTester.java | 2 +- .../tools/test/PluginCompatTesterTest.java | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jenkins/tools/test/PluginCompatTester.java b/src/main/java/org/jenkins/tools/test/PluginCompatTester.java index 93e9dc0b6..3ed78a2bc 100644 --- a/src/main/java/org/jenkins/tools/test/PluginCompatTester.java +++ b/src/main/java/org/jenkins/tools/test/PluginCompatTester.java @@ -612,7 +612,7 @@ private boolean onlyOnePluginIncluded() { * @return Update center data */ @SuppressFBWarnings(value = "REDOS", justification = "intended behavior") - private UpdateSite.Data scanWAR(File war, String pluginRegExp) { + static UpdateSite.Data scanWAR(File war, String pluginRegExp) { UpdateSite.Entry core = null; List plugins = new ArrayList<>(); try (JarFile jf = new JarFile(war)) { diff --git a/src/test/java/org/jenkins/tools/test/PluginCompatTesterTest.java b/src/test/java/org/jenkins/tools/test/PluginCompatTesterTest.java index 41a5f528b..ea4e701b5 100644 --- a/src/test/java/org/jenkins/tools/test/PluginCompatTesterTest.java +++ b/src/test/java/org/jenkins/tools/test/PluginCompatTesterTest.java @@ -30,8 +30,10 @@ import static org.hamcrest.core.Is.is; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import hudson.model.UpdateSite; import java.io.File; import java.nio.file.Files; import java.nio.file.Path; @@ -86,6 +88,24 @@ void smokes(@TempDir File tempDir) throws Exception { assertEquals(0, failures); } + @Test + void updateSite() { + UpdateSite.Data data = + PluginCompatTester.scanWAR( + new File("target", "megawar.war").getAbsoluteFile(), + "WEB-INF/(?:optional-)?plugins/([^/.]+)[.][hj]pi"); + assertEquals("core", data.core.name); + assertNotNull(data.core.version); + assertEquals("https://foobar", data.core.url); + UpdateSite.Plugin plugin = data.plugins.get("text-finder"); + assertNotNull(plugin); + assertEquals("Text Finder", plugin.getDisplayName()); + assertEquals("Text Finder", plugin.title); + assertEquals("text-finder", plugin.name); + assertNotNull(plugin.version); + assertNotNull(plugin.url); + } + @Test void testMatcher() {