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.