Utils { @DrawableRes public static int getImageGrade(@Nullable String grade) { if (grade == null) { return NO_DRAWABLE_RESOURCE; } switch (grade.toLowerCase(Locale.getDefault())) { case "a": return R.drawable.ic_nutriscore_a; case "b": return R.drawable.ic_nutriscore_b; case "c": return R.drawable.ic_nutriscore_c; case "d": return R.drawable.ic_nutriscore_d; case "e": return R.drawable.ic_nutriscore_e; default: return NO_DRAWABLE_RESOURCE; } } private  Utils(); static String bold(CharSequence... content); static void hideKeyboard(@NonNull Activity activity); static String compressImage(String fileUrl); static int getColor(Context context, int id); static boolean isApplicationInstalled(Context context, String packageName); @DrawableRes static int getImageGrade(@Nullable String grade); static int getImageGrade(@Nullable Product product); @Nullable static Drawable getImageGradeDrawable(@NonNull Context context, @Nullable String grade); @Nullable static Drawable getImageGradeDrawable(@NonNull Context context, @Nullable Product product); static String getNovaGroupExplanation(@Nullable String novaGroup, @NonNull Context context); static List<T> getViewsByType(ViewGroup root, Class<T> typeClass); static int getNovaGroupDrawable(@Nullable Product product); @DrawableRes static int getNovaGroupDrawable(@Nullable String novaGroup); static int getSmallImageGrade(Product product); static int getImageEnvironmentImpact(Product product); static int getSmallImageGrade(@Nullable String grade); static Bitmap getBitmapFromDrawable(@NonNull Context context, @DrawableRes int drawableId); static String getRoundNumber(String value); static String getRoundNumber(float value); static DaoSession getDaoSession(); static boolean isHardwareCameraInstalled(@NonNull Context context); static synchronized void scheduleProductUploadJob(Context context); static OkHttpClient httpClientBuilder(); static boolean isUserLoggedIn(@NonNull Context context); static boolean isNetworkConnected(@NonNull Context context); @NonNull static File makeOrGetPictureDirectory(@NonNull Context context); static boolean isExternalStorageWritable(); static Uri getOutputPicUri(Context context); @NonNull static CharSequence getClickableText(String text, String urlParameter, SearchType type, Activity activity, CustomTabsIntent customTabsIntent); static boolean isBatteryLevelLow(@NonNull Context context); static boolean isDisableImageLoad(@NonNull Context context); static void scan(@NonNull Activity activity); @NonNull static String getVersionName(@Nullable Context context); @NonNull static String getUserAgent(@NonNull String type); @NonNull static String getUserAgent(); @Nullable static JSONObject createJsonObject(@NonNull String response); @Contract(pure = true) @Nullable @SafeVarargs static T firstNotNull(@Nullable T... args); @Nullable static String firstNotEmpty(String... args); @NonNull static String getModifierNonDefault(String modifier); static int dpsToPixel(int dps, @Nullable Activity activity); static void startLoginToEditAnd(int requestCode, @Nullable Activity activity); static boolean isAllGranted(@NonNull int[] grantResults); static boolean isAllGranted(@NonNull Map<String, Boolean> grantResults); static final int CONNECTION_TIMEOUT; static final int RW_TIMEOUT; static final String SPACE; static final int MY_PERMISSIONS_REQUEST_CAMERA; static final int MY_PERMISSIONS_REQUEST_STORAGE; static final String HEADER_USER_AGENT_SCAN; static final String HEADER_USER_AGENT_SEARCH; static final int NO_DRAWABLE_RESOURCE; static final String FORCE_REFRESH_TAXONOMIES; }
@Test public void getImageGrade() { final Product mockProduct = mock(Product.class); when(mockProduct.getNutritionGradeFr()).thenReturn("a"); assertThat(Utils.getImageGrade(mockProduct)).isEqualTo(R.drawable.ic_nutriscore_a); when(mockProduct.getNutritionGradeFr()).thenReturn("b"); assertThat(Utils.getImageGrade(mockProduct)).isEqualTo(R.drawable.ic_nutriscore_b); when(mockProduct.getNutritionGradeFr()).thenReturn("c"); assertThat(Utils.getImageGrade(mockProduct)).isEqualTo(R.drawable.ic_nutriscore_c); when(mockProduct.getNutritionGradeFr()).thenReturn("d"); assertThat(Utils.getImageGrade(mockProduct)).isEqualTo(R.drawable.ic_nutriscore_d); when(mockProduct.getNutritionGradeFr()).thenReturn("e"); assertThat(Utils.getImageGrade(mockProduct)).isEqualTo(R.drawable.ic_nutriscore_e); when(mockProduct.getNutritionGradeFr()).thenReturn(""); assertThat(Utils.getImageGrade(mockProduct)).isEqualTo(Utils.NO_DRAWABLE_RESOURCE); when(mockProduct.getNutritionGradeFr()).thenReturn(null); assertThat(Utils.getImageGrade(mockProduct)).isEqualTo(Utils.NO_DRAWABLE_RESOURCE); }