summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/annotations/IconTest.java
blob: 9e95451cb1369b70268b61451f9484be4d49396f (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
package com.mapbox.mapboxsdk.annotations;

import android.graphics.Bitmap;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotSame;

public class IconTest {

    @Mock
    Bitmap mBitmap;

    @Before
    public void beforeTest() {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void testId() {
        String id = "test";
        Icon icon = IconFactory.recreate(id, Bitmap.createBitmap(0, 0, Bitmap.Config.ALPHA_8));
        assertEquals("id should match", id, icon.getId());
    }

    @Test
    public void testBitmap() {
        Icon icon = IconFactory.recreate("test", mBitmap);
        assertEquals("bitmap should match", mBitmap, icon.getBitmap());
    }

    @Test
    public void testEquals() {
        Icon icon1 = IconFactory.recreate("test", mBitmap);
        Icon icon2 = IconFactory.recreate("test", mBitmap);
        assertEquals("icons should not match", icon1, icon2);
    }

    @Test
    public void testEqualsObject() {
        Icon icon = IconFactory.recreate("test", Bitmap.createBitmap(0, 0, Bitmap.Config.ALPHA_8));
        assertNotSame("icon should not match", new Object(), icon);
    }

    @Test
    public void testHashcode() {
        Icon icon = IconFactory.recreate("test", mBitmap);
        long expectedHashcode = 31 * mBitmap.hashCode() + "test".hashCode();
        assertEquals("hashcode should match", expectedHashcode, icon.hashCode());
    }
}