Class SoftlyExtension
- java.lang.Object
-
- org.assertj.core.api.junit.jupiter.SoftlyExtension
-
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterTestExecutionCallback,org.junit.jupiter.api.extension.Extension,org.junit.jupiter.api.extension.TestInstancePostProcessor,org.junit.jupiter.api.extension.TestInstantiationAwareExtension
@Deprecated public class SoftlyExtension extends java.lang.Object implements org.junit.jupiter.api.extension.AfterTestExecutionCallback, org.junit.jupiter.api.extension.TestInstancePostProcessorDeprecated.This functionality (and more) has been rolled intoSoftAssertionsExtensionas of AssertJ 3.18.0.Extension for JUnit Jupiter that provides support for injecting an instance ofSoftAssertionsinto a class testSoftAssertionsfield.The injection occurs before each test method execution, after each test
assertAll()is invoked to evaluate all test assertions.A nested test class can provide a
SoftAssertionsfield when it extendsthisextension or can inherit the parent'sSoft assertions fieldThis extension throws an
IllegalStateExceptionif:- the test class lifecycle is
TestInstance.Lifecycle.PER_CLASS(see explanation below). - multiple
SoftAssertionsfields are found - no
SoftAssertionsfield is found
Detecting multiple
SoftAssertionsfields is a best effort at the time of this writing, some cases are not detected.Limitations:
- Cannot be used with test context that have
PER_CLASSlife cycle as the sameSoftAssertionswould be reused between tests. - May exhibit unpredictable behaviour in concurrent test execution
If you hit such limitations, consider using
SoftAssertionsExtensioninstead, since 3.18.0,SoftAssertionsExtensionsupports field injection with neither of these two limitations.Example:
@ExtendWith(SoftlyExtension.class) public class SoftlyExtensionExample { // initialized by the SoftlyExtension extension private SoftAssertions soft; @Test public void chained_soft_assertions_example() { String name = "Michael Jordan - Bulls"; soft.assertThat(name) .startsWith("Mi") .contains("Bulls"); // no need to call softly.assertAll(), this is done by the extension } // nested classes test work too @Nested class NestedExample { @Test public void football_assertions_example() { String kylian = "Kylian Mbappé"; soft.assertThat(kylian) .startsWith("Ky") .contains("bap"); // no need to call softly.assertAll(), this is done by the extension } } }
-
-
Field Summary
Fields Modifier and Type Field Description private static org.junit.jupiter.api.extension.ExtensionContext.NamespaceSOFTLY_EXTENSION_NAMESPACEDeprecated.
-
Constructor Summary
Constructors Constructor Description SoftlyExtension()Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidafterTestExecution(org.junit.jupiter.api.extension.ExtensionContext extensionContext)Deprecated.private static voidcheckTooManySoftAssertionsFields(java.util.Collection<java.lang.reflect.Field> softAssertionsFields)Deprecated.private static java.util.Optional<org.junit.jupiter.api.extension.ExtensionContext>getParent(java.util.Optional<org.junit.jupiter.api.extension.ExtensionContext> currentContext)Deprecated.private static org.junit.jupiter.api.extension.ExtensionContext.StoregetStore(org.junit.jupiter.api.extension.ExtensionContext extensionContext)Deprecated.private static java.util.Optional<SoftAssertions>initSoftAssertionsField(java.lang.Object testInstance)Deprecated.private static booleanisPerClassLifeCycle(org.junit.jupiter.api.extension.ExtensionContext methodExtensionContext)Deprecated.voidpostProcessTestInstance(java.lang.Object testInstance, org.junit.jupiter.api.extension.ExtensionContext extensionContext)Deprecated.
-
-
-
Method Detail
-
postProcessTestInstance
public void postProcessTestInstance(java.lang.Object testInstance, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws java.lang.ExceptionDeprecated.- Specified by:
postProcessTestInstancein interfaceorg.junit.jupiter.api.extension.TestInstancePostProcessor- Throws:
java.lang.Exception
-
afterTestExecution
public void afterTestExecution(org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws java.lang.ExceptionDeprecated.- Specified by:
afterTestExecutionin interfaceorg.junit.jupiter.api.extension.AfterTestExecutionCallback- Throws:
java.lang.Exception
-
getParent
private static java.util.Optional<org.junit.jupiter.api.extension.ExtensionContext> getParent(java.util.Optional<org.junit.jupiter.api.extension.ExtensionContext> currentContext)
Deprecated.
-
isPerClassLifeCycle
private static boolean isPerClassLifeCycle(org.junit.jupiter.api.extension.ExtensionContext methodExtensionContext)
Deprecated.
-
initSoftAssertionsField
private static java.util.Optional<SoftAssertions> initSoftAssertionsField(java.lang.Object testInstance) throws java.lang.IllegalAccessException
Deprecated.- Throws:
java.lang.IllegalAccessException
-
checkTooManySoftAssertionsFields
private static void checkTooManySoftAssertionsFields(java.util.Collection<java.lang.reflect.Field> softAssertionsFields)
Deprecated.
-
getStore
private static org.junit.jupiter.api.extension.ExtensionContext.Store getStore(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
Deprecated.
-
-