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

polish #532

Merged
merged 7 commits into from
Jan 4, 2025
Merged

polish #532

merged 7 commits into from
Jan 4, 2025

Conversation

livk-cloud
Copy link
Owner

@livk-cloud livk-cloud commented Jan 4, 2025

Summary by Sourcery

重构测试以使用 ApplicationContextRunner 和 WebApplicationContextRunner。

测试:

  • 在 SpringContextHolderTest、SpringExpressionResolverTest、AnnotationMetadataResolverTest 和 AviatorExpressionResolverTest 中使用 ApplicationContextRunner。
  • 在 SpringHttpTest 中使用 WebApplicationContextRunner。
  • 改进 StudentControllerTest、RestAppTest、UserControllerTest、AuthServerAppTest、InfoMvcControllerTest、ShopControllerTest、HttpControllerTest、DocControllerTest 和 UserControllerTest 中的测试断言。
Original summary in English

Summary by Sourcery

Refactor tests to use ApplicationContextRunner and WebApplicationContextRunner.

Tests:

  • Use ApplicationContextRunner in SpringContextHolderTest, SpringExpressionResolverTest, AnnotationMetadataResolverTest, and AviatorExpressionResolverTest.
  • Use WebApplicationContextRunner in SpringHttpTest.
  • Improve test assertions in StudentControllerTest, RestAppTest, UserControllerTest, AuthServerAppTest, InfoMvcControllerTest, ShopControllerTest, HttpControllerTest, DocControllerTest, and UserControllerTest.

测试:

  • 在 SpringContextHolderTest、SpringExpressionResolverTest、AnnotationMetadataResolverTest 和 AviatorExpressionResolverTest 中使用 ApplicationContextRunner。
  • 在 SpringHttpTest 中使用 WebApplicationContextRunner。
Original summary in English

Summary by Sourcery

重构测试以使用 ApplicationContextRunner 和 WebApplicationContextRunner。

测试:

  • 在 SpringContextHolderTest、SpringExpressionResolverTest、AnnotationMetadataResolverTest 和 AviatorExpressionResolverTest 中使用 ApplicationContextRunner。
  • 在 SpringHttpTest 中使用 WebApplicationContextRunner。
  • 改进 StudentControllerTest、RestAppTest、UserControllerTest、AuthServerAppTest、InfoMvcControllerTest、ShopControllerTest、HttpControllerTest、DocControllerTest 和 UserControllerTest 中的测试断言。
Original summary in English

Summary by Sourcery

Refactor tests to use ApplicationContextRunner and WebApplicationContextRunner.

Tests:

  • Use ApplicationContextRunner in SpringContextHolderTest, SpringExpressionResolverTest, AnnotationMetadataResolverTest, and AviatorExpressionResolverTest.
  • Use WebApplicationContextRunner in SpringHttpTest.
  • Improve test assertions in StudentControllerTest, RestAppTest, UserControllerTest, AuthServerAppTest, InfoMvcControllerTest, ShopControllerTest, HttpControllerTest, DocControllerTest, and UserControllerTest.

Copy link

sourcery-ai bot commented Jan 4, 2025

审阅者指南 by Sourcery

此拉取请求重构了多个测试类,以使用 ApplicationContextRunnerWebApplicationContextRunner 来改进测试设置和执行。

上下文接口变更的类图

classDiagram
    class Context {
      <<interface>>
      +create(Map~String,?~ map)$ Context
      +putAll(Map~String,?~ m)* Context
      +put(String key, Object value)* Context
      +asMap() Map~String,Object~
    }
    class ContextImpl {
      -Map~String,Object~ variables
      +put(String key, Object value) Context
      +putAll(Map~String,?~ m) Context
      +asMap() Map~String,Object~
    }
    Context <|.. ContextImpl
    note for Context "更改为密封接口"
    note for ContextImpl "更改为非密封类"
Loading

文件级变更

变更 详情 文件
在涉及 Spring 上下文的测试中使用 ApplicationContextRunner
  • @SpringBootTest 注解替换为 ApplicationContextRunner
  • 使用必要的属性和 bean 初始化 ApplicationContextRunner
  • contextRunner.run() 方法中包装测试逻辑以进行上下文管理。
spring-extension-commons/src/test/java/com/livk/commons/SpringContextHolderTest.java
spring-extension-commons/src/test/java/com/livk/commons/expression/spring/SpringExpressionResolverTest.java
spring-extension-commons/src/test/java/com/livk/commons/util/AnnotationMetadataResolverTest.java
spring-extension-commons/src/test/java/com/livk/commons/expression/aviator/AviatorExpressionResolverTest.java
在 Spring Web 测试中使用 WebApplicationContextRunner
  • @SpringBootTest 注解替换为 WebApplicationContextRunner
  • 使用 Servlet Web 应用程序类型和必要配置初始化 WebApplicationContextRunner
  • 使用 withUserConfiguration 包含所需的测试配置。
  • contextRunner.run() 方法中使用 context.getBean() 访问 bean。
spring-extension-commons/src/test/java/com/livk/commons/http/SpringHttpTest.java
重构上下文创建和合并逻辑
  • Context 接口更改为密封接口。
  • 为合并上下文映射添加默认实现。
  • ContextFactoryAbstractExpressionResolver 中弃用现有的合并方法。
  • 更新 Context 实现以返回 Context 实例以支持方法链。
  • 为已弃用的方法在 ExpressionResolver 中添加默认方法。
spring-extension-commons/src/main/java/com/livk/commons/expression/Context.java
spring-extension-commons/src/main/java/com/livk/commons/expression/ContextFactory.java
spring-extension-commons/src/main/java/com/livk/commons/expression/AbstractExpressionResolver.java
spring-extension-commons/src/main/java/com/livk/commons/expression/ExpressionResolver.java
更新测试断言以进行更具体的检查
  • 将通用的 JSON 路径存在性检查替换为使用 .value() 的具体值断言。
spring-boot-extension-tests/redis-spring-boot-test/redisearch-spring-boot-test/redisearch-spring-boot-test-webmvc/src/test/java/com/livk/redisearch/mvc/controller/StudentControllerTest.java
spring-boot-example/spring-data-rest/src/test/java/com/livk/rest/RestAppTest.java
spring-boot-extension-tests/mapstruct-spring-boot-test/src/test/java/com/livk/mapstruct/controller/UserControllerTest.java
spring-boot-example/spring-crypto/spring-crypto-mvc/src/test/java/com/livk/crypto/mvc/controller/InfoMvcControllerTest.java
spring-boot-extension-tests/mybatis-extension-boot-test/mybatis-inject-monitor-boot-test/src/test/java/com/livk/mybatisplugins/controller/UserControllerTest.java
spring-boot-extension-tests/http-spring-boot-test/src/test/java/com/livk/http/controller/HttpControllerTest.java
spring-boot-example/spring-doc/spring-doc-mvc/src/test/java/com/livk/doc/mvc/controller/DocControllerTest.java
spring-boot-example/spring-security/security-sso/sso-auth/src/test/java/com/livk/sso/auth/controller/UserControllerTest.java
spring-boot-extension-tests/distributed-lock-boot-test/curator-lock-boot-test/src/test/java/com/livk/curator/lock/ShopControllerTest.java
spring-boot-extension-tests/distributed-lock-boot-test/redisson-lock-boot-test/src/test/java/com/livk/redisson/lock/ShopControllerTest.java
删除未使用的类和资源
  • 删除未使用的 additional-spring-configuration-metadata.json 文件。
  • 删除未使用的 SpringBootMain 测试类。
  • RedissonPropertyEditorRegistrar 设为 final。
  • AnnotationBasePackageSupportTest 中删除 @SpringBootTest 并引入嵌套的 @TestConfiguration
spring-extension-commons/src/main/resources/META-INF/additional-spring-configuration-metadata.json
spring-extension-commons/src/test/java/com/livk/commons/SpringBootMain.java
spring-boot-extension-autoconfigure/src/main/java/com/livk/autoconfigure/redisson/RedissonPropertyEditorRegistrar.java
spring-extension-commons/src/test/java/com/livk/commons/spring/AnnotationBasePackageSupportTest.java
重构 ContextFactory 的测试
  • 在测试方法中为不同的上下文创建场景添加单独的代码块。
spring-extension-commons/src/test/java/com/livk/commons/expression/ContextFactoryTest.java

提示和命令

与 Sourcery 交互

  • 触发新的审阅: 在拉取请求中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 从审阅评论生成 GitHub 问题: 通过回复审阅评论,要求 Sourcery 创建一个问题。
  • 生成拉取请求标题: 在拉取请求标题的任何位置写 @sourcery-ai 以随时生成标题。
  • 生成拉取请求摘要: 在拉取请求正文的任何位置写 @sourcery-ai summary 以随时生成 PR 摘要。您还可以使用此命令指定摘要的插入位置。

自定义您的体验

访问您的仪表板以:

  • 启用或禁用审阅功能,如 Sourcery 生成的拉取请求摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、删除或编辑自定义审阅说明。
  • 调整其他审阅设置。

获取帮助

Original review guide in English

Reviewer's Guide by Sourcery

This pull request refactors several test classes to use ApplicationContextRunner and WebApplicationContextRunner for improved test setup and execution.

Class diagram for Context interface changes

classDiagram
    class Context {
      <<interface>>
      +create(Map~String,?~ map)$ Context
      +putAll(Map~String,?~ m)* Context
      +put(String key, Object value)* Context
      +asMap() Map~String,Object~
    }
    class ContextImpl {
      -Map~String,Object~ variables
      +put(String key, Object value) Context
      +putAll(Map~String,?~ m) Context
      +asMap() Map~String,Object~
    }
    Context <|.. ContextImpl
    note for Context "Changed to sealed interface"
    note for ContextImpl "Changed to non-sealed class"
Loading

File-Level Changes

Change Details Files
Use ApplicationContextRunner for tests involving Spring context
  • Replaced @SpringBootTest annotation with ApplicationContextRunner.
  • Initialized ApplicationContextRunner with necessary properties and beans.
  • Wrapped test logic within contextRunner.run() method for context management.
spring-extension-commons/src/test/java/com/livk/commons/SpringContextHolderTest.java
spring-extension-commons/src/test/java/com/livk/commons/expression/spring/SpringExpressionResolverTest.java
spring-extension-commons/src/test/java/com/livk/commons/util/AnnotationMetadataResolverTest.java
spring-extension-commons/src/test/java/com/livk/commons/expression/aviator/AviatorExpressionResolverTest.java
Use WebApplicationContextRunner for Spring web tests
  • Replaced @SpringBootTest annotation with WebApplicationContextRunner.
  • Initialized WebApplicationContextRunner with servlet web application type and necessary configurations.
  • Used withUserConfiguration to include required test configurations.
  • Accessed beans from the context using context.getBean() within contextRunner.run() method.
spring-extension-commons/src/test/java/com/livk/commons/http/SpringHttpTest.java
Refactor Context creation and merging logic
  • Changed Context interface to a sealed interface.
  • Added default implementation for merging context maps.
  • Deprecated existing merge methods in ContextFactory and AbstractExpressionResolver.
  • Updated Context implementation to return Context instance for method chaining.
  • Added default methods to ExpressionResolver for deprecated methods.
spring-extension-commons/src/main/java/com/livk/commons/expression/Context.java
spring-extension-commons/src/main/java/com/livk/commons/expression/ContextFactory.java
spring-extension-commons/src/main/java/com/livk/commons/expression/AbstractExpressionResolver.java
spring-extension-commons/src/main/java/com/livk/commons/expression/ExpressionResolver.java
Update test assertions for more specific checks
  • Replaced general JSON path existence checks with specific value assertions using .value().
spring-boot-extension-tests/redis-spring-boot-test/redisearch-spring-boot-test/redisearch-spring-boot-test-webmvc/src/test/java/com/livk/redisearch/mvc/controller/StudentControllerTest.java
spring-boot-example/spring-data-rest/src/test/java/com/livk/rest/RestAppTest.java
spring-boot-extension-tests/mapstruct-spring-boot-test/src/test/java/com/livk/mapstruct/controller/UserControllerTest.java
spring-boot-example/spring-crypto/spring-crypto-mvc/src/test/java/com/livk/crypto/mvc/controller/InfoMvcControllerTest.java
spring-boot-extension-tests/mybatis-extension-boot-test/mybatis-inject-monitor-boot-test/src/test/java/com/livk/mybatisplugins/controller/UserControllerTest.java
spring-boot-extension-tests/http-spring-boot-test/src/test/java/com/livk/http/controller/HttpControllerTest.java
spring-boot-example/spring-doc/spring-doc-mvc/src/test/java/com/livk/doc/mvc/controller/DocControllerTest.java
spring-boot-example/spring-security/security-sso/sso-auth/src/test/java/com/livk/sso/auth/controller/UserControllerTest.java
spring-boot-extension-tests/distributed-lock-boot-test/curator-lock-boot-test/src/test/java/com/livk/curator/lock/ShopControllerTest.java
spring-boot-extension-tests/distributed-lock-boot-test/redisson-lock-boot-test/src/test/java/com/livk/redisson/lock/ShopControllerTest.java
Remove unused classes and resources
  • Removed unused additional-spring-configuration-metadata.json file.
  • Removed unused SpringBootMain test class.
  • Made RedissonPropertyEditorRegistrar final.
  • Removed @SpringBootTest from AnnotationBasePackageSupportTest and introduced nested @TestConfiguration.
spring-extension-commons/src/main/resources/META-INF/additional-spring-configuration-metadata.json
spring-extension-commons/src/test/java/com/livk/commons/SpringBootMain.java
spring-boot-extension-autoconfigure/src/main/java/com/livk/autoconfigure/redisson/RedissonPropertyEditorRegistrar.java
spring-extension-commons/src/test/java/com/livk/commons/spring/AnnotationBasePackageSupportTest.java
Refactor test for ContextFactory
  • Added separate blocks for different context creation scenarios within the test method.
spring-extension-commons/src/test/java/com/livk/commons/expression/ContextFactoryTest.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

@livk-cloud - 我已经审查了你的更改,看起来非常棒!

以下是我在审查期间关注的内容
  • 🟢 一般性问题:一切看起来都很好
  • 🟢 安全性:一切看起来都很好
  • 🟢 测试:一切看起来都很好
  • 🟢 复杂性:一切看起来都很好
  • 🟢 文档:一切看起来都很好

Sourcery 对开源项目是免费的 - 如果你喜欢我们的评论,请考虑分享 ✨
帮助我变得更有用!请在每条评论上点击 👍 或 👎,我将使用这些反馈来改进你的评论。
Original comment in English

Hey @livk-cloud - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

sonarqubecloud bot commented Jan 4, 2025

@livk-cloud
Copy link
Owner Author

@sourcery-ai review

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

@livk-cloud - 我已经审查了你的更改,看起来非常棒!

以下是我在审查期间关注的内容
  • 🟢 一般性问题:一切看起来都很好
  • 🟢 安全性:一切看起来都很好
  • 🟢 测试:一切看起来都很好
  • 🟢 复杂性:一切看起来都很好
  • 🟢 文档:一切看起来都很好

Sourcery 对开源项目是免费的 - 如果你喜欢我们的评论,请考虑分享 ✨
帮助我变得更有用!请在每条评论上点击 👍 或 👎,我将使用这些反馈来改进你的评论。
Original comment in English

Hey @livk-cloud - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@livk-cloud livk-cloud merged commit 7b8e86a into main Jan 4, 2025
15 checks passed
@livk-cloud livk-cloud deleted the refactor-dev branch January 4, 2025 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant