【发布时间】:2020-05-11 19:08:56
【问题描述】:
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
我错过了一步吗?标题错了吗?我注意到它正在寻找大写标题......但即使这样它也没有找到
【问题讨论】:
-
我会确保您正在加载您认为正在加载的文件。
-
@Deadron 嗯。我想我可以/应该在调试器中单步执行它,但是当
RuntimeException抛出它时,它里面有那个文件名。 -
@Deadron 是的,它肯定在查看那个文件