### Question:
ToolMapper implements EntityMapper<ToolWithDescription> { @Override public XContentBuilder map(final EntityContainer<ToolWithDescription> doc) { try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) { final Tool tool = doc.getEntity().getTool(); final ToolDescription toolDescription = doc.getEntity().getToolDescription(); jsonBuilder .startObject() .field(DOC_TYPE_FIELD, SearchDocumentType.TOOL.name()) .field("id", tool.getId()) .field("registry", tool.getRegistry()) .field("registryId", tool.getRegistryId()) .field("image", tool.getImage()) .field("createdDate", parseDataToString(tool.getCreatedDate())) .field("description", tool.getDescription()) .field("shortDescription", tool.getShortDescription()) .field("defaultCommand", tool.getDefaultCommand()) .field("toolGroupId", tool.getToolGroupId()); buildLabels(tool.getLabels(), jsonBuilder); buildVersions(toolDescription, jsonBuilder); buildPackages(toolDescription, jsonBuilder); buildUserContent(doc.getOwner(), jsonBuilder); buildMetadata(doc.getMetadata(), jsonBuilder); buildPermissions(doc.getPermissions(), jsonBuilder); jsonBuilder.endObject(); return jsonBuilder; } catch (IOException e) { throw new IllegalArgumentException("Failed to create elasticsearch document for tool: ", e); } }  @Override XContentBuilder map(final EntityContainer<ToolWithDescription> doc);  }### Answer:
@Test void shouldMapTool() throws IOException { ToolMapper mapper = new ToolMapper(); Tool tool = new Tool(); tool.setId(1L); tool.setRegistry(TEST_NAME); tool.setRegistryId(1L); tool.setImage(TEST_PATH); tool.setDescription(TEST_DESCRIPTION); tool.setDefaultCommand(TEST_CMD); tool.setToolGroupId(1L); tool.setLabels(Collections.singletonList(TEST_LABEL)); final ToolDescription toolDescription = new ToolDescription(); toolDescription.setVersions(Collections.singletonList(new ToolVersionAttributes())); toolDescription.setToolId(tool.getId()); EntityContainer<ToolWithDescription> container = EntityContainer.<ToolWithDescription>builder() .entity(new ToolWithDescription(tool, toolDescription)) .owner(USER) .metadata(METADATA) .permissions(PERMISSIONS_CONTAINER) .build(); XContentBuilder contentBuilder = mapper.map(container); verifyTool(tool, contentBuilder); verifyPipelineUser(USER, contentBuilder); verifyPermissions(PERMISSIONS_CONTAINER, contentBuilder); verifyMetadata(EXPECTED_METADATA, contentBuilder); }