Fix new line issues that were causing some tests to fail on Windows OS

This commit is contained in:
Vlad Mihalcea 2016-03-08 11:11:31 +02:00
parent 3f37fff04a
commit fe247985f2
2 changed files with 16 additions and 14 deletions

View File

@ -11,19 +11,19 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.jdbc.Work;
import org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor;
import org.hibernate.testing.AfterClassOnce;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
@ -62,7 +62,7 @@ public class MultiLineImportFileTest extends BaseCoreFunctionalTestCase {
final String multiLineText = (String) s.createSQLQuery( "SELECT text FROM test_data WHERE id = 2" )
.uniqueResult();
// "Multi-line comment line 1\n-- line 2'\n/* line 3 */"
final String expected = String.format( "Multi-line comment line 1\n-- line 2'\n/* line 3 */" );
final String expected = String.format( "Multi-line comment line 1%n-- line 2'%n/* line 3 */" );
assertEquals( "Multi-line string inserted incorrectly", expected, multiLineText );
String empty = (String) s.createSQLQuery( "SELECT text FROM test_data WHERE id = 3" ).uniqueResult();

View File

@ -29,12 +29,11 @@ import org.junit.Test;
@RequiresDialect( H2Dialect.class )
public class SchemaUpdateFormatterTest {
private static final String AFTER_FORMAT =
System.lineSeparator() +
" create table test_entity (" + System.lineSeparator() +
" field varchar(255) not null," + System.lineSeparator() +
" primary key (field)" + System.lineSeparator() +
" );" + System.lineSeparator();
private static final String AFTER_FORMAT =
"\n create table test_entity (\n" +
" field varchar(255) not null,\n" +
" primary key (field)\n" +
" );\n";
private static final String DELIMITER = ";";
@Test
@ -58,10 +57,13 @@ public class SchemaUpdateFormatterTest {
.setFormat( true )
.execute( EnumSet.of( TargetType.SCRIPT ), metadata );
Assert.assertEquals(
AFTER_FORMAT,
new String(Files.readAllBytes(output.toPath()))
);
String outputContent = new String(Files.readAllBytes(output.toPath()));
//Old Macs use \r as a new line delimiter
outputContent = outputContent.replaceAll( "\r", "\n");
//On Windows, \r\n would become \n\n, so we eliminate duplicates
outputContent = outputContent.replaceAll( "\n\n", "\n");
Assert.assertEquals( AFTER_FORMAT, outputContent );
}
finally {
StandardServiceRegistryBuilder.destroy( ssr );