### Question:
CacheManager { public Ehcache addCacheIfAbsent(final Ehcache cache) { checkStatus(); return cache == null ? null : addCacheNoCheck(cache, false); } CacheManager(Configuration configuration);  CacheManager(String configurationFileName);  CacheManager(URL configurationURL);  CacheManager(InputStream configurationInputStream);  CacheManager(); String getClusterUUID(); Store createTerracottaStore(Ehcache cache); WriteBehind createTerracottaWriteBehind(Ehcache cache); CacheEventListener createTerracottaEventReplicator(Ehcache cache); static CacheManager create(); static CacheManager getInstance(); static CacheManager create(String configurationFileName); static CacheManager create(URL configurationFileURL); static CacheManager create(InputStream inputStream); static CacheManager create(Configuration config); Cache getCache(String name); Ehcache getEhcache(String name); void addCache(String cacheName); void addCache(Cache cache); void addCache(Ehcache cache); void addDecoratedCache(Ehcache decoratedCache); boolean cacheExists(String cacheName); void removalAll(); void removeCache(String cacheName); void shutdown(); String[] getCacheNames(); Status getStatus(); void clearAll(); void clearAllStartingWith(String prefix); CacheManagerPeerProvider getCacheManagerPeerProvider(String scheme); CacheManagerPeerListener getCachePeerListener(String scheme); CacheManagerEventListener getCacheManagerEventListener(); void setCacheManagerEventListener(CacheManagerEventListener cacheManagerEventListener); CacheManagerEventListenerRegistry getCacheManagerEventListenerRegistry(); void replaceCacheWithDecoratedCache(Ehcache ehcache, Ehcache decoratedCache); String getName(); boolean isNamed(); void setName(String name); @Override String toString(); String getDiskStorePath(); FailSafeTimer getTimer(); CacheCluster getCluster(ClusterScheme scheme); String getOriginalConfigurationText(); String getActiveConfigurationText(); String getOriginalConfigurationText(String cacheName); String getActiveConfigurationText(String cacheName); @Override int hashCode(); Ehcache addCacheIfAbsent(final Ehcache cache); Ehcache addCacheIfAbsent(final String cacheName); static final String DEFAULT_NAME; static final List<CacheManager> ALL_CACHE_MANAGERS; static final String ENABLE_SHUTDOWN_HOOK_PROPERTY; }### Answer:
@Test public void testAddCacheIfAbsent() { singletonManager = CacheManager.create(); singletonManager.addCache("present"); assertTrue(singletonManager.getCache("present") == singletonManager.addCacheIfAbsent(new Cache(new CacheConfiguration("present", 1000)))); Cache theCache = new Cache(new CacheConfiguration("absent", 1000)); Ehcache cache = singletonManager.addCacheIfAbsent(theCache); assertNotNull(cache); assertTrue(theCache == cache); assertEquals("absent", cache.getName()); Cache other = new Cache(new CacheConfiguration(cache.getName(), 1000)); Ehcache actualCacheRegisteredWithManager = singletonManager.addCacheIfAbsent(other); assertNotNull(actualCacheRegisteredWithManager); assertFalse(other == actualCacheRegisteredWithManager); assertTrue(cache == actualCacheRegisteredWithManager); Cache newCache = new Cache(new CacheConfiguration(cache.getName(), 1000)); singletonManager.removeCache(actualCacheRegisteredWithManager.getName()); actualCacheRegisteredWithManager = singletonManager.addCacheIfAbsent(newCache); assertNotNull(actualCacheRegisteredWithManager); assertFalse(cache == actualCacheRegisteredWithManager); assertTrue(newCache == actualCacheRegisteredWithManager); assertTrue(singletonManager.addCacheIfAbsent(new Cache(new CacheConfiguration(actualCacheRegisteredWithManager.getName(), 1000))) == actualCacheRegisteredWithManager); assertNull(singletonManager.addCacheIfAbsent((Ehcache) null)); }