Skip to content

Instantly share code, notes, and snippets.

View kaszabimre's full-sized avatar
🎯
Focusing

Imre Kaszab kaszabimre

🎯
Focusing
View GitHub Profile
@kaszabimre
kaszabimre / build.gradle
Last active July 17, 2020 09:31
Add Hilt dependency to your root build.gradle
buildscript {
....
ext.hilt_version = '2.28-alpha'
ext.hilt_jetpack_version = '1.0.0-alpha01'
....
dependencies {
....
@kaszabimre
kaszabimre / app\build.gradle
Created July 17, 2020 09:32
Add Hilt dependency to your app/build.gradle
....
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'
....
dependencies {
....
implementation "androidx.hilt:hilt-lifecycle-viewmodel:$hilt_jetpack_version"
kapt "androidx.hilt:hilt-compiler:$hilt_jetpack_version"
@kaszabimre
kaszabimre / HiltApplication.kt
Created July 17, 2020 09:39
Update HiltApplication.kt
@HiltAndroidApp
class HiltApplication : Application()
@kaszabimre
kaszabimre / NotificationServiceModule.kt
Created July 17, 2020 09:59
Update NotificationServiceModule
@Module
@InstallIn(ApplicationComponent::class)
class NotificationServiceModule {
@Provides
@Singleton
fun provideNotificationManager(@ApplicationContext context: Context) =
context.getSystemService<NotificationManager>()!!
}
@kaszabimre
kaszabimre / MainActivity.kt
Created July 17, 2020 10:19
Update MainActivity
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
// AndroidInjection.inject(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
@kaszabimre
kaszabimre / MainMenuFragment.kt
Created July 17, 2020 10:22
Update MainMenuFragment
@AndroidEntryPoint
class MainMenuFragment : Fragment() {
....
// override fun onAttach(context: Context) {
// AndroidSupportInjection.inject(this)
// super.onAttach(context)
// }
@kaszabimre
kaszabimre / MainMenuFragment.kt
Created July 17, 2020 10:35
Update MainMenuFragment again
@AndroidEntryPoint
class MainMenuFragment : Fragment() {
// @Inject
// lateinit var viewModelFactory: ViewModelProvider.Factory
@Inject
lateinit var notificationManager: NotificationManager
// private val viewModel = viewModels<MainMenuViewModel>(factoryProducer = { viewModelFactory })
@kaszabimre
kaszabimre / app\build.gradle
Created July 17, 2020 10:38
Remove Dagger-Android dependencies
....
dependencies {
....
// Dagger
implementation "com.google.dagger:dagger:$dagger_version"
// implementation "com.google.dagger:dagger-android-support:$dagger_version"
kapt "com.google.dagger:dagger-compiler:$dagger_version"
@kaszabimre
kaszabimre / GitHubUserListViewModelTests.kt
Created June 21, 2023 09:27
Unit test for the searchUser method in the ViewModel class, utilizing the MockKMP for verification. The test ensures that when a mock username is provided, the method returns a non-empty list with the user. Mock objects and assertions are used to validate the expected behavior.
@Test
fun `given mock username when searchUser called then returns non-emptyList with the user`() = runTest {
// Given
val userName = MockData.userName
everySuspending { action.searchUser(isAny()) } returns Unit
every { store.getUsers() } returns flowOf(listOf(MockData.user))
every { store.isFetchingFinished() } returns flowOf(true)
// When
viewModel.searchUser(userName)
@kaszabimre
kaszabimre / GitHubUserListViewModelTest.kt
Created June 21, 2023 09:30
Unit test for the GitHubUserListViewModel class showcasing the simplicity of using MockKMP framework. The test sets up mock objects for GitHubUserAction and GitHubUserStore, both of which are interfaces. The GitHubUserListViewModel is instantiated using the mock dependencies, demonstrating the ease of integration with MockKMP.
class GitHubUserListViewModelTest : TestsWithMocks() {
@Mock
lateinit var action: GitHubUserAction
@Mock
lateinit var store: GitHubUserStore
private val viewModel by withMocks { GitHubUserListViewModel(action, store) }
override fun setUpMocks() = injectMocks(mocker)