OpenCSV Header 找不到必填字段 []

OpenCSV Header is missing required fields found []

opencsv 5.1

Caused by: com.opencsv.exceptions.CsvRequiredFieldEmptyException: Header is missing required fields [ALGVERIFICATION, DISTAL MV, LOCATION, PREDICTED STATE, PROXIMAL MV, RUN, SAMPLE TIME]. The list of headers encountered is [].
    at com.opencsv.bean.HeaderNameBaseMappingStrategy.captureHeader(HeaderNameBaseMappingStrategy.java:69)
@ParameterizedTest
@ArgumentsSource(MyArgumentsProvider.class)
void test( AlgorithmVerification verifications )
{
    Log.d("test", verifications.location);
    assertThat(verifications).isNotNull();
}


public enum State {
    NA,
    ADVANCE,
    RETRACT,
}

public static class StateConverter extends AbstractBeanField {

    @Override
    protected Object convert(String value) {
        return State.valueOf(value);
    }
}

public static class AlgorithmVerification {
    @CsvBindByName(column = "Sample Time", required = true)
    protected float sampleTime;

    @CsvBindByName(column = "Distal mV", required = true)
    protected int distalMV;

    @CsvBindByName(column = "Proximal mV", required = true)
    protected int proximalMV;

    @CsvCustomBindByName(column = "Predicted State", converter = StateConverter.class, required = true)
    protected State predictedState;

    @CsvBindByName(column = "run", required = true)
    protected String run;

    @CsvCustomBindByName(column = "Location", converter = StateConverter.class, required = true)
    protected String location;

    @CsvCustomBindByName(column = "AlgVerification", converter = StateConverter.class, required = true)
    protected State algVerification;
}


static class MyArgumentsProvider implements ArgumentsProvider {

    @Override
    public Stream<? extends Arguments> provideArguments(ExtensionContext context) throws IOException, URISyntaxException {
        return Files.list(Paths.get(ClassLoader.getSystemResource("avd").toURI()))
            .map(Path::toFile)
            .map( f -> Try.withResources( () -> new FileReader(f) )
                .of(CsvToBeanBuilder::new)
                .map(b -> b.withType(AlgorithmVerification.class) )
                .map(CsvToBeanBuilder::build)
                .map(CsvToBean::parse)
                .getOrElseThrow((throwable) -> new RuntimeException(f.getName(), throwable))
            )
            .flatMap(List::stream)
            .map(Arguments::of);
    }
}

这是文件的开头

Sample Time,Distal mV,Proximal mV,Predicted State,run,Location,AlgVerification
0.016,2509,2502,NA,DV-MyString,-1,-1

我错过了一步吗? headers 是不是错了?我注意到它正在寻找大写 headers... 但即便如此它也在寻找 none

看来我对 vavr Try.withResources 的用法是错误的,应该是这样

return Files.list(Paths.get(ClassLoader.getSystemResource("avd").toURI()))
    .map(Path::toFile)
    .map( f -> Try.withResources( () -> new FileReader(f) )
            .of((fr ) -> new CsvToBeanBuilder<AlgorithmVerification>(fr)
                .withType(AlgorithmVerification.class)
                .build()
                .parse())
        .getOrElseThrow((throwable) -> new RuntimeException(f.getName(), throwable))
    )
    .flatMap(List::stream)
    .map(Arguments::of);