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@RegisterExtensionJunit5 mechanism and made variablestatic.
But if you want to removestatickeyword 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 usewithPerMethodLifecycle(boolean)to control this behavior - eg to speed up at the cost of isolation using onlyBeforeAll@RegisterExtension GreenMailExtension greenMail = new GreenMailExtension(ServerSetupTest.SMTP_IMAP) .withPerMethodLifecycle(false); @BeforeAll public void setup() { ... }- See Also:
RegisterExtension,TestInstance
-
-
Constructor Summary
Constructors Constructor Description GreenMailExtension()Initialize with all server setups.GreenMailExtension(ServerSetup serverSetup)Initialize with single server setups.GreenMailExtension(ServerSetup[] serverSetups)Initialize with multiple server setups.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterAll(ExtensionContext context)voidafterEach(ExtensionContext context)voidbeforeAll(ExtensionContext context)voidbeforeEach(ExtensionContext context)protected GreenMailgetGreenMail()booleanisRunning()GreenMailExtensionwithConfiguration(GreenMailConfiguration config)GreenMailExtensionwithPerMethodLifecycle(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
getImap, getImaps, getManagers, getPop3, getPop3s, getReceivedMessages, getReceivedMessagesForDomain, getSmtp, getSmtps, getUserManager, purgeEmailFromAllMailboxes, reset, setQuotaSupported, setUser, setUser, setUsers, start, stop, waitForIncomingEmail, waitForIncomingEmail
-
Methods inherited from class com.icegreen.greenmail.configuration.ConfiguredGreenMail
doConfigure
-
-
-
-
Constructor Detail
-
GreenMailExtension
public GreenMailExtension(ServerSetup serverSetup)
Initialize with single server setups.- Parameters:
serverSetup- Setup to use
-
GreenMailExtension
public GreenMailExtension()
Initialize with all server setups.
-
GreenMailExtension
public GreenMailExtension(ServerSetup[] serverSetups)
Initialize with multiple server setups.- Parameters:
serverSetups- All setups to use
-
-
Method Detail
-
beforeEach
public void beforeEach(ExtensionContext context)
- Specified by:
beforeEachin interfaceBeforeEachCallback
-
afterEach
public void afterEach(ExtensionContext context)
- Specified by:
afterEachin interfaceAfterEachCallback
-
beforeAll
public void beforeAll(ExtensionContext context)
- Specified by:
beforeAllin interfaceBeforeAllCallback
-
afterAll
public void afterAll(ExtensionContext context)
- Specified by:
afterAllin interfaceAfterAllCallback
-
withPerMethodLifecycle
public GreenMailExtension withPerMethodLifecycle(boolean perMethod)
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
protected GreenMail getGreenMail()
- Specified by:
getGreenMailin classGreenMailProxy
-
withConfiguration
public GreenMailExtension withConfiguration(GreenMailConfiguration config)
- Specified by:
withConfigurationin interfaceGreenMailOperations- Overrides:
withConfigurationin classConfiguredGreenMail
-
isRunning
public boolean isRunning()
- Specified by:
isRunningin interfaceGreenMailOperations
-
-