-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add junit test for text fields check #12057
Conversation
…erty.MULTILINE_TEXT properly
…t-test-for-text-fields-check merge upstream main
…rea creation, Check TextInputControl field
…t-test-for-text-fields-check merge upstream changes
There was a problem hiding this 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.
There was a problem hiding this 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.
There was a problem hiding this 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".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small comments, otherwise, looks OK.
* b) Has an EditorTextArea object creation | ||
*/ | ||
@Test | ||
public void fieldEditorTextAreaTest() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More self-descriptive test name please. I think fieldEditorsMatchMultilineProperty
could be a good name.
*/ | ||
@Test | ||
public void fieldEditorTextAreaTest() throws IOException { | ||
// get all field editors and their properties in FieldEditors.java |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this comment - it is exactly the method name (which is good)
|
||
CompilationUnit cu = PARSER.parse(filePath).getResult().orElse(null); | ||
if (cu == null) { | ||
throw new RuntimeException("Failed to analyze " + filePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No RuntimeExeption
s in tests. Use normal Exception
s. And use throws
clause.
NullPointerExceptions are also OK.
The text Failed to analyze
is too generic. Is it because of a logic issue? The NullPointerException
is more specific than a general failure
|
||
try { | ||
CompilationUnit cu = PARSER.parse(Paths.get(filePath)).getResult().orElse(null); | ||
if (cu == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above
} catch (IOException e) { | ||
LOGGER.log(Level.SEVERE, "Error parsing file: " + filePath, e); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are crafting a JUnit test - just let exceptions flow - no need to handle or log them.
However, it is green now. What do you mean by "unreliable".
No. Please keep as is. The statement
We can do as follow up. |
2. Rename the test method and file. 3. Use normal exceptions 4. Remove logger
I noticed that the holdEditorTextField method appears to be unused within the codebase. Should we consider removing it to simplify the code and improve maintainability? Unless there’s a planned usage or if it’s reserved for future features, removing unused methods could help keep the code clean and focused. |
It feels somewhat fragile since the check relies heavily on the current structure of |
I think we could keep it for now, as it might be useful once we can specifically check whether the FieldEditor should use a TextField. |
Then, we can delete it. You can add a JavaDoc to the text just stating your text. You can be stronger: "This test is somewhat fragile ..." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add JavaDoc (see above) and small indent fix.
2. Optimize indentation and some comments
Closes #11939
This is an approach try to test if
FieldEditor
has the appropriate usage ofTextArea
orTextField
by using Java Parser to analyzeFieldEditors.java
. However, there are currently many limitations.This test does the following:
if
statements inFieldEditors.getForField
and create a map..java
file path of theFieldEditor
class (for example:src/.../UrlEditor.java
)FieldProperties
by analyzing theif
statement conditions (for example:[FieldProperty.EXTERNAL]
)properties
includeFieldProperty.MULTILINE_TEXT
, then perform the following tests:FieldEditorFX
and calls theestablishBinding
method, get the name of the first parameter.TextInputControl
.EditorTextArea
creation in this class.Limitations:
EditorTextField
field correctly because we cannot determine if theFieldEditor
class has multiple lines fromFieldEditors.java
. For example, thePersonsEditor
should be able to useTextArea
, but fromFieldEditors.java
we can't determine if thePersonEditor
will have theMULTILINE_TEXT
property. In fact, none of theseFieldEditor
classes can be determined to have theMULTILINE_TEXT
property if we only analyzeFieldEditors.java
.Suggestions:
final boolean isMultiLine
but instead check if thefield
parameter holds theMULTILINE_TEXT
property.TextArea
orTextField
).Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if applicable)