HaloUtils { @Api(1.0) @SuppressWarnings("deprecation") public static Drawable getDrawable(Context context, @DrawableRes int resource) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return context.getResources().getDrawable(resource, null); } return context.getResources().getDrawable(resource); } private  HaloUtils(); @Api(1.0) static boolean isNetworkConnected(Context context); @Api(2.0) static boolean isCharging(@NonNull Context context, @Nullable Intent intent); @Api(1.0) static void hideKeyboard(@Nullable View focusView); @Api(1.0) static void postUI(Runnable runnable); @Api(1.0) static boolean isAvailableForVersion(int sdkVersion); @Api(1.0) @SuppressWarnings("deprecation") static Drawable getDrawable(Context context, @DrawableRes int resource); @Api(1.0) static Uri getUriFromResource(Context context, int resourceId); @Api(1.0) static boolean hasFlag(int flags, int optionFlag); @Api(1.0) static int getArgb(String hexadecimal); @Api(1.0) static boolean isColor(String color); @Api(2.0) static String sha1(@NonNull String origin); @Api(2.0) static String convertToHex(byte[] data); @NonNull @Api(1.3) static String getEventName(@NonNull Context context, @NonNull String eventName); @Api(2.0) static String bytesToHex(@NonNull byte[] bytes); @Api(2.0) static byte[] hexToBytes(@NonNull String data); @Api(2.5) static boolean isServiceRunning(Context context, Class<?> serviceClass);  }
@Test public void thatCanGetDrawable(){ Resources resources = mock(Resources.class); Drawable drawable = mock(Drawable.class); when(mContext.getResources()).thenReturn(resources); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { when(resources.getDrawable(android.R.drawable.alert_dark_frame,null)).thenReturn(drawable); } else{ when(resources.getDrawable(android.R.drawable.alert_dark_frame)).thenReturn(drawable); } assertThat(HaloUtils.getDrawable(mContext, android.R.drawable.alert_dark_frame)).isNotNull(); assertThat(HaloUtils.getDrawable(mContext, android.R.drawable.alert_dark_frame)).isEqualTo(drawable); }