Skip to content

Commit

Permalink
Use Java 17 language features
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkEWaite committed Jan 17, 2025
1 parent c2fa48c commit 52a03ef
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,11 @@ public void testRemoveBadge() throws Exception {
p.getPublishersList()
.add(new GroovyPostbuildRecorder(
new SecureGroovyScript(
"manager.addShortText('test1');\n"
+ "manager.addShortText('test2');\n"
+ "manager.removeBadge(0);",
"""
manager.addShortText('test1');
manager.addShortText('test2');
manager.removeBadge(0);\
""",
true, // sandbox
Collections.<ClasspathEntry>emptyList()),
2, // behavior
Expand All @@ -638,9 +640,11 @@ public void testRemoveBadges() throws Exception {
p.getPublishersList()
.add(new GroovyPostbuildRecorder(
new SecureGroovyScript(
"manager.addShortText('test1');\n"
+ "manager.addShortText('test2');\n"
+ "manager.removeBadges();",
"""
manager.addShortText('test1');
manager.addShortText('test2');
manager.removeBadges();\
""",
true, // sandbox
Collections.<ClasspathEntry>emptyList()),
2, // behavior
Expand All @@ -659,9 +663,11 @@ public void testRemoveBadgeForHtmlBadge() throws Exception {
p.getPublishersList()
.add(new GroovyPostbuildRecorder(
new SecureGroovyScript(
"manager.addHtmlBadge('test1');\n"
+ "manager.addShortText('test2');\n"
+ "manager.removeBadge(0);",
"""
manager.addHtmlBadge('test1');
manager.addShortText('test2');
manager.removeBadge(0);\
""",
true, // sandbox
Collections.<ClasspathEntry>emptyList()),
2, // behavior
Expand All @@ -678,15 +684,17 @@ public void testRemoveSummary() throws Exception {
j.jenkins.setMarkupFormatter(RawHtmlMarkupFormatter.INSTANCE);

String template = "method org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder$BadgeManager %s";
ScriptApproval.get().approveSignature(String.format(template, "removeSummary int"));
ScriptApproval.get().approveSignature(String.format(template, "createSummary java.lang.String"));
ScriptApproval.get().approveSignature(template.formatted("removeSummary int"));
ScriptApproval.get().approveSignature(template.formatted("createSummary java.lang.String"));
FreeStyleProject p = j.createFreeStyleProject();
p.getPublishersList()
.add(new GroovyPostbuildRecorder(
new SecureGroovyScript(
"manager.createSummary('attribute.png').appendText('Test1', false, false, false, 'Black');\n"
+ "manager.createSummary('attribute.png').appendText('Test2', false, false, false, 'Black');\n"
+ "manager.removeSummary(0);",
"""
manager.createSummary('attribute.png').appendText('Test1', false, false, false, 'Black');
manager.createSummary('attribute.png').appendText('Test2', false, false, false, 'Black');
manager.removeSummary(0);\
""",
true,
Collections.<ClasspathEntry>emptyList()),
2, // behavior
Expand All @@ -701,14 +709,16 @@ public void testRemoveSummary() throws Exception {
@Test
public void testRemoveSummaries() throws Exception {
String template = "method org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder$BadgeManager %s";
ScriptApproval.get().approveSignature(String.format(template, "removeSummaries"));
ScriptApproval.get().approveSignature(String.format(template, "createSummary java.lang.String"));
ScriptApproval.get().approveSignature(template.formatted("removeSummaries"));
ScriptApproval.get().approveSignature(template.formatted("createSummary java.lang.String"));
FreeStyleProject p = j.createFreeStyleProject();
p.getPublishersList()
.add(new GroovyPostbuildRecorder(
new SecureGroovyScript(
"manager.createSummary('attribute.png').appendText('Test1', false, false, false, 'Black');\n"
+ "manager.removeSummaries();",
"""
manager.createSummary('attribute.png').appendText('Test1', false, false, false, 'Black');
manager.removeSummaries();\
""",
true,
Collections.<ClasspathEntry>emptyList()),
2, // behavior
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public void usingManagerErrorBadge() throws Exception {
public void logContains() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"echo '1st message'\n" + "echo '2nd message'\n"
+ "sleep 1\n"
+ // to flush output (inspecting Run.log from the build itself is unreliable; use a
// TaskListenerDecorator instead)
"echo(/found first message? ${manager.logContains(/1st message/)} second? ${manager.logContains(/2nd message/)} third? ${manager.logContains(/3rd message/)} /); ",
"""
echo '1st message'
echo '2nd message'
sleep 1
echo(/found first message? ${manager.logContains(/1st message/)} second? ${manager.logContains(/2nd message/)} third? ${manager.logContains(/3rd message/)} /); """,
true));
logging.record(WorkflowRun.class, Level.WARNING).capture(100);
r.assertLogContains(
Expand Down

0 comments on commit 52a03ef

Please sign in to comment.