### Question:
EntityId { public static <T extends EntityId> T fromMetadataEntity(MetadataEntity metadataEntity) { EntityType.valueOf(metadataEntity.getType().toUpperCase()); return getSelfOrParentEntityId(metadataEntity); } protected  EntityId(EntityType entity); static void ensureValidId(String propertyName, String name); static void ensureValidArtifactId(String propertyName, String name); static boolean isValidId(String name); static boolean isValidArtifactId(String name); static void ensureValidDatasetId(String propertyName, String datasetId); static boolean isValidDatasetId(String datasetId); static void ensureValidNamespace(String namespace); static boolean isValidNamespace(String namespace); static boolean isValidVersionId(String datasetId); abstract Iterable<String> toIdParts(); abstract String getEntityName(); MetadataEntity toMetadataEntity(); static T fromMetadataEntity(MetadataEntity metadataEntity); static T getSelfOrParentEntityId(MetadataEntity metadataEntity); final EntityType getEntityType(); static T fromString(String string); @Override final String toString(); @Override boolean equals(Object o); @Override int hashCode(); Iterable<EntityId> getHierarchy(); static final String IDSTRING_TYPE_SEPARATOR; static final String IDSTRING_PART_SEPARATOR; static final Pattern IDSTRING_PART_SEPARATOR_PATTERN; }### Answer:
@Test public void testFromMetadataEntity() { ApplicationId applicationId = new ApplicationId("testNs", "app1"); Assert.assertEquals(applicationId, EntityId.fromMetadataEntity(applicationId.toMetadataEntity())); MetadataEntity metadataEntity = MetadataEntity.builder().append(MetadataEntity.NAMESPACE, "testNs") .appendAsType(MetadataEntity.APPLICATION, "app1").build(); Assert.assertEquals(applicationId, EntityId.fromMetadataEntity(metadataEntity)); metadataEntity = MetadataEntity.builder(MetadataEntity.ofDataset("testNs", "testDs")) .appendAsType("field", "testField").build(); try { EntityId.fromMetadataEntity(metadataEntity); Assert.fail("Should have failed to get create an EntityId from MetadataEntity"); } catch (IllegalArgumentException e) { } ProgramId programId = new ProgramId(applicationId, ProgramType.WORKER, "testWorker"); Assert.assertEquals(programId, EntityId.fromMetadataEntity(programId.toMetadataEntity())); ArtifactId artifactId = new ArtifactId("testNs", "testArtifact-1.0.0.jar"); Assert.assertEquals(artifactId, EntityId.fromMetadataEntity(artifactId.toMetadataEntity())); ScheduleId scheduleId = applicationId.schedule("sch"); metadataEntity = MetadataEntity.builder().append(MetadataEntity.NAMESPACE, "testNs") .append(MetadataEntity.APPLICATION, "app1").appendAsType(MetadataEntity.SCHEDULE, "sch").build(); Assert.assertEquals(scheduleId, EntityId.fromMetadataEntity(metadataEntity)); }