提交 2a4cebb4 编写于 作者: S Stefan Spieker

minor improvements to unit tests

上级 58ac3a0f
......@@ -25,6 +25,7 @@
package hudson;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import org.apache.tools.ant.filters.StringInputStream;
import org.junit.Test;
......@@ -145,7 +146,7 @@ public class PluginManagerTest {
File newFolder = tmp.newFolder("myJar");
String manifestPath = "META-INF/MANIFEST.MF";
new File("META-INF").mkdir();
FileUtils.write(new File(newFolder, manifestPath), SAMPLE_MANIFEST_FILE);
FileUtils.write(new File(newFolder, manifestPath), SAMPLE_MANIFEST_FILE, StandardCharsets.UTF_8);
final File f = new File(tmp.getRoot(), "my.hpi");
try(ZipOutputStream out = new ZipOutputStream(Files.newOutputStream(f.toPath()))) {
......
......@@ -66,7 +66,7 @@ public class ConsistentHashTest {
assertEquals(z,x);
all.add(itr.next());
all.add(itr.next());
assertTrue(!itr.hasNext());
assertFalse(itr.hasNext());
assertEquals(3,all.size());
}
......
......@@ -39,7 +39,6 @@ import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.SortedMap;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicInteger;
......@@ -201,7 +200,7 @@ public class AbstractLazyLoadRunMapTest {
final FakeMap m = localExpiredBuilder.add(1).add(2).make();
// force index creation
m.entrySet();
assertEquals(2, m.entrySet().size());
m.search(1, Direction.EXACT).asserts(1);
assertNull(m.search(3, Direction.EXACT));
......@@ -259,10 +258,9 @@ public class AbstractLazyLoadRunMapTest {
@Test
public void identity() {
assertTrue(a.equals(a));
assertTrue(!a.equals(b));
a.hashCode();
b.hashCode();
assertEquals(a, a);
assertNotEquals(a, b);
assertNotEquals(a.hashCode(), b.hashCode());
}
@Issue("JENKINS-15439")
......@@ -285,7 +283,7 @@ public class AbstractLazyLoadRunMapTest {
}
@Issue("JENKINS-18065")
@Test public void all() throws Exception {
@Test public void all() {
assertEquals("[]", a.getLoadedBuilds().keySet().toString());
Set<Map.Entry<Integer,Build>> entries = a.entrySet();
assertEquals("[]", a.getLoadedBuilds().keySet().toString());
......@@ -399,18 +397,8 @@ public class AbstractLazyLoadRunMapTest {
slowBuilderLoadCount.put(i, new AtomicInteger());
}
final FakeMap m = slowBuilder.make();
Future<Build> firstLoad = Timer.get().submit(new Callable<Build>() {
@Override
public Build call() throws Exception {
return m.getByNumber(2);
}
});
Future<Build> secondLoad = Timer.get().submit(new Callable<Build>() {
@Override
public Build call() throws Exception {
return m.getByNumber(2);
}
});
Future<Build> firstLoad = Timer.get().submit(() -> m.getByNumber(2));
Future<Build> secondLoad = Timer.get().submit(() -> m.getByNumber(2));
slowBuilderStartSemaphores.get(2).acquire(1);
// now one of them is inside retrieve(…); the other is waiting for the lock
slowBuilderEndSemaphores.get(2).release(2); // allow both to proceed
......
......@@ -6,6 +6,7 @@ import org.apache.commons.io.IOUtils;
import org.junit.Test;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.stream.Collectors;
......@@ -29,12 +30,10 @@ public class DetachedPluginsUtilTest {
final List<DetachedPluginsUtil.DetachedPlugin> detachedPlugins = DetachedPluginsUtil.getDetachedPlugins();
if (JavaUtils.isRunningWithJava8OrBelow()) {
assertEquals(0, detachedPlugins.stream()
.filter(plugin -> plugin.getShortName().equals("jaxb"))
.collect(Collectors.toList()).size());
.filter(plugin -> plugin.getShortName().equals("jaxb")).count());
} else if (JavaUtils.getCurrentJavaRuntimeVersionNumber().isNewerThanOrEqualTo(new VersionNumber("11.0.2"))) {
assertEquals(1, detachedPlugins.stream()
.filter(plugin -> plugin.getShortName().equals("jaxb"))
.collect(Collectors.toList()).size());
.filter(plugin -> plugin.getShortName().equals("jaxb")).count());
final List<DetachedPluginsUtil.DetachedPlugin> detachedPluginsSince2_161 =
DetachedPluginsUtil.getDetachedPlugins(new VersionNumber("2.161"));
......@@ -49,8 +48,8 @@ public class DetachedPluginsUtilTest {
*/
@Test
public void checkSplitPluginsFileFormat() throws IOException {
final List<String> splitPluginsLines = IOUtils.readLines(getClass().getResourceAsStream("/jenkins/split-plugins.txt"));
assertTrue(!splitPluginsLines.isEmpty());
final List<String> splitPluginsLines = IOUtils.readLines(getClass().getResourceAsStream("/jenkins/split-plugins.txt"), StandardCharsets.UTF_8);
assertFalse(splitPluginsLines.isEmpty());
// File is not only comments
final List<String> linesWithoutComments = splitPluginsLines.stream()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册