You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2023/05/26 18:40:00 UTC

[jira] [Created] (CALCITE-5726) Canonize use of Hamcrest matchers in test code

Julian Hyde created CALCITE-5726:
------------------------------------

             Summary: Canonize use of Hamcrest matchers in test code
                 Key: CALCITE-5726
                 URL: https://issues.apache.org/jira/browse/CALCITE-5726
             Project: Calcite
          Issue Type: Bug
            Reporter: Julian Hyde


Canonize use of Hamcrest matchers in test code.

1. If there are multiple equivalent methods, use the canonical one:
* CoreMatchers.is &rarr; Is.is
* Matchers.hasToString &rarr; HasToString.hasToString
* Matchers.hasSize &rarr; IsCollectionWithSize.hasSize
* Matchers.aMapWithSize &rarr; IsMapWithSize.aMapWithSize

2. Use matchers for {{Object.toString()}}, {{Collection.size()}}, {{Map.size()}}:
* assertThat(map.size(), is\(n)) &rarr; assertThat(map, aMapWithSize\(n));
* assertThat(list.size(), is\(n)) &rarr; assertThat(map, IsCollectionWithSize.hasSize\(n));
* assertThat(o.toString(), is(s)) &rarr; assertThat(o, hasToString(s));
* assertThat(o.toString(), equalTo(s)) &rarr; 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}}.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)