Fixing bad EOL assumptions based on running OS (should be based on git checkout state)

This commit is contained in:
Joakim Erdfelt 2014-04-29 15:44:00 -07:00
parent 808818281d
commit f65e40f8e7
1 changed files with 55 additions and 26 deletions

View File

@ -18,6 +18,7 @@
package org.eclipse.jetty.server.handler;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@ -25,6 +26,8 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConfiguration;
@ -48,7 +51,7 @@ import org.junit.Test;
*/
public class ResourceHandlerTest
{
private static final String LN = System.getProperty("line.separator");
private static String LN = System.getProperty("line.separator");
private static Server _server;
private static HttpConfiguration _config;
private static ServerConnector _connector;
@ -61,7 +64,8 @@ public class ResourceHandlerTest
File dir = MavenTestingUtils.getTargetFile("test-classes/simple");
File huge = new File(dir,"huge.txt");
File big = new File(dir,"big.txt");
try (OutputStream out = new FileOutputStream(huge)) {
try (OutputStream out = new FileOutputStream(huge))
{
for (int i = 0; i < 100; i++)
{
try (InputStream in = new FileInputStream(big))
@ -72,6 +76,32 @@ public class ResourceHandlerTest
}
huge.deleteOnExit();
// determine how the SCM of choice checked out the big.txt EOL
// we can't just use whatever is the OS default.
// because, for example, a windows system using git can be configured for EOL handling using
// local, remote, file lists, patterns, etc, rendering assumptions about the OS EOL choice
// wrong for unit tests.
LN = System.getProperty("line.separator");
try (BufferedReader reader = Files.newBufferedReader(big.toPath(),StandardCharsets.UTF_8))
{
// a buffer large enough to capture at least 1 EOL
char cbuf[] = new char[128];
reader.read(cbuf);
String sample = new String(cbuf);
if (sample.contains("\r\n"))
{
LN = "\r\n";
}
else if (sample.contains("\n\r"))
{
LN = "\n\r";
}
else
{
LN = "\n";
}
}
_server = new Server();
_config = new HttpConfiguration();
_config.setOutputBufferSize(2048);
@ -117,7 +147,6 @@ public class ResourceHandlerTest
Assert.assertEquals("simple text",sr.getString("/resource/simple.txt"));
}
@Test
public void testBigFile() throws Exception
{