Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The changes in this diff introduce several improvements to the codeba…
…se, primarily focusing on code style, efficiency, and using Kotlin idioms more effectively. Let's break down the changes file by file: **api/src/main/kotlin/app/utils/AppUtils.kt:** * **Import Optimization:** The import for `StringUtils.stripAccents` is changed to a direct import of `stripAccents`, reducing unnecessary namespace qualification. This is a minor change but improves readability. * **Kotlin Idiomatic `toJson`:** The `toJson` extension property is rewritten using `run`, making the code more concise and idiomatic Kotlin. * **Direct `stripAccents` Call:** Similar to the import change, the call to `StringUtils.stripAccents` within `nameToLogin` is simplified to a direct call to `stripAccents`. **api/src/test/kotlin/users/TestTools.kt:** * **Import Optimization:** Several wildcard imports are replaced with explicit imports, which is generally considered better practice for readability and avoiding potential naming conflicts. * **Assertions:** The `Assertions` class from AssertJ is now used with direct function calls like `assertThat` instead of qualifying each assertion with `Assertions.assertThat`. This simplifies the assertions and makes the test code more readable. * **Kotlin Idioms:** The code uses Kotlin idioms like `apply`, `let`, `run`, and `repeat` where appropriate, leading to more concise and expressive code. For example, the `equalsVerifier` function utilizes `apply` effectively to scope the instance and avoid repetition. **api/src/test/kotlin/users/ServiceTests.kt:** * **Suppress Warning:** The `RedundantUnitReturnType` warning suppression is added. This suggests that some functions that explicitly declared a `Unit` return type have been simplified to omit the redundant declaration. This aligns with Kotlin's best practices. * **Constant Imports:** Constants from the `Constants` object, like `DEVELOPMENT`, `PRODUCTION`, and `STARTUP_LOG_MSG_KEY`, are now imported directly, improving code clarity. * **Injection:** The `@Autowired` annotation is replaced with `@Inject`, which is generally recommended for constructor injection in Kotlin. * **Lateinit var and ObjectMapper:** The `mapper` and `validator` properties are removed. `mapper` is now acquired directly within the `check toJson build a valid json format` test, using `context.getBean<ObjectMapper>()`. This makes the dependency explicit where it's used and potentially avoids unnecessary instantiation if the test isn't run. `validator` isn't used in the provided diff. * **Simplified String Building:** The string building in the `ConfigurationsTests - MessageSource test message startupLog` test is made slightly more concise using string templates. * **Kotlin Idioms:** Similar to `TestTools.kt`, Kotlin idioms like `run` and `let` are used to improve code conciseness and readability, particularly within test functions. * **Data Class usage:** `OFFICIAL_SITE` from `TestUtils.Data` replaces the direct string reference, suggesting better organization of test data. * **Removal of Unused Imports and Locale Usage:** Unnecessary imports are removed, and the explicit `Locale.getDefault()` call is simplified to `getDefault()`, further improving code cleanliness. Overall, these changes represent good refactoring work, making the code more readable, efficient, and idiomatic. The changes leverage Kotlin's features effectively and adhere to best practices. The removal of seemingly unused variables and simplification of dependencies indicate a focus on cleaner code and potential performance gains.
- Loading branch information