SUT - the type of the subject-under-test@FunctionalInterface public interface FactoryBasedJ8UnitTest<SUT> extends J8UnitTest<SUT>
In case a subject-under-test (SUT) based J8Unit test uses a SUT factory to produce fresh SUT instances, this
interface should be used in preference to J8UnitTest. In detail, this interface provides
a factory query method that is used by the default implementation of
createNewSUT().
| Modifier and Type | Method and Description |
|---|---|
default SUT |
createNewSUT()
Factory method to create a new subject-under-test (of type
SUT). |
Supplier<SUT> |
getSUTFactory()
Returns a factory to be used when creating new subject-under-test instances (each of
type
SUT). |
Supplier<SUT> getSUTFactory()
Returns a factory to be used when creating new subject-under-test instances (each of
type SUT).
default SUT createNewSUT()
Factory method to create a new subject-under-test (of type SUT).
If the specific SUT is deeply immutable (and, thus, cannot be altered in any circumstance), it is absolutely allowed to return the same SUT instance each time this method is called. If, otherwise, the SUT is mutable, a fresh instance must be returned to prevent any strange side-effect when asserting specific behaviour during the unit tests.
To say it clear: You do not know what specific usage will be executed on the SUT instance afterwards! So, think twice before carelessly returning a single instance again and again! Keep in mind internal caches, states, buffers, and further prevent SUT instances from being immutable; Immutability cannot be detected by looking at the visible elements only.
Due to the SUT factory based nature of this J8Unit test, this method has been
implemented with the following default behaviour:
final Supplier<SUT> factory = this.getSUTFactory(); assert factory != null; final SUT sut = factory.get(); assert sut != null; return sut;
createNewSUT in interface J8UnitTest<SUT>Copyright © 2015. All rights reserved.