HHH-7693 Formatting and duplicate code

This commit is contained in:
brmeyer 2012-10-22 13:34:49 -04:00
parent 0916baf2f8
commit b6763565e4
1 changed files with 91 additions and 85 deletions

View File

@ -3,7 +3,7 @@
* *
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC. * distributed under license by Red Hat Middleware LLC.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * This copyrighted material is made available to anyone wishing to use, modify,
@ -12,14 +12,14 @@
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
* *
*/ */
package org.hibernate.engine.jdbc.dialect.internal; package org.hibernate.engine.jdbc.dialect.internal;
@ -49,102 +49,108 @@ import org.junit.Test;
*/ */
public class StandardDialectResolverTest extends BaseUnitTestCase { public class StandardDialectResolverTest extends BaseUnitTestCase {
@Test @Test
public void testResolveDialectInternalForSQLServer2000() throws SQLException { public void testResolveDialectInternalForSQLServer2000()
runSQLServerDialectTest(8, SQLServerDialect.class); throws SQLException {
} runSQLServerDialectTest( 8, SQLServerDialect.class );
}
@Test @Test
public void testResolveDialectInternalForSQLServer2005() throws SQLException { public void testResolveDialectInternalForSQLServer2005()
runSQLServerDialectTest(9, SQLServer2005Dialect.class); throws SQLException {
} runSQLServerDialectTest( 9, SQLServer2005Dialect.class );
}
@Test @Test
public void testResolveDialectInternalForSQLServer2008() throws SQLException { public void testResolveDialectInternalForSQLServer2008()
runSQLServerDialectTest(10, SQLServer2008Dialect.class); throws SQLException {
} runSQLServerDialectTest( 10, SQLServer2008Dialect.class );
}
@Test @Test
public void testResolveDialectInternalForSQLServer2012() throws SQLException { public void testResolveDialectInternalForSQLServer2012()
runSQLServerDialectTest(11, SQLServer2008Dialect.class); throws SQLException {
} runSQLServerDialectTest( 11, SQLServer2008Dialect.class );
}
@Test @Test
public void testResolveDialectInternalForUnknownSQLServerVersion() throws SQLException { public void testResolveDialectInternalForUnknownSQLServerVersion()
runSQLServerDialectTest(7, SQLServerDialect.class); throws SQLException {
} runSQLServerDialectTest( 7, SQLServerDialect.class );
}
@Test @Test
public void testResolveDialectInternalForPostgres81() throws SQLException { public void testResolveDialectInternalForPostgres81()
runPostgresDialectTest(8, 1, PostgreSQL81Dialect.class); throws SQLException {
} runPostgresDialectTest( 8, 1, PostgreSQL81Dialect.class );
}
@Test @Test
public void testResolveDialectInternalForPostgres82() throws SQLException { public void testResolveDialectInternalForPostgres82()
runPostgresDialectTest(8, 2, PostgreSQL82Dialect.class); throws SQLException {
} runPostgresDialectTest( 8, 2, PostgreSQL82Dialect.class );
}
@Test @Test
public void testResolveDialectInternalForPostgres83() throws SQLException { public void testResolveDialectInternalForPostgres83() throws SQLException {
runPostgresDialectTest(8, 3, PostgreSQL82Dialect.class); runPostgresDialectTest( 8, 3, PostgreSQL82Dialect.class );
} }
@Test @Test
public void testResolveDialectInternalForPostgres84() throws SQLException { public void testResolveDialectInternalForPostgres84() throws SQLException {
runPostgresDialectTest(8, 4, PostgreSQL82Dialect.class); runPostgresDialectTest( 8, 4, PostgreSQL82Dialect.class );
} }
@Test @Test
public void testResolveDialectInternalForPostgres9() throws SQLException { public void testResolveDialectInternalForPostgres9() throws SQLException {
runPostgresDialectTest(9, 0, PostgreSQL82Dialect.class); runPostgresDialectTest( 9, 0, PostgreSQL82Dialect.class );
} }
@Test @Test
public void testResolveDialectInternalForPostgres91() throws SQLException { public void testResolveDialectInternalForPostgres91() throws SQLException {
runPostgresDialectTest(9, 1, PostgreSQL82Dialect.class); runPostgresDialectTest( 9, 1, PostgreSQL82Dialect.class );
} }
@Test @Test
public void testResolveDialectInternalForPostgres92() throws SQLException { public void testResolveDialectInternalForPostgres92() throws SQLException {
runPostgresDialectTest(9, 2, PostgreSQL82Dialect.class); 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);
Dialect dialect = new StandardDialectResolver().resolveDialect(metaData); private static void runSQLServerDialectTest(
assertNotNull("Dialect for SQL Server version " + version + " should not be null", dialect); int version, Class<? extends SQLServerDialect> expectedDialect)
assertTrue("Dialect for SQL Server version " + version + " should be " + expectedDialect.getSimpleName(), throws SQLException {
expectedDialect.isInstance(dialect)); runDialectTest( "Microsoft SQL Server", version, 0,
} expectedDialect );
}
private static void runPostgresDialectTest(int majorVersion, int minorVersion, private static void runPostgresDialectTest(
Class<? extends Dialect> expectedDialect) throws SQLException { int majorVersion, int minorVersion,
runDialectTest("PostgreSQL", majorVersion, minorVersion, expectedDialect); Class<? extends Dialect> expectedDialect) throws SQLException {
} runDialectTest( "PostgreSQL", majorVersion, minorVersion,
expectedDialect );
}
private static void runDialectTest(String productName, int majorVersion, int minorVersion, private static void runDialectTest(
Class<? extends Dialect> expectedDialect) throws SQLException { String productName, int majorVersion, int minorVersion,
DatabaseMetaData metaData = mock(DatabaseMetaData.class); Class<? extends Dialect> expectedDialect) throws SQLException {
when(metaData.getDatabaseProductName()).thenReturn(productName); DatabaseMetaData metaData = mock( DatabaseMetaData.class );
when(metaData.getDatabaseMajorVersion()).thenReturn(majorVersion); when( metaData.getDatabaseProductName() ).thenReturn( productName );
when(metaData.getDatabaseMinorVersion()).thenReturn(minorVersion); when( metaData.getDatabaseMajorVersion() ).thenReturn( majorVersion );
when( metaData.getDatabaseMinorVersion() ).thenReturn( minorVersion );
Dialect dialect = new StandardDialectResolver().resolveDialect(metaData); Dialect dialect = new StandardDialectResolver().resolveDialect(
metaData );
StringBuilder builder = new StringBuilder(productName) StringBuilder builder = new StringBuilder( productName ).append( " " )
.append(" ") .append( majorVersion );
.append(majorVersion); if ( minorVersion > 0 ) {
if (minorVersion > 0) { builder.append( "." ).append( minorVersion );
builder.append(".").append(minorVersion); }
} String dbms = builder.toString();
String dbms = builder.toString();
assertNotNull("Dialect for " + dbms + " should not be null", dialect); assertNotNull( "Dialect for " + dbms + " should not be null", dialect );
assertTrue("Dialect for " + dbms + " should be " + expectedDialect.getSimpleName(), assertTrue( "Dialect for " + dbms + " should be "
expectedDialect.isInstance(dialect)); + expectedDialect.getSimpleName(),
} expectedDialect.isInstance( dialect ) );
} }
}