Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._4082.jdk21;

import java.util.List;

import org.mapstruct.ap.testutil.IssueKey;
import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.ap.testutil.runner.Compiler;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

@WithClasses({ Source.class, Target.class, SourceMapper.class })
@IssueKey("4082")
class Issue4082Test {

@ProcessorTest(Compiler.JDK)
void shouldMapFirstAndLastFromSequencedCollection() {
Source source = new Source( List.of( "alpha", "beta", "gamma" ) );

Target target = SourceMapper.INSTANCE.map( source );

assertThat( target.getFirst() ).isEqualTo( "alpha" );
assertThat( target.getLast() ).isEqualTo( "gamma" );
}

@ProcessorTest(Compiler.JDK)
void shouldReturnNullWhenItemsListIsNull() {
Source source = new Source( null );

Target target = SourceMapper.INSTANCE.map( source );

assertThat( target.getFirst() ).isNull();
assertThat( target.getLast() ).isNull();
}

@ProcessorTest(Compiler.JDK)
void shouldThrowWhenItemsListIsEmpty() {
Source source = new Source( List.of() );

assertThatThrownBy( () -> SourceMapper.INSTANCE.map( source ) )
.isInstanceOf( java.util.NoSuchElementException.class );
}
Comment on lines +44 to +48
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._4082.jdk21;

import java.util.List;

public class Source {

private List<String> items;

public Source(List<String> items) {
this.items = items;
}

public List<String> getItems() {
return items;
}

public void setItems(List<String> items) {
this.items = items;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._4082.jdk21;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

@Mapper
public interface SourceMapper {

SourceMapper INSTANCE = Mappers.getMapper( SourceMapper.class );

@Mapping(source = "items.first", target = "first")
@Mapping(source = "items.last", target = "last")
Target map(Source source);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.bugs._4082.jdk21;

public class Target {

private String first;
private String last;

public String getFirst() {
return first;
}

public void setFirst(String first) {
this.first = first;
}

public String getLast() {
return last;
}

public void setLast(String last) {
this.last = last;
}
}
Loading