File构造函数中的FileNotFoundException

时间:2014-05-26 00:07:21

标签: unit-testing grails spock

我正在处理grails应用程序,并且无法对包含此代码块的语句进行单元测试

DateTime getExifTimestamp(UploadedFile uploadedFile) {
    // Get the metadata directory with the timestamp
    ExifSubIFDDirectory directory = ImageMetadataReader
            .readMetadata(new File(uploadedFile.currentPath))
            .getDirectory(ExifSubIFDDirectory.class)

    def retVal = new LocalDateTime(directory.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL)).toDateTime()
    log.trace("Image time: $retVal")
    // TODO: Pull this sort of logging into an annotation or something else

    retVal
}

每当我调用此方法时,ExifSubIFDDirectory行总是会窒息并给出以下错误消息

    java.io.FileNotFoundException: currentPath (The system cannot find the file specified)
    at java.io.FileInputStream.<init>(FileInputStream.java:146)
    at com.drew.imaging.ImageMetadataReader.readMetadata(ImageMetadataReader.java:86)
    at com.witsmd.pronghorn.ConvertToDicomService.$tt__getExifTimestamp(ConvertToDicomService.groovy:164)
    at com.witsmd.pronghorn.ConvertToDicomServiceSpec.(ConvertToDicomServiceSpec.groovy:149)

1 个答案:

答案 0 :(得分:0)

对我来说,这看起来像文件名是&#34; currentPath&#34;,这可能不是你想要的,是吗?