Add tests for SequencedCollection getFirst/getLast nested property mapping (#4082) - #4098
Open
klouds27 wants to merge 1 commit into
Open
Add tests for SequencedCollection getFirst/getLast nested property mapping (#4082)#4098klouds27 wants to merge 1 commit into
klouds27 wants to merge 1 commit into
Conversation
…#4082) Verify that source="items.first" and source="items.last" correctly resolve to List.getFirst() / List.getLast() when compiled under JDK 21, and document the null-list safety and empty-list NoSuchElementException behavior of the generated code. Signed-off-by: klouds27 <adalwolf@gmail.com>
There was a problem hiding this comment.
Pull request overview
Adds JDK 21-only processor tests to validate nested property-path mappings using items.first / items.last against List (SequencedCollection) sources, covering normal, null, and empty-list behaviors.
Changes:
- Added
Source,Target, andSourceMapperfixtures foritems.first/items.lastmapping. - Added
@ProcessorTest(Compiler.JDK)test coverage for happy path, null list, and empty list behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| processor/src/test/java/org/mapstruct/ap/test/bugs/_4082/jdk21/Target.java | Target bean with first / last properties for assertions. |
| processor/src/test/java/org/mapstruct/ap/test/bugs/_4082/jdk21/SourceMapper.java | Mapper exercising source="items.first" and source="items.last". |
| processor/src/test/java/org/mapstruct/ap/test/bugs/_4082/jdk21/Source.java | Source bean with List<String> items used by the tests. |
| processor/src/test/java/org/mapstruct/ap/test/bugs/_4082/jdk21/Issue4082Test.java | JDK-only tests validating mapping and edge cases for SequencedCollection accessors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+44
to
+48
| Source source = new Source( List.of() ); | ||
|
|
||
| assertThatThrownBy( () -> SourceMapper.INSTANCE.map( source ) ) | ||
| .isInstanceOf( java.util.NoSuchElementException.class ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4082
Adds
@ProcessorTest(Compiler.JDK)tests coveringsource="items.first"andsource="items.last"nested property paths on aListfield.The three tests cover the happy path (three-element list maps first and last correctly), null-list safety (generated null guard returns null), and empty-list behavior (
NoSuchElementExceptionfromgetFirst()on an empty list).Note:
--release < 21suppresses these methods from thejavax.lang.modelview ofListvia CT.sym, so the tests are JDK-only. With JDK 21 as MapStruct's minimum, the feature resolves correctly in all supported environments.