|
18 | 18 | import com.google.android.gms.maps.MapsInitializer; |
19 | 19 | import com.google.android.gms.maps.model.BitmapDescriptor; |
20 | 20 | import com.google.android.gms.maps.model.BitmapDescriptorFactory; |
21 | | -import com.google.maps.android.TestUtil; |
22 | 21 |
|
23 | | -import org.junit.Assume; |
| 22 | +import org.junit.After; |
24 | 23 | import org.junit.Before; |
25 | | -import org.junit.Ignore; |
26 | 24 | import org.junit.Test; |
27 | 25 | import org.junit.runner.RunWith; |
| 26 | +import org.mockito.MockedStatic; |
28 | 27 | import org.robolectric.RobolectricTestRunner; |
29 | 28 |
|
30 | 29 | import java.util.Arrays; |
|
35 | 34 | import static org.junit.Assert.assertFalse; |
36 | 35 | import static org.junit.Assert.assertNull; |
37 | 36 | import static org.junit.Assert.assertTrue; |
| 37 | +import static org.mockito.Mockito.mock; |
| 38 | +import static org.mockito.Mockito.mockStatic; |
| 39 | +import static org.mockito.Mockito.when; |
38 | 40 |
|
39 | 41 | @RunWith(RobolectricTestRunner.class) |
40 | 42 | public class GeoJsonPointStyleTest { |
41 | 43 | private GeoJsonPointStyle pointStyle; |
42 | 44 |
|
| 45 | + private MockedStatic<BitmapDescriptorFactory> mockedStatic; |
| 46 | + |
43 | 47 | @Before |
44 | 48 | public void setUp() { |
45 | 49 | MapsInitializer.initialize(InstrumentationRegistry.getInstrumentation().getTargetContext()); |
46 | 50 | pointStyle = new GeoJsonPointStyle(); |
| 51 | + mockedStatic = mockStatic(BitmapDescriptorFactory.class); |
| 52 | + } |
| 53 | + |
| 54 | + @After |
| 55 | + public void tearDown() { |
| 56 | + if (mockedStatic != null) { |
| 57 | + mockedStatic.close(); |
| 58 | + } |
47 | 59 | } |
48 | 60 |
|
49 | 61 | @Test |
@@ -84,16 +96,15 @@ public void testFlat() { |
84 | 96 | assertTrue(pointStyle.toMarkerOptions().isFlat()); |
85 | 97 | } |
86 | 98 |
|
87 | | - @Ignore("I should run via Robolectric - java.lang.NullPointerException: IBitmapDescriptorFactory is not initialized") // FIXME |
88 | 99 | @Test |
89 | 100 | public void testIcon() { |
90 | | - if (TestUtil.isRunningOnTravis()) { |
91 | | - Assume.assumeTrue("Skipping GeoJsonPointStyleTest.testIcon() - this is expected behavior on Travis CI (#573)", false); |
92 | | - return; |
93 | | - } |
94 | | - BitmapDescriptor icon = |
95 | | - BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN); |
| 101 | + // Mock the return value of defaultMarker |
| 102 | + BitmapDescriptor mockedIcon = mock(BitmapDescriptor.class); |
| 103 | + when(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)).thenReturn(mockedIcon); |
| 104 | + |
| 105 | + BitmapDescriptor icon = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN); |
96 | 106 | pointStyle.setIcon(icon); |
| 107 | + |
97 | 108 | assertEquals(icon, pointStyle.getIcon()); |
98 | 109 | assertEquals(icon, pointStyle.toMarkerOptions().getIcon()); |
99 | 110 | } |
|
0 commit comments