diff --git a/app/src/test/java/com/google/samples/apps/sunflower/data/GardenPlantingTest.kt b/app/src/test/java/com/google/samples/apps/sunflower/data/GardenPlantingTest.kt index 1fd83fcc7..404b72313 100644 --- a/app/src/test/java/com/google/samples/apps/sunflower/data/GardenPlantingTest.kt +++ b/app/src/test/java/com/google/samples/apps/sunflower/data/GardenPlantingTest.kt @@ -16,7 +16,7 @@ package com.google.samples.apps.sunflower.data -import com.google.samples.apps.sunflower.test.HasSameDateWith.Companion.hasSameDateWith +import com.google.samples.apps.sunflower.test.CalendarMatcher.Companion.equalTo import org.hamcrest.CoreMatchers.`is` import org.hamcrest.MatcherAssert.assertThat import org.junit.Test @@ -28,8 +28,8 @@ internal class GardenPlantingTest { fun testDefaultValues() { val gardenPlanting = GardenPlanting("1") val calendar = Calendar.getInstance() - assertThat(gardenPlanting.plantDate, hasSameDateWith(calendar)) - assertThat(gardenPlanting.lastWateringDate, hasSameDateWith(calendar)) + assertThat(gardenPlanting.plantDate, equalTo(calendar)) + assertThat(gardenPlanting.lastWateringDate, equalTo(calendar)) assertThat(gardenPlanting.gardenPlantingId, `is`(0L)) } } diff --git a/app/src/test/java/com/google/samples/apps/sunflower/test/HasSameDateWith.kt b/app/src/test/java/com/google/samples/apps/sunflower/test/CalendarMatcher.kt similarity index 84% rename from app/src/test/java/com/google/samples/apps/sunflower/test/HasSameDateWith.kt rename to app/src/test/java/com/google/samples/apps/sunflower/test/CalendarMatcher.kt index 50e886509..f9ee5eb9e 100644 --- a/app/src/test/java/com/google/samples/apps/sunflower/test/HasSameDateWith.kt +++ b/app/src/test/java/com/google/samples/apps/sunflower/test/CalendarMatcher.kt @@ -30,7 +30,7 @@ import java.util.Calendar.YEAR * Calendar matcher. * Only Year/Month/Day precision is needed for comparing GardenPlanting Calendar entries */ -internal class HasSameDateWith( +internal class CalendarMatcher( private val expected: Calendar ) : TypeSafeDiagnosingMatcher() { private val formatter = SimpleDateFormat("dd.MM.yyyy") @@ -40,13 +40,14 @@ internal class HasSameDateWith( } override fun matchesSafely(actual: Calendar?, mismatchDescription: Description?): Boolean { - return (actual?.let { - actual.get(YEAR) == expected.get(YEAR) && - actual.get(MONTH) == expected.get(MONTH) && - actual.get(DAY_OF_MONTH) == expected.get(DAY_OF_MONTH) - } ?: false).also { _ -> + return if (actual != null && actual.get(YEAR) == expected.get(YEAR) && + actual.get(MONTH) == expected.get(MONTH) && + actual.get(DAY_OF_MONTH) == expected.get(DAY_OF_MONTH) + ) true + else { mismatchDescription?.appendText("was ") ?.appendText(actual?.time?.let { formatter.format(it) } ?: "null") + false } } @@ -61,6 +62,6 @@ internal class HasSameDateWith( * @param expected calendar that has expected year, month and day [Calendar] */ @Factory - fun hasSameDateWith(expected: Calendar): Matcher = HasSameDateWith(expected) + fun equalTo(expected: Calendar): Matcher = CalendarMatcher(expected) } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d78f30516..fc44a93f9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -16,7 +16,7 @@ [versions] accessibilityTestFramework = "4.0.0" activityCompose = "1.7.2" -androidGradlePlugin = "8.0.2" +androidGradlePlugin = "8.1.1" benchmark = "1.1.0" # @keep compileSdk = "33"