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

PSM-671 Introduce a check for test method names #6

Merged
merged 8 commits into from
Jan 7, 2021

Conversation

anicolasgar
Copy link
Contributor

Extra information ℹ️

@anicolasgar
Copy link
Contributor Author

anicolasgar commented Dec 7, 2020

Tested against PSM and seems to work correctly ✅

diff git . --stat
 id-support/src/test/java/tech/picnic/id/validators/UserIdTest.java                                                                    |  2 +-
 jooq-support/src/test/java/com/picnic/jooq/test/JooqPostgresTestContainerTest.java                                                    |  2 +-
 mongodb-support/src/test/java/com/picnic/mongo/test/SpringMongoDBTestContainerTest.java                                               |  8 ++++----
 rest-support/src/test/java/com/picnic/rest/AbstractRxHttpClientTest.java                                                              |  2 +-
 security-support/security-support-commons/src/test/java/tech/picnic/security/aspect/SystemRoleAnalyzerInvocationsTest.java            |  2 +-
 security-support/security-support-webflux/src/test/java/tech/picnic/security/webflux/SecurityContextPropagatorTest.java               |  2 +-
 security-support/security-support-webflux/src/test/java/tech/picnic/security/webflux/access/SecuredReactiveMethodInterceptorTest.java | 10 +++++-----
 security-support/security-support-webflux/src/test/java/tech/picnic/security/webflux/auth/PicnicAuthenticationTokenTest.java          |  2 +-
 security-support/security-support-webflux/src/test/java/tech/picnic/security/webflux/auth/PicnicAuthoritiesManagerTest.java           | 10 +++++-----
 security-support/security-support-webflux/src/test/java/tech/picnic/security/webflux/authproxy/AuthProxyHeadersConverterTest.java     |  2 +-
 test-support/src/main/java/com/picnic/testing/AbstractArchitectureTest.java                                                           | 10 +++++-----
 test-support/src/main/java/com/picnic/testing/AbstractMainApplicationTest.java                                                        |  4 ++--
 webapp-support/webapp-support-webmvc/src/test/java/tech/picnic/webapp/webmvc/ContextForwardingScheduledThreadPoolExecutorTest.java    |  4 ++--
 13 files changed, 30 insertions(+), 30 deletions(-)

@anicolasgar
Copy link
Contributor Author

After the new changes, running again against PSM:

diff git . --stat
general-components/src/test/java/com/picnic/validators/PicnicEmailValidatorTest.java                                                  |  2 +-
jooq-support/src/test/java/com/picnic/jooq/test/JooqPostgresTestContainerTest.java                                                    |  2 +-
logging-support/src/test/java/tech/picnic/logging/PasswordFilteringConverterTest.java                                                 |  2 +-
messaging-support/src/test/java/com/picnic/messaging/ChainableContentHandlerAdaptorTest.java                                          |  2 +-
messaging-support/src/test/java/com/picnic/messaging/amqp/RabbitMQConsumerTest.java                                                   |  2 +-
messaging-support/src/test/java/com/picnic/messaging/amqp/RoutingTemplateTest.java                                                    |  2 +-
mongodb-support/src/test/java/com/picnic/mongo/test/SpringMongoDBTestContainerTest.java                                               |  8 ++++----
rest-support/src/test/java/com/picnic/rest/AbstractRxHttpClientTest.java                                                              |  2 +-
scalyr-support/src/test/java/com/picnic/scalyr/ScalyrServiceIntegrationTest.java                                                      |  2 +-
security-support/security-support-webflux/src/test/java/tech/picnic/security/webflux/PicnicAuthenticationTest.java                    |  2 +-
security-support/security-support-webflux/src/test/java/tech/picnic/security/webflux/PicnicAuthorizationTest.java                     |  2 +-
security-support/security-support-webflux/src/test/java/tech/picnic/security/webflux/SecurityContextPropagatorTest.java               |  2 +-
security-support/security-support-webflux/src/test/java/tech/picnic/security/webflux/access/SecuredReactiveMethodInterceptorTest.java | 10 +++++-----
security-support/security-support-webflux/src/test/java/tech/picnic/security/webflux/webhookkey/WebhookAuthenticationTest.java        |  2 +-
slack-support/src/test/java/com/picnic/slack/client/SlackIntegrationTest.java                                                         |  2 +-
swagger-support/swagger-support-commons/src/test/java/com/picnic/swagger/SchemaGenerationTest.java                                    |  2 +-
swagger-support/swagger-support-webflux/src/test/java/com/picnic/swagger/webflux/SwaggerWebFluxConfigTest.java                        |  2 +-
vault-support/src/test/java/com/picnic/vault/VaultPropertiesTest.java                                                                 |  2 +-
webapp-support/webapp-support-webmvc/src/test/java/tech/picnic/webapp/webmvc/DateTimeRequestParamFormattingTest.java                  |  2 +-
webapp-support/webapp-support-webmvc/src/test/java/tech/picnic/webapp/webmvc/PicnicTraceLoggingInterceptorTest.java                   |  2 +-
webapp-support/webapp-support-webmvc/src/test/java/tech/picnic/webapp/webmvc/RxHttpClientContextPropagationTest.java                  |  2 +-
webapp-support/webapp-support-webmvc/src/test/java/tech/picnic/webapp/webmvc/SwaggerWebMvcConfigTest.java                             |  2 +-
webclient-support/webclient-support-agent/src/test/java/tech/picnic/webclient/WebClientAgentTest.java                                 |  6 +++---
webclient-support/webclient-support-commons/src/test/java/tech/picnic/webclient/ErrorResponseFilterFunctionTest.java                  |  4 ++--
webclient-support/webclient-support-commons/src/test/java/tech/picnic/webclient/LoggingExchangeFilterFunctionTest.java                |  2 +-
webclient-support/webclient-support-commons/src/test/java/tech/picnic/webclient/WebClientConfigTest.java                              |  2 +-
wiw-support/src/test/java/tech/picnic/wiw/WhenIWorkAuthTest.java                                                                      |  2 +-
wiw-support/src/test/java/tech/picnic/wiw/WhenIWorkTest.java                                                                          |  2 +- 
28 files changed, 38 insertions(+), 38 deletions(-)

@Stephan202 Stephan202 force-pushed the anicolasgar/PSM-671 branch from 2440393 to 37208bd Compare January 1, 2021 21:24
Copy link
Member

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased and added a commit. Left a few XXX comments in the code, but I think we can defer those. If you're okay with my changes I'll merge :)

MethodSymbol sym = ASTHelpers.getSymbol(tree);

if (sym == null
|| OVERRIDE_ANNOTATION.matches(tree, state)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we cater for this, should we also omit warnings for public methods in abstract classes?

annotations(AT_LEAST_ONE, isType("java.lang.Override"));

@Override
public Description matchMethod(MethodTree tree, VisitorState state) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not abstract, we can also require the class to be package-private.

Actually we can require that none of the members of such a class are public, and the fields should be private.

Edit: but let's defer that to another PR.

SuggestedFixes.removeModifiers(tree, state, ILLEGAL_MODIFIERS.toArray(Modifier[]::new))
.ifPresent(builder::merge);
/* Remove the 'test' prefix, if possible. */
renameMethod(tree, state, sym.getQualifiedName().toString()).ifPresent(builder::merge);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it's unlikely to cause issues in practice, I guess it'd be more correct to only attempt this for actual test methods; will push a proposal.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing: in theory this could cause a method name clash. Likely not worth the hassle of catering for this, but let's flag it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also thought about the case where the old method name is referred in a JavaDoc, but it doesn't seem to be easy to fix. Anyways, it'd cause a compilation error and it'd be easy to fix it by hand.

@anicolasgar
Copy link
Contributor Author

Rebased and added a commit. Left a few XXX comments in the code, but I think we can defer those. If you're okay with my changes I'll merge :)

Thanks for your feedback @Stephan202 , your changes LGTM :). Added a small commit with some tweaks.

@Stephan202
Copy link
Member

Tnx! Will merge :)

@Stephan202 Stephan202 merged commit a53e497 into master Jan 7, 2021
@Stephan202 Stephan202 deleted the anicolasgar/PSM-671 branch January 7, 2021 21:11
@Stephan202 Stephan202 added this to the 0.1.0 milestone Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants