Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package com.d4rk.androidtutorials.java.ui.screens.startup;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import android.app.Activity;

import androidx.arch.core.executor.testing.InstantTaskExecutorRule;

import com.d4rk.androidtutorials.java.data.repository.StartupRepository.OnFormError;
import com.d4rk.androidtutorials.java.domain.startup.LoadConsentFormUseCase;
import com.d4rk.androidtutorials.java.domain.startup.RequestConsentInfoUseCase;
import com.google.android.ump.ConsentRequestParameters;

import org.junit.Rule;
import org.junit.Test;

public class StartupViewModelTest {

@Rule
public InstantTaskExecutorRule instantTaskExecutorRule = new InstantTaskExecutorRule();

@Test
public void requestConsentInfoUpdateDelegatesToUseCase() {
RequestConsentInfoUseCase requestUseCase = mock(RequestConsentInfoUseCase.class);
LoadConsentFormUseCase loadUseCase = mock(LoadConsentFormUseCase.class);
StartupViewModel viewModel = new StartupViewModel(requestUseCase, loadUseCase);

Activity activity = mock(Activity.class);
ConsentRequestParameters params = mock(ConsentRequestParameters.class);
Runnable onSuccess = mock(Runnable.class);
OnFormError onError = mock(OnFormError.class);

viewModel.requestConsentInfoUpdate(activity, params, onSuccess, onError);

verify(requestUseCase).invoke(activity, params, onSuccess, onError);
Comment on lines +32 to +36

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Fix OnFormError type mismatch in StartupViewModel tests

The new tests pass com.d4rk.androidtutorials.java.data.repository.StartupRepository.OnFormError into StartupViewModel.requestConsentInfoUpdate, but the ViewModel’s method is typed to com.d4rk.androidtutorials.java.ui.screens.startup.repository.StartupRepository.OnFormError (a type that doesn’t exist). This causes the test suite to fail to compile before it can exercise the delegation logic. Align the test with the ViewModel’s API or, preferably, adjust the ViewModel to depend on the data-layer interface so both production and test code compile.

Useful? React with 👍 / 👎.

}

@Test
public void loadConsentFormDelegatesToUseCase() {
RequestConsentInfoUseCase requestUseCase = mock(RequestConsentInfoUseCase.class);
LoadConsentFormUseCase loadUseCase = mock(LoadConsentFormUseCase.class);
StartupViewModel viewModel = new StartupViewModel(requestUseCase, loadUseCase);

Activity activity = mock(Activity.class);
OnFormError onError = mock(OnFormError.class);

viewModel.loadConsentForm(activity, onError);

verify(loadUseCase).invoke(activity, onError);
}
}