### Question:
CacheManager implements CacheManagerBean { long getCacheSizePercent(double percent) { checkArgument(percent >= 0d && percent <= 0.9, "percent must be between zero and 90% (0.9)"); final long maxMemory = getMaximumHeapSize(); return (long) (maxMemory * percent); } @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 getCacheSizePercentNegative() { Exception e = assertThrows(IllegalArgumentException.class, () -> cacheManager.getCacheSizePercent(-1)); assertThat(e.getMessage(), containsString("between zero and 90%")); }
public @Test void getCacheSizePercentExceedsMaximumAllowed() { Exception e = assertThrows(IllegalArgumentException.class, () -> cacheManager.getCacheSizePercent(0.91)); assertThat(e.getMessage(), containsString("between zero and 90%")); }
public @Test void getCacheSizePercent() { final long maxHeapSize = 1024 * 1024; doReturn(maxHeapSize).when(cacheManager).getMaximumHeapSize(); assertEquals(0L, cacheManager.getCacheSizePercent(0)); assertEquals(maxHeapSize / 2, cacheManager.getCacheSizePercent(0.5)); }