@Service class RoamingService( private val roamingApiClient: MvnoRoamingApiClient ) {…
- User
@Service class RoamingService( private val roamingApiClient: MvnoRoamingApiClient ) { suspend fun getCountries(headers: Headers, namePattern: String?): List = roamingApiClient.getCountries( headers = FeignHeaders.of(headers), namePattern = namePattern ).awaitFirst().countries
codesuspend fun getCommonServices(headers: Headers, mcc: String): List<CommonServiceDto> = roamingApiClient.getCommonServices( headers = FeignHeaders.of(headers), mcc = mcc ).awaitFirst().services suspend fun getAdditionalServices(headers: Headers, mcc: String, contractId: String): List<AdditionalServiceDto> = roamingApiClient.getAdditionalServices( headers = FeignHeaders.of(headers), mcc = mcc, contractId = contractId ).awaitFirst().additionalServices suspend fun getIdentTypes(headers: Headers, additionalServices: List<AdditionalServiceDto>) = coroutineScope { additionalServices .map { it.identType } .toSet() .map { identType -> async { getRoamingGroups(headers, identType) } } .awaitAll() .flatten() } suspend fun getRoamingGroups(headers: Headers, identType: String?): List<IdentTypeDto> = roamingApiClient.getAdditionalServicesMccGroups( headers = FeignHeaders.of(headers), identType = identType ).awaitFirst().identTypes fun getRoamingMinimumGroupOrEmpty(identTypes: List<IdentTypeDto>): Set<String> { val minGroupOrNull = identTypes.minByOrNull { it.mccGroup.size } return if (minGroupOrNull == null) { emptySet() } else { minGroupOrNull.mccGroup.toSet() } }}
using kotlin juni5 mockito extention mock<>() write test for function getRoamingGroupOrEmpty
- Assistant
Certainly! Below is an example of how you can write a JUnit 5 test for the
getRoamingMinimumGroupOrEmptyfunction of yourRoamingServiceclass using Kotlin with Mockito extensionmock().Since
getRoamingMinimumGroupOrEmptyis a pure function (doesn't depend on external services or suspend functions), the test is straightforward: just prepare input data and verify the output.