Skip to content

TestTypeExcludeFilter does not implement hashCode and equals as required by its super-class #23978

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

Closed
alonelyleaf opened this issue Oct 30, 2020 · 5 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@alonelyleaf
Copy link

alonelyleaf commented Oct 30, 2020

Why the class TestTypeExcludeFilter has not implemented hashCode? I have a problem with that, How can I exclude the TestTypeExcludeFilter from my test cases?

TypeExcludeFilter class org.springframework.boot.test.context.filter.TestTypeExcludeFilter has not implemented hashCode

best wishes!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 30, 2020
@wilkinsona
Copy link
Member

I'm not sure that I understand the problem you're seeing. Can you please expand a bit on the problem that you're seeing and what it is that isn't working as you expect. A complete yet minimal sample that reproduces the problem would be the ideal way to do that. You can share such a sample with us by pushing it to a separate repository on GitHub or zipping it up and attaching it to this issue.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Oct 30, 2020
@alonelyleaf
Copy link
Author

The method hashCode in TypeExcludeFilter need be implemented, but org.springframework.boot.test.context.filter.TestTypeExcludeFilter didn't do that. When I use its hashCode method, it throws a error.

      // the method in TypeExcludeFilter
        @Override
	public int hashCode() {
		throw new IllegalStateException("TypeExcludeFilter " + getClass() + " has not implemented hashCode");
	}
// my test code, When I run my test cases, it throw a Exception.
@Configuration
public class MyConfiguration {

    @Resource
    private Map<String, Object> consumerContainer;

    @Bean
    public MyAspect myAspect() {
        return new MyAspect(this.consumerContainer);
    }
}

@Aspect
public class MyAspect implements ApplicationContextAware {

    private Map<String, Object> container;
    private ApplicationContext applicationContext;

    public MyAspect(Map<String, Object> container) {
        this.container = container;
        System.out.println(toString());
    }

    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    public Map<String, Object> getContainer() {
        return container;
    }

    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public String toString() {
        return "MyAspect(container=" + this.getContainer() + ", applicationContext=" + this.getApplicationContext() + ")";
    }
}

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 30, 2020
@wilkinsona
Copy link
Member

Thanks for the additional information. Unfortunately, I can't see the connection between what you've shared and TestTypeExcludeFilter. Before we make any changes, I'd like to fully understand the problem. To that end, can you please provide the complete and minimal sample that I requested above.

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Oct 30, 2020
@alonelyleaf
Copy link
Author

I am sorry to provide the code now. you see my test code. Run the test class com.example.demo.DemoApplicationTests, And you can see the exception.

https://github.com/alonelyleaf/demo-TypeExcludeFilter

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 30, 2020
@wilkinsona
Copy link
Member

Thanks for the sample. I've reproduced the failure. Your code is quite unusual, in particular injecting a Map<String, Object> of every bean in the context is something that I'm not sure I've seen before, particularly when also injecting ApplicationContext as well. Due to the minimal nature of the sample (thank you for keeping it nice and small) I can't tell what is the purpose of the map of beans, but I'd encourage you to take a different approach if at all possible.

With all that said, now that I understand the nature of the problem, I think we should implement hashCode() (and equals(Object)) on TestTypeExcludeFilter.

@wilkinsona wilkinsona changed the title TestTypeExcludeFilter has not implemented hashCode TestTypeExcludeFilter does not implement hashCode and equals as required by its super-class Oct 30, 2020
@wilkinsona wilkinsona added type: bug A general bug and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Oct 30, 2020
@wilkinsona wilkinsona added this to the 2.2.x milestone Oct 30, 2020
@wilkinsona wilkinsona self-assigned this Nov 3, 2020
@wilkinsona wilkinsona modified the milestones: 2.2.x, 2.2.12 Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants