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

Make BugPattern{,Test}Extractor tests more maintainable #937

Merged
merged 2 commits into from
Jan 10, 2024

Conversation

Stephan202
Copy link
Member

@Stephan202 Stephan202 commented Dec 23, 2023

These change are backported from the website branch.

Suggested commit message:

Make `BugPattern{,Test}Extractor` tests more maintainable (#937)

As we're moving to a Java-based website generator located in the same
package as the `Extractor` implementations, there is no need to validate
the exact format of generated files; only that the data can be
deserialized again.

While there, track the source file from which data is extracted.

@Stephan202 Stephan202 added this to the 0.15.0 milestone Dec 23, 2023
Copy link

  • Surviving mutants in this change: 5
  • Killed mutants in this change: 12
class surviving killed
🧟tech.picnic.errorprone.documentation.Json 3 2
🧟tech.picnic.errorprone.documentation.BugPatternTestExtractor$ReplacementTestEntry 1 2
🧟tech.picnic.errorprone.documentation.BugPatternTestExtractor$IdentificationTestEntry 1 2
🎉tech.picnic.errorprone.documentation.BugPatternExtractor$BugPatternDocumentation 0 1
🎉tech.picnic.errorprone.documentation.BugPatternTestExtractor$TestCases 0 1
🎉tech.picnic.errorprone.documentation.DocumentationGeneratorTaskListener 0 3
🎉tech.picnic.errorprone.documentation.BugPatternTestExtractor$TestCase 0 1

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member Author

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

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

Some context.

Comment on lines +99 to +123
static BugPatternDocumentation create(
URI source,
String fullyQualifiedName,
String name,
ImmutableList<String> altNames,
String link,
ImmutableList<String> tags,
String summary,
String explanation,
SeverityLevel severityLevel,
boolean canDisable,
ImmutableList<String> suppressionAnnotations) {
return new AutoValue_BugPatternExtractor_BugPatternDocumentation(
source,
fullyQualifiedName,
name,
altNames,
link,
tags,
summary,
explanation,
severityLevel,
canDisable,
suppressionAnnotations);
}
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 boilerplate, but Error Prone flags new AutoValue_BugPatternExtractor_BugPatternDocumentation (and similar) calls outside the class in which the immutable type is defined.

Comment on lines +13 to +21
/**
* Utility class that offers mutually consistent JSON serialization and deserialization operations,
* without further specifying the exact schema used.
*/
final class Json {
private static final ObjectMapper OBJECT_MAPPER =
new ObjectMapper()
.setVisibility(PropertyAccessor.FIELD, Visibility.ANY)
.registerModules(new GuavaModule(), new ParameterNamesModule());
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 logic is moved to a separate class, not only because the tests use it, but also because other yet-to-backported code relies on it.

Comment on lines +46 to +57
BugPatternDocumentation.create(
URI.create("file:///MinimalBugChecker.java"),
"pkg.MinimalBugChecker",
"MinimalBugChecker",
ImmutableList.of(),
"",
ImmutableList.of(),
"MinimalBugChecker summary",
"",
ERROR,
/* canDisable= */ true,
ImmutableList.of(SuppressWarnings.class.getCanonicalName())));
Copy link
Member Author

Choose a reason for hiding this comment

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

Here and below: these objects replace the JSON resource files.

Copy link
Contributor

@mohamedsamehsalah mohamedsamehsalah left a comment

Choose a reason for hiding this comment

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

Nothing stands out to me 🚀

Only one comment about field order, but I am fine as-is ✅

Copy link
Member Author

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

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

Tnx for the quick review @mohamedsamehsalah! 🚀

I added one more commit, as I forgot to include a test class.

Copy link

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 15
class surviving killed
🧟tech.picnic.errorprone.documentation.BugPatternTestExtractor$ReplacementTestEntry 1 2
🧟tech.picnic.errorprone.documentation.BugPatternTestExtractor$IdentificationTestEntry 1 2
🎉tech.picnic.errorprone.documentation.BugPatternExtractor$BugPatternDocumentation 0 1
🎉tech.picnic.errorprone.documentation.BugPatternTestExtractor$TestCases 0 1
🎉tech.picnic.errorprone.documentation.Json 0 5
🎉tech.picnic.errorprone.documentation.DocumentationGeneratorTaskListener 0 3
🎉tech.picnic.errorprone.documentation.BugPatternTestExtractor$TestCase 0 1

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@Stephan202 Stephan202 added the chore A task not related to code (build, formatting, process, ...) label Dec 24, 2023
Copy link
Member

@rickie rickie left a comment

Choose a reason for hiding this comment

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

💯

}

@FormatMethod
private static UncheckedIOException failure(IOException cause, String format, Object... args) {
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to have the same ordering as creating the exception, so having cause last?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, Java requires that the varargs argument is last (to avoid ambiguity). :)

Copy link
Member

Choose a reason for hiding this comment

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

😂 oh ofcourse, forgot that. Let's merge!

As we're moving to a Java-based website generator located in the same
package as the `Extractor` implementations, there is no need to validate
the exact format of generated files; only that the data can be
deserialized again.

While there, track the source file from which data is extracted.
@rickie rickie force-pushed the sschroevers/bugpattern-data-extrator-improvements branch from 56833db to 9a0ad2b Compare January 10, 2024 08:26
Copy link

sonarcloud bot commented Jan 10, 2024

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

1 New issue
0 Security Hotspots
100.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 15
class surviving killed
🧟tech.picnic.errorprone.documentation.BugPatternTestExtractor$ReplacementTestEntry 1 2
🧟tech.picnic.errorprone.documentation.BugPatternTestExtractor$IdentificationTestEntry 1 2
🎉tech.picnic.errorprone.documentation.BugPatternExtractor$BugPatternDocumentation 0 1
🎉tech.picnic.errorprone.documentation.BugPatternTestExtractor$TestCases 0 1
🎉tech.picnic.errorprone.documentation.Json 0 5
🎉tech.picnic.errorprone.documentation.DocumentationGeneratorTaskListener 0 3
🎉tech.picnic.errorprone.documentation.BugPatternTestExtractor$TestCase 0 1

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@rickie rickie merged commit fbd9b06 into master Jan 10, 2024
16 checks passed
@rickie rickie deleted the sschroevers/bugpattern-data-extrator-improvements branch January 10, 2024 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore A task not related to code (build, formatting, process, ...)
Development

Successfully merging this pull request may close these issues.

None yet

3 participants