summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerOptionsTest.java
blob: 5062a9b9cc4d84ec6e0655c93a5cfa349c6d6ac2 (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
package com.mapbox.mapboxsdk.plugins.locationlayer;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;

import com.mapbox.mapboxsdk.R;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class LocationLayerOptionsTest {

  @Mock
  private Context context;
  @Mock
  private TypedArray array;
  @Mock
  private Resources resources;

  @Rule
  public ExpectedException thrown = ExpectedException.none();

  @Before
  public void setUp() throws Exception {
    when(context.obtainStyledAttributes(R.style.mapbox_LocationLayer, R.styleable.mapbox_LocationLayer))
      .thenReturn(array);
    when(array.getResourceId(R.styleable.mapbox_LocationLayer_mapbox_foregroundDrawable, -1))
      .thenReturn(R.drawable.mapbox_user_icon);
    when(context.getResources()).thenReturn(resources);
  }

  @Test
  public void sanity() throws Exception {
    LocationLayerOptions locationLayerOptions = LocationLayerOptions.builder(context)
      .accuracyAlpha(0.5f)
      .build();
    assertNotNull(locationLayerOptions);
  }

  @Test
  public void passingOutOfRangeAccuracyAlpha_throwsException() throws Exception {
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("Location layer accuracy alpha value must be between 0.0 and "
      + "1.0.");
    LocationLayerOptions.builder(context)
      .accuracyAlpha(2f)
      .build();
  }

  @Test
  public void negativeElevation_causesExceptionToBeThrown() throws Exception {
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("Invalid shadow size -500.0. Must be >= 0");
    LocationLayerOptions.builder(context)
      .elevation(-500)
      .build();
  }
}