From 7f8c60e2a1ecd365501f67c3425d75cc92cc9ac7 Mon Sep 17 00:00:00 2001 From: "Bruno P. Kinoshita" Date: Sun, 18 Aug 2024 15:38:47 +0200 Subject: [PATCH] Close webclient try-with-resources --- .../issue62835/TestForNodeLabelParameter.java | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/test/java/org/biouno/unochoice/issue62835/TestForNodeLabelParameter.java b/src/test/java/org/biouno/unochoice/issue62835/TestForNodeLabelParameter.java index 14bd8b68..4f2d712c 100644 --- a/src/test/java/org/biouno/unochoice/issue62835/TestForNodeLabelParameter.java +++ b/src/test/java/org/biouno/unochoice/issue62835/TestForNodeLabelParameter.java @@ -57,7 +57,6 @@ import com.google.common.collect.Lists; import hudson.model.FreeStyleProject; -import hudson.model.ParameterDefinition; import hudson.model.ParametersDefinitionProperty; import hudson.model.labels.LabelAtom; import hudson.slaves.DumbSlave; @@ -117,30 +116,31 @@ public void testNodeLabelParameterValueFound() throws IOException, SAXException true, 1); - project.addProperty(new ParametersDefinitionProperty(Arrays.asList(nodeLabelParameter, reactsToNodeLabelParameter))); + project.addProperty(new ParametersDefinitionProperty(Arrays.asList(nodeLabelParameter, reactsToNodeLabelParameter))); project.save(); - WebClient wc = j.createWebClient(); - wc.setThrowExceptionOnFailingStatusCode(false); - HtmlPage configPage = wc.goTo("job/" + project.getName() + "/build?delay=0sec"); - DomElement renderedParameterElement = configPage.getElementById("random-name"); - HtmlSelect select = null; - for (DomNode node: renderedParameterElement.getChildren()) { - if (node instanceof HtmlSelect) { - select = (HtmlSelect) node; - break; + try (WebClient wc = j.createWebClient()) { + wc.setThrowExceptionOnFailingStatusCode(false); + HtmlPage configPage = wc.goTo("job/" + project.getName() + "/build?delay=0sec"); + DomElement renderedParameterElement = configPage.getElementById("random-name"); + HtmlSelect select = null; + for (DomNode node: renderedParameterElement.getChildren()) { + if (node instanceof HtmlSelect) { + select = (HtmlSelect) node; + break; + } } + if (select == null) { + fail("Missing cascade parameter select HTML node element!"); + } + List htmlOptions = select.getOptions(); + final List options = htmlOptions + .stream() + .map(HtmlOption::getText) + .collect(Collectors.toList()); + final List expected = new LinkedList<>(Collections.singletonList(nodeName)); + assertEquals("Wrong number of HTML options rendered", expected.size(), options.size()); + assertEquals("Wrong HTML options rendered (or out of order)", expected, options); } - if (select == null) { - fail("Missing cascade parameter select HTML node element!"); - } - List htmlOptions = select.getOptions(); - final List options = htmlOptions - .stream() - .map(HtmlOption::getText) - .collect(Collectors.toList()); - final List expected = new LinkedList<>(Collections.singletonList(nodeName)); - assertEquals("Wrong number of HTML options rendered", expected.size(), options.size()); - assertEquals("Wrong HTML options rendered (or out of order)", expected, options); } }