Add the SimpleTestReportFormatter.
continuous-integration/drone/push Build is failing Details
continuous-integration/drone/tag Build is failing Details

main 0.8.0
KKlochko 2 years ago
parent 189ba44c1d
commit 696037c2d3

@ -0,0 +1,57 @@
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 {
private ArrayList<AbstractMap.SimpleEntry<String, String>> testMetaData;
private boolean isPassed;
final private String passedIcon = "✓";
final private String failedIcon = "";
public SimpleTestReportFormatter(ArrayList<AbstractMap.SimpleEntry<String, String>> testMetaData, boolean isPassed) {
setTestMetaData(testMetaData);
setPassed(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 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;
}
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"
}
}
Loading…
Cancel
Save