Skip to content

Commit

Permalink
Issue #207: Cannot override CAS content set in a BeforeEach method
Browse files Browse the repository at this point in the history
- Reset CAS after the test, not before the test
  • Loading branch information
reckart committed Nov 10, 2022
1 parent 56d1e4d commit 02177f5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.AfterTestExecutionCallback;
import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestWatcher;

Expand All @@ -50,8 +49,7 @@
* handed out to any thread are reset (except any CASes which may meanwhile have been garbage
* collected).
*/
public final class ManagedCas implements TestWatcher, BeforeTestExecutionCallback,
AfterTestExecutionCallback, AfterAllCallback {
public final class ManagedCas implements TestWatcher, AfterTestExecutionCallback, AfterAllCallback {
private final ThreadLocal<CAS> casHolder;

private final Set<CAS> managedCases = synchronizedSet(newSetFromMap(new WeakHashMap<>()));
Expand Down Expand Up @@ -103,14 +101,10 @@ public void afterAll(ExtensionContext aContext) throws Exception {
casHolder.remove();
}

@Override
public void beforeTestExecution(ExtensionContext aContext) throws Exception {
managedCases.forEach(CAS::reset);
}

@Override
public void afterTestExecution(ExtensionContext context) throws Exception {
managedCases.forEach(this::assertValid);
managedCases.forEach(CAS::reset);
}

public ManagedCas skipValidation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.AfterTestExecutionCallback;
import org.junit.jupiter.api.extension.BeforeTestExecutionCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestWatcher;

Expand All @@ -50,8 +49,8 @@
* handed out to any thread are reset (except any JCases which may meanwhile have been garbage
* collected).
*/
public final class ManagedJCas implements TestWatcher, BeforeTestExecutionCallback,
AfterTestExecutionCallback, AfterAllCallback {
public final class ManagedJCas
implements TestWatcher, AfterTestExecutionCallback, AfterAllCallback {
private final ThreadLocal<JCas> casHolder;

private final Set<JCas> managedCases = synchronizedSet(newSetFromMap(new WeakHashMap<>()));
Expand Down Expand Up @@ -103,14 +102,10 @@ public void afterAll(ExtensionContext aContext) throws Exception {
casHolder.remove();
}

@Override
public void beforeTestExecution(ExtensionContext aContext) throws Exception {
managedCases.forEach(JCas::reset);
}

@Override
public void afterTestExecution(ExtensionContext context) throws Exception {
managedCases.forEach(this::assertValid);
managedCases.forEach(JCas::reset);
}

public ManagedJCas skipValidation() {
Expand Down

0 comments on commit 02177f5

Please sign in to comment.