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

Add junit test for text fields check #12057

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

ShunL12324
Copy link

Closes #11939

This is an approach try to test if FieldEditor has the appropriate usage of TextArea or TextField by using Java Parser to analyze FieldEditors.java. However, there are currently many limitations.

This test does the following:

  • Step one: Use Java Parser to analyze all if statements in FieldEditors.getForField and create a map.
    • The key: The .java file path of the FieldEditor class (for example: src/.../UrlEditor.java)
    • The value: The possible FieldProperties by analyzing the if statement conditions (for example: [FieldProperty.EXTERNAL])
  • Step two: Analyze each entry. If the properties include FieldProperty.MULTILINE_TEXT, then perform the following tests:
    • Since the class implements FieldEditorFX and calls the establishBinding method, get the name of the first parameter.
    • Check the corresponding field declaration to see if the field is an instance of TextInputControl.
    • If yes, check if there is an EditorTextArea creation in this class.

Limitations:

  • We cannot test if the class uses an EditorTextField field correctly because we cannot determine if the FieldEditor class has multiple lines from FieldEditors.java. For example, the PersonsEditor should be able to use TextArea, but from FieldEditors.java we can't determine if the PersonEditor will have the MULTILINE_TEXT property. In fact, none of these FieldEditor classes can be determined to have the MULTILINE_TEXT property if we only analyze FieldEditors.java.
  • This test seems to be unreliable and not robust, but I have no other way to do it.

Suggestions:

  • I think we should change the design first. We should not use the parameter final boolean isMultiLine but instead check if the field parameter holds the MULTILINE_TEXT property.
  • Maybe use a field to mark if this editor can be multi-line, then check if it holds the correct GUI component (TextArea or TextField).
  • At this moment, maybe just add some comments or documentation?

Mandatory checks

  • I own the copyright of the code submitted and I licence it under the MIT license
  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.

You can check review dog's comments at the tab "Files changed" of your pull request.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Your code currently does not meet JabRef's code guidelines.
We use Checkstyle to identify issues.
The tool reviewdog already placed comments on GitHub to indicate the places. See the tab "Files" in you PR.
Please carefully follow the setup guide for the codestyle.
Afterwards, please run checkstyle locally and fix the issues.

You can check review dog's comments at the tab "Files changed" of your pull request.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Your code currently does not meet JabRef's code guidelines.
We use OpenRewrite to ensure "modern" Java coding practices.
The issues found can be automatically fixed.
Please execute the gradle task rewriteRun, check the results, commit, and push.

You can check the detailed error output by navigating to your pull request, selecting the tab "Checks", section "Tests" (on the left), subsection "OpenRewrite".

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.

Consistency check for text fields
2 participants