<commit_before>package me.nya_n.notificationnotifier.domain.usecase

import android.content.pm.PackageManager
import androidx.annotation.VisibleForTesting
import me.nya_n.notificationnotifier.domain.entities.AppException
import me.nya_n.notificationnotifier.domain.entities.InstalledApp
import me.nya_n.notificationnotifier.repositories.AppRepository
import me.nya_n.notificationnotifier.repositories.UserSettingRepository

class LoadAppUseCase(
    private val userSettingRepository: UserSettingRepository,
    private val appRepository: AppRepository
) {
    suspend operator fun invoke(pm: PackageManager): Result<Outputs> {
        val apps = loadInstalledAppList(pm).getOrElse {
            return Result.failure(it)
        }
        val targets = loadTargetList()
        return Result.success(Outputs(apps, targets))
    }

    @VisibleForTesting(otherwise = VisibleForTesting.NONE)
    fun loadInstalledAppList(pm: PackageManager): Result<List<InstalledApp>> {
        val setting = userSettingRepository.getUserSetting()
        return if (!setting.isPackageVisibilityGranted) {
            Result.failure(AppException.PermissionDeniedException())
        } else {
            Result.success(appRepository.loadInstalledAppList(pm))
        }
    }

    @VisibleForTesting(otherwise = VisibleForTesting.NONE)
    suspend fun loadTargetList(): List<InstalledApp> {
        return appRepository.getTargetAppList()
    }

    data class Outputs(
        val installs: List<InstalledApp>,
        val targets: List<InstalledApp>,
    )
}<commit_msg>VisibleForTestingの修正<commit_after>package me.nya_n.notificationnotifier.domain.usecase

import android.content.pm.PackageManager
import androidx.annotation.VisibleForTesting
import me.nya_n.notificationnotifier.domain.entities.AppException
import me.nya_n.notificationnotifier.domain.entities.InstalledApp
import me.nya_n.notificationnotifier.repositories.AppRepository
import me.nya_n.notificationnotifier.repositories.UserSettingRepository

class LoadAppUseCase(
    private val userSettingRepository: UserSettingRepository,
    private val appRepository: AppRepository
) {
    suspend operator fun invoke(pm: PackageManager): Result<Outputs> {
        val apps = loadInstalledAppList(pm).getOrElse {
            return Result.failure(it)
        }
        val targets = loadTargetList()
        return Result.success(Outputs(apps, targets))
    }

    @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
    fun loadInstalledAppList(pm: PackageManager): Result<List<InstalledApp>> {
        val setting = userSettingRepository.getUserSetting()
        return if (!setting.isPackageVisibilityGranted) {
            Result.failure(AppException.PermissionDeniedException())
        } else {
            Result.success(appRepository.loadInstalledAppList(pm))
        }
    }

    @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
    suspend fun loadTargetList(): List<InstalledApp> {
        return appRepository.getTargetAppList()
    }

    data class Outputs(
        val installs: List<InstalledApp>,
        val targets: List<InstalledApp>,
    )
}
{'fraction_non_alphanumeric': 0.08138417173982698, 'fraction_numerical': 0.0, 'mean_word_length': 4.04361873990307, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6965727', 'n_tokens_mistral': 854, 'n_tokens_neox': 835, 'n_words': 146}