@Test public void shouldGenerateContent() { String expectedContent = "<Patterns>" + "<Pattern>Method1</Pattern>" + "<Pattern>Method2</Pattern>" + "</Patterns>"; final CommandLineSetup setup = new CommandLineSetup("tool", Collections.<CommandLineArgument>emptyList(), Collections.<CommandLineResource>emptyList()); myCtx.checking(new Expectations() {{ oneOf(myRunnerParametersService).tryGetRunnerParameter(Constants.THRESHOLDS_VAR); will(returnValue("thresholds")); oneOf(myReportPatternsParser).parse("thresholds"); will(returnValue(new Metrics(Arrays.asList(new Metric("Method1", "100", "200"), new Metric("Method2", "200", "300"))))); }}); final PatternsGenerator instance = createInstance(); final String content = instance.create(new Context(setup, new File("a"), new File("b"), new File("c"), new File("s"))); myCtx.assertIsSatisfied(); then(content.trim().replace("\n", "").replace("\r", "")).isEqualTo(expectedContent.trim().replace("\n", "").replace("\r", "")); }
@NotNull @Override public String create(@NotNull final Context context) { final Document doc = myDocumentManager.createDocument(); final Element patternsElement = doc.createElement(PATTERNS_ELEMENT); String thresholdsStr = myParametersService.tryGetRunnerParameter(Constants.THRESHOLDS_VAR); if(!StringUtil.isEmptyOrSpaces(thresholdsStr)) { final Metrics metrics = myThresholdsParser.parse(thresholdsStr); for(Metric metric : metrics.getMetrics()) { final Element patternElement = createSimpleElement(doc, PATTERN_ELEMENT, metric.getMethodName()); patternsElement.appendChild(patternElement); } } doc.appendChild(patternsElement); return myDocumentManager.convertDocumentToString(doc, Collections.<String, String>emptyMap()); }
PatternsGenerator implements ResourceGenerator<Context> { @NotNull @Override public String create(@NotNull final Context context) { final Document doc = myDocumentManager.createDocument(); final Element patternsElement = doc.createElement(PATTERNS_ELEMENT); String thresholdsStr = myParametersService.tryGetRunnerParameter(Constants.THRESHOLDS_VAR); if(!StringUtil.isEmptyOrSpaces(thresholdsStr)) { final Metrics metrics = myThresholdsParser.parse(thresholdsStr); for(Metric metric : metrics.getMetrics()) { final Element patternElement = createSimpleElement(doc, PATTERN_ELEMENT, metric.getMethodName()); patternsElement.appendChild(patternElement); } } doc.appendChild(patternsElement); return myDocumentManager.convertDocumentToString(doc, Collections.<String, String>emptyMap()); } }
PatternsGenerator implements ResourceGenerator<Context> { @NotNull @Override public String create(@NotNull final Context context) { final Document doc = myDocumentManager.createDocument(); final Element patternsElement = doc.createElement(PATTERNS_ELEMENT); String thresholdsStr = myParametersService.tryGetRunnerParameter(Constants.THRESHOLDS_VAR); if(!StringUtil.isEmptyOrSpaces(thresholdsStr)) { final Metrics metrics = myThresholdsParser.parse(thresholdsStr); for(Metric metric : metrics.getMetrics()) { final Element patternElement = createSimpleElement(doc, PATTERN_ELEMENT, metric.getMethodName()); patternsElement.appendChild(patternElement); } } doc.appendChild(patternsElement); return myDocumentManager.convertDocumentToString(doc, Collections.<String, String>emptyMap()); } PatternsGenerator(
    @NotNull final TextParser<Metrics> thresholdsParser,
    @NotNull final RunnerParametersService parametersService,
    @NotNull final XmlDocumentManager documentManager); }
PatternsGenerator implements ResourceGenerator<Context> { @NotNull @Override public String create(@NotNull final Context context) { final Document doc = myDocumentManager.createDocument(); final Element patternsElement = doc.createElement(PATTERNS_ELEMENT); String thresholdsStr = myParametersService.tryGetRunnerParameter(Constants.THRESHOLDS_VAR); if(!StringUtil.isEmptyOrSpaces(thresholdsStr)) { final Metrics metrics = myThresholdsParser.parse(thresholdsStr); for(Metric metric : metrics.getMetrics()) { final Element patternElement = createSimpleElement(doc, PATTERN_ELEMENT, metric.getMethodName()); patternsElement.appendChild(patternElement); } } doc.appendChild(patternsElement); return myDocumentManager.convertDocumentToString(doc, Collections.<String, String>emptyMap()); } PatternsGenerator(
    @NotNull final TextParser<Metrics> thresholdsParser,
    @NotNull final RunnerParametersService parametersService,
    @NotNull final XmlDocumentManager documentManager); @NotNull @Override String create(@NotNull final Context context); }
PatternsGenerator implements ResourceGenerator<Context> { @NotNull @Override public String create(@NotNull final Context context) { final Document doc = myDocumentManager.createDocument(); final Element patternsElement = doc.createElement(PATTERNS_ELEMENT); String thresholdsStr = myParametersService.tryGetRunnerParameter(Constants.THRESHOLDS_VAR); if(!StringUtil.isEmptyOrSpaces(thresholdsStr)) { final Metrics metrics = myThresholdsParser.parse(thresholdsStr); for(Metric metric : metrics.getMetrics()) { final Element patternElement = createSimpleElement(doc, PATTERN_ELEMENT, metric.getMethodName()); patternsElement.appendChild(patternElement); } } doc.appendChild(patternsElement); return myDocumentManager.convertDocumentToString(doc, Collections.<String, String>emptyMap()); } PatternsGenerator(
    @NotNull final TextParser<Metrics> thresholdsParser,
    @NotNull final RunnerParametersService parametersService,
    @NotNull final XmlDocumentManager documentManager); @NotNull @Override String create(@NotNull final Context context);  }