Utils { public static String getValidityTime(String transactionTime) { if (transactionTime != null) { String data[] = transactionTime.split(" "); if (data.length > 1) { try { @SuppressLint("SimpleDateFormat") SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); Calendar calendar = Calendar.getInstance(); calendar.setTime(simpleDateFormat.parse(data[0])); calendar.add(Calendar.DATE, 1); String date = simpleDateFormat.format(calendar.getTime()); String splitedDate[] = date.split("-"); String month = getMonth(Integer.parseInt(splitedDate[1])); String validityTime = "" + splitedDate[2] + " " + month + " " + splitedDate[0] + ", " + data[1]; Logger.i("after parsing validity date becomes : " + date); Logger.i("month is : " + month); Logger.i("validity time is : " + validityTime); return validityTime; } catch (ParseException ex) { Logger.e("Error while parsing date : " + ex.getMessage()); } } } return transactionTime; }  static String mappingToCreditCardAuthentication(String type, boolean secure); static boolean isNetworkAvailable(Context context); static void hideKeyboard(Context context, View editText); static String getFormattedAmount(double amount); static String getValidityTime(String transactionTime); static String getMonth(int monthValue); static int dpToPx(int dp); static String getFormattedCreditCardNumber(String unformattedCardNumber); static String getCardType(@NonNull String cardNo); static String getFormattedTime(long time); static String formatDouble(double d); static String getDeviceType(Activity activity); static final String CARD_TYPE_VISA; static final String CARD_TYPE_MASTERCARD; static final String CARD_TYPE_AMEX; static final String CARD_TYPE_JCB; }
@Test public void getValidityTime_whenNull() { Assert.assertEquals(null, Utils.getValidityTime(null)); }
@Test public void getValidityTime_whenNotNull() { Assert.assertNotNull(Utils.getValidityTime("2015-10-30 20:32:51")); }
@Test public void getValidtyTime_whenParseExcetion() { String sampleTime = "string error 23423 234"; Assert.assertEquals(sampleTime, Utils.getValidityTime(sampleTime)); PowerMockito.verifyStatic(Mockito.times(1)); Logger.e(Matchers.anyString()); }