I'm working on a weird issue, I was doing integration testing, calling my controller to get an object from database that doesn't exist.
public Optional<T> get(Long id) {
try {
return Optional.ofNullable(repository.getOne(id));
} catch(EntityNotFoundException e) {
return Optional.empty();
}
}
When getOne(…)
is not able to find anything, I was expecting an EntityNotFoundException
but actually nothing. If I inspect my result I can see that I have an empty entity with a handler link to it "threw EntityNotFoundException
" but we don't go in the catch and I return an optional of this weird entity.
I can't understand this behavior.