Skip to content

Commit

Permalink
Added tests for PublicBuildStatusAction class and fixed a typo
Browse files Browse the repository at this point in the history
  • Loading branch information
yashpal2104 committed Dec 20, 2024
1 parent e327ae1 commit d693164
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public String doText(
Run<?, ?> run = null;

if (project != null && build != null) {
// as the user might have ViewStatus permission only (e.g. as anonymous) we get get the
// as the user might have ViewStatus permission only (e.g. as anonymous) we get the
// project impersonate and check for permission after getting the project
try (ACLContext ctx = ACL.as2(ACL.SYSTEM2)) {
for (String token : build.split(",")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,29 @@ public void testGetDisplayName() throws IOException {
private boolean isWindows() {
return File.pathSeparatorChar == ';';
}

@Test
public void doText_shouldReturnMissingQueryParameterWhenJobIsNull() throws IOException {
PublicBuildStatusAction action = new PublicBuildStatusAction();
String result = action.doText(null, null, null, "123");
assertThat(result, is("Missing query parameter: job"));
}

@Test
public void doText_shouldReturnProjectIconColorDescription() throws Exception {
Run<?, ?> build = job.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(build);
String result =
new PublicBuildStatusAction().doText(null, null, job.getName(), String.valueOf(build.getNumber()));
assertThat(result, is(job.getIconColor().getDescription()));
}

@Test
public void doText_shouldReturnRunIconColorDescription() throws Exception {
Run<?, ?> build = job.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(build);
String result =
new PublicBuildStatusAction().doText(null, null, job.getName(), String.valueOf(build.getNumber()));
assertThat(result, is(build.getIconColor().getDescription()));
}
}

0 comments on commit d693164

Please sign in to comment.