Skip to content

Commit

Permalink
fix: Spotless applied
Browse files Browse the repository at this point in the history
  • Loading branch information
nandorholozsnyak committed Jan 24, 2022
1 parent a223b8d commit e64038d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
13 changes: 9 additions & 4 deletions src/main/java/dev/jbang/catalog/TemplateProperty.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package dev.jbang.catalog;

import com.google.gson.annotations.SerializedName;

import java.util.Objects;

import com.google.gson.annotations.SerializedName;

/**
* Class representing a property in the JBang catalog templates.
*/
public class TemplateProperty {

private String description;
Expand Down Expand Up @@ -33,8 +36,10 @@ public void setDefaultValue(String defaultValue) {

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
TemplateProperty that = (TemplateProperty) o;
return Objects.equals(description, that.description) && Objects.equals(defaultValue, that.defaultValue);
}
Expand Down
39 changes: 23 additions & 16 deletions src/test/java/dev/jbang/cli/TestTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
import java.nio.file.Paths;
import java.util.AbstractMap;

import dev.jbang.catalog.TemplateProperty;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import dev.jbang.BaseTest;
import dev.jbang.Settings;
import dev.jbang.catalog.Catalog;
import dev.jbang.catalog.Template;
import dev.jbang.catalog.TemplateProperty;
import dev.jbang.util.Util;

import picocli.CommandLine;
Expand Down Expand Up @@ -189,10 +189,11 @@ void testGetTemplateThreeWithProperties() throws IOException {
assertThat(template.fileRefs.values(), hasItems("tpl2/file2_1.java", "tpl2/file2_2.java"));
assertThat(template.properties.entrySet(), hasItems(
new AbstractMap.SimpleEntry<>("test-key", new TemplateProperty(null, null)),
new AbstractMap.SimpleEntry<>("test-key-with-description", new TemplateProperty("This is a test description", null)),
new AbstractMap.SimpleEntry<>("test-key-with-description-and-default-value", new TemplateProperty("This is a test description with default value", "2.11")),
new AbstractMap.SimpleEntry<>("test-key-with-default-value", new TemplateProperty(null, "3.12"))
));
new AbstractMap.SimpleEntry<>("test-key-with-description",
new TemplateProperty("This is a test description", null)),
new AbstractMap.SimpleEntry<>("test-key-with-description-and-default-value",
new TemplateProperty("This is a test description with default value", "2.11")),
new AbstractMap.SimpleEntry<>("test-key-with-default-value", new TemplateProperty(null, "3.12"))));
}

@Test
Expand Down Expand Up @@ -238,8 +239,7 @@ void testAddWithSingleProperty() throws IOException {
is(true));
Template name = Template.get("template-with-single-property");
assertThat(name.properties.entrySet(), hasItems(
new AbstractMap.SimpleEntry<>("new-test-key", new TemplateProperty(null, null))
));
new AbstractMap.SimpleEntry<>("new-test-key", new TemplateProperty(null, null))));
}

@Test
Expand All @@ -249,14 +249,16 @@ void testAddWithSingleComplexProperty() throws IOException {
Files.write(testFile, "// Test file".getBytes());
assertThat(Files.isRegularFile(Paths.get(cwd.toString(), Catalog.JBANG_CATALOG_JSON)), is(false));
JBang jbang = new JBang();
new CommandLine(jbang).execute("template", "add", "-f", cwd.toString(), "--name=template-with-single-complex-property",
"-d", "Description of the template", "-P", "new-test-key:This is a description for the property key:3.14", testFile.toString());
new CommandLine(jbang).execute("template", "add", "-f", cwd.toString(),
"--name=template-with-single-complex-property",
"-d", "Description of the template", "-P",
"new-test-key:This is a description for the property key:3.14", testFile.toString());
assertThat(Files.isRegularFile(Paths.get(cwd.toString(), Catalog.JBANG_CATALOG_JSON)),
is(true));
Template name = Template.get("template-with-single-complex-property");
assertThat(name.properties.entrySet(), hasItems(
new AbstractMap.SimpleEntry<>("new-test-key", new TemplateProperty("This is a description for the property key", "3.14"))
));
new AbstractMap.SimpleEntry<>("new-test-key",
new TemplateProperty("This is a description for the property key", "3.14"))));
}

@Test
Expand All @@ -266,14 +268,19 @@ void testAddWithMultipleComplexProperties() throws IOException {
Files.write(testFile, "// Test file".getBytes());
assertThat(Files.isRegularFile(Paths.get(cwd.toString(), Catalog.JBANG_CATALOG_JSON)), is(false));
JBang jbang = new JBang();
new CommandLine(jbang).execute("template", "add", "-f", cwd.toString(), "--name=template-with-complex-properties",
"-d", "Description of the template", "-P", "new-test-key:This is a description for the property key:3.14", "--property", "second-test-key:This is another description for the second property key:Non-Blocker", testFile.toString());
new CommandLine(jbang).execute("template", "add", "-f", cwd.toString(),
"--name=template-with-complex-properties",
"-d", "Description of the template", "-P",
"new-test-key:This is a description for the property key:3.14", "--property",
"second-test-key:This is another description for the second property key:Non-Blocker",
testFile.toString());
assertThat(Files.isRegularFile(Paths.get(cwd.toString(), Catalog.JBANG_CATALOG_JSON)),
is(true));
Template name = Template.get("template-with-complex-properties");
assertThat(name.properties.entrySet(), hasItems(
new AbstractMap.SimpleEntry<>("new-test-key", new TemplateProperty("This is a description for the property key", "3.14")),
new AbstractMap.SimpleEntry<>("second-test-key", new TemplateProperty("This is another description for the second property key", "Non-Blocker"))
));
new AbstractMap.SimpleEntry<>("new-test-key",
new TemplateProperty("This is a description for the property key", "3.14")),
new AbstractMap.SimpleEntry<>("second-test-key", new TemplateProperty(
"This is another description for the second property key", "Non-Blocker"))));
}
}

0 comments on commit e64038d

Please sign in to comment.