GpsHelper { static boolean reflectedIsLimitAdTrackingEnabled(final Object adInfo, final boolean defaultValue) { try { Boolean result = (Boolean) MethodBuilderFactory.create(adInfo, "isLimitAdTrackingEnabled").execute(); return (result != null) ? result : defaultValue; } catch (Exception exception) { return defaultValue; } }  static boolean isPlayServicesAvailable(final Context context); static boolean isLimitAdTrackingEnabled(Context context); static void fetchAdvertisingInfoAsync(final Context context, final GpsHelperListener gpsHelperListener); @Nullable static AdvertisingInfo fetchAdvertisingInfoSync(final Context context); @Deprecated static void setClassNamesForTesting(); static final int GOOGLE_PLAY_SUCCESS_CODE; static final String ADVERTISING_ID_KEY; static final String IS_LIMIT_AD_TRACKING_ENABLED_KEY; }
@Test public void reflectedGetIsLimitAdTrackingEnabled_whenIsLimitAdTrackingEnabledIsSet_shouldReturnIsLimitAdTrackingEnabled() throws Exception { MethodBuilderFactory.setInstance(new MethodBuilderFactory()); assertThat(GpsHelper.reflectedIsLimitAdTrackingEnabled(adInfo, false)).isEqualTo(adInfo.LIMIT_AD_TRACKING_ENABLED); }
@Test public void reflectedGetIsLimitAdTrackingEnabled_whenReflectedMethodCallThrows_shouldReturnDefaultValue() throws Exception { when(methodBuilder.execute()).thenThrow(new Exception()); assertThat(GpsHelper.reflectedIsLimitAdTrackingEnabled(new Object(), false)).isFalse(); verify(methodBuilder).execute(); assertThat(GpsHelper.reflectedIsLimitAdTrackingEnabled(new Object(), true)).isTrue(); verify(methodBuilder, times(2)).execute(); }
@Test public void reflectedGetIsLimitAdTrackingEnabled_whenReflectedMethodCallReturnsNull_shouldReturnDefaultValue() throws Exception { when(methodBuilder.execute()).thenReturn(null); assertThat(GpsHelper.reflectedIsLimitAdTrackingEnabled(new Object(), false)).isFalse(); verify(methodBuilder).execute(); assertThat(GpsHelper.reflectedIsLimitAdTrackingEnabled(new Object(), true)).isTrue(); verify(methodBuilder, times(2)).execute(); }