Skip to content

Commit

Permalink
address code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bitrunner committed Sep 18, 2023
1 parent dcdb41e commit 817d21c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import edu.umd.cs.findbugs.annotations.CheckForNull;

import j2html.tags.ContainerTag;
import j2html.tags.Tag;
import static j2html.TagCreator.*;

import se.bjurr.violations.lib.model.Violation;
Expand Down Expand Up @@ -67,7 +66,7 @@ private String generateDescriptionHtml(final Violation violation) {
).render();
}

private Tag generateGeneralTableHtml(final String executable, final String uniqueId, @CheckForNull final String threadId, @CheckForNull final String threadName, @CheckForNull final JSONArray auxWhats) {
private ContainerTag generateGeneralTableHtml(final String executable, final String uniqueId, @CheckForNull final String threadId, @CheckForNull final String threadName, @CheckForNull final JSONArray auxWhats) {
ContainerTag generalTable =
table(
attrs(".table.table-striped"),
Expand All @@ -86,9 +85,9 @@ private Tag generateGeneralTableHtml(final String executable, final String uniqu
return generalTable;
}

private Tag maybeGenerateStackTracesHtml(@CheckForNull final String stacksJson, final String message, @CheckForNull final JSONArray auxWhats) {
private @CheckForNull ContainerTag maybeGenerateStackTracesHtml(@CheckForNull final String stacksJson, final String message, @CheckForNull final JSONArray auxWhats) {
if (StringUtils.isBlank(stacksJson)) {
return iff(false, null);
return null;
}

final JSONArray stacks = new JSONArray(new JSONTokener(stacksJson));
Expand Down Expand Up @@ -117,10 +116,10 @@ private Tag maybeGenerateStackTracesHtml(@CheckForNull final String stacksJson,
return stackTraces;
}

return iff(false, null);
return null;
}

private Tag generateStackTraceHtml(final String title, @CheckForNull final String message, final JSONArray frames) {
private ContainerTag generateStackTraceHtml(final String title, @CheckForNull final String message, final JSONArray frames) {
ContainerTag stackTraceContainer =
div(
br(),
Expand All @@ -141,29 +140,28 @@ private Tag generateStackTraceHtml(final String title, @CheckForNull final Strin
return stackTraceContainer;
}

private Tag generateStackFrameHtml(final JSONObject frame) {
private ContainerTag generateStackFrameHtml(final JSONObject frame) {
return
table(
attrs(".table.table-striped"),
maybeGenerateTableRowHtml("Object", frame.optString("obj")),
maybeGenerateTableRowHtml("Function", frame.optString("fn")),
maybeGenerateStackFrameFileTableRowHtml(frame)
);
}

private Tag maybeGenerateSuppressionHtml(@CheckForNull final String suppression) {
private ContainerTag maybeGenerateSuppressionHtml(@CheckForNull final String suppression) {
return
iff(
StringUtils.isNotBlank(suppression),
div(br(), h4("Suppression"), table(attrs(".table.table-striped"), tr(td(pre(suppression)))))
div(br(), h4("Suppression"), table(tr(td(pre(suppression)))))
);
}

private Tag maybeGenerateTableRowHtml(final String name, @CheckForNull final String value) {
private ContainerTag maybeGenerateTableRowHtml(final String name, @CheckForNull final String value) {
return iff(StringUtils.isNotBlank(value), tr(td(text(name), td(text(value)))));
}

private Tag maybeGenerateStackFrameFileTableRowHtml(final JSONObject frame) throws JSONException {
private @CheckForNull ContainerTag maybeGenerateStackFrameFileTableRowHtml(final JSONObject frame) throws JSONException {
final String file = frame.optString("file");

if (StringUtils.isNotBlank(file)) {
Expand All @@ -184,7 +182,7 @@ private Tag maybeGenerateStackFrameFileTableRowHtml(final JSONObject frame) thro
return maybeGenerateTableRowHtml("File", fileBuilder.toString());
}

return iff(false, null);
return null;
}

@CheckForNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

/**
* A descriptor for Valgrind.
* See https://valgrind.org for more information about Valgrind.
*/
public class ValgrindDescriptor extends ParserDescriptor {
private static final String ID = "valgrind";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import se.bjurr.violations.lib.model.Violation;

import static org.assertj.core.api.Assertions.*;

/**
* Tests the class {@link ValgrindAdapter}.
*
Expand Down Expand Up @@ -62,11 +60,10 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti
issue -> {
final String description = issue.getDescription();
if (Violation.NO_FILE.equals(issue.getFileName())) {
assertThat(!description.contains("Primary Stack Trace"));
softly.assertThat(description).doesNotContain("Primary Stack Trace");
}
else {
assertThat(description.contains("Primary Stack Trace"));
assertThat(description.contains("<insert_a_suppression_name_here>"));
softly.assertThat(description).contains("Primary Stack Trace", "<insert_a_suppression_name_here>");
}
}
);
Expand Down

0 comments on commit 817d21c

Please sign in to comment.