diff --git a/.github/workflows/gradle.yml b/.github/workflows/test.yml similarity index 91% rename from .github/workflows/gradle.yml rename to .github/workflows/test.yml index a185adad..7010c8ee 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/test.yml @@ -21,6 +21,8 @@ jobs: distribution: "temurin" - name: Test with Gradle run: ./gradlew --no-daemon --continue test + - name: Upload test coverage + uses: coverallsapp/github-action@3dfc5567390f6fa9267c0ee9c251e4c8c3f18949 smoke_tests: name: Smoke tests diff --git a/README.md b/README.md index 73727635..90452e03 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# java-analyzer +# Java Analyzer [![Coverage Status](https://coveralls.io/repos/github/exercism/java-analyzer/badge.svg?branch=main)](https://coveralls.io/github/exercism/java-analyzer?branch=main) -The Java track project-auto-mentor analyzer using abstract syntax trees +The Java track project-auto-mentor analyzer using abstract syntax trees. ## Running in docker diff --git a/build.gradle b/build.gradle index a88d0123..180efdef 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ plugins { id "com.github.johnrengelman.shadow" version "8.1.1" id "java" id "application" + id "jacoco" } group = "org.exercism" @@ -38,4 +39,13 @@ test { showStandardStreams = true events = ["passed", "failed", "skipped"] } + + finalizedBy jacocoTestReport +} + +jacocoTestReport { + dependsOn test + reports { + xml.required = true + } } diff --git a/src/test/java/analyzer/exercises/leap/LeapAnalyzerTest.java b/src/test/java/analyzer/exercises/leap/LeapAnalyzerTest.java new file mode 100644 index 00000000..6f2883b5 --- /dev/null +++ b/src/test/java/analyzer/exercises/leap/LeapAnalyzerTest.java @@ -0,0 +1,45 @@ +package analyzer.exercises.leap; + +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 { + private static final String RESOURCE_LOCATION = "/analyzer/exercises/leap/"; + + public LeapAnalyzerTest() { + super(LeapAnalyzer.class); + } + + @Test + public void optimalSolution() { + var analysis = analyzeResourceFile(RESOURCE_LOCATION + "OptimalSolution.java"); + assertThat(analysis.getComments()).isEmpty(); + } + + private static Stream testCases() { + return Stream.of( + Arguments.of("HardCodedTestCases.java", new AvoidHardCodedTestCases()), + Arguments.of("UsingGregorianCalendar.java", new NoBuiltInMethods()), + Arguments.of("UsingIfStatements.java", new AvoidConditionalLogic()), + Arguments.of("UsingJavaTime.java", new NoBuiltInMethods()), + Arguments.of("UsingTernary.java", new AvoidConditionalLogic()), + Arguments.of("UsingTooManyChecks.java", new UseMinimumNumberOfChecks()) + ); + } + + @ParameterizedTest(name = "{0}") + @MethodSource("testCases") + public void testCommentsOnSolution(String filename, Comment expectedComment) { + var analysis = analyzeResourceFile(RESOURCE_LOCATION + filename); + assertThat(analysis.getComments()).contains(expectedComment); + } +} diff --git a/src/test/resources/analyzer/exercises/leap/HardCodedTestCases.java b/src/test/resources/analyzer/exercises/leap/HardCodedTestCases.java new file mode 100644 index 00000000..84e26b16 --- /dev/null +++ b/src/test/resources/analyzer/exercises/leap/HardCodedTestCases.java @@ -0,0 +1,5 @@ +class Leap { + boolean isLeapYear(int year) { + return year == 1960 || year == 2000 || year == 2400 || year == 1996; + } +} diff --git a/src/test/resources/analyzer/exercises/leap/OptimalSolution.java b/src/test/resources/analyzer/exercises/leap/OptimalSolution.java new file mode 100644 index 00000000..2987c90a --- /dev/null +++ b/src/test/resources/analyzer/exercises/leap/OptimalSolution.java @@ -0,0 +1,5 @@ +class Leap { + boolean isLeapYear(int year) { + return year % 400 == 0 || year % 100 != 0 && year % 4 == 0; + } +} diff --git a/tests/leap/using-gregorian-calendar/src/main/java/Leap.java b/src/test/resources/analyzer/exercises/leap/UsingGregorianCalendar.java similarity index 100% rename from tests/leap/using-gregorian-calendar/src/main/java/Leap.java rename to src/test/resources/analyzer/exercises/leap/UsingGregorianCalendar.java diff --git a/tests/leap/using-if-statements/src/main/java/Leap.java b/src/test/resources/analyzer/exercises/leap/UsingIfStatements.java similarity index 100% rename from tests/leap/using-if-statements/src/main/java/Leap.java rename to src/test/resources/analyzer/exercises/leap/UsingIfStatements.java diff --git a/src/test/resources/analyzer/exercises/leap/UsingJavaTime.java b/src/test/resources/analyzer/exercises/leap/UsingJavaTime.java new file mode 100644 index 00000000..e3957535 --- /dev/null +++ b/src/test/resources/analyzer/exercises/leap/UsingJavaTime.java @@ -0,0 +1,7 @@ +import java.time.Year; + +class Leap { + boolean isLeapYear(int year) { + return Year.isLeap(year); + } +} diff --git a/tests/leap/using-ternary/src/main/java/Leap.java b/src/test/resources/analyzer/exercises/leap/UsingTernary.java similarity index 100% rename from tests/leap/using-ternary/src/main/java/Leap.java rename to src/test/resources/analyzer/exercises/leap/UsingTernary.java diff --git a/tests/leap/using-too-many-checks/src/main/java/Leap.java b/src/test/resources/analyzer/exercises/leap/UsingTooManyChecks.java similarity index 100% rename from tests/leap/using-too-many-checks/src/main/java/Leap.java rename to src/test/resources/analyzer/exercises/leap/UsingTooManyChecks.java diff --git a/tests/leap/using-gregorian-calendar/.meta/config.json b/tests/leap/using-gregorian-calendar/.meta/config.json deleted file mode 100644 index d977953c..00000000 --- a/tests/leap/using-gregorian-calendar/.meta/config.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "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-gregorian-calendar/expected_analysis.json b/tests/leap/using-gregorian-calendar/expected_analysis.json deleted file mode 100644 index d7466506..00000000 --- a/tests/leap/using-gregorian-calendar/expected_analysis.json +++ /dev/null @@ -1,10 +0,0 @@ -{"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-gregorian-calendar/expected_tags.json b/tests/leap/using-gregorian-calendar/expected_tags.json deleted file mode 100644 index 9e26dfee..00000000 --- a/tests/leap/using-gregorian-calendar/expected_tags.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/tests/leap/using-if-statements/.meta/config.json b/tests/leap/using-if-statements/.meta/config.json deleted file mode 100644 index d977953c..00000000 --- a/tests/leap/using-if-statements/.meta/config.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "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 deleted file mode 100644 index f09b4a58..00000000 --- a/tests/leap/using-if-statements/expected_analysis.json +++ /dev/null @@ -1,10 +0,0 @@ -{"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 deleted file mode 100644 index 9e26dfee..00000000 --- a/tests/leap/using-if-statements/expected_tags.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/tests/leap/using-ternary/.meta/config.json b/tests/leap/using-ternary/.meta/config.json deleted file mode 100644 index d977953c..00000000 --- a/tests/leap/using-ternary/.meta/config.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "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 deleted file mode 100644 index f09b4a58..00000000 --- a/tests/leap/using-ternary/expected_analysis.json +++ /dev/null @@ -1,10 +0,0 @@ -{"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 deleted file mode 100644 index 9e26dfee..00000000 --- a/tests/leap/using-ternary/expected_tags.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file diff --git a/tests/leap/using-too-many-checks/.meta/config.json b/tests/leap/using-too-many-checks/.meta/config.json deleted file mode 100644 index d977953c..00000000 --- a/tests/leap/using-too-many-checks/.meta/config.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "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 deleted file mode 100644 index 55786b70..00000000 --- a/tests/leap/using-too-many-checks/expected_analysis.json +++ /dev/null @@ -1,10 +0,0 @@ -{"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 deleted file mode 100644 index 9e26dfee..00000000 --- a/tests/leap/using-too-many-checks/expected_tags.json +++ /dev/null @@ -1 +0,0 @@ -{} \ No newline at end of file