Repository: corona-warn-app/cwa-app-android
File: Corona-Warn-App/src/test/java/de/rki/coronawarnapp/ccl/configuration/update/CclConfigurationUpdaterTest.kt (Kotlin)

Code before:
            cclSettings.setExecutionTimeToNow(any())
            dccWalletInfoUpdateTrigger.triggerAfterConfigChange(true)
        }

        // false should be passed to the trigger when there are no updates
        coEvery { boosterRulesRepository.update() } returns UpdateResult.NO_UPDATE
        getInstance().updateIfRequired()
        coVerify(exactly = 1) { dccWalletInfoUpdateTrigger.triggerAfterConfigChange(false) }
    }

    @Test
    fun `updateIfRequired() should NOT update booster rules and ccl configuration if NOT required but should trigger DccWalletInfo recalculation`() =
        runBlockingTest {
            coEvery { cclSettings.getLastExecutionTime() } returns Instant.parse("2000-01-01T00:00:00Z")
            coEvery { timeStamper.nowUTC } returns Instant.parse("2000-01-01T00:00:00Z")

            getInstance().updateIfRequired()

            verify { boosterRulesRepository wasNot Called }
            verify { cclConfigurationRepository wasNot Called }

            coVerify(exactly = 1) { dccWalletInfoUpdateTrigger.triggerAfterConfigChange(false) }
        }

    @Test
    fun `updateConfiguration() should return true if any item was downloaded or false otherwise`() =
        runBlockingTest {

            val updater = getInstance()

            coEvery { boosterRulesRepository.update() } returns UpdateResult.NO_UPDATE
            coEvery { cclConfigurationRepository.updateCclConfiguration() } returns UpdateResult.NO_UPDATE
            coEvery { dccValidationRepository.updateInvalidationRules() } returns UpdateResult.NO_UPDATE
            updater.updateConfiguration() shouldBe false

            coEvery { boosterRulesRepository.update() } returns UpdateResult.UPDATE
            coEvery { cclConfigurationRepository.updateCclConfiguration() } returns UpdateResult.NO_UPDATE
            coEvery { dccValidationRepository.updateInvalidationRules() } returns UpdateResult.NO_UPDATE
            updater.updateConfiguration() shouldBe true

            coEvery { boosterRulesRepository.update() } returns UpdateResult.NO_UPDATE
            coEvery { cclConfigurationRepository.updateCclConfiguration() } returns UpdateResult.UPDATE
            coEvery { dccValidationRepository.updateInvalidationRules() } returns UpdateResult.NO_UPDATE
            updater.updateConfiguration() shouldBe true

            coEvery { boosterRulesRepository.update() } returns UpdateResult.NO_UPDATE
            coEvery { cclConfigurationRepository.updateCclConfiguration() } returns UpdateResult.NO_UPDATE
            coEvery { dccValidationRepository.updateInvalidationRules() } returns UpdateResult.UPDATE
            updater.updateConfiguration() shouldBe true

            coEvery { boosterRulesRepository.update() } returns UpdateResult.UPDATE

Review comment (suggestion):
I think test above called `updateIfRequired() should NOT update booster rules and ccl configuration if NOT required but should trigger DccWalletInfo recalculation` should also verify that the `dccValidationRepository` was not called. 

Code after:

                cclSettings.setExecutionTimeToNow(any())
                dccWalletInfoUpdateTrigger.triggerAfterConfigChange(true)
            }

            // false should be passed to the trigger when there are no updates
            coEvery { boosterRulesRepository.update() } returns UpdateResult.NO_UPDATE
            getInstance().updateIfRequired()
            coVerify(exactly = 1) { dccWalletInfoUpdateTrigger.triggerAfterConfigChange(false) }
        }

    @Test
    fun `updateIfRequired() should NOT update if NOT required but should trigger DccWalletInfo recalculation`() =
        runBlockingTest {
            coEvery { cclSettings.getLastExecutionTime() } returns Instant.parse("2000-01-01T00:00:00Z")
            coEvery { timeStamper.nowUTC } returns Instant.parse("2000-01-01T00:00:00Z")

            getInstance().updateIfRequired()

            verify {
                boosterRulesRepository wasNot Called
                cclConfigurationRepository wasNot Called
                dccValidationRepository wasNot Called
            }

            coVerify(exactly = 1) { dccWalletInfoUpdateTrigger.triggerAfterConfigChange(false) }
        }

    @Test
    fun `updateConfiguration() should return true if anything was downloaded or false otherwise`() =
        runBlockingTest {

            val updater = getInstance()

            coEvery { boosterRulesRepository.update() } returns UpdateResult.NO_UPDATE
            coEvery { cclConfigurationRepository.updateCclConfiguration() } returns UpdateResult.NO_UPDATE
            coEvery { dccValidationRepository.updateInvalidationRules() } returns UpdateResult.NO_UPDATE
            updater.updateConfiguration() shouldBe false

            coEvery { boosterRulesRepository.update() } returns UpdateResult.UPDATE
            coEvery { cclConfigurationRepository.updateCclConfiguration() } returns UpdateResult.NO_UPDATE
            coEvery { dccValidationRepository.updateInvalidationRules() } returns UpdateResult.NO_UPDATE
            updater.updateConfiguration() shouldBe true

            coEvery { boosterRulesRepository.update() } returns UpdateResult.NO_UPDATE
            coEvery { cclConfigurationRepository.updateCclConfiguration() } returns UpdateResult.UPDATE
            coEvery { dccValidationRepository.updateInvalidationRules() } returns UpdateResult.NO_UPDATE
            updater.updateConfiguration() shouldBe true

            coEvery { boosterRulesRepository.update() } returns UpdateResult.NO_UPDATE
            coEvery { cclConfigurationRepository.updateCclConfiguration() } returns UpdateResult.NO_UPDATE