ProviderBasedDataObjectService implements DataObjectService { protected Object reduceCompoundKey(Object id) { if (id instanceof CompoundKey) { CompoundKey compoundKey = (CompoundKey)id; if (compoundKey.getKeys().size() == 1) { id = compoundKey.getKeys().values().iterator().next(); } } return id; }  @Override T find(Class<T> type, Object id); @Override QueryResults<T> findMatching(Class<T> type, QueryByCriteria queryByCriteria); @Override QueryResults<T> findAll(Class<T> type); @Override T findUnique(Class<T> type, QueryByCriteria queryByCriteria); @Override void delete(Object dataObject); @Override void deleteMatching(Class<T> type, QueryByCriteria queryByCriteria); @Override void deleteAll(Class<T> type); @Override T save(T dataObject, PersistenceOption... options); @Override MetadataRepository getMetadataRepository(); @Override T copyInstance(T dataObject, CopyOption... options); @Override DataObjectWrapper<T> wrap(T dataObject); @Override boolean supports(Class<T> type); @Override void flush(Class<?> type); @Required void setProviderRegistry(ProviderRegistry providerRegistry); @Required void setMetadataRepository(MetadataRepository metadataRepository); ReferenceLinker getReferenceLinker(); @Required void setReferenceLinker(ReferenceLinker referenceLinker);  }
@Test public void testReduceCompoundKey_Null() { assertNull(service.reduceCompoundKey(null)); }
@Test public void testReduceCompoundKey_NonCompoundKey() { assertEquals("1234", service.reduceCompoundKey("1234")); }
@Test public void testReduceCompoundKey_CompoundKeyOneValue() { Map<String, Object> singleKeyMap = new HashMap<String, Object>(); singleKeyMap.put("myAwesomeId", 123456L); CompoundKey singleKey = new CompoundKey(singleKeyMap); assertEquals(123456L, service.reduceCompoundKey(singleKey)); }
@Test public void testReduceCompoundKey_CompoutKeyMultiValue() { Map<String, Object> multiKeyMap = new HashMap<String, Object>(); multiKeyMap.put("myAwesomeId", 123456L); multiKeyMap.put("myOtherAwesomeId", "abcdefg"); CompoundKey multiKey = new CompoundKey(multiKeyMap); assertEquals(multiKey, service.reduceCompoundKey(multiKey)); }