-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clean up usage of jmte Engine and use singleton instance #3564
Conversation
|
||
@Test | ||
public void testFormat() { | ||
|
||
final DecoratorImpl decorator = getDecoratorConfig("${field_a}: ${field_b}", "message", true); | ||
|
||
final FormatStringDecorator formatStringDecorator = new FormatStringDecorator(decorator); | ||
final FormatStringDecorator formatStringDecorator = new FormatStringDecorator(decorator, templateEngine); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it not possible to mock out the engine instead of supplying a real instance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible, but what advantage would using a mock over the real engine have here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That we are only testing this class and not an external dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which test case exactly?
FWIW, I'm trying to use real objects and not mocks whenever possible, also see https://martinfowler.com/articles/mocksArentStubs.html#ClassicalAndMockistTesting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅
|
||
@Before | ||
public void setUp() throws Exception { | ||
this.emailAlertSender = new FormattedEmailAlertSender(new EmailConfiguration(), mockNotificationService, mockNodeId); | ||
this.emailAlertSender = new FormattedEmailAlertSender(new EmailConfiguration(), mockNotificationService, mockNodeId, templateEngine); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible, but what advantage would using a mock over the real engine have here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What advantage would using a mock over the real engine have here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅
Instead of instantiating the jmte template engine all over the place, this PR cleans up a bit and injects a compiling template engine as a singleton into the relevant classes.