GpsHelper { static String reflectedGetAdvertisingId(final Object adInfo, final String defaultValue) { try { return (String) MethodBuilderFactory.create(adInfo, "getId").execute(); } catch (Exception exception) { return defaultValue; } }  static boolean isLimitAdTrackingEnabled(Context context); static void fetchAdvertisingInfoAsync(final Context context, final GpsHelperListener gpsHelperListener); @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 reflectedGetAdvertisingId_whenAdvertisingIdIsSet_shouldReturnAdvertisingId() throws Exception { MethodBuilderFactory.setInstance(new MethodBuilderFactory()); assertThat(GpsHelper.reflectedGetAdvertisingId(adInfo, null)).isEqualTo(adInfo.ADVERTISING_ID); }
@Test public void reflectedGetAdvertisingId_whenReflectedMethodCallThrows_shouldReturnDefaultValue() throws Exception { when(methodBuilder.execute()).thenThrow(new Exception()); assertThat(GpsHelper.reflectedGetAdvertisingId(new Object(), null)).isNull(); verify(methodBuilder).execute(); String defaultAdId = "TEST_DEFAULT"; assertThat(GpsHelper.reflectedGetAdvertisingId(new Object(), defaultAdId)).isEqualTo(defaultAdId); verify(methodBuilder, times(2)).execute(); }