Skip to content

Commit

Permalink
chore(qulice): resolved all Qulice warnings
Browse files Browse the repository at this point in the history
Refs: #58
  • Loading branch information
nergal-perm committed Sep 5, 2024
1 parent ba8eedf commit a330641
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
11 changes: 5 additions & 6 deletions src/main/java/ru/ewc/checklogic/TestResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ private String classBasedOnSuccess() {
}

@Override
public int compareTo(TestResult o) {
final int success = Boolean.compare(this.successful, o.successful);
if (success == 0) {
return this.file.compareTo(o.file);
} else {
return success;
public int compareTo(final TestResult other) {
int result = Boolean.compare(this.successful, other.successful);
if (result == 0) {
result = this.file.compareTo(other.file);
}
return result;
}
}
8 changes: 6 additions & 2 deletions src/main/java/ru/ewc/checklogic/server/AllEndpoints.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ private Response getAddressFor(final Request request) {
final Response result;
final String address = request.requestLine().getPathDetails().getIsolatedPath();
if (address.isEmpty()) {
result = this.pages.indexPage();
result = this.renderHtmlFor("templates/index.html");
} else if ("test".equals(address)) {
if (this.context.hasTestsFolder()) {
result = this.pages.testPage();
} else {
result = this.pages.noTestsFolder();
result = this.renderHtmlFor("templates/noTestsFolder.html");
}
} else if ("state".equals(address)) {
result = this.pages.statePage(this.context);
Expand All @@ -108,6 +108,10 @@ private Response getAddressFor(final Request request) {
return result;
}

private Response renderHtmlFor(final String template) {
return Response.htmlOk(this.pages.renderInLayout(template, Map.of()));
}

private static Response staticResource(final Request request) {
final Response result;
if (request.requestLine().getPathDetails().getIsolatedPath().endsWith("main.css")) {
Expand Down
25 changes: 9 additions & 16 deletions src/main/java/ru/ewc/checklogic/server/WebPages.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,10 @@ public static WebPages testable() {
return new WebPages(new MockTemplateRender(), "root folder");
}

public Response indexPage() {
return Response.htmlOk(this.renderInLayout("templates/index.html", Map.of()));
}

public Response uninitializedPage() {
return Response.htmlOk(this.renderInLayout("templates/uninitialized.html", Map.of()));
}

public Response noTestsFolder() {
return Response.htmlOk(this.renderInLayout("templates/noTestsFolder.html", Map.of()));
}

public Response testPage() {
final CheckSuite suite = CheckSuite.using(
new CombinedCsvFileReader(Path.of(this.root, "tests").toUri(), ".csv", ";")
Expand Down Expand Up @@ -128,21 +120,22 @@ public Response statePage(final ServerInstance context) {
);
}

public String configPage() {
return this.renderInLayout("templates/config.html", Map.of());
}

private String renderInLayout(final String template, final Map<String, String> values) {
public String renderInLayout(final String template, final Map<String, String> values) {
return this.processors.renderInLayout(template, values);
}

private static String resultAsUnorderedList(final Map.Entry<String, List<CheckFailure>> entry) {
return "<ul>%s</ul>".formatted(String.join("", checkFailureAsHtml(entry.getValue())));
}

private static String checkFailureAsHtml(final List<CheckFailure> failure) {
return failure.stream()
.map(f -> "<li>Expected: <kbd>%s</kbd>, but got: <kbd>%s</kbd></li>".formatted(f.expectation(), f.actual()))
private static String checkFailureAsHtml(final List<CheckFailure> failures) {
return failures.stream()
.map(WebPages::formattedDescriptionFor)
.collect(Collectors.joining());
}

private static String formattedDescriptionFor(final CheckFailure failure) {
return "<li>Expected: <kbd>%s</kbd>, but got: <kbd>%s</kbd></li>"
.formatted(failure.expectation(), failure.actual());
}
}
3 changes: 2 additions & 1 deletion src/test/java/ru/ewc/checklogic/server/WebPagesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package ru.ewc.checklogic.server;

import java.util.Map;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
Expand All @@ -38,7 +39,7 @@ void shouldRenderConfigPage() {
final WebPages pages = WebPages.testable();
MatcherAssert.assertThat(
"Should render the exact config page",
pages.configPage(),
pages.renderInLayout("templates/config.html", Map.of()),
Matchers.is("Layout rendering")
);
}
Expand Down

1 comment on commit a330641

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on a330641 Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 47-58f96870 disappeared from src/main/java/ru/ewc/checklogic/server/WebPages.java), that's why I closed #50. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.