File tree 3 files changed +49
-3
lines changed
main/kotlin/net/mullvad/mullvadvpn
test/kotlin/net/mullvad/mullvadvpn/repository
3 files changed +49
-3
lines changed Original file line number Diff line number Diff line change @@ -2,9 +2,12 @@ package net.mullvad.mullvadvpn.repository
2
2
3
3
import android.content.SharedPreferences
4
4
import net.mullvad.mullvadvpn.util.IChangelogDataProvider
5
+ import net.mullvad.mullvadvpn.util.trimAll
5
6
6
7
private const val MISSING_VERSION_CODE = - 1
7
8
private const val NEWLINE_CHAR = ' \n '
9
+ private const val SPACE_STRING = " "
10
+ private const val BULLET_POINT_CHAR = ' -'
8
11
private const val LAST_SHOWED_CHANGELOG_VERSION_CODE = " last_showed_changelog_version_code"
9
12
10
13
class ChangelogRepository (
@@ -18,7 +21,10 @@ class ChangelogRepository(
18
21
fun setVersionCodeOfMostRecentChangelogShowed (versionCode : Int ) =
19
22
preferences.edit().putInt(LAST_SHOWED_CHANGELOG_VERSION_CODE , versionCode).apply ()
20
23
21
- fun getLastVersionChanges (): List <String > {
22
- return dataProvider.getChangelog().split(NEWLINE_CHAR ).filter { it.isNotEmpty() }
23
- }
24
+ fun getLastVersionChanges (): List <String > =
25
+ dataProvider
26
+ .getChangelog()
27
+ .split(BULLET_POINT_CHAR )
28
+ .map { it.split(NEWLINE_CHAR ).trimAll().joinToString(SPACE_STRING ).trim() }
29
+ .filter { it.isNotEmpty() }
24
30
}
Original file line number Diff line number Diff line change @@ -12,3 +12,5 @@ fun String.appendHideNavOnPlayBuild(isPlayBuild: Boolean): String =
12
12
13
13
fun String.removeHtmlTags (): String =
14
14
Html .fromHtml(this , HtmlCompat .FROM_HTML_MODE_LEGACY ).toString()
15
+
16
+ fun List<String>.trimAll () = map { it.trim() }
Original file line number Diff line number Diff line change
1
+ package net.mullvad.mullvadvpn.repository
2
+
3
+ import android.content.SharedPreferences
4
+ import io.mockk.every
5
+ import io.mockk.mockk
6
+ import net.mullvad.mullvadvpn.lib.common.test.assertLists
7
+ import net.mullvad.mullvadvpn.util.IChangelogDataProvider
8
+ import org.junit.jupiter.api.Test
9
+
10
+ class ChangelogRepositoryTest {
11
+
12
+ private val mockedPreferences: SharedPreferences = mockk()
13
+ private val mockDataProvider: IChangelogDataProvider = mockk()
14
+
15
+ private val changelogRepository =
16
+ ChangelogRepository (preferences = mockedPreferences, dataProvider = mockDataProvider)
17
+
18
+ @Test
19
+ fun `when given a changelog text should return a list of correctly formatted strings` () {
20
+ // Arrange
21
+ val testChangelog =
22
+ " - Added very nice new feature with a very long descriptive message\n " +
23
+ " about how it works...\n " +
24
+ " - Fixed super bad leak."
25
+ val expectedResult =
26
+ listOf (
27
+ " Added very nice new feature with a very long descriptive message about how it works..." ,
28
+ " Fixed super bad leak."
29
+ )
30
+ every { mockDataProvider.getChangelog() } returns testChangelog
31
+
32
+ // Act
33
+ val result = changelogRepository.getLastVersionChanges()
34
+
35
+ // Assert
36
+ assertLists(expectedResult, result)
37
+ }
38
+ }
You can’t perform that action at this time.
0 commit comments