@Test
  public void testGetBinaryBlobs() throws RepositoryException {

    when(mockNode.getProperty(JCR_DATA)).thenReturn(mockProperty);
    when(mockStore.toString()).thenReturn("foo");
    when(mockKeyFunc.apply(mockProperty)).thenReturn(mockKey);
    when(mockStoreFunc.apply(mockRepo)).thenReturn(mockStore);
    final LowLevelStorageService testObj = new LowLevelStorageService();
    testObj.setGetBinaryStore(mockStoreFunc);
    testObj.setGetBinaryKey(mockKeyFunc);
    testObj.setRepository(mockRepo);
    final Set<LowLevelCacheEntry> actual = testObj.getLowLevelCacheEntries(mockNode);
    assertEquals("/foo", actual.iterator().next().getExternalIdentifier());
  }
  @Test
  public void testTransformBinaryBlobs() throws RepositoryException {

    when(mockNode.getProperty(JcrConstants.JCR_DATA)).thenReturn(mockProperty);
    when(mockStore.toString()).thenReturn("foo");
    when(mockKeyFunc.apply(mockProperty)).thenReturn(mockKey);
    when(mockStoreFunc.apply(mockRepo)).thenReturn(mockStore);
    final LowLevelStorageService testObj = new LowLevelStorageService();
    testObj.setGetBinaryStore(mockStoreFunc);
    testObj.setGetBinaryKey(mockKeyFunc);
    testObj.setRepository(mockRepo);
    @SuppressWarnings("unchecked")
    final Function<LowLevelCacheEntry, String> testFunc = mock(Function.class);
    when(testFunc.apply(any(LowLevelCacheEntry.class))).thenReturn("bar");
    final Collection<String> actual = testObj.transformLowLevelCacheEntries(mockNode, testFunc);
    assertEquals("bar", actual.iterator().next());
    verify(testFunc).apply(any(LowLevelCacheEntry.class));
  }
  @SuppressWarnings("unchecked")
  @Test
  public void shouldRetrieveLowLevelCacheStoresForCompositeStore() throws Exception {

    mockStatic(ServiceHelpers.class);

    final Cache<?, ?> ispnCache1 = mock(Cache.class);
    final Cache<?, ?> ispnCache2 = mock(Cache.class);
    final CacheStore ispnCacheStore1 = mock(CacheStore.class);
    final CacheStore ispnCacheStore2 = mock(CacheStore.class);
    final BinaryStore plainBinaryStore = mock(BinaryStore.class);
    final BinaryStore plainBinaryStore2 = mock(BinaryStore.class);

    final GetCacheStore mockCacheStoreFunc = mock(GetCacheStore.class);
    when(mockCacheStoreFunc.apply(ispnCache1)).thenReturn(ispnCacheStore1);
    when(mockCacheStoreFunc.apply(ispnCache2)).thenReturn(ispnCacheStore2);

    final CompositeBinaryStore mockStore = mock(CompositeBinaryStore.class);

    final HashMap<String, BinaryStore> map = new HashMap<>();
    final List<Cache<?, ?>> caches = new ArrayList<>();
    caches.add(ispnCache1);
    caches.add(ispnCache2);

    map.put("default", plainBinaryStore);
    map.put("a", plainBinaryStore2);
    final InfinispanBinaryStore infinispanBinaryStore = mock(InfinispanBinaryStore.class);
    when(infinispanBinaryStore.getCaches()).thenReturn(caches);
    map.put("b", infinispanBinaryStore);
    when(mockStore.getNamedStoreIterator()).thenReturn(map.entrySet().iterator());

    final DistributedExecutorService mockCluster = mock(DistributedExecutorService.class);
    when(getClusterExecutor(infinispanBinaryStore)).thenReturn(mockCluster);

    final BinaryKey key = new BinaryKey("key-123");

    final LowLevelCacheEntry cacheEntry1 = new CacheStoreEntry(ispnCacheStore1, "cache1", key);
    final Set<LowLevelCacheEntry> cacheResponse1 = of(cacheEntry1);
    final LowLevelCacheEntry cacheEntry2 = new CacheStoreEntry(ispnCacheStore2, "cache2", key);
    final Set<LowLevelCacheEntry> cacheResponse2 = of(cacheEntry2);
    final Future<Collection<LowLevelCacheEntry>> future1 = mock(Future.class);
    final Future<Collection<LowLevelCacheEntry>> future2 = mock(Future.class);
    when(future1.get(any(Long.class), eq(MILLISECONDS))).thenReturn(cacheResponse1);
    when(future2.get(any(Long.class), eq(MILLISECONDS))).thenReturn(cacheResponse2);

    final List<Future<?>> mockClusterResults = new ArrayList<>(2);
    mockClusterResults.add(future1);
    mockClusterResults.add(future2);

    when(mockCluster.submitEverywhere(any(CacheLocalTransform.class)))
        .thenReturn(mockClusterResults);

    final LowLevelStorageService testObj = new LowLevelStorageService();

    when(plainBinaryStore.hasBinary(key)).thenReturn(true);
    when(plainBinaryStore2.hasBinary(key)).thenReturn(false);
    when(infinispanBinaryStore.hasBinary(key)).thenReturn(true);
    final Set<LowLevelCacheEntry> entries =
        testObj.getLowLevelCacheEntriesFromStore(mockStore, key);

    assertEquals(3, entries.size());

    assertTrue(entries.contains(new LocalBinaryStoreEntry(plainBinaryStore, key)));
    assertFalse(entries.contains(new LocalBinaryStoreEntry(plainBinaryStore2, key)));
    assertTrue(entries.contains(new CacheStoreEntry(ispnCacheStore1, "cache1", key)));
    assertTrue(entries.contains(new CacheStoreEntry(ispnCacheStore2, "cache2", key)));
  }