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

Improve testability of new Profiles support [SPR-16962] #21500

spring-issuemaster opened this issue Jun 20, 2018 · 2 comments


Copy link

@spring-issuemaster spring-issuemaster commented Jun 20, 2018

Andy Wilkinson opened SPR-16962 and commented

The introduction of the Profiles type in #17063 has made verifying that a call to Environment.acceptsProfiles has been made more difficult. When String was used, verification with Mockito was easy:


With the new Profiles type this will fail as ParsedProfiles does not override equals:


The best that I have come up with is to capture the argument that's passed into acceptsProfiles, abuse matches to capture the names of the profiles, and assert that they are as expected:

ArgumentCaptor<Profiles> profiles = ArgumentCaptor.forClass(Profiles.class);
List<String> profileNames = new ArrayList<String>();
profiles.getValue().matches((profile) -> {
	return false;

Affects: 5.1 RC1

Issue Links:

  • #17063 Support AND operator in @Profile annotation

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jun 21, 2018

Stéphane Nicoll commented

 With the new Profiles type this will fail as ParsedProfiles does not override equals

Good catch. Implementing equals there may not be the easiest thing to do if we want to make this right. The input arguments can be provided in any order and that makes still two Profiles equal. Same thing within an expression to some extent.

I understand the problem but I am not keen to implement a basic equals for the purpose of restoring a simple "string" checks. Do you have any suggestion?


This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jun 21, 2018

Andy Wilkinson commented

I wasn't necessarily suggesting that implementing equals was the answer. It was just the first thing that I tried after upgrading the code to remove the use of deprecated methods. That said, from a usage perspective, implementing equals feels to me like the right thing to do. I suspect it could prove useful outside of tests as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.