public Resource locateSpecification(Fixture fixture) {
    Check.notNull(fixture, "Fixture is null");
    String fixturePath = fixture.getFixturePathWithoutSuffix();
    String resourcePath = "/" + fixturePath + "." + specificationSuffix;

    return new Resource(resourcePath);
  }
예제 #2
0
 public void write(Resource resource, String s) throws IOException {
   Check.notNull(resource, "resource is null");
   mkdirs(resource);
   FileOutputStream os = new FileOutputStream(getFile(resource));
   Writer writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
   try {
     writer.write(s);
   } finally {
     writer.close();
     os.close();
   }
 }
예제 #3
0
  public void beforeParsing(Document document) {
    nu.xom.Element html = document.getRootElement();
    nu.xom.Element head = html.getFirstChildElement("head");
    Check.notNull(head, "<head> section is missing from document");
    script = new nu.xom.Element("script");
    script.addAttribute(new Attribute("type", "text/javascript"));

    // Fix for Issue #26: Strict XHTML DTD requires an explicit end tag for <script> element
    // Thanks to Matthias Schwegler for reporting and supplying a fix for this.
    script.appendChild("");

    head.appendChild(script);
  }
예제 #4
0
 public void copyTo(Resource resource, InputStream inputStream) throws IOException {
   Check.notNull(resource, "resource is null");
   mkdirs(resource);
   File outputFile = getFile(resource);
   // Do not overwrite if a recent copy already exists
   if (outputFile.exists() && isFreshEnough(outputFile)) {
     return;
   }
   OutputStream outputStream = createOutputStream(resource);
   try {
     IOUtil.copy(inputStream, outputStream);
   } finally {
     outputStream.close();
   }
 }
예제 #5
0
  @Override
  public void verify(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder) {
    Check.isFalse(
        commandCall.hasChildCommands(), "Nesting commands inside an 'echo' is not supported");

    Object result = evaluator.evaluate(commandCall.getExpression());

    Element element = commandCall.getElement();
    if (result != null) {
      element.appendText(result.toString());
    } else {
      Element child = new Element("em");
      child.appendText("null");
      element.appendChild(child);
    }
  }
 public String getWrittenString(Resource resource) {
   Check.isTrue(
       writtenStrings.containsKey(resource),
       "Expected resource '" + resource.getPath() + "' was not written to target");
   return writtenStrings.get(resource);
 }
예제 #7
0
 public OutputStream getOutputStream(Resource resource) throws IOException {
   Check.notNull(resource, "resource is null");
   mkdirs(resource);
   return createOutputStream(resource);
 }
예제 #8
0
 public void delete(Resource resource) throws IOException {
   Check.notNull(resource, "resource is null");
   getFile(resource).delete();
 }