Fix new line issues that were causing some tests to fail on Windows OS
This commit is contained in:
parent
3f37fff04a
commit
fe247985f2
|
@ -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();
|
||||||
|
|
|
@ -30,11 +30,10 @@ import org.junit.Test;
|
||||||
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 );
|
||||||
|
|
Loading…
Reference in New Issue