Skip to content

Commit

Permalink
Add default values to the SelectionState interface (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoColman authored Mar 30, 2022
1 parent 22b3070 commit 3c56ff1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import java.time.LocalDate

@Stable
public interface SelectionState {
public fun isDateSelected(date: LocalDate): Boolean
public fun onDateSelected(date: LocalDate)
public fun isDateSelected(date: LocalDate): Boolean = false
public fun onDateSelected(date: LocalDate) { }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package io.github.boguszpawlowski.composecalendar.selection

import io.kotest.assertions.throwables.shouldNotThrowAny
import io.kotest.core.spec.style.ShouldSpec
import io.kotest.matchers.collections.shouldContainExactly
import io.kotest.matchers.shouldBe
Expand Down Expand Up @@ -135,4 +136,18 @@ internal class SelectionStateTest : ShouldSpec({
state.selection.endOrNull() shouldBe null
}
}

context("Selection State interface default values") {
val myInterfaceWithNoMethods = object : SelectionState {}

should("Default isDateSelected to false") {
myInterfaceWithNoMethods.isDateSelected(today) shouldBe false
}

should("Have a default implementation that doesn't throw an exception for onDateSelected") {
shouldNotThrowAny {
myInterfaceWithNoMethods.onDateSelected(today)
}
}
}
})

0 comments on commit 3c56ff1

Please sign in to comment.