/*
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.android.gnd.ui.tos;

import androidx.arch.core.executor.testing.InstantTaskExecutorRule;
import com.google.android.gnd.persistence.local.LocalDatabaseModule;
import com.google.android.gnd.persistence.local.LocalValueStore;
import com.google.android.gnd.persistence.remote.RemoteDataStore;
import com.google.android.gnd.repository.TermsOfServiceRepository;
import com.google.android.gnd.rx.SchedulersModule;
import com.google.android.gnd.ui.common.Navigator;
import com.google.common.truth.Truth;
import dagger.hilt.android.testing.HiltAndroidRule;
import dagger.hilt.android.testing.HiltAndroidTest;
import dagger.hilt.android.testing.HiltTestApplication;
import dagger.hilt.android.testing.UninstallModules;
import javax.inject.Inject;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

@HiltAndroidTest
@UninstallModules({SchedulersModule.class, LocalDatabaseModule.class})
@Config(application = HiltTestApplication.class)
@RunWith(RobolectricTestRunner.class)
public class TermsOfServiceViewModelTest {

  @Rule public MockitoRule rule = MockitoJUnit.rule();

  @Rule public HiltAndroidRule hiltRule = new HiltAndroidRule(this);

  public TermsOfServiceViewModel termsOfServiceViewModel;
  @Rule public InstantTaskExecutorRule instantTaskExecutorRule = new InstantTaskExecutorRule();
  @Inject Navigator navigator;
  @Inject LocalValueStore localValueStore;
  @Mock RemoteDataStore mockRemoteDataStore;
  private TermsOfServiceRepository termsOfServiceRepository;

  @Before
  public void before() {
    hiltRule.inject();
    termsOfServiceRepository = new TermsOfServiceRepository(mockRemoteDataStore, localValueStore);
    termsOfServiceViewModel = new TermsOfServiceViewModel(navigator, termsOfServiceRepository);
  }

  @Test
  public void testButtonClick() {
    termsOfServiceViewModel.onButtonClicked();
    Truth.assertThat(termsOfServiceRepository.isTermsOfServiceAccepted()).isTrue();
  }

  @Test
  public void testTermsOfServiceText() {
    termsOfServiceViewModel.setTermsOfServiceText("Terms Text");
    Truth.assertThat(termsOfServiceViewModel.getTermsOfServiceText()).isEqualTo("Terms Text");
  }

  @Test
  public void testTermsOfServiceText_mismatch() {
    termsOfServiceViewModel.setTermsOfServiceText("Terms");
    Truth.assertThat(termsOfServiceViewModel.getTermsOfServiceText()).isNotEqualTo("Terms Text");
  }
}

@@ -640,634 +640,185 @@
 ort 
-androidx.arch.core.executor.testing.InstantTaskExecutorRule;%0Aimport com.google.android.gnd.persistence.local.LocalDatabaseModule;%0Aimport com.google.android.gnd.persistence.local.LocalValueStore;%0Aimport com.google.android.gnd.persistence.remote.RemoteDataStore;%0Aimport com.google.android.gnd.repository.TermsOfServiceRepository;%0Aimport com.google.android.gnd.rx.SchedulersModule;%0Aimport com.google.android.gnd.ui.common.Navigator;%0Aimport com.google.common.truth.Truth;%0Aimport dagger.hilt.android.testing.HiltAndroidRule;%0Aimport dagger.hilt.android.testing.HiltAndroidTest;%0Aimport dagger.hilt.android.testing.HiltTestApplica
+com.google.android.gnd.repository.TermsOfServiceRepository;%0Aimport com.google.android.gnd.ui.common.Navigator;%0Aimport com.google.android.gnd.ui.home.HomeScreenFragmentDirec
 tion
+s
 ;%0Aim
@@ -826,80 +826,37 @@
 ort 
-dagger.hilt.android.testing.UninstallModules;%0Aimport javax.inject.Inject
+com.google.common.truth.Truth
 ;%0Aim
@@ -939,28 +939,20 @@
 org.
-junit.runner.RunWith
+mockito.Mock
 ;%0Aim
@@ -964,32 +964,35 @@
 org.mockito.Mock
+ito
 ;%0Aimport org.moc
@@ -1058,605 +1058,116 @@
 le;%0A
-import org.robolectric.RobolectricTestRunner;%0Aimport org.robolectric.annotation.Config;%0A%0A@HiltAndroidTest%0A@UninstallModules(%7BSchedulersModule.class, LocalDatabaseModule.class%7D)%0A@Config(application = HiltTestApplication.class)%0A@RunWith(RobolectricTestRunner.class)%0Apublic class TermsOfServiceViewModelTest %7B%0A%0A  @Rule public MockitoRule rule = MockitoJUnit.rule();%0A%0A  @Rule public HiltAndroidRule hiltRule = new HiltAndroidRule(this);%0A%0A  public TermsOfServiceViewModel termsOfServiceViewModel;%0A  @Rule public InstantTaskExecutorRule instantTaskExecutorRule = new InstantTaskExecutorRule();%0A  @Inject
+%0Apublic class TermsOfServiceViewModelTest %7B%0A%0A  @Rule public MockitoRule rule = MockitoJUnit.rule();%0A%0A  @Mock
  Nav
@@ -1173,17 +1173,21 @@
 vigator 
-n
+mockN
 avigator
@@ -1195,92 +1195,54 @@
 %0A  @
-Inject LocalValueStore localValueStore;%0A  @Mock RemoteDataStore
+Mock TermsOfServiceRepository
  mockRe
-moteDataStore;
+pository;%0A
 %0A  p
@@ -1266,43 +1266,27 @@
 vice
-Repository termsOfServiceRepository
+ViewModel viewModel
 ;%0A%0A 
@@ -1327,145 +1327,9 @@
     
-hiltRule.inject();%0A    termsOfServiceRepository = new TermsOfServiceRepository(mockRemoteDataStore, localValueStore);%0A    termsOfServiceV
+v
 iewM
@@ -1363,17 +1363,21 @@
 ewModel(
-n
+mockN
 avigator
@@ -1378,30 +1378,20 @@
 igator, 
-termsOfService
+mock
 Reposito
@@ -1426,16 +1426,18 @@
 oid test
+On
 ButtonCl
@@ -1439,16 +1439,18 @@
 tonClick
+ed
 () %7B%0A   
@@ -1446,39 +1446,25 @@
 ked() %7B%0A    
-termsOfServiceV
+v
 iewModel.onB
@@ -1487,52 +1487,60 @@
     
-Truth.assertThat(termsOfServiceRepository.is
+Mockito.verify(mockRepository, Mockito.times(1)).set
 Term
@@ -1562,232 +1562,130 @@
 ted(
-)).isT
+t
 rue
-(
 );%0A  
-%7D%0A%0A  @Test%0A  public void testTermsOfServiceText() %7B%0A    termsOfServiceViewModel.setTermsOfServiceText(%22Terms Text%22);%0A    Truth.assertThat(termsOfServiceViewModel.getTermsOfServiceText()).isEqualTo(%22Terms Text%22
+  Mockito.verify(mockNavigator, Mockito.times(1))%0A        .navigate(HomeScreenFragmentDirections.showHomeScreen()
 );%0A 
@@ -1736,41 +1736,18 @@
 Text
-_mismatch() %7B%0A    termsOfServiceV
+() %7B%0A    v
 iewM
@@ -1779,16 +1779,21 @@
 t(%22Terms
+ Text
 %22);%0A    
@@ -1813,23 +1813,9 @@
 hat(
-termsOfServiceV
+v
 iewM
@@ -1850,11 +1850,8 @@
 ).is
-Not
 Equa

Simplify TermsOfServiceViewModelTest