Xiao Wang created CAY-2717:
------------------------------
Summary: Refactor MockChannelListener in
DataContextDataChannelEventsIT to improve test logic
Key: CAY-2717
URL: https://issues.apache.org/jira/browse/CAY-2717
Project: Cayenne
Issue Type: Improvement
Reporter: Xiao Wang
h3. Description
I noticed that there is a test class
[MockChannelListener|https://github.com/apache/cayenne/blob/b156addac1c8e4079fa88e977fee609210c5da69/cayenne-server/src/test/java/org/apache/cayenne/access/DataContextDataChannelEventsIT.java#L182]
implements production interface
[DataChannelListener|https://github.com/apache/cayenne/blob/b156addac1c8e4079fa88e977fee609210c5da69/cayenne-server/src/main/java/org/apache/cayenne/DataChannelListener.java#L38]
to assist testing the ineractions among {{commitChanges()}},
{{commitChangesToParent()}} and {{rollbackChanges()}}. This might not be the
best practice in testing and can be improved by leveraging mocking frameworks.
h3. Current Implementation
* {{MockChannelListener}} implements {{DataChannelListener}}. The sub test
class creates three fields to keep tracking the invocation status of three
overridden methods.
* In test cases, an instance of {{MockChannelListener}} is passed to
{{EventUtil.listenForChannelEvents(DataChannel, DataChannelListener)}}. The new
fields in test sub class are used in assertion statements to assert test sub
class's behavior.
h3. Proposed Implementation
* Replace {{MockChannelListener}} with a mocking object created by Mockito.
* Remove the fields created in test subclass to make test logic more clear.
* Remove the redundant method overrides to make test logic more clear.
* Use {{Mockito.verify()}} to directly verify the behavior of the mocking
object and make test condition more explict.
h3. Motivation
* Decoupling test class {{MockChannelListener}} from production interface
{{DataChannelListener}}
* Making test condition more clear by removing redundant overridden methods and
new fields.
* Use {{Mockito.verify()}} to directly verify the behavior of the mocking
object and make test condition more explict.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)