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.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
import org.junit.Test;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment; import org.hibernate.cfg.Environment;
import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.H2Dialect;
import org.hibernate.jdbc.Work; import org.hibernate.jdbc.Work;
import org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor;
import org.hibernate.testing.AfterClassOnce; import org.hibernate.testing.AfterClassOnce;
import org.hibernate.testing.RequiresDialect; import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; 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.assertEquals;
import static org.junit.Assert.assertNull; 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" ) final String multiLineText = (String) s.createSQLQuery( "SELECT text FROM test_data WHERE id = 2" )
.uniqueResult(); .uniqueResult();
// "Multi-line comment line 1\n-- line 2'\n/* line 3 */" // "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 ); assertEquals( "Multi-line string inserted incorrectly", expected, multiLineText );
String empty = (String) s.createSQLQuery( "SELECT text FROM test_data WHERE id = 3" ).uniqueResult(); 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 ) @RequiresDialect( H2Dialect.class )
public class SchemaUpdateFormatterTest { public class SchemaUpdateFormatterTest {
private static final String AFTER_FORMAT = private static final String AFTER_FORMAT =
System.lineSeparator() + "\n create table test_entity (\n" +
" create table test_entity (" + System.lineSeparator() + " field varchar(255) not null,\n" +
" field varchar(255) not null," + System.lineSeparator() + " primary key (field)\n" +
" primary key (field)" + System.lineSeparator() + " );\n";
" );" + System.lineSeparator();
private static final String DELIMITER = ";"; private static final String DELIMITER = ";";
@Test @Test
@ -58,10 +57,13 @@ public class SchemaUpdateFormatterTest {
.setFormat( true ) .setFormat( true )
.execute( EnumSet.of( TargetType.SCRIPT ), metadata ); .execute( EnumSet.of( TargetType.SCRIPT ), metadata );
Assert.assertEquals( String outputContent = new String(Files.readAllBytes(output.toPath()));
AFTER_FORMAT, //Old Macs use \r as a new line delimiter
new String(Files.readAllBytes(output.toPath())) 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 { finally {
StandardServiceRegistryBuilder.destroy( ssr ); StandardServiceRegistryBuilder.destroy( ssr );