feat(interop): add Result.fromOptional and Try.fromOptional (#45)#60
feat(interop): add Result.fromOptional and Try.fromOptional (#45)#60
Result.fromOptional and Try.fromOptional (#45)#60Conversation
Bridge `java.util.Optional` to both `Result` and `Try`: - `Result.fromOptional(Optional<V>)` → `Result<V, NoSuchElementException>` - `Try.fromOptional(Optional<V>, Supplier<Throwable>)` → `Try<V>` Includes null-guard validation and 7 new tests in `InteropTest`.
📝 WalkthroughWalkthroughAdded factory methods to Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/src/test/java/codes/domix/fun/InteropTest.java (1)
168-178: Add one test forexceptionSupplierreturningnull.This is a useful edge case to pin the Line 697 contract in
Try.fromOptional.Proposed test addition
`@Test` void try_fromOptional_nullSupplier_throwsNPE() { assertThrows(NullPointerException.class, () -> Try.fromOptional(Optional.empty(), null)); } + +@Test +void try_fromOptional_supplierReturningNull_throwsNPE() { + assertThrows(NullPointerException.class, + () -> Try.fromOptional(Optional.empty(), () -> null)); +}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/src/test/java/codes/domix/fun/InteropTest.java` around lines 168 - 178, Add a test that verifies Try.fromOptional throws a NullPointerException when the provided exceptionSupplier returns null: create a new test method (e.g., try_fromOptional_exceptionSupplierReturningNull_throwsNPE) that calls Try.fromOptional(Optional.empty(), () -> null) and uses assertThrows(NullPointerException.class, ...) to assert the behavior; reference the Try.fromOptional method and the exceptionSupplier lambda in the test so the edge case at the method's contract is covered.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@lib/src/test/java/codes/domix/fun/InteropTest.java`:
- Around line 168-178: Add a test that verifies Try.fromOptional throws a
NullPointerException when the provided exceptionSupplier returns null: create a
new test method (e.g.,
try_fromOptional_exceptionSupplierReturningNull_throwsNPE) that calls
Try.fromOptional(Optional.empty(), () -> null) and uses
assertThrows(NullPointerException.class, ...) to assert the behavior; reference
the Try.fromOptional method and the exceptionSupplier lambda in the test so the
edge case at the method's contract is covered.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6a168317-6fab-4535-90a1-822f69c20059
📒 Files selected for processing (3)
lib/src/main/java/codes/domix/fun/Result.javalib/src/main/java/codes/domix/fun/Try.javalib/src/test/java/codes/domix/fun/InteropTest.java
|
Bridge
java.util.Optionalto bothResultandTry:Result.fromOptional(Optional<V>)→Result<V, NoSuchElementException>Try.fromOptional(Optional<V>, Supplier<Throwable>)→Try<V>Includes null-guard validation and 7 new tests in
InteropTest.Pull Request
📌 Summary
Briefly describe the purpose of this pull request and what problem it solves.
✅ Checklist
Please check all that apply:
🔗 Related Issues
Closes #45
Fixes #[issue-number]
(Related but not closing: #[issue-number])
💬 Additional Notes
Any other context, screenshots, design decisions, or points to be reviewed carefully.
Summary by CodeRabbit
Release Notes
New Features
Tests