Skip to content

Commit

Permalink
HHH-13379 Enhance date/time tests to allow testing certain values onl…
Browse files Browse the repository at this point in the history
…y when forcing the JDBC timezone

(cherry picked from commit de8e965)
  • Loading branch information
yrodiere authored and gbadner committed Aug 2, 2019
1 parent 330b5da commit f4fd801
Showing 1 changed file with 28 additions and 12 deletions.
Expand Up @@ -243,6 +243,8 @@ protected static abstract class AbstractParametersBuilder<S extends AbstractPara

private final List<Class<? extends AbstractRemappingH2Dialect>> remappingDialectClasses = new ArrayList<>();

private ZoneId forcedJdbcTimeZone = null;

protected AbstractParametersBuilder() {
dialect = determineDialect();
remappingDialectClasses.add( null ); // Always test without remapping
Expand All @@ -261,6 +263,18 @@ public S skippedForDialects(List<Class<?>> dialectClasses, Consumer<S> skippedIf
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
public final S alsoTestRemappingsWithH2(Class<? extends AbstractRemappingH2Dialect> ... dialectClasses) {
if ( dialect instanceof H2Dialect ) {
Expand All @@ -281,24 +295,26 @@ protected final S add(ZoneId defaultJvmTimeZone, Object ... subClassParameters)
parameters.add(
new EnvironmentParameters(
defaultJvmTimeZone,
null,
forcedJdbcTimeZone,
remappingDialectClass
)
);
Collections.addAll( parameters, subClassParameters );
result.add( parameters.toArray() );
}
for ( ZoneId hibernateJdbcTimeZone : getHibernateJdbcTimeZonesToTest() ) {
List<Object> parameters = new ArrayList<>();
parameters.add(
new EnvironmentParameters(
defaultJvmTimeZone,
hibernateJdbcTimeZone,
null
)
);
Collections.addAll( parameters, subClassParameters );
result.add( parameters.toArray() );
if ( forcedJdbcTimeZone == null ) {
for ( ZoneId hibernateJdbcTimeZone : getHibernateJdbcTimeZonesToTest() ) {
List<Object> parameters = new ArrayList<>();
parameters.add(
new EnvironmentParameters(
defaultJvmTimeZone,
hibernateJdbcTimeZone,
null
)
);
Collections.addAll( parameters, subClassParameters );
result.add( parameters.toArray() );
}
}
return thisAsS();
}
Expand Down

0 comments on commit f4fd801

Please sign in to comment.