Utils { public static void hideKeyboard(Context context, View editText) { try { InputMethodManager imm = (InputMethodManager) context.getSystemService(Context .INPUT_METHOD_SERVICE); if (editText != null) { imm.hideSoftInputFromWindow(editText.getWindowToken(), 0); editText.clearFocus(); } } catch (Exception e) { Logger.e(e.getMessage()); } }  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 hideKeyboard() { Mockito.when(contextMock.getSystemService(Context.INPUT_METHOD_SERVICE)).thenReturn(inputMethodMock); Mockito.when(viewMock.getWindowToken()).thenReturn(binderMock); Mockito.when(inputMethodMock.hideSoftInputFromWindow(binderMock, 0)).thenReturn(true); Utils.hideKeyboard(contextMock, viewMock); Mockito.verify(inputMethodMock).hideSoftInputFromWindow(binderMock, 0); }
@Test public void hideKeyboard_exception() { Mockito.when(contextMock.getSystemService(Context.INPUT_METHOD_SERVICE)).thenReturn(null); Mockito.when(viewMock.getWindowToken()).thenReturn(null); Mockito.when(inputMethodMock.hideSoftInputFromWindow(binderMock, 0)).thenReturn(true); Utils.hideKeyboard(contextMock, viewMock); PowerMockito.verifyStatic(Mockito.times(1)); Logger.e(Matchers.anyString()); }