提交 3aa812fe 编写于 作者: O Oliver Gondža

Refactor CLI tests

上级 de132fb3
......@@ -35,9 +35,7 @@ import org.jvnet.hudson.test.MockFolder;
import static org.hamcrest.MatcherAssert.assertThat;
import static hudson.cli.CLICommandInvoker.Matcher.hasNoStandardOutput;
import static hudson.cli.CLICommandInvoker.Matcher.hasNoErrorOutput;
import static hudson.cli.CLICommandInvoker.Matcher.succeeded;
import static hudson.cli.CLICommandInvoker.Matcher.succeededSilently;
@SuppressWarnings("DM_DEFAULT_ENCODING")
public class CopyJobCommandTest {
......@@ -56,9 +54,7 @@ public class CopyJobCommandTest {
CLICommandInvoker.Result result = command.invokeWithArgs("dir1/p1", "dir2/p2");
assertThat(result, succeeded());
assertThat(result, hasNoStandardOutput());
assertThat(result, hasNoErrorOutput());
assertThat(result, succeededSilently());
assertNotNull(j.jenkins.getItemByFullName("dir2/p2"));
// TODO test copying from/to root, or into nonexistent folder
......@@ -72,9 +68,7 @@ public class CopyJobCommandTest {
CLICommandInvoker.Result result = command.invokeWithArgs(p1.getName(), copiedProjectName);
assertThat(result, succeeded());
assertThat(result, hasNoStandardOutput());
assertThat(result, hasNoErrorOutput());
assertThat(result, succeededSilently());
FreeStyleProject p2 = (FreeStyleProject)j.jenkins.getItem(copiedProjectName);
......
......@@ -28,7 +28,9 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.text.IsEmptyString.isEmptyString;
import static hudson.cli.CLICommandInvoker.Matcher.failedWith;
import static hudson.cli.CLICommandInvoker.Matcher.hasNoStandardOutput;
import static hudson.cli.CLICommandInvoker.Matcher.succeededSilently;
import hudson.model.Computer;
import hudson.model.Node;
import hudson.model.Slave;
......@@ -59,8 +61,8 @@ public class CreateNodeCommandTest {
;
assertThat(result.stderr(), containsString("user is missing the Slave/Create permission"));
assertThat("No output expected", result.stdout(), isEmptyString());
assertThat("Command is expected to fail", result.returnCode(), equalTo(-1));
assertThat(result, hasNoStandardOutput());
assertThat(result, failedWith(-1));
}
@Test public void createNode() throws Exception {
......@@ -71,8 +73,7 @@ public class CreateNodeCommandTest {
.invoke()
;
assertThat("No error output expected", result.stderr(), isEmptyString());
assertThat("Command is expected to succeed", result.returnCode(), equalTo(0));
assertThat(result, succeededSilently());
final Slave updatedSlave = (Slave) j.jenkins.getNode("SlaveFromXML");
assertThat(updatedSlave.getNodeName(), equalTo("SlaveFromXML"));
......@@ -88,8 +89,7 @@ public class CreateNodeCommandTest {
.invokeWithArgs("CustomSlaveName")
;
assertThat("No error output expected", result.stderr(), isEmptyString());
assertThat("Command is expected to succeed", result.returnCode(), equalTo(0));
assertThat(result, succeededSilently());
assertThat("A slave with original name should not exist", j.jenkins.getNode("SlaveFromXml"), nullValue());
......@@ -109,8 +109,7 @@ public class CreateNodeCommandTest {
.invokeWithArgs("CustomSlaveName")
;
assertThat("No error output expected", result.stderr(), isEmptyString());
assertThat("Command is expected to succeed", result.returnCode(), equalTo(0));
assertThat(result, succeededSilently());
assertThat("A slave with original name should be left untouched", j.jenkins.getNode("SlaveFromXml"), equalTo(originalSlave));
......@@ -131,8 +130,8 @@ public class CreateNodeCommandTest {
;
assertThat(result.stderr(), containsString("Node 'SlaveFromXML' already exists"));
assertThat("No output expected", result.stdout(), isEmptyString());
assertThat("Command is expected to fail", result.returnCode(), equalTo(-1));
assertThat(result, hasNoStandardOutput());
assertThat(result, failedWith(-1));
}
@Test public void createNodeShouldFailIfNodeAlreadyExistWhenNameSpecifiedExplicitly() throws Exception {
......@@ -146,7 +145,7 @@ public class CreateNodeCommandTest {
;
assertThat(result.stderr(), containsString("Node 'ExistingSlave' already exists"));
assertThat("No output expected", result.stdout(), isEmptyString());
assertThat("Command is expected to fail", result.returnCode(), equalTo(-1));
assertThat(result, hasNoStandardOutput());
assertThat(result, failedWith(-1));
}
}
......@@ -28,6 +28,7 @@ import static hudson.cli.CLICommandInvoker.Matcher.failedWith;
import static hudson.cli.CLICommandInvoker.Matcher.hasNoStandardOutput;
import static hudson.cli.CLICommandInvoker.Matcher.hasNoErrorOutput;
import static hudson.cli.CLICommandInvoker.Matcher.succeeded;
import static hudson.cli.CLICommandInvoker.Matcher.succeededSilently;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
......@@ -76,9 +77,7 @@ public class CreateViewCommandTest {
.invoke()
;
assertThat(result, succeeded());
assertThat(result, hasNoErrorOutput());
assertThat(result, hasNoStandardOutput());
assertThat(result, succeededSilently());
final View updatedView = j.jenkins.getView("ViewFromXML");
assertThat(updatedView.getViewName(), equalTo("ViewFromXML"));
......@@ -94,9 +93,7 @@ public class CreateViewCommandTest {
.invokeWithArgs("CustomViewName")
;
assertThat(result, succeeded());
assertThat(result, hasNoErrorOutput());
assertThat(result, hasNoStandardOutput());
assertThat(result, succeededSilently());
assertThat("A view with original name should not exist", j.jenkins.getView("ViewFromXML"), nullValue());
......
......@@ -31,6 +31,7 @@ import static org.hamcrest.Matchers.nullValue;
import static hudson.cli.CLICommandInvoker.Matcher.hasNoStandardOutput;
import static hudson.cli.CLICommandInvoker.Matcher.hasNoErrorOutput;
import static hudson.cli.CLICommandInvoker.Matcher.succeeded;
import static hudson.cli.CLICommandInvoker.Matcher.succeededSilently;
import static hudson.cli.CLICommandInvoker.Matcher.failedWith;
import java.io.IOException;
......@@ -78,9 +79,7 @@ public class DeleteViewCommandTest {
.invokeWithArgs("aView")
;
assertThat(result, succeeded());
assertThat(result, hasNoStandardOutput());
assertThat(result, hasNoErrorOutput());
assertThat(result, succeededSilently());
assertThat(j.jenkins.getView("aView"), nullValue());
}
......
......@@ -24,6 +24,10 @@
package hudson.cli;
import static hudson.cli.CLICommandInvoker.Matcher.failedWith;
import static hudson.cli.CLICommandInvoker.Matcher.hasNoStandardOutput;
import static hudson.cli.CLICommandInvoker.Matcher.hasNoErrorOutput;
import static hudson.cli.CLICommandInvoker.Matcher.succeeded;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
......@@ -58,8 +62,8 @@ public class GetNodeCommandTest {
;
assertThat(result.stderr(), containsString("user is missing the Slave/ExtendedRead permission"));
assertThat("No output expected", result.stdout(), isEmptyString());
assertThat("Command is expected to fail", result.returnCode(), equalTo(-1));
assertThat(result, failedWith(-1));
assertThat(result, hasNoStandardOutput());
}
@Test public void getNodeShouldYieldConfigXml() throws Exception {
......@@ -73,8 +77,8 @@ public class GetNodeCommandTest {
assertThat(result.stdout(), startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
assertThat(result.stdout(), containsString("<name>MySlave</name>"));
assertThat("No error output expected", result.stderr(), isEmptyString());
assertThat("Command is expected to succeed", result.returnCode(), equalTo(0));
assertThat(result, hasNoErrorOutput());
assertThat(result, succeeded());
}
@Test public void getNodeShouldFailIfNodeDoesNotExist() throws Exception {
......@@ -85,7 +89,7 @@ public class GetNodeCommandTest {
;
assertThat(result.stderr(), containsString("No such node 'MySlave'"));
assertThat("No output expected", result.stdout(), isEmptyString());
assertThat("Command is expected to fail", result.returnCode(), equalTo(-1));
assertThat(result, failedWith(-1));
assertThat(result, hasNoStandardOutput());
}
}
......@@ -24,9 +24,9 @@
package hudson.cli;
import static hudson.cli.CLICommandInvoker.Matcher.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.text.IsEmptyString.isEmptyString;
import static org.hamcrest.text.StringContainsInOrder.stringContainsInOrder;
import java.io.PrintStream;
......@@ -58,15 +58,15 @@ public class HelpCommandTest {
assertContainsOverviewOfMethodCommand(generalHelp);
Result result = command.invokeWithArgs(ClassCommand.NAME);
assertThat(result.returnCode(), equalTo(0));
assertThat(result.stdout(), isEmptyString());
assertThat(result, succeeded());
assertThat(result, hasNoStandardOutput());
assertContainsUsageOfClassCommand(result.stderr());
result = command.invokeWithArgs("offline-node");
assertThat(result.returnCode(), equalTo(0));
assertThat(result.stdout(), isEmptyString());
assertThat(result, succeeded());
assertThat(result, hasNoStandardOutput());
assertContainsUsageOfMethodCommand(result.stderr());
}
......
......@@ -24,10 +24,12 @@
package hudson.cli;
import static hudson.cli.CLICommandInvoker.Matcher.failedWith;
import static hudson.cli.CLICommandInvoker.Matcher.hasNoStandardOutput;
import static hudson.cli.CLICommandInvoker.Matcher.succeededSilently;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.text.IsEmptyString.isEmptyString;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
......@@ -56,8 +58,8 @@ public class SetBuildDisplayNameCommandTest {
;
assertThat(result.stderr(), containsString("Build #42 does not exist"));
assertThat("No output expected", result.stdout(), isEmptyString());
assertThat("Command is expected to fail", result.returnCode(), equalTo(-1));
assertThat(result, hasNoStandardOutput());
assertThat(result, failedWith(-1));
}
@Test public void setDescriptionSuccesfully() throws Exception {
......@@ -69,9 +71,7 @@ public class SetBuildDisplayNameCommandTest {
.invokeWithArgs("project", "1", "DisplayName")
;
assertThat("No output expected", result.stdout(), isEmptyString());
assertThat("No error output expected", result.stderr(), isEmptyString());
assertThat("Command is expected to succeed", result.returnCode(), equalTo(0));
assertThat(result, succeededSilently());
assertThat(build.getDisplayName(), equalTo("DisplayName"));
}
}
......@@ -28,7 +28,9 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.text.IsEmptyString.isEmptyString;
import static hudson.cli.CLICommandInvoker.Matcher.failedWith;
import static hudson.cli.CLICommandInvoker.Matcher.hasNoStandardOutput;
import static hudson.cli.CLICommandInvoker.Matcher.succeededSilently;
import hudson.model.Computer;
import hudson.model.Node;
import jenkins.model.Jenkins;
......@@ -59,8 +61,8 @@ public class UpdateNodeCommandTest {
;
assertThat(result.stderr(), containsString("user is missing the Slave/Configure permission"));
assertThat("No output expected", result.stdout(), isEmptyString());
assertThat("Command is expected to fail", result.returnCode(), equalTo(-1));
assertThat(result, failedWith(-1));
assertThat(result, hasNoStandardOutput());
}
@Test public void updateNodeShouldModifyNodeConfiguration() throws Exception {
......@@ -73,8 +75,7 @@ public class UpdateNodeCommandTest {
.invokeWithArgs("MySlave")
;
assertThat("No error output expected", result.stderr(), isEmptyString());
assertThat("Command is expected to succeed", result.returnCode(), equalTo(0));
assertThat(result, succeededSilently());
assertThat("A slave with old name should not exist", j.jenkins.getNode("MySlave"), nullValue());
......@@ -92,7 +93,7 @@ public class UpdateNodeCommandTest {
;
assertThat(result.stderr(), containsString("No such node 'MySlave'"));
assertThat("No output expected", result.stdout(), isEmptyString());
assertThat("Command is expected to fail", result.returnCode(), equalTo(-1));
assertThat(result, failedWith(-1));
assertThat(result, hasNoStandardOutput());
}
}
......@@ -28,6 +28,7 @@ import static hudson.cli.CLICommandInvoker.Matcher.failedWith;
import static hudson.cli.CLICommandInvoker.Matcher.hasNoStandardOutput;
import static hudson.cli.CLICommandInvoker.Matcher.hasNoErrorOutput;
import static hudson.cli.CLICommandInvoker.Matcher.succeeded;
import static hudson.cli.CLICommandInvoker.Matcher.succeededSilently;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
......@@ -77,8 +78,7 @@ public class UpdateViewCommandTest {
.invokeWithArgs("aView")
;
assertThat(result, succeeded());
assertThat(result, hasNoErrorOutput());
assertThat(result, succeededSilently());
assertThat("Update should not modify view name", j.jenkins.getView("ViewFromXML"), nullValue());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册