Created
January 12, 2017 12:09
-
-
Save hardikm9850/af22ede7dc8ccc73536a7f83dce18f6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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