How to write JUnit test cases for Settings.Global methods?

29 views Asked by At

Could you please support to write Junit test for the following functions storeDataScrollableFromSWC() and readDataScrollableFromSWC()? These belong to a viewmodel class. I tried multiple ways, but could not succeed.

@HiltViewModel
public class ViewModel extends AndroidViewModel {
public static final String SCROLL_FROM_SWC = "SCROLL_FROM_SWC";
public static final int CHECKED_STATE = 1;
public static final int UN_CHECKED_STATE = 0;
private static final int DEFAULT_VALUE = 0;

@Inject
public InputSettingViewModel(@NonNull Application application) {
    super(application);
}

public void storeDataScrollableFromSWC(boolean state) {
    int intValue = state ? CHECKED_STATE : UN_CHECKED_STATE;
    Settings.Global.putInt(getApplication().getContentResolver(), SCROLL_FROM_SWC, intValue);
}

public int readDataScrollableFromSWC() {
    return Settings.Global.getInt(getApplication().getContentResolver(), SCROLL_FROM_SWC, DEFAULT_VALUE);
}
0

There are 0 answers