Make tests more maintainable

This commit is contained in:
Stephan Schroevers
2023-12-23 14:45:57 +01:00
parent 0d960eaa38
commit 6712446146
5 changed files with 7 additions and 20 deletions

View File

@@ -93,9 +93,6 @@ public final class BugPatternExtractor implements Extractor<BugPatternDocumentat
return (T) value;
}
// XXX: Here and below: Test (serialization round trips. And given that the only "production"
// reader of the serialized data is also defined in this package, perhaps we don't need to
// validate the serialized format.
@AutoValue
@JsonDeserialize(as = AutoValue_BugPatternExtractor_BugPatternDocumentation.class)
abstract static class BugPatternDocumentation {

View File

@@ -77,7 +77,7 @@ public final class BugPatternTestExtractor implements Extractor<TestCases> {
"com.google.errorprone.CompilationTestHelper",
"com.google.errorprone.BugCheckerRefactoringTestHelper")
.named("newInstance")
.withParameters("java.lang.Class", "java.lang.Class");
.withParameters(Class.class.getCanonicalName(), Class.class.getCanonicalName());
private static final Matcher<ExpressionTree> IDENTIFICATION_SOURCE_LINES =
instanceMethod()
.onDescendantOf("com.google.errorprone.CompilationTestHelper")
@@ -207,9 +207,6 @@ public final class BugPatternTestExtractor implements Extractor<TestCases> {
}
}
// XXX: Here and below: Test (serialization round trips. And given that the only "production"
// reader of the serialized data is also defined in this package, perhaps we don't need to
// validate the serialized format.
@AutoValue
@JsonDeserialize(as = AutoValue_BugPatternTestExtractor_TestCases.class)
abstract static class TestCases {

View File

@@ -14,8 +14,6 @@ import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import com.fasterxml.jackson.datatype.guava.GuavaModule;
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
import com.github.difflib.DiffUtils;
import com.github.difflib.UnifiedDiffUtils;
import com.github.difflib.patch.Patch;
@@ -51,11 +49,6 @@ import tech.picnic.errorprone.documentation.models.RefasterTemplateTestData;
// XXX: Rename this class. Then also update the reference in `website/.gitignore`.
public final class JekyllCollectionGenerator {
// XXX: Dedup with DocumentationGeneratorTaskListener.
private static final ObjectMapper OBJECT_MAPPER =
new ObjectMapper()
.setVisibility(PropertyAccessor.FIELD, Visibility.ANY)
.registerModules(new GuavaModule(), new ParameterNamesModule());
// XXX: Find a bette name. Also, externalize this.
private static final PathMatcher PATH_MATCHER =
FileSystems.getDefault().getPathMatcher("glob:**/target/docs/*.json");
@@ -100,7 +93,7 @@ public final class JekyllCollectionGenerator {
new ArrayList<>();
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
if (!PATH_MATCHER.matches(file)) {
return FileVisitResult.CONTINUE;
}
@@ -110,12 +103,12 @@ public final class JekyllCollectionGenerator {
// XXX: Alternatively, use polymorphism and let Jackson figure it out.
String fileName = file.getFileName().toString();
if (fileName.startsWith("bugpattern-test")) {
bugPatternTests.add(OBJECT_MAPPER.readValue(file.toFile(), TestCases.class));
bugPatternTests.add(Json.read(file, TestCases.class));
} else if (fileName.startsWith("bugpattern")) {
bugPatterns.add(OBJECT_MAPPER.readValue(file.toFile(), BugPatternDocumentation.class));
bugPatterns.add(Json.read(file, BugPatternDocumentation.class));
} else if (fileName.startsWith("refaster-test")) {
refasterTemplateCollectionTests.add(
OBJECT_MAPPER.readValue(file.toFile(), RefasterTemplateCollectionTestData.class));
Json.read(file, RefasterTemplateCollectionTestData.class));
} else {
// XXX: Handle differently?
throw new IllegalStateException("Unexpected file: " + fileName);

View File

@@ -11,7 +11,7 @@ import com.google.common.collect.ImmutableList;
// XXX: This class is not yet used.
@AutoValue
@JsonDeserialize(as = AutoValue_RefasterTemplateCollectionData.class)
public abstract class RefasterTemplateCollectionData {
abstract class RefasterTemplateCollectionData {
static RefasterTemplateCollectionData create(
String name, String description, String link, ImmutableList<RefasterTemplateData> templates) {
return new AutoValue_RefasterTemplateCollectionData(name, description, link, templates);

View File

@@ -7,7 +7,7 @@ import com.google.errorprone.BugPattern.SeverityLevel;
// XXX: This class is not yet used.
@AutoValue
@JsonDeserialize(as = AutoValue_RefasterTemplateData.class)
public abstract class RefasterTemplateData {
abstract class RefasterTemplateData {
static RefasterTemplateData create(
String name, String description, String link, SeverityLevel severityLevel) {
return new AutoValue_RefasterTemplateData(name, description, link, severityLevel);