Support arrays and maps in verifyEach - #2398
Conversation
Add verifyEach(U[], ...) overloads that delegate to the existing Iterable versions via Arrays.asList, so object arrays can be used directly without wrapping them in a list first.
Add verifyEach(Map<K, V>, ...) overloads that iterate the map's entries. Following Groovy's Map.each idiom, the closure can use zero to three parameters: none (the entry is the delegate, exposing key and value), the entry, key and value, or key, value and index.
Reject an unsupported number of closure parameters (0 to 2 for iterables and arrays, 0 to 3 for maps) with a clear InvalidSpecException before iterating, instead of collecting a confusing per-item failure for each element. A zero-parameter closure asserts against the delegate (the item, or the map entry exposing key and value).
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2398 +/- ##
============================================
+ Coverage 82.28% 82.39% +0.10%
- Complexity 4884 4903 +19
============================================
Files 474 474
Lines 15267 15314 +47
Branches 1964 1968 +4
============================================
+ Hits 12563 12618 +55
+ Misses 2004 1999 -5
+ Partials 700 697 -3
🚀 New features to boost your workflow:
|
3ee054e to
3ce070a
Compare
Add verifyEach overloads accepting java.util.stream.Stream (with and without a namer), adapting the single-use stream to an Iterable that is iterated exactly once.
3ce070a to
a7ef128
Compare
🔎 No tests executed 🔎🏷️ Commit: a7ef128 Learn more about TestLens at testlens.app. |
Extends
verifyEachbeyondIterableso it can also assert on object arrays andMaps.Changes
verifyEachnow accepts object arrays, not onlyIterable.verifyEachaccepts aMap, iterating its entries with Groovy's key/value destructuring, mirroring theMap.eachidiom. The closure can use zero to three parameters:Map.Entryis the delegate, sokey/valueare referenced directlyInvalidSpecExceptionfor an unsupported count (0 to 2 for iterables/arrays) instead of failing with a less obvious error mid-iteration.Docs & tests
VerifyEachBlocks.groovyand a primer doc spec + snapshot.🤖 Generated with Claude Code