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

JavadocMetadataScrapperTest and InlineConfigParser fixes #10827

Merged
merged 2 commits into from Oct 2, 2021

Conversation

rnveach
Copy link
Member

@rnveach rnveach commented Sep 26, 2021

reworks JavadocMetadataScrapperTest to make more sense

Moved all tests related to JavadocMetadataScrapper into JavadocMetadataScrapperTest and use BDD and actually verify outputs from the check. Hopefully, at some point we can use pitest and such on this class to verify it's code.

changes InlineConfigParser to respect fully qualified name

This is a simple change to so that when it gets the fully qualified name, it takes as the fully qualified name and doesn't make any other changes. This is all because JavadocMetadataScrapper doesn't end with Check so BDD can't recognize it. No idea why the class was named this, but BDD should still be changed as I expect the FQN to be the FQN.

@@ -213,10 +227,7 @@ else if (ast.getType() == JavadocTokenTypes.SINCE_LITERAL) {
public void finishJavadocTree(DetailNode rootAst) {
moduleDetails.setDescription(getDescriptionText());
if (isTopLevelClassJavadoc()) {
if (getFileContents().getFileName().contains("test")) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the main reason the property is needed to drop having this code that checks the file name which will cause issues with checks with that word in them. New property always defaults to write.

@@ -603,13 +617,18 @@ private static String getPackageName(String filePath) {
return Collections.unmodifiableMap(MODULE_DETAILS_STORE);
}

/** Reset the module detail store of any previous information. */
public static void resetModuleDetailsStore() {
MODULE_DETAILS_STORE.clear();
Copy link
Member Author

Choose a reason for hiding this comment

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

Tests are writing to a global static field. Nothing ensure this field is cleared, so this reset method is there to ensure the field is cleared.

@@ -234,7 +248,7 @@ public void finishJavadocTree(DetailNode rootAst) {
*
* @param ast javadoc ast
*/
public void scrapeContent(DetailNode ast) {
private void scrapeContent(DetailNode ast) {
Copy link
Member Author

Choose a reason for hiding this comment

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

No reason this method should be public.

/**
* Check if the current javadoc block comment AST corresponds to the top-level class as we
* only want to scrape top-level class javadoc.
*
* @return true if the current AST corresponds to top level class
*/
public boolean isTopLevelClassJavadoc() {
private boolean isTopLevelClassJavadoc() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Same.

}

@Test
public void testPropertyNameWithNoCodeTag() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed test basically got encompassed into the new tests.


assertNull(testCheckMeta.getProperties().get(0).getName(),
"Check with no property name {@code } tag should have null property name");
private static String split(String string, int size) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Split code is to help ensure line does not exceed the 100 character limit.

@rnveach rnveach changed the title Meta tests JavadocMetadataScrapperTest and InlineConfigParser fixes Sep 26, 2021
rnveach added a commit to rnveach/checkstyle that referenced this pull request Sep 26, 2021
rnveach added a commit to rnveach/checkstyle that referenced this pull request Sep 26, 2021
@@ -76,23 +78,18 @@ public static void generate(String... args) throws IOException, CheckstyleExcept
private static void dumpMetadata(Checker checker, String path) throws CheckstyleException,
IOException {
final List<File> validFiles = new ArrayList<>();
if (path.endsWith(".java")) {
validFiles.add(new File(path));
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed testing single files which I assume was only used by UTs. Most of our needs scan folders.

@strkkk strkkk assigned pbludov and unassigned strkkk Sep 29, 2021
@strkkk strkkk requested a review from pbludov September 29, 2021 09:58
@pbludov pbludov assigned rnveach and romani and unassigned pbludov and rnveach Sep 30, 2021
@pbludov pbludov requested a review from romani September 30, 2021 13:12
Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

ok to merge

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

ok to merge

@pbludov pbludov merged commit 9fcd1e0 into checkstyle:master Oct 2, 2021
@rnveach rnveach added this to the 9.1 milestone Oct 2, 2021
@rnveach rnveach deleted the meta_tests branch October 2, 2021 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants