### Question:
MetadataEntityMapper implements EntityMapper<MetadataEntity> { @Override public XContentBuilder map(final EntityContainer<MetadataEntity> container) { MetadataEntity entity = container.getEntity(); try (XContentBuilder jsonBuilder = XContentFactory.jsonBuilder()) { jsonBuilder.startObject(); jsonBuilder .field(DOC_TYPE_FIELD, SearchDocumentType.METADATA_ENTITY.name()) .field("id", entity.getId()) .field("externalId", entity.getExternalId()) .field("parentId", Optional.ofNullable(entity.getParent()) .map(BaseEntity::getId).orElse(null)) .field("name", StringUtils.defaultString(entity.getName(), entity.getExternalId())); buildEntityClass(entity.getClassEntity(), jsonBuilder); buildPermissions(container.getPermissions(), jsonBuilder); buildMap(prepareEntityMetadata(entity.getData()), jsonBuilder, "fields"); jsonBuilder.endObject(); return jsonBuilder; } catch (IOException e) { throw new IllegalArgumentException("Failed to create elasticsearch document for metadata: ", e); } }  @Override XContentBuilder map(final EntityContainer<MetadataEntity> container);  }### Answer:
@Test void shouldMapMetadataEntity() throws IOException { MetadataEntityMapper mapper = new MetadataEntityMapper(); MetadataClass metadataClass = new MetadataClass(1L, "Sample"); MetadataEntity metadataEntity = new MetadataEntity(); metadataEntity.setClassEntity(metadataClass); metadataEntity.setId(1L); metadataEntity.setExternalId("external"); metadataEntity.setParent(new Folder(1L)); metadataEntity.setName(TEST_NAME); metadataEntity.setData(Collections.singletonMap(TEST_KEY, new PipeConfValue("string", TEST_VALUE))); EntityContainer<MetadataEntity> container = EntityContainer.<MetadataEntity>builder() .entity(metadataEntity) .permissions(PERMISSIONS_CONTAINER) .build(); XContentBuilder contentBuilder = mapper.map(container); verifyMetadataEntity(metadataEntity, EXPECTED_METADATA, contentBuilder); verifyPermissions(PERMISSIONS_CONTAINER, contentBuilder); }