From 1eb56f1dc616bc0c52994040288593bc0170136f Mon Sep 17 00:00:00 2001 From: Michael Gumowski Date: Wed, 23 Sep 2020 10:07:00 +0200 Subject: [PATCH] Adjust CheckListTest to correctly test deprecated rules --- .../org/sonar/java/checks/CheckListTest.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/java-checks/src/test/java/org/sonar/java/checks/CheckListTest.java b/java-checks/src/test/java/org/sonar/java/checks/CheckListTest.java index a4cf55fd653..7e1c60adcfc 100644 --- a/java-checks/src/test/java/org/sonar/java/checks/CheckListTest.java +++ b/java-checks/src/test/java/org/sonar/java/checks/CheckListTest.java @@ -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"); + } } } } @@ -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