Generates unit tests for MapStruct mappers and custom converters. Validates entity-to-DTO transformations, null handling, bidirectional mapping, nested objects, enums, and collections.
From developer-kit-javanpx claudepluginhub giuseppe-trisciuoglio/developer-kit --plugin developer-kit-javaThis skill is limited to using the following tools:
references/examples.mdSearches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Searches prompts.chat for AI prompt templates by keyword or category, retrieves by ID with variable handling, and improves prompts via AI. Use for discovering or enhancing prompts.
Designs and optimizes AI agent action spaces, tool definitions, observation formats, error recovery, and context for higher task completion rates.
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