我必须将选项转换为可选,并为此创建了代码,但我相信不使用私有方法可能会更短。
Optional<Long> optionalLong ;
Optional<Instant> optionalInstant;
assertThat(createdOrder.acceptedTime, is( OptionalLongToOptionalInstant(expectedOrder.acceptedTime())));
private Optional<Instant> OptionalLongToOptionalInstant(Optional<Long> optionalLong ) {
if(optionalLong.isPresent()){
return Optional.of(Instant.ofEpochMilli(optionalLong.get()));
}
return Optional.empty();
}