jparams / to-string-verifier

To String Verifier provides an easy and convenient way to test the toString method on your class.
MIT License
33 stars 6 forks source link

Commons-lang3 toString style does not fit the expected style of to-string-verifier #59

Open DennisGoermannMD opened 2 years ago

DennisGoermannMD commented 2 years ago

Hello,

we use apache common-lang3 to generate toString presentations. Starting with commons-lang3 3.11 the output was changed for maps. See https://issues.apache.org/jira/browse/LANG-1543 If we update the apache dependency our test will failed due the to-string-verifier does not expect this new style.

Please fix this.

Example:

public class Example {

    private Map<String, Integer> exampleMap;

    public Map<String, Integer> getExampleMap() {
        return exampleMap;
    }

    public void setExampleMap(Map<String, Integer> exampleMap) {
        this.exampleMap = exampleMap;
    }

    @Override
    public String toString() {
        return new ReflectionToStringBuilder(this, ToStringStyle.JSON_STYLE).append("class", this.getClass().getCanonicalName())
                .toString();
    }
}
@Test
    public void testExampleToString() {
        ToStringVerifier.forClass(Example.class).verify();
    }

the result with to-string-verifier 1.4.8 is: java.lang.AssertionError:

Failed verification:

com.Example

Expected auto generated toString:
{"class":"com.Example","exampleMap":{"3585d9b7-9589-4a2c-a291-151b6d5551df":-1387581510}}

To contain fields with values:
  - exampleMap: {3585d9b7-9589-4a2c-a291-151b6d5551df=-1387581510

The problem seems to be the equals-sign "=". It was replaced with ":" for legal json representation.

With kind regards Dennis

DennisGoermannMD commented 2 years ago

Commons-lang3 >3.11 has more changes to the string style. Now the output will be legal json!