-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close resource in inverse order of addition (#2387)
Resolves #2211.
- Loading branch information
1 parent
10aef49
commit 68bb2e3
Showing
9 changed files
with
143 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
.../testFixtures/java/org/junit/jupiter/api/extension/ExtensionContextParameterResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2015-2020 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.jupiter.api.extension; | ||
|
||
public class ExtensionContextParameterResolver implements ParameterResolver { | ||
|
||
@Override | ||
public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) | ||
throws ParameterResolutionException { | ||
return ExtensionContext.class.equals(parameterContext.getParameter().getType()); | ||
} | ||
|
||
@Override | ||
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) | ||
throws ParameterResolutionException { | ||
return extensionContext; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...gine/src/test/java/org/junit/jupiter/api/extension/CloseableResourceIntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2015-2020 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.jupiter.api.extension; | ||
|
||
import static org.junit.platform.testkit.engine.EventConditions.reportEntry; | ||
|
||
import java.util.Map; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.engine.AbstractJupiterTestEngineTests; | ||
|
||
public class CloseableResourceIntegrationTests extends AbstractJupiterTestEngineTests { | ||
|
||
@Test | ||
void closesCloseableResourcesInReverseInsertOrder() { | ||
executeTestsForClass(TestCase.class).allEvents().reportingEntryPublished() // | ||
.assertEventsMatchExactly( // | ||
reportEntry(Map.of("3", "closed")), // | ||
reportEntry(Map.of("2", "closed")), // | ||
reportEntry(Map.of("1", "closed"))); | ||
} | ||
|
||
@ExtendWith(ExtensionContextParameterResolver.class) | ||
static class TestCase { | ||
@Test | ||
void closesCloseableResourcesInExtensionContext(ExtensionContext extensionContext) { | ||
ExtensionContext.Store store = extensionContext.getStore(ExtensionContext.Namespace.GLOBAL); | ||
store.put("foo", reportEntryOnClose(extensionContext, "1")); | ||
store.put("bar", reportEntryOnClose(extensionContext, "2")); | ||
store.put("baz", reportEntryOnClose(extensionContext, "3")); | ||
} | ||
|
||
@NotNull | ||
private ExtensionContext.Store.CloseableResource reportEntryOnClose(ExtensionContext extensionContext, | ||
String key) { | ||
return () -> extensionContext.publishReportEntry(Map.of(key, "closed")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters