@Override public String lookup(String name) { try { Object value = evaluator.evaluate(name); if (value == null) { return ""; } else { return value.toString(); } } catch (Exception e) { resultRecorder.record(Result.FAILURE); return "<span class=\"failure\">" + e.toString() + "</span>"; } } }, "$(", ")", '\\');
private void rethrowFailFastException(ResultRecorder resultRecorder, Throwable t) { for (Class<? extends Throwable> exceptionType : failFastExceptions) { Throwable cause = t.getCause() == null? t:t.getCause(); if (exceptionType.isAssignableFrom(cause.getClass())) { FailFastException failFastException = new FailFastException("An exception was thrown in a @FailFast fixture", t); resultRecorder.recordFailFastException(failFastException); throw failFastException; } } } }
public void processExample(Evaluator evaluator, String example, ResultRecorder resultRecorder, Fixture fixture) { if (!hasExampleCommandNodes() || OUTER_EXAMPLE_NAME.equals(example)) { processNode(rootCommandNode, evaluator, resultRecorder, fixture); return; } for (ExampleCommandCall commandCall: examples) { if (commandCall.getExampleName().equals(example)) { resultRecorder.setForExample(true); processNode(commandCall.getCommandCall(), evaluator, resultRecorder, fixture); } } }
public void execute(CommandCall node, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { String exampleName = getExampleName(node); boolean isBeforeExample = isBeforeExample(node); resultRecorder.setSpecificationDescription( specificationDescriber.getDescription(node.getResource(), exampleName)); ImplementationStatus status = getImplementationStatus(node); if (!isBeforeExample && status != ImplementationStatus.IGNORED) { announceBeforeExample(exampleName, node.getElement(), resultRecorder, fixture); } try { resultRecorder.setImplementationStatus(status); if (status == ImplementationStatus.IGNORED) { resultRecorder.record(Result.IGNORED); } else { node.getChildren().processSequentially(evaluator, resultRecorder, fixture); } } catch (FailFastException f) { // Ignore - it'll be re-thrown later by the implementation status checker if necessary. } setupCommandForExample(node, resultRecorder, exampleName); if (!isBeforeExample && status != ImplementationStatus.IGNORED) { announceAfterExample(exampleName, node.getElement(), resultRecorder, fixture); } }
public static void setupCommandForExample(CommandCall node, ResultRecorder resultRecorder, String exampleName) { node.getElement().addAttribute("id", exampleName); // let's be really nice and add the implementation status text into the element itself. ImplementationStatusChecker checker = ImplementationStatusChecker.implementationStatusCheckerFor(resultRecorder.getImplementationStatus()); Element fixtureNode = new Element("p"); fixtureNode.appendText(checker.printNoteToString()); node.getElement().prependChild(fixtureNode); }
@Override public void execute(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { if (specificationDescriber != null) { resultRecorder.setSpecificationDescription(getSpecificationDescription(commandCall)); } try { announceBeforeOuterExampleEvent(commandCall.getElement(), (SummarizingResultRecorder) resultRecorder, fixture); commandCall.getChildren().processSequentially(evaluator, resultRecorder, fixture); } catch (FailFastException e) { // Ignore - it'll be re-thrown later if necessary. } finally { announceAfterOuterExampleEvent(commandCall.getElement(), (SummarizingResultRecorder) resultRecorder, fixture); } }
public void execute(CommandCall node, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { String exampleName = getExampleName(node); boolean isBeforeExample = isBeforeExample(node); resultRecorder.setSpecificationDescription( specificationDescriber.getDescription(node.getResource(), exampleName)); ImplementationStatus status = getImplementationStatus(node); if (!isBeforeExample && status != ImplementationStatus.IGNORED) { announceBeforeExample(exampleName, node.getElement(), resultRecorder, fixture); } try { resultRecorder.setImplementationStatus(status); if (status == ImplementationStatus.IGNORED) { resultRecorder.record(Result.IGNORED); } else { node.getChildren().processSequentially(evaluator, resultRecorder, fixture); } } catch (FailFastException f) { // Ignore - it'll be re-thrown later by the implementation status checker if necessary. } setupCommandForExample(node, resultRecorder, exampleName); if (!isBeforeExample && status != ImplementationStatus.IGNORED) { announceAfterExample(exampleName, node.getElement(), resultRecorder, fixture); } }
public static void setupCommandForExample(CommandCall node, ResultRecorder resultRecorder, String exampleName) { node.getElement().addAttribute("id", exampleName); // let's be really nice and add the implementation status text into the element itself. ImplementationStatusChecker checker = ImplementationStatusChecker.implementationStatusCheckerFor(resultRecorder.getImplementationStatus()); Element fixtureNode = new Element("p"); fixtureNode.appendText(checker.printNoteToString()); node.getElement().prependChild(fixtureNode); }
@Override public void execute(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { if (specificationDescriber != null) { resultRecorder.setSpecificationDescription(getSpecificationDescription(commandCall)); } try { announceBeforeOuterExampleEvent(commandCall.getElement(), (SummarizingResultRecorder) resultRecorder, fixture); commandCall.getChildren().processSequentially(evaluator, resultRecorder, fixture); } catch (FailFastException e) { // Ignore - it'll be re-thrown later if necessary. } finally { announceAfterOuterExampleEvent(commandCall.getElement(), (SummarizingResultRecorder) resultRecorder, fixture); } }
public void call(Runner runner, Resource resource, String href, ResultAnnouncer announcer, ResultRecorder resultRecorder) { try { ResultSummary result = runner.execute(resource, href); announcer.announce(result); resultRecorder.record(result); } catch (FailFastException e) { announcer.announceException(e); resultRecorder.record(Result.EXCEPTION); // we let fail fast exceptions percolate up through the system throw e; } catch (Throwable e) { announcer.announceException(e); resultRecorder.record(Result.EXCEPTION); } } }
public void processExample(Evaluator evaluator, String example, ResultRecorder resultRecorder, Fixture fixture) { if (!hasExampleCommandNodes() || OUTER_EXAMPLE_NAME.equals(example)) { processNode(rootCommandNode, evaluator, resultRecorder, fixture); return; } for (ExampleCommandCall commandCall: examples) { if (commandCall.getExampleName().equals(example)) { resultRecorder.setForExample(true); processNode(commandCall.getCommandCall(), evaluator, resultRecorder, fixture); } } }
private void rethrowFailFastException(ResultRecorder resultRecorder, Throwable t) { for (Class<? extends Throwable> exceptionType : failFastExceptions) { Throwable cause = t.getCause() == null? t:t.getCause(); if (exceptionType.isAssignableFrom(cause.getClass())) { FailFastException failFastException = new FailFastException("An exception was thrown in a @FailFast fixture", t); resultRecorder.recordFailFastException(failFastException); throw failFastException; } } } }
public void call(Runner runner, Resource resource, String href, ResultAnnouncer announcer, ResultRecorder resultRecorder) { try { ResultSummary result = runner.execute(resource, href); announcer.announce(result); resultRecorder.record(result); } catch (FailFastException e) { announcer.announceException(e); resultRecorder.record(Result.EXCEPTION); // we let fail fast exceptions percolate up through the system throw e; } catch (Throwable e) { announcer.announceException(e); resultRecorder.record(Result.EXCEPTION); } } }
@Override protected void processTrueResult(CommandCall commandCall, ResultRecorder resultRecorder) { resultRecorder.record(Result.SUCCESS); announceSuccess(commandCall.getElement()); } }
@Override protected void processFalseResult(CommandCall commandCall, ResultRecorder resultRecorder) { resultRecorder.record(Result.SUCCESS); announceSuccess(commandCall.getElement()); }
@Override protected void processFalseResult(CommandCall commandCall, ResultRecorder resultRecorder) { resultRecorder.record(Result.SUCCESS); announceSuccess(commandCall.getElement()); }
@Override protected void processTrueResult(CommandCall commandCall, ResultRecorder resultRecorder) { resultRecorder.record(Result.SUCCESS); announceSuccess(commandCall.getElement()); } }
@Override public void verify(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { Check.isFalse(commandCall.hasChildCommands(), "Nesting commands inside an 'assertEquals' is not supported"); Element element = commandCall.getElement(); Object actual = evaluator.evaluate(commandCall.getExpression()); String expected = element.getText(); if (comparator.compare(actual, expected) == 0) { resultRecorder.record(Result.SUCCESS); announceSuccess(element); } else { resultRecorder.record(Result.FAILURE); announceFailure(element, expected, actual); } }
@Override protected void processTrueResult(CommandCall commandCall, ResultRecorder resultRecorder) { resultRecorder.record(Result.FAILURE); String expected = commandCall.getElement().getText(); announceFailure(commandCall.getElement(), expected, "== true"); }
@Override public void verify(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder, Fixture fixture) { Check.isFalse(commandCall.hasChildCommands(), "Nesting commands inside an 'assertEquals' is not supported"); Element element = commandCall.getElement(); Object actual = evaluator.evaluate(commandCall.getExpression()); String expected = element.getText(); if (comparator.compare(actual, expected) == 0) { resultRecorder.record(Result.SUCCESS); announceSuccess(element); } else { resultRecorder.record(Result.FAILURE); announceFailure(element, expected, actual); } }