From c2628d856a76bb728c4795a0d0e773f31be3ef38 Mon Sep 17 00:00:00 2001 From: Manuel Maxera <95315128+manumafe98@users.noreply.github.com> Date: Wed, 27 Mar 2024 12:43:45 -0300 Subject: [PATCH] Implement analyzer for wizards-and-warriors (#145) * Implement analyzer for wizards-and-warriors * Fixing smoke tests * Making WizardsAndWarriorsClassAnalyzer static * Apllying suggestion to make analyzer that checks for override annotation more sophisticated Adding extra analyzer and scenario to test that --- src/main/java/analyzer/AnalyzerRoot.java | 2 + .../UseOverrideAnnotation.java | 19 ++++++ .../WizardsAndWarriorsAnalyzer.java | 68 +++++++++++++++++++ .../analyzer/AnalyzerIntegrationTest.java | 15 ++++ ...sandwarriors.ExemplarSolution.approved.txt | 11 +++ ...mplarSolutionWithTodoComments.approved.txt | 14 ++++ ...s.NotUsingOverrideAnnotations.approved.txt | 14 ++++ ...ditionalEqualsMethodOverrided.approved.txt | 11 +++ .../ExemplarSolution.java | 54 +++++++++++++++ .../ExemplarSolutionWithTodoComments.java | 56 +++++++++++++++ .../NotUsingOverrideAnnotations.java | 48 +++++++++++++ .../UsingAditionalEqualsMethodOverrided.java | 59 ++++++++++++++++ .../exemplar-solution/.meta/config.json | 27 ++++++++ .../exemplar-solution/expected_analysis.json | 11 +++ .../exemplar-solution/expected_tags.json | 3 + .../src/main/java/Fighter.java | 52 ++++++++++++++ .../.meta/config.json | 27 ++++++++ .../expected_analysis.json | 14 ++++ .../expected_tags.json | 3 + .../src/main/java/Fighter.java | 46 +++++++++++++ .../todos-not-removed/.meta/config.json | 27 ++++++++ .../todos-not-removed/expected_analysis.json | 14 ++++ .../todos-not-removed/expected_tags.json | 3 + .../src/main/java/Fighter.java | 54 +++++++++++++++ 24 files changed, 652 insertions(+) create mode 100644 src/main/java/analyzer/exercises/wizardsandwarriors/UseOverrideAnnotation.java create mode 100644 src/main/java/analyzer/exercises/wizardsandwarriors/WizardsAndWarriorsAnalyzer.java create mode 100644 src/test/resources/analyzer/AnalyzerIntegrationTest.wizardsandwarriors.ExemplarSolution.approved.txt create mode 100644 src/test/resources/analyzer/AnalyzerIntegrationTest.wizardsandwarriors.ExemplarSolutionWithTodoComments.approved.txt create mode 100644 src/test/resources/analyzer/AnalyzerIntegrationTest.wizardsandwarriors.NotUsingOverrideAnnotations.approved.txt create mode 100644 src/test/resources/analyzer/AnalyzerIntegrationTest.wizardsandwarriors.UsingAditionalEqualsMethodOverrided.approved.txt create mode 100644 src/test/resources/scenarios/wizards-and-warriors/ExemplarSolution.java create mode 100644 src/test/resources/scenarios/wizards-and-warriors/ExemplarSolutionWithTodoComments.java create mode 100644 src/test/resources/scenarios/wizards-and-warriors/NotUsingOverrideAnnotations.java create mode 100644 src/test/resources/scenarios/wizards-and-warriors/UsingAditionalEqualsMethodOverrided.java create mode 100644 tests/wizards-and-warriors/exemplar-solution/.meta/config.json create mode 100644 tests/wizards-and-warriors/exemplar-solution/expected_analysis.json create mode 100644 tests/wizards-and-warriors/exemplar-solution/expected_tags.json create mode 100644 tests/wizards-and-warriors/exemplar-solution/src/main/java/Fighter.java create mode 100644 tests/wizards-and-warriors/missing-override-annotations/.meta/config.json create mode 100644 tests/wizards-and-warriors/missing-override-annotations/expected_analysis.json create mode 100644 tests/wizards-and-warriors/missing-override-annotations/expected_tags.json create mode 100644 tests/wizards-and-warriors/missing-override-annotations/src/main/java/Fighter.java create mode 100644 tests/wizards-and-warriors/todos-not-removed/.meta/config.json create mode 100644 tests/wizards-and-warriors/todos-not-removed/expected_analysis.json create mode 100644 tests/wizards-and-warriors/todos-not-removed/expected_tags.json create mode 100644 tests/wizards-and-warriors/todos-not-removed/src/main/java/Fighter.java diff --git a/src/main/java/analyzer/AnalyzerRoot.java b/src/main/java/analyzer/AnalyzerRoot.java index 483a61e9..edcb41e9 100644 --- a/src/main/java/analyzer/AnalyzerRoot.java +++ b/src/main/java/analyzer/AnalyzerRoot.java @@ -10,6 +10,7 @@ import analyzer.exercises.needforspeed.NeedForSpeedAnalyzer; import analyzer.exercises.secrets.SecretsAnalyzer; import analyzer.exercises.twofer.TwoferAnalyzer; +import analyzer.exercises.wizardsandwarriors.WizardsAndWarriorsAnalyzer; import java.util.ArrayList; import java.util.List; @@ -57,6 +58,7 @@ private static List createAnalyzers(String slug) { case "need-for-speed" -> analyzers.add(new NeedForSpeedAnalyzer()); case "secrets" -> analyzers.add(new SecretsAnalyzer()); case "two-fer" -> analyzers.add(new TwoferAnalyzer()); + case "wizards-and-warriors" -> analyzers.add(new WizardsAndWarriorsAnalyzer()); } return List.copyOf(analyzers); diff --git a/src/main/java/analyzer/exercises/wizardsandwarriors/UseOverrideAnnotation.java b/src/main/java/analyzer/exercises/wizardsandwarriors/UseOverrideAnnotation.java new file mode 100644 index 00000000..0f937f4e --- /dev/null +++ b/src/main/java/analyzer/exercises/wizardsandwarriors/UseOverrideAnnotation.java @@ -0,0 +1,19 @@ +package analyzer.exercises.wizardsandwarriors; + +import analyzer.Comment; + +/** + * @see Markdown Template + */ +class UseOverrideAnnotation extends Comment { + + @Override + public String getKey() { + return "java.wizards-and-warriors.use_override_annotation"; + } + + @Override + public Type getType() { + return Type.INFORMATIVE; + } +} diff --git a/src/main/java/analyzer/exercises/wizardsandwarriors/WizardsAndWarriorsAnalyzer.java b/src/main/java/analyzer/exercises/wizardsandwarriors/WizardsAndWarriorsAnalyzer.java new file mode 100644 index 00000000..524f81cd --- /dev/null +++ b/src/main/java/analyzer/exercises/wizardsandwarriors/WizardsAndWarriorsAnalyzer.java @@ -0,0 +1,68 @@ +package analyzer.exercises.wizardsandwarriors; + +import com.github.javaparser.ast.body.MethodDeclaration; +import com.github.javaparser.ast.comments.LineComment; +import com.github.javaparser.ast.expr.AnnotationExpr; +import com.github.javaparser.ast.visitor.VoidVisitorAdapter; + +import analyzer.Analyzer; +import analyzer.OutputCollector; +import analyzer.Solution; +import analyzer.comments.ExemplarSolution; +import analyzer.comments.RemoveTodoComments; + +/** + * The {@link WizardsAndWarriorsAnalyzer} is the analyzer implementation for the {@code wizards-and-warriors} practice exercise. + * It has a subclass WizardsAndWarriorsClassAnalyzer that extends the {@link VoidVisitorAdapter} and uses the visitor pattern to traverse each compilation unit. + * + * @see The wizards-and-warriors exercise on the Java track + */ +public class WizardsAndWarriorsAnalyzer implements Analyzer { + private static final String EXERCISE_NAME = "Wizards and Warriors"; + private static final String TO_STRING = "toString"; + private static final String IS_VULNERABLE = "isVulnerable"; + private static final String GET_DAMAGE_POINTS = "getDamagePoints"; + + @Override + public void analyze(Solution solution, OutputCollector output) { + var wizardsAndWarriorsClassAnalyzer = new WizardsAndWarriorsClassAnalyzer(); + + for (var compilationUnit : solution.getCompilationUnits()) { + compilationUnit.getClassByName("Wizard").ifPresent(c -> c.accept(wizardsAndWarriorsClassAnalyzer, output)); + compilationUnit.getClassByName("Warrior").ifPresent(c -> c.accept(wizardsAndWarriorsClassAnalyzer, output)); + } + + if (output.getComments().isEmpty()) { + output.addComment(new ExemplarSolution(EXERCISE_NAME)); + } + } + + static class WizardsAndWarriorsClassAnalyzer extends VoidVisitorAdapter { + + @Override + public void visit(LineComment node, OutputCollector output) { + if (node.getContent().contains("TODO")) { + output.addComment(new RemoveTodoComments()); + } + + super.visit(node, output); + } + + @Override + public void visit(MethodDeclaration node, OutputCollector output) { + if (itsOverridedMethod(node) && doesNotHaveOverrideAnnotation(node)) { + output.addComment(new UseOverrideAnnotation()); + } + + super.visit(node, output); + } + + private static boolean doesNotHaveOverrideAnnotation(MethodDeclaration node) { + return node.findAll(AnnotationExpr.class).isEmpty(); + } + + private static boolean itsOverridedMethod(MethodDeclaration node) { + return node.getNameAsString().equals(TO_STRING) || node.getNameAsString().equals(IS_VULNERABLE) || node.getNameAsString().equals(GET_DAMAGE_POINTS); + } + } +} diff --git a/src/test/java/analyzer/AnalyzerIntegrationTest.java b/src/test/java/analyzer/AnalyzerIntegrationTest.java index 5a1650ac..bdb15d7c 100644 --- a/src/test/java/analyzer/AnalyzerIntegrationTest.java +++ b/src/test/java/analyzer/AnalyzerIntegrationTest.java @@ -169,4 +169,19 @@ void secrets(String scenario) throws IOException { Approvals.verify(serialize(output.analysis()), Approvals.NAMES.withParameters(scenario)); } + + @ParameterizedTest + @ValueSource(strings = { + "ExemplarSolution", + "ExemplarSolutionWithTodoComments", + "NotUsingOverrideAnnotations", + "UsingAditionalEqualsMethodOverrided" + }) + void wizardsandwarriors(String scenario) throws IOException { + var path = Path.of("wizards-and-warriors", scenario + ".java"); + var solution = new SolutionFromFiles("wizards-and-warriors", SCENARIOS.resolve(path)); + var output = AnalyzerRoot.analyze(solution); + + Approvals.verify(serialize(output.analysis()), Approvals.NAMES.withParameters(scenario)); + } } diff --git a/src/test/resources/analyzer/AnalyzerIntegrationTest.wizardsandwarriors.ExemplarSolution.approved.txt b/src/test/resources/analyzer/AnalyzerIntegrationTest.wizardsandwarriors.ExemplarSolution.approved.txt new file mode 100644 index 00000000..8f72e277 --- /dev/null +++ b/src/test/resources/analyzer/AnalyzerIntegrationTest.wizardsandwarriors.ExemplarSolution.approved.txt @@ -0,0 +1,11 @@ +{ + "comments": [ + { + "comment": "java.general.exemplar", + "params": { + "exerciseName": "Wizards and Warriors" + }, + "type": "celebratory" + } + ] +} \ No newline at end of file diff --git a/src/test/resources/analyzer/AnalyzerIntegrationTest.wizardsandwarriors.ExemplarSolutionWithTodoComments.approved.txt b/src/test/resources/analyzer/AnalyzerIntegrationTest.wizardsandwarriors.ExemplarSolutionWithTodoComments.approved.txt new file mode 100644 index 00000000..c4660b76 --- /dev/null +++ b/src/test/resources/analyzer/AnalyzerIntegrationTest.wizardsandwarriors.ExemplarSolutionWithTodoComments.approved.txt @@ -0,0 +1,14 @@ +{ + "comments": [ + { + "comment": "java.general.remove_todo_comments", + "params": {}, + "type": "actionable" + }, + { + "comment": "java.general.feedback_request", + "params": {}, + "type": "informative" + } + ] +} \ No newline at end of file diff --git a/src/test/resources/analyzer/AnalyzerIntegrationTest.wizardsandwarriors.NotUsingOverrideAnnotations.approved.txt b/src/test/resources/analyzer/AnalyzerIntegrationTest.wizardsandwarriors.NotUsingOverrideAnnotations.approved.txt new file mode 100644 index 00000000..5a667984 --- /dev/null +++ b/src/test/resources/analyzer/AnalyzerIntegrationTest.wizardsandwarriors.NotUsingOverrideAnnotations.approved.txt @@ -0,0 +1,14 @@ +{ + "comments": [ + { + "comment": "java.wizards-and-warriors.use_override_annotation", + "params": {}, + "type": "informative" + }, + { + "comment": "java.general.feedback_request", + "params": {}, + "type": "informative" + } + ] +} \ No newline at end of file diff --git a/src/test/resources/analyzer/AnalyzerIntegrationTest.wizardsandwarriors.UsingAditionalEqualsMethodOverrided.approved.txt b/src/test/resources/analyzer/AnalyzerIntegrationTest.wizardsandwarriors.UsingAditionalEqualsMethodOverrided.approved.txt new file mode 100644 index 00000000..8f72e277 --- /dev/null +++ b/src/test/resources/analyzer/AnalyzerIntegrationTest.wizardsandwarriors.UsingAditionalEqualsMethodOverrided.approved.txt @@ -0,0 +1,11 @@ +{ + "comments": [ + { + "comment": "java.general.exemplar", + "params": { + "exerciseName": "Wizards and Warriors" + }, + "type": "celebratory" + } + ] +} \ No newline at end of file diff --git a/src/test/resources/scenarios/wizards-and-warriors/ExemplarSolution.java b/src/test/resources/scenarios/wizards-and-warriors/ExemplarSolution.java new file mode 100644 index 00000000..b0db7ffc --- /dev/null +++ b/src/test/resources/scenarios/wizards-and-warriors/ExemplarSolution.java @@ -0,0 +1,54 @@ +package scenarios.wizardsandwarriors; + +class Fighter { + + boolean isVulnerable() { + return true; + } + + int getDamagePoints(Fighter fighter) { + return 1; + } +} + +class Warrior extends Fighter { + + @Override + public String toString() { + return "Fighter is a Warrior"; + } + + @Override + public boolean isVulnerable() { + return false; + } + + @Override + int getDamagePoints(Fighter target) { + return target.isVulnerable() ? 10 : 6; + } +} + +class Wizard extends Fighter { + + boolean isSpellPrepared = false; + + @Override + public String toString() { + return "Fighter is a Wizard"; + } + + @Override + boolean isVulnerable() { + return !isSpellPrepared; + } + + @Override + int getDamagePoints(Fighter target) { + return isSpellPrepared ? 12 : 3; + } + + void prepareSpell() { + isSpellPrepared = true; + } +} diff --git a/src/test/resources/scenarios/wizards-and-warriors/ExemplarSolutionWithTodoComments.java b/src/test/resources/scenarios/wizards-and-warriors/ExemplarSolutionWithTodoComments.java new file mode 100644 index 00000000..4edcf3dc --- /dev/null +++ b/src/test/resources/scenarios/wizards-and-warriors/ExemplarSolutionWithTodoComments.java @@ -0,0 +1,56 @@ +package scenarios.wizardsandwarriors; + +class Fighter { + + boolean isVulnerable() { + return true; + } + + int getDamagePoints(Fighter fighter) { + return 1; + } +} + +// TODO: define the Warrior class +class Warrior extends Fighter { + + @Override + public String toString() { + return "Fighter is a Warrior"; + } + + @Override + public boolean isVulnerable() { + return false; + } + + @Override + int getDamagePoints(Fighter target) { + return target.isVulnerable() ? 10 : 6; + } +} + +// TODO: define the Wizard class +class Wizard extends Fighter { + + boolean isSpellPrepared = false; + + @Override + public String toString() { + return "Fighter is a Wizard"; + } + + @Override + boolean isVulnerable() { + return !isSpellPrepared; + } + + @Override + int getDamagePoints(Fighter target) { + return isSpellPrepared ? 12 : 3; + } + + void prepareSpell() { + isSpellPrepared = true; + } +} diff --git a/src/test/resources/scenarios/wizards-and-warriors/NotUsingOverrideAnnotations.java b/src/test/resources/scenarios/wizards-and-warriors/NotUsingOverrideAnnotations.java new file mode 100644 index 00000000..08d7f8ba --- /dev/null +++ b/src/test/resources/scenarios/wizards-and-warriors/NotUsingOverrideAnnotations.java @@ -0,0 +1,48 @@ +package scenarios.wizardsandwarriors; + +class Fighter { + + boolean isVulnerable() { + return true; + } + + int getDamagePoints(Fighter fighter) { + return 1; + } +} + +class Warrior extends Fighter { + + public String toString() { + return "Fighter is a Warrior"; + } + + public boolean isVulnerable() { + return false; + } + + int getDamagePoints(Fighter target) { + return target.isVulnerable() ? 10 : 6; + } +} + +class Wizard extends Fighter { + + boolean isSpellPrepared = false; + + public String toString() { + return "Fighter is a Wizard"; + } + + boolean isVulnerable() { + return !isSpellPrepared; + } + + int getDamagePoints(Fighter target) { + return isSpellPrepared ? 12 : 3; + } + + void prepareSpell() { + isSpellPrepared = true; + } +} diff --git a/src/test/resources/scenarios/wizards-and-warriors/UsingAditionalEqualsMethodOverrided.java b/src/test/resources/scenarios/wizards-and-warriors/UsingAditionalEqualsMethodOverrided.java new file mode 100644 index 00000000..ae27c572 --- /dev/null +++ b/src/test/resources/scenarios/wizards-and-warriors/UsingAditionalEqualsMethodOverrided.java @@ -0,0 +1,59 @@ +package scenarios.wizardsandwarriors; + +class Fighter { + + boolean isVulnerable() { + return true; + } + + int getDamagePoints(Fighter fighter) { + return 1; + } +} + +class Warrior extends Fighter { + + @Override + public String toString() { + return "Fighter is a Warrior"; + } + + @Override + public boolean isVulnerable() { + return false; + } + + @Override + int getDamagePoints(Fighter target) { + return target.isVulnerable() ? 10 : 6; + } + + @Override + public boolean equals(Object obj) { + return super.equals(obj); + } +} + +class Wizard extends Fighter { + + boolean isSpellPrepared = false; + + @Override + public String toString() { + return "Fighter is a Wizard"; + } + + @Override + boolean isVulnerable() { + return !isSpellPrepared; + } + + @Override + int getDamagePoints(Fighter target) { + return isSpellPrepared ? 12 : 3; + } + + void prepareSpell() { + isSpellPrepared = true; + } +} diff --git a/tests/wizards-and-warriors/exemplar-solution/.meta/config.json b/tests/wizards-and-warriors/exemplar-solution/.meta/config.json new file mode 100644 index 00000000..0efc7983 --- /dev/null +++ b/tests/wizards-and-warriors/exemplar-solution/.meta/config.json @@ -0,0 +1,27 @@ +{ + "authors": [ + "himanshugoyal1065" + ], + "contributors": [ + "manumafe98", + "sanderploegsma" + ], + "files": { + "solution": [ + "src/main/java/Fighter.java" + ], + "test": [ + "src/test/java/FighterTest.java" + ], + "exemplar": [ + ".meta/src/reference/java/Fighter.java" + ], + "invalidator": [ + "build.gradle" + ] + }, + "forked_from": [ + "csharp/wizards-and-warriors" + ], + "blurb": "Learn about inheritance by creating an RPG." +} \ No newline at end of file diff --git a/tests/wizards-and-warriors/exemplar-solution/expected_analysis.json b/tests/wizards-and-warriors/exemplar-solution/expected_analysis.json new file mode 100644 index 00000000..b75e1a1d --- /dev/null +++ b/tests/wizards-and-warriors/exemplar-solution/expected_analysis.json @@ -0,0 +1,11 @@ +{ + "comments": [ + { + "comment": "java.general.exemplar", + "params": { + "exerciseName": "Wizards and Warriors" + }, + "type": "celebratory" + } + ] +} \ No newline at end of file diff --git a/tests/wizards-and-warriors/exemplar-solution/expected_tags.json b/tests/wizards-and-warriors/exemplar-solution/expected_tags.json new file mode 100644 index 00000000..eb25b190 --- /dev/null +++ b/tests/wizards-and-warriors/exemplar-solution/expected_tags.json @@ -0,0 +1,3 @@ +{ + "tags": [] +} \ No newline at end of file diff --git a/tests/wizards-and-warriors/exemplar-solution/src/main/java/Fighter.java b/tests/wizards-and-warriors/exemplar-solution/src/main/java/Fighter.java new file mode 100644 index 00000000..3365aa2d --- /dev/null +++ b/tests/wizards-and-warriors/exemplar-solution/src/main/java/Fighter.java @@ -0,0 +1,52 @@ +class Fighter { + + boolean isVulnerable() { + return true; + } + + int getDamagePoints(Fighter fighter) { + return 1; + } +} + +class Warrior extends Fighter { + + @Override + public String toString() { + return "Fighter is a Warrior"; + } + + @Override + public boolean isVulnerable() { + return false; + } + + @Override + int getDamagePoints(Fighter target) { + return target.isVulnerable() ? 10 : 6; + } +} + +class Wizard extends Fighter { + + boolean isSpellPrepared = false; + + @Override + public String toString() { + return "Fighter is a Wizard"; + } + + @Override + boolean isVulnerable() { + return !isSpellPrepared; + } + + @Override + int getDamagePoints(Fighter target) { + return isSpellPrepared ? 12 : 3; + } + + void prepareSpell() { + isSpellPrepared = true; + } +} diff --git a/tests/wizards-and-warriors/missing-override-annotations/.meta/config.json b/tests/wizards-and-warriors/missing-override-annotations/.meta/config.json new file mode 100644 index 00000000..0efc7983 --- /dev/null +++ b/tests/wizards-and-warriors/missing-override-annotations/.meta/config.json @@ -0,0 +1,27 @@ +{ + "authors": [ + "himanshugoyal1065" + ], + "contributors": [ + "manumafe98", + "sanderploegsma" + ], + "files": { + "solution": [ + "src/main/java/Fighter.java" + ], + "test": [ + "src/test/java/FighterTest.java" + ], + "exemplar": [ + ".meta/src/reference/java/Fighter.java" + ], + "invalidator": [ + "build.gradle" + ] + }, + "forked_from": [ + "csharp/wizards-and-warriors" + ], + "blurb": "Learn about inheritance by creating an RPG." +} \ No newline at end of file diff --git a/tests/wizards-and-warriors/missing-override-annotations/expected_analysis.json b/tests/wizards-and-warriors/missing-override-annotations/expected_analysis.json new file mode 100644 index 00000000..fe7d6c30 --- /dev/null +++ b/tests/wizards-and-warriors/missing-override-annotations/expected_analysis.json @@ -0,0 +1,14 @@ +{ + "comments": [ + { + "comment": "java.wizards-and-warriors.use_override_annotation", + "params": {}, + "type": "informative" + }, + { + "comment": "java.general.feedback_request", + "params": {}, + "type": "informative" + } + ] +} \ No newline at end of file diff --git a/tests/wizards-and-warriors/missing-override-annotations/expected_tags.json b/tests/wizards-and-warriors/missing-override-annotations/expected_tags.json new file mode 100644 index 00000000..eb25b190 --- /dev/null +++ b/tests/wizards-and-warriors/missing-override-annotations/expected_tags.json @@ -0,0 +1,3 @@ +{ + "tags": [] +} \ No newline at end of file diff --git a/tests/wizards-and-warriors/missing-override-annotations/src/main/java/Fighter.java b/tests/wizards-and-warriors/missing-override-annotations/src/main/java/Fighter.java new file mode 100644 index 00000000..b208ea60 --- /dev/null +++ b/tests/wizards-and-warriors/missing-override-annotations/src/main/java/Fighter.java @@ -0,0 +1,46 @@ +class Fighter { + + boolean isVulnerable() { + return true; + } + + int getDamagePoints(Fighter fighter) { + return 1; + } +} + +class Warrior extends Fighter { + + public String toString() { + return "Fighter is a Warrior"; + } + + public boolean isVulnerable() { + return false; + } + + int getDamagePoints(Fighter target) { + return target.isVulnerable() ? 10 : 6; + } +} + +class Wizard extends Fighter { + + boolean isSpellPrepared = false; + + public String toString() { + return "Fighter is a Wizard"; + } + + boolean isVulnerable() { + return !isSpellPrepared; + } + + int getDamagePoints(Fighter target) { + return isSpellPrepared ? 12 : 3; + } + + void prepareSpell() { + isSpellPrepared = true; + } +} diff --git a/tests/wizards-and-warriors/todos-not-removed/.meta/config.json b/tests/wizards-and-warriors/todos-not-removed/.meta/config.json new file mode 100644 index 00000000..0efc7983 --- /dev/null +++ b/tests/wizards-and-warriors/todos-not-removed/.meta/config.json @@ -0,0 +1,27 @@ +{ + "authors": [ + "himanshugoyal1065" + ], + "contributors": [ + "manumafe98", + "sanderploegsma" + ], + "files": { + "solution": [ + "src/main/java/Fighter.java" + ], + "test": [ + "src/test/java/FighterTest.java" + ], + "exemplar": [ + ".meta/src/reference/java/Fighter.java" + ], + "invalidator": [ + "build.gradle" + ] + }, + "forked_from": [ + "csharp/wizards-and-warriors" + ], + "blurb": "Learn about inheritance by creating an RPG." +} \ No newline at end of file diff --git a/tests/wizards-and-warriors/todos-not-removed/expected_analysis.json b/tests/wizards-and-warriors/todos-not-removed/expected_analysis.json new file mode 100644 index 00000000..58bf320f --- /dev/null +++ b/tests/wizards-and-warriors/todos-not-removed/expected_analysis.json @@ -0,0 +1,14 @@ +{ + "comments": [ + { + "comment": "java.general.remove_todo_comments", + "params": {}, + "type": "actionable" + }, + { + "comment": "java.general.feedback_request", + "params": {}, + "type": "informative" + } + ] +} \ No newline at end of file diff --git a/tests/wizards-and-warriors/todos-not-removed/expected_tags.json b/tests/wizards-and-warriors/todos-not-removed/expected_tags.json new file mode 100644 index 00000000..eb25b190 --- /dev/null +++ b/tests/wizards-and-warriors/todos-not-removed/expected_tags.json @@ -0,0 +1,3 @@ +{ + "tags": [] +} \ No newline at end of file diff --git a/tests/wizards-and-warriors/todos-not-removed/src/main/java/Fighter.java b/tests/wizards-and-warriors/todos-not-removed/src/main/java/Fighter.java new file mode 100644 index 00000000..bd3f13e0 --- /dev/null +++ b/tests/wizards-and-warriors/todos-not-removed/src/main/java/Fighter.java @@ -0,0 +1,54 @@ +class Fighter { + + boolean isVulnerable() { + return true; + } + + int getDamagePoints(Fighter fighter) { + return 1; + } +} + +// TODO: define the Warrior class +class Warrior extends Fighter { + + @Override + public String toString() { + return "Fighter is a Warrior"; + } + + @Override + public boolean isVulnerable() { + return false; + } + + @Override + int getDamagePoints(Fighter target) { + return target.isVulnerable() ? 10 : 6; + } +} + +// TODO: define the Wizard class +class Wizard extends Fighter { + + boolean isSpellPrepared = false; + + @Override + public String toString() { + return "Fighter is a Wizard"; + } + + @Override + boolean isVulnerable() { + return !isSpellPrepared; + } + + @Override + int getDamagePoints(Fighter target) { + return isSpellPrepared ? 12 : 3; + } + + void prepareSpell() { + isSpellPrepared = true; + } +}