提交 08a4f042 编写于 作者: S Stefan Spieker

minor code cleanup, simplified asserts and try with resources

上级 d5b416eb
...@@ -240,9 +240,9 @@ public class CLITest { ...@@ -240,9 +240,9 @@ public class CLITest {
WebResponse rsp = wc.goTo("cli-proxy/").getWebResponse(); WebResponse rsp = wc.goTo("cli-proxy/").getWebResponse();
assertEquals(rsp.getContentAsString(), HttpURLConnection.HTTP_MOVED_TEMP, rsp.getStatusCode()); assertEquals(rsp.getContentAsString(), HttpURLConnection.HTTP_MOVED_TEMP, rsp.getStatusCode());
assertEquals(rsp.getContentAsString(), null, rsp.getResponseHeaderValue("X-Jenkins")); assertNull(rsp.getContentAsString(), rsp.getResponseHeaderValue("X-Jenkins"));
assertEquals(rsp.getContentAsString(), null, rsp.getResponseHeaderValue("X-Jenkins-CLI-Port")); assertNull(rsp.getContentAsString(), rsp.getResponseHeaderValue("X-Jenkins-CLI-Port"));
assertEquals(rsp.getContentAsString(), null, rsp.getResponseHeaderValue("X-SSH-Endpoint")); assertNull(rsp.getContentAsString(), rsp.getResponseHeaderValue("X-SSH-Endpoint"));
for (String transport: Arrays.asList("-http", "-ssh")) { for (String transport: Arrays.asList("-http", "-ssh")) {
......
...@@ -47,11 +47,8 @@ public class BuildExecutionTest { ...@@ -47,11 +47,8 @@ public class BuildExecutionTest {
FreeStyleBuild b = r.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get()); FreeStyleBuild b = r.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get());
r.assertLogContains(Messages.Build_post_build_steps_failed(), b); r.assertLogContains(Messages.Build_post_build_steps_failed(), b);
FilePath ws = r.jenkins.getWorkspaceFor(p); FilePath ws = r.jenkins.getWorkspaceFor(p);
WorkspaceList.Lease lease = r.jenkins.toComputer().getWorkspaceList().allocate(ws); try (WorkspaceList.Lease lease = r.jenkins.toComputer().getWorkspaceList().allocate(ws)) {
try {
assertEquals(ws, lease.path); assertEquals(ws, lease.path);
} finally {
lease.close();
} }
} }
......
...@@ -26,6 +26,7 @@ package hudson.model; ...@@ -26,6 +26,7 @@ package hudson.model;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
...@@ -78,7 +79,7 @@ public class FreeStyleProjectTest { ...@@ -78,7 +79,7 @@ public class FreeStyleProjectTest {
assertEquals(1,builders.size()); assertEquals(1,builders.size());
assertEquals(Shell.class,builders.get(0).getClass()); assertEquals(Shell.class,builders.get(0).getClass());
assertEquals("echo hello",((Shell)builders.get(0)).getCommand().trim()); assertEquals("echo hello",((Shell)builders.get(0)).getCommand().trim());
assertTrue(builders.get(0)!=shell); assertNotSame(builders.get(0), shell);
} }
/** /**
...@@ -127,7 +128,7 @@ public class FreeStyleProjectTest { ...@@ -127,7 +128,7 @@ public class FreeStyleProjectTest {
assertEquals(1,builders.size()); assertEquals(1,builders.size());
assertEquals(Shell.class,builders.get(0).getClass()); assertEquals(Shell.class,builders.get(0).getClass());
assertEquals("echo hello",((Shell)builders.get(0)).getCommand().trim()); assertEquals("echo hello",((Shell)builders.get(0)).getCommand().trim());
assertTrue(builders.get(0)!=shell); assertNotSame(builders.get(0), shell);
System.out.println(project.getConfigFile().asString()); System.out.println(project.getConfigFile().asString());
} }
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
package hudson.model; package hudson.model;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import com.gargoylesoftware.htmlunit.html.DomNodeUtil; import com.gargoylesoftware.htmlunit.html.DomNodeUtil;
...@@ -65,7 +66,7 @@ public class ManagementLinkTest { ...@@ -65,7 +66,7 @@ public class ManagementLinkTest {
@Test @Issue("JENKINS-33683") @Test @Issue("JENKINS-33683")
public void invisibleLinks() throws Exception { public void invisibleLinks() throws Exception {
assertEquals(null, j.jenkins.getDynamic("and_fail_trying")); assertNull(j.jenkins.getDynamic("and_fail_trying"));
} }
@TestExtension // Intentionally hooked in all tests @TestExtension // Intentionally hooked in all tests
......
...@@ -98,7 +98,7 @@ public class ParametersAction2Test { ...@@ -98,7 +98,7 @@ public class ParametersAction2Test {
@Issue("SECURITY-170") @Issue("SECURITY-170")
public void parametersDefinitionChange() throws Exception { public void parametersDefinitionChange() throws Exception {
FreeStyleProject p = j.createFreeStyleProject(); FreeStyleProject p = j.createFreeStyleProject();
p.addProperty(new ParametersDefinitionProperty(Arrays.<ParameterDefinition>asList( p.addProperty(new ParametersDefinitionProperty(Arrays.asList(
new StringParameterDefinition("foo", "foo"), new StringParameterDefinition("foo", "foo"),
new StringParameterDefinition("bar", "bar")))); new StringParameterDefinition("bar", "bar"))));
...@@ -108,28 +108,28 @@ public class ParametersAction2Test { ...@@ -108,28 +108,28 @@ public class ParametersAction2Test {
new StringParameterValue("undef", "undef") new StringParameterValue("undef", "undef")
))); )));
assertTrue("undef parameter is not listed in getParameters", assertFalse("undef parameter is not listed in getParameters",
!hasParameterWithName(build.getAction(ParametersAction.class), "undef")); hasParameterWithName(build.getAction(ParametersAction.class), "undef"));
p.removeProperty(ParametersDefinitionProperty.class); p.removeProperty(ParametersDefinitionProperty.class);
p.addProperty(new ParametersDefinitionProperty(Arrays.<ParameterDefinition>asList( p.addProperty(new ParametersDefinitionProperty(Arrays.asList(
new StringParameterDefinition("foo", "foo"), new StringParameterDefinition("foo", "foo"),
new StringParameterDefinition("bar", "bar"), new StringParameterDefinition("bar", "bar"),
new StringParameterDefinition("undef", "undef")))); new StringParameterDefinition("undef", "undef"))));
// undef is still not listed even after being added to the job parameters definition // undef is still not listed even after being added to the job parameters definition
assertTrue("undef parameter is not listed in getParameters", assertFalse("undef parameter is not listed in getParameters",
!hasParameterWithName(build.getAction(ParametersAction.class), "undef")); hasParameterWithName(build.getAction(ParametersAction.class), "undef"));
// remove bar and undef from parameters definition // remove bar and undef from parameters definition
p.removeProperty(ParametersDefinitionProperty.class); p.removeProperty(ParametersDefinitionProperty.class);
p.addProperty(new ParametersDefinitionProperty(Arrays.<ParameterDefinition>asList( p.addProperty(new ParametersDefinitionProperty(Arrays.asList(
new StringParameterDefinition("foo", "foo")))); new StringParameterDefinition("foo", "foo"))));
assertTrue("the build still have 2 parameters", build.getAction(ParametersAction.class).getParameters().size() == 2); assertEquals("the build still have 2 parameters", 2, build.getAction(ParametersAction.class).getParameters().size());
p.removeProperty(ParametersDefinitionProperty.class); p.removeProperty(ParametersDefinitionProperty.class);
assertTrue("the build still have 2 parameters", build.getAction(ParametersAction.class).getParameters().size() == 2); assertEquals("the build still have 2 parameters", 2, build.getAction(ParametersAction.class).getParameters().size());
} }
@Test @Test
...@@ -163,13 +163,13 @@ public class ParametersAction2Test { ...@@ -163,13 +163,13 @@ public class ParametersAction2Test {
public void whitelistedParameterByOverride() throws Exception { public void whitelistedParameterByOverride() throws Exception {
FreeStyleProject p = j.createFreeStyleProject(); FreeStyleProject p = j.createFreeStyleProject();
String name = p.getFullName(); String name = p.getFullName();
p.addProperty(new ParametersDefinitionProperty(Arrays.<ParameterDefinition>asList( p.addProperty(new ParametersDefinitionProperty(Arrays.asList(
new StringParameterDefinition("foo", "foo"), new StringParameterDefinition("foo", "foo"),
new StringParameterDefinition("bar", "bar")))); new StringParameterDefinition("bar", "bar"))));
try { try {
ParametersAction action = new ParametersAction( ParametersAction action = new ParametersAction(
Arrays.<ParameterValue>asList( Arrays.asList(
new StringParameterValue("foo", "baz"), new StringParameterValue("foo", "baz"),
new StringParameterValue("bar", "bar"), new StringParameterValue("bar", "bar"),
new StringParameterValue("whitelisted1", "x"), new StringParameterValue("whitelisted1", "x"),
...@@ -185,8 +185,6 @@ public class ParametersAction2Test { ...@@ -185,8 +185,6 @@ public class ParametersAction2Test {
hasParameterWithName(build.getAction(ParametersAction.class), "whitelisted2")); hasParameterWithName(build.getAction(ParametersAction.class), "whitelisted2"));
assertFalse("whitelisted3 parameter is listed in getParameters", assertFalse("whitelisted3 parameter is listed in getParameters",
hasParameterWithName(build.getAction(ParametersAction.class), "whitelisted3")); hasParameterWithName(build.getAction(ParametersAction.class), "whitelisted3"));
p = null;
build = null;
j.jenkins.reload(); j.jenkins.reload();
//Test again after reload //Test again after reload
p = j.jenkins.getItemByFullName(name, FreeStyleProject.class); p = j.jenkins.getItemByFullName(name, FreeStyleProject.class);
...@@ -207,7 +205,7 @@ public class ParametersAction2Test { ...@@ -207,7 +205,7 @@ public class ParametersAction2Test {
public void whitelistedParameterSameAfterChange() throws Exception { public void whitelistedParameterSameAfterChange() throws Exception {
FreeStyleProject p = j.createFreeStyleProject(); FreeStyleProject p = j.createFreeStyleProject();
String name = p.getFullName(); String name = p.getFullName();
p.addProperty(new ParametersDefinitionProperty(Arrays.<ParameterDefinition>asList( p.addProperty(new ParametersDefinitionProperty(Arrays.asList(
new StringParameterDefinition("foo", "foo"), new StringParameterDefinition("foo", "foo"),
new StringParameterDefinition("bar", "bar")))); new StringParameterDefinition("bar", "bar"))));
...@@ -231,8 +229,6 @@ public class ParametersAction2Test { ...@@ -231,8 +229,6 @@ public class ParametersAction2Test {
hasParameterWithName(build.getAction(ParametersAction.class), "whitelisted4")); hasParameterWithName(build.getAction(ParametersAction.class), "whitelisted4"));
System.setProperty(ParametersAction.SAFE_PARAMETERS_SYSTEM_PROPERTY_NAME, "whitelisted3,whitelisted4"); System.setProperty(ParametersAction.SAFE_PARAMETERS_SYSTEM_PROPERTY_NAME, "whitelisted3,whitelisted4");
p = null;
build = null;
j.jenkins.reload(); j.jenkins.reload();
p = j.jenkins.getItemByFullName(name, FreeStyleProject.class); p = j.jenkins.getItemByFullName(name, FreeStyleProject.class);
build = p.getLastBuild(); build = p.getLastBuild();
...@@ -261,10 +257,10 @@ public class ParametersAction2Test { ...@@ -261,10 +257,10 @@ public class ParametersAction2Test {
new StringParameterValue("bar", "bar") new StringParameterValue("bar", "bar")
))); )));
assertTrue("foo parameter is not listed in getParameters", assertFalse("foo parameter is not listed in getParameters",
!hasParameterWithName(build.getAction(ParametersAction.class), "foo")); hasParameterWithName(build.getAction(ParametersAction.class), "foo"));
assertTrue("bar parameter is not listed in getParameters", assertFalse("bar parameter is not listed in getParameters",
!hasParameterWithName(build.getAction(ParametersAction.class), "bar")); hasParameterWithName(build.getAction(ParametersAction.class), "bar"));
} }
@Test @Test
...@@ -348,13 +344,13 @@ public class ParametersAction2Test { ...@@ -348,13 +344,13 @@ public class ParametersAction2Test {
if (expectLegacyBehavior) { if (expectLegacyBehavior) {
assertTrue("undef parameter is listed in getParameters", hasParameterWithName(pa.getParameters(), "undef")); assertTrue("undef parameter is listed in getParameters", hasParameterWithName(pa.getParameters(), "undef"));
assertTrue("undef parameter is listed in iterator", hasParameterWithName(pa, "undef")); assertTrue("undef parameter is listed in iterator", hasParameterWithName(pa, "undef"));
assertTrue("undef in environment", build.getEnvironment(listener).keySet().contains("undef")); assertTrue("undef in environment", build.getEnvironment(listener).containsKey("undef"));
assertTrue("UNDEF in environment", build.getEnvironment(listener).keySet().contains("UNDEF")); assertTrue("UNDEF in environment", build.getEnvironment(listener).containsKey("UNDEF"));
} else { } else {
assertFalse("undef parameter is not listed in getParameters", hasParameterWithName(pa.getParameters(), "undef")); assertFalse("undef parameter is not listed in getParameters", hasParameterWithName(pa.getParameters(), "undef"));
assertFalse("undef parameter is not listed in iterator", hasParameterWithName(pa, "undef")); assertFalse("undef parameter is not listed in iterator", hasParameterWithName(pa, "undef"));
assertFalse("undef not in environment", build.getEnvironment(listener).keySet().contains("undef")); assertFalse("undef not in environment", build.getEnvironment(listener).containsKey("undef"));
assertFalse("UNDEF not in environment", build.getEnvironment(listener).keySet().contains("UNDEF")); assertFalse("UNDEF not in environment", build.getEnvironment(listener).containsKey("UNDEF"));
} }
assertTrue("undef parameter is listed in getAllParameters", hasParameterWithName(pa.getAllParameters(), "undef")); assertTrue("undef parameter is listed in getAllParameters", hasParameterWithName(pa.getAllParameters(), "undef"));
......
package hudson.scm; package hudson.scm;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import hudson.Extension; import hudson.Extension;
import hudson.MarkupText; import hudson.MarkupText;
...@@ -30,7 +31,7 @@ public class ChangeLogSetTest { ...@@ -30,7 +31,7 @@ public class ChangeLogSetTest {
notCaught = true; notCaught = true;
} }
assertEquals((new EntryImpl()).getMsg(), change.getMsg()); assertEquals((new EntryImpl()).getMsg(), change.getMsg());
assertEquals(false, notCaught); assertFalse(notCaught);
} }
@Extension @Extension
......
...@@ -101,7 +101,7 @@ public class HudsonPrivateSecurityRealmTest { ...@@ -101,7 +101,7 @@ public class HudsonPrivateSecurityRealmTest {
String secure = PASSWORD_ENCODER.encodePassword("hello world", null); String secure = PASSWORD_ENCODER.encodePassword("hello world", null);
assertTrue(PASSWORD_ENCODER.isPasswordValid(old,"hello world",null)); assertTrue(PASSWORD_ENCODER.isPasswordValid(old,"hello world",null));
assertFalse(secure.equals(old)); assertNotEquals(secure, old);
} }
...@@ -284,14 +284,14 @@ public class HudsonPrivateSecurityRealmTest { ...@@ -284,14 +284,14 @@ public class HudsonPrivateSecurityRealmTest {
assertTrue(spySecurityListener.loggedInUsernames.isEmpty()); assertTrue(spySecurityListener.loggedInUsernames.isEmpty());
createFirstAccount("admin"); createFirstAccount("admin");
assertTrue(spySecurityListener.loggedInUsernames.get(0).equals("admin")); assertEquals("admin", spySecurityListener.loggedInUsernames.get(0));
createAccountByAdmin("alice"); createAccountByAdmin("alice");
// no new event in such case // no new event in such case
assertTrue(spySecurityListener.loggedInUsernames.isEmpty()); assertEquals(true, spySecurityListener.loggedInUsernames.isEmpty());
selfRegistration("bob"); selfRegistration("bob");
assertTrue(spySecurityListener.loggedInUsernames.get(0).equals("bob")); assertEquals("bob", spySecurityListener.loggedInUsernames.get(0));
} }
@Issue("JENKINS-55307") @Issue("JENKINS-55307")
...@@ -306,8 +306,8 @@ public class HudsonPrivateSecurityRealmTest { ...@@ -306,8 +306,8 @@ public class HudsonPrivateSecurityRealmTest {
selfRegistration("bob"); selfRegistration("bob");
selfRegistration("charlie"); selfRegistration("charlie");
assertTrue(spySecurityListener.createdUsers.get(0).equals("bob")); assertEquals("bob", spySecurityListener.createdUsers.get(0));
assertTrue(spySecurityListener.createdUsers.get(1).equals("charlie")); assertEquals("charlie", spySecurityListener.createdUsers.get(1));
} }
@Issue("JENKINS-55307") @Issue("JENKINS-55307")
...@@ -327,8 +327,8 @@ public class HudsonPrivateSecurityRealmTest { ...@@ -327,8 +327,8 @@ public class HudsonPrivateSecurityRealmTest {
u2.setFullName("Debbie User"); u2.setFullName("Debbie User");
u2.save(); u2.save();
assertTrue(spySecurityListener.createdUsers.get(0).equals("alice")); assertEquals("alice", spySecurityListener.createdUsers.get(0));
assertTrue(spySecurityListener.createdUsers.get(1).equals("debbie")); assertEquals("debbie", spySecurityListener.createdUsers.get(1));
} }
@Issue("JENKINS-55307") @Issue("JENKINS-55307")
...@@ -342,7 +342,7 @@ public class HudsonPrivateSecurityRealmTest { ...@@ -342,7 +342,7 @@ public class HudsonPrivateSecurityRealmTest {
securityRealm.createAccountWithHashedPassword("charlie_hashed", "#jbcrypt:" + BCrypt.hashpw("charliePassword", BCrypt.gensalt())); securityRealm.createAccountWithHashedPassword("charlie_hashed", "#jbcrypt:" + BCrypt.hashpw("charliePassword", BCrypt.gensalt()));
assertTrue(spySecurityListener.createdUsers.get(0).equals("charlie_hashed")); assertEquals("charlie_hashed", spySecurityListener.createdUsers.get(0));
} }
private void createFirstAccount(String login) throws Exception { private void createFirstAccount(String login) throws Exception {
......
...@@ -106,7 +106,6 @@ public class SecurityRealmTest { ...@@ -106,7 +106,6 @@ public class SecurityRealmTest {
calendar.add(Calendar.DAY_OF_YEAR, 1); calendar.add(Calendar.DAY_OF_YEAR, 1);
Date tomorrow = calendar.getTime(); Date tomorrow = calendar.getTime();
Collections.nCopies(8, 1) Collections.nCopies(8, 1)
.stream()
.forEach(i -> addSessionCookie(manager, LOCALHOST, "/jenkins", tomorrow)); .forEach(i -> addSessionCookie(manager, LOCALHOST, "/jenkins", tomorrow));
addSessionCookie(manager, LOCALHOST, WILL_NOT_BE_SENT, tomorrow); addSessionCookie(manager, LOCALHOST, WILL_NOT_BE_SENT, tomorrow);
......
...@@ -135,7 +135,7 @@ public class TokenBasedRememberMeServices2Test { ...@@ -135,7 +135,7 @@ public class TokenBasedRememberMeServices2Test {
wc.executeOnServer(() -> { wc.executeOnServer(() -> {
Authentication a = Jenkins.getAuthentication(); Authentication a = Jenkins.getAuthentication();
assertEquals("bob", a.getName()); assertEquals("bob", a.getName());
assertEquals(ImmutableList.of("authenticated", "myteam"), Arrays.asList(a.getAuthorities()).stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList())); assertEquals(ImmutableList.of("authenticated", "myteam"), Arrays.stream(a.getAuthorities()).map(GrantedAuthority::getAuthority).collect(Collectors.toList()));
return null; return null;
}); });
} }
......
...@@ -262,8 +262,8 @@ public class FingerprinterTest { ...@@ -262,8 +262,8 @@ public class FingerprinterTest {
fingerprints = action.getFingerprints().values(); fingerprints = action.getFingerprints().values();
for (Fingerprint f: fingerprints) { for (Fingerprint f: fingerprints) {
assertTrue(f.getOriginal().is(upstream)); assertTrue(f.getOriginal().is(upstream));
assertTrue(f.getOriginal().getName().equals(renamedProject1)); assertEquals(f.getOriginal().getName(), renamedProject1);
assertFalse(f.getOriginal().getName().equals(oldUpstreamName)); assertNotEquals(f.getOriginal().getName(), oldUpstreamName);
} }
// Verify that usage entry in fingerprint record is changed after // Verify that usage entry in fingerprint record is changed after
......
...@@ -360,7 +360,7 @@ public class MavenTest { ...@@ -360,7 +360,7 @@ public class MavenTest {
MavenInstallation maven = ToolInstallations.configureMaven3(); MavenInstallation maven = ToolInstallations.configureMaven3();
MavenInstallation maven2 = ToolInstallations.configureMaven3(); MavenInstallation maven2 = ToolInstallations.configureMaven3();
assertEquals(maven.hashCode(), maven2.hashCode()); assertEquals(maven.hashCode(), maven2.hashCode());
assertTrue(maven.equals(maven2)); assertEquals(maven, maven2);
} }
@Issue("JENKINS-34138") @Issue("JENKINS-34138")
...@@ -368,6 +368,6 @@ public class MavenTest { ...@@ -368,6 +368,6 @@ public class MavenTest {
MavenInstallation maven3 = ToolInstallations.configureMaven3(); MavenInstallation maven3 = ToolInstallations.configureMaven3();
MavenInstallation maven2 = ToolInstallations.configureDefaultMaven(); MavenInstallation maven2 = ToolInstallations.configureDefaultMaven();
assertNotEquals(maven3.hashCode(), maven2.hashCode()); assertNotEquals(maven3.hashCode(), maven2.hashCode());
assertFalse(maven3.equals(maven2)); assertNotEquals(maven3, maven2);
} }
} }
...@@ -35,6 +35,8 @@ import java.util.TreeMap; ...@@ -35,6 +35,8 @@ import java.util.TreeMap;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import static jenkins.model.ModelObjectWithContextMenu.*; import static jenkins.model.ModelObjectWithContextMenu.*;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.jvnet.hudson.test.Issue; import org.jvnet.hudson.test.Issue;
...@@ -64,7 +66,7 @@ public class ContextMenuTest { ...@@ -64,7 +66,7 @@ public class ContextMenuTest {
f.visible = false; f.visible = false;
menu = j.executeOnServer(doContextMenu); menu = j.executeOnServer(doContextMenu);
parsed = parse(menu); parsed = parse(menu);
assertEquals(parsed.toString(), null, parsed.get("testing")); assertNull(parsed.toString(), parsed.get("testing"));
} }
@TestExtension public static class ActionFactory extends TransientProjectActionFactory { @TestExtension public static class ActionFactory extends TransientProjectActionFactory {
......
...@@ -25,7 +25,6 @@ import java.util.Arrays; ...@@ -25,7 +25,6 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
...@@ -287,9 +286,8 @@ public class JenkinsBuildsAndWorkspacesDirectoriesTest { ...@@ -287,9 +286,8 @@ public class JenkinsBuildsAndWorkspacesDirectoriesTest {
private boolean logWasFoundAtLevel(String searched, Level level) { private boolean logWasFoundAtLevel(String searched, Level level) {
return loggerRule.getRecords().stream() return loggerRule.getRecords().stream()
.filter(record -> record.getMessage().contains(searched)) .filter(record -> record.getMessage().contains(searched))
.filter(record -> record.getLevel().equals(level)) .filter(record -> record.getLevel().equals(level)).count() > 0;
.collect(Collectors.toList()).size() > 0;
} }
@Test @Test
......
...@@ -383,7 +383,7 @@ public class JenkinsTest { ...@@ -383,7 +383,7 @@ public class JenkinsTest {
} }
public HttpResponse doDynamic() { public HttpResponse doDynamic() {
assertTrue(Jenkins.get().getAuthentication().getName().equals("anonymous")); assertEquals("anonymous", Jenkins.get().getAuthentication().getName());
count++; count++;
return HttpResponses.html("OK"); return HttpResponses.html("OK");
} }
...@@ -411,7 +411,7 @@ public class JenkinsTest { ...@@ -411,7 +411,7 @@ public class JenkinsTest {
j.jenkins.setAuthorizationStrategy(auth); j.jenkins.setAuthorizationStrategy(auth);
// no anonymous read access // no anonymous read access
assertTrue(!Jenkins.get().hasPermission(Jenkins.ANONYMOUS, Jenkins.READ)); assertFalse(Jenkins.get().hasPermission(Jenkins.ANONYMOUS, Jenkins.READ));
WebClient wc = j.createWebClient() WebClient wc = j.createWebClient()
.withThrowExceptionOnFailingStatusCode(false); .withThrowExceptionOnFailingStatusCode(false);
......
package jenkins.model; package jenkins.model;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertEquals;
import hudson.model.Node.Mode; import hudson.model.Node.Mode;
...@@ -17,8 +17,8 @@ public class MasterBuildConfigurationTest { ...@@ -17,8 +17,8 @@ public class MasterBuildConfigurationTest {
@Issue("JENKINS-23966") @Issue("JENKINS-23966")
public void retainMasterLabelWhenNoSlaveDefined() throws Exception { public void retainMasterLabelWhenNoSlaveDefined() throws Exception {
Jenkins jenkins = j.getInstance(); Jenkins jenkins = j.getInstance();
assertTrue("Test is for master with no slave", jenkins.getComputers().length == 1); assertEquals("Test is for master with no slave", 1, jenkins.getComputers().length);
// set our own label & mode // set our own label & mode
final String myTestLabel = "TestLabelx0123"; final String myTestLabel = "TestLabelx0123";
...@@ -29,7 +29,7 @@ public class MasterBuildConfigurationTest { ...@@ -29,7 +29,7 @@ public class MasterBuildConfigurationTest {
j.configRoundtrip(); j.configRoundtrip();
// make sure settings were not lost // make sure settings were not lost
assertTrue("Master's label is lost", myTestLabel.equals(jenkins.getLabelString())); assertEquals("Master's label is lost", myTestLabel, jenkins.getLabelString());
assertTrue("Master's mode is lost", Mode.EXCLUSIVE.equals(jenkins.getMode())); assertEquals("Master's mode is lost", Mode.EXCLUSIVE, jenkins.getMode());
} }
} }
...@@ -48,8 +48,8 @@ public class LazyBuildMixInTest { ...@@ -48,8 +48,8 @@ public class LazyBuildMixInTest {
FreeStyleBuild b3 = r.buildAndAssertSuccess(p); FreeStyleBuild b3 = r.buildAndAssertSuccess(p);
assertEquals(b2, b1.getNextBuild()); assertEquals(b2, b1.getNextBuild());
assertEquals(b3, b2.getNextBuild()); assertEquals(b3, b2.getNextBuild());
assertEquals(null, b3.getNextBuild()); assertNull(b3.getNextBuild());
assertEquals(null, b1.getPreviousBuild()); assertNull(b1.getPreviousBuild());
assertEquals(b1, b2.getPreviousBuild()); assertEquals(b1, b2.getPreviousBuild());
assertEquals(b2, b3.getPreviousBuild()); assertEquals(b2, b3.getPreviousBuild());
b1.getRunMixIn().createReference().clear(); b1.getRunMixIn().createReference().clear();
...@@ -70,8 +70,8 @@ public class LazyBuildMixInTest { ...@@ -70,8 +70,8 @@ public class LazyBuildMixInTest {
FreeStyleBuild b3 = r.buildAndAssertSuccess(p); FreeStyleBuild b3 = r.buildAndAssertSuccess(p);
assertEquals(b2, b1.getNextBuild()); assertEquals(b2, b1.getNextBuild());
assertEquals(b3, b2.getNextBuild()); assertEquals(b3, b2.getNextBuild());
assertEquals(null, b3.getNextBuild()); assertNull(b3.getNextBuild());
assertEquals(null, b1.getPreviousBuild()); assertNull(b1.getPreviousBuild());
assertEquals(b1, b2.getPreviousBuild()); assertEquals(b1, b2.getPreviousBuild());
assertEquals(b2, b3.getPreviousBuild()); assertEquals(b2, b3.getPreviousBuild());
b2.delete(); b2.delete();
......
...@@ -63,11 +63,8 @@ public class FilePathSecureTest { ...@@ -63,11 +63,8 @@ public class FilePathSecureTest {
dir.mkdirs(); dir.mkdirs();
dir.child("stuff").write("hello", null); dir.child("stuff").write("hello", null);
FilePath tar = root.child("dir.tar"); FilePath tar = root.child("dir.tar");
OutputStream os = tar.write(); try (OutputStream os = tar.write()) {
try {
dir.tar(os, new DirScanner.Full()); dir.tar(os, new DirScanner.Full());
} finally {
os.close();
} }
tar.untar(remote, FilePath.TarCompression.NONE); tar.untar(remote, FilePath.TarCompression.NONE);
assertEquals("hello", remote.child("dir/stuff").readToString()); assertEquals("hello", remote.child("dir/stuff").readToString());
...@@ -88,11 +85,8 @@ public class FilePathSecureTest { ...@@ -88,11 +85,8 @@ public class FilePathSecureTest {
dir.mkdirs(); dir.mkdirs();
dir.child("stuff").write("hello", null); dir.child("stuff").write("hello", null);
FilePath tar = root.child("dir.tar"); FilePath tar = root.child("dir.tar");
OutputStream os = tar.write(); try (OutputStream os = tar.write()) {
try {
dir.tar(os, new DirScanner.Full()); dir.tar(os, new DirScanner.Full());
} finally {
os.close();
} }
tar.untar(root, FilePath.TarCompression.NONE); tar.untar(root, FilePath.TarCompression.NONE);
assertEquals("hello", remote.child("dir/stuff").readToString()); assertEquals("hello", remote.child("dir/stuff").readToString());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册