Skip to content

Commit 4da0fae

Browse files
committed
Added option failIfUnavailable to JUnit4 helper
1 parent dab9b75 commit 4da0fae

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

tests/junit4-support/src/main/java/tech/ydb/test/junit4/GrpcTransportRule.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,21 @@
2121
public class GrpcTransportRule extends ProxyGrpcTransport implements TestRule {
2222
private static final Logger logger = LoggerFactory.getLogger(GrpcTransportRule.class);
2323

24-
private final AtomicReference<GrpcTransport> proxy = new AtomicReference<>();
24+
private final AtomicReference<GrpcTransport> proxy;
25+
private final boolean skipOnUnavailable;
26+
27+
private GrpcTransportRule(AtomicReference<GrpcTransport> proxy, boolean skipOnUnavailable) {
28+
this.proxy = proxy;
29+
this.skipOnUnavailable = skipOnUnavailable;
30+
}
31+
32+
public GrpcTransportRule() {
33+
this(new AtomicReference<>(), true);
34+
}
35+
36+
public GrpcTransportRule failIfUnavailable() {
37+
return new GrpcTransportRule(proxy, false);
38+
}
2539

2640
@Override
2741
public Statement apply(Statement base, Description description) {
@@ -30,17 +44,20 @@ public Statement apply(Statement base, Description description) {
3044
return new Statement() {
3145
@Override
3246
public void evaluate() throws Throwable {
47+
String path = description.getDisplayName();
48+
if (description.getMethodName() != null) {
49+
path += "/" + description.getMethodName();
50+
}
51+
3352
if (!factory.isEnabled()) {
34-
logger.info("Test {} skipped because ydb helper is not available", description.getDisplayName());
53+
if (!skipOnUnavailable) {
54+
throw new AssertionError("Ydb helper is not available " + path);
55+
}
56+
logger.info("Test {} skipped because ydb helper is not available", path);
3557
Assume.assumeFalse("YDB Helper is not available", true);
3658
return;
3759
}
3860

39-
String path = description.getClassName();
40-
if (description.getMethodName() != null) {
41-
path += "/" + description.getMethodName();
42-
}
43-
4461
logger.debug("create ydb helper for test {}", path);
4562
try (YdbHelper helper = factory.createHelper()) {
4663
try (GrpcTransport transport = helper.createTransport()) {

tests/junit4-support/src/main/java/tech/ydb/test/junit4/YdbHelperRule.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,21 @@
2020
public class YdbHelperRule extends ProxyYdbHelper implements TestRule {
2121
private static final Logger logger = LoggerFactory.getLogger(YdbHelperRule.class);
2222

23-
private final AtomicReference<YdbHelper> proxy = new AtomicReference<>();
23+
private final AtomicReference<YdbHelper> proxy;
24+
private final boolean skipOnUnavailable;
25+
26+
private YdbHelperRule(AtomicReference<YdbHelper> proxy, boolean skipOnUnavailable) {
27+
this.proxy = proxy;
28+
this.skipOnUnavailable = skipOnUnavailable;
29+
}
30+
31+
public YdbHelperRule() {
32+
this(new AtomicReference<>(), true);
33+
}
34+
35+
public YdbHelperRule failIfUnavailable() {
36+
return new YdbHelperRule(proxy, false);
37+
}
2438

2539
@Override
2640
public Statement apply(Statement base, Description description) {
@@ -29,13 +43,17 @@ public Statement apply(Statement base, Description description) {
2943
return new Statement() {
3044
@Override
3145
public void evaluate() throws Throwable {
46+
String path = description.getDisplayName();
47+
3248
if (!factory.isEnabled()) {
33-
logger.info("Test {} skipped because ydb helper is not available", description.getDisplayName());
49+
if (!skipOnUnavailable) {
50+
throw new AssertionError("Ydb helper is not available " + path);
51+
}
52+
logger.info("Test {} skipped because ydb helper is not available", path);
3453
Assume.assumeFalse("YDB Helper is not available", true);
3554
return;
3655
}
3756

38-
String path = description.getDisplayName();
3957
logger.debug("create ydb helper for test {}", path);
4058
try (YdbHelper helper = factory.createHelper()) {
4159
proxy.set(helper);

0 commit comments

Comments
 (0)