commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ralph Goers (JIRA)" <j...@apache.org>
Subject [jira] Commented: (VFS-234) Can't listen to file modifications, event raised is fileCreated rather than fileChanged
Date Mon, 16 Nov 2009 06:50:39 GMT

    [ https://issues.apache.org/jira/browse/VFS-234?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12778225#action_12778225
] 

Ralph Goers commented on VFS-234:
---------------------------------

Have you tested this on trunk? I am pretty sure that there are unit tests that verify the
correct behavior.

> Can't listen to file modifications, event raised is fileCreated rather than fileChanged
> ---------------------------------------------------------------------------------------
>
>                 Key: VFS-234
>                 URL: https://issues.apache.org/jira/browse/VFS-234
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 1.0
>         Environment: Windows, Java 6
>            Reporter: Antonio Terreno
>
> It seems like that a FileCreated event is raised even when the file changes. 
> I checked out the tests on the repository and the test is on file creation not modification.

> The below test uses mockito to mock the Listener, I had the same result using a real
listener. 
>     @Test 
>     public void testShouldListenToFileChanges() throws Exception {
>         FileObject child = folder.resolveFile( "fileToChange.txt" );
>         FileSystem fs = folder.getFileSystem();
>         
>         FileMonitor defaultFileMonitor = new DefaultFileMonitor(fileListener);
>         defaultFileMonitor.addFile( child );        
>         fs.addListener( child, fileListener );        
>         OutputStream out = child.getContent().getOutputStream();
>         out.write( "bla".getBytes() );
>         out.close();        
>         child.getContent().close();
>         
>         verify( fileListener).fileCreated( argThat( isAFileChangeEventOn( child ) ) );
>         verify( fileListener).fileChanged( argThat( isAFileChangeEventOn( child ) ) );
>     }
> class FileChangeEventMatcher extends BaseMatcher<FileChangeEvent> {
>        
>     private final FileObject fileObject;
>     public FileChangeEventMatcher( FileObject fileObject ) {
>         this.fileObject = fileObject;
>     }
>     
>     public static FileChangeEventMatcher isAFileChangeEventOn( FileObject child ) {
>         return new FileChangeEventMatcher( child );
>     }
>     @Override
>     public boolean matches( Object obj ) {
>         FileChangeEvent event = (FileChangeEvent) ( obj );
>         if ( event.getFile().equals( fileObject ) )
>             return true;
>         return false;
>     }
>     @Override
>     public void describeTo( Description description ) {
>     }
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message