Improving test reliability (esp on Windows)

This commit is contained in:
Joakim Erdfelt 2017-06-29 06:43:27 -07:00
parent f297096716
commit e65d0ba0e7
5 changed files with 27 additions and 24 deletions

View File

@ -19,6 +19,12 @@
package org.eclipse.jetty.util;
import static org.hamcrest.CoreMatchers.is;
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 java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileWriter;
@ -35,12 +41,6 @@ import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class BufferUtilTest
{
@Test
@ -346,7 +346,7 @@ public class BufferUtilTest
String data="Now is the time for all good men to come to the aid of the party";
File file = File.createTempFile("test",".txt");
file.deleteOnExit();
try(FileWriter out = new FileWriter(file);)
try(FileWriter out = new FileWriter(file))
{
out.write(data);
}

View File

@ -35,7 +35,7 @@ import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.TestingDir;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
@ -166,7 +166,7 @@ public class RolloverFileOutputStreamTest
@Test
public void testFileHandling() throws Exception
{
File testDir = testingDir.getEmptyPathDir().toFile();
File testDir = MavenTestingUtils.getTargetTestingDir(RolloverFileOutputStreamTest.class.getName() + "_testFileHandling");
Path testPath = testDir.toPath();
FS.ensureEmpty(testDir);
@ -277,7 +277,7 @@ public class RolloverFileOutputStreamTest
@Test
public void testRollover() throws Exception
{
File testDir = testingDir.getEmptyPathDir().toFile();
File testDir = MavenTestingUtils.getTargetTestingDir(RolloverFileOutputStreamTest.class.getName() + "_testRollover");
FS.ensureEmpty(testDir);
TimeZone zone = toZoneId("Australia/Sydney");

View File

@ -19,14 +19,16 @@
package org.eclipse.jetty.util;
import org.eclipse.jetty.toolchain.test.JDK;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.eclipse.jetty.toolchain.test.JDK;
import org.junit.Assert;
import org.junit.Test;
public class TypeUtilTest
{
@Test
@ -129,18 +131,19 @@ public class TypeUtilTest
public void testGetLocationOfClass() throws Exception
{
Path mavenRepoPath = Paths.get( System.getProperty( "mavenRepoPath" ) );
String mavenRepo = mavenRepoPath.toFile().getPath();
String mavenRepo = mavenRepoPath.toFile().getPath().replaceAll("\\\\", "/");
// Classes from maven dependencies
Assert.assertThat(TypeUtil.getLocationOfClass(Assert.class).toASCIIString(),Matchers.containsString(mavenRepo));
assertThat(TypeUtil.getLocationOfClass(Assert.class).toASCIIString(),containsString(mavenRepo));
// Class from project dependencies
Assert.assertThat(TypeUtil.getLocationOfClass(TypeUtil.class).toASCIIString(),Matchers.containsString("/classes/"));
assertThat(TypeUtil.getLocationOfClass(TypeUtil.class).toASCIIString(),containsString("/classes/"));
// Class from JVM core
String expectedJavaBase = "/rt.jar";
if(JDK.IS_9)
expectedJavaBase = "/java.base/";
Assert.assertThat(TypeUtil.getLocationOfClass(String.class).toASCIIString(),Matchers.containsString(expectedJavaBase));
assertThat(TypeUtil.getLocationOfClass(String.class).toASCIIString(),containsString(expectedJavaBase));
}
}

View File

@ -1404,13 +1404,12 @@ public class FileSystemResourceTest
assumeTrue("Only windows supports UNC paths", OS.IS_WINDOWS);
assumeFalse("FileResource does not support this test", _class.equals(FileResource.class));
try (Resource base = newResource(URI.create("file://127.0.0.1/path")))
try (Resource base = newResource(URI.create("file:////127.0.0.1/path")))
{
Resource resource = base.addPath("WEB-INF/");
assertThat("getURI()", resource.getURI().toASCIIString(), containsString("path/WEB-INF/"));
assertThat("isAlias()", resource.isAlias(), is(true));
assertThat("getAlias()", resource.getAlias(), notNullValue());
assertThat("getAlias()", resource.getAlias().toASCIIString(), containsString("path/WEB-INF"));
assertThat("isAlias()", resource.isAlias(), is(false));
assertThat("getAlias()", resource.getAlias(), nullValue());
}
}
}

View File

@ -196,7 +196,8 @@ public class ResourceTest
File testDir = MavenTestingUtils.getTargetTestingDir(ResourceTest.class.getName());
FS.ensureEmpty(testDir);
File tmpFile = File.createTempFile("test",null,testDir);
File tmpFile = new File(testDir, "test.tmp");
FS.touch(tmpFile);
cases.addCase(new Data(tmpFile.toString(),EXISTS,!DIR));