Repository: corona-warn-app/cwa-app-android
File: Corona-Warn-App/src/main/java/de/rki/coronawarnapp/covidcertificate/test/core/TestCertificateRepository.kt (Kotlin)

Code before:
            is PCRCertificateData -> data.copy(recycledAt = time)
            is RACertificateData -> data.copy(recycledAt = time)
            is GenericTestCertificateData -> data.copy(recycledAt = time)
        }
    }

    private fun TestCertificateQRCode.createContainer(nowUtc: Instant = timeStamper.nowUTC): TestCertificateContainer {
        val data = GenericTestCertificateData(
            identifier = UUID.randomUUID().toString(),
            registeredAt = nowUtc,
            certificateReceivedAt = nowUtc, // Set this as we don't need to retrieve one
            testCertificateQrCode = qrCode,
            certificateSeenByUser = false // Newly added, should show badge
        )
        return TestCertificateContainer(
            data = data,
            qrCodeExtractor = qrCodeExtractor,
        )
    }

    private fun TestCertificateContainer.toTestCertificateOrNull(
        valueSet: TestCertificateValueSets?,
        certificateState: CwaCovidCertificate.State
    ): TestCertificate? {
        try {
            return toTestCertificate(valueSet, certificateState)
        } catch (e: Exception) {
            Timber.e(e, "Creating TestCertificate failed")
        }
        return null
    }

    private suspend fun TestCertificateContainer.toTestCertificateWrapper(
        valueSets: TestCertificateValueSets,
        dccValidityMeasures: DccValidityMeasures
    ): TestCertificateWrapper? {
        try {
            val state = when {
                isCertificateRetrievalPending -> Invalid()
                else -> testCertificateQRCode?.let {
                    dccState(
                        dccData = it.data,
                        qrCodeHash = it.qrCode.toSHA256(),
                        dccValidityMeasures = dccValidityMeasures
                    )
                } ?: Invalid()
            }

            return TestCertificateWrapper(
                valueSets = valueSets,
                container = this,

Review comment (refactor):
```suggestion
            return toTestCertificate(valueSet, certificateState)
            // read value from dcc data to throw an exception early if the DccQrCodeExtractor is not able to parse
            // the certificate
```

Code after:
            is PCRCertificateData -> data.copy(recycledAt = time)
            is RACertificateData -> data.copy(recycledAt = time)
            is GenericTestCertificateData -> data.copy(recycledAt = time)
        }
    }

    private fun TestCertificateQRCode.createContainer(nowUtc: Instant = timeStamper.nowUTC): TestCertificateContainer {
        val data = GenericTestCertificateData(
            identifier = UUID.randomUUID().toString(),
            registeredAt = nowUtc,
            certificateReceivedAt = nowUtc, // Set this as we don't need to retrieve one
            testCertificateQrCode = qrCode,
            certificateSeenByUser = false // Newly added, should show badge
        )
        return TestCertificateContainer(
            data = data,
            qrCodeExtractor = qrCodeExtractor,
        )
    }

    private fun TestCertificateContainer.toTestCertificateOrNull(
        valueSet: TestCertificateValueSets?,
        certificateState: CwaCovidCertificate.State
    ): TestCertificate? {
        try {
            return toTestCertificate(valueSet, certificateState)
            // read value from dcc data to throw an exception early if the DccQrCodeExtractor is not able to parse
            // the certificate
        } catch (e: Exception) {
            Timber.e(e, "Creating TestCertificate failed")
        }
        return null
    }

    private suspend fun TestCertificateContainer.toTestCertificateWrapper(
        valueSets: TestCertificateValueSets,
        dccValidityMeasures: DccValidityMeasures
    ): TestCertificateWrapper? {
        try {
            val state = when {
                isCertificateRetrievalPending -> Invalid()
                else -> testCertificateQRCode?.let {
                    dccState(
                        dccData = it.data,
                        qrCodeHash = it.qrCode.toSHA256(),
                        dccValidityMeasures = dccValidityMeasures
                    )
                } ?: Invalid()
            }

            return TestCertificateWrapper(