aboutsummaryrefslogtreecommitdiff
path: root/library/src/test/java/com/bumptech/glide/load/resource/gif/GifDataTest.java
blob: 2baa9e57df9248c4f461a8b1648340511d8e47f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.bumptech.glide.load.resource.gif;

import android.graphics.Bitmap;

import com.bumptech.glide.gifdecoder.GifHeader;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.tests.GlideShadowLooper;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import java.util.ArrayList;
import java.util.List;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotSame;
import static junit.framework.Assert.assertTrue;
import static junit.framework.TestCase.assertNotNull;
import static org.mockito.Mockito.mock;

@RunWith(RobolectricTestRunner.class)
@Config(shadows = GlideShadowLooper.class)
public class GifDataTest {
    private GifData data;
    private byte[] bytes;

    @Before
    public void setUp() {
        BitmapPool bitmapPool = mock(BitmapPool.class);
        GifHeader header = mock(GifHeader.class);
        bytes = new byte[] { 'G', 'I', 'F' };
        data = new GifData(Robolectric.application, bitmapPool, "gifId", header, bytes, 123, 456);
    }

    @Test
    public void testReturnsDecoderByteSize() {
        assertEquals(bytes.length, data.getByteSize());
    }

    @SuppressWarnings("unchecked")
    @Test
    public void testReturnsSetTransformation() {
        Transformation<Bitmap> transformation = mock(Transformation.class);

        data.setFrameTransformation(transformation);
        assertEquals(transformation, data.getFrameTransformation());
    }

    @Test
    public void testReturnsDifferentDrawables() {
        GifDrawable first = data.getDrawable();
        GifDrawable second = data.getDrawable();

        assertNotSame(first, second);
    }

    @Test
    public void testCallsRecycleOnAllReturnedDrawablesWhenRecycled() {
        List<GifDrawable> drawables = new ArrayList<GifDrawable>();
        for (int i = 0; i < 10; i++) {
            drawables.add(data.getDrawable());
        }
        data.recycle();
        for (GifDrawable drawable : drawables) {
            assertTrue(drawable.isRecycled());
        }
    }

    @Test
    public void testReturnsNonNullDrawable() {
        assertNotNull(data.getDrawable());
    }
}