HHH-7693 Formatting and duplicate code
This commit is contained in:
parent
1333725bcf
commit
5e158e8861
|
@ -43,107 +43,113 @@ import org.junit.Test;
|
|||
|
||||
/**
|
||||
* Unit test of the {@link StandardDialectResolver} class.
|
||||
*
|
||||
*
|
||||
* @author Bryan Turner
|
||||
*/
|
||||
public class StandardDialectResolverTest extends BaseUnitTestCase {
|
||||
|
||||
@Test
|
||||
public void testResolveDialectInternalForSQLServer2000() throws SQLException {
|
||||
runSQLServerDialectTest(8, SQLServerDialect.class);
|
||||
}
|
||||
@Test
|
||||
public void testResolveDialectInternalForSQLServer2000()
|
||||
throws SQLException {
|
||||
runSQLServerDialectTest( 8, SQLServerDialect.class );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveDialectInternalForSQLServer2005() throws SQLException {
|
||||
runSQLServerDialectTest(9, SQLServer2005Dialect.class);
|
||||
}
|
||||
@Test
|
||||
public void testResolveDialectInternalForSQLServer2005()
|
||||
throws SQLException {
|
||||
runSQLServerDialectTest( 9, SQLServer2005Dialect.class );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveDialectInternalForSQLServer2008() throws SQLException {
|
||||
runSQLServerDialectTest(10, SQLServer2008Dialect.class);
|
||||
}
|
||||
@Test
|
||||
public void testResolveDialectInternalForSQLServer2008()
|
||||
throws SQLException {
|
||||
runSQLServerDialectTest( 10, SQLServer2008Dialect.class );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveDialectInternalForSQLServer2012() throws SQLException {
|
||||
runSQLServerDialectTest(11, SQLServer2008Dialect.class);
|
||||
}
|
||||
@Test
|
||||
public void testResolveDialectInternalForSQLServer2012()
|
||||
throws SQLException {
|
||||
runSQLServerDialectTest( 11, SQLServer2008Dialect.class );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveDialectInternalForUnknownSQLServerVersion() throws SQLException {
|
||||
runSQLServerDialectTest(7, SQLServerDialect.class);
|
||||
}
|
||||
@Test
|
||||
public void testResolveDialectInternalForUnknownSQLServerVersion()
|
||||
throws SQLException {
|
||||
runSQLServerDialectTest( 7, SQLServerDialect.class );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveDialectInternalForPostgres81() throws SQLException {
|
||||
runPostgresDialectTest(8, 1, PostgreSQL81Dialect.class);
|
||||
}
|
||||
@Test
|
||||
public void testResolveDialectInternalForPostgres81()
|
||||
throws SQLException {
|
||||
runPostgresDialectTest( 8, 1, PostgreSQL81Dialect.class );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveDialectInternalForPostgres82() throws SQLException {
|
||||
runPostgresDialectTest(8, 2, PostgreSQL82Dialect.class);
|
||||
}
|
||||
@Test
|
||||
public void testResolveDialectInternalForPostgres82()
|
||||
throws SQLException {
|
||||
runPostgresDialectTest( 8, 2, PostgreSQL82Dialect.class );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveDialectInternalForPostgres83() throws SQLException {
|
||||
runPostgresDialectTest(8, 3, PostgreSQL82Dialect.class);
|
||||
}
|
||||
@Test
|
||||
public void testResolveDialectInternalForPostgres83() throws SQLException {
|
||||
runPostgresDialectTest( 8, 3, PostgreSQL82Dialect.class );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveDialectInternalForPostgres84() throws SQLException {
|
||||
runPostgresDialectTest(8, 4, PostgreSQL82Dialect.class);
|
||||
}
|
||||
@Test
|
||||
public void testResolveDialectInternalForPostgres84() throws SQLException {
|
||||
runPostgresDialectTest( 8, 4, PostgreSQL82Dialect.class );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveDialectInternalForPostgres9() throws SQLException {
|
||||
runPostgresDialectTest(9, 0, PostgreSQL82Dialect.class);
|
||||
}
|
||||
@Test
|
||||
public void testResolveDialectInternalForPostgres9() throws SQLException {
|
||||
runPostgresDialectTest( 9, 0, PostgreSQL82Dialect.class );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveDialectInternalForPostgres91() throws SQLException {
|
||||
runPostgresDialectTest(9, 1, PostgreSQL82Dialect.class);
|
||||
}
|
||||
@Test
|
||||
public void testResolveDialectInternalForPostgres91() throws SQLException {
|
||||
runPostgresDialectTest( 9, 1, PostgreSQL82Dialect.class );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResolveDialectInternalForPostgres92() throws SQLException {
|
||||
runPostgresDialectTest(9, 2, PostgreSQL82Dialect.class);
|
||||
}
|
||||
|
||||
private static void runSQLServerDialectTest(int version, Class<? extends SQLServerDialect> expectedDialect)
|
||||
throws SQLException {
|
||||
DatabaseMetaData metaData = mock(DatabaseMetaData.class);
|
||||
when(metaData.getDatabaseProductName()).thenReturn("Microsoft SQL Server");
|
||||
when(metaData.getDatabaseMajorVersion()).thenReturn(version);
|
||||
@Test
|
||||
public void testResolveDialectInternalForPostgres92() throws SQLException {
|
||||
runPostgresDialectTest( 9, 2, PostgreSQL82Dialect.class );
|
||||
}
|
||||
|
||||
Dialect dialect = new StandardDialectResolver().resolveDialectInternal(metaData);
|
||||
assertNotNull("Dialect for SQL Server version " + version + " should not be null", dialect);
|
||||
assertTrue("Dialect for SQL Server version " + version + " should be " + expectedDialect.getSimpleName(),
|
||||
expectedDialect.isInstance(dialect));
|
||||
}
|
||||
private static void runSQLServerDialectTest(
|
||||
int version, Class<? extends SQLServerDialect> expectedDialect)
|
||||
throws SQLException {
|
||||
runDialectTest( "Microsoft SQL Server", version, 0,
|
||||
expectedDialect );
|
||||
}
|
||||
|
||||
private static void runPostgresDialectTest(int majorVersion, int minorVersion,
|
||||
Class<? extends Dialect> expectedDialect) throws SQLException {
|
||||
runDialectTest("PostgreSQL", majorVersion, minorVersion, expectedDialect);
|
||||
}
|
||||
private static void runPostgresDialectTest(
|
||||
int majorVersion, int minorVersion,
|
||||
Class<? extends Dialect> expectedDialect) throws SQLException {
|
||||
runDialectTest( "PostgreSQL", majorVersion, minorVersion,
|
||||
expectedDialect );
|
||||
}
|
||||
|
||||
private static void runDialectTest(String productName, int majorVersion, int minorVersion,
|
||||
Class<? extends Dialect> expectedDialect) throws SQLException {
|
||||
DatabaseMetaData metaData = mock(DatabaseMetaData.class);
|
||||
when(metaData.getDatabaseProductName()).thenReturn(productName);
|
||||
when(metaData.getDatabaseMajorVersion()).thenReturn(majorVersion);
|
||||
when(metaData.getDatabaseMinorVersion()).thenReturn(minorVersion);
|
||||
private static void runDialectTest(
|
||||
String productName, int majorVersion, int minorVersion,
|
||||
Class<? extends Dialect> expectedDialect) throws SQLException {
|
||||
DatabaseMetaData metaData = mock( DatabaseMetaData.class );
|
||||
when( metaData.getDatabaseProductName() ).thenReturn( productName );
|
||||
when( metaData.getDatabaseMajorVersion() ).thenReturn( majorVersion );
|
||||
when( metaData.getDatabaseMinorVersion() ).thenReturn( minorVersion );
|
||||
|
||||
Dialect dialect = new StandardDialectResolver().resolveDialectInternal(metaData);
|
||||
Dialect dialect = new StandardDialectResolver().resolveDialectInternal(
|
||||
metaData );
|
||||
|
||||
StringBuilder builder = new StringBuilder(productName)
|
||||
.append(" ")
|
||||
.append(majorVersion);
|
||||
if (minorVersion > 0) {
|
||||
builder.append(".").append(minorVersion);
|
||||
}
|
||||
String dbms = builder.toString();
|
||||
StringBuilder builder = new StringBuilder( productName ).append( " " )
|
||||
.append( majorVersion );
|
||||
if ( minorVersion > 0 ) {
|
||||
builder.append( "." ).append( minorVersion );
|
||||
}
|
||||
String dbms = builder.toString();
|
||||
|
||||
assertNotNull("Dialect for " + dbms + " should not be null", dialect);
|
||||
assertTrue("Dialect for " + dbms + " should be " + expectedDialect.getSimpleName(),
|
||||
expectedDialect.isInstance(dialect));
|
||||
}
|
||||
assertNotNull( "Dialect for " + dbms + " should not be null", dialect );
|
||||
assertTrue( "Dialect for " + dbms + " should be "
|
||||
+ expectedDialect.getSimpleName(),
|
||||
expectedDialect.isInstance( dialect ) );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue