Package com.icegreen.greenmail.junit5
Class GreenMailExtension
java.lang.Object
com.icegreen.greenmail.configuration.ConfiguredGreenMail
com.icegreen.greenmail.util.GreenMailProxy
com.icegreen.greenmail.junit5.GreenMailExtension
- All Implemented Interfaces:
GreenMailOperations,AfterAllCallback,AfterEachCallback,BeforeAllCallback,BeforeEachCallback,Extension
public class GreenMailExtension
extends GreenMailProxy
implements BeforeAllCallback, AfterAllCallback, BeforeEachCallback, AfterEachCallback
To use this extension you need to use
But if you want to remove
@RegisterExtension Junit5 mechanism and made variable static.But if you want to remove
static keyword annotate test class with @TestInstance(TestInstance.Lifecycle.PER_CLASS).
By default you get a new GreenMail instance per method which works with BeforeEach.
You can use withPerMethodLifecycle(boolean) to control this behavior - eg to speed
up at the cost of isolation using only BeforeAll
@RegisterExtension
GreenMailExtension greenMail = new GreenMailExtension(ServerSetupTest.SMTP_IMAP)
.withPerMethodLifecycle(false);
@BeforeAll
public void setup() { ... }
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionInitialize with all server setups.GreenMailExtension(ServerSetup serverSetup) Initialize with single server setups.GreenMailExtension(ServerSetup[] serverSetups) Initialize with multiple server setups. -
Method Summary
Modifier and TypeMethodDescriptionvoidafterAll(ExtensionContext context) voidafterEach(ExtensionContext context) voidbeforeAll(ExtensionContext context) voidbeforeEach(ExtensionContext context) protected GreenMailbooleanwithPerMethodLifecycle(boolean perMethod) Specify whether GreenMail should be set up and torn down before and after each method or before and after all methods.Methods inherited from class com.icegreen.greenmail.util.GreenMailProxy
findReceivedMessages, getImap, getImaps, getManagers, getPop3, getPop3s, getReceivedMessages, getReceivedMessagesForDomain, getSmtp, getSmtps, getUserManager, loadEmails, purgeEmailFromAllMailboxes, reset, setQuotaSupported, setUser, setUser, setUsers, start, stop, waitForIncomingEmail, waitForIncomingEmailMethods inherited from class com.icegreen.greenmail.configuration.ConfiguredGreenMail
doConfigure
-
Constructor Details
-
GreenMailExtension
Initialize with single server setups.- Parameters:
serverSetup- Setup to use
-
GreenMailExtension
public GreenMailExtension()Initialize with all server setups. -
GreenMailExtension
Initialize with multiple server setups.- Parameters:
serverSetups- All setups to use
-
-
Method Details
-
beforeEach
- Specified by:
beforeEachin interfaceBeforeEachCallback
-
afterEach
- Specified by:
afterEachin interfaceAfterEachCallback
-
beforeAll
- Specified by:
beforeAllin interfaceBeforeAllCallback
-
afterAll
- Specified by:
afterAllin interfaceAfterAllCallback
-
withPerMethodLifecycle
Specify whether GreenMail should be set up and torn down before and after each method or before and after all methods.- Parameters:
perMethod- Iftrue, per-method lifecycle is used, per-class otherwise.- Returns:
- The GreenMail extension for chaining calls.
-
getGreenMail
- Specified by:
getGreenMailin classGreenMailProxy
-
withConfiguration
- Specified by:
withConfigurationin interfaceGreenMailOperations- Overrides:
withConfigurationin classConfiguredGreenMail
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceGreenMailOperations
-