I am trying to mock a static method readAttributesusing the groovy convention metaClass, but the real get method is being called.
This is how I made fun of the static function:
def "test"() {
File file = fold.newFile('file.txt')
Files.metaClass.static.readAttributes = { path, cls ->
null
}
when:
fileUtil.fileCreationTime(file)
then:
1 * fileUtil.LOG.debug('null attribute')
}
Am I doing something wrong here?
My java method
public Object fileCreationTime(File file) {
try {
BasicFileAttributes attributes = Files.readAttributes(file.toPath(), BasicFileAttributes.class);
if(attributes == null) {
LOG.debug("null attribute");
}
} catch (IOException exception) {
}
return new Object();
}
source
share