Skip to content

Instantly share code, notes, and snippets.

View Egorand's full-sized avatar
🔲
sup sup

Egor Andreevich Egorand

🔲
sup sup
View GitHub Profile
@Egorand
Egorand / build.gradle
Last active July 2, 2016 09:32
android-espresso-sorted-list-dependencies
def APPCOMPAT_VERSION = "24.0.0"
def ESPRESSO_RUNNER_VERSION = "0.5"
dependencies {
// dependencies with "compile" scope go here
androidTestCompile "com.android.support:support-annotations:${APPCOMPAT_VERSION}"
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile "com.android.support.test:runner:${ESPRESSO_RUNNER_VERSION}"
androidTestCompile "com.android.support.test:rules:${ESPRESSO_RUNNER_VERSION}"
@Egorand
Egorand / build.gradle
Created July 2, 2016 09:33
android-espresso-sorted-list-instrumentation-runner-setup
defaultConfig {
// default setup here
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
@Egorand
Egorand / TeamsActivityTest.java
Created July 2, 2016 09:36
android-espresso-sorted-list-teams-activity-test
@RunWith(AndroidJUnit4.class)
@LargeTest
public class TeamsActivityTest { }
@Egorand
Egorand / TeamsActivityTest.java
Created July 2, 2016 09:38
android-espresso-sorted-list-activity-test-rule
@Rule public ActivityTestRule<TeamsActivity> activityTestRule =
new ActivityTestRule<>(TeamsActivity.class);
@Egorand
Egorand / TeamsActivityTest.java
Created July 2, 2016 09:39
android-espresso-sorted-list-test-case
@Test
public void teamsListIsSortedAlphabetically() {
onView(withId(android.R.id.list)).check(matches(isSortedAlphabetically()));
}
@Egorand
Egorand / TeamsActivityTest.java
Created July 2, 2016 09:44
android-espresso-sorted-list-is-sorted-alphabetically
private static Matcher<View> isSortedAlphabetically() {
return new TypeSafeMatcher<View>() {
private final List<String> teamNames = new ArrayList<>();
@Override
protected boolean matchesSafely(View item) {
RecyclerView recyclerView = (RecyclerView) item;
TeamsAdapter teamsAdapter = (TeamsAdapter) recyclerView.getAdapter();
teamNames.clear();
@Egorand
Egorand / build.gradle
Created July 2, 2016 09:46
android-espresso-sorted-list-recyclerview-dependency
dependencies {
// other "compile" dependencies go here
compile "com.android.support:recyclerview-v7:${APPCOMPAT_VERSION}"
// "androidTest" dependencies are here
}
@Egorand
Egorand / Team.java
Created July 2, 2016 09:47
android-espresso-sorted-list-team
public class Team {
public final String name;
public final @DrawableRes int logoRes;
public Team(@NonNull String name, @DrawableRes int logoRes) {
this.name = name;
this.logoRes = logoRes;
}
@Egorand
Egorand / TeamsAdapter.java
Created July 2, 2016 09:49
android-espresso-sorted-list-teams-adapter
public class TeamsAdapter extends RecyclerView.Adapter<TeamsAdapter.ViewHolder> {
private final LayoutInflater layoutInflater;
private final List<Team> teams;
public TeamsAdapter(LayoutInflater layoutInflater) {
this.layoutInflater = layoutInflater;
this.teams = new ArrayList<>();
}
@Egorand
Egorand / TeamsActivity.java
Created July 2, 2016 09:50
android-espresso-sorted-list-teams-activity-oncreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RecyclerView teamsRecyclerView = (RecyclerView) findViewById(android.R.id.list);
teamsRecyclerView.setLayoutManager(new LinearLayoutManager(this));
TeamsAdapter teamsAdapter = new TeamsAdapter(LayoutInflater.from(this));
teamsAdapter.setTeams(createTeams());