Skip to content

Commit

Permalink
Add new samples for WorkManager & Navigation.
Browse files Browse the repository at this point in the history
Update GithubBrowserDemo to use navigation.

Change-Id: Iaa864e2f6eaaf006d5437c1be7c65318c3f29559
  • Loading branch information
yigit committed May 7, 2018
1 parent 16dd6c9 commit 8e77a8b
Show file tree
Hide file tree
Showing 174 changed files with 6,629 additions and 175 deletions.
24 changes: 21 additions & 3 deletions BasicRxJavaSample/versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
ext.deps = [:]
def versions = [:]
versions.arch_core = "1.1.1"
versions.room = "1.1.0-rc1"
versions.room = "1.1.0"
versions.lifecycle = "1.1.1"
versions.support = "27.1.1"
versions.dagger = "2.15"
Expand All @@ -39,14 +39,16 @@ versions.dexmaker = "2.2.0"
versions.constraint_layout = "1.0.2"
versions.glide = "4.7.1"
versions.timber = "4.5.1"
versions.android_gradle_plugin = "3.1.1"
versions.android_gradle_plugin = "3.1.2"
versions.rxjava2 = "2.1.3"
versions.rx_android = "2.0.1"
versions.atsl_runner = "1.0.1"
versions.atsl_rules = "1.0.1"
versions.hamcrest = "1.3"
versions.kotlin = "1.2.41"
versions.paging = "1.0.0-rc1"
versions.paging = "1.0.0"
versions.work = "1.0.0-alpha01"
versions.navigation = "1.0.0-alpha01"
def deps = [:]

def support = [:]
Expand Down Expand Up @@ -139,6 +141,22 @@ build_versions.target_sdk = 26
build_versions.build_tools = "27.0.3"
ext.build_versions = build_versions

def work = [:]
work.runtime = "android.arch.work:work-runtime:$versions.work"
work.testing = "android.arch.work:work-testing:$versions.work"
work.firebase = "android.arch.work:work-firebase:$versions.work"
deps.work = work

def navigation = [:]
navigation.runtime = "android.arch.navigation:navigation-runtime:$versions.navigation"
navigation.runtime_ktx = "android.arch.navigation:navigation-runtime-ktx:$versions.navigation"
navigation.fragment = "android.arch.navigation:navigation-fragment:$versions.navigation"
navigation.fragment_ktx = "android.arch.navigation:navigation-fragment-ktx:$versions.navigation"
navigation.safe_args_plugin = "android.arch.navigation:navigation-safe-args-gradle-plugin:$versions.navigation"
navigation.testing_ktx = "android.arch.navigation:navigation-testing-ktx:$versions.navigation"
deps.navigation = navigation

ext.deps = deps

def addRepos(RepositoryHandler handler) {
handler.google()
Expand Down
24 changes: 21 additions & 3 deletions BasicRxJavaSampleKotlin/versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
ext.deps = [:]
def versions = [:]
versions.arch_core = "1.1.1"
versions.room = "1.1.0-rc1"
versions.room = "1.1.0"
versions.lifecycle = "1.1.1"
versions.support = "27.1.1"
versions.dagger = "2.15"
Expand All @@ -39,14 +39,16 @@ versions.dexmaker = "2.2.0"
versions.constraint_layout = "1.0.2"
versions.glide = "4.7.1"
versions.timber = "4.5.1"
versions.android_gradle_plugin = "3.1.1"
versions.android_gradle_plugin = "3.1.2"
versions.rxjava2 = "2.1.3"
versions.rx_android = "2.0.1"
versions.atsl_runner = "1.0.1"
versions.atsl_rules = "1.0.1"
versions.hamcrest = "1.3"
versions.kotlin = "1.2.41"
versions.paging = "1.0.0-rc1"
versions.paging = "1.0.0"
versions.work = "1.0.0-alpha01"
versions.navigation = "1.0.0-alpha01"
def deps = [:]

def support = [:]
Expand Down Expand Up @@ -139,6 +141,22 @@ build_versions.target_sdk = 26
build_versions.build_tools = "27.0.3"
ext.build_versions = build_versions

def work = [:]
work.runtime = "android.arch.work:work-runtime:$versions.work"
work.testing = "android.arch.work:work-testing:$versions.work"
work.firebase = "android.arch.work:work-firebase:$versions.work"
deps.work = work

def navigation = [:]
navigation.runtime = "android.arch.navigation:navigation-runtime:$versions.navigation"
navigation.runtime_ktx = "android.arch.navigation:navigation-runtime-ktx:$versions.navigation"
navigation.fragment = "android.arch.navigation:navigation-fragment:$versions.navigation"
navigation.fragment_ktx = "android.arch.navigation:navigation-fragment-ktx:$versions.navigation"
navigation.safe_args_plugin = "android.arch.navigation:navigation-safe-args-gradle-plugin:$versions.navigation"
navigation.testing_ktx = "android.arch.navigation:navigation-testing-ktx:$versions.navigation"
deps.navigation = navigation

ext.deps = deps

def addRepos(RepositoryHandler handler) {
handler.google()
Expand Down
24 changes: 21 additions & 3 deletions BasicSample/versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
ext.deps = [:]
def versions = [:]
versions.arch_core = "1.1.1"
versions.room = "1.1.0-rc1"
versions.room = "1.1.0"
versions.lifecycle = "1.1.1"
versions.support = "27.1.1"
versions.dagger = "2.15"
Expand All @@ -39,14 +39,16 @@ versions.dexmaker = "2.2.0"
versions.constraint_layout = "1.0.2"
versions.glide = "4.7.1"
versions.timber = "4.5.1"
versions.android_gradle_plugin = "3.1.1"
versions.android_gradle_plugin = "3.1.2"
versions.rxjava2 = "2.1.3"
versions.rx_android = "2.0.1"
versions.atsl_runner = "1.0.1"
versions.atsl_rules = "1.0.1"
versions.hamcrest = "1.3"
versions.kotlin = "1.2.41"
versions.paging = "1.0.0-rc1"
versions.paging = "1.0.0"
versions.work = "1.0.0-alpha01"
versions.navigation = "1.0.0-alpha01"
def deps = [:]

def support = [:]
Expand Down Expand Up @@ -139,6 +141,22 @@ build_versions.target_sdk = 26
build_versions.build_tools = "27.0.3"
ext.build_versions = build_versions

def work = [:]
work.runtime = "android.arch.work:work-runtime:$versions.work"
work.testing = "android.arch.work:work-testing:$versions.work"
work.firebase = "android.arch.work:work-firebase:$versions.work"
deps.work = work

def navigation = [:]
navigation.runtime = "android.arch.navigation:navigation-runtime:$versions.navigation"
navigation.runtime_ktx = "android.arch.navigation:navigation-runtime-ktx:$versions.navigation"
navigation.fragment = "android.arch.navigation:navigation-fragment:$versions.navigation"
navigation.fragment_ktx = "android.arch.navigation:navigation-fragment-ktx:$versions.navigation"
navigation.safe_args_plugin = "android.arch.navigation:navigation-safe-args-gradle-plugin:$versions.navigation"
navigation.testing_ktx = "android.arch.navigation:navigation-testing-ktx:$versions.navigation"
deps.navigation = navigation

ext.deps = deps

def addRepos(RepositoryHandler handler) {
handler.google()
Expand Down
3 changes: 3 additions & 0 deletions GithubBrowserSample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

apply plugin: 'kotlin-allopen'
apply plugin: 'androidx.navigation.safeargs'

allOpen {
// allows mocking for classes w/o directly opening them for release builds
Expand Down Expand Up @@ -70,6 +71,7 @@ dependencies {
implementation deps.support.recyclerview
implementation deps.support.cardview
implementation deps.support.design
implementation deps.navigation.fragment_ktx
implementation deps.room.runtime
implementation deps.lifecycle.runtime
implementation deps.lifecycle.extensions
Expand Down Expand Up @@ -100,6 +102,7 @@ dependencies {
})
testImplementation deps.mockito.core

androidTestImplementation deps.navigation.testing_ktx
androidTestImplementation deps.support.app_compat
androidTestImplementation deps.support.recyclerview
androidTestImplementation deps.support.cardview
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ import android.support.test.espresso.matcher.ViewMatchers.withId
import android.support.test.espresso.matcher.ViewMatchers.withText
import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import androidx.navigation.NavController
import com.android.example.github.R
import com.android.example.github.binding.FragmentBindingAdapters
import com.android.example.github.testing.SingleFragmentActivity
import com.android.example.github.ui.common.NavigationController
import com.android.example.github.util.CountingAppExecutorsRule
import com.android.example.github.util.EspressoTestUtil
import com.android.example.github.util.RecyclerViewMatcher
import com.android.example.github.util.TaskExecutorWithIdlingResourceRule
import com.android.example.github.util.TestUtil
import com.android.example.github.util.ViewModelUtil
import com.android.example.github.util.matcher
import com.android.example.github.util.mock
import com.android.example.github.vo.Contributor
import com.android.example.github.vo.Repo
import com.android.example.github.vo.Resource
Expand Down Expand Up @@ -67,19 +69,17 @@ class RepoFragmentTest {
val countingAppExecutors = CountingAppExecutorsRule()
private val repoLiveData = MutableLiveData<Resource<Repo>>()
private val contributorsLiveData = MutableLiveData<Resource<List<Contributor>>>()
private lateinit var repoFragment: RepoFragment
private lateinit var viewModel: RepoViewModel
private lateinit var mockBindingAdapter: FragmentBindingAdapters
private lateinit var navigationController: NavigationController

private val repoFragment = TestRepoFragment().apply {
arguments = RepoFragmentArgs.Builder("a", "b").build().toBundle()
}

@Before
fun init() {
EspressoTestUtil.disableProgressBarAnimations(activityRule)
repoFragment = RepoFragment.create("a", "b")
viewModel = mock(RepoViewModel::class.java)
mockBindingAdapter = mock(FragmentBindingAdapters::class.java)
navigationController = mock(NavigationController::class.java)
doNothing().`when`(viewModel).setId(anyString(), anyString())
`when`(viewModel.repo).thenReturn(repoLiveData)
`when`(viewModel.contributors).thenReturn(contributorsLiveData)
Expand All @@ -90,8 +90,8 @@ class RepoFragmentTest {
return mockBindingAdapter
}
}
repoFragment.navigationController = navigationController
activityRule.activity.setFragment(repoFragment)
EspressoTestUtil.disableProgressBarAnimations(activityRule)
}

@Test
Expand Down Expand Up @@ -168,7 +168,9 @@ class RepoFragmentTest {
fun testContributorClick() {
setContributors("aa", "bb", "cc")
onView(withText("cc")).perform(click())
verify(navigationController).navigateToUser("cc")
verify(repoFragment.navController).navigate(
RepoFragmentDirections.showUser("cc").matcher()
)
}

@Test
Expand Down Expand Up @@ -200,4 +202,9 @@ class RepoFragmentTest {
private fun getString(@StringRes id: Int, vararg args: Any): String {
return InstrumentationRegistry.getTargetContext().getString(id, *args)
}

class TestRepoFragment : RepoFragment() {
val navController = mock<NavController>()
override fun navController() = navController
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import android.support.v7.widget.RecyclerView
import android.view.KeyEvent
import androidx.navigation.NavController
import com.android.example.github.R
import com.android.example.github.binding.FragmentBindingAdapters
import com.android.example.github.testing.SingleFragmentActivity
import com.android.example.github.ui.common.NavigationController
import com.android.example.github.util.CountingAppExecutorsRule
import com.android.example.github.util.EspressoTestUtil
import com.android.example.github.util.RecyclerViewMatcher
import com.android.example.github.util.TaskExecutorWithIdlingResourceRule
import com.android.example.github.util.TestUtil
import com.android.example.github.util.ViewModelUtil
import com.android.example.github.util.matcher
import com.android.example.github.util.mock
import com.android.example.github.vo.Repo
import com.android.example.github.vo.Resource
import org.hamcrest.CoreMatchers.not
Expand All @@ -70,21 +72,18 @@ class SearchFragmentTest {
val countingAppExecutors = CountingAppExecutorsRule()

private lateinit var mockBindingAdapter: FragmentBindingAdapters
private lateinit var navigationController: NavigationController
private lateinit var viewModel: SearchViewModel
private val results = MutableLiveData<Resource<List<Repo>>>()
private val loadMoreStatus = MutableLiveData<SearchViewModel.LoadMoreState>()
private val searchFragment = TestSearchFragment()

@Before
fun init() {
EspressoTestUtil.disableProgressBarAnimations(activityRule)
val searchFragment = SearchFragment()
viewModel = mock(SearchViewModel::class.java)
doReturn(loadMoreStatus).`when`(viewModel).loadMoreStatus
`when`(viewModel.results).thenReturn(results)

mockBindingAdapter = mock(FragmentBindingAdapters::class.java)
navigationController = mock(NavigationController::class.java)

searchFragment.appExecutors = countingAppExecutors.appExecutors
searchFragment.viewModelFactory = ViewModelUtil.createFor(viewModel)
Expand All @@ -93,8 +92,8 @@ class SearchFragmentTest {
return mockBindingAdapter
}
}
searchFragment.navigationController = navigationController
activityRule.activity.setFragment(searchFragment)
EspressoTestUtil.disableProgressBarAnimations(activityRule)
}

@Test
Expand Down Expand Up @@ -147,7 +146,9 @@ class SearchFragmentTest {
val repo = TestUtil.createRepo("foo", "bar", "desc")
results.postValue(Resource.success(arrayListOf(repo)))
onView(withText("desc")).perform(click())
verify(navigationController).navigateToRepo("foo", "bar")
verify(searchFragment.navController).navigate(
SearchFragmentDirections.showRepo("foo", "bar").matcher()
)
}

@Test
Expand All @@ -171,4 +172,9 @@ class SearchFragmentTest {
private fun listMatcher(): RecyclerViewMatcher {
return RecyclerViewMatcher(R.id.repo_list)
}

class TestSearchFragment : SearchFragment() {
val navController = mock<NavController>()
override fun navController() = navController
}
}
Loading

0 comments on commit 8e77a8b

Please sign in to comment.