HHH-16500 Remove unnecessary reflection from JpaStreamTest

This commit is contained in:
Christoph Dreis 2023-04-24 16:10:35 +02:00 committed by Christian Beikov
parent a8b1dfd7be
commit a5ae8737a6
1 changed files with 46 additions and 64 deletions

View File

@ -6,8 +6,6 @@
*/
package org.hibernate.orm.test.stream.basic;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@ -22,7 +20,6 @@ import org.hibernate.Session;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.engine.jdbc.spi.JdbcCoordinator;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.resource.jdbc.ResourceRegistry;
import org.hibernate.testing.TestForIssue;
@ -41,7 +38,6 @@ import static org.hibernate.testing.orm.junit.ExtraAssertions.assertTyping;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Steve Ebersole
@ -429,7 +425,7 @@ public class JpaStreamTest {
//Test call close explicitly
scope.inTransaction( session -> {
try (Stream<Long> stream = getLongStream(
try (Stream<Integer> stream = getIntegerStream(
prepare,
session,
onCloseCallbacks,
@ -458,10 +454,7 @@ public class JpaStreamTest {
//Test Java 9 Stream methods
scope.inTransaction( session -> {
Method takeWhileMethod = ReflectHelper.getMethod( Stream.class, "takeWhile", Predicate.class );
if ( takeWhileMethod != null ) {
try (Stream<Long> stream = getLongStream(
try (Stream<Integer> stream = getIntegerStream(
prepare,
session,
onCloseCallbacks,
@ -474,7 +467,7 @@ public class JpaStreamTest {
Predicate<Integer> predicate = id -> id <= 5;
Stream<Integer> takeWhileStream = (Stream<Integer>) takeWhileMethod.invoke( stream, predicate );
Stream<Integer> takeWhileStream = stream.takeWhile( predicate );
List<Integer> result = takeWhileStream.collect( Collectors.toList() );
assertTrue( resourceRegistry.hasRegisteredResources() );
@ -491,17 +484,10 @@ public class JpaStreamTest {
onCloseAssertion.run();
}
catch (IllegalAccessException | InvocationTargetException e) {
fail( "Could not execute takeWhile because of " + e.getMessage() );
}
}
} );
scope.inTransaction( session -> {
Method dropWhileMethod = ReflectHelper.getMethod( Stream.class, "dropWhile", Predicate.class );
if ( dropWhileMethod != null ) {
try (Stream<Long> stream = getLongStream(
try (Stream<Integer> stream = getIntegerStream(
prepare,
session,
onCloseCallbacks,
@ -513,7 +499,7 @@ public class JpaStreamTest {
Predicate<Integer> predicate = id -> id <= 5;
Stream<Integer> dropWhileStream = (Stream<Integer>) dropWhileMethod.invoke( stream, predicate );
Stream<Integer> dropWhileStream = stream.dropWhile( predicate );
try {
List<Integer> result = dropWhileStream.collect( Collectors.toList() );
assertTrue( resourceRegistry.hasRegisteredResources() );
@ -530,10 +516,6 @@ public class JpaStreamTest {
onCloseAssertion.run();
}
catch (IllegalAccessException | InvocationTargetException e) {
fail( "Could not execute takeWhile because of " + e.getMessage() );
}
}
} );
}
@ -553,7 +535,7 @@ public class JpaStreamTest {
);
}
private static Stream<Long> getLongStream(
private static Stream<Integer> getIntegerStream(
Runnable prepare,
Session session,
List<Runnable> onCloseCallbacks,