HHH-13379 Enhance date/time tests to allow testing certain values only when forcing the JDBC timezone

This commit is contained in:
Yoann Rodière 2019-07-26 10:10:08 +02:00 committed by gbadner
parent 65fa9cb1e7
commit de8e965cc8
1 changed files with 28 additions and 12 deletions

View File

@ -243,6 +243,8 @@ abstract class AbstractJavaTimeTypeTest<T, E> extends BaseCoreFunctionalTestCase
private final List<Class<? extends AbstractRemappingH2Dialect>> remappingDialectClasses = new ArrayList<>(); private final List<Class<? extends AbstractRemappingH2Dialect>> remappingDialectClasses = new ArrayList<>();
private ZoneId forcedJdbcTimeZone = null;
protected AbstractParametersBuilder() { protected AbstractParametersBuilder() {
dialect = determineDialect(); dialect = determineDialect();
remappingDialectClasses.add( null ); // Always test without remapping remappingDialectClasses.add( null ); // Always test without remapping
@ -261,6 +263,18 @@ abstract class AbstractJavaTimeTypeTest<T, E> extends BaseCoreFunctionalTestCase
return thisAsS(); return thisAsS();
} }
public S withForcedJdbcTimezone(String zoneIdString, Consumer<S> contributor) {
ZoneId zoneId = ZoneId.of( zoneIdString );
this.forcedJdbcTimeZone = zoneId;
try {
contributor.accept( thisAsS() );
}
finally {
this.forcedJdbcTimeZone = null;
}
return thisAsS();
}
@SafeVarargs @SafeVarargs
public final S alsoTestRemappingsWithH2(Class<? extends AbstractRemappingH2Dialect> ... dialectClasses) { public final S alsoTestRemappingsWithH2(Class<? extends AbstractRemappingH2Dialect> ... dialectClasses) {
if ( dialect instanceof H2Dialect ) { if ( dialect instanceof H2Dialect ) {
@ -281,13 +295,14 @@ abstract class AbstractJavaTimeTypeTest<T, E> extends BaseCoreFunctionalTestCase
parameters.add( parameters.add(
new EnvironmentParameters( new EnvironmentParameters(
defaultJvmTimeZone, defaultJvmTimeZone,
null, forcedJdbcTimeZone,
remappingDialectClass remappingDialectClass
) )
); );
Collections.addAll( parameters, subClassParameters ); Collections.addAll( parameters, subClassParameters );
result.add( parameters.toArray() ); result.add( parameters.toArray() );
} }
if ( forcedJdbcTimeZone == null ) {
for ( ZoneId hibernateJdbcTimeZone : getHibernateJdbcTimeZonesToTest() ) { for ( ZoneId hibernateJdbcTimeZone : getHibernateJdbcTimeZonesToTest() ) {
List<Object> parameters = new ArrayList<>(); List<Object> parameters = new ArrayList<>();
parameters.add( parameters.add(
@ -300,6 +315,7 @@ abstract class AbstractJavaTimeTypeTest<T, E> extends BaseCoreFunctionalTestCase
Collections.addAll( parameters, subClassParameters ); Collections.addAll( parameters, subClassParameters );
result.add( parameters.toArray() ); result.add( parameters.toArray() );
} }
}
return thisAsS(); return thisAsS();
} }