I am trying to mock the one of static method readAttributes
using groovy's metaClass
convention, but the real method get invoked.
This is how I mocked 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");
}
//doSomething
} catch (IOException exception) {
//doSomething
}
return new Object();
}