-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Reimplement unit tests to use Approvals library * Add OutputCollectorTest * Convert OutputCollector to interface * Merge analyzer tests into AnalyzerIntegrationTest * Add Comments unit tests * Update Javadoc * Add unit test for SubmittedSolution class * Add Javadoc to test helper classes * Remove checks for CLI argument paths ending with / * Make sure there are at least two smoke tests per exercise * Update AnalyzerIntegrationTest after merge * Fix compilation error after resolving conflicts
- Loading branch information
1 parent
d7b8abe
commit e389344
Showing
148 changed files
with
1,556 additions
and
650 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
* text=auto | ||
|
||
*.bat text eol=crlf | ||
|
||
*.approved.* binary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,7 @@ build | |
.project | ||
.classpath | ||
|
||
src/test/**/*.received.txt | ||
|
||
tests/**/*/analysis.json | ||
tests/**/*/tags.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package analyzer; | ||
|
||
import java.util.List; | ||
|
||
public record Output(Analysis analysis, Tags tags) { | ||
|
||
public record Analysis(String summary, List<Comment> comments) { | ||
} | ||
|
||
public record Tags(List<String> tags) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package analyzer; | ||
|
||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
class OutputBuilder implements OutputCollector { | ||
private String summary; | ||
private final Set<Comment> comments = new LinkedHashSet<>(); | ||
private final Set<String> tags = new LinkedHashSet<>(); | ||
|
||
public String getSummary() { | ||
return summary; | ||
} | ||
|
||
public void setSummary(String summary) { | ||
this.summary = summary; | ||
} | ||
|
||
public List<Comment> getComments() { | ||
return List.copyOf(comments); | ||
} | ||
|
||
public List<String> getTags() { | ||
return List.copyOf(tags); | ||
} | ||
|
||
public void addComment(Comment comment) { | ||
comments.add(comment); | ||
} | ||
|
||
public void addTag(String tag) { | ||
tags.add(tag); | ||
} | ||
|
||
Output build() { | ||
var sortedComments = this.comments.stream().sorted(OutputBuilder::compareCommentsByType).toList(); | ||
var analysis = new Output.Analysis(this.summary, sortedComments); | ||
var tags = new Output.Tags(List.copyOf(this.tags)); | ||
return new Output(analysis, tags); | ||
} | ||
|
||
private static int compareCommentsByType(Comment a, Comment b) { | ||
var ordinalA = Optional.ofNullable(a.getType()).map(Comment.Type::ordinal).orElse(Integer.MAX_VALUE); | ||
var ordinalB = Optional.ofNullable(b.getType()).map(Comment.Type::ordinal).orElse(Integer.MAX_VALUE); | ||
return Integer.compare(ordinalA, ordinalB); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package analyzer; | ||
|
||
import com.google.gson.*; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
/** | ||
* Serializer to convert the analyzer output to JSON. | ||
* | ||
* @see <a href="https://exercism.org/docs/building/tooling/analyzers/interface">The analyzer interface in the Exercism documentation</a> | ||
*/ | ||
class OutputSerializer { | ||
private static final Gson GSON = new GsonBuilder() | ||
.registerTypeAdapter(Comment.class, new CommentJsonSerializer()) | ||
.setPrettyPrinting() | ||
.create(); | ||
|
||
static String serialize(Output.Analysis analysis) { | ||
return GSON.toJson(analysis); | ||
} | ||
|
||
static String serialize(Output.Tags tags) { | ||
return GSON.toJson(tags); | ||
} | ||
|
||
private static class CommentJsonSerializer implements JsonSerializer<Comment> { | ||
@Override | ||
public JsonElement serialize(Comment comment, Type type, JsonSerializationContext jsonSerializationContext) { | ||
var json = new JsonObject(); | ||
json.addProperty("comment", comment.getKey()); | ||
json.add("params", serializeParameters(comment.getParameters())); | ||
|
||
if (comment.getType() != null) { | ||
json.addProperty("type", comment.getType().name().toLowerCase()); | ||
} | ||
|
||
return json; | ||
} | ||
|
||
private static JsonElement serializeParameters(Map<String, String> parameters) { | ||
var json = new JsonObject(); | ||
new TreeMap<>(parameters).forEach(json::addProperty); | ||
return json; | ||
} | ||
} | ||
} |
Oops, something went wrong.