mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
#2375 Add records cross module integration test
This commit is contained in:
parent
857f87276f
commit
9ce9d4fb3a
@ -109,6 +109,13 @@ public class MavenIntegrationTest {
|
|||||||
void recordsTest() {
|
void recordsTest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ProcessorTest(baseDir = "recordsCrossModuleTest", processorTypes = {
|
||||||
|
ProcessorTest.ProcessorType.JAVAC
|
||||||
|
})
|
||||||
|
@EnabledForJreRange(min = JRE.JAVA_17)
|
||||||
|
void recordsCrossModuleTest() {
|
||||||
|
}
|
||||||
|
|
||||||
@ProcessorTest(baseDir = "kotlinDataTest", processorTypes = {
|
@ProcessorTest(baseDir = "kotlinDataTest", processorTypes = {
|
||||||
ProcessorTest.ProcessorType.JAVAC
|
ProcessorTest.ProcessorType.JAVAC
|
||||||
}, forkJvm = true)
|
}, forkJvm = true)
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
Copyright MapStruct Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
-->
|
||||||
|
<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">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<artifactId>recordsCrossModuleTest</artifactId>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>records-cross-module-api</artifactId>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,13 @@
|
|||||||
|
/*
|
||||||
|
* Copyright MapStruct Authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*/
|
||||||
|
package org.mapstruct.itest.records.api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
public record CustomerDto(String name, String email) {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
Copyright MapStruct Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
-->
|
||||||
|
<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">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<artifactId>recordsCrossModuleTest</artifactId>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>records-cross-module-mapper</artifactId>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>records-cross-module-api</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright MapStruct Authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*/
|
||||||
|
package org.mapstruct.itest.records.mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
public class CustomerEntity {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String mail;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMail() {
|
||||||
|
return mail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMail(String mail) {
|
||||||
|
this.mail = mail;
|
||||||
|
}
|
||||||
|
}
|
@ -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.itest.records.mapper;
|
||||||
|
|
||||||
|
import org.mapstruct.InheritInverseConfiguration;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.Mapping;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
import org.mapstruct.itest.records.api.CustomerDto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Filip Hrisafov
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface CustomerMapper {
|
||||||
|
|
||||||
|
CustomerMapper INSTANCE = Mappers.getMapper( CustomerMapper.class );
|
||||||
|
|
||||||
|
@Mapping(target = "mail", source = "email")
|
||||||
|
CustomerEntity fromRecord(CustomerDto record);
|
||||||
|
|
||||||
|
@InheritInverseConfiguration
|
||||||
|
CustomerDto toRecord(CustomerEntity entity);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright MapStruct Authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*/
|
||||||
|
package org.mapstruct.itest.records.mapper;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mapstruct.itest.records.api.CustomerDto;
|
||||||
|
import org.mapstruct.itest.records.mapper.CustomerEntity;
|
||||||
|
import org.mapstruct.itest.records.mapper.CustomerMapper;
|
||||||
|
|
||||||
|
public class RecordsTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldMapRecord() {
|
||||||
|
CustomerEntity customer = CustomerMapper.INSTANCE.fromRecord( new CustomerDto( "Kermit", "kermit@test.com" ) );
|
||||||
|
|
||||||
|
assertThat( customer ).isNotNull();
|
||||||
|
assertThat( customer.getName() ).isEqualTo( "Kermit" );
|
||||||
|
assertThat( customer.getMail() ).isEqualTo( "kermit@test.com" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldMapIntoRecord() {
|
||||||
|
CustomerEntity entity = new CustomerEntity();
|
||||||
|
entity.setName( "Kermit" );
|
||||||
|
entity.setMail( "kermit@test.com" );
|
||||||
|
|
||||||
|
CustomerDto customer = CustomerMapper.INSTANCE.toRecord( entity );
|
||||||
|
|
||||||
|
assertThat( customer ).isNotNull();
|
||||||
|
assertThat( customer.name() ).isEqualTo( "Kermit" );
|
||||||
|
assertThat( customer.email() ).isEqualTo( "kermit@test.com" );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
Copyright MapStruct Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
-->
|
||||||
|
<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">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.mapstruct</groupId>
|
||||||
|
<artifactId>mapstruct-it-parent</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>recordsCrossModuleTest</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
<module>api</module>
|
||||||
|
<module>mapper</module>
|
||||||
|
</modules>
|
||||||
|
</project>
|
Loading…
x
Reference in New Issue
Block a user