From 1d4ede7b947d4013f95570b4eb4244b962584ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miquel=20Mart=C3=AD?= Date: Fri, 12 Jan 2024 18:41:10 +0100 Subject: [PATCH] migrate from @MethodSource to @CsvSource when possible --- .../application/RedrawWidgetUseCaseTest.kt | 141 ++--- .../user/ProcessIntentUseCaseTest.kt | 26 +- .../minimalcalendarwidget/domain/DayTest.kt | 236 +++----- .../domain/InstanceTest.kt | 290 ++++----- .../domain/component/DaysHeaderServiceTest.kt | 527 +++------------- .../domain/component/DaysServiceTest.kt | 570 ++++++++---------- .../domain/component/LayoutServiceTest.kt | 40 +- .../MonthAndYearHeaderServiceTest.kt | 112 ++-- .../domain/configuration/item/CalendarTest.kt | 58 +- .../domain/configuration/item/ColourTest.kt | 10 +- .../configuration/item/SymbolSetTest.kt | 47 +- .../domain/configuration/item/TextSizeTest.kt | 84 ++- .../domain/configuration/item/ThemeTest.kt | 437 ++------------ .../configuration/item/TransparencyTest.kt | 125 ++-- .../resolver/CalendarResolverTest.kt | 11 +- .../resolver/SystemResolverTest.kt | 35 +- 16 files changed, 906 insertions(+), 1843 deletions(-) diff --git a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/application/RedrawWidgetUseCaseTest.kt b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/application/RedrawWidgetUseCaseTest.kt index a9ae130b..995b3f47 100644 --- a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/application/RedrawWidgetUseCaseTest.kt +++ b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/application/RedrawWidgetUseCaseTest.kt @@ -25,7 +25,7 @@ import io.mockk.verify import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.MethodSource +import org.junit.jupiter.params.provider.CsvSource import java.time.DayOfWeek import java.util.concurrent.TimeoutException import kotlin.system.measureTimeMillis @@ -91,8 +91,21 @@ internal class RedrawWidgetUseCaseTest : BaseTest() { } @ParameterizedTest - @MethodSource("getWidgetIdsWithDrawingConfigurations") - fun shouldRedrawWidgetRegardlessOfBinderProxyTransactionTimeout(testProperties: RedrawWidgetUseCaseTestProperties) { + @CsvSource( + "1,32,DARK,20,33,MONDAY,false", + "5,100,LIGHT,5,33,SUNDAY,false", + "7,0,DARK,100,34,THURSDAY,true", + "14,50,DARK,32,35,MONDAY,true" + ) + fun shouldRedrawWidgetRegardlessOfBinderProxyTransactionTimeout( + appWidgetId: Int, + textSizePercentage: Int, + widgetTheme: Theme, + transparencyPercentage: Int, + runtimeSDK: Int, + firstDayOfWeek: DayOfWeek, + shouldHaveFirstWeekLocalPreferenceEnabled: Boolean + ) { mockkObject( ActionableView.ConfigurationIcon, ActionableView.MonthAndYearHeader, @@ -110,62 +123,32 @@ internal class RedrawWidgetUseCaseTest : BaseTest() { justRun { ActionableView.ConfigurationIcon.addListener(context, any()) } justRun { ActionableView.MonthAndYearHeader.addListener(context, any()) } - mockWidgetTextSize(testProperties.textSize) - mockWidgetTheme(testProperties.widgetTheme) - mockWidgetTransparency(testProperties.transparency) + val textSize = TextSize(textSizePercentage) + val transparency = Transparency(transparencyPercentage) + mockWidgetTextSize(textSize) + mockWidgetTheme(widgetTheme) + mockWidgetTransparency(transparency) - mockGetRuntimeSDK(testProperties.runtimeSDK) - if (testProperties.shouldHaveFirstWeekLocalPreferenceEnabled) { - mockGetSystemFirstDayOfWeek(testProperties.firstDayOfWeek) + mockGetRuntimeSDK(runtimeSDK) + if (shouldHaveFirstWeekLocalPreferenceEnabled) { + mockGetSystemFirstDayOfWeek(firstDayOfWeek) } else { - mockFirstDayOfWeek(testProperties.firstDayOfWeek) + mockFirstDayOfWeek(firstDayOfWeek) } - justRun { - LayoutService.draw( - context = context, - widgetRemoteView = any(), - widgetTheme = testProperties.widgetTheme, - transparency = testProperties.transparency - ) - } - justRun { - MonthAndYearHeaderService.draw( - context = context, - widgetRemoteView = any(), - textSize = testProperties.textSize, - widgetTheme = testProperties.widgetTheme - ) - } - justRun { - DaysHeaderService.draw( - context = context, - widgetRemoteView = any(), - firstDayOfWeek = testProperties.firstDayOfWeek, - widgetTheme = testProperties.widgetTheme, - transparency = testProperties.transparency, - textSize = testProperties.textSize - ) - } - justRun { - DaysService.draw( - context = context, - widgetRemoteView = any(), - firstDayOfWeek = testProperties.firstDayOfWeek, - widgetTheme = testProperties.widgetTheme, - transparency = testProperties.transparency, - textSize = testProperties.textSize - ) - } + justRun { LayoutService.draw(context, any(), widgetTheme, transparency) } + justRun { MonthAndYearHeaderService.draw(context, any(), textSize, widgetTheme) } + justRun { DaysHeaderService.draw(context, any(), firstDayOfWeek, widgetTheme, transparency, textSize) } + justRun { DaysService.draw(context, any(), firstDayOfWeek, widgetTheme, transparency, textSize) } val binderProxyTransactionTimeoutInMillis = 1000L - every { appWidgetManager.updateAppWidget(testProperties.appWidgetId, any()) } answers { + every { appWidgetManager.updateAppWidget(appWidgetId, any()) } answers { Thread.sleep(binderProxyTransactionTimeoutInMillis) throw TimeoutException("android.os.BinderProxy.transactNative timeout") } val executionTime = measureTimeMillis { - RedrawWidgetUseCase.execute(context, appWidgetManager, testProperties.appWidgetId) + RedrawWidgetUseCase.execute(context, appWidgetManager, appWidgetId) } assertThat(executionTime).isLessThan(binderProxyTransactionTimeoutInMillis) @@ -173,51 +156,20 @@ internal class RedrawWidgetUseCaseTest : BaseTest() { verifyWidgetTheme() verifyWidgetTransparency() verifyGetRuntimeSDK() - when (testProperties.shouldHaveFirstWeekLocalPreferenceEnabled) { + when (shouldHaveFirstWeekLocalPreferenceEnabled) { true -> verifyGetSystemFirstDayOfWeek() else -> verifyFirstDayOfWeek() } verify { context.packageName } verify { ActionableView.ConfigurationIcon.addListener(context, any()) } verify { ActionableView.MonthAndYearHeader.addListener(context, any()) } - verify { - LayoutService.draw( - context = context, - widgetRemoteView = any(), - widgetTheme = testProperties.widgetTheme, - transparency = testProperties.transparency - ) - } - verify { - MonthAndYearHeaderService.draw( - context = context, - widgetRemoteView = any(), - textSize = testProperties.textSize, - widgetTheme = testProperties.widgetTheme - ) - } - verify { - DaysHeaderService.draw( - context = context, - widgetRemoteView = any(), - firstDayOfWeek = testProperties.firstDayOfWeek, - widgetTheme = testProperties.widgetTheme, - transparency = testProperties.transparency, - textSize = testProperties.textSize - ) - } - verify { - DaysService.draw( - context = context, - widgetRemoteView = any(), - firstDayOfWeek = testProperties.firstDayOfWeek, - widgetTheme = testProperties.widgetTheme, - transparency = testProperties.transparency, - textSize = testProperties.textSize - ) - } - verify { appWidgetManager.updateAppWidget(testProperties.appWidgetId, any()) } + verify { LayoutService.draw(context, any(), widgetTheme, transparency) } + verify { MonthAndYearHeaderService.draw(context, any(), textSize, widgetTheme) } + verify { DaysHeaderService.draw(context, any(), firstDayOfWeek, widgetTheme, transparency, textSize) } + verify { DaysService.draw(context, any(), firstDayOfWeek, widgetTheme, transparency, textSize) } + + verify { appWidgetManager.updateAppWidget(appWidgetId, any()) } confirmVerified( appWidgetManager, @@ -227,21 +179,4 @@ internal class RedrawWidgetUseCaseTest : BaseTest() { DaysService ) } - - private fun getWidgetIdsWithDrawingConfigurations() = listOf( - RedrawWidgetUseCaseTestProperties(1, TextSize(32), Theme.DARK, Transparency(20), 33, DayOfWeek.MONDAY, false), - RedrawWidgetUseCaseTestProperties(5, TextSize(100), Theme.LIGHT, Transparency(5), 33, DayOfWeek.SUNDAY, false), - RedrawWidgetUseCaseTestProperties(7, TextSize(0), Theme.DARK, Transparency(100), 34, DayOfWeek.THURSDAY, true), - RedrawWidgetUseCaseTestProperties(14, TextSize(50), Theme.DARK, Transparency(32), 35, DayOfWeek.MONDAY, true) - ) - - internal data class RedrawWidgetUseCaseTestProperties( - val appWidgetId: Int, - val textSize: TextSize, - val widgetTheme: Theme, - val transparency: Transparency, - val runtimeSDK: Int, - val firstDayOfWeek: DayOfWeek, - val shouldHaveFirstWeekLocalPreferenceEnabled: Boolean - ) } \ No newline at end of file diff --git a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/application/user/ProcessIntentUseCaseTest.kt b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/application/user/ProcessIntentUseCaseTest.kt index 01e43ffb..fcfeaf55 100644 --- a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/application/user/ProcessIntentUseCaseTest.kt +++ b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/application/user/ProcessIntentUseCaseTest.kt @@ -16,8 +16,7 @@ import io.mockk.mockkObject import io.mockk.verify import org.junit.jupiter.api.Test import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.Arguments.of -import org.junit.jupiter.params.provider.MethodSource +import org.junit.jupiter.params.provider.CsvSource import org.junit.jupiter.params.provider.NullSource import org.junit.jupiter.params.provider.ValueSource import java.time.Instant.ofEpochSecond @@ -147,7 +146,14 @@ internal class ProcessIntentUseCaseTest : BaseTest() { } @ParameterizedTest - @MethodSource("getMincalCalendarIntentActionAndExpectedExtraInstantAndStartTimeInstant") + @ValueSource( + strings = [ + "$CELL_DAY_CLICK_ACTION.1675786154", + "$CELL_DAY_CLICK_ACTION.1671349586", + "$CELL_DAY_CLICK_ACTION.1624298458", + "$CELL_DAY_CLICK_ACTION.1434887405" + ] + ) fun shouldLaunchCalendarActivityOnTodayAndRedrawWidget(action: String) { mockIntent(action) mockIsReadCalendarPermitted(true) @@ -172,7 +178,12 @@ internal class ProcessIntentUseCaseTest : BaseTest() { } @ParameterizedTest - @MethodSource("getMincalCalendarIntentActionAndExpectedExtraInstantAndStartTimeInstant") + @CsvSource( + "$CELL_DAY_CLICK_ACTION.1675886154,1675886154,1675863134", + "$CELL_DAY_CLICK_ACTION.1671249586,1671249586,1671283934", + "$CELL_DAY_CLICK_ACTION.1624398458,1624398458,1624455134", + "$CELL_DAY_CLICK_ACTION.1434987405,1434987405,1434979934" + ) fun shouldLaunchCalendarActivityOnIntentExtraAndRedrawWidget_whenIntentAndPermissionsGiven( action: String, extraInstantEpochSeconds: Long, @@ -204,11 +215,4 @@ internal class ProcessIntentUseCaseTest : BaseTest() { verify { RedrawWidgetUseCase.execute(context) } verify { AutoUpdate.set(context) } } - - private fun getMincalCalendarIntentActionAndExpectedExtraInstantAndStartTimeInstant() = listOf( - of("$CELL_DAY_CLICK_ACTION.1675886154", 1675886154, 1675863134), - of("$CELL_DAY_CLICK_ACTION.1671249586", 1671249586, 1671283934), - of("$CELL_DAY_CLICK_ACTION.1624398458", 1624398458, 1624455134), - of("$CELL_DAY_CLICK_ACTION.1434987405", 1434987405, 1434979934) - ) } \ No newline at end of file diff --git a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/DayTest.kt b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/DayTest.kt index 40306dfb..fbeba365 100644 --- a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/DayTest.kt +++ b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/DayTest.kt @@ -5,194 +5,118 @@ package cat.mvmike.minimalcalendarwidget.domain import cat.mvmike.minimalcalendarwidget.BaseTest import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.MethodSource +import org.junit.jupiter.params.provider.CsvSource import java.time.DayOfWeek import java.time.LocalDate -import java.time.LocalDate.parse internal class DayTest : BaseTest() { @ParameterizedTest - @MethodSource("getLocalDatesWithExpectations") - fun getDayOfWeek(dayProperties: DayTestProperties) { - val day = Day( - dayLocalDate = dayProperties.localDate - ) + @CsvSource( + "2018-01-01,MONDAY", + "2017-12-02,SATURDAY", + "2018-12-04,TUESDAY", + "2012-07-05,THURSDAY", + "2018-05-05,SATURDAY", + "2020-12-09,WEDNESDAY", + "2021-11-11,THURSDAY", + "2030-02-12,TUESDAY", + "2015-03-15,SUNDAY", + "2016-06-21,TUESDAY", + "1994-04-23,SATURDAY", + "2000-08-27,SUNDAY", + "2018-12-28,FRIDAY", + "2019-12-31,TUESDAY" + ) + fun getDayOfWeek(dayLocalDate: LocalDate, expectedDayOfWeek: DayOfWeek) { + val day = Day(dayLocalDate) val result = day.getDayOfWeek() - assertThat(result).isEqualTo(dayProperties.expectedDayOfWeek) + assertThat(result).isEqualTo(expectedDayOfWeek) } @ParameterizedTest - @MethodSource("getLocalDatesWithExpectations") - fun getDayOfMonthString(dayProperties: DayTestProperties) { - val day = Day( - dayLocalDate = dayProperties.localDate - ) + @CsvSource( + "2018-01-01,1", + "2017-12-02,2", + "2018-12-04,4", + "2012-07-05,5", + "2018-05-05,5", + "2020-12-09,9", + "2021-11-11,11", + "2030-02-12,12", + "2015-03-15,15", + "2016-06-21,21", + "1994-04-23,23", + "2000-08-27,27", + "2018-12-28,28", + "2019-12-31,31" + ) + fun getDayOfMonthString(dayLocalDate: LocalDate, expectedDayOfMonthString: String) { + val day = Day(dayLocalDate) val result = day.getDayOfMonthString() - assertThat(result).isEqualTo(dayProperties.expectedDayOfMonthString) + assertThat(result).isEqualTo(expectedDayOfMonthString) } @ParameterizedTest - @MethodSource("getLocalDatesWithExpectations") - fun isInMonth(dayProperties: DayTestProperties) { - val day = Day( - dayLocalDate = dayProperties.localDate - ) + @CsvSource( + "2017-12-02,false", + "2018-11-30,false", + "2018-12-01,true", + "2018-12-04,true", + "2018-12-31,true", + "2019-01-01,false", + "2030-02-12,false" + ) + fun isInMonth(dayLocalDate: LocalDate, expectedIsInMonth: Boolean) { + val day = Day(dayLocalDate) val result = day.isInMonth(systemLocalDate) - assertThat(result).isEqualTo(dayProperties.expectedIsInMonth) + assertThat(result).isEqualTo(expectedIsInMonth) } @ParameterizedTest - @MethodSource("getLocalDatesWithExpectations") - fun isToday(dayProperties: DayTestProperties) { - val day = Day( - dayLocalDate = dayProperties.localDate - ) + @CsvSource( + "2018-01-01,false", + "2017-12-02,false", + "2018-12-04,true", + "2012-07-05,false", + "2018-05-05,false" + ) + fun isToday(dayLocalDate: LocalDate, expectedIsToday: Boolean) { + val day = Day(dayLocalDate) val result = day.isToday(systemLocalDate) - assertThat(result).isEqualTo(dayProperties.expectedIsToday) + assertThat(result).isEqualTo(expectedIsToday) } @ParameterizedTest - @MethodSource("getLocalDatesWithExpectations") - fun isWeekend(dayProperties: DayTestProperties) { - val day = Day( - dayLocalDate = dayProperties.localDate - ) + @CsvSource( + "2018-01-01,false", + "2017-12-02,true", + "2018-12-04,false", + "2012-07-05,false", + "2018-05-05,true", + "2020-12-09,false", + "2021-11-11,false", + "2030-02-12,false", + "2015-03-15,true", + "2016-06-21,false", + "1994-04-23,true", + "2000-08-27,true", + "2018-12-28,false", + "2019-12-31,false" + ) + fun isWeekend(dayLocalDate: LocalDate, expectedIsWeekend: Boolean) { + val day = Day(dayLocalDate) val result = day.isWeekend() - assertThat(result).isEqualTo(dayProperties.expectedIsWeekend) + assertThat(result).isEqualTo(expectedIsWeekend) } - - private fun getLocalDatesWithExpectations() = listOf( - DayTestProperties( - localDate = parse("2018-01-01"), - expectedDayOfMonthString = "1", - expectedDayOfWeek = DayOfWeek.MONDAY, - expectedIsInMonth = false, - expectedIsToday = false, - expectedIsWeekend = false - ), - DayTestProperties( - localDate = parse("2017-12-02"), - expectedDayOfMonthString = "2", - expectedDayOfWeek = DayOfWeek.SATURDAY, - expectedIsInMonth = false, - expectedIsToday = false, - expectedIsWeekend = true - ), - DayTestProperties( - localDate = parse("2018-12-04"), - expectedDayOfMonthString = "4", - expectedDayOfWeek = DayOfWeek.TUESDAY, - expectedIsInMonth = true, - expectedIsToday = true, - expectedIsWeekend = false - ), - DayTestProperties( - localDate = parse("2012-07-05"), - expectedDayOfMonthString = "5", - expectedDayOfWeek = DayOfWeek.THURSDAY, - expectedIsInMonth = false, - expectedIsToday = false, - expectedIsWeekend = false - ), - DayTestProperties( - localDate = parse("2018-05-05"), - expectedDayOfMonthString = "5", - expectedDayOfWeek = DayOfWeek.SATURDAY, - expectedIsInMonth = false, - expectedIsToday = false, - expectedIsWeekend = true - ), - DayTestProperties( - localDate = parse("2020-12-09"), - expectedDayOfMonthString = "9", - expectedDayOfWeek = DayOfWeek.WEDNESDAY, - expectedIsInMonth = false, - expectedIsToday = false, - expectedIsWeekend = false - ), - DayTestProperties( - localDate = parse("2021-11-11"), - expectedDayOfMonthString = "11", - expectedDayOfWeek = DayOfWeek.THURSDAY, - expectedIsInMonth = false, - expectedIsToday = false, - expectedIsWeekend = false - ), - DayTestProperties( - localDate = parse("2030-02-12"), - expectedDayOfMonthString = "12", - expectedDayOfWeek = DayOfWeek.TUESDAY, - expectedIsInMonth = false, - expectedIsToday = false, - expectedIsWeekend = false - ), - DayTestProperties( - localDate = parse("2015-03-15"), - expectedDayOfMonthString = "15", - expectedDayOfWeek = DayOfWeek.SUNDAY, - expectedIsInMonth = false, - expectedIsToday = false, - expectedIsWeekend = true - ), - DayTestProperties( - localDate = parse("2016-06-21"), - expectedDayOfMonthString = "21", - expectedDayOfWeek = DayOfWeek.TUESDAY, - expectedIsInMonth = false, - expectedIsToday = false, - expectedIsWeekend = false - ), - DayTestProperties( - localDate = parse("1994-04-23"), - expectedDayOfMonthString = "23", - expectedDayOfWeek = DayOfWeek.SATURDAY, - expectedIsInMonth = false, - expectedIsToday = false, - expectedIsWeekend = true - ), - DayTestProperties( - localDate = parse("2000-08-27"), - expectedDayOfMonthString = "27", - expectedDayOfWeek = DayOfWeek.SUNDAY, - expectedIsInMonth = false, - expectedIsToday = false, - expectedIsWeekend = true - ), - DayTestProperties( - localDate = parse("2018-12-28"), - expectedDayOfMonthString = "28", - expectedDayOfWeek = DayOfWeek.FRIDAY, - expectedIsInMonth = true, - expectedIsToday = false, - expectedIsWeekend = false - ), - DayTestProperties( - localDate = parse("2019-12-31"), - expectedDayOfMonthString = "31", - expectedDayOfWeek = DayOfWeek.TUESDAY, - expectedIsInMonth = false, - expectedIsToday = false, - expectedIsWeekend = false - ) - ) - - internal data class DayTestProperties( - val localDate: LocalDate, - val expectedDayOfMonthString: String, - val expectedDayOfWeek: DayOfWeek, - val expectedIsInMonth: Boolean, - val expectedIsToday: Boolean, - val expectedIsWeekend: Boolean - ) } \ No newline at end of file diff --git a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/InstanceTest.kt b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/InstanceTest.kt index 610cfd79..8e72e054 100644 --- a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/InstanceTest.kt +++ b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/InstanceTest.kt @@ -19,7 +19,16 @@ import java.time.ZonedDateTime internal class InstanceTest : BaseTest() { @ParameterizedTest - @MethodSource("getInstancesWithExpectedIsInDay") + @MethodSource( + value = [ + "getInstancesStartingAndEndingBeforeSystemLocalDate", + "getInstancesStartingBeforeAndEndingInSystemLocalDate", + "getInstancesStartingBeforeAndEndingAfterSystemLocalDate", + "getInstancesStartingInAndEndingInSystemLocalDate", + "getInstancesStartingInAndEndingAfterSystemLocalDate", + "getInstancesStartingAfterAndEndingAfterSystemLocalDate" + ] + ) fun isInDay( instance: Instance, expectedIsInDay: Boolean @@ -61,168 +70,125 @@ internal class InstanceTest : BaseTest() { verify { CalendarResolver.getInstances(context, initEpochMillis, endEpochMillis) } } - // calendarProvider uses UTC when allDay, systemOffset otherwise - private fun getInstancesWithExpectedIsInDay() = listOf( - // starting and ending before day - of( - TimedInstance( - eventId = random.nextInt(), - isDeclined = false, - start = ZonedDateTime.parse("2018-12-02T02:15:00+03:00"), - end = ZonedDateTime.parse("2018-12-03T23:15:00+03:00") - ), - false - ), - of( - TimedInstance( - eventId = random.nextInt(), - isDeclined = false, - start = ZonedDateTime.parse("2018-12-02T02:15:00-08:00"), - end = ZonedDateTime.parse("2018-12-03T11:30:00-08:00") - ), - false - ), - of( - AllDayInstance( - eventId = random.nextInt(), - isDeclined = false, - start = LocalDate.parse("2018-12-02"), - end = LocalDate.parse("2018-12-03") - ), - false - ), - // starting before and ending in day - of( - TimedInstance( - eventId = random.nextInt(), - isDeclined = false, - start = ZonedDateTime.parse("2018-12-01T00:00:00+03:00"), - end = ZonedDateTime.parse("2018-12-04T23:59:00+03:00") - ), - true - ), - of( - TimedInstance( - eventId = random.nextInt(), - isDeclined = false, - start = ZonedDateTime.parse("2018-12-02T02:15:00-08:00"), - end = ZonedDateTime.parse("2018-12-03T13:30:00-08:00") - ), - true - ), - of( - AllDayInstance( - eventId = random.nextInt(), - isDeclined = false, - start = LocalDate.parse("2018-12-01"), - end = LocalDate.parse("2018-12-05") - ), - true - ), - // starting before and ending after day - of( - TimedInstance( - eventId = random.nextInt(), - isDeclined = false, - start = ZonedDateTime.parse("2018-12-01T10:55:00+03:00"), - end = ZonedDateTime.parse("2018-12-07T23:00:00+03:00") - ), - true - ), - of( - AllDayInstance( - eventId = random.nextInt(), - isDeclined = false, - start = LocalDate.parse("2018-12-01"), - end = LocalDate.parse("2018-12-07") - ), - true - ), - // starting in and ending in day - of( - TimedInstance( - eventId = random.nextInt(), - isDeclined = false, - start = ZonedDateTime.parse("2018-12-04T23:00:00+03:00"), - end = ZonedDateTime.parse("2018-12-04T23:50:00+03:00") - ), - true - ), - of( - TimedInstance( - eventId = random.nextInt(), - isDeclined = false, - start = ZonedDateTime.parse("2018-12-03T13:30:00-08:00"), - end = ZonedDateTime.parse("2018-12-04T10:30:00-08:00") - ), - true - ), - of( - AllDayInstance( - eventId = random.nextInt(), - isDeclined = false, - start = LocalDate.parse("2018-12-04"), - end = LocalDate.parse("2018-12-05") - ), - true - ), - // starting in and ending after day - of( - TimedInstance( - eventId = random.nextInt(), - isDeclined = false, - start = ZonedDateTime.parse("2018-12-04T23:00:00+03:00"), - end = ZonedDateTime.parse("2018-12-05T01:00:00+03:00") - ), - true - ), - of( - TimedInstance( - eventId = random.nextInt(), - isDeclined = false, - start = ZonedDateTime.parse("2018-12-04T12:30:00-08:00"), - end = ZonedDateTime.parse("2018-12-04T16:30:00-08:00") - ), - true - ), - of( - AllDayInstance( - eventId = random.nextInt(), - isDeclined = false, - start = LocalDate.parse("2018-12-04"), - end = LocalDate.parse("2018-12-06") - ), - true - ), - // starting after and ending after day - of( - TimedInstance( - eventId = random.nextInt(), - isDeclined = false, - start = ZonedDateTime.parse("2018-12-05T00:00:00+03:00"), - end = ZonedDateTime.parse("2018-12-05T02:00:00+03:00") - ), - false - ), - of( - TimedInstance( - eventId = random.nextInt(), - isDeclined = false, - start = ZonedDateTime.parse("2018-12-04T13:30:00-08:00"), - end = ZonedDateTime.parse("2018-12-04T16:30:00-08:00") - ), - false - ), - of( - AllDayInstance( - eventId = random.nextInt(), - isDeclined = false, - start = LocalDate.parse("2018-12-05"), - end = LocalDate.parse("2018-12-06") - ), - false + private fun getInstancesStartingAndEndingBeforeSystemLocalDate() = listOf( + TimedInstance( + eventId = random.nextInt(), + isDeclined = false, + start = ZonedDateTime.parse("2018-12-02T02:15:00+03:00"), + end = ZonedDateTime.parse("2018-12-03T23:15:00+03:00") + ), + TimedInstance( + eventId = random.nextInt(), + isDeclined = false, + start = ZonedDateTime.parse("2018-12-02T02:15:00-08:00"), + end = ZonedDateTime.parse("2018-12-03T11:30:00-08:00") + ), + AllDayInstance( + eventId = random.nextInt(), + isDeclined = false, + start = LocalDate.parse("2018-12-02"), + end = LocalDate.parse("2018-12-03") ) - ) + ).map { of(it, false) } + + private fun getInstancesStartingBeforeAndEndingInSystemLocalDate() = listOf( + TimedInstance( + eventId = random.nextInt(), + isDeclined = false, + start = ZonedDateTime.parse("2018-12-01T00:00:00+03:00"), + end = ZonedDateTime.parse("2018-12-04T23:59:00+03:00") + ), + TimedInstance( + eventId = random.nextInt(), + isDeclined = false, + start = ZonedDateTime.parse("2018-12-02T02:15:00-08:00"), + end = ZonedDateTime.parse("2018-12-03T13:30:00-08:00") + ), + AllDayInstance( + eventId = random.nextInt(), + isDeclined = false, + start = LocalDate.parse("2018-12-01"), + end = LocalDate.parse("2018-12-05") + ) + ).map { of(it, true) } + + private fun getInstancesStartingBeforeAndEndingAfterSystemLocalDate() = listOf( + TimedInstance( + eventId = random.nextInt(), + isDeclined = false, + start = ZonedDateTime.parse("2018-12-01T10:55:00+03:00"), + end = ZonedDateTime.parse("2018-12-07T23:00:00+03:00") + ), + AllDayInstance( + eventId = random.nextInt(), + isDeclined = false, + start = LocalDate.parse("2018-12-01"), + end = LocalDate.parse("2018-12-07") + ) + ).map { of(it, true) } + + private fun getInstancesStartingInAndEndingInSystemLocalDate() = listOf( + TimedInstance( + eventId = random.nextInt(), + isDeclined = false, + start = ZonedDateTime.parse("2018-12-04T23:00:00+03:00"), + end = ZonedDateTime.parse("2018-12-04T23:50:00+03:00") + ), + TimedInstance( + eventId = random.nextInt(), + isDeclined = false, + start = ZonedDateTime.parse("2018-12-03T13:30:00-08:00"), + end = ZonedDateTime.parse("2018-12-04T10:30:00-08:00") + ), + AllDayInstance( + eventId = random.nextInt(), + isDeclined = false, + start = LocalDate.parse("2018-12-04"), + end = LocalDate.parse("2018-12-05") + ) + ).map { of(it, true) } + + private fun getInstancesStartingInAndEndingAfterSystemLocalDate() = listOf( + TimedInstance( + eventId = random.nextInt(), + isDeclined = false, + start = ZonedDateTime.parse("2018-12-04T23:00:00+03:00"), + end = ZonedDateTime.parse("2018-12-05T01:00:00+03:00") + ), + TimedInstance( + eventId = random.nextInt(), + isDeclined = false, + start = ZonedDateTime.parse("2018-12-04T12:30:00-08:00"), + end = ZonedDateTime.parse("2018-12-04T16:30:00-08:00") + ), + AllDayInstance( + eventId = random.nextInt(), + isDeclined = false, + start = LocalDate.parse("2018-12-04"), + end = LocalDate.parse("2018-12-06") + ) + ).map { of(it, true) } + + private fun getInstancesStartingAfterAndEndingAfterSystemLocalDate() = listOf( + TimedInstance( + eventId = random.nextInt(), + isDeclined = false, + start = ZonedDateTime.parse("2018-12-05T00:00:00+03:00"), + end = ZonedDateTime.parse("2018-12-05T02:00:00+03:00") + ), + TimedInstance( + eventId = random.nextInt(), + isDeclined = false, + start = ZonedDateTime.parse("2018-12-04T13:30:00-08:00"), + end = ZonedDateTime.parse("2018-12-04T16:30:00-08:00") + ), + AllDayInstance( + eventId = random.nextInt(), + isDeclined = false, + start = LocalDate.parse("2018-12-05"), + end = LocalDate.parse("2018-12-06") + ) + ).map { of(it, false) } private fun getSetsOfExpectedInstances() = listOf( emptySet(), diff --git a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/component/DaysHeaderServiceTest.kt b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/component/DaysHeaderServiceTest.kt index c94951cc..b0d39d6c 100644 --- a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/component/DaysHeaderServiceTest.kt +++ b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/component/DaysHeaderServiceTest.kt @@ -5,9 +5,12 @@ package cat.mvmike.minimalcalendarwidget.domain.component import android.widget.RemoteViews import cat.mvmike.minimalcalendarwidget.BaseTest import cat.mvmike.minimalcalendarwidget.R +import cat.mvmike.minimalcalendarwidget.domain.component.DaysHeaderService.getRotatedDaysOfWeek import cat.mvmike.minimalcalendarwidget.domain.configuration.item.Cell import cat.mvmike.minimalcalendarwidget.domain.configuration.item.TextSize import cat.mvmike.minimalcalendarwidget.domain.configuration.item.Theme +import cat.mvmike.minimalcalendarwidget.domain.configuration.item.Theme.DARK +import cat.mvmike.minimalcalendarwidget.domain.configuration.item.Theme.LIGHT import cat.mvmike.minimalcalendarwidget.domain.configuration.item.Transparency import cat.mvmike.minimalcalendarwidget.domain.configuration.item.TransparencyRange import cat.mvmike.minimalcalendarwidget.domain.intent.ActionableView @@ -19,6 +22,7 @@ import io.mockk.mockk import io.mockk.mockkObject import io.mockk.verify import io.mockk.verifyOrder +import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.Arguments.of import org.junit.jupiter.params.provider.MethodSource @@ -38,46 +42,42 @@ internal class DaysHeaderServiceTest : BaseTest() { private val daysHeaderRowRv = mockk() @ParameterizedTest - @MethodSource("getStartWeekDayAndThemeAndTextSizeWithExpectedOutput") + @MethodSource("getFirstDayOfWeekAndThemeAndThemeAndTextSizeWithExpectedOutput") fun draw_shouldAddViewBasedOnCurrentConfigAndTextSize( firstDayOfWeek: DayOfWeek, widgetTheme: Theme, transparency: Transparency, textSize: TextSize, - expectedDayHeaders: List + expectedDayHeaders: List ) { mockkObject(ActionableView.RowHeader) - every { GraphicResolver.createDaysHeaderRow(context) } returns daysHeaderRowRv - - expectedDayHeaders.forEach { - mockTransparency(it.getCellHeader(widgetTheme).background, transparency, TransparencyRange.MODERATE) - val resourceAndTranslation = it.dayOfWeek.getExpectedResourceIdAndTranslation() + val rotatedWeekDays = getRotatedDaysOfWeek(firstDayOfWeek) + rotatedWeekDays.forEach { + mockTransparency(widgetTheme.getCellHeader(it).background, transparency, TransparencyRange.MODERATE) + val resourceAndTranslation = it.getExpectedResourceIdAndTranslation() every { context.getString(resourceAndTranslation.first) } returns resourceAndTranslation.second } - - justRun { - GraphicResolver.addToDaysHeaderRow(context, daysHeaderRowRv, any(), any()) - } + justRun { GraphicResolver.addToDaysHeaderRow(context, daysHeaderRowRv, any(), any()) } justRun { GraphicResolver.addToWidget(widgetRv, daysHeaderRowRv) } justRun { ActionableView.RowHeader.addListener(context, widgetRv) } DaysHeaderService.draw(context, widgetRv, firstDayOfWeek, widgetTheme, transparency, textSize) verify(exactly = 1) { GraphicResolver.createDaysHeaderRow(context) } - expectedDayHeaders.forEach { - verify { context.getString(it.dayOfWeek.getExpectedResourceIdAndTranslation().first) } - verifyTransparency(it.getCellHeader(widgetTheme).background, transparency, TransparencyRange.MODERATE) + rotatedWeekDays.forEach { + verify { context.getString(it.getExpectedResourceIdAndTranslation().first) } + verifyTransparency(widgetTheme.getCellHeader(it).background, transparency, TransparencyRange.MODERATE) } verifyOrder { - expectedDayHeaders.forEach { + rotatedWeekDays.zip(expectedDayHeaders).forEach { GraphicResolver.addToDaysHeaderRow( context = context, daysHeaderRowRemoteView = daysHeaderRowRv, - dayHeaderBackgroundColour = it.getCellHeader(widgetTheme).background, + dayHeaderBackgroundColour = widgetTheme.getCellHeader(it.first).background, cell = Cell( - text = it.expectedHeaderText, - colour = it.getCellHeader(widgetTheme).textColour, + text = it.second, + colour = widgetTheme.getCellHeader(it.first).textColour, relativeSize = textSize.relativeValue ) ) @@ -88,444 +88,63 @@ internal class DaysHeaderServiceTest : BaseTest() { confirmVerified(widgetRv, daysHeaderRowRv) } - private fun getStartWeekDayAndThemeAndTextSizeWithExpectedOutput() = listOf( - of( - MONDAY, - Theme.DARK, - Transparency(10), - TextSize(40), - listOf( - DayHeaderTestProperties(MONDAY, "MON"), - DayHeaderTestProperties(TUESDAY, "DOO"), - DayHeaderTestProperties(WEDNESDAY, "WED"), - DayHeaderTestProperties(THURSDAY, "THU"), - DayHeaderTestProperties(FRIDAY, "FRI"), - DayHeaderTestProperties(SATURDAY, "SAT"), - DayHeaderTestProperties(SUNDAY, "SUN") - ) - ), - of( - TUESDAY, - Theme.DARK, - Transparency(20), - TextSize(40), - listOf( - DayHeaderTestProperties(TUESDAY, "DOO"), - DayHeaderTestProperties(WEDNESDAY, "WED"), - DayHeaderTestProperties(THURSDAY, "THU"), - DayHeaderTestProperties(FRIDAY, "FRI"), - DayHeaderTestProperties(SATURDAY, "SAT"), - DayHeaderTestProperties(SUNDAY, "SUN"), - DayHeaderTestProperties(MONDAY, "MON") - ) - ), - of( - WEDNESDAY, - Theme.DARK, - Transparency(20), - TextSize(40), - listOf( - DayHeaderTestProperties(WEDNESDAY, "WED"), - DayHeaderTestProperties(THURSDAY, "THU"), - DayHeaderTestProperties(FRIDAY, "FRI"), - DayHeaderTestProperties(SATURDAY, "SAT"), - DayHeaderTestProperties(SUNDAY, "SUN"), - DayHeaderTestProperties(MONDAY, "MON"), - DayHeaderTestProperties(TUESDAY, "DOO") - ) - ), - of( - THURSDAY, - Theme.DARK, - Transparency(30), - TextSize(40), - listOf( - DayHeaderTestProperties(THURSDAY, "THU"), - DayHeaderTestProperties(FRIDAY, "FRI"), - DayHeaderTestProperties(SATURDAY, "SAT"), - DayHeaderTestProperties(SUNDAY, "SUN"), - DayHeaderTestProperties(MONDAY, "MON"), - DayHeaderTestProperties(TUESDAY, "DOO"), - DayHeaderTestProperties(WEDNESDAY, "WED") - ) - ), - of( - FRIDAY, - Theme.DARK, - Transparency(90), - TextSize(40), - listOf( - DayHeaderTestProperties(FRIDAY, "FRI"), - DayHeaderTestProperties(SATURDAY, "SAT"), - DayHeaderTestProperties(SUNDAY, "SUN"), - DayHeaderTestProperties(MONDAY, "MON"), - DayHeaderTestProperties(TUESDAY, "DOO"), - DayHeaderTestProperties(WEDNESDAY, "WED"), - DayHeaderTestProperties(THURSDAY, "THU") - ) - ), - of( - SATURDAY, - Theme.DARK, - Transparency(15), - TextSize(40), - listOf( - DayHeaderTestProperties(SATURDAY, "SAT"), - DayHeaderTestProperties(SUNDAY, "SUN"), - DayHeaderTestProperties(MONDAY, "MON"), - DayHeaderTestProperties(TUESDAY, "DOO"), - DayHeaderTestProperties(WEDNESDAY, "WED"), - DayHeaderTestProperties(THURSDAY, "THU"), - DayHeaderTestProperties(FRIDAY, "FRI") - ) - ), - of( - SUNDAY, - Theme.DARK, - Transparency(20), - TextSize(40), - listOf( - DayHeaderTestProperties(SUNDAY, "SUN"), - DayHeaderTestProperties(MONDAY, "MON"), - DayHeaderTestProperties(TUESDAY, "DOO"), - DayHeaderTestProperties(WEDNESDAY, "WED"), - DayHeaderTestProperties(THURSDAY, "THU"), - DayHeaderTestProperties(FRIDAY, "FRI"), - DayHeaderTestProperties(SATURDAY, "SAT") - ) - ), - of( - MONDAY, - Theme.DARK, - Transparency(0), - TextSize(15), - listOf( - DayHeaderTestProperties(MONDAY, "M"), - DayHeaderTestProperties(TUESDAY, "D"), - DayHeaderTestProperties(WEDNESDAY, "W"), - DayHeaderTestProperties(THURSDAY, "T"), - DayHeaderTestProperties(FRIDAY, "F"), - DayHeaderTestProperties(SATURDAY, "S"), - DayHeaderTestProperties(SUNDAY, "S") - ) - ), - of( - TUESDAY, - Theme.DARK, - Transparency(55), - TextSize(15), - listOf( - DayHeaderTestProperties(TUESDAY, "D"), - DayHeaderTestProperties(WEDNESDAY, "W"), - DayHeaderTestProperties(THURSDAY, "T"), - DayHeaderTestProperties(FRIDAY, "F"), - DayHeaderTestProperties(SATURDAY, "S"), - DayHeaderTestProperties(SUNDAY, "S"), - DayHeaderTestProperties(MONDAY, "M") - ) - ), - of( - WEDNESDAY, - Theme.DARK, - Transparency(15), - TextSize(15), - listOf( - DayHeaderTestProperties(WEDNESDAY, "W"), - DayHeaderTestProperties(THURSDAY, "T"), - DayHeaderTestProperties(FRIDAY, "F"), - DayHeaderTestProperties(SATURDAY, "S"), - DayHeaderTestProperties(SUNDAY, "S"), - DayHeaderTestProperties(MONDAY, "M"), - DayHeaderTestProperties(TUESDAY, "D") - ) - ), - of( - THURSDAY, - Theme.DARK, - Transparency(20), - TextSize(15), - listOf( - DayHeaderTestProperties(THURSDAY, "T"), - DayHeaderTestProperties(FRIDAY, "F"), - DayHeaderTestProperties(SATURDAY, "S"), - DayHeaderTestProperties(SUNDAY, "S"), - DayHeaderTestProperties(MONDAY, "M"), - DayHeaderTestProperties(TUESDAY, "D"), - DayHeaderTestProperties(WEDNESDAY, "W") - ) - ), - of( - FRIDAY, - Theme.DARK, - Transparency(20), - TextSize(15), - listOf( - DayHeaderTestProperties(FRIDAY, "F"), - DayHeaderTestProperties(SATURDAY, "S"), - DayHeaderTestProperties(SUNDAY, "S"), - DayHeaderTestProperties(MONDAY, "M"), - DayHeaderTestProperties(TUESDAY, "D"), - DayHeaderTestProperties(WEDNESDAY, "W"), - DayHeaderTestProperties(THURSDAY, "T") - ) - ), - of( - SATURDAY, - Theme.DARK, - Transparency(20), - TextSize(15), - listOf( - DayHeaderTestProperties(SATURDAY, "S"), - DayHeaderTestProperties(SUNDAY, "S"), - DayHeaderTestProperties(MONDAY, "M"), - DayHeaderTestProperties(TUESDAY, "D"), - DayHeaderTestProperties(WEDNESDAY, "W"), - DayHeaderTestProperties(THURSDAY, "T"), - DayHeaderTestProperties(FRIDAY, "F") - ) - ), - of( - SUNDAY, - Theme.DARK, - Transparency(20), - TextSize(15), - listOf( - DayHeaderTestProperties(SUNDAY, "S"), - DayHeaderTestProperties(MONDAY, "M"), - DayHeaderTestProperties(TUESDAY, "D"), - DayHeaderTestProperties(WEDNESDAY, "W"), - DayHeaderTestProperties(THURSDAY, "T"), - DayHeaderTestProperties(FRIDAY, "F"), - DayHeaderTestProperties(SATURDAY, "S") - ) - ), - of( - MONDAY, - Theme.LIGHT, - Transparency(80), - TextSize(40), - listOf( - DayHeaderTestProperties(MONDAY, "MON"), - DayHeaderTestProperties(TUESDAY, "DOO"), - DayHeaderTestProperties(WEDNESDAY, "WED"), - DayHeaderTestProperties(THURSDAY, "THU"), - DayHeaderTestProperties(FRIDAY, "FRI"), - DayHeaderTestProperties(SATURDAY, "SAT"), - DayHeaderTestProperties(SUNDAY, "SUN") - ) - ), - of( - TUESDAY, - Theme.LIGHT, - Transparency(5), - TextSize(40), - listOf( - DayHeaderTestProperties(TUESDAY, "DOO"), - DayHeaderTestProperties(WEDNESDAY, "WED"), - DayHeaderTestProperties(THURSDAY, "THU"), - DayHeaderTestProperties(FRIDAY, "FRI"), - DayHeaderTestProperties(SATURDAY, "SAT"), - DayHeaderTestProperties(SUNDAY, "SUN"), - DayHeaderTestProperties(MONDAY, "MON") - ) - ), - of( - WEDNESDAY, - Theme.LIGHT, - Transparency(20), - TextSize(40), - listOf( - DayHeaderTestProperties(WEDNESDAY, "WED"), - DayHeaderTestProperties(THURSDAY, "THU"), - DayHeaderTestProperties(FRIDAY, "FRI"), - DayHeaderTestProperties(SATURDAY, "SAT"), - DayHeaderTestProperties(SUNDAY, "SUN"), - DayHeaderTestProperties(MONDAY, "MON"), - DayHeaderTestProperties(TUESDAY, "DOO") - ) - ), - of( - THURSDAY, - Theme.LIGHT, - Transparency(20), - TextSize(40), - listOf( - DayHeaderTestProperties(THURSDAY, "THU"), - DayHeaderTestProperties(FRIDAY, "FRI"), - DayHeaderTestProperties(SATURDAY, "SAT"), - DayHeaderTestProperties(SUNDAY, "SUN"), - DayHeaderTestProperties(MONDAY, "MON"), - DayHeaderTestProperties(TUESDAY, "DOO"), - DayHeaderTestProperties(WEDNESDAY, "WED") - ) - ), - of( - FRIDAY, - Theme.LIGHT, - Transparency(20), - TextSize(40), - listOf( - DayHeaderTestProperties(FRIDAY, "FRI"), - DayHeaderTestProperties(SATURDAY, "SAT"), - DayHeaderTestProperties(SUNDAY, "SUN"), - DayHeaderTestProperties(MONDAY, "MON"), - DayHeaderTestProperties(TUESDAY, "DOO"), - DayHeaderTestProperties(WEDNESDAY, "WED"), - DayHeaderTestProperties(THURSDAY, "THU") - ) - ), - of( - SATURDAY, - Theme.LIGHT, - Transparency(20), - TextSize(40), - listOf( - DayHeaderTestProperties(SATURDAY, "SAT"), - DayHeaderTestProperties(SUNDAY, "SUN"), - DayHeaderTestProperties(MONDAY, "MON"), - DayHeaderTestProperties(TUESDAY, "DOO"), - DayHeaderTestProperties(WEDNESDAY, "WED"), - DayHeaderTestProperties(THURSDAY, "THU"), - DayHeaderTestProperties(FRIDAY, "FRI") - ) - ), - of( - SUNDAY, - Theme.LIGHT, - Transparency(20), - TextSize(40), - listOf( - DayHeaderTestProperties(SUNDAY, "SUN"), - DayHeaderTestProperties(MONDAY, "MON"), - DayHeaderTestProperties(TUESDAY, "DOO"), - DayHeaderTestProperties(WEDNESDAY, "WED"), - DayHeaderTestProperties(THURSDAY, "THU"), - DayHeaderTestProperties(FRIDAY, "FRI"), - DayHeaderTestProperties(SATURDAY, "SAT") - ) - ), - of( - MONDAY, - Theme.LIGHT, - Transparency(20), - TextSize(15), - listOf( - DayHeaderTestProperties(MONDAY, "M"), - DayHeaderTestProperties(TUESDAY, "D"), - DayHeaderTestProperties(WEDNESDAY, "W"), - DayHeaderTestProperties(THURSDAY, "T"), - DayHeaderTestProperties(FRIDAY, "F"), - DayHeaderTestProperties(SATURDAY, "S"), - DayHeaderTestProperties(SUNDAY, "S") - ) - ), - of( - TUESDAY, - Theme.LIGHT, - Transparency(20), - TextSize(15), - listOf( - DayHeaderTestProperties(TUESDAY, "D"), - DayHeaderTestProperties(WEDNESDAY, "W"), - DayHeaderTestProperties(THURSDAY, "T"), - DayHeaderTestProperties(FRIDAY, "F"), - DayHeaderTestProperties(SATURDAY, "S"), - DayHeaderTestProperties(SUNDAY, "S"), - DayHeaderTestProperties(MONDAY, "M") - ) - ), - of( - WEDNESDAY, - Theme.LIGHT, - Transparency(15), - TextSize(15), - listOf( - DayHeaderTestProperties(WEDNESDAY, "W"), - DayHeaderTestProperties(THURSDAY, "T"), - DayHeaderTestProperties(FRIDAY, "F"), - DayHeaderTestProperties(SATURDAY, "S"), - DayHeaderTestProperties(SUNDAY, "S"), - DayHeaderTestProperties(MONDAY, "M"), - DayHeaderTestProperties(TUESDAY, "D") - ) - ), - of( - THURSDAY, - Theme.LIGHT, - Transparency(100), - TextSize(15), - listOf( - DayHeaderTestProperties(THURSDAY, "T"), - DayHeaderTestProperties(FRIDAY, "F"), - DayHeaderTestProperties(SATURDAY, "S"), - DayHeaderTestProperties(SUNDAY, "S"), - DayHeaderTestProperties(MONDAY, "M"), - DayHeaderTestProperties(TUESDAY, "D"), - DayHeaderTestProperties(WEDNESDAY, "W") - ) - ), - of( - FRIDAY, - Theme.LIGHT, - Transparency(0), - TextSize(15), - listOf( - DayHeaderTestProperties(FRIDAY, "F"), - DayHeaderTestProperties(SATURDAY, "S"), - DayHeaderTestProperties(SUNDAY, "S"), - DayHeaderTestProperties(MONDAY, "M"), - DayHeaderTestProperties(TUESDAY, "D"), - DayHeaderTestProperties(WEDNESDAY, "W"), - DayHeaderTestProperties(THURSDAY, "T") - ) - ), - of( - SATURDAY, - Theme.LIGHT, - Transparency(20), - TextSize(15), - listOf( - DayHeaderTestProperties(SATURDAY, "S"), - DayHeaderTestProperties(SUNDAY, "S"), - DayHeaderTestProperties(MONDAY, "M"), - DayHeaderTestProperties(TUESDAY, "D"), - DayHeaderTestProperties(WEDNESDAY, "W"), - DayHeaderTestProperties(THURSDAY, "T"), - DayHeaderTestProperties(FRIDAY, "F") - ) - ), - of( - SUNDAY, - Theme.LIGHT, - Transparency(20), - TextSize(15), - listOf( - DayHeaderTestProperties(SUNDAY, "S"), - DayHeaderTestProperties(MONDAY, "M"), - DayHeaderTestProperties(TUESDAY, "D"), - DayHeaderTestProperties(WEDNESDAY, "W"), - DayHeaderTestProperties(THURSDAY, "T"), - DayHeaderTestProperties(FRIDAY, "F"), - DayHeaderTestProperties(SATURDAY, "S") - ) - ) + @ParameterizedTest + @MethodSource("getFirstDayOfWeekAndTExpectedRotatedDaysOfWeek") + fun getRotatedDaysOfWeek_shouldReturnDaysOfWeekBasedOnFirstDayOfWeek( + firstDayOfWeek: DayOfWeek, + expectedRotatedDayOfWeek: List + ) { + assertThat(getRotatedDaysOfWeek(firstDayOfWeek)).isEqualTo(expectedRotatedDayOfWeek) + } + + private fun getFirstDayOfWeekAndThemeAndThemeAndTextSizeWithExpectedOutput() = listOf( + of(MONDAY, DARK, Transparency(10), TextSize(40), listOf("MON", "DOO", "WED", "THU", "FRI", "SAT", "SUN")), + of(TUESDAY, DARK, Transparency(20), TextSize(40), listOf("DOO", "WED", "THU", "FRI", "SAT", "SUN", "MON")), + of(WEDNESDAY, DARK, Transparency(20), TextSize(40), listOf("WED", "THU", "FRI", "SAT", "SUN", "MON", "DOO")), + of(THURSDAY, DARK, Transparency(30), TextSize(40), listOf("THU", "FRI", "SAT", "SUN", "MON", "DOO", "WED")), + of(FRIDAY, DARK, Transparency(90), TextSize(40), listOf("FRI", "SAT", "SUN", "MON", "DOO", "WED", "THU")), + of(SATURDAY, DARK, Transparency(15), TextSize(40), listOf("SAT", "SUN", "MON", "DOO", "WED", "THU", "FRI")), + of(SUNDAY, DARK, Transparency(20), TextSize(40), listOf("SUN", "MON", "DOO", "WED", "THU", "FRI", "SAT")), + of(MONDAY, DARK, Transparency(0), TextSize(15), listOf("M", "D", "W", "T", "F", "S", "S")), + of(TUESDAY, DARK, Transparency(55), TextSize(15), listOf("D", "W", "T", "F", "S", "S", "M")), + of(WEDNESDAY, DARK, Transparency(15), TextSize(15), listOf("W", "T", "F", "S", "S", "M", "D")), + of(THURSDAY, DARK, Transparency(20), TextSize(15), listOf("T", "F", "S", "S", "M", "D", "W")), + of(FRIDAY, DARK, Transparency(20), TextSize(15), listOf("F", "S", "S", "M", "D", "W", "T")), + of(SATURDAY, DARK, Transparency(20), TextSize(15), listOf("S", "S", "M", "D", "W", "T", "F")), + of(SUNDAY, DARK, Transparency(20), TextSize(15), listOf("S", "M", "D", "W", "T", "F", "S")), + of(MONDAY, LIGHT, Transparency(80), TextSize(40), listOf("MON", "DOO", "WED", "THU", "FRI", "SAT", "SUN")), + of(TUESDAY, LIGHT, Transparency(5), TextSize(40), listOf("DOO", "WED", "THU", "FRI", "SAT", "SUN", "MON")), + of(WEDNESDAY, LIGHT, Transparency(20), TextSize(40), listOf("WED", "THU", "FRI", "SAT", "SUN", "MON", "DOO")), + of(THURSDAY, LIGHT, Transparency(20), TextSize(40), listOf("THU", "FRI", "SAT", "SUN", "MON", "DOO", "WED")), + of(FRIDAY, LIGHT, Transparency(20), TextSize(40), listOf("FRI", "SAT", "SUN", "MON", "DOO", "WED", "THU")), + of(SATURDAY, LIGHT, Transparency(20), TextSize(40), listOf("SAT", "SUN", "MON", "DOO", "WED", "THU", "FRI")), + of(SUNDAY, LIGHT, Transparency(20), TextSize(40), listOf("SUN", "MON", "DOO", "WED", "THU", "FRI", "SAT")), + of(MONDAY, LIGHT, Transparency(20), TextSize(15), listOf("M", "D", "W", "T", "F", "S", "S")), + of(TUESDAY, LIGHT, Transparency(20), TextSize(15), listOf("D", "W", "T", "F", "S", "S", "M")), + of(WEDNESDAY, LIGHT, Transparency(15), TextSize(15), listOf("W", "T", "F", "S", "S", "M", "D")), + of(THURSDAY, LIGHT, Transparency(100), TextSize(15), listOf("T", "F", "S", "S", "M", "D", "W")), + of(FRIDAY, LIGHT, Transparency(0), TextSize(15), listOf("F", "S", "S", "M", "D", "W", "T")), + of(SATURDAY, LIGHT, Transparency(20), TextSize(15), listOf("S", "S", "M", "D", "W", "T", "F")), + of(SUNDAY, LIGHT, Transparency(20), TextSize(15), listOf("S", "M", "D", "W", "T", "F", "S")) ) - private fun DayOfWeek.getExpectedResourceIdAndTranslation() = - when (this) { - MONDAY -> Pair(R.string.monday_abb, "MONDAY") - TUESDAY -> Pair(R.string.tuesday_abb, "DOOMSDAY") - WEDNESDAY -> Pair(R.string.wednesday_abb, "WEDNESDAY") - THURSDAY -> Pair(R.string.thursday_abb, "THURSDAY") - FRIDAY -> Pair(R.string.friday_abb, "FRIDAY") - SATURDAY -> Pair(R.string.saturday_abb, "SATURDAY") - SUNDAY -> Pair(R.string.sunday_abb, "SUNDAY") - } + private fun getFirstDayOfWeekAndTExpectedRotatedDaysOfWeek() = listOf( + of(MONDAY, listOf(MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY)), + of(TUESDAY, listOf(TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY, MONDAY)), + of(WEDNESDAY, listOf(WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY, MONDAY, TUESDAY)), + of(THURSDAY, listOf(THURSDAY, FRIDAY, SATURDAY, SUNDAY, MONDAY, TUESDAY, WEDNESDAY)), + of(FRIDAY, listOf(FRIDAY, SATURDAY, SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY)), + of(SATURDAY, listOf(SATURDAY, SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY)), + of(SUNDAY, listOf(SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY)) + ) - internal data class DayHeaderTestProperties( - val dayOfWeek: DayOfWeek, - val expectedHeaderText: String - ) { - fun getCellHeader(theme: Theme) = theme.getCellHeader(dayOfWeek) + private fun DayOfWeek.getExpectedResourceIdAndTranslation() = when (this) { + MONDAY -> Pair(R.string.monday_abb, "MONDAY") + TUESDAY -> Pair(R.string.tuesday_abb, "DOOMSDAY") + WEDNESDAY -> Pair(R.string.wednesday_abb, "WEDNESDAY") + THURSDAY -> Pair(R.string.thursday_abb, "THURSDAY") + FRIDAY -> Pair(R.string.friday_abb, "FRIDAY") + SATURDAY -> Pair(R.string.saturday_abb, "SATURDAY") + SUNDAY -> Pair(R.string.sunday_abb, "SUNDAY") } } \ No newline at end of file diff --git a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/component/DaysServiceTest.kt b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/component/DaysServiceTest.kt index 6408f59b..f5449c56 100644 --- a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/component/DaysServiceTest.kt +++ b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/component/DaysServiceTest.kt @@ -3,6 +3,7 @@ package cat.mvmike.minimalcalendarwidget.domain.component import android.text.Layout +import android.text.Layout.Alignment.ALIGN_OPPOSITE import android.widget.RemoteViews import cat.mvmike.minimalcalendarwidget.BaseTest import cat.mvmike.minimalcalendarwidget.domain.Day @@ -28,7 +29,7 @@ import io.mockk.mockkObject import io.mockk.verify import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.Arguments.of +import org.junit.jupiter.params.provider.CsvSource import org.junit.jupiter.params.provider.MethodSource import java.time.DayOfWeek import java.time.DayOfWeek.FRIDAY @@ -184,7 +185,19 @@ internal class DaysServiceTest : BaseTest() { } @ParameterizedTest - @MethodSource("getSystemLocalDateAndFirstDayOfWeekWithExpectedCurrentWeekFocusedInitialLocalDate") + @CsvSource( + "2022-02-24,MONDAY,2022-02-14", + "2022-02-27,MONDAY,2022-02-14", + "2022-02-28,MONDAY,2022-02-21", + "2022-02-28,TUESDAY,2022-02-15", + "2022-03-01,TUESDAY,2022-02-22", + "2022-01-01,WEDNESDAY,2021-12-22", + "2022-01-01,SATURDAY,2021-12-25", + "2022-02-20,SUNDAY,2022-02-13", + "2022-02-25,SUNDAY,2022-02-13", + "2022-02-26,SUNDAY,2022-02-13", + "2022-02-27,SUNDAY,2022-02-20" + ) fun getFocusedOnCurrentWeekInitialLocalDate_shouldReturnWidgetInitialDate( systemLocalDate: LocalDate, firstDayOfWeek: DayOfWeek, @@ -196,7 +209,28 @@ internal class DaysServiceTest : BaseTest() { } @ParameterizedTest - @MethodSource("getSystemLocalDateAndFirstDayOfWeekWithExpectedNaturalMonthInitialLocalDate") + @CsvSource( + "2018-01-26,MONDAY,2018-01-01", + "2018-01-26,TUESDAY,2017-12-26", + "2018-01-26,WEDNESDAY,2017-12-27", + "2018-01-26,THURSDAY,2017-12-28", + "2018-01-26,FRIDAY,2017-12-29", + "2018-01-26,SATURDAY,2017-12-30", + "2018-01-26,SUNDAY,2017-12-31", + "2005-02-19,WEDNESDAY,2005-01-26", + "2027-03-05,SUNDAY,2027-02-28", + "2099-04-30,MONDAY,2099-03-30", + "2000-05-01,SATURDAY,2000-04-29", + "1998-06-02,WEDNESDAY,1998-05-27", + "1992-07-07,TUESDAY,1992-06-30", + "2018-08-01,FRIDAY,2018-07-27", + "1987-09-12,FRIDAY,1987-08-28", + "2017-10-01,THURSDAY,2017-09-28", + "1000-11-12,SATURDAY,1000-11-01", + "1994-12-13,THURSDAY,1994-12-01", + "2021-02-13,MONDAY,2021-02-01", + "2021-03-13,MONDAY,2021-03-01" + ) fun getNaturalMonthInitialLocalDate_shouldReturnWidgetInitialDate( systemLocalDate: LocalDate, firstDayOfWeek: DayOfWeek, @@ -208,15 +242,63 @@ internal class DaysServiceTest : BaseTest() { } @ParameterizedTest - @MethodSource("getLocalDateAndIncludeDeclinedEventsWithExpectedNumberOfInstances") + @CsvSource( + "2018-11-26,1,1", + "2018-11-27,0,0", + "2018-11-28,1,1", + "2018-11-29,1,1", + "2018-11-30,0,0", + "2018-12-01,0,0", + "2018-12-02,0,0", + "2018-12-03,1,1", + "2018-12-04,1,1", + "2018-12-05,0,0", + "2018-12-06,3,3", + "2018-12-07,1,1", + "2018-12-08,0,0", + "2018-12-09,0,0", + "2018-12-10,4,4", + "2018-12-11,1,1", + "2018-12-12,0,0", + "2018-12-13,0,0", + "2018-12-14,0,0", + "2018-12-15,0,0", + "2018-12-16,0,0", + "2018-12-17,0,0", + "2018-12-18,1,0", + "2018-12-19,0,0", + "2018-12-20,0,0", + "2018-12-21,0,0", + "2018-12-22,0,0", + "2018-12-23,0,0", + "2018-12-24,0,0", + "2018-12-25,0,0", + "2018-12-26,0,0", + "2018-12-27,1,1", + "2018-12-28,0,0", + "2018-12-29,0,0", + "2018-12-30,5,5", + "2018-12-31,0,0", + "2019-01-01,1,1", + "2019-01-02,2,2", + "2019-01-03,2,2", + "2019-01-04,2,2", + "2019-01-05,8,8", + "2019-01-06,2,2" + ) fun getNumberOfInstances_shouldReturnEventsInDayAndConsideringDeclinedEvents( localDate: LocalDate, - includeDeclinedEvents: Boolean, - expectedNumberOfInstances: Int + expectedNumberOfInstancesWithDeclinedEvents: Int, + expectedNumberOfInstancesWithoutDeclinedEvents: Int ) { - val result = getSystemInstances().getNumberOfInstances(Day(localDate), systemZoneId, includeDeclinedEvents) + val day = Day(localDate) + val systemInstances = getSystemInstances() - assertThat(result).isEqualTo(expectedNumberOfInstances) + val numberOfInstancesWithDeclinedEvents = systemInstances.getNumberOfInstances(day, systemZoneId, true) + val numberOfInstancesWithoutDeclinedEvents = systemInstances.getNumberOfInstances(day, systemZoneId, false) + + assertThat(numberOfInstancesWithDeclinedEvents).isEqualTo(expectedNumberOfInstancesWithDeclinedEvents) + assertThat(numberOfInstancesWithoutDeclinedEvents).isEqualTo(expectedNumberOfInstancesWithoutDeclinedEvents) } private fun getSystemInstances(): Set = setOf( @@ -395,56 +477,57 @@ internal class DaysServiceTest : BaseTest() { expectedInstancesQueryInitEpochMillis = 1543179600000, expectedInstancesQueryEndEpochMillis = 1546808400000, expectedDayProperties = listOf( - ExpectedDayProperties("26", '·', MONDAY, ofEpochSecond(1543179600)), - ExpectedDayProperties("27", ' ', TUESDAY, ofEpochSecond(1543266000)), - ExpectedDayProperties("28", '·', WEDNESDAY, ofEpochSecond(1543352400)), - ExpectedDayProperties("29", '·', THURSDAY, ofEpochSecond(1543438800)), - ExpectedDayProperties("30", ' ', FRIDAY, ofEpochSecond(1543525200)), - ExpectedDayProperties("1", ' ', SATURDAY, ofEpochSecond(1543611600), true), - ExpectedDayProperties("2", ' ', SUNDAY, ofEpochSecond(1543698000), true), - ExpectedDayProperties("3", '·', MONDAY, ofEpochSecond(1543784400), true), - ExpectedDayProperties( + DayProperties("26", '·', MONDAY, ofEpochSecond(1543179600), alignment = ALIGN_OPPOSITE), + DayProperties("27", ' ', TUESDAY, ofEpochSecond(1543266000), alignment = ALIGN_OPPOSITE), + DayProperties("28", '·', WEDNESDAY, ofEpochSecond(1543352400), alignment = ALIGN_OPPOSITE), + DayProperties("29", '·', THURSDAY, ofEpochSecond(1543438800), alignment = ALIGN_OPPOSITE), + DayProperties("30", ' ', FRIDAY, ofEpochSecond(1543525200), alignment = ALIGN_OPPOSITE), + DayProperties("1", ' ', SATURDAY, ofEpochSecond(1543611600), true, alignment = ALIGN_OPPOSITE), + DayProperties("2", ' ', SUNDAY, ofEpochSecond(1543698000), true, alignment = ALIGN_OPPOSITE), + DayProperties("3", '·', MONDAY, ofEpochSecond(1543784400), true, alignment = ALIGN_OPPOSITE), + DayProperties( dayOfMonth = "4", instancesSymbol = '·', dayOfWeek = TUESDAY, startOfDay = ofEpochSecond(1543870800), isInMonth = true, isToday = true, - highlightDrawable = 2131165277 + highlightDrawable = 2131165277, + alignment = ALIGN_OPPOSITE ), - ExpectedDayProperties("5", ' ', WEDNESDAY, ofEpochSecond(1543957200), true), - ExpectedDayProperties("6", '∴', THURSDAY, ofEpochSecond(1544043600), true), - ExpectedDayProperties("7", '·', FRIDAY, ofEpochSecond(1544130000), true), - ExpectedDayProperties("8", ' ', SATURDAY, ofEpochSecond(1544216400), true), - ExpectedDayProperties("9", ' ', SUNDAY, ofEpochSecond(1544302800), true), - ExpectedDayProperties("10", '∷', MONDAY, ofEpochSecond(1544389200), true), - ExpectedDayProperties("11", '·', TUESDAY, ofEpochSecond(1544475600), true), - ExpectedDayProperties("12", ' ', WEDNESDAY, ofEpochSecond(1544562000), true), - ExpectedDayProperties("13", ' ', THURSDAY, ofEpochSecond(1544648400), true), - ExpectedDayProperties("14", ' ', FRIDAY, ofEpochSecond(1544734800), true), - ExpectedDayProperties("15", ' ', SATURDAY, ofEpochSecond(1544821200), true), - ExpectedDayProperties("16", ' ', SUNDAY, ofEpochSecond(1544907600), true), - ExpectedDayProperties("17", ' ', MONDAY, ofEpochSecond(1544994000), true), - ExpectedDayProperties("18", ' ', TUESDAY, ofEpochSecond(1545080400), true), - ExpectedDayProperties("19", ' ', WEDNESDAY, ofEpochSecond(1545166800), true), - ExpectedDayProperties("20", ' ', THURSDAY, ofEpochSecond(1545253200), true), - ExpectedDayProperties("21", ' ', FRIDAY, ofEpochSecond(1545339600), true), - ExpectedDayProperties("22", ' ', SATURDAY, ofEpochSecond(1545426000), true), - ExpectedDayProperties("23", ' ', SUNDAY, ofEpochSecond(1545512400), true), - ExpectedDayProperties("24", ' ', MONDAY, ofEpochSecond(1545598800), true), - ExpectedDayProperties("25", ' ', TUESDAY, ofEpochSecond(1545685200), true), - ExpectedDayProperties("26", ' ', WEDNESDAY, ofEpochSecond(1545771600), true), - ExpectedDayProperties("27", '·', THURSDAY, ofEpochSecond(1545858000), true), - ExpectedDayProperties("28", ' ', FRIDAY, ofEpochSecond(1545944400), true), - ExpectedDayProperties("29", ' ', SATURDAY, ofEpochSecond(1546030800), true), - ExpectedDayProperties("30", '◇', SUNDAY, ofEpochSecond(1546117200), true), - ExpectedDayProperties("31", ' ', MONDAY, ofEpochSecond(1546203600), true), - ExpectedDayProperties("1", '·', TUESDAY, ofEpochSecond(1546290000)), - ExpectedDayProperties("2", '∶', WEDNESDAY, ofEpochSecond(1546376400)), - ExpectedDayProperties("3", '∶', THURSDAY, ofEpochSecond(1546462800)), - ExpectedDayProperties("4", '∶', FRIDAY, ofEpochSecond(1546549200)), - ExpectedDayProperties("5", '◈', SATURDAY, ofEpochSecond(1546635600)), - ExpectedDayProperties("6", '∶', SUNDAY, ofEpochSecond(1546722000)) + DayProperties("5", ' ', WEDNESDAY, ofEpochSecond(1543957200), true, alignment = ALIGN_OPPOSITE), + DayProperties("6", '∴', THURSDAY, ofEpochSecond(1544043600), true, alignment = ALIGN_OPPOSITE), + DayProperties("7", '·', FRIDAY, ofEpochSecond(1544130000), true, alignment = ALIGN_OPPOSITE), + DayProperties("8", ' ', SATURDAY, ofEpochSecond(1544216400), true, alignment = ALIGN_OPPOSITE), + DayProperties("9", ' ', SUNDAY, ofEpochSecond(1544302800), true, alignment = ALIGN_OPPOSITE), + DayProperties("10", '∷', MONDAY, ofEpochSecond(1544389200), true, alignment = ALIGN_OPPOSITE), + DayProperties("11", '·', TUESDAY, ofEpochSecond(1544475600), true, alignment = ALIGN_OPPOSITE), + DayProperties("12", ' ', WEDNESDAY, ofEpochSecond(1544562000), true, alignment = ALIGN_OPPOSITE), + DayProperties("13", ' ', THURSDAY, ofEpochSecond(1544648400), true, alignment = ALIGN_OPPOSITE), + DayProperties("14", ' ', FRIDAY, ofEpochSecond(1544734800), true, alignment = ALIGN_OPPOSITE), + DayProperties("15", ' ', SATURDAY, ofEpochSecond(1544821200), true, alignment = ALIGN_OPPOSITE), + DayProperties("16", ' ', SUNDAY, ofEpochSecond(1544907600), true, alignment = ALIGN_OPPOSITE), + DayProperties("17", ' ', MONDAY, ofEpochSecond(1544994000), true, alignment = ALIGN_OPPOSITE), + DayProperties("18", ' ', TUESDAY, ofEpochSecond(1545080400), true, alignment = ALIGN_OPPOSITE), + DayProperties("19", ' ', WEDNESDAY, ofEpochSecond(1545166800), true, alignment = ALIGN_OPPOSITE), + DayProperties("20", ' ', THURSDAY, ofEpochSecond(1545253200), true, alignment = ALIGN_OPPOSITE), + DayProperties("21", ' ', FRIDAY, ofEpochSecond(1545339600), true, alignment = ALIGN_OPPOSITE), + DayProperties("22", ' ', SATURDAY, ofEpochSecond(1545426000), true, alignment = ALIGN_OPPOSITE), + DayProperties("23", ' ', SUNDAY, ofEpochSecond(1545512400), true, alignment = ALIGN_OPPOSITE), + DayProperties("24", ' ', MONDAY, ofEpochSecond(1545598800), true, alignment = ALIGN_OPPOSITE), + DayProperties("25", ' ', TUESDAY, ofEpochSecond(1545685200), true, alignment = ALIGN_OPPOSITE), + DayProperties("26", ' ', WEDNESDAY, ofEpochSecond(1545771600), true, alignment = ALIGN_OPPOSITE), + DayProperties("27", '·', THURSDAY, ofEpochSecond(1545858000), true, alignment = ALIGN_OPPOSITE), + DayProperties("28", ' ', FRIDAY, ofEpochSecond(1545944400), true, alignment = ALIGN_OPPOSITE), + DayProperties("29", ' ', SATURDAY, ofEpochSecond(1546030800), true, alignment = ALIGN_OPPOSITE), + DayProperties("30", '◇', SUNDAY, ofEpochSecond(1546117200), true, alignment = ALIGN_OPPOSITE), + DayProperties("31", ' ', MONDAY, ofEpochSecond(1546203600), true, alignment = ALIGN_OPPOSITE), + DayProperties("1", '·', TUESDAY, ofEpochSecond(1546290000), alignment = ALIGN_OPPOSITE), + DayProperties("2", '∶', WEDNESDAY, ofEpochSecond(1546376400), alignment = ALIGN_OPPOSITE), + DayProperties("3", '∶', THURSDAY, ofEpochSecond(1546462800), alignment = ALIGN_OPPOSITE), + DayProperties("4", '∶', FRIDAY, ofEpochSecond(1546549200), alignment = ALIGN_OPPOSITE), + DayProperties("5", '◈', SATURDAY, ofEpochSecond(1546635600), alignment = ALIGN_OPPOSITE), + DayProperties("6", '∶', SUNDAY, ofEpochSecond(1546722000), alignment = ALIGN_OPPOSITE) ) ), DrawDaysUseCaseTestProperties( @@ -463,56 +546,57 @@ internal class DaysServiceTest : BaseTest() { expectedInstancesQueryInitEpochMillis = 1543093200000, expectedInstancesQueryEndEpochMillis = 1546722000000, expectedDayProperties = listOf( - ExpectedDayProperties("25", ' ', SUNDAY, ofEpochSecond(1543093200)), - ExpectedDayProperties("26", '☱', MONDAY, ofEpochSecond(1543179600)), - ExpectedDayProperties("27", ' ', TUESDAY, ofEpochSecond(1543266000)), - ExpectedDayProperties("28", '☱', WEDNESDAY, ofEpochSecond(1543352400)), - ExpectedDayProperties("29", '☱', THURSDAY, ofEpochSecond(1543438800)), - ExpectedDayProperties("30", ' ', FRIDAY, ofEpochSecond(1543525200)), - ExpectedDayProperties("1", ' ', SATURDAY, ofEpochSecond(1543611600), true), - ExpectedDayProperties("2", ' ', SUNDAY, ofEpochSecond(1543698000), true), - ExpectedDayProperties("3", '☱', MONDAY, ofEpochSecond(1543784400), true), - ExpectedDayProperties( + DayProperties("25", ' ', SUNDAY, ofEpochSecond(1543093200), alignment = ALIGN_OPPOSITE), + DayProperties("26", '☱', MONDAY, ofEpochSecond(1543179600), alignment = ALIGN_OPPOSITE), + DayProperties("27", ' ', TUESDAY, ofEpochSecond(1543266000), alignment = ALIGN_OPPOSITE), + DayProperties("28", '☱', WEDNESDAY, ofEpochSecond(1543352400), alignment = ALIGN_OPPOSITE), + DayProperties("29", '☱', THURSDAY, ofEpochSecond(1543438800), alignment = ALIGN_OPPOSITE), + DayProperties("30", ' ', FRIDAY, ofEpochSecond(1543525200), alignment = ALIGN_OPPOSITE), + DayProperties("1", ' ', SATURDAY, ofEpochSecond(1543611600), true, alignment = ALIGN_OPPOSITE), + DayProperties("2", ' ', SUNDAY, ofEpochSecond(1543698000), true, alignment = ALIGN_OPPOSITE), + DayProperties("3", '☱', MONDAY, ofEpochSecond(1543784400), true, alignment = ALIGN_OPPOSITE), + DayProperties( dayOfMonth = "4", instancesSymbol = '☱', dayOfWeek = TUESDAY, startOfDay = ofEpochSecond(1543870800), isInMonth = true, isToday = true, - highlightDrawable = 2131165278 + highlightDrawable = 2131165278, + alignment = ALIGN_OPPOSITE ), - ExpectedDayProperties("5", ' ', WEDNESDAY, ofEpochSecond(1543957200), true), - ExpectedDayProperties("6", '☳', THURSDAY, ofEpochSecond(1544043600), true), - ExpectedDayProperties("7", '☱', FRIDAY, ofEpochSecond(1544130000), true), - ExpectedDayProperties("8", ' ', SATURDAY, ofEpochSecond(1544216400), true), - ExpectedDayProperties("9", ' ', SUNDAY, ofEpochSecond(1544302800), true), - ExpectedDayProperties("10", '☴', MONDAY, ofEpochSecond(1544389200), true), - ExpectedDayProperties("11", '☱', TUESDAY, ofEpochSecond(1544475600), true), - ExpectedDayProperties("12", ' ', WEDNESDAY, ofEpochSecond(1544562000), true), - ExpectedDayProperties("13", ' ', THURSDAY, ofEpochSecond(1544648400), true), - ExpectedDayProperties("14", ' ', FRIDAY, ofEpochSecond(1544734800), true), - ExpectedDayProperties("15", ' ', SATURDAY, ofEpochSecond(1544821200), true), - ExpectedDayProperties("16", ' ', SUNDAY, ofEpochSecond(1544907600), true), - ExpectedDayProperties("17", ' ', MONDAY, ofEpochSecond(1544994000), true), - ExpectedDayProperties("18", ' ', TUESDAY, ofEpochSecond(1545080400), true), - ExpectedDayProperties("19", ' ', WEDNESDAY, ofEpochSecond(1545166800), true), - ExpectedDayProperties("20", ' ', THURSDAY, ofEpochSecond(1545253200), true), - ExpectedDayProperties("21", ' ', FRIDAY, ofEpochSecond(1545339600), true), - ExpectedDayProperties("22", ' ', SATURDAY, ofEpochSecond(1545426000), true), - ExpectedDayProperties("23", ' ', SUNDAY, ofEpochSecond(1545512400), true), - ExpectedDayProperties("24", ' ', MONDAY, ofEpochSecond(1545598800), true), - ExpectedDayProperties("25", ' ', TUESDAY, ofEpochSecond(1545685200), true), - ExpectedDayProperties("26", ' ', WEDNESDAY, ofEpochSecond(1545771600), true), - ExpectedDayProperties("27", '☱', THURSDAY, ofEpochSecond(1545858000), true), - ExpectedDayProperties("28", ' ', FRIDAY, ofEpochSecond(1545944400), true), - ExpectedDayProperties("29", ' ', SATURDAY, ofEpochSecond(1546030800), true), - ExpectedDayProperties("30", '☵', SUNDAY, ofEpochSecond(1546117200), true), - ExpectedDayProperties("31", ' ', MONDAY, ofEpochSecond(1546203600), true), - ExpectedDayProperties("1", '☱', TUESDAY, ofEpochSecond(1546290000)), - ExpectedDayProperties("2", '☲', WEDNESDAY, ofEpochSecond(1546376400)), - ExpectedDayProperties("3", '☲', THURSDAY, ofEpochSecond(1546462800)), - ExpectedDayProperties("4", '☲', FRIDAY, ofEpochSecond(1546549200)), - ExpectedDayProperties("5", '※', SATURDAY, ofEpochSecond(1546635600)) + DayProperties("5", ' ', WEDNESDAY, ofEpochSecond(1543957200), true, alignment = ALIGN_OPPOSITE), + DayProperties("6", '☳', THURSDAY, ofEpochSecond(1544043600), true, alignment = ALIGN_OPPOSITE), + DayProperties("7", '☱', FRIDAY, ofEpochSecond(1544130000), true, alignment = ALIGN_OPPOSITE), + DayProperties("8", ' ', SATURDAY, ofEpochSecond(1544216400), true, alignment = ALIGN_OPPOSITE), + DayProperties("9", ' ', SUNDAY, ofEpochSecond(1544302800), true, alignment = ALIGN_OPPOSITE), + DayProperties("10", '☴', MONDAY, ofEpochSecond(1544389200), true, alignment = ALIGN_OPPOSITE), + DayProperties("11", '☱', TUESDAY, ofEpochSecond(1544475600), true, alignment = ALIGN_OPPOSITE), + DayProperties("12", ' ', WEDNESDAY, ofEpochSecond(1544562000), true, alignment = ALIGN_OPPOSITE), + DayProperties("13", ' ', THURSDAY, ofEpochSecond(1544648400), true, alignment = ALIGN_OPPOSITE), + DayProperties("14", ' ', FRIDAY, ofEpochSecond(1544734800), true, alignment = ALIGN_OPPOSITE), + DayProperties("15", ' ', SATURDAY, ofEpochSecond(1544821200), true, alignment = ALIGN_OPPOSITE), + DayProperties("16", ' ', SUNDAY, ofEpochSecond(1544907600), true, alignment = ALIGN_OPPOSITE), + DayProperties("17", ' ', MONDAY, ofEpochSecond(1544994000), true, alignment = ALIGN_OPPOSITE), + DayProperties("18", ' ', TUESDAY, ofEpochSecond(1545080400), true, alignment = ALIGN_OPPOSITE), + DayProperties("19", ' ', WEDNESDAY, ofEpochSecond(1545166800), true, alignment = ALIGN_OPPOSITE), + DayProperties("20", ' ', THURSDAY, ofEpochSecond(1545253200), true, alignment = ALIGN_OPPOSITE), + DayProperties("21", ' ', FRIDAY, ofEpochSecond(1545339600), true, alignment = ALIGN_OPPOSITE), + DayProperties("22", ' ', SATURDAY, ofEpochSecond(1545426000), true, alignment = ALIGN_OPPOSITE), + DayProperties("23", ' ', SUNDAY, ofEpochSecond(1545512400), true, alignment = ALIGN_OPPOSITE), + DayProperties("24", ' ', MONDAY, ofEpochSecond(1545598800), true, alignment = ALIGN_OPPOSITE), + DayProperties("25", ' ', TUESDAY, ofEpochSecond(1545685200), true, alignment = ALIGN_OPPOSITE), + DayProperties("26", ' ', WEDNESDAY, ofEpochSecond(1545771600), true, alignment = ALIGN_OPPOSITE), + DayProperties("27", '☱', THURSDAY, ofEpochSecond(1545858000), true, alignment = ALIGN_OPPOSITE), + DayProperties("28", ' ', FRIDAY, ofEpochSecond(1545944400), true, alignment = ALIGN_OPPOSITE), + DayProperties("29", ' ', SATURDAY, ofEpochSecond(1546030800), true, alignment = ALIGN_OPPOSITE), + DayProperties("30", '☵', SUNDAY, ofEpochSecond(1546117200), true, alignment = ALIGN_OPPOSITE), + DayProperties("31", ' ', MONDAY, ofEpochSecond(1546203600), true, alignment = ALIGN_OPPOSITE), + DayProperties("1", '☱', TUESDAY, ofEpochSecond(1546290000), alignment = ALIGN_OPPOSITE), + DayProperties("2", '☲', WEDNESDAY, ofEpochSecond(1546376400), alignment = ALIGN_OPPOSITE), + DayProperties("3", '☲', THURSDAY, ofEpochSecond(1546462800), alignment = ALIGN_OPPOSITE), + DayProperties("4", '☲', FRIDAY, ofEpochSecond(1546549200), alignment = ALIGN_OPPOSITE), + DayProperties("5", '※', SATURDAY, ofEpochSecond(1546635600), alignment = ALIGN_OPPOSITE) ) ), DrawDaysUseCaseTestProperties( @@ -531,19 +615,19 @@ internal class DaysServiceTest : BaseTest() { expectedInstancesQueryInitEpochMillis = 1542834000000, expectedInstancesQueryEndEpochMillis = 1546462800000, expectedDayProperties = listOf( - ExpectedDayProperties("22", ' ', THURSDAY, ofEpochSecond(1542834000), alignment = null), - ExpectedDayProperties("23", ' ', FRIDAY, ofEpochSecond(1542920400), alignment = null), - ExpectedDayProperties("24", ' ', SATURDAY, ofEpochSecond(1543006800), alignment = null), - ExpectedDayProperties("25", ' ', SUNDAY, ofEpochSecond(1543093200), alignment = null), - ExpectedDayProperties("26", ' ', MONDAY, ofEpochSecond(1543179600), alignment = null), - ExpectedDayProperties("27", ' ', TUESDAY, ofEpochSecond(1543266000), alignment = null), - ExpectedDayProperties("28", ' ', WEDNESDAY, ofEpochSecond(1543352400), alignment = null), - ExpectedDayProperties("29", ' ', THURSDAY, ofEpochSecond(1543438800), alignment = null), - ExpectedDayProperties("30", ' ', FRIDAY, ofEpochSecond(1543525200), alignment = null), - ExpectedDayProperties("1", ' ', SATURDAY, ofEpochSecond(1543611600), true, alignment = null), - ExpectedDayProperties("2", ' ', SUNDAY, ofEpochSecond(1543698000), true, alignment = null), - ExpectedDayProperties("3", ' ', MONDAY, ofEpochSecond(1543784400), true, alignment = null), - ExpectedDayProperties( + DayProperties("22", ' ', THURSDAY, ofEpochSecond(1542834000), alignment = null), + DayProperties("23", ' ', FRIDAY, ofEpochSecond(1542920400), alignment = null), + DayProperties("24", ' ', SATURDAY, ofEpochSecond(1543006800), alignment = null), + DayProperties("25", ' ', SUNDAY, ofEpochSecond(1543093200), alignment = null), + DayProperties("26", ' ', MONDAY, ofEpochSecond(1543179600), alignment = null), + DayProperties("27", ' ', TUESDAY, ofEpochSecond(1543266000), alignment = null), + DayProperties("28", ' ', WEDNESDAY, ofEpochSecond(1543352400), alignment = null), + DayProperties("29", ' ', THURSDAY, ofEpochSecond(1543438800), alignment = null), + DayProperties("30", ' ', FRIDAY, ofEpochSecond(1543525200), alignment = null), + DayProperties("1", ' ', SATURDAY, ofEpochSecond(1543611600), true, alignment = null), + DayProperties("2", ' ', SUNDAY, ofEpochSecond(1543698000), true, alignment = null), + DayProperties("3", ' ', MONDAY, ofEpochSecond(1543784400), true, alignment = null), + DayProperties( dayOfMonth = "4", instancesSymbol = ' ', dayOfWeek = TUESDAY, @@ -553,35 +637,35 @@ internal class DaysServiceTest : BaseTest() { highlightDrawable = 2131165273, alignment = null ), - ExpectedDayProperties("5", ' ', WEDNESDAY, ofEpochSecond(1543957200), true, alignment = null), - ExpectedDayProperties("6", ' ', THURSDAY, ofEpochSecond(1544043600), true, alignment = null), - ExpectedDayProperties("7", ' ', FRIDAY, ofEpochSecond(1544130000), true, alignment = null), - ExpectedDayProperties("8", ' ', SATURDAY, ofEpochSecond(1544216400), true, alignment = null), - ExpectedDayProperties("9", ' ', SUNDAY, ofEpochSecond(1544302800), true, alignment = null), - ExpectedDayProperties("10", ' ', MONDAY, ofEpochSecond(1544389200), true, alignment = null), - ExpectedDayProperties("11", ' ', TUESDAY, ofEpochSecond(1544475600), true, alignment = null), - ExpectedDayProperties("12", ' ', WEDNESDAY, ofEpochSecond(1544562000), true, alignment = null), - ExpectedDayProperties("13", ' ', THURSDAY, ofEpochSecond(1544648400), true, alignment = null), - ExpectedDayProperties("14", ' ', FRIDAY, ofEpochSecond(1544734800), true, alignment = null), - ExpectedDayProperties("15", ' ', SATURDAY, ofEpochSecond(1544821200), true, alignment = null), - ExpectedDayProperties("16", ' ', SUNDAY, ofEpochSecond(1544907600), true, alignment = null), - ExpectedDayProperties("17", ' ', MONDAY, ofEpochSecond(1544994000), true, alignment = null), - ExpectedDayProperties("18", ' ', TUESDAY, ofEpochSecond(1545080400), true, alignment = null), - ExpectedDayProperties("19", ' ', WEDNESDAY, ofEpochSecond(1545166800), true, alignment = null), - ExpectedDayProperties("20", ' ', THURSDAY, ofEpochSecond(1545253200), true, alignment = null), - ExpectedDayProperties("21", ' ', FRIDAY, ofEpochSecond(1545339600), true, alignment = null), - ExpectedDayProperties("22", ' ', SATURDAY, ofEpochSecond(1545426000), true, alignment = null), - ExpectedDayProperties("23", ' ', SUNDAY, ofEpochSecond(1545512400), true, alignment = null), - ExpectedDayProperties("24", ' ', MONDAY, ofEpochSecond(1545598800), true, alignment = null), - ExpectedDayProperties("25", ' ', TUESDAY, ofEpochSecond(1545685200), true, alignment = null), - ExpectedDayProperties("26", ' ', WEDNESDAY, ofEpochSecond(1545771600), true, alignment = null), - ExpectedDayProperties("27", ' ', THURSDAY, ofEpochSecond(1545858000), true, alignment = null), - ExpectedDayProperties("28", ' ', FRIDAY, ofEpochSecond(1545944400), true, alignment = null), - ExpectedDayProperties("29", ' ', SATURDAY, ofEpochSecond(1546030800), true, alignment = null), - ExpectedDayProperties("30", ' ', SUNDAY, ofEpochSecond(1546117200), true, alignment = null), - ExpectedDayProperties("31", ' ', MONDAY, ofEpochSecond(1546203600), true, alignment = null), - ExpectedDayProperties("1", ' ', TUESDAY, ofEpochSecond(1546290000), alignment = null), - ExpectedDayProperties("2", ' ', WEDNESDAY, ofEpochSecond(1546376400), alignment = null) + DayProperties("5", ' ', WEDNESDAY, ofEpochSecond(1543957200), true, alignment = null), + DayProperties("6", ' ', THURSDAY, ofEpochSecond(1544043600), true, alignment = null), + DayProperties("7", ' ', FRIDAY, ofEpochSecond(1544130000), true, alignment = null), + DayProperties("8", ' ', SATURDAY, ofEpochSecond(1544216400), true, alignment = null), + DayProperties("9", ' ', SUNDAY, ofEpochSecond(1544302800), true, alignment = null), + DayProperties("10", ' ', MONDAY, ofEpochSecond(1544389200), true, alignment = null), + DayProperties("11", ' ', TUESDAY, ofEpochSecond(1544475600), true, alignment = null), + DayProperties("12", ' ', WEDNESDAY, ofEpochSecond(1544562000), true, alignment = null), + DayProperties("13", ' ', THURSDAY, ofEpochSecond(1544648400), true, alignment = null), + DayProperties("14", ' ', FRIDAY, ofEpochSecond(1544734800), true, alignment = null), + DayProperties("15", ' ', SATURDAY, ofEpochSecond(1544821200), true, alignment = null), + DayProperties("16", ' ', SUNDAY, ofEpochSecond(1544907600), true, alignment = null), + DayProperties("17", ' ', MONDAY, ofEpochSecond(1544994000), true, alignment = null), + DayProperties("18", ' ', TUESDAY, ofEpochSecond(1545080400), true, alignment = null), + DayProperties("19", ' ', WEDNESDAY, ofEpochSecond(1545166800), true, alignment = null), + DayProperties("20", ' ', THURSDAY, ofEpochSecond(1545253200), true, alignment = null), + DayProperties("21", ' ', FRIDAY, ofEpochSecond(1545339600), true, alignment = null), + DayProperties("22", ' ', SATURDAY, ofEpochSecond(1545426000), true, alignment = null), + DayProperties("23", ' ', SUNDAY, ofEpochSecond(1545512400), true, alignment = null), + DayProperties("24", ' ', MONDAY, ofEpochSecond(1545598800), true, alignment = null), + DayProperties("25", ' ', TUESDAY, ofEpochSecond(1545685200), true, alignment = null), + DayProperties("26", ' ', WEDNESDAY, ofEpochSecond(1545771600), true, alignment = null), + DayProperties("27", ' ', THURSDAY, ofEpochSecond(1545858000), true, alignment = null), + DayProperties("28", ' ', FRIDAY, ofEpochSecond(1545944400), true, alignment = null), + DayProperties("29", ' ', SATURDAY, ofEpochSecond(1546030800), true, alignment = null), + DayProperties("30", ' ', SUNDAY, ofEpochSecond(1546117200), true, alignment = null), + DayProperties("31", ' ', MONDAY, ofEpochSecond(1546203600), true, alignment = null), + DayProperties("1", ' ', TUESDAY, ofEpochSecond(1546290000), alignment = null), + DayProperties("2", ' ', WEDNESDAY, ofEpochSecond(1546376400), alignment = null) ) ), DrawDaysUseCaseTestProperties( @@ -600,16 +684,16 @@ internal class DaysServiceTest : BaseTest() { expectedInstancesQueryInitEpochMillis = 1574629200000, expectedInstancesQueryEndEpochMillis = 1578258000000, expectedDayProperties = listOf( - ExpectedDayProperties("25", ' ', MONDAY, ofEpochSecond(1574629200), alignment = null), - ExpectedDayProperties("26", ' ', TUESDAY, ofEpochSecond(1574715600), alignment = null), - ExpectedDayProperties("27", ' ', WEDNESDAY, ofEpochSecond(1574802000), alignment = null), - ExpectedDayProperties("28", ' ', THURSDAY, ofEpochSecond(1574888400), alignment = null), - ExpectedDayProperties("29", ' ', FRIDAY, ofEpochSecond(1574974800), alignment = null), - ExpectedDayProperties("30", ' ', SATURDAY, ofEpochSecond(1575061200), alignment = null), - ExpectedDayProperties("1", ' ', SUNDAY, ofEpochSecond(1575147600), true, alignment = null), - ExpectedDayProperties("2", ' ', MONDAY, ofEpochSecond(1575234000), true, alignment = null), - ExpectedDayProperties("3", ' ', TUESDAY, ofEpochSecond(1575320400), true, alignment = null), - ExpectedDayProperties( + DayProperties("25", ' ', MONDAY, ofEpochSecond(1574629200), alignment = null), + DayProperties("26", ' ', TUESDAY, ofEpochSecond(1574715600), alignment = null), + DayProperties("27", ' ', WEDNESDAY, ofEpochSecond(1574802000), alignment = null), + DayProperties("28", ' ', THURSDAY, ofEpochSecond(1574888400), alignment = null), + DayProperties("29", ' ', FRIDAY, ofEpochSecond(1574974800), alignment = null), + DayProperties("30", ' ', SATURDAY, ofEpochSecond(1575061200), alignment = null), + DayProperties("1", ' ', SUNDAY, ofEpochSecond(1575147600), true, alignment = null), + DayProperties("2", ' ', MONDAY, ofEpochSecond(1575234000), true, alignment = null), + DayProperties("3", ' ', TUESDAY, ofEpochSecond(1575320400), true, alignment = null), + DayProperties( dayOfMonth = "4", instancesSymbol = ' ', dayOfWeek = WEDNESDAY, @@ -619,166 +703,42 @@ internal class DaysServiceTest : BaseTest() { highlightDrawable = 2131165273, alignment = null ), - ExpectedDayProperties("5", ' ', THURSDAY, ofEpochSecond(1575493200), true, alignment = null), - ExpectedDayProperties("6", ' ', FRIDAY, ofEpochSecond(1575579600), true, alignment = null), - ExpectedDayProperties("7", ' ', SATURDAY, ofEpochSecond(1575666000), true, alignment = null), - ExpectedDayProperties("8", ' ', SUNDAY, ofEpochSecond(1575752400), true, alignment = null), - ExpectedDayProperties("9", ' ', MONDAY, ofEpochSecond(1575838800), true, alignment = null), - ExpectedDayProperties("10", ' ', TUESDAY, ofEpochSecond(1575925200), true, alignment = null), - ExpectedDayProperties("11", ' ', WEDNESDAY, ofEpochSecond(1576011600), true, alignment = null), - ExpectedDayProperties("12", ' ', THURSDAY, ofEpochSecond(1576098000), true, alignment = null), - ExpectedDayProperties("13", ' ', FRIDAY, ofEpochSecond(1576184400), true, alignment = null), - ExpectedDayProperties("14", ' ', SATURDAY, ofEpochSecond(1576270800), true, alignment = null), - ExpectedDayProperties("15", ' ', SUNDAY, ofEpochSecond(1576357200), true, alignment = null), - ExpectedDayProperties("16", ' ', MONDAY, ofEpochSecond(1576443600), true, alignment = null), - ExpectedDayProperties("17", ' ', TUESDAY, ofEpochSecond(1576530000), true, alignment = null), - ExpectedDayProperties("18", ' ', WEDNESDAY, ofEpochSecond(1576616400), true, alignment = null), - ExpectedDayProperties("19", ' ', THURSDAY, ofEpochSecond(1576702800), true, alignment = null), - ExpectedDayProperties("20", ' ', FRIDAY, ofEpochSecond(1576789200), true, alignment = null), - ExpectedDayProperties("21", ' ', SATURDAY, ofEpochSecond(1576875600), true, alignment = null), - ExpectedDayProperties("22", ' ', SUNDAY, ofEpochSecond(1576962000), true, alignment = null), - ExpectedDayProperties("23", ' ', MONDAY, ofEpochSecond(1577048400), true, alignment = null), - ExpectedDayProperties("24", ' ', TUESDAY, ofEpochSecond(1577134800), true, alignment = null), - ExpectedDayProperties("25", ' ', WEDNESDAY, ofEpochSecond(1577221200), true, alignment = null), - ExpectedDayProperties("26", ' ', THURSDAY, ofEpochSecond(1577307600), true, alignment = null), - ExpectedDayProperties("27", ' ', FRIDAY, ofEpochSecond(1577394000), true, alignment = null), - ExpectedDayProperties("28", ' ', SATURDAY, ofEpochSecond(1577480400), true, alignment = null), - ExpectedDayProperties("29", ' ', SUNDAY, ofEpochSecond(1577566800), true, alignment = null), - ExpectedDayProperties("30", ' ', MONDAY, ofEpochSecond(1577653200), true, alignment = null), - ExpectedDayProperties("31", ' ', TUESDAY, ofEpochSecond(1577739600), true, alignment = null), - ExpectedDayProperties("1", ' ', WEDNESDAY, ofEpochSecond(1577826000), alignment = null), - ExpectedDayProperties("2", ' ', THURSDAY, ofEpochSecond(1577912400), alignment = null), - ExpectedDayProperties("3", ' ', FRIDAY, ofEpochSecond(1577998800), alignment = null), - ExpectedDayProperties("4", ' ', SATURDAY, ofEpochSecond(1578085200), alignment = null), - ExpectedDayProperties("5", ' ', SUNDAY, ofEpochSecond(1578171600), alignment = null) + DayProperties("5", ' ', THURSDAY, ofEpochSecond(1575493200), true, alignment = null), + DayProperties("6", ' ', FRIDAY, ofEpochSecond(1575579600), true, alignment = null), + DayProperties("7", ' ', SATURDAY, ofEpochSecond(1575666000), true, alignment = null), + DayProperties("8", ' ', SUNDAY, ofEpochSecond(1575752400), true, alignment = null), + DayProperties("9", ' ', MONDAY, ofEpochSecond(1575838800), true, alignment = null), + DayProperties("10", ' ', TUESDAY, ofEpochSecond(1575925200), true, alignment = null), + DayProperties("11", ' ', WEDNESDAY, ofEpochSecond(1576011600), true, alignment = null), + DayProperties("12", ' ', THURSDAY, ofEpochSecond(1576098000), true, alignment = null), + DayProperties("13", ' ', FRIDAY, ofEpochSecond(1576184400), true, alignment = null), + DayProperties("14", ' ', SATURDAY, ofEpochSecond(1576270800), true, alignment = null), + DayProperties("15", ' ', SUNDAY, ofEpochSecond(1576357200), true, alignment = null), + DayProperties("16", ' ', MONDAY, ofEpochSecond(1576443600), true, alignment = null), + DayProperties("17", ' ', TUESDAY, ofEpochSecond(1576530000), true, alignment = null), + DayProperties("18", ' ', WEDNESDAY, ofEpochSecond(1576616400), true, alignment = null), + DayProperties("19", ' ', THURSDAY, ofEpochSecond(1576702800), true, alignment = null), + DayProperties("20", ' ', FRIDAY, ofEpochSecond(1576789200), true, alignment = null), + DayProperties("21", ' ', SATURDAY, ofEpochSecond(1576875600), true, alignment = null), + DayProperties("22", ' ', SUNDAY, ofEpochSecond(1576962000), true, alignment = null), + DayProperties("23", ' ', MONDAY, ofEpochSecond(1577048400), true, alignment = null), + DayProperties("24", ' ', TUESDAY, ofEpochSecond(1577134800), true, alignment = null), + DayProperties("25", ' ', WEDNESDAY, ofEpochSecond(1577221200), true, alignment = null), + DayProperties("26", ' ', THURSDAY, ofEpochSecond(1577307600), true, alignment = null), + DayProperties("27", ' ', FRIDAY, ofEpochSecond(1577394000), true, alignment = null), + DayProperties("28", ' ', SATURDAY, ofEpochSecond(1577480400), true, alignment = null), + DayProperties("29", ' ', SUNDAY, ofEpochSecond(1577566800), true, alignment = null), + DayProperties("30", ' ', MONDAY, ofEpochSecond(1577653200), true, alignment = null), + DayProperties("31", ' ', TUESDAY, ofEpochSecond(1577739600), true, alignment = null), + DayProperties("1", ' ', WEDNESDAY, ofEpochSecond(1577826000), alignment = null), + DayProperties("2", ' ', THURSDAY, ofEpochSecond(1577912400), alignment = null), + DayProperties("3", ' ', FRIDAY, ofEpochSecond(1577998800), alignment = null), + DayProperties("4", ' ', SATURDAY, ofEpochSecond(1578085200), alignment = null), + DayProperties("5", ' ', SUNDAY, ofEpochSecond(1578171600), alignment = null) ) ) ) - private fun getSystemLocalDateAndFirstDayOfWeekWithExpectedCurrentWeekFocusedInitialLocalDate() = listOf( - of(parse("2022-02-24"), MONDAY, parse("2022-02-14")), - of(parse("2022-02-27"), MONDAY, parse("2022-02-14")), - of(parse("2022-02-28"), MONDAY, parse("2022-02-21")), - of(parse("2022-02-28"), TUESDAY, parse("2022-02-15")), - of(parse("2022-03-01"), TUESDAY, parse("2022-02-22")), - of(parse("2022-01-01"), WEDNESDAY, parse("2021-12-22")), - of(parse("2022-01-01"), SATURDAY, parse("2021-12-25")), - of(parse("2022-02-20"), SUNDAY, parse("2022-02-13")), - of(parse("2022-02-25"), SUNDAY, parse("2022-02-13")), - of(parse("2022-02-26"), SUNDAY, parse("2022-02-13")), - of(parse("2022-02-27"), SUNDAY, parse("2022-02-20")) - ) - - private fun getSystemLocalDateAndFirstDayOfWeekWithExpectedNaturalMonthInitialLocalDate() = listOf( - of(parse("2018-01-26"), MONDAY, parse("2018-01-01")), - of(parse("2018-01-26"), TUESDAY, parse("2017-12-26")), - of(parse("2018-01-26"), WEDNESDAY, parse("2017-12-27")), - of(parse("2018-01-26"), THURSDAY, parse("2017-12-28")), - of(parse("2018-01-26"), FRIDAY, parse("2017-12-29")), - of(parse("2018-01-26"), SATURDAY, parse("2017-12-30")), - of(parse("2018-01-26"), SUNDAY, parse("2017-12-31")), - of(parse("2005-02-19"), WEDNESDAY, parse("2005-01-26")), - of(parse("2027-03-05"), SUNDAY, parse("2027-02-28")), - of(parse("2099-04-30"), MONDAY, parse("2099-03-30")), - of(parse("2000-05-01"), SATURDAY, parse("2000-04-29")), - of(parse("1998-06-02"), WEDNESDAY, parse("1998-05-27")), - of(parse("1992-07-07"), TUESDAY, parse("1992-06-30")), - of(parse("2018-08-01"), FRIDAY, parse("2018-07-27")), - of(parse("1987-09-12"), FRIDAY, parse("1987-08-28")), - of(parse("2017-10-01"), THURSDAY, parse("2017-09-28")), - of(parse("1000-11-12"), SATURDAY, parse("1000-11-01")), - of(parse("1994-12-13"), THURSDAY, parse("1994-12-01")), - of(parse("2021-02-13"), MONDAY, parse("2021-02-01")), - of(parse("2021-03-13"), MONDAY, parse("2021-03-01")) - ) - - private fun getLocalDateAndIncludeDeclinedEventsWithExpectedNumberOfInstances() = listOf( - of(parse("2018-11-26"), false, 1), - of(parse("2018-11-27"), false, 0), - of(parse("2018-11-28"), false, 1), - of(parse("2018-11-29"), false, 1), - of(parse("2018-11-30"), false, 0), - of(parse("2018-12-01"), false, 0), - of(parse("2018-12-02"), false, 0), - of(parse("2018-12-03"), false, 1), - of(parse("2018-12-04"), false, 1), - of(parse("2018-12-05"), false, 0), - of(parse("2018-12-06"), false, 3), - of(parse("2018-12-07"), false, 1), - of(parse("2018-12-08"), false, 0), - of(parse("2018-12-09"), false, 0), - of(parse("2018-12-10"), false, 4), - of(parse("2018-12-11"), false, 1), - of(parse("2018-12-12"), false, 0), - of(parse("2018-12-13"), false, 0), - of(parse("2018-12-14"), false, 0), - of(parse("2018-12-15"), false, 0), - of(parse("2018-12-16"), false, 0), - of(parse("2018-12-17"), false, 0), - of(parse("2018-12-18"), false, 0), - of(parse("2018-12-19"), false, 0), - of(parse("2018-12-20"), false, 0), - of(parse("2018-12-21"), false, 0), - of(parse("2018-12-22"), false, 0), - of(parse("2018-12-23"), false, 0), - of(parse("2018-12-24"), false, 0), - of(parse("2018-12-25"), false, 0), - of(parse("2018-12-26"), false, 0), - of(parse("2018-12-27"), false, 1), - of(parse("2018-12-28"), false, 0), - of(parse("2018-12-29"), false, 0), - of(parse("2018-12-30"), false, 5), - of(parse("2018-12-31"), false, 0), - of(parse("2019-01-01"), false, 1), - of(parse("2019-01-02"), false, 2), - of(parse("2019-01-03"), false, 2), - of(parse("2019-01-04"), false, 2), - of(parse("2019-01-05"), false, 8), - of(parse("2019-01-06"), false, 2), - of(parse("2018-11-26"), true, 1), - of(parse("2018-11-27"), true, 0), - of(parse("2018-11-28"), true, 1), - of(parse("2018-11-29"), true, 1), - of(parse("2018-11-30"), true, 0), - of(parse("2018-12-01"), true, 0), - of(parse("2018-12-02"), true, 0), - of(parse("2018-12-03"), true, 1), - of(parse("2018-12-04"), true, 1), - of(parse("2018-12-05"), true, 0), - of(parse("2018-12-06"), true, 3), - of(parse("2018-12-07"), true, 1), - of(parse("2018-12-08"), true, 0), - of(parse("2018-12-09"), true, 0), - of(parse("2018-12-10"), true, 4), - of(parse("2018-12-11"), true, 1), - of(parse("2018-12-12"), true, 0), - of(parse("2018-12-13"), true, 0), - of(parse("2018-12-14"), true, 0), - of(parse("2018-12-15"), true, 0), - of(parse("2018-12-16"), true, 0), - of(parse("2018-12-17"), true, 0), - of(parse("2018-12-18"), true, 1), - of(parse("2018-12-19"), true, 0), - of(parse("2018-12-20"), true, 0), - of(parse("2018-12-21"), true, 0), - of(parse("2018-12-22"), true, 0), - of(parse("2018-12-23"), true, 0), - of(parse("2018-12-24"), true, 0), - of(parse("2018-12-25"), true, 0), - of(parse("2018-12-26"), true, 0), - of(parse("2018-12-27"), true, 1), - of(parse("2018-12-28"), true, 0), - of(parse("2018-12-29"), true, 0), - of(parse("2018-12-30"), true, 5), - of(parse("2018-12-31"), true, 0), - of(parse("2019-01-01"), true, 1), - of(parse("2019-01-02"), true, 2), - of(parse("2019-01-03"), true, 2), - of(parse("2019-01-04"), true, 2), - of(parse("2019-01-05"), true, 8), - of(parse("2019-01-06"), true, 2) - ) - internal data class DrawDaysUseCaseTestProperties( val systemLocalDate: LocalDate, val systemInstances: Set, @@ -794,10 +754,10 @@ internal class DaysServiceTest : BaseTest() { val expectedFirstDay: LocalDate, val expectedInstancesQueryInitEpochMillis: Long, val expectedInstancesQueryEndEpochMillis: Long, - val expectedDayProperties: List + val expectedDayProperties: List ) - internal data class ExpectedDayProperties( + internal data class DayProperties( val dayOfMonth: String, val instancesSymbol: Char, val dayOfWeek: DayOfWeek, @@ -805,6 +765,6 @@ internal class DaysServiceTest : BaseTest() { val isInMonth: Boolean = false, val isToday: Boolean = false, val highlightDrawable: Int? = null, - val alignment: Layout.Alignment? = Layout.Alignment.ALIGN_OPPOSITE + val alignment: Layout.Alignment? ) } \ No newline at end of file diff --git a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/component/LayoutServiceTest.kt b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/component/LayoutServiceTest.kt index 0397e3ce..eb66625d 100644 --- a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/component/LayoutServiceTest.kt +++ b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/component/LayoutServiceTest.kt @@ -14,8 +14,7 @@ import io.mockk.justRun import io.mockk.mockk import io.mockk.verify import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.Arguments.of -import org.junit.jupiter.params.provider.MethodSource +import org.junit.jupiter.params.provider.CsvSource private const val DARK_THEME_MAIN_LAYOUT = 2131034143 private const val LIGHT_THEME_MAIN_LAYOUT = 2131034144 @@ -25,12 +24,28 @@ internal class LayoutServiceTest : BaseTest() { private val widgetRv = mockk() @ParameterizedTest - @MethodSource("getCombinationOfThemesAndTransparencyLevels") + @CsvSource( + "DARK,0,$DARK_THEME_MAIN_LAYOUT", + "DARK,1,$DARK_THEME_MAIN_LAYOUT", + "DARK,20,$DARK_THEME_MAIN_LAYOUT", + "DARK,50,$DARK_THEME_MAIN_LAYOUT", + "DARK,79,$DARK_THEME_MAIN_LAYOUT", + "DARK,90,$DARK_THEME_MAIN_LAYOUT", + "DARK,100,$DARK_THEME_MAIN_LAYOUT", + "LIGHT,0,$LIGHT_THEME_MAIN_LAYOUT", + "LIGHT,5,$LIGHT_THEME_MAIN_LAYOUT", + "LIGHT,70,$LIGHT_THEME_MAIN_LAYOUT", + "LIGHT,72,$LIGHT_THEME_MAIN_LAYOUT", + "LIGHT,98,$LIGHT_THEME_MAIN_LAYOUT", + "LIGHT,99,$LIGHT_THEME_MAIN_LAYOUT", + "LIGHT,100,$LIGHT_THEME_MAIN_LAYOUT" + ) fun draw_shouldSetLayoutWithThemeBackgroundColourAndTransparency( widgetTheme: Theme, - transparency: Transparency, + transparencyPercentage: Int, mainLayout: Int ) { + val transparency = Transparency(transparencyPercentage) mockTransparency(mainLayout, transparency, TransparencyRange.COMPLETE) justRun { @@ -51,21 +66,4 @@ internal class LayoutServiceTest : BaseTest() { } confirmVerified(widgetRv) } - - private fun getCombinationOfThemesAndTransparencyLevels() = listOf( - of(Theme.DARK, Transparency(0), DARK_THEME_MAIN_LAYOUT), - of(Theme.DARK, Transparency(1), DARK_THEME_MAIN_LAYOUT), - of(Theme.DARK, Transparency(20), DARK_THEME_MAIN_LAYOUT), - of(Theme.DARK, Transparency(50), DARK_THEME_MAIN_LAYOUT), - of(Theme.DARK, Transparency(79), DARK_THEME_MAIN_LAYOUT), - of(Theme.DARK, Transparency(90), DARK_THEME_MAIN_LAYOUT), - of(Theme.DARK, Transparency(100), DARK_THEME_MAIN_LAYOUT), - of(Theme.LIGHT, Transparency(0), LIGHT_THEME_MAIN_LAYOUT), - of(Theme.LIGHT, Transparency(5), LIGHT_THEME_MAIN_LAYOUT), - of(Theme.LIGHT, Transparency(70), LIGHT_THEME_MAIN_LAYOUT), - of(Theme.LIGHT, Transparency(72), LIGHT_THEME_MAIN_LAYOUT), - of(Theme.LIGHT, Transparency(98), LIGHT_THEME_MAIN_LAYOUT), - of(Theme.LIGHT, Transparency(99), LIGHT_THEME_MAIN_LAYOUT), - of(Theme.LIGHT, Transparency(100), LIGHT_THEME_MAIN_LAYOUT) - ) } \ No newline at end of file diff --git a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/component/MonthAndYearHeaderServiceTest.kt b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/component/MonthAndYearHeaderServiceTest.kt index 0f835fad..5ae1089a 100644 --- a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/component/MonthAndYearHeaderServiceTest.kt +++ b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/component/MonthAndYearHeaderServiceTest.kt @@ -15,10 +15,8 @@ import io.mockk.justRun import io.mockk.mockk import io.mockk.verify import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.Arguments.of -import org.junit.jupiter.params.provider.MethodSource +import org.junit.jupiter.params.provider.CsvSource import java.time.LocalDate -import java.time.LocalDate.parse import java.time.Month internal class MonthAndYearHeaderServiceTest : BaseTest() { @@ -26,21 +24,47 @@ internal class MonthAndYearHeaderServiceTest : BaseTest() { private val widgetRv = mockk() @ParameterizedTest - @MethodSource("getInstancesWithTextSizeAndThemeAndCalendarWithExpectedMonthAndYear") + @CsvSource( + "2018-01-26,40,DARK,GREGORIAN,January,2018", + "2018-01-26,15,DARK,GREGORIAN,Jan,2018", + "2005-02-19,40,DARK,HOLOCENE,February,12005", + "2005-02-19,15,DARK,GREGORIAN,Feb,2005", + "2027-03-05,40,DARK,GREGORIAN,March,2027", + "2027-03-05,15,DARK,HOLOCENE,Mar,12027", + "2099-04-30,40,DARK,HOLOCENE,April,12099", + "2099-04-30,15,DARK,GREGORIAN,Apr,2099", + "2000-05-01,40,DARK,GREGORIAN,May,2000", + "2000-05-01,15,DARK,HOLOCENE,May,12000", + "1998-06-02,40,DARK,GREGORIAN,June,1998", + "1998-06-02,15,DARK,HOLOCENE,Jun,11998", + "1992-07-07,40,LIGHT,GREGORIAN,July,1992", + "1992-07-07,15,LIGHT,GREGORIAN,Jul,1992", + "2018-08-01,40,LIGHT,GREGORIAN,August,2018", + "2018-08-01,15,LIGHT,HOLOCENE,Aug,12018", + "1987-09-12,40,LIGHT,HOLOCENE,September,11987", + "1987-09-12,15,LIGHT,GREGORIAN,Sep,1987", + "2017-10-01,40,LIGHT,GREGORIAN,October,2017", + "2017-10-01,15,LIGHT,GREGORIAN,Oct,2017", + "1000-11-12,40,LIGHT,HOLOCENE,November,11000", + "1000-11-12,15,LIGHT,GREGORIAN,Nov,1000", + "1994-12-13,40,LIGHT,GREGORIAN,December,1994", + "1994-12-13,15,LIGHT,GREGORIAN,Dec,1994" + ) fun draw_shouldAddMonthAndYearWithColourAndRelativeMonthAndYearSize( localDate: LocalDate, - textSize: TextSize, + textSizePercentage: Int, widgetTheme: Theme, calendar: Calendar, expectedMonth: String, expectedYear: String ) { val expectedHeaderRelativeYearSize = 0.6f + val textSize = TextSize(textSizePercentage) mockGetSystemLocalDate(localDate) mockWidgetCalendar(calendar) every { - context.getString(localDate.month.getExpectedResourceId()) - } returns localDate.month.getExpectedAbbreviatedString() + context.getString(localDate.month.getExpectedResourceIdAndTranslation().first) + } returns localDate.month.getExpectedResourceIdAndTranslation().second justRun { createMonthAndYearHeader( context = context, @@ -56,7 +80,7 @@ internal class MonthAndYearHeaderServiceTest : BaseTest() { MonthAndYearHeaderService.draw(context, widgetRv, textSize, widgetTheme) verifyGetSystemLocalDate() - verify { context.getString(localDate.month.getExpectedResourceId()) } + verify { context.getString(localDate.month.getExpectedResourceIdAndTranslation().first) } verifyWidgetCalendar() verify { createMonthAndYearHeader( @@ -72,62 +96,18 @@ internal class MonthAndYearHeaderServiceTest : BaseTest() { confirmVerified(widgetRv) } - private fun getInstancesWithTextSizeAndThemeAndCalendarWithExpectedMonthAndYear() = listOf( - of(parse("2018-01-26"), TextSize(40), Theme.DARK, Calendar.GREGORIAN, "January", "2018"), - of(parse("2018-01-26"), TextSize(15), Theme.DARK, Calendar.GREGORIAN, "Jan", "2018"), - of(parse("2005-02-19"), TextSize(40), Theme.DARK, Calendar.HOLOCENE, "February", "12005"), - of(parse("2005-02-19"), TextSize(15), Theme.DARK, Calendar.GREGORIAN, "Feb", "2005"), - of(parse("2027-03-05"), TextSize(40), Theme.DARK, Calendar.GREGORIAN, "March", "2027"), - of(parse("2027-03-05"), TextSize(15), Theme.DARK, Calendar.HOLOCENE, "Mar", "12027"), - of(parse("2099-04-30"), TextSize(40), Theme.DARK, Calendar.HOLOCENE, "April", "12099"), - of(parse("2099-04-30"), TextSize(15), Theme.DARK, Calendar.GREGORIAN, "Apr", "2099"), - of(parse("2000-05-01"), TextSize(40), Theme.DARK, Calendar.GREGORIAN, "May", "2000"), - of(parse("2000-05-01"), TextSize(15), Theme.DARK, Calendar.HOLOCENE, "May", "12000"), - of(parse("1998-06-02"), TextSize(40), Theme.DARK, Calendar.GREGORIAN, "June", "1998"), - of(parse("1998-06-02"), TextSize(15), Theme.DARK, Calendar.HOLOCENE, "Jun", "11998"), - of(parse("1992-07-07"), TextSize(40), Theme.LIGHT, Calendar.GREGORIAN, "July", "1992"), - of(parse("1992-07-07"), TextSize(15), Theme.LIGHT, Calendar.GREGORIAN, "Jul", "1992"), - of(parse("2018-08-01"), TextSize(40), Theme.LIGHT, Calendar.GREGORIAN, "August", "2018"), - of(parse("2018-08-01"), TextSize(15), Theme.LIGHT, Calendar.HOLOCENE, "Aug", "12018"), - of(parse("1987-09-12"), TextSize(40), Theme.LIGHT, Calendar.HOLOCENE, "September", "11987"), - of(parse("1987-09-12"), TextSize(15), Theme.LIGHT, Calendar.GREGORIAN, "Sep", "1987"), - of(parse("2017-10-01"), TextSize(40), Theme.LIGHT, Calendar.GREGORIAN, "October", "2017"), - of(parse("2017-10-01"), TextSize(15), Theme.LIGHT, Calendar.GREGORIAN, "Oct", "2017"), - of(parse("1000-11-12"), TextSize(40), Theme.LIGHT, Calendar.HOLOCENE, "November", "11000"), - of(parse("1000-11-12"), TextSize(15), Theme.LIGHT, Calendar.GREGORIAN, "Nov", "1000"), - of(parse("1994-12-13"), TextSize(40), Theme.LIGHT, Calendar.GREGORIAN, "December", "1994"), - of(parse("1994-12-13"), TextSize(15), Theme.LIGHT, Calendar.GREGORIAN, "Dec", "1994") - ) - - private fun Month.getExpectedResourceId() = - when (this) { - Month.JANUARY -> R.string.january - Month.FEBRUARY -> R.string.february - Month.MARCH -> R.string.march - Month.APRIL -> R.string.april - Month.MAY -> R.string.may - Month.JUNE -> R.string.june - Month.JULY -> R.string.july - Month.AUGUST -> R.string.august - Month.SEPTEMBER -> R.string.september - Month.OCTOBER -> R.string.october - Month.NOVEMBER -> R.string.november - Month.DECEMBER -> R.string.december - } - - private fun Month.getExpectedAbbreviatedString() = - when (this) { - Month.JANUARY -> "January" - Month.FEBRUARY -> "February" - Month.MARCH -> "March" - Month.APRIL -> "April" - Month.MAY -> "May" - Month.JUNE -> "June" - Month.JULY -> "July" - Month.AUGUST -> "August" - Month.SEPTEMBER -> "September" - Month.OCTOBER -> "October" - Month.NOVEMBER -> "November" - Month.DECEMBER -> "December" - } + private fun Month.getExpectedResourceIdAndTranslation() = when (this) { + Month.JANUARY -> Pair(R.string.january, "January") + Month.FEBRUARY -> Pair(R.string.february, "February") + Month.MARCH -> Pair(R.string.march, "March") + Month.APRIL -> Pair(R.string.april, "April") + Month.MAY -> Pair(R.string.may, "May") + Month.JUNE -> Pair(R.string.june, "June") + Month.JULY -> Pair(R.string.july, "July") + Month.AUGUST -> Pair(R.string.august, "August") + Month.SEPTEMBER -> Pair(R.string.september, "September") + Month.OCTOBER -> Pair(R.string.october, "October") + Month.NOVEMBER -> Pair(R.string.november, "November") + Month.DECEMBER -> Pair(R.string.december, "December") + } } \ No newline at end of file diff --git a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/CalendarTest.kt b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/CalendarTest.kt index 3d47da16..08a37c72 100644 --- a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/CalendarTest.kt +++ b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/CalendarTest.kt @@ -5,15 +5,38 @@ package cat.mvmike.minimalcalendarwidget.domain.configuration.item import cat.mvmike.minimalcalendarwidget.BaseTest import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.Arguments.of -import org.junit.jupiter.params.provider.MethodSource +import org.junit.jupiter.params.provider.CsvSource import java.time.LocalDate -import java.time.LocalDate.parse internal class CalendarTest : BaseTest() { @ParameterizedTest - @MethodSource("getSpreadCalendarsAndDatesWithExpectedText") + @CsvSource( + "GREGORIAN,2018-01-26,2018", + "HOLOCENE,2018-01-26,12018", + "HOLOCENE,2005-02-19,12005", + "GREGORIAN,2005-02-19,2005", + "GREGORIAN,2027-03-05,2027", + "HOLOCENE,2027-03-05,12027", + "HOLOCENE,2099-04-30,12099", + "GREGORIAN,2099-04-30,2099", + "GREGORIAN,2000-05-01,2000", + "HOLOCENE,2000-05-01,12000", + "GREGORIAN,1998-06-02,1998", + "HOLOCENE,1998-06-02,11998", + "HOLOCENE,1992-07-07,11992", + "GREGORIAN,1992-07-07,1992", + "GREGORIAN,2018-08-01,2018", + "HOLOCENE,2018-08-01,12018", + "HOLOCENE,1987-09-12,11987", + "GREGORIAN,1987-09-12,1987", + "GREGORIAN,2017-10-01,2017", + "HOLOCENE,2017-10-01,12017", + "HOLOCENE,1000-11-12,11000", + "GREGORIAN,1000-11-12,1000", + "GREGORIAN,1994-12-13,1994", + "GREGORIAN,1994-12-13,1994" + ) fun getYear_shouldReturnExpectedString( calendar: Calendar, localDate: LocalDate, @@ -21,31 +44,4 @@ internal class CalendarTest : BaseTest() { ) { assertThat(calendar.getYear(localDate)).isEqualTo(expectedYear) } - - private fun getSpreadCalendarsAndDatesWithExpectedText() = listOf( - of(Calendar.GREGORIAN, parse("2018-01-26"), "2018"), - of(Calendar.HOLOCENE, parse("2018-01-26"), "12018"), - of(Calendar.HOLOCENE, parse("2005-02-19"), "12005"), - of(Calendar.GREGORIAN, parse("2005-02-19"), "2005"), - of(Calendar.GREGORIAN, parse("2027-03-05"), "2027"), - of(Calendar.HOLOCENE, parse("2027-03-05"), "12027"), - of(Calendar.HOLOCENE, parse("2099-04-30"), "12099"), - of(Calendar.GREGORIAN, parse("2099-04-30"), "2099"), - of(Calendar.GREGORIAN, parse("2000-05-01"), "2000"), - of(Calendar.HOLOCENE, parse("2000-05-01"), "12000"), - of(Calendar.GREGORIAN, parse("1998-06-02"), "1998"), - of(Calendar.HOLOCENE, parse("1998-06-02"), "11998"), - of(Calendar.HOLOCENE, parse("1992-07-07"), "11992"), - of(Calendar.GREGORIAN, parse("1992-07-07"), "1992"), - of(Calendar.GREGORIAN, parse("2018-08-01"), "2018"), - of(Calendar.HOLOCENE, parse("2018-08-01"), "12018"), - of(Calendar.HOLOCENE, parse("1987-09-12"), "11987"), - of(Calendar.GREGORIAN, parse("1987-09-12"), "1987"), - of(Calendar.GREGORIAN, parse("2017-10-01"), "2017"), - of(Calendar.HOLOCENE, parse("2017-10-01"), "12017"), - of(Calendar.HOLOCENE, parse("1000-11-12"), "11000"), - of(Calendar.GREGORIAN, parse("1000-11-12"), "1000"), - of(Calendar.GREGORIAN, parse("1994-12-13"), "1994"), - of(Calendar.GREGORIAN, parse("1994-12-13"), "1994") - ) } \ No newline at end of file diff --git a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/ColourTest.kt b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/ColourTest.kt index 1b97b29a..63f1e9ca 100644 --- a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/ColourTest.kt +++ b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/ColourTest.kt @@ -26,10 +26,12 @@ internal class ColourTest : BaseTest() { @ParameterizedTest @EnumSource(value = Colour::class) fun getInstancesColour_shouldAlwaysReturnTheSameValueWhenIsToday(colour: Colour) { - Theme.entries.forEach { - val todayInstancesColour = colour.getInstancesColour(true, it) - assertThat(todayInstancesColour).isEqualTo(TEXT_COLOUR_TODAY_ID) - } + val todayInstancesColours = Theme.entries + .map { colour.getInstancesColour(true, it) } + .toSet() + + assertThat(todayInstancesColours).hasSize(1) + assertThat(todayInstancesColours).contains(TEXT_COLOUR_TODAY_ID) } @ParameterizedTest diff --git a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/SymbolSetTest.kt b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/SymbolSetTest.kt index 015ac84d..0afb2e3f 100644 --- a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/SymbolSetTest.kt +++ b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/SymbolSetTest.kt @@ -5,9 +5,8 @@ package cat.mvmike.minimalcalendarwidget.domain.configuration.item import cat.mvmike.minimalcalendarwidget.BaseTest import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.Arguments.of +import org.junit.jupiter.params.provider.CsvSource import org.junit.jupiter.params.provider.EnumSource -import org.junit.jupiter.params.provider.MethodSource internal class SymbolSetTest : BaseTest() { @@ -18,7 +17,27 @@ internal class SymbolSetTest : BaseTest() { } @ParameterizedTest - @MethodSource("getSymbolSetAndExpectedCharacter") + @CsvSource( + "MINIMAL,1,·", + "MINIMAL,6,◈", + "MINIMAL,7,◈", + "VERTICAL,4,⁞", + "VERTICAL,5,|", + "CIRCLES,1,◔", + "CIRCLES,4,●", + "CIRCLES,5,๑", + "NUMBERS,5,5", + "NUMBERS,9,9", + "NUMBERS,10,+", + "NUMBERS,11,+", + "ROMAN,2,Ⅱ", + "ROMAN,10,Ⅹ", + "ROMAN,11,∾", + "ROMAN,100,∾", + "BINARY,1,☱", + "BINARY,8,※", + "BINARY,9,※" + ) fun get_shouldReturnExpectedCharacter( symbolSet: SymbolSet, numberOfInstances: Int, @@ -26,26 +45,4 @@ internal class SymbolSetTest : BaseTest() { ) { assertThat(symbolSet.get(numberOfInstances)).isEqualTo(expectedCharacter) } - - private fun getSymbolSetAndExpectedCharacter() = listOf( - of(SymbolSet.MINIMAL, 1, '·'), - of(SymbolSet.MINIMAL, 6, '◈'), - of(SymbolSet.MINIMAL, 7, '◈'), - of(SymbolSet.VERTICAL, 4, '⁞'), - of(SymbolSet.VERTICAL, 5, '|'), - of(SymbolSet.CIRCLES, 1, '◔'), - of(SymbolSet.CIRCLES, 4, '●'), - of(SymbolSet.CIRCLES, 5, '๑'), - of(SymbolSet.NUMBERS, 5, '5'), - of(SymbolSet.NUMBERS, 9, '9'), - of(SymbolSet.NUMBERS, 10, '+'), - of(SymbolSet.NUMBERS, 11, '+'), - of(SymbolSet.ROMAN, 2, 'Ⅱ'), - of(SymbolSet.ROMAN, 10, 'Ⅹ'), - of(SymbolSet.ROMAN, 11, '∾'), - of(SymbolSet.ROMAN, 100, '∾'), - of(SymbolSet.BINARY, 1, '☱'), - of(SymbolSet.BINARY, 8, '※'), - of(SymbolSet.BINARY, 9, '※') - ) } \ No newline at end of file diff --git a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/TextSizeTest.kt b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/TextSizeTest.kt index db5540f0..46d0856f 100644 --- a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/TextSizeTest.kt +++ b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/TextSizeTest.kt @@ -6,7 +6,7 @@ import cat.mvmike.minimalcalendarwidget.BaseTest import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.assertThrows import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.MethodSource +import org.junit.jupiter.params.provider.CsvSource import org.junit.jupiter.params.provider.ValueSource internal class TextSizeTest : BaseTest() { @@ -20,51 +20,45 @@ internal class TextSizeTest : BaseTest() { } @ParameterizedTest - @MethodSource("getTextSizeWithAlphaLimitsAndExpectedOutputs") - fun getAlphaInHex(textSizeProperties: TextSizeTestProperties) { - val result = textSizeProperties.getTextSize() - - assertThat(result.monthHeaderLabelLength).isEqualTo(textSizeProperties.monthHeaderLabelLength) - assertThat(result.dayHeaderLabelLength).isEqualTo(textSizeProperties.dayHeaderLabelLength) - assertThat(result.relativeValue).isEqualTo(textSizeProperties.relativeValue) - } - - private fun getTextSizeWithAlphaLimitsAndExpectedOutputs() = listOf( - TextSizeTestProperties(0, 3, 1, 0.500f), - TextSizeTestProperties(1, 3, 1, 0.513f), - TextSizeTestProperties(5, 3, 1, 0.565f), - TextSizeTestProperties(10, 3, 1, 0.630f), - TextSizeTestProperties(15, 3, 1, 0.695f), - TextSizeTestProperties(17, 3, 1, 0.721f), - TextSizeTestProperties(20, 3, 1, 0.760f), - TextSizeTestProperties(23, 3, 1, 0.799f), - TextSizeTestProperties(24, 3, 1, 0.812f), - TextSizeTestProperties(25, Int.MAX_VALUE, 3, 0.825f), - TextSizeTestProperties(30, Int.MAX_VALUE, 3, 0.890f), - TextSizeTestProperties(35, Int.MAX_VALUE, 3, 0.955f), - TextSizeTestProperties(40, Int.MAX_VALUE, 3, 1.020f), - TextSizeTestProperties(45, Int.MAX_VALUE, 3, 1.085f), - TextSizeTestProperties(50, Int.MAX_VALUE, 3, 1.150f), - TextSizeTestProperties(55, Int.MAX_VALUE, 3, 1.215f), - TextSizeTestProperties(60, Int.MAX_VALUE, 3, 1.280f), - TextSizeTestProperties(65, Int.MAX_VALUE, 3, 1.345f), - TextSizeTestProperties(68, Int.MAX_VALUE, 3, 1.384f), - TextSizeTestProperties(70, Int.MAX_VALUE, 3, 1.410f), - TextSizeTestProperties(75, Int.MAX_VALUE, 3, 1.475f), - TextSizeTestProperties(80, Int.MAX_VALUE, 3, 1.540f), - TextSizeTestProperties(85, Int.MAX_VALUE, 3, 1.605f), - TextSizeTestProperties(90, Int.MAX_VALUE, 3, 1.670f), - TextSizeTestProperties(95, Int.MAX_VALUE, 3, 1.735f), - TextSizeTestProperties(99, Int.MAX_VALUE, 3, 1.787f), - TextSizeTestProperties(100, Int.MAX_VALUE, 3, 1.800f) + @CsvSource( + "0,3,1,0.500f", + "1,3,1,0.513f", + "5,3,1,0.565f", + "10,3,1,0.630f", + "15,3,1,0.695f", + "17,3,1,0.721f", + "20,3,1,0.760f", + "23,3,1,0.799f", + "24,3,1,0.812f", + "25,${Int.MAX_VALUE},3,0.825f", + "30,${Int.MAX_VALUE},3,0.890f", + "35,${Int.MAX_VALUE},3,0.955f", + "40,${Int.MAX_VALUE},3,1.020f", + "45,${Int.MAX_VALUE},3,1.085f", + "50,${Int.MAX_VALUE},3,1.150f", + "55,${Int.MAX_VALUE},3,1.215f", + "60,${Int.MAX_VALUE},3,1.280f", + "65,${Int.MAX_VALUE},3,1.345f", + "68,${Int.MAX_VALUE},3,1.384f", + "70,${Int.MAX_VALUE},3,1.410f", + "75,${Int.MAX_VALUE},3,1.475f", + "80,${Int.MAX_VALUE},3,1.540f", + "85,${Int.MAX_VALUE},3,1.605f", + "90,${Int.MAX_VALUE},3,1.670f", + "95,${Int.MAX_VALUE},3,1.735f", + "99,${Int.MAX_VALUE},3,1.787f", + "100,${Int.MAX_VALUE},3,1.800" ) - - internal data class TextSizeTestProperties( - private val percentage: Int, - val monthHeaderLabelLength: Int, - val dayHeaderLabelLength: Int, - val relativeValue: Float + fun getAlphaInHex( + percentage: Int, + expectedMonthHeaderLabelLength: Int, + expectedDayHeaderLabelLength: Int, + expectedRelativeValue: Float ) { - fun getTextSize() = TextSize(percentage) + val result = TextSize(percentage) + + assertThat(result.monthHeaderLabelLength).isEqualTo(expectedMonthHeaderLabelLength) + assertThat(result.dayHeaderLabelLength).isEqualTo(expectedDayHeaderLabelLength) + assertThat(result.relativeValue).isEqualTo(expectedRelativeValue) } } \ No newline at end of file diff --git a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/ThemeTest.kt b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/ThemeTest.kt index 4c90fabf..0e1c0124 100644 --- a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/ThemeTest.kt +++ b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/ThemeTest.kt @@ -5,8 +5,7 @@ package cat.mvmike.minimalcalendarwidget.domain.configuration.item import cat.mvmike.minimalcalendarwidget.BaseTest import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.Arguments.of -import org.junit.jupiter.params.provider.MethodSource +import org.junit.jupiter.params.provider.CsvSource import java.time.DayOfWeek // TEXT COLOUR @@ -36,25 +35,81 @@ private const val SUNDAY_LIGHT_THEME_CELL_BACKGROUND = 2131034152 internal class ThemeTest : BaseTest() { @ParameterizedTest - @MethodSource("getCombinationOfThemesAndDaysOfWeekWithExpectedCellHeader") + @CsvSource( + "DARK,MONDAY,$DARK_THEME_IN_MONTH_TEXT_COLOUR,", + "DARK,TUESDAY,$DARK_THEME_IN_MONTH_TEXT_COLOUR,", + "DARK,WEDNESDAY,$DARK_THEME_IN_MONTH_TEXT_COLOUR,", + "DARK,THURSDAY,$DARK_THEME_IN_MONTH_TEXT_COLOUR,", + "DARK,FRIDAY,$DARK_THEME_IN_MONTH_TEXT_COLOUR,", + "DARK,SATURDAY,$DARK_THEME_IN_MONTH_TEXT_COLOUR,$SATURDAY_IN_MONTH_DARK_THEME_CELL_BACKGROUND", + "DARK,SUNDAY,$DARK_THEME_IN_MONTH_TEXT_COLOUR,$SUNDAY_IN_MONTH_DARK_THEME_CELL_BACKGROUND", + "LIGHT,MONDAY,$LIGHT_THEME_IN_MONTH_TEXT_COLOUR,", + "LIGHT,TUESDAY,$LIGHT_THEME_IN_MONTH_TEXT_COLOUR,", + "LIGHT,WEDNESDAY,$LIGHT_THEME_IN_MONTH_TEXT_COLOUR,", + "LIGHT,THURSDAY,$LIGHT_THEME_IN_MONTH_TEXT_COLOUR,", + "LIGHT,FRIDAY,$LIGHT_THEME_IN_MONTH_TEXT_COLOUR,", + "LIGHT,SATURDAY,$LIGHT_THEME_IN_MONTH_TEXT_COLOUR,$SATURDAY_IN_MONTH_LIGHT_THEME_CELL_BACKGROUND", + "LIGHT,SUNDAY,$LIGHT_THEME_IN_MONTH_TEXT_COLOUR,$SUNDAY_IN_MONTH_LIGHT_THEME_CELL_BACKGROUND" + ) fun getCellHeader( widgetTheme: Theme, dayOfWeek: DayOfWeek, - expectedResult: CellTheme + expectedCellThemeTextColour: Int, + expectedCellThemeBackground: Int? ) { + val expectedResult = CellTheme( + textColour = expectedCellThemeTextColour, + background = expectedCellThemeBackground + ) + val result = widgetTheme.getCellHeader(dayOfWeek) assertThat(result).isEqualTo(expectedResult) } @ParameterizedTest - @MethodSource("getCombinationOfThemesAndDayStatusesWithExpectedCellDay") + @CsvSource( + "DARK,true,MONDAY,$DARK_THEME_IN_MONTH_TEXT_COLOUR,$IN_MONTH_DARK_THEME_CELL_BACKGROUND", + "DARK,true,TUESDAY,$DARK_THEME_IN_MONTH_TEXT_COLOUR,$IN_MONTH_DARK_THEME_CELL_BACKGROUND", + "DARK,true,WEDNESDAY,$DARK_THEME_IN_MONTH_TEXT_COLOUR,$IN_MONTH_DARK_THEME_CELL_BACKGROUND", + "DARK,true,THURSDAY,$DARK_THEME_IN_MONTH_TEXT_COLOUR,$IN_MONTH_DARK_THEME_CELL_BACKGROUND", + "DARK,true,FRIDAY,$DARK_THEME_IN_MONTH_TEXT_COLOUR,$IN_MONTH_DARK_THEME_CELL_BACKGROUND", + "DARK,true,SATURDAY,$DARK_THEME_IN_MONTH_TEXT_COLOUR,$SATURDAY_IN_MONTH_DARK_THEME_CELL_BACKGROUND", + "DARK,true,SUNDAY,$DARK_THEME_IN_MONTH_TEXT_COLOUR,$SUNDAY_IN_MONTH_DARK_THEME_CELL_BACKGROUND", + "DARK,false,MONDAY,$DARK_THEME_TEXT_COLOUR,", + "DARK,false,TUESDAY,$DARK_THEME_TEXT_COLOUR,", + "DARK,false,WEDNESDAY,$DARK_THEME_TEXT_COLOUR,", + "DARK,false,THURSDAY,$DARK_THEME_TEXT_COLOUR,", + "DARK,false,FRIDAY,$DARK_THEME_TEXT_COLOUR,", + "DARK,false,SATURDAY,$DARK_THEME_TEXT_COLOUR,$SATURDAY_DARK_THEME_CELL_BACKGROUND", + "DARK,false,SUNDAY,$DARK_THEME_TEXT_COLOUR,$SUNDAY_DARK_THEME_CELL_BACKGROUND", + "LIGHT,true,MONDAY,$LIGHT_THEME_IN_MONTH_TEXT_COLOUR,$IN_MONTH_LIGHT_THEME_CELL_BACKGROUND", + "LIGHT,true,TUESDAY,$LIGHT_THEME_IN_MONTH_TEXT_COLOUR,$IN_MONTH_LIGHT_THEME_CELL_BACKGROUND", + "LIGHT,true,WEDNESDAY,$LIGHT_THEME_IN_MONTH_TEXT_COLOUR,$IN_MONTH_LIGHT_THEME_CELL_BACKGROUND", + "LIGHT,true,THURSDAY,$LIGHT_THEME_IN_MONTH_TEXT_COLOUR,$IN_MONTH_LIGHT_THEME_CELL_BACKGROUND", + "LIGHT,true,FRIDAY,$LIGHT_THEME_IN_MONTH_TEXT_COLOUR,$IN_MONTH_LIGHT_THEME_CELL_BACKGROUND", + "LIGHT,true,SATURDAY,$LIGHT_THEME_IN_MONTH_TEXT_COLOUR,$SATURDAY_IN_MONTH_LIGHT_THEME_CELL_BACKGROUND", + "LIGHT,true,SUNDAY,$LIGHT_THEME_IN_MONTH_TEXT_COLOUR,$SUNDAY_IN_MONTH_LIGHT_THEME_CELL_BACKGROUND", + "LIGHT,false,MONDAY,$LIGHT_THEME_TEXT_COLOUR,", + "LIGHT,false,TUESDAY,$LIGHT_THEME_TEXT_COLOUR,", + "LIGHT,false,WEDNESDAY,$LIGHT_THEME_TEXT_COLOUR,", + "LIGHT,false,THURSDAY,$LIGHT_THEME_TEXT_COLOUR,", + "LIGHT,false,FRIDAY,$LIGHT_THEME_TEXT_COLOUR,", + "LIGHT,false,SATURDAY,$LIGHT_THEME_TEXT_COLOUR,$SATURDAY_LIGHT_THEME_CELL_BACKGROUND", + "LIGHT,false,SUNDAY,$LIGHT_THEME_TEXT_COLOUR,$SUNDAY_LIGHT_THEME_CELL_BACKGROUND" + ) fun getCellDay( widgetTheme: Theme, inMonth: Boolean, dayOfWeek: DayOfWeek, - expectedResult: CellTheme + expectedCellThemeTextColour: Int, + expectedCellThemeBackground: Int? ) { + val expectedResult = CellTheme( + textColour = expectedCellThemeTextColour, + background = expectedCellThemeBackground + ) + val result = widgetTheme.getCellDay( inMonth = inMonth, dayOfWeek = dayOfWeek @@ -62,374 +117,4 @@ internal class ThemeTest : BaseTest() { assertThat(result).isEqualTo(expectedResult) } - - private fun getCombinationOfThemesAndDaysOfWeekWithExpectedCellHeader() = listOf( - of( - Theme.DARK, - DayOfWeek.MONDAY, - CellTheme( - textColour = DARK_THEME_IN_MONTH_TEXT_COLOUR, - background = null - ) - ), - of( - Theme.DARK, - DayOfWeek.TUESDAY, - CellTheme( - textColour = DARK_THEME_IN_MONTH_TEXT_COLOUR, - background = null - ) - ), - of( - Theme.DARK, - DayOfWeek.WEDNESDAY, - CellTheme( - textColour = DARK_THEME_IN_MONTH_TEXT_COLOUR, - background = null - ) - ), - of( - Theme.DARK, - DayOfWeek.THURSDAY, - CellTheme( - textColour = DARK_THEME_IN_MONTH_TEXT_COLOUR, - background = null - ) - ), - of( - Theme.DARK, - DayOfWeek.FRIDAY, - CellTheme( - textColour = DARK_THEME_IN_MONTH_TEXT_COLOUR, - background = null - ) - ), - of( - Theme.DARK, - DayOfWeek.SATURDAY, - CellTheme( - textColour = DARK_THEME_IN_MONTH_TEXT_COLOUR, - background = SATURDAY_IN_MONTH_DARK_THEME_CELL_BACKGROUND - ) - ), - of( - Theme.DARK, - DayOfWeek.SUNDAY, - CellTheme( - textColour = DARK_THEME_IN_MONTH_TEXT_COLOUR, - background = SUNDAY_IN_MONTH_DARK_THEME_CELL_BACKGROUND - ) - ), - of( - Theme.LIGHT, - DayOfWeek.MONDAY, - CellTheme( - textColour = LIGHT_THEME_IN_MONTH_TEXT_COLOUR, - background = null - ) - ), - of( - Theme.LIGHT, - DayOfWeek.TUESDAY, - CellTheme( - textColour = LIGHT_THEME_IN_MONTH_TEXT_COLOUR, - background = null - ) - ), - of( - Theme.LIGHT, - DayOfWeek.WEDNESDAY, - CellTheme( - textColour = LIGHT_THEME_IN_MONTH_TEXT_COLOUR, - background = null - ) - ), - of( - Theme.LIGHT, - DayOfWeek.THURSDAY, - CellTheme( - textColour = LIGHT_THEME_IN_MONTH_TEXT_COLOUR, - background = null - ) - ), - of( - Theme.LIGHT, - DayOfWeek.FRIDAY, - CellTheme( - textColour = LIGHT_THEME_IN_MONTH_TEXT_COLOUR, - background = null - ) - ), - of( - Theme.LIGHT, - DayOfWeek.SATURDAY, - CellTheme( - textColour = LIGHT_THEME_IN_MONTH_TEXT_COLOUR, - background = SATURDAY_IN_MONTH_LIGHT_THEME_CELL_BACKGROUND - ) - ), - of( - Theme.LIGHT, - DayOfWeek.SUNDAY, - CellTheme( - textColour = LIGHT_THEME_IN_MONTH_TEXT_COLOUR, - background = SUNDAY_IN_MONTH_LIGHT_THEME_CELL_BACKGROUND - ) - ) - ) - - private fun getCombinationOfThemesAndDayStatusesWithExpectedCellDay() = listOf( - of( - Theme.DARK, - true, - DayOfWeek.MONDAY, - CellTheme( - textColour = DARK_THEME_IN_MONTH_TEXT_COLOUR, - background = IN_MONTH_DARK_THEME_CELL_BACKGROUND - ) - ), - of( - Theme.DARK, - true, - DayOfWeek.TUESDAY, - CellTheme( - textColour = DARK_THEME_IN_MONTH_TEXT_COLOUR, - background = IN_MONTH_DARK_THEME_CELL_BACKGROUND - ) - ), - of( - Theme.DARK, - true, - DayOfWeek.WEDNESDAY, - CellTheme( - textColour = DARK_THEME_IN_MONTH_TEXT_COLOUR, - background = IN_MONTH_DARK_THEME_CELL_BACKGROUND - ) - ), - of( - Theme.DARK, - true, - DayOfWeek.THURSDAY, - CellTheme( - textColour = DARK_THEME_IN_MONTH_TEXT_COLOUR, - background = IN_MONTH_DARK_THEME_CELL_BACKGROUND - ) - ), - of( - Theme.DARK, - true, - DayOfWeek.FRIDAY, - CellTheme( - textColour = DARK_THEME_IN_MONTH_TEXT_COLOUR, - background = IN_MONTH_DARK_THEME_CELL_BACKGROUND - ) - ), - of( - Theme.DARK, - true, - DayOfWeek.SATURDAY, - CellTheme( - textColour = DARK_THEME_IN_MONTH_TEXT_COLOUR, - background = SATURDAY_IN_MONTH_DARK_THEME_CELL_BACKGROUND - ) - ), - of( - Theme.DARK, - true, - DayOfWeek.SUNDAY, - CellTheme( - textColour = DARK_THEME_IN_MONTH_TEXT_COLOUR, - background = SUNDAY_IN_MONTH_DARK_THEME_CELL_BACKGROUND - ) - ), - of( - Theme.DARK, - false, - DayOfWeek.MONDAY, - CellTheme( - textColour = DARK_THEME_TEXT_COLOUR, - background = null - ) - ), - of( - Theme.DARK, - false, - DayOfWeek.TUESDAY, - CellTheme( - textColour = DARK_THEME_TEXT_COLOUR, - background = null - ) - ), - of( - Theme.DARK, - false, - DayOfWeek.WEDNESDAY, - CellTheme( - textColour = DARK_THEME_TEXT_COLOUR, - background = null - ) - ), - of( - Theme.DARK, - false, - DayOfWeek.THURSDAY, - CellTheme( - textColour = DARK_THEME_TEXT_COLOUR, - background = null - ) - ), - of( - Theme.DARK, - false, - DayOfWeek.FRIDAY, - CellTheme( - textColour = DARK_THEME_TEXT_COLOUR, - background = null - ) - ), - of( - Theme.DARK, - false, - DayOfWeek.SATURDAY, - CellTheme( - textColour = DARK_THEME_TEXT_COLOUR, - background = SATURDAY_DARK_THEME_CELL_BACKGROUND - ) - ), - of( - Theme.DARK, - false, - DayOfWeek.SUNDAY, - CellTheme( - textColour = DARK_THEME_TEXT_COLOUR, - background = SUNDAY_DARK_THEME_CELL_BACKGROUND - ) - ), - of( - Theme.LIGHT, - true, - DayOfWeek.MONDAY, - CellTheme( - textColour = LIGHT_THEME_IN_MONTH_TEXT_COLOUR, - background = IN_MONTH_LIGHT_THEME_CELL_BACKGROUND - ) - ), - of( - Theme.LIGHT, - true, - DayOfWeek.TUESDAY, - CellTheme( - textColour = LIGHT_THEME_IN_MONTH_TEXT_COLOUR, - background = IN_MONTH_LIGHT_THEME_CELL_BACKGROUND - ) - ), - of( - Theme.LIGHT, - true, - DayOfWeek.WEDNESDAY, - CellTheme( - textColour = LIGHT_THEME_IN_MONTH_TEXT_COLOUR, - background = IN_MONTH_LIGHT_THEME_CELL_BACKGROUND - ) - ), - of( - Theme.LIGHT, - true, - DayOfWeek.THURSDAY, - CellTheme( - textColour = LIGHT_THEME_IN_MONTH_TEXT_COLOUR, - background = IN_MONTH_LIGHT_THEME_CELL_BACKGROUND - ) - ), - of( - Theme.LIGHT, - true, - DayOfWeek.FRIDAY, - CellTheme( - textColour = LIGHT_THEME_IN_MONTH_TEXT_COLOUR, - background = IN_MONTH_LIGHT_THEME_CELL_BACKGROUND - ) - ), - of( - Theme.LIGHT, - true, - DayOfWeek.SATURDAY, - CellTheme( - textColour = LIGHT_THEME_IN_MONTH_TEXT_COLOUR, - background = SATURDAY_IN_MONTH_LIGHT_THEME_CELL_BACKGROUND - ) - ), - of( - Theme.LIGHT, - true, - DayOfWeek.SUNDAY, - CellTheme( - textColour = LIGHT_THEME_IN_MONTH_TEXT_COLOUR, - background = SUNDAY_IN_MONTH_LIGHT_THEME_CELL_BACKGROUND - ) - ), - of( - Theme.LIGHT, - false, - DayOfWeek.MONDAY, - CellTheme( - textColour = LIGHT_THEME_TEXT_COLOUR, - background = null - ) - ), - of( - Theme.LIGHT, - false, - DayOfWeek.TUESDAY, - CellTheme( - textColour = LIGHT_THEME_TEXT_COLOUR, - background = null - ) - ), - of( - Theme.LIGHT, - false, - DayOfWeek.WEDNESDAY, - CellTheme( - textColour = LIGHT_THEME_TEXT_COLOUR, - background = null - ) - ), - of( - Theme.LIGHT, - false, - DayOfWeek.THURSDAY, - CellTheme( - textColour = LIGHT_THEME_TEXT_COLOUR, - background = null - ) - ), - of( - Theme.LIGHT, - false, - DayOfWeek.FRIDAY, - CellTheme( - textColour = LIGHT_THEME_TEXT_COLOUR, - background = null - ) - ), - of( - Theme.LIGHT, - false, - DayOfWeek.SATURDAY, - CellTheme( - textColour = LIGHT_THEME_TEXT_COLOUR, - background = SATURDAY_LIGHT_THEME_CELL_BACKGROUND - ) - ), - of( - Theme.LIGHT, - false, - DayOfWeek.SUNDAY, - CellTheme( - textColour = LIGHT_THEME_TEXT_COLOUR, - background = SUNDAY_LIGHT_THEME_CELL_BACKGROUND - ) - ) - ) } \ No newline at end of file diff --git a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/TransparencyTest.kt b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/TransparencyTest.kt index 4d09677d..37b75a56 100644 --- a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/TransparencyTest.kt +++ b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/domain/configuration/item/TransparencyTest.kt @@ -6,7 +6,7 @@ import cat.mvmike.minimalcalendarwidget.BaseTest import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.assertThrows import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.MethodSource +import org.junit.jupiter.params.provider.CsvSource import org.junit.jupiter.params.provider.ValueSource internal class TransparencyTest : BaseTest() { @@ -20,73 +20,72 @@ internal class TransparencyTest : BaseTest() { } @ParameterizedTest - @MethodSource("getTransparencyWithAlphaLimitsAndExpectedOutputs") - fun getAlpha(transparencyProperties: TransparencyTestProperties) { - val result = transparencyProperties.getTransparency() - .getAlpha(transparencyProperties.transparencyRange) + @CsvSource( + "0,COMPLETE,255", + "0,MODERATE,80", + "0,LOW,30", + "1,COMPLETE,252", + "1,MODERATE,79", + "1,LOW,29", + "5,COMPLETE,242", + "20,COMPLETE,204", + "20,MODERATE,64", + "20,LOW,24", + "25,COMPLETE,191", + "65,COMPLETE,89", + "70,COMPLETE,76", + "70,MODERATE,24", + "70,LOW,9", + "75,COMPLETE,63", + "95,LOW,1", + "99,COMPLETE,2", + "100,COMPLETE,0", + "100,MODERATE,0", + "100,LOW,0" + ) + fun getAlpha( + transparencyPercentage: Int, + transparencyRange: TransparencyRange, + expectedAlpha: Int + ) { + val result = Transparency(transparencyPercentage) + .getAlpha(transparencyRange) - assertThat(result).isEqualTo(transparencyProperties.expectedAlpha) + assertThat(result).isEqualTo(expectedAlpha) } @ParameterizedTest - @MethodSource("getTransparencyWithAlphaLimitsAndExpectedOutputs") - fun getAlphaInHex(transparencyProperties: TransparencyTestProperties) { - val result = transparencyProperties.getTransparency() - .getAlphaInHex(transparencyProperties.transparencyRange) - - assertThat(result).isEqualTo(transparencyProperties.expectedAlphaInHex) - } - - private fun getTransparencyWithAlphaLimitsAndExpectedOutputs() = listOf( - TransparencyTestProperties(0, TransparencyRange.COMPLETE, 255, "FF"), - TransparencyTestProperties(0, TransparencyRange.MODERATE, 80, "50"), - TransparencyTestProperties(0, TransparencyRange.LOW, 30, "1E"), - TransparencyTestProperties(1, TransparencyRange.COMPLETE, 252, "FC"), - TransparencyTestProperties(1, TransparencyRange.MODERATE, 79, "4F"), - TransparencyTestProperties(1, TransparencyRange.LOW, 29, "1D"), - TransparencyTestProperties(5, TransparencyRange.COMPLETE, 242, "F2"), - TransparencyTestProperties(10, TransparencyRange.COMPLETE, 229, "E5"), - TransparencyTestProperties(15, TransparencyRange.COMPLETE, 216, "D8"), - TransparencyTestProperties(17, TransparencyRange.COMPLETE, 211, "D3"), - TransparencyTestProperties(20, TransparencyRange.COMPLETE, 204, "CC"), - TransparencyTestProperties(20, TransparencyRange.MODERATE, 64, "40"), - TransparencyTestProperties(20, TransparencyRange.LOW, 24, "18"), - TransparencyTestProperties(25, TransparencyRange.COMPLETE, 191, "BF"), - TransparencyTestProperties(30, TransparencyRange.COMPLETE, 178, "B2"), - TransparencyTestProperties(35, TransparencyRange.COMPLETE, 165, "A5"), - TransparencyTestProperties(40, TransparencyRange.COMPLETE, 153, "99"), - TransparencyTestProperties(45, TransparencyRange.COMPLETE, 140, "8C"), - TransparencyTestProperties(50, TransparencyRange.COMPLETE, 127, "7F"), - TransparencyTestProperties(55, TransparencyRange.COMPLETE, 114, "72"), - TransparencyTestProperties(60, TransparencyRange.COMPLETE, 102, "66"), - TransparencyTestProperties(60, TransparencyRange.MODERATE, 32, "20"), - TransparencyTestProperties(60, TransparencyRange.LOW, 12, "0C"), - TransparencyTestProperties(65, TransparencyRange.COMPLETE, 89, "59"), - TransparencyTestProperties(68, TransparencyRange.COMPLETE, 81, "51"), - TransparencyTestProperties(70, TransparencyRange.COMPLETE, 76, "4C"), - TransparencyTestProperties(70, TransparencyRange.MODERATE, 24, "18"), - TransparencyTestProperties(70, TransparencyRange.LOW, 9, "09"), - TransparencyTestProperties(75, TransparencyRange.COMPLETE, 63, "3F"), - TransparencyTestProperties(80, TransparencyRange.COMPLETE, 51, "33"), - TransparencyTestProperties(85, TransparencyRange.COMPLETE, 38, "26"), - TransparencyTestProperties(90, TransparencyRange.COMPLETE, 25, "19"), - TransparencyTestProperties(90, TransparencyRange.MODERATE, 8, "08"), - TransparencyTestProperties(90, TransparencyRange.LOW, 3, "03"), - TransparencyTestProperties(95, TransparencyRange.COMPLETE, 12, "0C"), - TransparencyTestProperties(95, TransparencyRange.MODERATE, 4, "04"), - TransparencyTestProperties(95, TransparencyRange.LOW, 1, "01"), - TransparencyTestProperties(99, TransparencyRange.COMPLETE, 2, "02"), - TransparencyTestProperties(100, TransparencyRange.COMPLETE, 0, "00"), - TransparencyTestProperties(100, TransparencyRange.MODERATE, 0, "00"), - TransparencyTestProperties(100, TransparencyRange.LOW, 0, "00") + @CsvSource( + "0,COMPLETE,FF", + "0,MODERATE,50", + "0,LOW,1E", + "1,COMPLETE,FC", + "1,MODERATE,4F", + "1,LOW,1D", + "5,COMPLETE,F2", + "20,COMPLETE,CC", + "20,MODERATE,40", + "20,LOW,18", + "25,COMPLETE,BF", + "65,COMPLETE,59", + "70,COMPLETE,4C", + "70,MODERATE,18", + "70,LOW,09", + "75,COMPLETE,3F", + "95,LOW,01", + "99,COMPLETE,02", + "100,COMPLETE,00", + "100,MODERATE,00", + "100,LOW,00" ) - - internal data class TransparencyTestProperties( - private val percentage: Int, - val transparencyRange: TransparencyRange, - val expectedAlpha: Int, - val expectedAlphaInHex: String + fun getAlphaInHex( + transparencyPercentage: Int, + transparencyRange: TransparencyRange, + expectedAlphaInHex: String ) { - fun getTransparency() = Transparency(percentage) + val result = Transparency(transparencyPercentage) + .getAlphaInHex(transparencyRange) + + assertThat(result).isEqualTo(expectedAlphaInHex) } } \ No newline at end of file diff --git a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/infrastructure/resolver/CalendarResolverTest.kt b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/infrastructure/resolver/CalendarResolverTest.kt index a0d9e058..e7cca022 100644 --- a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/infrastructure/resolver/CalendarResolverTest.kt +++ b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/infrastructure/resolver/CalendarResolverTest.kt @@ -28,7 +28,8 @@ internal class CalendarResolverTest : BaseTest() { private val validInstanceCursors = listOf( InstanceCursor(1, 1657097518736, 1659775918428, null, 1, 0), InstanceCursor(2, 1657065600000, 1657152000000, "UTC", 0, 1), - InstanceCursor(3, 1657097518738, 1659775918430, "CET", 2, 0) + InstanceCursor(3, 1657097518738, 1659775918430, "CET", 2, 0), + InstanceCursor(4, 1657097518738, 1659775918430, "America/Los_Angeles", 17, 0) ) @Test @@ -106,7 +107,7 @@ internal class CalendarResolverTest : BaseTest() { end ) } returns cursor - every { cursor.moveToNext() } returnsMany listOf(true, true, true, false) + every { cursor.moveToNext() } returnsMany validInstanceCursors.map { true }.plus(false) every { cursor.getInt(0) } returnsMany validInstanceCursors.map { it.eventId } every { cursor.getLong(1) } returnsMany validInstanceCursors.map { it.start } every { cursor.getLong(2) } returnsMany validInstanceCursors.map { it.end } @@ -135,6 +136,12 @@ internal class CalendarResolverTest : BaseTest() { isDeclined = true, start = ZonedDateTime.parse("2022-07-06T10:51:58.738+02:00[CET]"), end = ZonedDateTime.parse("2022-08-06T10:51:58.429+02:00[CET]") + ), + TimedInstance( + eventId = 4, + isDeclined = false, + start = ZonedDateTime.parse("2022-07-06T01:51:58.738-07:00[America/Los_Angeles]"), + end = ZonedDateTime.parse("2022-08-06T01:51:58.429-07:00[America/Los_Angeles]") ) ) verify { context.contentResolver } diff --git a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/infrastructure/resolver/SystemResolverTest.kt b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/infrastructure/resolver/SystemResolverTest.kt index 640973b2..ea89b8be 100644 --- a/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/infrastructure/resolver/SystemResolverTest.kt +++ b/app/src/test/kotlin/cat/mvmike/minimalcalendarwidget/infrastructure/resolver/SystemResolverTest.kt @@ -9,9 +9,7 @@ import io.mockk.mockkStatic import io.mockk.verify import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.Arguments.of import org.junit.jupiter.params.provider.CsvSource -import org.junit.jupiter.params.provider.MethodSource import java.time.DayOfWeek import java.util.Locale @@ -43,14 +41,27 @@ internal class SystemResolverTest : BaseTest() { } @ParameterizedTest - @MethodSource("getLocalDatesWithExpectations") + @CsvSource( + "ENGLISH,,SUNDAY", + "en,GB,MONDAY", + "ru,RU,MONDAY", + "en,US,SUNDAY", + "ca,ES,MONDAY", + "es,ES,MONDAY", + "fr,FR,MONDAY", + "iw,IL,SUNDAY", + "he,IL,SUNDAY", + "yue,CN,SUNDAY", + "tr,TR,MONDAY" + ) fun getSystemFirstDayOfWeek_shouldReturnLocaleDefaultWhenNoPreferenceValue( - locale: Locale, + language: String, + country: String?, expectedDayOfWeek: DayOfWeek ) { mockkStatic(LocalePreferences::class) every { LocalePreferences.getFirstDayOfWeek() } returns "" - every { SystemResolver.getSystemLocale() } returns locale + every { SystemResolver.getSystemLocale() } returns Locale(language, country ?: "") val result = SystemResolver.getSystemFirstDayOfWeek() @@ -58,18 +69,4 @@ internal class SystemResolverTest : BaseTest() { verify { SystemResolver.getSystemFirstDayOfWeek() } verify { SystemResolver.getSystemLocale() } } - - private fun getLocalDatesWithExpectations() = listOf( - of(Locale.ENGLISH, DayOfWeek.SUNDAY), - of(Locale("en", "GB"), DayOfWeek.MONDAY), - of(Locale("ru", "RU"), DayOfWeek.MONDAY), - of(Locale("en", "US"), DayOfWeek.SUNDAY), - of(Locale("ca", "ES"), DayOfWeek.MONDAY), - of(Locale("es", "ES"), DayOfWeek.MONDAY), - of(Locale("fr", "FR"), DayOfWeek.MONDAY), - of(Locale("iw", "IL"), DayOfWeek.SUNDAY), - of(Locale("he", "IL"), DayOfWeek.SUNDAY), - of(Locale("yue", "CN"), DayOfWeek.SUNDAY), - of(Locale("tr", "TR"), DayOfWeek.MONDAY) - ) } \ No newline at end of file