-
-
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.
Merge branch 'main' into feature/2816
- Loading branch information
Showing
78 changed files
with
4,706 additions
and
395 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
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
99 changes: 99 additions & 0 deletions
99
documentation/src/test/java/example/ContainerTemplateDemo.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,99 @@ | ||
/* | ||
* Copyright 2015-2025 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 example; | ||
|
||
import static java.util.Collections.singletonList; | ||
import static java.util.Collections.unmodifiableList; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
import example.ContainerTemplateDemo.MyContainerTemplateInvocationContextProvider; | ||
|
||
import org.junit.jupiter.api.ContainerTemplate; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ContainerTemplateInvocationContext; | ||
import org.junit.jupiter.api.extension.ContainerTemplateInvocationContextProvider; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.api.extension.Extension; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.junit.jupiter.api.extension.TestInstancePostProcessor; | ||
|
||
// tag::user_guide[] | ||
@ContainerTemplate | ||
@ExtendWith(MyContainerTemplateInvocationContextProvider.class) | ||
class ContainerTemplateDemo { | ||
|
||
static final List<String> WELL_KNOWN_FRUITS | ||
// tag::custom_line_break[] | ||
= unmodifiableList(Arrays.asList("apple", "banana", "lemon")); | ||
|
||
private String fruit; | ||
|
||
@Test | ||
void notNull() { | ||
assertNotNull(fruit); | ||
} | ||
|
||
@Test | ||
void wellKnown() { | ||
assertTrue(WELL_KNOWN_FRUITS.contains(fruit)); | ||
} | ||
|
||
// end::user_guide[] | ||
static | ||
// tag::user_guide[] | ||
public class MyContainerTemplateInvocationContextProvider | ||
// tag::custom_line_break[] | ||
implements ContainerTemplateInvocationContextProvider { | ||
|
||
@Override | ||
public boolean supportsContainerTemplate(ExtensionContext context) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Stream<ContainerTemplateInvocationContext> | ||
// tag::custom_line_break[] | ||
provideContainerTemplateInvocationContexts(ExtensionContext context) { | ||
|
||
return Stream.of(invocationContext("apple"), invocationContext("banana")); | ||
} | ||
|
||
private ContainerTemplateInvocationContext invocationContext(String parameter) { | ||
return new ContainerTemplateInvocationContext() { | ||
@Override | ||
public String getDisplayName(int invocationIndex) { | ||
return parameter; | ||
} | ||
|
||
// end::user_guide[] | ||
@SuppressWarnings("Convert2Lambda") | ||
// tag::user_guide[] | ||
@Override | ||
public List<Extension> getAdditionalExtensions() { | ||
return singletonList(new TestInstancePostProcessor() { | ||
@Override | ||
public void postProcessTestInstance( | ||
// tag::custom_line_break[] | ||
Object testInstance, ExtensionContext context) { | ||
((ContainerTemplateDemo) testInstance).fruit = parameter; | ||
} | ||
}); | ||
} | ||
}; | ||
} | ||
} | ||
} | ||
// end::user_guide[] |
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
65 changes: 65 additions & 0 deletions
65
junit-jupiter-api/src/main/java/org/junit/jupiter/api/ContainerTemplate.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,65 @@ | ||
/* | ||
* Copyright 2015-2025 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; | ||
|
||
import static org.apiguardian.api.API.Status.EXPERIMENTAL; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import org.apiguardian.api.API; | ||
import org.junit.platform.commons.annotation.Testable; | ||
|
||
/** | ||
* {@code @ContainerTemplate} is used to signal that the annotated class is a | ||
* <em>container template</em>. | ||
* | ||
* <p>In contrast to regular test classes, a container template is not directly | ||
* a test class but rather a template for a set of test cases. As such, it is | ||
* designed to be invoked multiple times depending on the number of {@linkplain | ||
* org.junit.jupiter.api.extension.ContainerTemplateInvocationContext invocation | ||
* contexts} returned by the registered {@linkplain | ||
* org.junit.jupiter.api.extension.ContainerTemplateInvocationContextProvider | ||
* providers}. Must be used together with at least one provider. Otherwise, | ||
* execution will fail. | ||
* | ||
* <p>Each invocation of a container template method behaves like the execution | ||
* of a regular test class with full support for the same lifecycle callbacks | ||
* and extensions. | ||
* | ||
* <p>{@code @ContainerTemplate} may be combined with {@link Nested @Nested} and | ||
* a container template may contain regular nested test classes or nested | ||
* container templates. | ||
* | ||
* <p>{@code @ContainerTemplate} may also be used as a meta-annotation in order | ||
* to create a custom <em>composed annotation</em> that inherits the semantics | ||
* of {@code @ContainerTemplate}. | ||
* | ||
* <h2>Inheritance</h2> | ||
* | ||
* <p>The {@code @ContainerTemplate} annotation is not inherited to subclasses | ||
* but needs to be declared on each container template class individually. | ||
* | ||
* @since 5.13 | ||
* @see TestTemplate | ||
* @see org.junit.jupiter.api.extension.ContainerTemplateInvocationContext | ||
* @see org.junit.jupiter.api.extension.ContainerTemplateInvocationContextProvider | ||
*/ | ||
@Target({ ElementType.ANNOTATION_TYPE, ElementType.TYPE }) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@API(status = EXPERIMENTAL, since = "5.13") | ||
@Testable | ||
public @interface ContainerTemplate { | ||
} |
Oops, something went wrong.