divinenickname / utgen-kotlin-idea-plugin

Simplify your testing process with automated test generation tailored for Kotlin codebases.
https://plugins.jetbrains.com/plugin/23907-utgen
Apache License 2.0
3 stars 1 forks source link

Unexpected behaviour for test generation #20

Open FrozenMorozen opened 2 weeks ago

FrozenMorozen commented 2 weeks ago

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

divinenickname commented 1 week ago

@FrozenMorozen, could you tell me what you expected in this case?

I see one problem with an unhandled throw-catch case. Is that what you meant?