### Question:
CacheManager implements CacheManagerBean { public @Override void setMaximumSize(long maxSizeBytes) throws IllegalArgumentException { final long absoluteMaximumSize = getAbsoluteMaximumSize(); checkArgument(maxSizeBytes >= 0 && maxSizeBytes <= absoluteMaximumSize, "Cache max size must be between 0 and %s, got %s", absoluteMaximumSize, maxSizeBytes); SharedCache cache; if (maxSizeBytes == 0) { cache = SharedCache.NO_CACHE; } else { SharedCacheBuilder builder; try { builder = new ServiceFinder().environmentVariable(ENV_VAR).systemProperty(ENV_VAR) .lookupDefaultService(SharedCacheBuilder.class); LOG.info("Obtained cache builder {}", builder.getClass().getName()); builder.setMaxSizeBytes(maxSizeBytes); cache = builder.build(); LOG.info("Initialized shared cache {}", cache.getClass().getName()); } catch (NoSuchElementException noBuilderPresent) { LOG.warn("No implementation of {} found in the classpath, " + "nor one was provided through the {} system property or environment variable. Cache is disabled.", SharedCacheBuilder.class.getName(), ENV_VAR); cache = SharedCache.NO_CACHE; } } SharedCache old = _SHARED_CACHE; _SHARED_CACHE = cache; if (old != null) { old.invalidateAll(); } this.currentMaxCacheSize = maxSizeBytes; } @VisibleForTesting  CacheManager(); void setEncoder(@NonNull RevObjectSerializer encoder); ObjectCache acquire(final @NonNull String uniqueCacheIdentifier); void release(ObjectCache cache); @Override long getSize(); @Override long getSizeBytes(); @Override double getSizeMB(); @Override void clear(); @Override long getHitCount(); @Override double getHitRate(); @Override long getMissCount(); @Override double getMissRate(); @Override long getEvictionCount(); @Override void setMaximumSizePercent(double percent); @Override void setMaximumSizeMB(double maxSizeMB); long getMaximumSize(); @Override double getMaximumSizeMB(); @Override void setMaximumSize(long maxSizeBytes); @Override double getMaximumSizePercent(); @Override double getDefaultSizeMB(); @Override double getAbsoluteMaximumSizeMB(); @Nullable @Override String getMaximumSizeSystemProperty(); @Nullable @Override String getMaximumSizeEnvVariable(); @Nullable @Override String getCacheImplementationName(); static final CacheManager INSTANCE; static final String ENV_VAR; }### Answer:
public @Test void setMaximumSize() { assertEquals(-1, cacheManager.getMaximumSize()); assertNull(cacheManager._SHARED_CACHE); cacheManager.setMaximumSize(0); assertNotNull(cacheManager._SHARED_CACHE); assertEquals(0, cacheManager.getMaximumSize()); SharedCache cache = cacheManager._SHARED_CACHE; cacheManager.setMaximumSize(1000); assertEquals(1000, cacheManager.getMaximumSize()); assertNotNull(cacheManager._SHARED_CACHE); assertNotSame(cache, cacheManager._SHARED_CACHE); doReturn(10_000L).when(cacheManager).getAbsoluteMaximumSize(); Exception e = assertThrows(IllegalArgumentException.class, () -> cacheManager.setMaximumSize(10_001)); assertThat(e.getMessage(), containsString("Cache max size must be between 0 and")); }