@@ -17,6 +17,8 @@ import org.wordpress.android.ui.stats.refresh.utils.StatsDateFormatter
1717import org.wordpress.android.ui.stats.refresh.utils.StatsUtils
1818import org.wordpress.android.util.text.PercentFormatter
1919import org.wordpress.android.viewmodel.ResourceProvider
20+ import java.math.RoundingMode
21+ import java.math.RoundingMode.HALF_UP
2022
2123class PostDayViewsMapperTest : BaseUnitTest () {
2224 @Mock lateinit var statsDateFormatter: StatsDateFormatter
@@ -57,7 +59,7 @@ class PostDayViewsMapperTest : BaseUnitTest() {
5759
5860 @Test
5961 fun `builds title with positive difference` () {
60- whenever(percentFormatter.format(3.0F )).thenReturn(" 300" )
62+ whenever(percentFormatter.format(value = 3.0F , rounding = RoundingMode . HALF_UP )).thenReturn(" 300" )
6163 val previousCount = 5
6264 val previousItem = selectedItem.copy(count = previousCount)
6365 val positiveLabel = " +15 (300%)"
@@ -92,7 +94,7 @@ class PostDayViewsMapperTest : BaseUnitTest() {
9294
9395 @Test
9496 fun `builds title with negative difference` () {
95- whenever(percentFormatter.format(- 0.33333334F )).thenReturn(" -33" )
97+ whenever(percentFormatter.format(value = - 0.33333334F , rounding = HALF_UP )).thenReturn(" -33" )
9698 val previousCount = 30
9799 val previousItem = selectedItem.copy(count = previousCount)
98100 val negativeLabel = " -10 (-33%)"
@@ -109,7 +111,7 @@ class PostDayViewsMapperTest : BaseUnitTest() {
109111
110112 @Test
111113 fun `builds title with max negative difference` () {
112- whenever(percentFormatter.format(- 1F )).thenReturn(" -100" )
114+ whenever(percentFormatter.format(value = - 1F , rounding = HALF_UP )).thenReturn(" -100" )
113115 val newCount = 0
114116 val newItem = selectedItem.copy(count = newCount)
115117 val negativeLabel = " -20 (-100%)"
@@ -150,7 +152,7 @@ class PostDayViewsMapperTest : BaseUnitTest() {
150152
151153 @Test
152154 fun `builds title with negative difference for the last item` () {
153- whenever(percentFormatter.format(- 0.33333334F )).thenReturn(" -33" )
155+ whenever(percentFormatter.format(value = - 0.33333334F , rounding = HALF_UP )).thenReturn(" -33" )
154156 val previousCount = 30
155157 val previousItem = selectedItem.copy(count = previousCount)
156158 val negativeLabel = " -10 (-33%)"
@@ -167,12 +169,12 @@ class PostDayViewsMapperTest : BaseUnitTest() {
167169
168170 @Test
169171 fun `should call PercentFormatter when builds title` () {
170- whenever(percentFormatter.format(3.0F )).thenReturn(" 3%" )
172+ whenever(percentFormatter.format(value = 3.0F , rounding = HALF_UP )).thenReturn(" 3%" )
171173 val previousCount = 5
172174 val previousItem = selectedItem.copy(count = previousCount)
173175 mapper.buildTitle(selectedItem, previousItem, false )
174176
175177 // buildChange is called twice: for change and unformattedChange
176- verify(percentFormatter, times(2 )).format(3.0F )
178+ verify(percentFormatter, times(2 )).format(value = 3.0F , rounding = HALF_UP )
177179 }
178180}
0 commit comments