Compare commits

...
6 Commits
Author SHA1 Message Date
KKlochko df7c7e2b9f Add default constructor for SimpleTestReportFormatter.
continuous-integration/drone/tag Build is passing
2023-10-07 20:07:31 +03:00
KKlochko 28cd218bf7 Add Apache Commons Lang library. 2023-10-07 20:05:45 +03:00
KKlochko ff09435c04 Refactor the SimpleTestReportFormatter to use the interface.
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2023-10-06 22:11:19 +03:00
KKlochko 6d76646d16 Add the AbstractTestReportFormatter. 2023-10-06 22:11:01 +03:00
KKlochko 458091a7e2 Fix the encoding issue.
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2023-10-06 18:38:54 +03:00
KKlochko 696037c2d3 Add the SimpleTestReportFormatter.
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build is failing
2023-10-04 22:38:15 +03:00
5 changed files with 153 additions and 0 deletions
+5
View File
@@ -12,6 +12,10 @@ java {
}
}
compileJava {
options.encoding = 'UTF-8'
}
repositories {
// Spock releases are available from Maven Central
mavenCentral()
@@ -19,6 +23,7 @@ repositories {
dependencies {
implementation 'com.google.guava:guava:32.1.2-jre'
implementation 'org.apache.commons:commons-lang3:3.13.0'
// mandatory dependencies for using Spock
implementation platform('org.apache.groovy:groovy-bom:4.0.15')
implementation 'org.apache.groovy:groovy'
+5
View File
@@ -84,6 +84,11 @@
<artifactId>guava</artifactId>
<version>32.1.2-jre</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.13.0</version>
</dependency>
<!-- Mandatory dependencies for using Spock -->
<dependency>
<groupId>org.spockframework</groupId>
@@ -0,0 +1,33 @@
package space.kklochko.simple_jbdd.tests.reports.fmt;
import java.util.AbstractMap;
import java.util.ArrayList;
abstract public class AbstractTestReportFormatter {
private ArrayList<AbstractMap.SimpleEntry<String, String>> testMetaData;
private boolean isPassed;
public AbstractTestReportFormatter(ArrayList<AbstractMap.SimpleEntry<String, String>> testMetaData, boolean isPassed) {
setTestMetaData(testMetaData);
setPassed(isPassed);
}
public abstract String format();
public ArrayList<AbstractMap.SimpleEntry<String, String>> getTestMetaData() {
return testMetaData;
}
public void setTestMetaData(ArrayList<AbstractMap.SimpleEntry<String, String>> testMetaData) {
this.testMetaData = testMetaData;
}
public boolean isPassed() {
return isPassed;
}
public void setPassed(boolean passed) {
isPassed = passed;
}
}
@@ -0,0 +1,42 @@
package space.kklochko.simple_jbdd.tests.reports.fmt;
import space.kklochko.simple_jbdd.tests.Test;
import java.util.AbstractMap;
import java.util.ArrayList;
public class SimpleTestReportFormatter extends AbstractTestReportFormatter {
final private String passedIcon = "";
final private String failedIcon = "";
public SimpleTestReportFormatter() {
super(null, false);
}
public SimpleTestReportFormatter(ArrayList<AbstractMap.SimpleEntry<String, String>> testMetaData, boolean isPassed) {
super(testMetaData, isPassed);
}
public String format() {
String status = (isPassed()) ? getPassedIcon() : getFailedIcon();
String title = getTestMetaData().get(0).getValue();
String result = String.format("%s %s\n", status, title);
for(int i=1; i<getTestMetaData().size(); ++i) {
AbstractMap.SimpleEntry<String, String> pair = getTestMetaData().get(i);
result += String.format("\t%s %s\n", pair.getKey(), pair.getValue());
}
return result;
}
public String getPassedIcon() {
return passedIcon;
}
public String getFailedIcon() {
return failedIcon;
}
}
@@ -0,0 +1,68 @@
package space.kklochko.simple_jbdd.tests.reports.fmt
import space.kklochko.simple_jbdd.test_examples.tests.SimpleFailedThenTest
import space.kklochko.simple_jbdd.test_examples.tests.SimpleGivenWhenThenTest
import space.kklochko.simple_jbdd.test_examples.tests.SimpleThenTest
import space.kklochko.simple_jbdd.test_examples.tests.SimpleThenTestWithoutTitle
import space.kklochko.simple_jbdd.tests.commands.AbstractTestCommand
import space.kklochko.simple_jbdd.tests.commands.decorators.BlockDecorator
import space.kklochko.simple_jbdd.tests.factories.meta.TestCommandMetaDataFactory
import spock.lang.Narrative
import spock.lang.Specification
import spock.lang.Subject
import spock.lang.Title
@Narrative("""The formatter must generate a format for the test command metadata, so
those tests check if the formatter generate it right.
""")
@Title("Unit tests for SimpleTestReportFormatter")
class SimpleTestReportFormatterSpec extends Specification {
def "If the map of methods have one test block."() {
given: "I have a metaData"
def metaData = [
new AbstractMap.SimpleEntry<>("Title", "A simple test"),
new AbstractMap.SimpleEntry<>("Then", "Then block")
]
and: "I have the formatter object"
@Subject
def formatter = new SimpleTestReportFormatter(metaData, isPassed)
when: "Generate the format"
def format = formatter.format()
then: "The format must be the same"
expectedFormat == format
where: "Possible variants of tests"
isPassed || expectedFormat
true || "✓ A simple test\n\tThen Then block\n"
false || " A simple test\n\tThen Then block\n"
}
def "If the map of methods have GivenWhenThen blocks."() {
given: "I have a metaData"
def metaData = [
new AbstractMap.SimpleEntry<>("Title", "A simple test"),
new AbstractMap.SimpleEntry<>("Given", "Given block"),
new AbstractMap.SimpleEntry<>("When", "When block"),
new AbstractMap.SimpleEntry<>("Then", "Then block")
]
and: "I have the formatter object"
@Subject
def formatter = new SimpleTestReportFormatter(metaData, isPassed)
when: "Generate the format"
def format = formatter.format()
then: "The format must be the same"
expectedFormat == format
where: "Possible variants of tests"
isPassed || expectedFormat
true || "✓ A simple test\n\tGiven Given block\n\tWhen When block\n\tThen Then block\n"
false || " A simple test\n\tGiven Given block\n\tWhen When block\n\tThen Then block\n"
}
}