use of com.bumptech.glide.load.Option.CacheKeyUpdater in project glide by bumptech.
the class ResourceCacheKeyTest method testEqualsAndHashCode.
@Test
public void testEqualsAndHashCode() {
Options memoryOptions = new Options();
memoryOptions.set(Option.memory("key", new Object()), new Object());
Options diskOptions = new Options();
diskOptions.set(Option.disk("key", new CacheKeyUpdater<String>() {
@Override
public void update(@NonNull byte[] keyBytes, @NonNull String value, @NonNull MessageDigest messageDigest) {
messageDigest.update(keyBytes);
messageDigest.update(value.getBytes(Key.CHARSET));
}
}), "value");
for (int i = 0; i < 20; i++) {
byte[] array = new byte[9];
Arrays.fill(array, (byte) 2);
arrayPool.put(array);
}
keyTester.addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, new Options()), new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("otherSource"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("otherSignature"), 100, 100, transformation1, Object.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 200, 100, transformation1, Object.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 200, transformation1, Object.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation2, Object.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Integer.class, new Options())).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, memoryOptions)).addEquivalenceGroup(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, diskOptions)).addRegressionTest(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, new Options()), "04d632bfe8e588544909fc44edb7328fa28bea6831b96927ade22b44818654e2").addRegressionTest(new ResourceCacheKey(arrayPool, new ObjectKey("source"), new ObjectKey("signature"), 100, 100, transformation1, Object.class, diskOptions), "781ff8cd30aaaf248134580004ea6d63a1b87ae20ea0f769caf379d7d84986d0").test();
}
use of com.bumptech.glide.load.Option.CacheKeyUpdater in project glide by bumptech.
the class EngineKeyTest method testEqualsAndHashCode.
@Test
public void testEqualsAndHashCode() {
Options memoryOptions = new Options();
memoryOptions.set(Option.memory("key", new Object()), new Object());
Options diskOptions = new Options();
diskOptions.set(Option.disk("key", new CacheKeyUpdater<String>() {
@Override
public void update(@NonNull byte[] keyBytes, @NonNull String value, @NonNull MessageDigest messageDigest) {
messageDigest.update(keyBytes);
messageDigest.update(value.getBytes(Key.CHARSET));
}
}), "value");
new EqualsTester().addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options()), new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("otherId", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("otherSignature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 200, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 200, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>singletonMap(Object.class, transformation), Object.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Integer.class, Object.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Integer.class, new Options())).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, memoryOptions)).addEqualityGroup(new EngineKey("id", new ObjectKey("signature"), 100, 100, Collections.<Class<?>, Transformation<?>>emptyMap(), Object.class, Object.class, diskOptions)).testEquals();
}
Aggregations