giuseppe-trisciuoglio avatar

Unit Test Mapper Converter

This handles the unglamorous but critical work of testing MapStruct mappers and custom converters. It walks you through validating field mappings, null handling, bidirectional transformations, and nested object conversions with concrete patterns for each scenario. The troubleshooting is practical: what to do when generated classes are missing, how to catch asymmetries in entity-to-DTO roundtrips, and why your custom expressions might be failing silently. Includes a complete executable test example with imports so you're not hunting down AssertJ syntax. Honest take: mapper tests feel tedious until a silent mapping bug corrupts data in production, then you wish you'd written them from the start.

skills.sh installs
3.9K
GitHub stars
369
last updated
Aug 21, 2026

Install

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

Installs into .claude/skills of the current project.

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.

Sponsors

Details

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

More from giuseppe-trisciuoglio/developer-kit

All 102
1giuseppe-trisciuoglio avatarunit-test-cachinggiuseppe-trisciuoglio/developer-kitProvides patterns for unit testing Spring Cache annotations (@Cacheable, @CachePut, @CacheEvict). Generates test code that mocks cache managers, verifies cache 3.8Kskills.sh installs
2bmad-labs avatartypescript-e2e-testingbmad-labs/skillsE2E and integration testing for TypeScript/NestJS projects using Jest, supertest, and real infrastructure via Docker (Kafka, PostgreSQL, MongoDB, Redis) with th2.3Kskills.sh installs
3web-infra-dev avatarvitest-midscene-e2eweb-infra-dev/midscene-skillsEnhances Vitest with Midscene for AI-powered UI testing across Web (Playwright), Android (ADB), and iOS (WDA). Scaffolds new projects, converts existing project2.1Kskills.sh installs
4cognitedata avatartest-coveragecognitedata/builder-skillsMUST be used whenever fixing test coverage for a Flows app to meet the 80% line coverage hard gate. This skill finds AND fixes coverage gaps — it configures too1.9Kskills.sh installs
5hieutrtr avatare2e-testinghieutrtr/ai1-skillsEnd-to-end testing patterns with Playwright for full-stack Python/React applications. Use when writing E2E tests for complete user workflows (login, CRUD, navig1.6Kskills.sh installs
6dbt-labs avataradding-dbt-unit-testdbt-labs/dbt-agent-skillsCreates unit test YAML definitions that mock upstream model inputs and validate expected outputs. Use when adding unit tests for a dbt model or practicing test-1.1Kskills.sh installs