Search in sources :

Example 1 with CacheKeyUpdater

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();
}
Also used : Options(com.bumptech.glide.load.Options) CacheKeyUpdater(com.bumptech.glide.load.Option.CacheKeyUpdater) NonNull(android.support.annotation.NonNull) ObjectKey(com.bumptech.glide.signature.ObjectKey) MessageDigest(java.security.MessageDigest) Test(org.junit.Test)

Example 2 with CacheKeyUpdater

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();
}
Also used : Options(com.bumptech.glide.load.Options) Transformation(com.bumptech.glide.load.Transformation) CacheKeyUpdater(com.bumptech.glide.load.Option.CacheKeyUpdater) EqualsTester(com.google.common.testing.EqualsTester) NonNull(android.support.annotation.NonNull) ObjectKey(com.bumptech.glide.signature.ObjectKey) MessageDigest(java.security.MessageDigest) Test(org.junit.Test)

Aggregations

NonNull (android.support.annotation.NonNull)2 CacheKeyUpdater (com.bumptech.glide.load.Option.CacheKeyUpdater)2 Options (com.bumptech.glide.load.Options)2 ObjectKey (com.bumptech.glide.signature.ObjectKey)2 MessageDigest (java.security.MessageDigest)2 Test (org.junit.Test)2 Transformation (com.bumptech.glide.load.Transformation)1 EqualsTester (com.google.common.testing.EqualsTester)1