未验证 提交 71e37fcc 编写于 作者: R Raihaan Shouhell 提交者: GitHub

Merge pull request #4671 from StefanSpieker/test_hamcrest

Test refactoring, mainly to use hamcrest matcher instead of deprecated junit assertThat
...@@ -54,7 +54,13 @@ import java.util.zip.ZipEntry; ...@@ -54,7 +54,13 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeFalse; import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue; import static org.junit.Assume.assumeTrue;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
...@@ -293,7 +299,7 @@ public class FilePathTest { ...@@ -293,7 +299,7 @@ public class FilePathTest {
} }
@Issue("JENKINS-6494") @Issue("JENKINS-6494")
@Test public void getParent() throws Exception { @Test public void getParent() {
FilePath fp = new FilePath((VirtualChannel)null, "/abc/def"); FilePath fp = new FilePath((VirtualChannel)null, "/abc/def");
assertEquals("/abc", (fp = fp.getParent()).getRemote()); assertEquals("/abc", (fp = fp.getParent()).getRemote());
assertEquals("/", (fp = fp.getParent()).getRemote()); assertEquals("/", (fp = fp.getParent()).getRemote());
...@@ -491,7 +497,7 @@ public class FilePathTest { ...@@ -491,7 +497,7 @@ public class FilePathTest {
} }
@Issue("JENKINS-13649") @Issue("JENKINS-13649")
@Test public void multiSegmentRelativePaths() throws Exception { @Test public void multiSegmentRelativePaths() {
VirtualChannel d = Mockito.mock(VirtualChannel.class); VirtualChannel d = Mockito.mock(VirtualChannel.class);
FilePath winPath = new FilePath(d, "c:\\app\\jenkins\\workspace"); FilePath winPath = new FilePath(d, "c:\\app\\jenkins\\workspace");
FilePath nixPath = new FilePath(d, "/opt/jenkins/workspace"); FilePath nixPath = new FilePath(d, "/opt/jenkins/workspace");
......
...@@ -23,8 +23,12 @@ ...@@ -23,8 +23,12 @@
*/ */
package hudson.util; package hudson.util;
import static org.junit.Assert.*; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
......
...@@ -22,9 +22,9 @@ import java.util.Set; ...@@ -22,9 +22,9 @@ import java.util.Set;
import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.core.Is.is; import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.StringContains.containsString; import static org.hamcrest.core.StringContains.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
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.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.junit.Assume.assumeThat; import static org.junit.Assume.assumeThat;
...@@ -86,7 +86,7 @@ public class AtomicFileWriterTest { ...@@ -86,7 +86,7 @@ public class AtomicFileWriterTest {
} }
@Test @Test
public void createFile() throws Exception { public void createFile() {
// Verify the file we created exists // Verify the file we created exists
assertTrue(Files.exists(afw.getTemporaryPath())); assertTrue(Files.exists(afw.getTemporaryPath()));
} }
...@@ -163,7 +163,7 @@ public class AtomicFileWriterTest { ...@@ -163,7 +163,7 @@ public class AtomicFileWriterTest {
@Issue("JENKINS-48407") @Issue("JENKINS-48407")
@Test @Test
public void checkPermissionsRespectUmask() throws IOException, InterruptedException { public void checkPermissionsRespectUmask() throws IOException {
final File newFile = tmp.newFile(); final File newFile = tmp.newFile();
boolean posixSupported = isPosixSupported(newFile); boolean posixSupported = isPosixSupported(newFile);
......
...@@ -13,7 +13,7 @@ import java.nio.charset.StandardCharsets; ...@@ -13,7 +13,7 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.StandardOpenOption; import java.nio.file.StandardOpenOption;
import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
public class FileChannelWriterTest { public class FileChannelWriterTest {
......
...@@ -32,7 +32,7 @@ import java.util.stream.Collectors; ...@@ -32,7 +32,7 @@ import java.util.stream.Collectors;
import jenkins.util.MemoryReductionUtil; import jenkins.util.MemoryReductionUtil;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Test; import org.junit.Test;
import org.jvnet.hudson.test.For; import org.jvnet.hudson.test.For;
......
...@@ -7,7 +7,11 @@ import java.nio.charset.Charset; ...@@ -7,7 +7,11 @@ import java.nio.charset.Charset;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*; import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
......
...@@ -52,10 +52,10 @@ import java.util.UUID; ...@@ -52,10 +52,10 @@ import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest(ApiTokenPropertyConfiguration.class) @PrepareForTest(ApiTokenPropertyConfiguration.class)
...@@ -108,6 +108,7 @@ public class ApiTokenStatsTest { ...@@ -108,6 +108,7 @@ public class ApiTokenStatsTest {
lastUsage = stats.getLastUseDate(); lastUsage = stats.getLastUseDate();
assertNotNull(lastUsage); assertNotNull(lastUsage);
// to avoid flaky test in case the test is run at midnight, normally it's 0 // to avoid flaky test in case the test is run at midnight, normally it's 0
assertThat(stats.getNumDaysUse(), lessThanOrEqualTo(1L)); assertThat(stats.getNumDaysUse(), lessThanOrEqualTo(1L));
} }
...@@ -164,7 +165,7 @@ public class ApiTokenStatsTest { ...@@ -164,7 +165,7 @@ public class ApiTokenStatsTest {
} }
@Test @Test
public void testResilientIfFileDoesNotExist() throws Exception { public void testResilientIfFileDoesNotExist() {
ApiTokenStats tokenStats = createFromFile(tmp.getRoot()); ApiTokenStats tokenStats = createFromFile(tmp.getRoot());
assertNotNull(tokenStats); assertNotNull(tokenStats);
} }
...@@ -193,7 +194,7 @@ public class ApiTokenStatsTest { ...@@ -193,7 +194,7 @@ public class ApiTokenStatsTest {
String content = FileUtils.readFileToString(statsFile.getFile(), Charset.defaultCharset()); String content = FileUtils.readFileToString(statsFile.getFile(), Charset.defaultCharset());
// now there are multiple times the same id in the file with different stats // now there are multiple times the same id in the file with different stats
String newContentWithDuplicatedId = content.replace(ID_1, ID_2).replace(ID_3, ID_2); String newContentWithDuplicatedId = content.replace(ID_1, ID_2).replace(ID_3, ID_2);
FileUtils.write(statsFile.getFile(), newContentWithDuplicatedId); FileUtils.write(statsFile.getFile(), newContentWithDuplicatedId, Charset.defaultCharset());
} }
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册