Skip to content

Remove or relax the new rule for strict String to Boolean conversion #3490

Closed as not planned
@Treverix

Description

@Treverix

#3178 made String to Boolean conversion more strict (added with version 5.10.0).

I strongly suggest to remove that feature or relax on the rule, because now we can't use our karnaugh maps (KM) on CSV sources anymore.

Karnaugh maps allow three values: false, true and don't care (or 0, 1, don't care).

Consider this (simple) example. We test if a method correctly computes, that a form is editable

    @ParameterizedTest
    @CsvSource(delimiter = '|', textBlock = """
        # isReadOnly | hasWriteAccess | isEditable
        # -----------+----------------+------------
          false      | true           | true
        # -----------+----------------+------------
          false      | false          | false
          true       | ?              | false
        # -----------+----------------+------------
        """)
    void isEditableTest(final boolean isReadOnly, final boolean hasWriteAccess, final boolean isEditable) {
   // ...
  }

If 'read-only' is true, then we don't care about user access rights - it's not editable. The implementation is not required to check that. Technically, we get a false injected, but: we don't care. Can be false or true. The implementation does not care and neither does the test. It shall work with false and true and it's ok to test with one of both.

Karnaugh maps can get a lot more complex, if the method under test has more then just two logical conditions. Those KM in CSV sources greatly improve readability and maintainability of unit tests.

#3178 makes that impossible now, because '?' or 'X' for 'don't care' are no accepted values anymore.

The common rule in JUnit is that the system looks for a constructor or static factory method, that takes a String. Here, it uses either new Boolean(String) or Boolean.valueOf(String) and both return Boolean.TRUE only if the String is true (case insensitive). #3178 breaks that rule.

I understand, that this is helpful to detect typos in parameterized test values. But I still think, that it adds more problems then value.

I suggest, that JUnit get's updated and either

  • removes that feature again or
  • adds a flag to opt out with a configuration parameter or
  • the existing rule allows two extra symbols: ? and x (case insensitve) so that we can keep our karnaugh maps in CSV sources.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions