EntitiesServiceImpl implements EntitiesService { @Override public Entity createEmptyEntity(String kind) { AppEngineHelper.disableApiHooks(); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Query query = new Query(kind); FetchOptions fetchOptions = FetchOptions.Builder.withOffset(0).limit(1); List<Entity> entities = datastore.prepare(query).asList(fetchOptions); Entity emptyEntity = null; if (!entities.isEmpty()) { Entity template = entities.get(0); emptyEntity = createEmptyEntityFromTemplate(template); } return emptyEntity; } @Inject  EntitiesServiceImpl(
            DatastoreHelper datastoreHelper,
            DefaultValueGenerator defaultValueGenerator,
            DatastoreCountProvider countProvider); @Override Iterable<Entity> getEntities(String kind, String namespace, Integer offset, Integer limit); @Override Collection<Entity> getEntities(List<Key> keys); @Override Entity createEmptyEntity(String kind); @Override void deleteEntities(String kind, String namespace, DeleteEntities deleteType, String encodedKeys); @Override long getCount(String kind, String namespace); @Override List<Key> put(Iterable<Entity> entities); @Override Future<List<Key>> putAsync(Iterable<Entity> entities);  }
@Test public void createEmptyEntity_entityStored_shouldReturnEmptyEntity() throws EntityNotFoundException, InstantiationException, IllegalAccessException { createEntityInDatastore(KIND_NAME, PROPERTY_NAME, A_NAME); Entity entity = entitiesService.createEmptyEntity(KIND_NAME); assertNotNull(entity); assertEquals(KIND_NAME, entity.getKind()); assertEquals("", entity.getProperty(PROPERTY_NAME)); }
@Test public void createEmptyEntity_entityStored_shouldKeepIndexes() throws EntityNotFoundException, InstantiationException, IllegalAccessException { createEntityWithMultipleProperties(); Entity entity = entitiesService.createEmptyEntity(KIND_NAME); assertNotNull(entity); assertEquals(KIND_NAME, entity.getKind()); assertEquals("", entity.getProperty(PROPERTY_NAME)); assertFalse(entity.isUnindexedProperty(PROPERTY_NAME)); assertEquals("", entity.getProperty(UNINDEXED_PROPERTY_NAME)); assertTrue(entity.isUnindexedProperty(UNINDEXED_PROPERTY_NAME)); }