I have the following code and it works as expected:
Optional.ofNullable(testItem.getId())
.map(testItemRepository::get)
.orElseThrow(() -> new TestException(ReturnCode.UNKNOWN_ID))
.orElseThrow(() -> new TestException(ReturnCode.UNKNOWN_ID));
I would like to know if there is a way to just have one orElseThrow-Part or do it less redundant ?