From 17f0bda3c79316d60817d5a65a23c93aea8d849a Mon Sep 17 00:00:00 2001
From: Sander Ploegsma <sanderploegsma@gmail.com>
Date: Sun, 21 Jan 2024 20:34:08 +0100
Subject: [PATCH] Convert Leap analyzer unit tests to golden tests

---
 bin/run-tests.sh                              | 10 ++--
 .../exercises/leap/LeapAnalyzerTest.java      | 51 -------------------
 .../analyzer/exercises/leap/UsesJavaTime.java |  7 ---
 .../hard-coded-test-cases/.meta/config.json   | 29 +++++++++++
 .../expected_analysis.json                    | 14 +++++
 .../expected_tags.json                        |  0
 .../src/main/java/Leap.java                   |  0
 tests/leap/optimal-solution/.meta/config.json | 29 +++++++++++
 .../optimal-solution/expected_analysis.json   |  1 +
 .../leap/optimal-solution/expected_tags.json  |  1 +
 .../optimal-solution/src/main/java/Leap.java  |  0
 .../.meta/config.json                         | 29 +++++++++++
 .../expected_analysis.json                    |  0
 .../expected_tags.json                        |  1 +
 .../src/main/java/Leap.java                   |  0
 .../using-if-statements/.meta/config.json     | 29 +++++++++++
 .../expected_analysis.json                    | 10 ++++
 .../using-if-statements/expected_tags.json    |  1 +
 .../src/main/java/Leap.java                   |  0
 tests/leap/using-java-time/.meta/config.json  | 29 +++++++++++
 .../using-java-time/expected_analysis.json    | 10 ++++
 tests/leap/using-java-time/expected_tags.json |  1 +
 .../src/main/java/Leap.java                   |  0
 tests/leap/using-ternary/.meta/config.json    | 29 +++++++++++
 .../leap/using-ternary/expected_analysis.json | 10 ++++
 tests/leap/using-ternary/expected_tags.json   |  1 +
 .../using-ternary/src/main/java/Leap.java     |  0
 .../using-too-many-checks/.meta/config.json   | 29 +++++++++++
 .../expected_analysis.json                    | 10 ++++
 .../using-too-many-checks/expected_tags.json  |  1 +
 .../src/main/java/Leap.java                   |  0
 31 files changed, 269 insertions(+), 63 deletions(-)
 delete mode 100644 src/test/java/analyzer/exercises/leap/LeapAnalyzerTest.java
 delete mode 100644 src/test/resources/analyzer/exercises/leap/UsesJavaTime.java
 create mode 100644 tests/leap/hard-coded-test-cases/.meta/config.json
 create mode 100644 tests/leap/hard-coded-test-cases/expected_analysis.json
 rename tests/leap/{ => hard-coded-test-cases}/expected_tags.json (100%)
 rename src/test/resources/analyzer/exercises/leap/HardCodedTestCases.java => tests/leap/hard-coded-test-cases/src/main/java/Leap.java (100%)
 create mode 100644 tests/leap/optimal-solution/.meta/config.json
 create mode 100644 tests/leap/optimal-solution/expected_analysis.json
 create mode 100644 tests/leap/optimal-solution/expected_tags.json
 rename src/test/resources/analyzer/exercises/leap/Optimal.java => tests/leap/optimal-solution/src/main/java/Leap.java (100%)
 create mode 100644 tests/leap/using-gregorian-calendar/.meta/config.json
 rename tests/leap/{ => using-gregorian-calendar}/expected_analysis.json (100%)
 create mode 100644 tests/leap/using-gregorian-calendar/expected_tags.json
 rename src/test/resources/analyzer/exercises/leap/UsesGregorianCalendar.java => tests/leap/using-gregorian-calendar/src/main/java/Leap.java (100%)
 create mode 100644 tests/leap/using-if-statements/.meta/config.json
 create mode 100644 tests/leap/using-if-statements/expected_analysis.json
 create mode 100644 tests/leap/using-if-statements/expected_tags.json
 rename src/test/resources/analyzer/exercises/leap/UsesIfStatements.java => tests/leap/using-if-statements/src/main/java/Leap.java (100%)
 create mode 100644 tests/leap/using-java-time/.meta/config.json
 create mode 100644 tests/leap/using-java-time/expected_analysis.json
 create mode 100644 tests/leap/using-java-time/expected_tags.json
 rename tests/leap/{ => using-java-time}/src/main/java/Leap.java (100%)
 create mode 100644 tests/leap/using-ternary/.meta/config.json
 create mode 100644 tests/leap/using-ternary/expected_analysis.json
 create mode 100644 tests/leap/using-ternary/expected_tags.json
 rename src/test/resources/analyzer/exercises/leap/UsesTernary.java => tests/leap/using-ternary/src/main/java/Leap.java (100%)
 create mode 100644 tests/leap/using-too-many-checks/.meta/config.json
 create mode 100644 tests/leap/using-too-many-checks/expected_analysis.json
 create mode 100644 tests/leap/using-too-many-checks/expected_tags.json
 rename src/test/resources/analyzer/exercises/leap/TooManyChecks.java => tests/leap/using-too-many-checks/src/main/java/Leap.java (100%)

diff --git a/bin/run-tests.sh b/bin/run-tests.sh
index 8060ca08..b4d319bd 100755
--- a/bin/run-tests.sh
+++ b/bin/run-tests.sh
@@ -14,15 +14,15 @@
 exit_code=0
 
 # Iterate over all test directories
-for test_dir in tests/*; do
-    test_dir_name=$(basename "${test_dir}")
+for test_dir in $(find tests -name expected_analysis.json | rev | cut -d '/' -f 2- | rev); do
     test_dir_path=$(realpath "${test_dir}")
+    test_slug=$(echo "${test_dir}" | awk -F/ '{ print $2 }')
 
-    bin/run.sh "${test_dir_name}" "${test_dir_path}/" "${test_dir_path}/"
+    bin/run.sh "${test_slug}" "${test_dir_path}/" "${test_dir_path}/"
 
     for file in analysis.json tags.json; do
         expected_file="expected_${file}"
-        echo "${test_dir_name}: comparing ${file} to ${expected_file}"
+        echo "${test_dir}: comparing ${file} to ${expected_file}"
 
         if ! diff "${test_dir_path}/${file}" "${test_dir_path}/${expected_file}"; then
             exit_code=1
@@ -30,4 +30,4 @@ for test_dir in tests/*; do
     done
 done
 
-exit ${exit_code}
+exit ${exit_code}
\ No newline at end of file
diff --git a/src/test/java/analyzer/exercises/leap/LeapAnalyzerTest.java b/src/test/java/analyzer/exercises/leap/LeapAnalyzerTest.java
deleted file mode 100644
index a5575a03..00000000
--- a/src/test/java/analyzer/exercises/leap/LeapAnalyzerTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package analyzer.exercises.leap;
-
-import analyzer.Analyzer;
-import analyzer.AnalyzerTest;
-import analyzer.Comment;
-import analyzer.comments.AvoidHardCodedTestCases;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.MethodSource;
-
-import java.util.stream.Stream;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class LeapAnalyzerTest extends AnalyzerTest {
-    @Override
-    protected Analyzer getAnalyzer() {
-        return new LeapAnalyzer();
-    }
-
-    @Test
-    public void noCommentsOnOptimalSolution() {
-        var actual = analyzeResourceFile(getResourceFileName("Optimal.java"));
-
-        assertThat(actual.getComments()).isEmpty();
-    }
-
-    private static Stream<Arguments> testCases() {
-        return Stream.of(
-                Arguments.of("UsesJavaTime.java", new Comment[]{new NoBuiltInMethods()}),
-                Arguments.of("UsesGregorianCalendar.java", new Comment[]{new NoBuiltInMethods()}),
-                Arguments.of("HardCodedTestCases.java", new Comment[]{new AvoidHardCodedTestCases()}),
-                Arguments.of("UsesIfStatements.java", new Comment[]{new AvoidConditionalLogic()}),
-                Arguments.of("UsesTernary.java", new Comment[]{new AvoidConditionalLogic()}),
-                Arguments.of("TooManyChecks.java", new Comment[]{new UseMinimumNumberOfChecks()})
-        );
-    }
-
-    @MethodSource("testCases")
-    @ParameterizedTest(name = "{0}")
-    public void testCommentsOnSolution(String solutionFile, Comment... expectedComments) {
-        var actual = analyzeResourceFile(getResourceFileName(solutionFile));
-
-        assertThat(actual.getComments()).contains(expectedComments);
-    }
-
-    private static String getResourceFileName(String testFileName) {
-        return "/analyzer/exercises/leap/" + testFileName;
-    }
-}
diff --git a/src/test/resources/analyzer/exercises/leap/UsesJavaTime.java b/src/test/resources/analyzer/exercises/leap/UsesJavaTime.java
deleted file mode 100644
index e3957535..00000000
--- a/src/test/resources/analyzer/exercises/leap/UsesJavaTime.java
+++ /dev/null
@@ -1,7 +0,0 @@
-import java.time.Year;
-
-class Leap {
-    boolean isLeapYear(int year) {
-        return Year.isLeap(year);
-    }
-}
diff --git a/tests/leap/hard-coded-test-cases/.meta/config.json b/tests/leap/hard-coded-test-cases/.meta/config.json
new file mode 100644
index 00000000..d977953c
--- /dev/null
+++ b/tests/leap/hard-coded-test-cases/.meta/config.json
@@ -0,0 +1,29 @@
+{
+  "authors": [
+    "sonapraneeth-a"
+  ],
+  "contributors": [
+    "jmrunkle",
+    "lemoncurry",
+    "msomji",
+    "muzimuzhi",
+    "sshine"
+  ],
+  "files": {
+    "solution": [
+      "src/main/java/Leap.java"
+    ],
+    "test": [
+      "src/test/java/LeapTest.java"
+    ],
+    "example": [
+      ".meta/src/reference/java/Leap.java"
+    ],
+    "invalidator": [
+      "build.gradle"
+    ]
+  },
+  "blurb": "Determine whether a given year is a leap year.",
+  "source": "CodeRanch Cattle Drive, Assignment 3",
+  "source_url": "https://coderanch.com/t/718816/Leap"
+}
\ No newline at end of file
diff --git a/tests/leap/hard-coded-test-cases/expected_analysis.json b/tests/leap/hard-coded-test-cases/expected_analysis.json
new file mode 100644
index 00000000..e4934cb5
--- /dev/null
+++ b/tests/leap/hard-coded-test-cases/expected_analysis.json
@@ -0,0 +1,14 @@
+{"comments": [
+  {
+    "comment": "java.general.avoid_hard_coded_test_cases",
+    "type": "essential"
+  },
+  {
+    "comment": "java.leap.use_minimum_number_of_checks",
+    "type": "actionable"
+  },
+  {
+    "comment": "java.general.feedback_request",
+    "type": "informative"
+  }
+]}
\ No newline at end of file
diff --git a/tests/leap/expected_tags.json b/tests/leap/hard-coded-test-cases/expected_tags.json
similarity index 100%
rename from tests/leap/expected_tags.json
rename to tests/leap/hard-coded-test-cases/expected_tags.json
diff --git a/src/test/resources/analyzer/exercises/leap/HardCodedTestCases.java b/tests/leap/hard-coded-test-cases/src/main/java/Leap.java
similarity index 100%
rename from src/test/resources/analyzer/exercises/leap/HardCodedTestCases.java
rename to tests/leap/hard-coded-test-cases/src/main/java/Leap.java
diff --git a/tests/leap/optimal-solution/.meta/config.json b/tests/leap/optimal-solution/.meta/config.json
new file mode 100644
index 00000000..d977953c
--- /dev/null
+++ b/tests/leap/optimal-solution/.meta/config.json
@@ -0,0 +1,29 @@
+{
+  "authors": [
+    "sonapraneeth-a"
+  ],
+  "contributors": [
+    "jmrunkle",
+    "lemoncurry",
+    "msomji",
+    "muzimuzhi",
+    "sshine"
+  ],
+  "files": {
+    "solution": [
+      "src/main/java/Leap.java"
+    ],
+    "test": [
+      "src/test/java/LeapTest.java"
+    ],
+    "example": [
+      ".meta/src/reference/java/Leap.java"
+    ],
+    "invalidator": [
+      "build.gradle"
+    ]
+  },
+  "blurb": "Determine whether a given year is a leap year.",
+  "source": "CodeRanch Cattle Drive, Assignment 3",
+  "source_url": "https://coderanch.com/t/718816/Leap"
+}
\ No newline at end of file
diff --git a/tests/leap/optimal-solution/expected_analysis.json b/tests/leap/optimal-solution/expected_analysis.json
new file mode 100644
index 00000000..9e26dfee
--- /dev/null
+++ b/tests/leap/optimal-solution/expected_analysis.json
@@ -0,0 +1 @@
+{}
\ No newline at end of file
diff --git a/tests/leap/optimal-solution/expected_tags.json b/tests/leap/optimal-solution/expected_tags.json
new file mode 100644
index 00000000..9e26dfee
--- /dev/null
+++ b/tests/leap/optimal-solution/expected_tags.json
@@ -0,0 +1 @@
+{}
\ No newline at end of file
diff --git a/src/test/resources/analyzer/exercises/leap/Optimal.java b/tests/leap/optimal-solution/src/main/java/Leap.java
similarity index 100%
rename from src/test/resources/analyzer/exercises/leap/Optimal.java
rename to tests/leap/optimal-solution/src/main/java/Leap.java
diff --git a/tests/leap/using-gregorian-calendar/.meta/config.json b/tests/leap/using-gregorian-calendar/.meta/config.json
new file mode 100644
index 00000000..d977953c
--- /dev/null
+++ b/tests/leap/using-gregorian-calendar/.meta/config.json
@@ -0,0 +1,29 @@
+{
+  "authors": [
+    "sonapraneeth-a"
+  ],
+  "contributors": [
+    "jmrunkle",
+    "lemoncurry",
+    "msomji",
+    "muzimuzhi",
+    "sshine"
+  ],
+  "files": {
+    "solution": [
+      "src/main/java/Leap.java"
+    ],
+    "test": [
+      "src/test/java/LeapTest.java"
+    ],
+    "example": [
+      ".meta/src/reference/java/Leap.java"
+    ],
+    "invalidator": [
+      "build.gradle"
+    ]
+  },
+  "blurb": "Determine whether a given year is a leap year.",
+  "source": "CodeRanch Cattle Drive, Assignment 3",
+  "source_url": "https://coderanch.com/t/718816/Leap"
+}
\ No newline at end of file
diff --git a/tests/leap/expected_analysis.json b/tests/leap/using-gregorian-calendar/expected_analysis.json
similarity index 100%
rename from tests/leap/expected_analysis.json
rename to tests/leap/using-gregorian-calendar/expected_analysis.json
diff --git a/tests/leap/using-gregorian-calendar/expected_tags.json b/tests/leap/using-gregorian-calendar/expected_tags.json
new file mode 100644
index 00000000..9e26dfee
--- /dev/null
+++ b/tests/leap/using-gregorian-calendar/expected_tags.json
@@ -0,0 +1 @@
+{}
\ No newline at end of file
diff --git a/src/test/resources/analyzer/exercises/leap/UsesGregorianCalendar.java b/tests/leap/using-gregorian-calendar/src/main/java/Leap.java
similarity index 100%
rename from src/test/resources/analyzer/exercises/leap/UsesGregorianCalendar.java
rename to tests/leap/using-gregorian-calendar/src/main/java/Leap.java
diff --git a/tests/leap/using-if-statements/.meta/config.json b/tests/leap/using-if-statements/.meta/config.json
new file mode 100644
index 00000000..d977953c
--- /dev/null
+++ b/tests/leap/using-if-statements/.meta/config.json
@@ -0,0 +1,29 @@
+{
+  "authors": [
+    "sonapraneeth-a"
+  ],
+  "contributors": [
+    "jmrunkle",
+    "lemoncurry",
+    "msomji",
+    "muzimuzhi",
+    "sshine"
+  ],
+  "files": {
+    "solution": [
+      "src/main/java/Leap.java"
+    ],
+    "test": [
+      "src/test/java/LeapTest.java"
+    ],
+    "example": [
+      ".meta/src/reference/java/Leap.java"
+    ],
+    "invalidator": [
+      "build.gradle"
+    ]
+  },
+  "blurb": "Determine whether a given year is a leap year.",
+  "source": "CodeRanch Cattle Drive, Assignment 3",
+  "source_url": "https://coderanch.com/t/718816/Leap"
+}
\ No newline at end of file
diff --git a/tests/leap/using-if-statements/expected_analysis.json b/tests/leap/using-if-statements/expected_analysis.json
new file mode 100644
index 00000000..f09b4a58
--- /dev/null
+++ b/tests/leap/using-if-statements/expected_analysis.json
@@ -0,0 +1,10 @@
+{"comments": [
+  {
+    "comment": "java.leap.avoid_conditional_logic",
+    "type": "actionable"
+  },
+  {
+    "comment": "java.general.feedback_request",
+    "type": "informative"
+  }
+]}
\ No newline at end of file
diff --git a/tests/leap/using-if-statements/expected_tags.json b/tests/leap/using-if-statements/expected_tags.json
new file mode 100644
index 00000000..9e26dfee
--- /dev/null
+++ b/tests/leap/using-if-statements/expected_tags.json
@@ -0,0 +1 @@
+{}
\ No newline at end of file
diff --git a/src/test/resources/analyzer/exercises/leap/UsesIfStatements.java b/tests/leap/using-if-statements/src/main/java/Leap.java
similarity index 100%
rename from src/test/resources/analyzer/exercises/leap/UsesIfStatements.java
rename to tests/leap/using-if-statements/src/main/java/Leap.java
diff --git a/tests/leap/using-java-time/.meta/config.json b/tests/leap/using-java-time/.meta/config.json
new file mode 100644
index 00000000..d977953c
--- /dev/null
+++ b/tests/leap/using-java-time/.meta/config.json
@@ -0,0 +1,29 @@
+{
+  "authors": [
+    "sonapraneeth-a"
+  ],
+  "contributors": [
+    "jmrunkle",
+    "lemoncurry",
+    "msomji",
+    "muzimuzhi",
+    "sshine"
+  ],
+  "files": {
+    "solution": [
+      "src/main/java/Leap.java"
+    ],
+    "test": [
+      "src/test/java/LeapTest.java"
+    ],
+    "example": [
+      ".meta/src/reference/java/Leap.java"
+    ],
+    "invalidator": [
+      "build.gradle"
+    ]
+  },
+  "blurb": "Determine whether a given year is a leap year.",
+  "source": "CodeRanch Cattle Drive, Assignment 3",
+  "source_url": "https://coderanch.com/t/718816/Leap"
+}
\ No newline at end of file
diff --git a/tests/leap/using-java-time/expected_analysis.json b/tests/leap/using-java-time/expected_analysis.json
new file mode 100644
index 00000000..d7466506
--- /dev/null
+++ b/tests/leap/using-java-time/expected_analysis.json
@@ -0,0 +1,10 @@
+{"comments": [
+  {
+    "comment": "java.leap.no_built_in_methods",
+    "type": "essential"
+  },
+  {
+    "comment": "java.general.feedback_request",
+    "type": "informative"
+  }
+]}
\ No newline at end of file
diff --git a/tests/leap/using-java-time/expected_tags.json b/tests/leap/using-java-time/expected_tags.json
new file mode 100644
index 00000000..9e26dfee
--- /dev/null
+++ b/tests/leap/using-java-time/expected_tags.json
@@ -0,0 +1 @@
+{}
\ No newline at end of file
diff --git a/tests/leap/src/main/java/Leap.java b/tests/leap/using-java-time/src/main/java/Leap.java
similarity index 100%
rename from tests/leap/src/main/java/Leap.java
rename to tests/leap/using-java-time/src/main/java/Leap.java
diff --git a/tests/leap/using-ternary/.meta/config.json b/tests/leap/using-ternary/.meta/config.json
new file mode 100644
index 00000000..d977953c
--- /dev/null
+++ b/tests/leap/using-ternary/.meta/config.json
@@ -0,0 +1,29 @@
+{
+  "authors": [
+    "sonapraneeth-a"
+  ],
+  "contributors": [
+    "jmrunkle",
+    "lemoncurry",
+    "msomji",
+    "muzimuzhi",
+    "sshine"
+  ],
+  "files": {
+    "solution": [
+      "src/main/java/Leap.java"
+    ],
+    "test": [
+      "src/test/java/LeapTest.java"
+    ],
+    "example": [
+      ".meta/src/reference/java/Leap.java"
+    ],
+    "invalidator": [
+      "build.gradle"
+    ]
+  },
+  "blurb": "Determine whether a given year is a leap year.",
+  "source": "CodeRanch Cattle Drive, Assignment 3",
+  "source_url": "https://coderanch.com/t/718816/Leap"
+}
\ No newline at end of file
diff --git a/tests/leap/using-ternary/expected_analysis.json b/tests/leap/using-ternary/expected_analysis.json
new file mode 100644
index 00000000..f09b4a58
--- /dev/null
+++ b/tests/leap/using-ternary/expected_analysis.json
@@ -0,0 +1,10 @@
+{"comments": [
+  {
+    "comment": "java.leap.avoid_conditional_logic",
+    "type": "actionable"
+  },
+  {
+    "comment": "java.general.feedback_request",
+    "type": "informative"
+  }
+]}
\ No newline at end of file
diff --git a/tests/leap/using-ternary/expected_tags.json b/tests/leap/using-ternary/expected_tags.json
new file mode 100644
index 00000000..9e26dfee
--- /dev/null
+++ b/tests/leap/using-ternary/expected_tags.json
@@ -0,0 +1 @@
+{}
\ No newline at end of file
diff --git a/src/test/resources/analyzer/exercises/leap/UsesTernary.java b/tests/leap/using-ternary/src/main/java/Leap.java
similarity index 100%
rename from src/test/resources/analyzer/exercises/leap/UsesTernary.java
rename to tests/leap/using-ternary/src/main/java/Leap.java
diff --git a/tests/leap/using-too-many-checks/.meta/config.json b/tests/leap/using-too-many-checks/.meta/config.json
new file mode 100644
index 00000000..d977953c
--- /dev/null
+++ b/tests/leap/using-too-many-checks/.meta/config.json
@@ -0,0 +1,29 @@
+{
+  "authors": [
+    "sonapraneeth-a"
+  ],
+  "contributors": [
+    "jmrunkle",
+    "lemoncurry",
+    "msomji",
+    "muzimuzhi",
+    "sshine"
+  ],
+  "files": {
+    "solution": [
+      "src/main/java/Leap.java"
+    ],
+    "test": [
+      "src/test/java/LeapTest.java"
+    ],
+    "example": [
+      ".meta/src/reference/java/Leap.java"
+    ],
+    "invalidator": [
+      "build.gradle"
+    ]
+  },
+  "blurb": "Determine whether a given year is a leap year.",
+  "source": "CodeRanch Cattle Drive, Assignment 3",
+  "source_url": "https://coderanch.com/t/718816/Leap"
+}
\ No newline at end of file
diff --git a/tests/leap/using-too-many-checks/expected_analysis.json b/tests/leap/using-too-many-checks/expected_analysis.json
new file mode 100644
index 00000000..55786b70
--- /dev/null
+++ b/tests/leap/using-too-many-checks/expected_analysis.json
@@ -0,0 +1,10 @@
+{"comments": [
+  {
+    "comment": "java.leap.use_minimum_number_of_checks",
+    "type": "actionable"
+  },
+  {
+    "comment": "java.general.feedback_request",
+    "type": "informative"
+  }
+]}
\ No newline at end of file
diff --git a/tests/leap/using-too-many-checks/expected_tags.json b/tests/leap/using-too-many-checks/expected_tags.json
new file mode 100644
index 00000000..9e26dfee
--- /dev/null
+++ b/tests/leap/using-too-many-checks/expected_tags.json
@@ -0,0 +1 @@
+{}
\ No newline at end of file
diff --git a/src/test/resources/analyzer/exercises/leap/TooManyChecks.java b/tests/leap/using-too-many-checks/src/main/java/Leap.java
similarity index 100%
rename from src/test/resources/analyzer/exercises/leap/TooManyChecks.java
rename to tests/leap/using-too-many-checks/src/main/java/Leap.java