Skip to content

Add tests for SequencedCollection getFirst/getLast nested property mapping (#4082) - #4098

Open
klouds27 wants to merge 1 commit into
mapstruct:mainfrom
klouds27:issue-4082-sequenced-collection-tests
Open

Add tests for SequencedCollection getFirst/getLast nested property mapping (#4082)#4098
klouds27 wants to merge 1 commit into
mapstruct:mainfrom
klouds27:issue-4082-sequenced-collection-tests

Conversation

@klouds27

Copy link
Copy Markdown

Closes #4082

Adds @ProcessorTest(Compiler.JDK) tests covering source="items.first" and source="items.last" nested property paths on a List field.

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 (NoSuchElementException from getFirst() on an empty list).

Note: --release < 21 suppresses these methods from the javax.lang.model view of List via CT.sym, so the tests are JDK-only. With JDK 21 as MapStruct's minimum, the feature resolves correctly in all supported environments.

…#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>
@klouds27
klouds27 marked this pull request as ready for review July 17, 2026 10:53
Copilot AI review requested due to automatic review settings July 17, 2026 10:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and SourceMapper fixtures for items.first / items.last mapping.
  • 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 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Java21 SequencedCollection::getFirst support

2 participants