unit-test-mapper-converter

Generates unit tests for MapStruct mappers and custom entity-to-DTO converters.

Updated Jun 28, 2026
One-click install
npx skills add https://github.com/412181-HerediaLara/ScaffoldingBE-FE --skill unit-test-mapper-converter-412181-heredialara
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unit-test-mapper-converter
Source: https://github.com/412181-HerediaLara/ScaffoldingBE-FE/tree/main/BE/.agents/skills/unit-test-mapper-converter
Command: npx skills add https://github.com/412181-HerediaLara/ScaffoldingBE-FE --skill unit-test-mapper-converter-412181-heredialara

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing tests for mappers and converters is often skipped or done superficially, leaving entity-to-DTO transformation bugs (null handling, nested objects, enum mismatches) undetected until runtime. This Skill provides structured patterns and executable examples for testing mapping logic in isolation. ## Core Features & Use Cases - MapStruct Mapper Testing: Validate generated mapper classes, field mapping accuracy, bidirectional round-trips, and collection transformations. - Custom Converter Testing: Test custom type converters, date formatters, and expression-based mappings that are not compile-time validated. - Edge Case Coverage: Handle null inputs, nested objects, enum mappings via @ValueMapping, and partial updates with @MappingTarget. - Use Case: You have a Spring Boot backend with MapStruct mappers converting JPA entities to DTOs. Use this Skill to generate tests that verify round-trip fidelity, null handling, and nested object mapping before merging. ## Quick Start Write unit tests for my UserMapper interface covering null handling, bidirectional mapping, and nested address objects.

Frequently Asked Questions about unit-test-mapper-converter

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I unit test a MapStruct mapper in Java?

Obtain the mapper instance with Mappers.getMapper() for standalone tests, then assert field mappings with AssertJ. Test null inputs, bidirectional round-trips using usingRecursiveComparison(), and verify generated classes exist in target/generated-sources after compilation.

How to test bidirectional entity-to-DTO mapping?

Map an entity to its DTO and back, then compare the restored object to the original using AssertJ's usingRecursiveComparison(). Set unmappedTargetPolicy = ReportingPolicy.ERROR on the @Mapper annotation to catch missing field mappings at compile time.

Why is my MapStruct generated implementation class missing?

Generated classes appear only after compilation. Run mvn compile or ./gradlew compileJava, verify the MapStruct annotation processor is configured in your build, and confirm the @Mapper interfaces are in a compiled source set.

Does MapStruct validate expressions in @Mapping at compile time?

No, expressions like @Mapping(target = "field", expression = "java(...)") are not compile-time validated. Test them explicitly by asserting the computed output values, and verify imported classes are accessible from the expression context.

How do I test enum mapping with @ValueMapping?

Write a test per mapped value asserting the expected target enum, plus an exhaustive test iterating over all source enum values with values() to confirm none map to null. This catches unmapped constants when new enum values are added.

What are the limitations of MapStruct mapper testing?

MapStruct cannot handle circular dependencies between mappers, and immutable collections may need special configuration. Date and time mappings should be verified across timezones, and null handling depends on the configured nullValueMappingStrategy.