private void assertThatDateIsConvertedWithFormat(
     final ParameterConverters parameterConverters, final DateFormat dateFormat) {
   final String date = "2010-10-10";
   try {
     assertThat(
         (Date) parameterConverters.convert(date, Date.class), equalTo(dateFormat.parse(date)));
   } catch (final ParseException e) {
     Assert.fail();
   }
 }
  public PreferredConfiguration(String storyUrl) {
    URL codeLocation = CodeLocations.codeLocationFromURL(storyUrl);
    Properties viewResources = new Properties();
    StoryPathResolver storyPathResolver = new UnderscoredCamelCaseResolver(".story");
    StoryReporterBuilder srb =
        new StoryReporterBuilder()
            .withDefaultFormats()
            .withViewResources(viewResources)
            .withFormats(Format.XML, Format.CONSOLE, Format.HTML, Format.IDE_CONSOLE, Format.TXT)
            .withFailureTrace(Config.displayStackTrace());

    // Setup parameters
    ParameterConverters parameterConverters =
        new ParameterConverters()
            .addConverters(
                new ExamplesTableConverter(
                    new ExamplesTableFactory(new LoadFromRelativeFile(codeLocation))));
    // factory to allow parameter conversion and loading from external
    // resources (used by StoryParser too)
    ExamplesTableFactory examplesTableFactory =
        new ExamplesTableFactory(
            new LocalizedKeywords(), new LoadFromRelativeFile(codeLocation), parameterConverters);
    // add custom coverters
    parameterConverters.addConverters(new ExamplesTableConverter(examplesTableFactory));
    viewResources.put("decorateNonHtml", "true");
    useStoryControls(
            new StoryControls()
                .doDryRun(false)
                .doSkipScenariosAfterFailure(false)
                .doResetStateBeforeStory(true)
                .useStoryMetaPrefix("story_")
                .useScenarioMetaPrefix("scenario_"))
        .useStoryLoader(new LoadFromRelativeFile(codeLocation))
        .useStoryReporterBuilder(srb)
        .useStoryPathResolver(storyPathResolver)
        .useStepMonitor(new SilentStepMonitor())
        .useStoryParser(new RegexStoryParser(examplesTableFactory))
        .useParameterConverters(parameterConverters);
  }
Example #3
0
 @Override
 public Configuration configuration() {
   Class<? extends Embeddable> embeddableClass = this.getClass();
   // Start from default ParameterConverters instance
   ParameterConverters parameterConverters = new ParameterConverters();
   // factory to allow parameter conversion and loading from external resources (used by
   // StoryParser too)
   ExamplesTableFactory examplesTableFactory =
       new ExamplesTableFactory(
           new LocalizedKeywords(), new LoadFromClasspath(embeddableClass), parameterConverters);
   // add custom converters
   parameterConverters.addConverters(
       new DateConverter(new SimpleDateFormat("yyyy-MM-dd")),
       new ExamplesTableConverter(examplesTableFactory));
   return new MostUsefulConfiguration()
       .useStoryLoader(new LoadFromClasspath(embeddableClass))
       .useStoryParser(new RegexStoryParser(examplesTableFactory))
       .useStoryReporterBuilder(
           new StoryReporterBuilder()
               .withCodeLocation(CodeLocations.codeLocationFromClass(embeddableClass))
               .withDefaultFormats()
               .withFormats(CONSOLE, TXT, HTML, XML))
       .useParameterConverters(parameterConverters);
 }
 private void assertThatCustomObjectIsConverted(final ParameterConverters parameterConverters) {
   assertThat(
       ((CustomObject) parameterConverters.convert("value", CustomObject.class)).toString(),
       equalTo(new CustomObject("value").toString()));
 }