Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
Resolve review comments. Update AGP.
Browse files Browse the repository at this point in the history
  • Loading branch information
Keworker committed Sep 14, 2023
1 parent 6f1d148 commit 4c94081
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Calendar>() {
private val formatter = SimpleDateFormat("dd.MM.yyyy")
Expand All @@ -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
}
}

Expand All @@ -61,6 +62,6 @@ internal class HasSameDateWith(
* @param expected calendar that has expected year, month and day [Calendar]
*/
@Factory
fun hasSameDateWith(expected: Calendar): Matcher<Calendar> = HasSameDateWith(expected)
fun equalTo(expected: Calendar): Matcher<Calendar> = CalendarMatcher(expected)
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4c94081

Please sign in to comment.