11package org .hibernate .reactive .env ;
22
3- import org .gradle .api .tasks .CacheableTask ;
3+ import java .util .HashMap ;
4+ import java .util .Map ;
5+
46import org .gradle .api .tasks .Input ;
57import org .gradle .api .tasks .Optional ;
68import org .gradle .api .tasks .testing .Test ;
79import org .gradle .api .tasks .testing .TestDescriptor ;
10+ import org .gradle .api .tasks .testing .TestListener ;
811import org .gradle .api .tasks .testing .TestResult ;
912
10- import groovy .lang .Closure ;
1113import org .jetbrains .annotations .NotNull ;
1214import org .jetbrains .annotations .Nullable ;
1315
14- @ CacheableTask
1516public abstract class TestDbTask extends Test {
1617
1718 @ NotNull
@@ -61,6 +62,14 @@ public void setShowStandardStreams(boolean showStandardStreams) {
6162 this .showStandardStreams = showStandardStreams ;
6263 }
6364
65+ @ Input
66+ public Map <String , String > getCustomSystemProperties () {
67+ final Map <String , String > props = new HashMap <>();
68+ props .put ("db" , dbName );
69+ props .put ("docker" , dockerEnabled ? "true" : "false" );
70+ return props ;
71+ }
72+
6473 public TestDbTask () {
6574 // Default logging configuration
6675 setDefaultCharacterEncoding ( "UTF-8" );
@@ -75,20 +84,35 @@ public TestDbTask() {
7584 // enforcing Hibernate internal state
7685 systemProperty ( "org.hibernate.reactive.common.InternalStateAssertions.ENFORCE" , "true" );
7786
78- // Add afterSuite hook
79- afterSuite ( new Closure <Object >( this , this ) {
80- public Object doCall (TestDescriptor desc , TestResult result ) {
81- logSummary ( desc , result );
82- return null ;
87+ addTestListener ( new TestListener () {
88+
89+ @ Override
90+ public void beforeSuite (TestDescriptor suite ) {
91+ /* Do nothing */
92+ }
93+
94+ // Add afterSuite hook
95+ @ Override
96+ public void afterSuite (TestDescriptor suite , TestResult result ) {
97+ logSummary ( suite , result );
98+ }
99+
100+ @ Override
101+ public void beforeTest (TestDescriptor testDescriptor ) {
102+ /* Do nothing */
103+ }
104+
105+ @ Override
106+ public void afterTest (TestDescriptor testDescriptor , TestResult result ) {
107+ /* Do nothing */
83108 }
84109 } );
85110 }
86111
87112 @ Override
88113 public void executeTests () {
89114 // Apply system properties before running
90- systemProperty ( "db" , dbName );
91- systemProperty ( "docker" , dockerEnabled ? "true" : "false" );
115+ getCustomSystemProperties ().forEach (this ::systemProperty );
92116 getTestLogging ().setShowStandardStreams ( showStandardStreams );
93117
94118 if ( includeTests != null && !includeTests .isEmpty () ) {
0 commit comments