Skip to content

Commit

Permalink
Adjust CheckListTest to correctly test deprecated rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Wohops authored and quentin-jaquier-sonarsource committed Sep 23, 2020
1 parent 81e0368 commit 1eb56f1
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions java-checks/src/test/java/org/sonar/java/checks/CheckListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,19 @@ void rules_targeting_tests_should_have_tests_tag() throws Exception {
File metadataFile = new File(metadataURL.toURI());
assertThat(metadataFile).exists();
try (FileReader jsonReader = new FileReader(metadataFile)) {
DummyMetatada metatada = gson.fromJson(jsonReader, DummyMetatada.class);
if (testChecks.contains(cls)) {
assertThat(metatada.tags).as("Rule " + key + " is targeting tests sources and should contain the 'tests' tag.").contains("tests");
} else {
assertThat(metatada.tags).as("Rule " + key + " is targeting main sources and should not contain the 'tests' tag.").doesNotContain("tests");
DummyMetatada metadata = gson.fromJson(jsonReader, DummyMetatada.class);

if (!"deprecated".equals(metadata.status)) {
// deprecated rules usually have no tags
if (testChecks.contains(cls)) {
assertThat(metadata.tags)
.as("Rule " + key + " is targeting tests sources and should contain the 'tests' tag.")
.contains("tests");
} else {
assertThat(metadata.tags)
.as("Rule " + key + " is targeting main sources and should not contain the 'tests' tag.")
.doesNotContain("tests");
}
}
}
}
Expand All @@ -212,6 +220,7 @@ void rules_targeting_tests_should_have_tests_tag() throws Exception {
private static class DummyMetatada {
// ignore all the other fields
String[] tags;
String status;
}

@Test
Expand Down

0 comments on commit 1eb56f1

Please sign in to comment.