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

Closed
spring-projects-issues opened this issue Jun 20, 2018 · 3 comments
Closed

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

spring-projects-issues opened this issue Jun 20, 2018 · 3 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues 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:

verify(this.environment).acceptsProfiles("dev");

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

verify(this.environment).acceptsProfiles(Profiles.of("dev"));

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);
verify(this.environment).acceptsProfiles(profiles.capture());
List<String> profileNames = new ArrayList<String>();
profiles.getValue().matches((profile) -> {
	profileNames.add(profile);
	return false;
});
assertThat(profileNames).containsExactly("dev");

Affects: 5.1 RC1

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

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?

@spring-projects-issues
Copy link
Collaborator Author

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.

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.x Backlog milestone Jan 11, 2019
@sbrannen
Copy link
Member

In the interim this got reported separately in #25340 and fixed.

In light of that, I am closing this as a:

@wilkinsona, feel free to provide additional feedback if you think this issue should be reopened.

@sbrannen sbrannen closed this as not planned Won't fix, can't repro, duplicate, stale Apr 25, 2023
@sbrannen sbrannen added the status: duplicate A duplicate of another issue label Apr 25, 2023
@sbrannen sbrannen removed this from the 6.x Backlog milestone Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants