Simplify the assertion of file code owner statuses

For each assertion of a file code owner status we have to check a bunch
of properties (old path, code owner status for old path, new path, code
owner status for new path, change type), which results in a quite
verbose code block that is not very readable.

File code owner statuses are asserted in many tests and having this code
block that often badly affects the readability of the tests.

To improve this we add helper methods that make it easy to create the
expected file code owner statuses. Then we can easily compare the actual
file code owner statuses with the expected file code owner statuses in a
single line. Since we are comparing AutoValue entities, it's
automatically checking all the properties.

Example:

old:

  FileCodeOwnerStatusSubject fileCodeOwnerStatusSubject =
    assertThatCollection(fileCodeOwnerStatuses).onlyElement();
  fileCodeOwnerStatusSubject.hasOldPathStatus().value().hasPathThat()
    .isEqualTo(oldPath);
  fileCodeOwnerStatusSubject
    .hasOldPathStatus()
    .value()
    .hasStatusThat()
    .isEqualTo(CodeOwnerStatus.INSUFFICIENT_REVIEWERS);
  fileCodeOwnerStatusSubject.hasNewPathStatus().value().hasPathThat()
    .isEqualTo(newPath);
  fileCodeOwnerStatusSubject
    .hasNewPathStatus()
    .value()
    .hasStatusThat()
    .isEqualTo(CodeOwnerStatus.INSUFFICIENT_REVIEWERS);
  fileCodeOwnerStatusSubject.hasChangedFile().isRename();
  fileCodeOwnerStatusSubject.hasChangedFile().isNoDeletion();

new:

  assertThatCollection(fileCodeOwnerStatuses)
    .containsExactly(
      FileCodeOwnerStatus.rename(
        oldPath,
        CodeOwnerStatus.INSUFFICIENT_REVIEWERS,
        newPath,
        CodeOwnerStatus.INSUFFICIENT_REVIEWERS));

This change doesn't migrate all tests to the new pattern yet, but at
least it's a start to clean this up.

Change-Id: I7068fae9dfe6d8e75a1b44cc7e3fd3de0434d7ad
Signed-off-by: Edwin Kempin <ekempin@google.com>
7 files changed
tree: 758e7dba24b9bf47fd0d20dba476edd3c19b5873
  1. java/
  2. javatests/
  3. proto/
  4. resources/
  5. test/
  6. ui/
  7. .eslintrc.json
  8. .gitignore
  9. .gitreview
  10. bower.json
  11. BUILD
  12. LICENSE
  13. package-lock.json
  14. package.json
  15. README.md
README.md

Gerrit Code Review code-owners plugin

This plugin provides support for defining code owners for files in a repository.

If the code-owners plugin is enabled, changes can only be submitted if all touched files are covered by approvals from code owners.

Also see resources/Documentation/about.md.

IMPORTANT: Before installing/enabling the plugin follow the instructions from the setup guide, see resources/Documentation/setup-guide.md.