Skip to content

Instantly share code, notes, and snippets.

@hardikm9850
Created January 12, 2017 12:09
Show Gist options
  • Save hardikm9850/af22ede7dc8ccc73536a7f83dce18f6d to your computer and use it in GitHub Desktop.
Save hardikm9850/af22ede7dc8ccc73536a7f83dce18f6d to your computer and use it in GitHub Desktop.
public class MockProfileTest extends ActivityInstrumentationTestCase2<FragmentContainer> {
final MockWebServer mMockWebServer = new MockWebServer();
private FragmentContainer fragmentContainer;
final int PORT = 9998;
Instrumentation instrumentation;
int id = 111;
String name = "name";
String city = "city";
String country = "country";
String phone = "0900990099";
String role = "Buyer";
@Rule public ActivityTestRule<FragmentContainer> activityRule = new ActivityTestRule<>(FragmentContainer.class, true, true);
@InjectMocks private SharedPreferences sharedPreferences;
private Context context;
public MockProfileTest() {
super("com.android.vegfru.tests", FragmentContainer.class);
}
@Before
public void setUps() throws Exception {
injectInstrumentation(InstrumentationRegistry.getInstrumentation());
Intent intent = new Intent();
intent.putExtra(CHOICE, TAG_PROFILE);
setActivityIntent(intent);
context = getInstrumentation().getContext();
sharedPreferences = Mockito.mock(SharedPreferences.class);
}
/**
* Test okhttp mockwebserver Dispatcher
*/
@Test
public void testMockWebServerDispatcher() {
when(sharedPreferences.getInt("userid", id)).thenReturn(id);
Intent intent = new Intent();
intent.putExtra(CHOICE, TAG_PROFILE);
activityRule.launchActivity(intent);
fragmentContainer = activityRule.getActivity();
mockUserInfo();
when(sharedPreferences.getInt("userid", id)).thenReturn(id);
onView(withId(R.id.txt_buy_lead)).check(matches(isDisplayed()));
onView(withId(R.id.txt_name_title)).check(matches(isDisplayed()));
onView(withId(R.id.txt_name)).check(ViewAssertions.matches(ViewMatchers.withText(name)));
onView(withId(R.id.txt_company_title)).check(matches(isDisplayed()));
}
private UserTable mockUserInfo() {
UserTable user = new UserTable(id, name, city, country,
"", "", phone,
0L, role, "", "");
user.update();
user.save();
return user;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment