use of org.jbehave.core.i18n.LocalizedKeywords in project jbehave-core by jbehave.
the class PrintStreamOutputBehaviour method shouldUseCustomDateFormatInOutcomesTable.
@Test
public void shouldUseCustomDateFormatInOutcomesTable() {
// Given
OutputStream out = new ByteArrayOutputStream();
StoryReporter reporter = new TxtOutput(new PrintStream(out));
// When
OutcomesTable outcomesTable = new OutcomesTable(new LocalizedKeywords(), "dd/MM/yyyy");
Date actualDate = StoryNarrator.dateFor("01/01/2011");
Date expectedDate = StoryNarrator.dateFor("02/01/2011");
outcomesTable.addOutcome("A wrong date", actualDate, new IsDateEqual(expectedDate, outcomesTable.getDateFormat()));
try {
outcomesTable.verify();
} catch (UUIDExceptionWrapper e) {
reporter.failedOutcomes("some step", ((OutcomesFailed) e.getCause()).outcomesTable());
}
// Then
String expected = "some step (FAILED)\n" + "(org.jbehave.core.model.OutcomesTable$OutcomesFailed)\n" + "|Description|Value|Matcher|Verified|\n" + "|A wrong date|01/01/2011|\"02/01/2011\"|No|\n";
assertThat(dos2unix(out.toString()), equalTo(expected));
}
use of org.jbehave.core.i18n.LocalizedKeywords in project jbehave-core by jbehave.
the class PrintStreamOutputBehaviour method shouldReportEventsToPrintStreamInItalian.
@Test
public void shouldReportEventsToPrintStreamInItalian() {
// Given
UUIDExceptionWrapper exception = new UUIDExceptionWrapper(new RuntimeException("Lasciate in pace i miei soldi!"));
OutputStream out = new ByteArrayOutputStream();
LocalizedKeywords keywords = new LocalizedKeywords(Locale.ITALIAN);
StoryReporter reporter = new TxtOutput(new PrintStream(out), new Properties(), keywords, true);
// When
reporter.successful("Dato che ho un saldo di $50");
reporter.successful("Quando richiedo $20");
reporter.failed("Quando chiedo a Liz un prestito di $100", exception);
reporter.pending("Allora dovrei avere un saldo di $30");
reporter.notPerformed("Allora dovrei avere $20");
// Then
String expected = "Dato che ho un saldo di $50\n" + "Quando richiedo $20\n" + "Quando chiedo a Liz un prestito di $100 (FALLITO)\n" + "(java.lang.RuntimeException: Lasciate in pace i miei soldi!)\n" + "Allora dovrei avere un saldo di $30 (IN SOSPESO)\n" + "Allora dovrei avere $20 (NON ESEGUITO)\n";
assertThat(dos2unix(out.toString()), equalTo(expected));
}
use of org.jbehave.core.i18n.LocalizedKeywords in project jbehave-core by jbehave.
the class PrintStreamOutputBehaviour method shouldSuppressStackTraceForKnownFailure.
@Test
public void shouldSuppressStackTraceForKnownFailure() {
// Given
final OutputStream out = new ByteArrayOutputStream();
PrintStreamFactory factory = new PrintStreamFactory() {
public PrintStream createPrintStream() {
return new PrintStream(out);
}
};
TxtOutput reporter = new TxtOutput(factory.createPrintStream(), new Properties(), new LocalizedKeywords(), true);
reporter.failed("Then I should have a balance of $30", new UUIDExceptionWrapper(new MyKnownFailure()));
reporter.afterScenario();
assertThat(dos2unix(out.toString()), equalTo("Then I should have a balance of $30 (FAILED)\n" + "(org.jbehave.core.reporters.PrintStreamOutputBehaviour$MyKnownFailure)\n\n" + ""));
}
use of org.jbehave.core.i18n.LocalizedKeywords in project jbehave-core by jbehave.
the class PrintStreamOutputBehaviour method shouldOutputStoryJson.
@Test
public void shouldOutputStoryJson() throws IOException, SAXException {
// Given
String name = "stream-story.json";
File file = new File("target/" + name);
StoryReporter reporter = new JsonOutput(new FilePrintStreamFactory.FilePrintStream(file, false), new LocalizedKeywords());
// When
StoryNarrator.narrateAnInterestingStory(reporter, false);
// Then
assertFileOutputIsSameAs(file, name);
validateFileOutput(file);
}
use of org.jbehave.core.i18n.LocalizedKeywords in project jbehave-core by jbehave.
the class PrintStreamOutputBehaviour method shouldReportFailureTraceWhenToldToDoSo.
@Test
public void shouldReportFailureTraceWhenToldToDoSo() {
// Given
UUIDExceptionWrapper exception = new UUIDExceptionWrapper(new RuntimeException("Leave my money alone!"));
OutputStream stackTrace = new ByteArrayOutputStream();
exception.getCause().printStackTrace(new PrintStream(stackTrace));
OutputStream out = new ByteArrayOutputStream();
TxtOutput reporter = new TxtOutput(new PrintStream(out), new Properties(), new LocalizedKeywords(), true);
// When
reporter.beforeScenario(new Scenario("A title", Meta.EMPTY));
reporter.successful("Given I have a balance of $50");
reporter.successful("When I request $20");
reporter.failed("When I ask Liz for a loan of $100", exception);
reporter.pending("Then I should have a balance of $30");
reporter.notPerformed("Then I should have $20");
reporter.afterScenario();
// Then
String expected = "Scenario: A title\n" + "Given I have a balance of $50\n" + "When I request $20\n" + "When I ask Liz for a loan of $100 (FAILED)\n" + "(java.lang.RuntimeException: Leave my money alone!)\n" + "Then I should have a balance of $30 (PENDING)\n" + "Then I should have $20 (NOT PERFORMED)\n" + "\n";
String actual = dos2unix(out.toString());
assertThat(actual, containsString(expected));
assertThat(actual, containsString("at org.jbehave.core.reporters.PrintStreamOutputBehaviour.shouldReportFailureTraceWhenToldToDoSo("));
// Given
out = new ByteArrayOutputStream();
reporter = new TxtOutput(new PrintStream(out));
// When
reporter.beforeScenario(new Scenario("A title", Meta.EMPTY));
reporter.successful("Given I have a balance of $50");
reporter.successful("When I request $20");
reporter.failed("When I ask Liz for a loan of $100", exception);
reporter.pending("Then I should have a balance of $30");
reporter.notPerformed("Then I should have $20");
reporter.afterScenario();
// Then
assertThat(out.toString().contains(stackTrace.toString()), is(false));
}
Aggregations