Skip to content

Commit

Permalink
fix a bad mocking strategy in GetClusterConfigurationTest test that w…
Browse files Browse the repository at this point in the history
…as reporting a success for the wrong reasons
  • Loading branch information
barmintor committed Jun 6, 2013
1 parent c628fde commit 7e9e885
Showing 1 changed file with 18 additions and 3 deletions.
Expand Up @@ -6,23 +6,30 @@

package org.fcrepo.services.functions;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import javax.jcr.Repository;

import org.infinispan.Cache;
import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.configuration.cache.ClusteringConfiguration;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.manager.DefaultCacheManager;
import org.junit.Before;
import org.junit.Test;
import org.modeshape.jcr.GetBinaryStore;
import org.modeshape.jcr.JcrRepository;
import org.modeshape.jcr.JcrRepository.RunningState;
import org.modeshape.jcr.RepositoryConfiguration;
import org.modeshape.jcr.RepositoryConfiguration.BinaryStorage;
import org.modeshape.jcr.value.binary.infinispan.InfinispanBinaryStore;
Expand All @@ -35,13 +42,20 @@
public class GetClusterConfigurationTest {

private GetClusterConfiguration testObj;

private GetBinaryStore mockGetBinaryStore;

/**
* @throws Exception
* @todo Add Documentation.
*/
@Before
public void setUp() {
public void setUp() throws Exception {
testObj = new GetClusterConfiguration();
Field field = GetClusterConfiguration.class.getDeclaredField("getBinaryStore");
field.setAccessible(true);
mockGetBinaryStore = mock(GetBinaryStore.class);
field.set(testObj, mockGetBinaryStore);
}

/**
Expand All @@ -57,7 +71,7 @@ public void testGood() throws Exception {
when(mockConfig.getBinaryStorage()).thenReturn(mockStorage);
final InfinispanBinaryStore mockStore =
mock(InfinispanBinaryStore.class);
when(mockStorage.getBinaryStore()).thenReturn(mockStore);
when(mockGetBinaryStore.apply(any(Repository.class))).thenReturn(mockStore);
@SuppressWarnings("unchecked")
final Cache<Object, Object> mockCache = mock(Cache.class);
final List<Cache<?, ?>> mockCaches =
Expand All @@ -74,6 +88,7 @@ public void testGood() throws Exception {
when(mockCache.getCacheManager()).thenReturn(mockCM);
final Map<String, String> actual = testObj.apply(mockRepo);
assertNotNull(actual);
assertFalse(actual.isEmpty());
}

/**
Expand All @@ -83,6 +98,6 @@ public void testGood() throws Exception {
public void testBad() {
final JcrRepository mockRepo = mock(JcrRepository.class);
final Map<String, String> actual = testObj.apply(mockRepo);
assertTrue("", actual.isEmpty());
assertTrue(actual.isEmpty());
}
}

0 comments on commit 7e9e885

Please sign in to comment.