summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/MarkerTest.java
blob: fa571e06b112d7d7b534646e70e9030adcb76b0e (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package com.mapbox.mapboxsdk.annotations;

import android.graphics.Bitmap;
import android.os.Parcelable;

import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.utils.MockParcel;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;

public class MarkerTest {

  @Test
  public void testSanity() {
    MarkerOptions markerOptions = new MarkerOptions();
    assertNotNull("markerOptions should not be null", markerOptions);
  }

  @Test
  public void testMarker() {
    MarkerOptions markerOptions = new MarkerOptions().position(new LatLng());
    assertNotNull("marker should not be null", markerOptions.getMarker());
  }

  @Test(expected = InvalidMarkerPositionException.class)
  public void testInvalidMarker() {
    new MarkerOptions().getMarker();
  }

  @Test
  public void testPosition() {
    MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(10, 12));
    Marker marker = markerOptions.getMarker();
    assertEquals(marker.getPosition(), new LatLng(10, 12));
    assertEquals(markerOptions.getPosition(), new LatLng(10, 12));
  }

  @Test
  public void testTitle() {
    MarkerOptions markerOptions = new MarkerOptions().title("Mapbox").position(new LatLng());
    Marker marker = markerOptions.getMarker();
    assertEquals(marker.getTitle(), "Mapbox");
    assertEquals(markerOptions.getTitle(), "Mapbox");
  }

  @Test
  public void testSnippet() {
    MarkerOptions markerOptions = new MarkerOptions().snippet("Mapbox").position(new LatLng());
    Marker marker = markerOptions.getMarker();
    assertEquals(marker.getSnippet(), "Mapbox");
  }

  @Test
  public void testBuilder() {
    Marker marker = new MarkerOptions().title("title").snippet("snippet").position(new LatLng(10, 12)).getMarker();
    assertEquals(marker.getSnippet(), "snippet");

    assertEquals(marker.getPosition(), new LatLng(10, 12));
  }

  @Test
  public void testIcon() {
    Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_4444);
    Icon icon = IconFactory.recreate("test", bitmap);
    MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()).icon(icon);
    Marker marker = markerOptions.getMarker();
    assertEquals("Icon should match", icon, marker.getIcon());
    assertEquals("Icon should match", icon, markerOptions.getIcon());
  }

  @Test
  public void testHashCode() {
    Marker marker = new MarkerOptions().position(new LatLng()).getMarker();
    assertEquals("hash code should match", marker.hashCode(), 0);
  }

  @Test
  public void testHashCodeBuilder() {
    MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(10, 12));
    assertEquals("hash code should match", markerOptions.hashCode(), 579999617);
  }

  @Test
  public void testEquals() {
    Marker markerOne = new MarkerOptions().position(new LatLng(0, 0)).getMarker();
    Marker markerTwo = new MarkerOptions().position(new LatLng(0, 0)).getMarker();
    assertEquals(markerOne, markerTwo);
  }

  @Test
  public void testEqualityDifferentLocation() {
    MarkerOptions marker = new MarkerOptions().position(new LatLng(0, 0));
    MarkerOptions other = new MarkerOptions().position(new LatLng(1, 0));
    assertNotEquals("Should not match", other, marker);
  }


  @Test
  public void testEqualityDifferentSnippet() {
    MarkerOptions marker = new MarkerOptions().snippet("s");
    MarkerOptions other = new MarkerOptions();
    assertNotEquals("Should not match", other, marker);
  }

  @Test
  public void testEqualityDifferentIcon() {
    MarkerOptions marker = new MarkerOptions().icon(mock(Icon.class));
    MarkerOptions other = new MarkerOptions();
    assertNotEquals("Should not match", other, marker);
  }

  @Test
  public void testEqualityDifferentTitle() {
    MarkerOptions marker = new MarkerOptions().title("t");
    MarkerOptions other = new MarkerOptions();
    assertNotEquals("Should not match", other, marker);
  }

  @Test
  public void testEqualsItself() {
    MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(0, 0));
    Marker marker = markerOptions.getMarker();
    assertEquals("Marker should match", marker, marker);
    assertEquals("MarkerOptions should match", markerOptions, markerOptions);
  }

  @Test
  public void testNotEquals() {
    MarkerOptions markerOptions = new MarkerOptions().position(new LatLng(0, 0));
    Marker marker = markerOptions.getMarker();
    assertNotEquals("MarkerOptions should match", markerOptions, new Object());
    assertNotEquals("Marker should match", marker, new Object());
  }

  @Test
  public void testEqualityBuilder() {
    MarkerOptions markerOne = new MarkerOptions().position(new LatLng(0, 0));
    MarkerOptions markerTwo = new MarkerOptions().position(new LatLng(0, 0));
    assertEquals(markerOne, markerTwo);
  }

  @Test
  public void testToString() {
    Marker marker = new MarkerOptions().position(new LatLng(0, 0)).getMarker();
    assertEquals(marker.toString(), "Marker [position[" + "LatLng [latitude=0.0, longitude=0.0, altitude=0.0]" + "]]");
  }

  @Test
  public void testParcelable() {
    MarkerOptions markerOptions = new MarkerOptions().position(new LatLng()).title("t").snippet("s");
    Parcelable parcelable = MockParcel.obtain(markerOptions);
    assertEquals("Parcel should match original object", parcelable, markerOptions);
  }
}