@Test(expected = ArchiveExportException.class)
  public void testExportThrowsArchiveExceptionOnAssetWriteFailure() throws IOException {
    log.info("testExportThrowsArchiveExceptionOnAssetWriteFailure");
    Archive<?> archive = createArchiveWithAssets();

    // Check if a the path already contains a node so we remove it from the parent's children
    if (archive.contains(PATH_ONE)) {
      archive.delete(PATH_ONE);
    }

    archive.add(
        new Asset() {
          @Override
          public InputStream openStream() {
            throw new RuntimeException("Mock Exception from an Asset write");
          }
        },
        PATH_ONE);

    // Export
    final InputStream in = this.exportAsInputStream(archive);

    // Read in the full content (to in turn empty the underlying buffer and ensure we complete)
    final OutputStream sink =
        new OutputStream() {
          @Override
          public void write(int b) throws IOException {}
        };
    IOUtil.copyWithClose(in, sink);
  }
 /** removes test class from web archive (test class will be replaced by transformed assertions) */
 private void removeTestClassFromDeployment(Archive<?> archive, TestClass testClass) {
   for (ArchivePath archivePath : archive.getContent().keySet()) {
     String path = archivePath.get();
     String classPath = testClass.getName().replace(".", "/");
     // remove TestClass and its anonymous classes - do not remove static inner classes
     if (path.matches("/WEB-INF/classes/" + classPath + "(\\$[0-9]*)?\\.class")) {
       archive.delete(archivePath);
     }
   }
 }