[
https://issues.apache.org/jira/browse/KAFKA-8977?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16964669#comment-16964669
]
bibin sebastian commented on KAFKA-8977:
----------------------------------------
I am assuming you are suggesting to create a generic mock of
`StreamsMetricsImpl` using the PowerMock/EasyMock and externalise for all
tests. Technically I think that is possible.
(Actually I think that is the only way to create mock for `StreamsMetricsImpl`.
Creating the mock by implementing the interface `StreamsMetrics` won't really
work because in most of the places `StreamsMetricsImpl` is directly referred
instead of using the interface references. Also this class have multiple static
methods. So I have a feeling that this class is used like a util class.)
So going by your suggestion, even if I create a generic mock, I am still not
convinced on the value of creating a mock in these scenarios where we have
indirect access to `StreamsMetricsImpl`.
Let me try to explain my thought process here.
Generally I use a mock instance to mock any external (direct) dependencies of
the class/method in test and I verify the usage of mock as part of assertion in
the end. In our case since StreamsMetricsImpl is not being directly referred
(most of the time) in classes/methods in test, even if we create a mock we
won't be realistically be able to verify the usage (methods invocations) on the
mock (using verify(mock) method). This is because we wouldn't want our tests to
fail assertion if the indirect usage of StreamsMetricsImpl changes at a later
point of time, so verifying the mock usage in the assertion wont really make
sense. So my point is what is the real value we gain if we can't verify the
usage of mock?
So I was preferring to leave its usage as it is in its full form rather than
using a mock. What do think?
[~cadonna]
> Remove MockStreamsMetrics Since it is not a Mock
> ------------------------------------------------
>
> Key: KAFKA-8977
> URL: https://issues.apache.org/jira/browse/KAFKA-8977
> Project: Kafka
> Issue Type: Improvement
> Components: streams
> Reporter: Bruno Cadonna
> Assignee: bibin sebastian
> Priority: Minor
> Labels: newbie
>
> The class {{MockStreamsMetrics}} is used throughout unit tests as a mock but
> it is not really a mock since it only hides two parameters of the
> {{StreamsMetricsImpl}} constructor. Either a real mock or the real
> {{StreamsMetricsImpl}} should be used in the tests.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)