Help us improve
Share bugs, ideas, or general feedback.
From developer-kit-java
Generates unit tests for MapStruct mappers and custom converters. Validates entity-to-DTO transformations, null handling, bidirectional mapping, nested objects, enums, and collections.
npx claudepluginhub giuseppe-trisciuoglio/developer-kit --plugin developer-kit-javaHow this skill is triggered — by the user, by Claude, or both
Slash command
/developer-kit-java:unit-test-mapper-converterThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Provides patterns for unit testing MapStruct mappers and custom converter classes. Covers field mapping accuracy, null handling, type conversions, nested object transformations, bidirectional mapping, enum mapping, and partial updates.
Creates a mapper (MapStruct interface or custom converter) between an entity and a DTO. Useful during CRUD setup or after DTO creation in Spring applications.
Provides patterns for unit testing JSON serialization/deserialization using Jackson and @JsonTest in Spring Boot apps. Validates POJOs, custom serializers, dates, and polymorphic types.
Generates JUnit 5 unit tests with Mockito and Testcontainers integration tests for Java services, repositories, controllers, and utilities. Auto-detects Maven/Gradle/Spring Boot setup from build files.
Share bugs, ideas, or general feedback.
Provides patterns for unit testing MapStruct mappers and custom converter classes. Covers field mapping accuracy, null handling, type conversions, nested object transformations, bidirectional mapping, enum mapping, and partial updates.
Before testing, verify generated mapper classes exist:
# Maven
ls target/generated-sources/
# Gradle
ls build/generated/sources/
If generated classes are missing:
mvn compile (Maven) or ./gradlew compileJava (Gradle)@Mapper interfaces are in a compiled source setassertThat(mapper.toDto(null)).isNull();
Configure nullValueMappingStrategy in mapper if null should return empty/default.
If null tests fail:
nullValueMappingStrategy = NullValueMappingStrategy.RETURN_NULL to @MappernullValuePropertyMappingStrategy for nested property handlingUser restored = mapper.toEntity(mapper.toDto(original));
assertThat(restored).usingRecursiveComparison().isEqualTo(original);
If bidirectional tests fail:
@Mapping annotations for field name mismatchesunmappedTargetPolicy = ReportingPolicy.ERROR to catch missing mappingsassertThat(dto.getNested()).usingRecursiveComparison().isEqualTo(expected);
If nested tests fail:
uses = NestedMapper.classelementMappingStrategyCustom expressions in @Mapping(target = "field", expression = "java(...)") are not compile-time validated.
If expression tests fail:
Use @ValueMapping for enum-to-enum translations. Test all enum values exhaustively.
Mappers.getMapper() for standalone tests, Spring injection for integration testsusingRecursiveComparison() for complex nested structuresnullValueMappingStrategy and nullValuePropertyMappingStrategy appropriately@Mapping are not validated at compile time—test them explicitlyComplete executable test with imports:
package com.example.mapper;
import org.junit.jupiter.api.Test;
import org.mapstruct.factory.Mappers;
import static org.assertj.core.api.Assertions.*;
class UserMapperCompleteTest {
private final UserMapper mapper = Mappers.getMapper(UserMapper.class);
@Test
void shouldMapUserToDto() {
User user = new User(1L, "Alice", "alice@example.com", 25);
UserDto dto = mapper.toDto(user);
assertThat(dto)
.isNotNull()
.extracting(UserDto::getName, UserDto::getEmail)
.containsExactly("Alice", "alice@example.com");
}
@Test
void shouldMaintainRoundTrip() {
User original = new User(1L, "Alice", "alice@example.com", 25);
assertThat(mapper.toEntity(mapper.toDto(original)))
.usingRecursiveComparison()
.isEqualTo(original);
}
@Test
void shouldHandleNullInput() {
assertThat(mapper.toDto(null)).isNull();
}
}
Additional examples in: references/examples.md