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

chore(java): write tests for most of the JavaIconProvider #146

Merged
merged 5 commits into from
Nov 20, 2024

Conversation

thelooter
Copy link
Collaborator

Warning

This PR depends on #145 getting merged before

Description

This PR introduces the following changes:

  1. Added a new run configuration for running tests on the plugin project.
  2. Updated the Gradle dependencies to include the Mockito Kotlin library for testing.
  3. Added an internal getVisibilityIconForTesting method in the JavaIconProvider class to allow accessing the getVisibilityIcon method for unit testing purposes.
  4. Added unit tests for the JavaIconProvider class to cover various scenarios for icon provision, including:
    • Testing visibility icon provision for different access modifiers (public, private, protected, package-private)
    • Handling cases where the requested element is not a PsiClass or the file is not a Java file
    • Testing the behavior when Java support is disabled in the plugin settings

Motivation and Context

The main goal of this PR is to improve the testability of the JavaIconProvider class in the Catppuccin JetBrains Icons plugin. The previous implementation did not provide a way to directly test the getVisibilityIcon method, which is an important part of the icon provision logic.

By adding the internal getVisibilityIconForTesting method and creating a comprehensive set of unit tests, we can ensure that the visibility icon provision works as expected, which will improve the overall reliability and maintainability of the plugin.

How Has This Been Tested?

This PR includes a new test suite for the JavaIconProvider class, which covers the various scenarios mentioned in the description. The tests ensure that the visibility icon provision logic works as expected for different access modifiers.

Checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed.

@thelooter thelooter added the enhancement New feature or request label Nov 8, 2024
@thelooter thelooter self-assigned this Nov 8, 2024
@sgoudham
Copy link
Contributor

sgoudham commented Nov 8, 2024

Added an internal getVisibilityIconForTesting method in the JavaIconProvider class to allow accessing the getVisibilityIcon method for unit testing purposes.

Afaik, this is a bit of an anti-pattern when you create methods just for testing purposes in your production code. Does Kotlin not have visibility levels similar to Java?

@thelooter thelooter changed the title feat(detekt): add detekt for static analysis and fix issues chore(java): write tests for most of the JavaIconProvider Nov 8, 2024
@thelooter
Copy link
Collaborator Author

Added an internal getVisibilityIconForTesting method in the JavaIconProvider class to allow accessing the getVisibilityIcon method for unit testing purposes.

Afaik, this is a bit of an anti-pattern when you create methods just for testing purposes in your production code. Does Kotlin not have visibility levels similar to Java?

fixed

The test case for class with no modifier list is removed along with the mockito-kotlin dependency since it's no longer needed in the test suite.
.run/Test Plugin.run.xml Outdated Show resolved Hide resolved
Copy link
Contributor

@kjnsn kjnsn left a comment

Choose a reason for hiding this comment

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

Please tidy up test descriptions ("Test" is redundant), and test method names

@thelooter thelooter requested a review from kjnsn November 19, 2024 12:09
@thelooter thelooter merged commit 50813c1 into main Nov 20, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants