Xiao Wang created VFS-809:
-----------------------------

             Summary: Refactor CountingListener in DefaultFileMonitorTest to 
improve test design
                 Key: VFS-809
                 URL: https://issues.apache.org/jira/browse/VFS-809
             Project: Commons VFS
          Issue Type: Improvement
            Reporter: Xiao Wang


h3. Description

I noticed that there is a test class 
[CountingListener|https://github.com/apache/commons-vfs/blob/1b47a36139789f9b259f564cddf2a10a7e875787/commons-vfs2/src/test/java/org/apache/commons/vfs2/impl/DefaultFileMonitorTest.java#L45]
 implements production interface 
[FileListener|https://github.com/apache/commons-vfs/blob/1b47a36139789f9b259f564cddf2a10a7e875787/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileListener.java#L22]
 to assist testing method 
[DefaultFileMonitor.addFile(FileObject)|https://github.com/apache/commons-vfs/blob/1b47a36139789f9b259f564cddf2a10a7e875787/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileMonitor.java#L164]
 and 
[DefaultFileMonitor.removeFile(FileObject)|https://github.com/apache/commons-vfs/blob/1b47a36139789f9b259f564cddf2a10a7e875787/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileMonitor.java#L196].
 This might not be the best priactice in unit testing and can be improved by 
leveraging mocking frameworks.

h3. Current Implementation
 * {{CountingListener}} implements {{FileListener}} and creates new variables 
to keep tracking of the method invocation status for {{fileChanged()}}, 
{{fileCreated()}} and {{fileDeleted()}}.
 * In test case, the new variables will be used to check the execution status 
of the three above methods.

h3. Proposed Implementation
 * Replace {{CountingListener}} with a mocking object created by Mockito.
 * Extract the AtomicLong attributes and use the extracted attribute in test 
case to check method invocation status.
 * Use method stub to control the behavior of the mocking object.

h3. Motivation
 * Decouple test class {{CountingListener}} from production interface 
{{FileListener}}.
 * Make test logic more clear by using method stub instead of method overriding.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to