Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
bennsimon committed Nov 24, 2020
1 parent 65ca54a commit 9593623
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ public static void hideKeyboard(Context context, View view) {
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
} catch (Exception e) {
logError("Error encountered while hiding keyboard " + e);
Timber.e(e, "Error encountered while hiding keyboard");
}
}

Expand Down
22 changes: 22 additions & 0 deletions opensrp-app/src/test/java/org/smartregister/util/UtilsTest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.smartregister.util;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.TableRow;

import androidx.test.core.app.ApplicationProvider;
Expand Down Expand Up @@ -49,8 +52,11 @@
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.only;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -470,5 +476,21 @@ public void testLogoutUserShouldInvokeRequiredMethods() {
verify(mockUserService, times(1)).logoutSession();
verify(context, times(1)).startActivity(any(Intent.class));
}

@Test
public void testHideKeyboardShouldInvokeRequireMethods() {
Activity activity = mock(Activity.class);

View view = mock(View.class);
doReturn(view).when(activity).getCurrentFocus();

InputMethodManager keyboard = mock(InputMethodManager.class);

doReturn(keyboard).when(activity).getSystemService(Context.INPUT_METHOD_SERVICE);

Utils.hideKeyboard(activity);

verify(keyboard, only()).hideSoftInputFromWindow(isNull(), eq(0));
}
}

0 comments on commit 9593623

Please sign in to comment.