App extends Application { @SuppressWarnings("deprecation") public static int getVersionCode(Context context) { PackageInfo pInfo; try { pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_META_DATA); return pInfo.versionCode; } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, null, e); return -1; } }  @Override void onCreate(); @Subscribe void autoBackupSettingsChanged(final AutoBackupSettingsChangedEvent event); static void register(Object listener); static void unregister(Object listener); static void post(Object event); @Nullable static String getVersionName(Context context); @SuppressWarnings("deprecation") static int getVersionCode(Context context); static boolean isInstalledOnSDCard(Context context); static final boolean LOCAL_LOGV; static final String TAG; static final String LOG; static final String CHANNEL_ID; static boolean gcmAvailable; }
@Test public void shouldGetVersionCode() throws Exception { assertThat(App.getVersionCode(RuntimeEnvironment.application)).isEqualTo(0); }