### Question:
AutoIndex { static Optional<AutoIndex> parseIndex(Map<String, Object> indexRow, String version) { Pattern pattern; Matcher matcher; String description = (String) indexRow.get("description"); String indexType = (String) indexRow.get("type"); if (indexType != null && indexType.toLowerCase(Locale.ENGLISH).contains("fulltext")) { logger.warn("Ignoring unsupported index type {}.", indexType); return Optional.empty(); } if (version.compareTo("4.0") < 0) { if (indexType.equals("node_unique_property")) { return empty(); } pattern = compile("INDEX ON :(?<label>.*)\\((?<property>.*)\\)"); matcher = pattern.matcher(description); if (matcher.matches()) { String label = matcher.group("label"); String[] properties = matcher.group("property").split(","); for (int i = 0; i < properties.length; i++) { properties[i] = properties[i].trim(); } if (properties.length > 1) { return of(new AutoIndex(IndexType.COMPOSITE_INDEX, label, properties)); } else { return of(new AutoIndex(SINGLE_INDEX, label, properties)); } } } if (indexRow.containsKey("uniqueness")) { String indexUniqueness = (String) indexRow.get("uniqueness"); if (indexUniqueness.equals("UNIQUE")) { return empty(); } } if (indexRow.containsKey("properties") && indexRow.containsKey("labelsOrTypes")) { String[] indexProperties = (String[]) indexRow.get("properties"); String indexLabel = ((String[]) indexRow.get("labelsOrTypes"))[0]; return of(new AutoIndex(indexProperties.length > 1 ? COMPOSITE_INDEX : SINGLE_INDEX, indexLabel, indexProperties)); } logger.warn("Could not parse index of type {} with description {}", indexType, description); return empty(); } AutoIndex(IndexType type, String owningType, String[] properties); String[] getProperties(); String getOwningType(); IndexType getType(); Statement getDropStatement(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); boolean hasOpposite(); AutoIndex createOppositeIndex();  }### Answer:
@Test public void parseIndex() { indexRow.put("description", "INDEX ON :Person(name)"); AutoIndex index = AutoIndex.parseIndex(indexRow, "3.5").get(); assertThat(index.getOwningType()).isEqualTo("Person"); assertThat(index.getProperties()).containsOnly("name"); assertThat(index.getType()).isEqualTo(IndexType.SINGLE_INDEX); assertThat(index.getDescription()).isEqualTo("INDEX ON :`Person`(`name`)"); }
@Test public void shouldNotFailOnUnknownIndexType() { indexRow.put("description", "INDEX ON NODE:User(givenName, familyName)"); indexRow.put("indexName", "name"); indexRow.put("tokenNames", new String[] { "User" }); indexRow.put("properties", new String[] { "givenName", "familyName" }); indexRow.put("state", "ONLINE"); indexRow.put("type", "node_fulltext"); indexRow.put("progress", 100.0); Map<String, String> provider = new HashMap<>(); provider.put("version", "1.0"); provider.put("key", "fulltext"); indexRow.put("provider", provider); indexRow.put("id", 3); indexRow.put("failureMessage", ""); Optional<AutoIndex> optionalAutoIndex = AutoIndex.parseIndex(indexRow, "3.5"); assertThat(optionalAutoIndex).isEmpty(); optionalAutoIndex = AutoIndex.parseIndex(indexRow, "4.0"); assertThat(optionalAutoIndex).isEmpty(); }