Skip to content

Commit 9ce9d4f

Browse files
committed
mapstruct#2375 Add records cross module integration test
1 parent 857f872 commit 9ce9d4f

File tree

8 files changed

+196
-0
lines changed

8 files changed

+196
-0
lines changed

integrationtest/src/test/java/org/mapstruct/itest/tests/MavenIntegrationTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ void protobufBuilderTest() {
109109
void recordsTest() {
110110
}
111111

112+
@ProcessorTest(baseDir = "recordsCrossModuleTest", processorTypes = {
113+
ProcessorTest.ProcessorType.JAVAC
114+
})
115+
@EnabledForJreRange(min = JRE.JAVA_17)
116+
void recordsCrossModuleTest() {
117+
}
118+
112119
@ProcessorTest(baseDir = "kotlinDataTest", processorTypes = {
113120
ProcessorTest.ProcessorType.JAVAC
114121
}, forkJvm = true)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright MapStruct Authors.
5+
6+
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
7+
8+
-->
9+
<project xmlns="http://maven.apache.org/POM/4.0.0"
10+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
11+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
12+
<modelVersion>4.0.0</modelVersion>
13+
14+
<parent>
15+
<artifactId>recordsCrossModuleTest</artifactId>
16+
<groupId>org.mapstruct</groupId>
17+
<version>1.0.0</version>
18+
</parent>
19+
20+
<artifactId>records-cross-module-api</artifactId>
21+
22+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.mapstruct.itest.records.api;
7+
8+
/**
9+
* @author Filip Hrisafov
10+
*/
11+
public record CustomerDto(String name, String email) {
12+
13+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright MapStruct Authors.
5+
6+
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
7+
8+
-->
9+
<project xmlns="http://maven.apache.org/POM/4.0.0"
10+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
11+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
12+
<modelVersion>4.0.0</modelVersion>
13+
14+
<parent>
15+
<artifactId>recordsCrossModuleTest</artifactId>
16+
<groupId>org.mapstruct</groupId>
17+
<version>1.0.0</version>
18+
</parent>
19+
20+
<artifactId>records-cross-module-mapper</artifactId>
21+
22+
23+
<dependencies>
24+
<dependency>
25+
<groupId>org.mapstruct</groupId>
26+
<artifactId>records-cross-module-api</artifactId>
27+
<version>1.0.0</version>
28+
</dependency>
29+
</dependencies>
30+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.mapstruct.itest.records.mapper;
7+
8+
/**
9+
* @author Filip Hrisafov
10+
*/
11+
public class CustomerEntity {
12+
13+
private String name;
14+
private String mail;
15+
16+
public String getName() {
17+
return name;
18+
}
19+
20+
public void setName(String name) {
21+
this.name = name;
22+
}
23+
24+
public String getMail() {
25+
return mail;
26+
}
27+
28+
public void setMail(String mail) {
29+
this.mail = mail;
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.mapstruct.itest.records.mapper;
7+
8+
import org.mapstruct.InheritInverseConfiguration;
9+
import org.mapstruct.Mapper;
10+
import org.mapstruct.Mapping;
11+
import org.mapstruct.factory.Mappers;
12+
import org.mapstruct.itest.records.api.CustomerDto;
13+
14+
/**
15+
* @author Filip Hrisafov
16+
*/
17+
@Mapper
18+
public interface CustomerMapper {
19+
20+
CustomerMapper INSTANCE = Mappers.getMapper( CustomerMapper.class );
21+
22+
@Mapping(target = "mail", source = "email")
23+
CustomerEntity fromRecord(CustomerDto record);
24+
25+
@InheritInverseConfiguration
26+
CustomerDto toRecord(CustomerEntity entity);
27+
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.mapstruct.itest.records.mapper;
7+
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
10+
import org.junit.Test;
11+
import org.mapstruct.itest.records.api.CustomerDto;
12+
import org.mapstruct.itest.records.mapper.CustomerEntity;
13+
import org.mapstruct.itest.records.mapper.CustomerMapper;
14+
15+
public class RecordsTest {
16+
17+
@Test
18+
public void shouldMapRecord() {
19+
CustomerEntity customer = CustomerMapper.INSTANCE.fromRecord( new CustomerDto( "Kermit", "[email protected]" ) );
20+
21+
assertThat( customer ).isNotNull();
22+
assertThat( customer.getName() ).isEqualTo( "Kermit" );
23+
assertThat( customer.getMail() ).isEqualTo( "[email protected]" );
24+
}
25+
26+
@Test
27+
public void shouldMapIntoRecord() {
28+
CustomerEntity entity = new CustomerEntity();
29+
entity.setName( "Kermit" );
30+
entity.setMail( "[email protected]" );
31+
32+
CustomerDto customer = CustomerMapper.INSTANCE.toRecord( entity );
33+
34+
assertThat( customer ).isNotNull();
35+
assertThat( customer.name() ).isEqualTo( "Kermit" );
36+
assertThat( customer.email() ).isEqualTo( "[email protected]" );
37+
}
38+
39+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright MapStruct Authors.
5+
6+
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
7+
8+
-->
9+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<parent>
13+
<groupId>org.mapstruct</groupId>
14+
<artifactId>mapstruct-it-parent</artifactId>
15+
<version>1.0.0</version>
16+
<relativePath>../pom.xml</relativePath>
17+
</parent>
18+
19+
<artifactId>recordsCrossModuleTest</artifactId>
20+
<packaging>pom</packaging>
21+
22+
<modules>
23+
<module>api</module>
24+
<module>mapper</module>
25+
</modules>
26+
</project>

0 commit comments

Comments
 (0)