DatastoreV1 { static boolean isValidKey(Key key) { List<PathElement> elementList = key.getPathList(); if (elementList.isEmpty()) { return false; } PathElement lastElement = elementList.get(elementList.size() - 1); return (lastElement.getId() != 0 || !lastElement.getName().isEmpty()); } DatastoreV1(); DatastoreV1.Read read(); Write write(); DeleteEntity deleteEntity(); DeleteKey deleteKey();  }
@Test public void testHasNameOrId() { Key key; key = makeKey("bird", "finch").build(); assertTrue(isValidKey(key)); key = makeKey("bird", 123).build(); assertTrue(isValidKey(key)); key = makeKey("bird").build(); assertFalse(isValidKey(key)); key = makeKey("bird", "owl").build(); key = makeKey(key, "bird", "horned").build(); assertTrue(isValidKey(key)); key = makeKey("bird", "owl").build(); key = makeKey(key, "bird", 123).build(); assertTrue(isValidKey(key)); key = makeKey("bird", "owl").build(); key = makeKey(key, "bird").build(); assertFalse(isValidKey(key)); key = makeKey().build(); assertFalse(isValidKey(key)); }