I tried to generate test via this plugin for the next class:
@Service
@Observed
class CustomerServiceImpl(
private val smthGraphQLClient: SmthGraphQLClient,
) : CustomerService {
@Throws(ExternalServiceException::class)
override fun getCustomerData(
customerGuid: UUID,
dataFieldNameList: List<String>,
delimiterForJsonField: String
): Map<String, Any> =
dataFieldNameList.asIterable()
.map { convertToGraphQlFriendlyField(it, delimiterForJsonField) }
.toList()
.runCatching { smthGraphQLClient.getCustomerDataByGuid(customerGuid, this) }
.onFailure { ex -> throw ExternalServiceException(ex.message) }
.getOrThrow()
/**
* Modifying field name with smth delimiter to graphQL friendly syntax
*
* @sample [fieldNameWithDelimiter]="customer.flag.reason" and [delimiter]=".".
* In this case result will be "{customer{flag{reason}}}"
*/
private fun convertToGraphQlFriendlyField(fieldNameWithDelimiter: String, delimiter: String): String {
val parts = fieldNameWithDelimiter.split(delimiter)
val output = StringBuilder()
for ((index, part) in parts.withIndex()) {
output.append(part)
if (index < parts.size - 1) {
output.append("{")
} else {
repeat(parts.size - 1) {
output.append("}")
}
}
}
return output.toString()
}
}
and got the generated test:
internal class CustomerServiceImplTest {
@Test
fun getCustomerDataTest() {
val obj = CustomerServiceImpl()
val expected = Map<String, Any>()
val actual = obj.getCustomerData()
Assertions.assertEquals(expected, actual)
}
}
May be it is not supported yet, but I am just leaving the trace about this problem
I tried to generate test via this plugin for the next class:
and got the generated test:
May be it is not supported yet, but I am just leaving the trace about this problem