Refactor test using Optional.