Skip to content

Instantly share code, notes, and snippets.

View hongbeomi's full-sized avatar
🏃‍♂️
Slowly And Steadily

ian.0701(이안) hongbeomi

🏃‍♂️
Slowly And Steadily
View GitHub Profile
ConcatAdapterController(
ConcatAdapter concatAdapter,
ConcatAdapter.Config config
) {
...
if (config.isolateViewTypes) {
mViewTypeStorage = new ViewTypeStorage.IsolatedViewTypeStorage();
} else {
mViewTypeStorage = new ViewTypeStorage.SharedIdRangeViewTypeStorage();
}
class ConcatAdapterController implements NestedAdapterWrapper.Callback {
...
private final ViewTypeStorage mViewTypeStorage;
...
}
class NestedAdapterWrapper {
@NonNull
private final ViewTypeStorage.ViewTypeLookup mViewTypeLookup;
@NonNull
private final StableIdStorage.StableIdLookup mStableIdLookup;
public final Adapter<ViewHolder> adapter;
final Callback mCallback;
int mCachedItemCount;
class ConcatAdapterController implements NestedAdapterWrapper.Callback
public static final class Config {
public final boolean isolateViewTypes;
@NonNull
public final StableIdMode stableIdMode;
@NonNull
public static final Config DEFAULT = new Config(true, NO_STABLE_IDS);
}
@Test
fun fetchData_loading() {
// 메인 디스패처를 게으르게 시작하는 디스패처로 교체
Dispatchers.setMain(StandardTestDispatcher())
// 데이터 가져오기
viewModel.fetch()
// 로딩 상태 체크
assertEquals(true, viewModel.loading.getOrAwaitValue())
// 예약되어 있던 작업 실행
advanceUntilIdle()
@Test
fun fetchData_loading() {
// 메인 디스패처 정지를 위해 pause
mainCoroutineRule.pauseDispatcher()
// 데이터 가져오기
viewModel.fetch()
// 로딩 상태 체크
assertEquals(true, viewModel.loading.getOrAwaitValue())
// 메인 디스패처 다시 시작을 위해 resume
mainCoroutineRule.resumeDispatcher()
class MainDispatcherRule(
val testDispatcher: TestDispatcher = UnconfinedTestDispatcher()
): TestWatcher() {
override fun starting(description: Description) {
super.starting(description)
Dispatchers.setMain(testDispatcher)
}
override fun finished(description: Description) {
class MainDispatcherRule(
val dispatcher = TestCoroutineDispatcher()
) : TestWatcher() {
override fun starting(description: Description?) {
super.starting(description)
Dispatchers.setMain(dispatcher)
}
override fun finished(description: Description?) {
@Test
// fun test() = coroutineRule.runBlockingTest {
// // Test
// }
fun test() = runTest {
// Test
}