### Question:
Parser { @SneakyThrows @SuppressWarnings({"PMD.ShortMethodName", "rawtypes"}) public static <T> T as(Object element, Class<T> objectClass) { Class<?> elementType = element.getClass(); if (is(elementType, objectClass)) { return (T) element; } for (ElementParser elementParser : ELEMENT_PARSERS) { if (is(elementType, elementParser.elementType())) { return (T) elementParser.as(element, objectClass); } } if (objectClass.isEnum()) { return (T) Enum.valueOf((Class<Enum>) objectClass, (String) element); } throw Query.Exceptions.invalidObjectType(element, objectClass); } private  Parser(); static void registerElementParser(ElementParser<?> elementParser); static boolean isPropertyValue(Field field); @SneakyThrows @SuppressWarnings({"PMD.ShortMethodName", "rawtypes"}) static T as(Object element, Class<T> objectClass);  }### Answer:
@Test public void testAsEnum() { assertEquals(MERGE, as("MERGE", Should.class)); }
@Test public void testAsItself() { assertEquals(MERGE, as(MERGE, Should.class)); }
@Test(expected = ClassCastException.class) public void testAsUnhandled() { assertEquals(Collections.emptyList(), as(new ArrayList<>(), Person.class)); }
@Test public void testAsVertex() { assertEquals(marko, as(new DetachedVertex( 1, "person", new HashMap<String, Object>() { { put("name", Arrays.asList(new HashMap<String, Object>() { { put("value", "marko"); } })); put("age", Arrays.asList(new HashMap<String, Object>() { { put("value", 29); } })); } }), Person.class)); }
@Test public void testAsEdge() { assertEquals(develops, as(new DetachedEdge( null, Label.of(Develops.class), new HashMap<String, Object>() { { put("since", develops.since()); } }, null, null, null, null), Develops.class)); }