View Javadoc

1   package com.atlassian.cache.compat;
2   
3   import com.atlassian.cache.CacheManager;
4   import com.atlassian.cache.memory.MemoryCacheManager;
5   
6   import org.junit.Test;
7   
8   import static org.hamcrest.Matchers.instanceOf;
9   import static org.hamcrest.Matchers.is;
10  import static org.hamcrest.Matchers.sameInstance;
11  import static org.junit.Assert.assertThat;
12  import static org.mockito.Mockito.mock;
13  
14  public class CacheManagerFactoryTest
15  {
16      @Test
17      public void testComponentLocatorProvidedCacheManagerIsUsed()
18      {
19          final CacheManager cacheManager = mock(CacheManager.class);
20          final CacheManagerFactory fixture = fixture(cacheManager);
21          assertThat(fixture.getCacheManager(), sameInstance(cacheManager));
22      }
23  
24      @Test
25      public void testMemoryCacheManagerCreatedWhenHostDoesNotProvideOne()
26      {
27          final CacheManagerFactory fixture = fixture(null);
28          assertThat(fixture.getCacheManager(), is(instanceOf(MemoryCacheManager.class)));
29      }
30  
31  
32  
33      // Mocks out the interaction with the ComponentLocator's static methods
34      static CacheManagerFactory fixture(final CacheManager cacheManagerFromComponentLocator)
35      {
36          return new CacheManagerFactory()
37          {
38              @Override
39              CacheManager getCacheManagerFromComponentLocator()
40              {
41                  return cacheManagerFromComponentLocator;
42              }
43          };
44      }
45  }