Skip to content

Commit

Permalink
Add json extension
Browse files Browse the repository at this point in the history
  • Loading branch information
charphi committed Aug 28, 2024
1 parent bbc5ada commit 58c43ee
Show file tree
Hide file tree
Showing 20 changed files with 170 additions and 36 deletions.
5 changes: 0 additions & 5 deletions heylogs-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@
<groupId>com.github.nbbrd.java-io-util</groupId>
<artifactId>java-io-http</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.11.0</version>
</dependency>

<!-- test only -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
package internal.heylogs;

import tests.heylogs.api.Sample;
import com.vladsch.flexmark.ast.LinkNodeBase;
import com.vladsch.flexmark.util.ast.Node;
import nbbrd.heylogs.Nodes;
import nbbrd.heylogs.spi.Rule;
import nbbrd.heylogs.spi.RuleIssue;
import nbbrd.heylogs.spi.RuleLoader;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import tests.heylogs.api.Sample;

import java.util.Objects;

import static tests.heylogs.api.Sample.using;
import static internal.heylogs.ExtendedRules.NO_RULE_ISSUE;
import static internal.heylogs.ExtendedRules.validateConsistentSeparator;
import static nbbrd.heylogs.Nodes.of;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.data.Index.atIndex;
import static tests.heylogs.api.Sample.using;
import static tests.heylogs.spi.RuleAssert.assertRuleCompliance;

public class ExtendedRulesTest {

@Test
public void testIdPattern() {
assertThat(ExtendedRules.values())
.extracting(Rule::getRuleId)
.allMatch(RuleLoader.ID_PATTERN.asPredicate());
public void testCompliance() {
assertRuleCompliance(new ExtendedRules.Batch());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,25 @@

import com.vladsch.flexmark.ast.Heading;
import com.vladsch.flexmark.util.ast.Node;
import nbbrd.heylogs.spi.Rule;
import nbbrd.heylogs.spi.RuleIssue;
import nbbrd.heylogs.spi.RuleLoader;
import org.junit.jupiter.api.Test;

import java.util.Objects;

import static tests.heylogs.api.Sample.using;
import static internal.heylogs.GuidingPrinciples.validateForHumans;
import static internal.heylogs.GuidingPrinciples.validateLatestVersionFirst;
import static nbbrd.heylogs.Nodes.of;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.data.Index.atIndex;
import static tests.heylogs.api.Sample.using;
import static tests.heylogs.spi.RuleAssert.assertRuleCompliance;

public class
GuidingPrinciplesTest {

@Test
public void testIdPattern() {
assertThat(GuidingPrinciples.values())
.extracting(Rule::getRuleId)
.allMatch(RuleLoader.ID_PATTERN.asPredicate());
public void testCompliance() {
assertRuleCompliance(new GuidingPrinciples.Batch());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
import nbbrd.heylogs.spi.FormatType;
import org.junit.jupiter.api.Test;

import static tests.heylogs.api.Sample.*;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static tests.heylogs.api.Sample.*;
import static tests.heylogs.spi.FormatAssert.assertFormatCompliance;

class StylishFormatTest {

@Test
public void testCompliance() {
assertFormatCompliance(new StylishFormat());
}

@Test
public void testIdPattern() {
assertThat(new StylishFormat().getFormatId())
Expand Down
53 changes: 53 additions & 0 deletions heylogs-api/src/test/java/tests/heylogs/spi/FormatAssert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package tests.heylogs.spi;

import lombok.NonNull;
import nbbrd.heylogs.spi.Format;

import static java.util.Collections.emptyList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNullPointerException;

public final class FormatAssert {

private FormatAssert() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}

@SuppressWarnings("DataFlowIssue")
public static void assertFormatCompliance(@NonNull Format x) {
assertThat(x.getFormatId())
.matches(nbbrd.heylogs.spi.FormatLoader.ID_PATTERN);

assertThat(x.getFormatName())
.isNotEmpty()
.isNotNull();

assertThat(x.getFormatCategory())
.isNotEmpty()
.isNotNull();

assertThat(x.getSupportedFormatTypes())
.isNotNull();

assertThatNullPointerException()
.isThrownBy(() -> x.formatStatus(null, emptyList()));

assertThatNullPointerException()
.isThrownBy(() -> x.formatStatus(new StringBuilder(), null));

assertThatNullPointerException()
.isThrownBy(() -> x.formatResources(null, emptyList()));

assertThatNullPointerException()
.isThrownBy(() -> x.formatResources(new StringBuilder(), null));

assertThatNullPointerException()
.isThrownBy(() -> x.formatProblems(null, emptyList()));

assertThatNullPointerException()
.isThrownBy(() -> x.formatProblems(new StringBuilder(), null));

assertThat(x.getClass())
.isFinal();
}
}
5 changes: 5 additions & 0 deletions heylogs-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
</dependency>
<dependency>
<artifactId>heylogs-ext-json</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
</dependency>
<dependency>
<artifactId>heylogs-ext-semver</artifactId>
<groupId>${project.groupId}</groupId>
Expand Down
5 changes: 5 additions & 0 deletions heylogs-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
</dependency>
<dependency>
<artifactId>heylogs-ext-json</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
</dependency>
<dependency>
<artifactId>heylogs-ext-semver</artifactId>
<groupId>${project.groupId}</groupId>
Expand Down
71 changes: 71 additions & 0 deletions heylogs-ext-json/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.github.nbbrd.heylogs</groupId>
<artifactId>heylogs-parent</artifactId>
<version>0.8.2-SNAPSHOT</version>
</parent>

<artifactId>heylogs-ext-json</artifactId>
<packaging>jar</packaging>

<dependencies>
<!-- compile only -->
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.nbbrd.java-design-util</groupId>
<artifactId>java-design-processor</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.nbbrd.java-service-util</groupId>
<artifactId>java-service-processor</artifactId>
<scope>provided</scope>
</dependency>

<!-- compile and runtime -->
<dependency>
<artifactId>heylogs-api</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.11.0</version>
</dependency>

<!-- test only -->
<dependency>
<artifactId>heylogs-api</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
<classifier>tests</classifier>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package internal.heylogs;
package nbbrd.heylogs.ext.json;

import com.google.gson.*;
import lombok.NonNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,60 +1,59 @@
package internal.heylogs;
package nbbrd.heylogs.ext.json;

import nbbrd.heylogs.spi.Format;
import nbbrd.heylogs.spi.FormatLoader;
import org.junit.jupiter.api.Test;

import static tests.heylogs.api.Sample.*;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static tests.heylogs.api.Sample.*;
import static tests.heylogs.spi.FormatAssert.assertFormatCompliance;

class JsonFormatTest {

@Test
public void testIdPattern() {
assertThat(new JsonFormat().getFormatId())
.matches(FormatLoader.ID_PATTERN);
public void testCompliance() {
assertFormatCompliance(new JsonFormat());
}

@Test
public void testFormatProblems() {
Format x = new JsonFormat();

assertThat(writing(appendable -> x.formatProblems(appendable, singletonList(CHECK1))))
.isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "check1.json"));
.isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "/check1.json"));

assertThat(writing(appendable -> x.formatProblems(appendable, singletonList(CHECK2))))
.isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "check2.json"));
.isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "/check2.json"));

assertThat(writing(appendable -> x.formatProblems(appendable, singletonList(CHECK3))))
.isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "check3.json"));
.isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "/check3.json"));
}

@Test
public void testFormatStatus() {
Format x = new JsonFormat();

assertThat(writing(appendable -> x.formatStatus(appendable, singletonList(SCAN1))))
.isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "scan1.json"));
.isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "/scan1.json"));

assertThat(writing(appendable -> x.formatStatus(appendable, singletonList(SCAN2))))
.isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "scan2.json"));
.isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "/scan2.json"));
}

@Test
public void testFormatResource() {
Format x = new JsonFormat();

assertThat(writing(appendable -> x.formatResources(appendable, emptyList())))
.isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "resource1.json"));
.isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "/resource1.json"));

assertThat(writing(appendable -> x.formatResources(appendable, singletonList(RESOURCE1))))
.isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "resource2.json"));
.isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "/resource2.json"));

assertThat(writing(appendable -> x.formatResources(appendable, asList(RESOURCE1, RESOURCE2))))
.isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "resource3.json"));
.isEqualToNormalizingNewlines(contentOf(JsonFormatTest.class, "/resource3.json"));
}

}
5 changes: 5 additions & 0 deletions heylogs-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
</dependency>
<dependency>
<artifactId>heylogs-ext-json</artifactId>
<groupId>${project.groupId}</groupId>
<version>${project.version}</version>
</dependency>
<dependency>
<artifactId>heylogs-ext-semver</artifactId>
<groupId>${project.groupId}</groupId>
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
<module>heylogs-maven-plugin</module>
<module>heylogs-bom</module>
<module>heylogs-ext-github</module>
<module>heylogs-ext-json</module>
<module>heylogs-ext-semver</module>
</modules>

Expand Down

0 comments on commit 58c43ee

Please sign in to comment.