From a3f1331b0b6b0bb41670439da1f80786fce3c48b Mon Sep 17 00:00:00 2001 From: Jonatan Rhodin Date: Wed, 19 Jun 2024 23:36:20 +0200 Subject: [PATCH] Add unit test for changelog parsing --- .../repository/ChangelogRepositoryTest.kt | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 android/app/src/test/kotlin/net/mullvad/mullvadvpn/repository/ChangelogRepositoryTest.kt diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/repository/ChangelogRepositoryTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/repository/ChangelogRepositoryTest.kt new file mode 100644 index 000000000000..4df5c101a759 --- /dev/null +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/repository/ChangelogRepositoryTest.kt @@ -0,0 +1,38 @@ +package net.mullvad.mullvadvpn.repository + +import android.content.SharedPreferences +import io.mockk.every +import io.mockk.mockk +import net.mullvad.mullvadvpn.lib.common.test.assertLists +import net.mullvad.mullvadvpn.util.IChangelogDataProvider +import org.junit.jupiter.api.Test + +class ChangelogRepositoryTest { + + private val mockedPreferences: SharedPreferences = mockk() + private val mockDataProvider: IChangelogDataProvider = mockk() + + private val changelogRepository = + ChangelogRepository(preferences = mockedPreferences, dataProvider = mockDataProvider) + + @Test + fun `when given a changelog text should return a list of correctly formatted strings`() { + // Arrange + val testChangelog = + "- Added very nice new feature with a very long descriptive message\n" + + " about how it works...\n" + + "- Fixed super bad leak." + val expectedResult = + listOf( + "Added very nice new feature with a very long descriptive message about how it works...", + "Fixed super bad leak." + ) + every { mockDataProvider.getChangelog() } returns testChangelog + + // Act + val result = changelogRepository.getLastVersionChanges() + + // Assert + assertLists(expectedResult, result) + } +}