Skip to content

Fixed NPE in JUnit5 helper if docker is not availabled #506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@
<release>8</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- Hides warnings of mockito and jacoco usage in tests on JDK 21+ -->
<argLine>${argLine} -XX:+EnableDynamicAgentLoading</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -22,8 +21,8 @@
*
* @author Aleksandr Gorshenin
*/
public class GrpcTransportExtension extends ProxyGrpcTransport implements ExecutionCondition,
AfterAllCallback, AfterEachCallback, BeforeAllCallback, BeforeEachCallback {
public class GrpcTransportExtension extends ProxyGrpcTransport implements AfterAllCallback, AfterEachCallback,
BeforeAllCallback, BeforeEachCallback {
private static final Logger logger = LoggerFactory.getLogger(GrpcTransportExtension.class);

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

@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
if (!context.getTestInstance().isPresent()) {
return ConditionEvaluationResult.enabled("OK");
}

if (!YdbHelperFactory.getInstance().isEnabled()) {
return ConditionEvaluationResult.disabled("Ydb helper is disabled");
}
return ConditionEvaluationResult.enabled("OK");
private void ensureEnabled(String displayName) {
Assumptions.assumeTrue(YdbHelperFactory.getInstance().isEnabled(), "Ydb helper is disabled " + displayName);
}

@Override
public void beforeAll(ExtensionContext ec) throws Exception {
ensureEnabled(ec.getDisplayName());
holder.before(ec);
}

@Override
public void afterAll(ExtensionContext ec) throws Exception {
ensureEnabled(ec.getDisplayName());
holder.after(ec);
}

@Override
public void beforeEach(ExtensionContext ec) throws Exception {
ensureEnabled(ec.getDisplayName());
holder.before(ec);
}

@Override
public void afterEach(ExtensionContext ec) throws Exception {
ensureEnabled(ec.getDisplayName());
holder.after(ec);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -20,8 +19,8 @@
/**
* @author Aleksandr Gorshenin
*/
public class YdbHelperExtension extends ProxyYdbHelper implements ExecutionCondition,
BeforeAllCallback, AfterAllCallback, BeforeEachCallback, AfterEachCallback {
public class YdbHelperExtension extends ProxyYdbHelper implements BeforeAllCallback, AfterAllCallback,
BeforeEachCallback, AfterEachCallback {
private static final Logger logger = LoggerFactory.getLogger(GrpcTransportExtension.class);

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

@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
if (!context.getTestInstance().isPresent()) {
return ConditionEvaluationResult.enabled("OK");
}

if (!YdbHelperFactory.getInstance().isEnabled()) {
return ConditionEvaluationResult.disabled("Ydb helper is disabled " + context.getDisplayName());
}
return ConditionEvaluationResult.enabled("OK");
private void ensureEnabled(String displayName) {
Assumptions.assumeTrue(YdbHelperFactory.getInstance().isEnabled(), "Ydb helper is disabled " + displayName);
}

@Override
public void beforeAll(ExtensionContext ec) throws Exception {
ensureEnabled(ec.getDisplayName());
holder.before(ec);
}

@Override
public void afterAll(ExtensionContext ec) throws Exception {
ensureEnabled(ec.getDisplayName());
holder.after(ec);
}

@Override
public void beforeEach(ExtensionContext ec) throws Exception {
ensureEnabled(ec.getDisplayName());
holder.before(ec);
}

@Override
public void afterEach(ExtensionContext ec) throws Exception {
ensureEnabled(ec.getDisplayName());
holder.after(ec);
}

Expand Down