Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-5726

Canonize use of Hamcrest matchers in test code

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.35.0
    • None
    • None

    Description

      Canonize use of Hamcrest matchers in test code.

      1. If there are multiple equivalent methods, use the canonical one. Examples:

      • Is.is → CoreMatchers.is
      • HasToString.hasToString → Matchers.hasToString
      • IsCollectionWithSize.hasSize → Matchers.hasSize
      • IsMapWithSize.aMapWithSize → Matchers.aMapWithSize

      2. Use matchers for Object.toString(), Collection.size(), Map.size():

      • assertThat(map.size(), is(n)) → assertThat(map, aMapWithSize(n));
      • assertThat(list.size(), is(n)) → assertThat(map, IsCollectionWithSize.hasSize(n));
      • assertThat(o.toString(), is(s)) → assertThat(o, hasToString(s));
      • assertThat(o.toString(), equalTo(s)) → assertThat(o, hasToString(s));

      Require static import of Hamcrest methods.
       
      The benefit is conciseness/uniformity of tests. Most of these transformations can be accomplished using autostyle rules in the Gradle build.gradle.kts, so people's code will be fixed using gradle autostyleApply.

      Attachments

        Issue Links

          Activity

            People

              julianhyde Julian Hyde
              julianhyde Julian Hyde
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: