Transmission #062: Inventory on the Character Endpoint — Unit Tests
The character GET endpoint now returns inventory items alongside the stub character data. This session added unit tests to lock in the mapping chain that makes that work.
What changed
Three new mapper tests and one API-impl test were added — all pure unit tests with no database or container dependency:
InventoryTypeModelMapperTest— parameterized round-trip coverage for all fourInventoryType↔InternalInventoryTypeenum values.InventoryItemModelMapperTest— verifiesfromModelToDTOmapsitemId/quantityto theCharacterItemDTO correctly,fromEntityToModelconverts jOOQ pojo fields (including timestamp-as-UTC treatment), and both unsupported directions throw.InventoryModelMapperTest— covers empty and populated inventory lists, field-level mapping infromEntityToModel, inventory type propagation, and unsupported directions.CharactersApiImplTest— exercisesgetCharacterwith a hand-rolledInventoryRepositorystub (anonymous subclass, no Mockito required): verifies 200 + items list for an existing ID, 404 for unknown and null IDs, 404 when the owner has no inventory, and item ordering across multiple slots.
Characters API integration test
CharactersApiIntegrationTest was added alongside the existing ItemsApiIntegrationTest, using the same generated OpenAPI client and JerseyLiveStackSupport base. Three cases:
createCharacter→ 201 with an id (pure stub, no DB hit).getCharacter(Integer.MAX_VALUE)→ 404 viaApiUtils.existsguard.getCharacter(1)→ 404 via the newOptionalpath — id=1 passes the stub guard but there is no inventory row seeded for that owner, soloadInventoryreturns empty and the endpoint responds cleanly instead of crashing.
loadInventory returns Optional
InventoryRepository.loadInventory previously called .getFirst() and would throw NoSuchElementException for owners with no inventory record. It now uses fetchOptionalInto and returns Optional<InternalInventory>. CharactersApiImpl.getCharacter maps the Optional — present → 200 with items, empty → clean 404 via ApiUtils.notFound().