I have MailTransport.java and two classes extending it: LiveMailTransport.java and TestMailTransport.java.
LiveMailTransport will really send emails while TestMailTransprot will only write them to the log for testing purpose.
Somewhere I do new MailTransport(); and I would like to replace every usage of MailTransport in my server-side code either with Live- or with TestMailTransport depending on the profile used for compiling (local, production, etc..).
(Similar to gwts "replace-with" on client side…)
How could I do that with Maven?
What you want is a factory which accepts a system property. If the system property isn’t set, create an instance of
LiveMailTransport. If the property is there, create an instance ofTestMailTransport.Proposed name of property:
com.pany.app.enableTestMailsBoolean.getBoolean(String) is your friend.
Now configure the surefire plugin to set the property and you’re done.