use of org.jbehave.core.io.StoryLocation in project jbehave-core by jbehave.
the class FilePrintStreamFactoryBehaviour method shouldAllowOverrideOfDefaultConfiguration.
@Test
public void shouldAllowOverrideOfDefaultConfiguration() {
// Given
URL codeLocation = CodeLocations.codeLocationFromClass(this.getClass());
String storyPath = "org/jbehave/examples/trader/stories/my_given.story";
FileConfiguration configuration = new FileConfiguration("ext");
// When
FilePrintStreamFactory factory = new FilePrintStreamFactory(new StoryLocation(codeLocation, storyPath), configuration);
assertThat(factory.configuration(), equalTo(configuration));
FileConfiguration newConfiguration = new FileConfiguration();
factory.useConfiguration(newConfiguration);
// Then
assertThat(factory.configuration(), not(equalTo(configuration)));
assertThat(factory.configuration().toString(), containsString(FileConfiguration.EXTENSION));
assertThat(factory.configuration().toString(), containsString(FileConfiguration.RELATIVE_DIRECTORY));
}
use of org.jbehave.core.io.StoryLocation in project jbehave-core by jbehave.
the class FilePrintStreamFactoryBehaviour method shouldFailIfPrintStreamCannotBeCreated.
@Test(expected = PrintStreamCreationFailed.class)
public void shouldFailIfPrintStreamCannotBeCreated() {
// Given
URL codeLocation = CodeLocations.codeLocationFromClass(this.getClass());
String storyPath = "org/jbehave/examples/trader/stories/my_given.story";
FileConfiguration configuration = new FileConfiguration("ext");
FilePrintStreamFactory factory = new FilePrintStreamFactory(new StoryLocation(codeLocation, storyPath), configuration) {
protected File outputDirectory() {
return new File((String) null);
}
};
// When
factory.createPrintStream();
// Then fail as expected
}
use of org.jbehave.core.io.StoryLocation in project jbehave-core by jbehave.
the class FilePrintStreamFactoryBehaviour method assertThatOutputNameIs.
private void assertThatOutputNameIs(String storyPath, String outputName, FilePathResolver pathResolver) {
// Given
URL codeLocation = CodeLocations.codeLocationFromClass(this.getClass());
String extension = "ext";
FileConfiguration configuration = (pathResolver != null ? new FileConfiguration("", extension, pathResolver) : new FileConfiguration(extension));
// When
FilePrintStreamFactory factory = new FilePrintStreamFactory(new StoryLocation(codeLocation, storyPath), configuration);
// Then
assertThat(factory.outputName(), equalTo(outputName));
}
use of org.jbehave.core.io.StoryLocation in project jbehave-core by jbehave.
the class StoryReporterBuilderBehaviour method shouldBuildWithCustomReporterForAGivenFormat.
@Test
public void shouldBuildWithCustomReporterForAGivenFormat() throws IOException {
// Given
String storyPath = storyPath(MyStory.class);
final FilePrintStreamFactory factory = new FilePrintStreamFactory(new StoryLocation(CodeLocations.codeLocationFromClass(MyStory.class), storyPath));
final StoryReporter txtReporter = new TxtOutput(factory.createPrintStream(), new Properties(), new LocalizedKeywords(), true);
StoryReporterBuilder builder = new StoryReporterBuilder() {
@Override
public StoryReporter reporterFor(String storyPath, org.jbehave.core.reporters.Format format) {
if (format == org.jbehave.core.reporters.Format.TXT) {
factory.useConfiguration(new FilePrintStreamFactory.FileConfiguration("text"));
return txtReporter;
} else {
return super.reporterFor(storyPath, format);
}
}
};
// When
StoryReporter reporter = builder.withDefaultFormats().withFormats(TXT).build(storyPath);
// Then
assertThat(reporter, instanceOf(ConcurrentStoryReporter.class));
StoryReporter delegate = ((ConcurrentStoryReporter) reporter).getDelegate();
assertThat(delegate, instanceOf(DelegatingStoryReporter.class));
Collection<StoryReporter> delegates = ((DelegatingStoryReporter) delegate).getDelegates();
assertThat(delegates.size(), equalTo(2));
assertThat(delegates.contains(txtReporter), is(true));
}
use of org.jbehave.core.io.StoryLocation in project jbehave-core by jbehave.
the class StoryReporterBuilderBehaviour method shouldBuildWithCustomReportersAsProvidedFormat.
@Test
public void shouldBuildWithCustomReportersAsProvidedFormat() throws IOException {
// Given
String storyPath = storyPath(MyStory.class);
FilePrintStreamFactory factory = new FilePrintStreamFactory(new StoryLocation(CodeLocations.codeLocationFromClass(MyStory.class), storyPath));
StoryReporter txtReporter = new TxtOutput(factory.createPrintStream(), new Properties(), new LocalizedKeywords(), true);
StoryReporter htmlReporter = new TxtOutput(factory.createPrintStream(), new Properties(), new LocalizedKeywords(), true);
StoryReporterBuilder builder = new StoryReporterBuilder();
// When
StoryReporter reporter = builder.withReporters(txtReporter, htmlReporter).build(storyPath);
// Then
assertThat(reporter, instanceOf(ConcurrentStoryReporter.class));
StoryReporter delegate = ((ConcurrentStoryReporter) reporter).getDelegate();
assertThat(delegate, instanceOf(DelegatingStoryReporter.class));
Collection<StoryReporter> delegates = ((DelegatingStoryReporter) delegate).getDelegates();
assertThat(delegates.size(), equalTo(2));
assertThat(delegates.contains(txtReporter), is(true));
assertThat(delegates.contains(htmlReporter), is(true));
}
Aggregations