-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Profiles should be comparable when created via Profiles.of() #25340
Comments
@sbrannen Let's backport this to 5.1.x as well since that specific |
@jhoeller, I was literally just about to discuss this with you. It turns out it's not as simple as it may appear at a quick glance. I've experimented locally but haven't checked anything into a branch. In summary... In order to properly implement Currently, Now... the information is present in the internal Let's discuss our options... |
Maybe we should simply restrict it to literal equality of the input String... probably good enough for the mocking scenario here. We could even preserve whitespace in the comparison, avoiding any special processing of the String for comparison purposes. |
Prior to this commit, a Profiles instance created via Profiles.of() was not considered equivalent to another Profiles instance created via Profiles.of() with the exact same expressions. This makes it difficult to mock invocations of Environment#acceptsProfiles(Profiles) -- for example, when using a mocking library such as Mockito. This commit makes Profiles instances created via Profiles.of() "comparable" by implementing equals() and hashCode() in ParsedProfiles. Note, however, that equivalence is only guaranteed if the exact same profile expression strings are supplied to Profiles.of(). In other words, Profiles.of("A & B", "C | D") is equivalent to Profiles.of("A & B", "C | D") and Profiles.of("C | D", "A & B"), but Profiles.of("X & Y") is not equivalent to Profiles.of("X&Y") or Profiles.of("Y & X"). Closes spring-projectsgh-25340
Prior to this commit, a Profiles instance created via Profiles.of() was not considered equivalent to another Profiles instance created via Profiles.of() with the exact same expressions. This makes it difficult to mock invocations of Environment#acceptsProfiles(Profiles) -- for example, when using a mocking library such as Mockito. This commit makes Profiles instances created via Profiles.of() "comparable" by implementing equals() and hashCode() in ParsedProfiles. Note, however, that equivalence is only guaranteed if the exact same profile expression strings are supplied to Profiles.of(). In other words, Profiles.of("A & B", "C | D") is equivalent to Profiles.of("A & B", "C | D") and Profiles.of("C | D", "A & B"), but Profiles.of("X & Y") is not equivalent to Profiles.of("X&Y") or Profiles.of("Y & X"). Closes spring-projectsgh-25340
Prior to this commit, a Profiles instance created via Profiles.of() was not considered equivalent to another Profiles instance created via Profiles.of() with the exact same expressions. This makes it difficult to mock invocations of Environment#acceptsProfiles(Profiles) -- for example, when using a mocking library such as Mockito. This commit makes Profiles instances created via Profiles.of() "comparable" by implementing equals() and hashCode() in ParsedProfiles. Note, however, that equivalence is only guaranteed if the exact same profile expression strings are supplied to Profiles.of(). In other words, Profiles.of("A & B", "C | D") is equivalent to Profiles.of("A & B", "C | D") and Profiles.of("C | D", "A & B"), but Profiles.of("X & Y") is not equivalent to Profiles.of("X&Y") or Profiles.of("Y & X"). Closes spring-projectsgh-25340
Suppose we have this code in production:
Then I want to mock this in tests and I write something like:
And at runtime the mock fails to return
true
, because comparison of arguments fails due to missingequals()
andhashCode()
implementations inParsedProfiles
.This makes us use the deprecated API and rewrite the example code like:
and use of the deprecated API in turn makes Sonar unhappy.
The text was updated successfully, but these errors were encountered: