提交 820c9b43 编写于 作者: S Stefan Spieker

minor test refactoring, mainly to use hamcrest matcher instead of deprecated junit assertThat

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