Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValidationMessage.toString should contain all properties used for equality check #299

Closed
koppor opened this issue Jun 5, 2020 · 5 comments

Comments

@koppor
Copy link

koppor commented Jun 5, 2020

I am unit testing validation.

        Arguments.of(
            Collections.singleton(
                (new ValidationMessage.Builder())
                    .type("pattern")
                    .code("1023")
                    .path("$")
                    .arguments("___version")
                    .format(
                        new MessageFormat(
                            "{0}.{1}: does not match the regex pattern ^1\\.0\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"))
                    .build()),
            Paths.get(
                "wrong-version.json")),

The test fails:

org.opentest4j.AssertionFailedError: expected: java.util.Collections$SingletonSet@6f2cb653<[$._version: does not match the regex pattern ^1\.0\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$]> but was: java.util.LinkedHashSet@14c01636<[$._version: does not match the regex pattern ^1\.0\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$]>
Expected :[$._version: does not match the regex pattern ^1\.0\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$]
Actual   :[$._version: does not match the regex pattern ^1\.0\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$]

In IntelliJ, I can "Click to see the difference":

image

How can I quickly find out the differences without debugging?

Thus, I propose to include all properties in toString which are used at equals.

@stevehu
Copy link
Contributor

stevehu commented Jun 5, 2020

We have a pending issue with the error messages. It is still in active discussion but we are leaning to the specification recommendations.

#286

@koppor
Copy link
Author

koppor commented Jun 5, 2020

In case the ValidationMessage is changed to something containing more than the specification demands, there should be toString() and getMessage() (or toReadbleString())

@stevehu
Copy link
Contributor

stevehu commented Jun 5, 2020

@koppor I think these methods all have their purposes.

@koppor
Copy link
Author

koppor commented Jun 27, 2020

@stevehu Yeah, I think, the purposes are different. toString() is IMHO for debuggin (also backed by the article at https://dev.to/kylec32/effective-java-tuesday-override-tostring-14n7). Maybe you like Lombok's @ToString?

@stevehu
Copy link
Contributor

stevehu commented Jun 27, 2020

I agree with you that toString is used mostly internally like debugging or auditing. Lombok's toString generator looks pretty good; however, I don't think we should introduce another library for this purpose. In my opinion, we want to ensure that this library is as green as possible to not introduce any dependency conflict to users. We basically follow the same principle for the entire light platform.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants