Skip to content

Commit eb68dac

Browse files
authored
Merge pull request #506 from alex268/master
Fixed NPE in JUnit5 helper if docker is not availabled
2 parents e266207 + e357e3c commit eb68dac

File tree

3 files changed

+26
-28
lines changed

3 files changed

+26
-28
lines changed

pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@
248248
<release>8</release>
249249
</configuration>
250250
</plugin>
251+
<plugin>
252+
<groupId>org.apache.maven.plugins</groupId>
253+
<artifactId>maven-surefire-plugin</artifactId>
254+
<configuration>
255+
<!-- Hides warnings of mockito and jacoco usage in tests on JDK 21+ -->
256+
<argLine>${argLine} -XX:+EnableDynamicAgentLoading</argLine>
257+
</configuration>
258+
</plugin>
251259
</plugins>
252260
</build>
253261
</profile>

tests/junit5-support/src/main/java/tech/ydb/test/junit5/GrpcTransportExtension.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
import java.util.concurrent.locks.Lock;
44
import java.util.concurrent.locks.ReentrantLock;
55

6+
import org.junit.jupiter.api.Assumptions;
67
import org.junit.jupiter.api.extension.AfterAllCallback;
78
import org.junit.jupiter.api.extension.AfterEachCallback;
89
import org.junit.jupiter.api.extension.BeforeAllCallback;
910
import org.junit.jupiter.api.extension.BeforeEachCallback;
10-
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
11-
import org.junit.jupiter.api.extension.ExecutionCondition;
1211
import org.junit.jupiter.api.extension.ExtensionContext;
1312
import org.slf4j.Logger;
1413
import org.slf4j.LoggerFactory;
@@ -22,8 +21,8 @@
2221
*
2322
* @author Aleksandr Gorshenin
2423
*/
25-
public class GrpcTransportExtension extends ProxyGrpcTransport implements ExecutionCondition,
26-
AfterAllCallback, AfterEachCallback, BeforeAllCallback, BeforeEachCallback {
24+
public class GrpcTransportExtension extends ProxyGrpcTransport implements AfterAllCallback, AfterEachCallback,
25+
BeforeAllCallback, BeforeEachCallback {
2726
private static final Logger logger = LoggerFactory.getLogger(GrpcTransportExtension.class);
2827

2928
private final Holder holder = new Holder();
@@ -33,35 +32,31 @@ protected GrpcTransport origin() {
3332
return holder.transport();
3433
}
3534

36-
@Override
37-
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
38-
if (!context.getTestInstance().isPresent()) {
39-
return ConditionEvaluationResult.enabled("OK");
40-
}
41-
42-
if (!YdbHelperFactory.getInstance().isEnabled()) {
43-
return ConditionEvaluationResult.disabled("Ydb helper is disabled");
44-
}
45-
return ConditionEvaluationResult.enabled("OK");
35+
private void ensureEnabled(String displayName) {
36+
Assumptions.assumeTrue(YdbHelperFactory.getInstance().isEnabled(), "Ydb helper is disabled " + displayName);
4637
}
4738

4839
@Override
4940
public void beforeAll(ExtensionContext ec) throws Exception {
41+
ensureEnabled(ec.getDisplayName());
5042
holder.before(ec);
5143
}
5244

5345
@Override
5446
public void afterAll(ExtensionContext ec) throws Exception {
47+
ensureEnabled(ec.getDisplayName());
5548
holder.after(ec);
5649
}
5750

5851
@Override
5952
public void beforeEach(ExtensionContext ec) throws Exception {
53+
ensureEnabled(ec.getDisplayName());
6054
holder.before(ec);
6155
}
6256

6357
@Override
6458
public void afterEach(ExtensionContext ec) throws Exception {
59+
ensureEnabled(ec.getDisplayName());
6560
holder.after(ec);
6661
}
6762

tests/junit5-support/src/main/java/tech/ydb/test/junit5/YdbHelperExtension.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
import java.util.concurrent.locks.Lock;
44
import java.util.concurrent.locks.ReentrantLock;
55

6+
import org.junit.jupiter.api.Assumptions;
67
import org.junit.jupiter.api.extension.AfterAllCallback;
78
import org.junit.jupiter.api.extension.AfterEachCallback;
89
import org.junit.jupiter.api.extension.BeforeAllCallback;
910
import org.junit.jupiter.api.extension.BeforeEachCallback;
10-
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
11-
import org.junit.jupiter.api.extension.ExecutionCondition;
1211
import org.junit.jupiter.api.extension.ExtensionContext;
1312
import org.slf4j.Logger;
1413
import org.slf4j.LoggerFactory;
@@ -20,8 +19,8 @@
2019
/**
2120
* @author Aleksandr Gorshenin
2221
*/
23-
public class YdbHelperExtension extends ProxyYdbHelper implements ExecutionCondition,
24-
BeforeAllCallback, AfterAllCallback, BeforeEachCallback, AfterEachCallback {
22+
public class YdbHelperExtension extends ProxyYdbHelper implements BeforeAllCallback, AfterAllCallback,
23+
BeforeEachCallback, AfterEachCallback {
2524
private static final Logger logger = LoggerFactory.getLogger(GrpcTransportExtension.class);
2625

2726
private final Holder holder = new Holder();
@@ -31,35 +30,31 @@ protected YdbHelper origin() {
3130
return holder.helper();
3231
}
3332

34-
@Override
35-
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
36-
if (!context.getTestInstance().isPresent()) {
37-
return ConditionEvaluationResult.enabled("OK");
38-
}
39-
40-
if (!YdbHelperFactory.getInstance().isEnabled()) {
41-
return ConditionEvaluationResult.disabled("Ydb helper is disabled " + context.getDisplayName());
42-
}
43-
return ConditionEvaluationResult.enabled("OK");
33+
private void ensureEnabled(String displayName) {
34+
Assumptions.assumeTrue(YdbHelperFactory.getInstance().isEnabled(), "Ydb helper is disabled " + displayName);
4435
}
4536

4637
@Override
4738
public void beforeAll(ExtensionContext ec) throws Exception {
39+
ensureEnabled(ec.getDisplayName());
4840
holder.before(ec);
4941
}
5042

5143
@Override
5244
public void afterAll(ExtensionContext ec) throws Exception {
45+
ensureEnabled(ec.getDisplayName());
5346
holder.after(ec);
5447
}
5548

5649
@Override
5750
public void beforeEach(ExtensionContext ec) throws Exception {
51+
ensureEnabled(ec.getDisplayName());
5852
holder.before(ec);
5953
}
6054

6155
@Override
6256
public void afterEach(ExtensionContext ec) throws Exception {
57+
ensureEnabled(ec.getDisplayName());
6358
holder.after(ec);
6459
}
6560

0 commit comments

Comments
 (0)