Skip to content

Commit

Permalink
Some test code clean-up (#5669)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Jacomb <timjacomb1+github@gmail.com>
  • Loading branch information
offa and timja committed Aug 19, 2021
1 parent e0ada43 commit 3c8dd16
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 56 deletions.
46 changes: 18 additions & 28 deletions test/src/test/java/hudson/cli/WaitNodeOnlineCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
Expand Down Expand Up @@ -86,15 +85,12 @@ public void waitNodeOnlineShouldTimeoutOnGoingOfflineNode() throws Exception {
slave.toComputer().setTemporarilyOffline(true);

boolean timeoutOccurred = false;
FutureTask task = new FutureTask(new Callable() {
@Override
public Object call() {
final CLICommandInvoker.Result result = command
.authorizedTo(Jenkins.READ)
.invokeWithArgs("aNode");
fail("Never should return from previous CLI call!");
return null;
}
FutureTask task = new FutureTask(() -> {
final CLICommandInvoker.Result result = command
.authorizedTo(Jenkins.READ)
.invokeWithArgs("aNode");
fail("Never should return from previous CLI call!");
return null;
});
try {
task.get(30, TimeUnit.SECONDS);
Expand All @@ -115,15 +111,12 @@ public void waitNodeOnlineShouldTimeoutOnDisconnectedNode() throws Exception {
slave.toComputer().waitUntilOffline();

boolean timeoutOccurred = false;
FutureTask task = new FutureTask(new Callable() {
@Override
public Object call() {
final CLICommandInvoker.Result result = command
.authorizedTo(Jenkins.READ)
.invokeWithArgs("aNode");
fail("Never should return from previous CLI call!");
return null;
}
FutureTask task = new FutureTask(() -> {
final CLICommandInvoker.Result result = command
.authorizedTo(Jenkins.READ)
.invokeWithArgs("aNode");
fail("Never should return from previous CLI call!");
return null;
});
try {
task.get(30, TimeUnit.SECONDS);
Expand All @@ -143,15 +136,12 @@ public void waitNodeOnlineShouldTimeoutOnDisconnectingNode() throws Exception {
slave.toComputer().disconnect();

boolean timeoutOccurred = false;
FutureTask task = new FutureTask(new Callable() {
@Override
public Object call() {
final CLICommandInvoker.Result result = command
.authorizedTo(Jenkins.READ)
.invokeWithArgs("aNode");
fail("Never should return from previous CLI call!");
return null;
}
FutureTask task = new FutureTask(() -> {
final CLICommandInvoker.Result result = command
.authorizedTo(Jenkins.READ)
.invokeWithArgs("aNode");
fail("Never should return from previous CLI call!");
return null;
});
try {
task.get(30, TimeUnit.SECONDS);
Expand Down
8 changes: 0 additions & 8 deletions test/src/test/java/hudson/diagnosis/OldDataMonitorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@ public class OldDataMonitorTest {
OldDataMonitor odm = OldDataMonitor.get(r.jenkins);
FreeStyleProject p = r.jenkins.getItemByFullName("busted", FreeStyleProject.class);
assertNotNull(p);
/*
System.err.println(p.getActions());
for (Map.Entry<Saveable,OldDataMonitor.VersionRange> entry : odm.getData().entrySet()) {
System.err.println(entry.getKey());
System.err.println(entry.getValue());
System.err.println(entry.getValue().extra);
}
*/
assertEquals(Collections.singleton(p), odm.getData().keySet());
odm.doDiscard(null, null);
assertEquals(Collections.emptySet(), odm.getData().keySet());
Expand Down
4 changes: 2 additions & 2 deletions test/src/test/java/hudson/model/DependencyGraphTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void testTriggerJob() throws Exception {
j.jenkins.rebuildDependencyGraph();
// First build won't trigger down1 (Unstable doesn't meet threshold)
// but will trigger down2 (build #1 is odd).
Build b = (Build)p.scheduleBuild2(0, new Cause.UserCause()).get();
Build b = (Build)p.scheduleBuild2(0, new Cause.UserIdCause()).get();
String log = j.getLog(b);
Queue.Item q = j.jenkins.getQueue().getItem(down1);
assertNull("down1 should not be triggered: " + log, q);
Expand All @@ -85,7 +85,7 @@ public void testTriggerJob() throws Exception {
j.jenkins.rebuildDependencyGraph();
// ..and next build will trigger down1 (Success meets threshold),
// but not down2 (build #2 is even)
b = (Build)p.scheduleBuild2(0, new Cause.UserCause()).get();
b = (Build)p.scheduleBuild2(0, new Cause.UserIdCause()).get();
log = j.getLog(b);
q = j.jenkins.getQueue().getItem(down2);
assertNull("down2 should not be triggered: " + log, q);
Expand Down
4 changes: 2 additions & 2 deletions test/src/test/java/hudson/model/MyViewTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void setup() {
}

@Test
public void testContains() throws IOException, Exception{
public void testContains() throws Exception{

GlobalMatrixAuthorizationStrategy auth = new GlobalMatrixAuthorizationStrategy();
rule.jenkins.setAuthorizationStrategy(auth);
Expand All @@ -77,7 +77,7 @@ public void testContains() throws IOException, Exception{
}

@Test
public void testDoCreateItem() throws IOException, Exception{
public void testDoCreateItem() throws Exception{
logs.record(AbstractItem.class, Level.ALL);
MyView view = new MyView("My", rule.jenkins);
rule.jenkins.addView(view);
Expand Down
6 changes: 2 additions & 4 deletions test/src/test/java/hudson/model/NodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,11 @@ public void assertThatCloudLabel(boolean contains, TagCloud<LabelAtom> tagCloud,
}

// Gather information for failure message just in case.
containsFailureMessage.append("{").append(entry.item.toString()).append(", ").append(entry.weight).append("}");
containsFailureMessage.append("{").append(entry.item).append(", ").append(entry.weight).append("}");
}

// If a label should be part of the cloud label then fail.
if (contains) {
fail(containsFailureMessage.toString() + "]");
}
assertFalse(containsFailureMessage + "]", contains);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test/src/test/java/hudson/model/ViewTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public class ViewTest {
}

@Test
public void testGetQueueItems() throws IOException, Exception{
public void testGetQueueItems() throws Exception{
ListView view1 = listView("view1");
view1.filterQueue = true;
ListView view2 = listView("view2");
Expand Down Expand Up @@ -367,7 +367,7 @@ private void assertNotContainsItems(View view, Task... items) {
}

@Test
public void testGetComputers() throws IOException, Exception{
public void testGetComputers() throws Exception{
ListView view1 = listView("view1");
ListView view2 = listView("view2");
ListView view3 = listView("view3");
Expand Down
2 changes: 1 addition & 1 deletion test/src/test/java/hudson/security/SecurityRealmTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void many_sessions_logout() throws Exception {
}
}
}
System.err.println(builder.toString());
System.err.println(builder);
assertThat(unexpectedSessionCookies, is(0));
}

Expand Down
4 changes: 2 additions & 2 deletions test/src/test/java/hudson/tasks/FingerprinterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,15 @@ public void fingerprintCleanup() throws Exception {
}


private FreeStyleProject createFreeStyleProjectWithFingerprints(String[] contents, String[] files) throws IOException, Exception {
private FreeStyleProject createFreeStyleProjectWithFingerprints(String[] contents, String[] files) throws Exception {
FreeStyleProject project = j.createFreeStyleProject();

addFingerprinterToProject(project, contents, files);

return project;
}

private void addFingerprinterToProject(AbstractProject<?, ?> project, String[] contents, String[] files) throws Exception {
private void addFingerprinterToProject(AbstractProject<?, ?> project, String[] contents, String[] files) {
StringBuilder targets = new StringBuilder();
for (int i = 0; i < contents.length; i++) {
if (project instanceof MatrixProject) {
Expand Down
2 changes: 1 addition & 1 deletion test/src/test/java/hudson/util/BootFailureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public WebAppMain.FileAndDescription getHomeDir(ServletContextEvent event) {
ServletContext ws = createWebServer((context, server) -> {
NoListenerConfiguration noListenerConfiguration = context.getBean(NoListenerConfiguration.class);
// future-proof
Assert.notNull(noListenerConfiguration);
Assert.notNull(noListenerConfiguration, "Value must not be null");
if (noListenerConfiguration != null) {
context.removeBean(noListenerConfiguration);
context.addBean(new AbstractLifeCycle() {
Expand Down
4 changes: 2 additions & 2 deletions test/src/test/java/jenkins/install/SetupWizardTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private static final class CustomLocalUpdateSite extends UpdateSite {
private final File tmpdir;

CustomLocalUpdateSite(File tmpdir) throws MalformedURLException {
super("custom-uc", tmpdir.toURI().toURL().toString() + "update-center.json");
super("custom-uc", tmpdir.toURI().toURL() + "update-center.json");
this.tmpdir = tmpdir;
}

Expand All @@ -197,7 +197,7 @@ private static final class CustomLocalUpdateSiteWithWrapperJSON extends UpdateSi
private final File tmpdir;

CustomLocalUpdateSiteWithWrapperJSON(File tmpdir) throws MalformedURLException {
super("custom-uc2", tmpdir.toURI().toURL().toString() + "update-center.json");
super("custom-uc2", tmpdir.toURI().toURL() + "update-center.json");
this.tmpdir = tmpdir;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.kohsuke.stapler.beanutils;

import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.MissingAttributeException;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
import org.xml.sax.SAXException;
Expand All @@ -14,7 +13,7 @@ public void setClass(Object clazz) {
}

@Override
public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
public void doTag(XMLOutput output) throws JellyTagException {
try {
output.writeComment("Tag with object property\n");
output.writeCDATA(getClass().getName() + ":" + clazz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.apache.commons.jelly.DynaTag;
import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.MissingAttributeException;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
import org.xml.sax.SAXException;
Expand All @@ -15,7 +14,7 @@ public void setClass(String clazz) {
}

@Override
public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
public void doTag(XMLOutput output) throws JellyTagException {
try {
output.writeComment("Tag with string property\n");
output.writeCDATA(getClass().getName() + ":" + clazz);
Expand Down

0 comments on commit 3c8dd16

Please sign in to comment.