This file contains hidden or 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 MainActivity extends AppCompatActivity implements WifiChangeBroadcastReceiver.WifiChangeBroadcastListener { | |
| private WifiManager wifiManager; | |
| private ConnectivityManager connectivityManager; | |
| private WifiChangeBroadcastReceiver wifiStateChangeReceiver; | |
| @Override | |
| protected void onCreate(@Nullable Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); |
This file contains hidden or 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
| @HiltViewModel | |
| class MainViewModel | |
| @Inject constructor(private val userServices: UserServices) : ViewModel() { | |
| val state = MutableStateFlow<State>(State.START) | |
| init { | |
| loadUser() | |
| } |
This file contains hidden or 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
| class MainViewModelTest { | |
| private val userServices = mock<UserServices>() | |
| private lateinit var viewModel: MainViewModel | |
| @Before | |
| fun setup(){ | |
| viewModel = MainViewModel(userServices) | |
| } |
This file contains hidden or 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
| class MainViewModelTest { | |
| private val userServices = mock<UserServices>() | |
| private lateinit var viewModel: MainViewModel | |
| @Test | |
| fun `Loading state works`() = runBlocking { | |
| whenever(userServices.getUsers()).thenReturn(emptyList()) | |
| viewModel = MainViewModel(userServices) |
This file contains hidden or 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
| @ExperimentalCoroutinesApi | |
| class MainCoroutineRule : TestWatcher(), | |
| TestCoroutineScope by TestCoroutineScope() { | |
| override fun starting(description: Description) { | |
| super.starting(description) | |
| Dispatchers.setMain( | |
| this.coroutineContext[ContinuationInterceptor] as CoroutineDispatcher) | |
| } |
This file contains hidden or 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
| class MainViewModelTest { | |
| @get:Rule | |
| val mainCoroutineRule = MainCoroutineRule() | |
| private val userServices = mock<UserServices>() | |
| private lateinit var viewModel: MainViewModel | |
| @Test |
This file contains hidden or 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
| data class AppDispatchers( | |
| val IO: CoroutineDispatcher = Dispatchers.IO | |
| ) |
This file contains hidden or 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
| @HiltViewModel | |
| class MainViewModel | |
| @Inject constructor( | |
| private val userServices: UserServices, | |
| private val appDispatchers: AppDispatchers, | |
| ) : ViewModel() { | |
| val state = MutableStateFlow<State>(State.START) | |
| init { |
This file contains hidden or 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 val testDispatcher = AppDispatchers( | |
| IO = TestCoroutineDispatcher() | |
| ) |
This file contains hidden or 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
| class MainViewModelTest { | |
| @get:Rule | |
| val mainCoroutineRule = MainCoroutineRule() | |
| private val userServices = mock<UserServices>() | |
| private lateinit var viewModel: MainViewModel | |
| private val testDispatcher = AppDispatchers( |
OlderNewer