@After
  public void tearDown() {
    if (m_fileAnticipator.isInitialized()) {
      m_fileAnticipator.deleteExpected();
    }

    m_fileAnticipator.tearDown();
  }
 /**
  * Generate schema.
  *
  * @throws Exception the exception
  */
 @Test
 public void generateSchema() throws Exception {
   File schemaFile = fileAnticipator.expecting("tca-datacollection-config.xsd");
   context.generateSchema(new TestOutputResolver(schemaFile));
   if (fileAnticipator.isInitialized()) {
     fileAnticipator.deleteExpected();
   }
 }
Esempio n. 3
0
  /** tearDown */
  public void tearDown() {
    if (!isInitialized()) {
      return;
    }

    try {
      // Windows is really picky about filehandle reaping, triggering a GC
      // keeps it from holding on to files when we're trying to delete them
      deleteExpected(true);

      for (ListIterator<File> i = m_deleteMe.listIterator(m_deleteMe.size()); i.hasPrevious(); ) {
        File f = i.previous();
        if (!f.exists()) continue;
        if (!FileUtils.deleteQuietly(f)) {
          final StringBuffer b = new StringBuffer();
          b.append("Could not delete " + f.getAbsolutePath() + ": is it a non-empty directory?");
          b.append("\nDirectory listing:");
          if (f.listFiles() != null) {
            for (File file : f.listFiles()) {
              b.append("\n\t");
              b.append(file.getName());
            }
          }
          fail(b.toString());
        }
      }
      if (m_tempDir != null) {
        assertFalse(m_tempDir + " exists", m_tempDir.exists());
      }
    } catch (Throwable t) {
      if (m_tempDir != null && m_tempDir.exists()) {
        try {
          FileUtils.forceDelete(m_tempDir);
          return;
        } catch (final IOException innerThrowable) {
          LOG.warn(
              "an error occurred while forcibly removing temporary directory {}",
              m_tempDir,
              innerThrowable);
        }
      } else {
        LOG.warn("does not exist? {}", m_tempDir, t);
      }
      if (t instanceof RuntimeException) {
        throw (RuntimeException) t;
      } else {
        throw new RuntimeException(t);
      }
    }
  }
Esempio n. 4
0
 /**
  * Delete expected files, throwing an AssertionFailedError if any of the expected files don't
  * exist.
  */
 public void deleteExpected() {
   deleteExpected(false);
 }