Skip to content

Commit

Permalink
Reduce number of store operations
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Nov 2, 2023
1 parent 3f6c32b commit 6dd79b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ public void beforeEach(ExtensionContext context) {

private static void installFailureTracker(ExtensionContext context) {
context.getStore(NAMESPACE).put(FAILURE_TRACKER, (CloseableResource) () -> context.getParent() //
.ifPresent(it -> it.getStore(NAMESPACE).put(CHILD_FAILED, selfOrChildFailed(context))));
.ifPresent(it -> {
if (selfOrChildFailed(context)) {
it.getStore(NAMESPACE).put(CHILD_FAILED, true);
}
}));
}

private void injectStaticFields(ExtensionContext context, Class<?> testClass) {
Expand Down Expand Up @@ -268,7 +272,7 @@ static CloseablePath createTempDir(TempDirFactory factory, CleanupMode cleanupMo

private static boolean selfOrChildFailed(ExtensionContext context) {
return context.getExecutionException().isPresent() //
|| Boolean.TRUE.equals(context.getStore(NAMESPACE).get(CHILD_FAILED));
|| context.getStore(NAMESPACE).getOrDefault(CHILD_FAILED, Boolean.class, false);
}

static class CloseablePath implements CloseableResource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
import java.nio.file.Path;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.io.CleanupMode;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.engine.AbstractJupiterTestEngineTests;
Expand Down Expand Up @@ -245,16 +248,23 @@ void testOnSuccessFailingField() {
}
}

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
static class OnSuccessFailingStaticFieldCase {

@TempDir(cleanup = ON_SUCCESS)
static Path onSuccessFailingFieldDir;

@Test
void test() {
@Order(1)
void failing() {
TempDirFieldTests.onSuccessFailingFieldDir = onSuccessFailingFieldDir;
fail();
}

@Test
@Order(2)
void passing() {
}
}

static class OnSuccessFailingStaticFieldWithNestingCase {
Expand Down

0 comments on commit 6dd79b8

Please sign in to comment.