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
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}" |
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
defaultConfig { | |
// default setup here | |
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | |
} |
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
@RunWith(AndroidJUnit4.class) | |
@LargeTest | |
public class TeamsActivityTest { } |
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
@Rule public ActivityTestRule<TeamsActivity> activityTestRule = | |
new ActivityTestRule<>(TeamsActivity.class); |
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
@Test | |
public void teamsListIsSortedAlphabetically() { | |
onView(withId(android.R.id.list)).check(matches(isSortedAlphabetically())); | |
} |
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
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(); |
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
dependencies { | |
// other "compile" dependencies go here | |
compile "com.android.support:recyclerview-v7:${APPCOMPAT_VERSION}" | |
// "androidTest" dependencies are here | |
} |
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 Team { | |
public final String name; | |
public final @DrawableRes int logoRes; | |
public Team(@NonNull String name, @DrawableRes int logoRes) { | |
this.name = name; | |
this.logoRes = logoRes; | |
} |
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 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<>(); | |
} |
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
@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()); |
OlderNewer