简体   繁体   中英

groovy.lang.MissingMethodException: No signature of method exception when using Groovy default Builder annotation

I have the following enum, trait and a class.

enum FileFormat {
    V2, V3
}

trait FileSet {
    int fileSetId
    List<DataFile> srcFiles = Collections.emptyList()
    boolean header = false
    boolean mixedPack = false
    FileFormat format

    List<String> getSrcFileNames() {
        srcFiles.collect { it -> it.getSrcFileName() }
    }

    int getFileCount() {
        srcFiles.size()
    }

    abstract boolean isValid()

    def addFile(HeaderFileType hdrType) {
        def f = DataFile()
    }
}

@Builder(builderMethodName = "builder", buildMethodName = "build", prefix = "with", excludes = "srcFileNames, valid, fileCount")
class VolumeFileSet implements FileSet {

    @Override
    boolean isValid() {
        //TODO implement based on VolumeFileSet validation rules
        return true
    }
}

When I try to use builder to set the format enum, I am getting the error

groovy.lang.MissingMethodException: No signature of method: static com.tccc.bia.testdrive.nsr.VolumeFileSet.witFormat() is applicable for argument types: (com.tccc.bia.testdrive.nsr.FileFormat) values: [V3]
Possible solutions: setFormat(com.tccc.bia.testdrive.nsr.FileFormat), getFormat()

Here is the test

class TestSpec extends Specification {

    def setupSpec() {
        def volumeFileSet = VolumeFileSet
                .builder()
                .withHeader(true)
                .withMixedPack(true)
                .witFormat(FileFormat.V3) //ERROR here
                .build()
    }
}

You misspelled the method name.

It should be withFormat(FileFormat.V3) , not witFormat .

When corrected, the code compiles and runs just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM