giuseppe-trisciuoglio avatar

Unit Test Mapper Converter

Unit testing patterns for MapStruct mappers and custom converters, covering nulls, round-trips, and nested objects.

CCM score
51 of 100
skills.sh installs
3.9K
GitHub stars
372
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers field mapping accuracy, null handling, type conversions, nested transformations, bidirectional mapping, enum mapping, and partial updates
  • Includes step-by-step guidance for verifying generated classes in target/generated-sources/ or build/generated/sources/ before testing
  • Enforces null-safety checks through nullValueMappingStrategy and round-trip assertions with usingRecursiveComparison()
  • Designed for Java projects using MapStruct that need isolated tests of entity-to-DTO transformation logic

Install

$ npx -y skills add giuseppe-trisciuoglio/developer-kit --skill unit-test-mapper-converter -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Unit Testing Mappers and Converters

Overview

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.

When to Use

  • Writing mapping tests for MapStruct mapper implementations
  • Testing custom entity-to-DTO converters and bean mappings
  • Validating nested object mapping and collection transformations

Instructions

1. Validate Generated Mapper Classes

Before testing, verify generated mapper classes exist:

# Maven
ls target/generated-sources/

# Gradle
ls build/generated/sources/

If generated classes are missing:

  1. Run mvn compile (Maven) or ./gradlew compileJava (Gradle)
  2. Check that the MapStruct annotation processor is configured
  3. Verify @Mapper interfaces are in a compiled source set

2. Test Null Handling

assertThat(mapper.toDto(null)).isNull();

Configure nullValueMappingStrategy in mapper if null should return empty/default.

Details

Repository
github.com/giuseppe-trisciuoglio/developer-kit
Categories
Testing & QA, Java & JVM
First seen
May 16, 2026

More from giuseppe-trisciuoglio/developer-kit

All 95

Similar to Unit Test Mapper Converter

More Testing & QA