realm-java icon indicating copy to clipboard operation
realm-java copied to clipboard

Exhaustive-type tests using generics should use an all-types enum

Open edualonso opened this issue 5 years ago • 0 comments

Having an AllTypes enum where we define all possible types that could be used in collections or dictionaries would allow us to determine in our tests whether a particular type is supported by said collections or dictionaries. If we add a new type and don't handle it correctly our tests should fail.

For example:

enum class AllTypes {
  LONG, SHORT, STRING      // and many more

  fun isListSupported(type: AllTypes): Boolean {
    return when (type) {
      LONG,
      SHORT -> true
      SOMETHING_ELSE -> false
    }
  }

  fun isDictionarySupported(type: AllTypes): Boolean {
    // ...
  }
}

edualonso avatar Mar 03 '21 21:03 edualonso