Uploaded image for project: 'OpenMRS Core'
  1. OpenMRS Core
  2. TRUNK-5137

Add custom hamcrest matcher HasGlobalError

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: TBD
    • Resolution: Fixed
    • Affects Version/s: Core 2.2.0
    • Fix Version/s: Core 2.2.0
    • Component/s: None
    • Labels:
      None
    • Complexity:
      Low

      Description

      During cleanup/refactor of ValidatorTests (~ 6/50 validator tests) I found quite a number of tests that said they were testing case X but didnt prepare the target object properly so they were actually testing case Y.

      In our tests of the validators we often just check if there are errors without looking at the error code.

      In case of global errors that you can create in the validator by errors.reject("myerror.code") it might be because you need to loop through the errors.getGlobalErrors() list

      To:

      • make it easy for devs to assert global errors of specific codes
      • remove duplication, since almost every validator test needs this

      SOLUTION:
      Add a custom hamcrest matcher HasGlobalErrors which enables

              assertThat(errors, hasGlobalErrors());
              assertThat(errors, hasGlobalErrors("error.null"));
      

      Provide factories which enables the above after static imports of
      the matcher.

      Show use of matcher in PersonNameValidatorTest and ConceptValidatorTest

        Attachments

          Activity

            People

            Assignee:
            teleivo Ivo Ulrich
            Reporter:
            teleivo Ivo Ulrich
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: