From c6bb73fb337c416d2ac4e8b88f1cc38c4c451195 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Tue, 19 Jul 2022 15:26:34 -0400 Subject: [PATCH] Improve `ShellStepTest.label` with Hamcrest --- .../steps/durable_task/ShellStepTest.java | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/test/java/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStepTest.java b/src/test/java/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStepTest.java index 3a02c8b1..302476af 100644 --- a/src/test/java/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStepTest.java +++ b/src/test/java/org/jenkinsci/plugins/workflow/steps/durable_task/ShellStepTest.java @@ -361,16 +361,9 @@ private static class Decorator extends LauncherDecorator implements Serializable WorkflowRun b = j.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0).get()); - boolean found = false; FlowGraphTable t = new FlowGraphTable(b.getExecution()); t.build(); - for (Row r : t.getRows()) { - if (r.getDisplayName().contains("Step with label")) { - found = true; - } - } - - assertTrue(found); + assertThat(t.getRows().stream().map(Row::getDisplayName).toArray(String[]::new), hasItemInArray(containsString("Step with label"))); } @Test public void labelShortened() throws Exception { @@ -382,16 +375,9 @@ private static class Decorator extends LauncherDecorator implements Serializable WorkflowRun b = j.assertBuildStatus(Result.SUCCESS, p.scheduleBuild2(0).get()); - boolean found = false; FlowGraphTable t = new FlowGraphTable(b.getExecution()); t.build(); - for (Row r : t.getRows()) { - if (r.getDisplayName().contains(singleLabel)) { - found = true; - } - } - - assertTrue(found); + assertThat(t.getRows().stream().map(Row::getDisplayName).toArray(String[]::new), hasItemInArray(containsString(singleLabel))); } @Issue("JENKINS-38381")