private static void delete(File directory) {
   for (File file : directory.listFiles()) {
     if (file.isDirectory()) {
       delete(file);
     } else {
       assertTrue(file.delete());
     }
   }
   assertTrue(directory.delete());
 }
  private File createDelimitedFile(Set<TestBean> theBeans) {

    File aDelimitedFile = null;

    try {

      // Create a temporary file ...
      aDelimitedFile = createTempFile(this.getClass().getName(), ".csv");
      aDelimitedFile.deleteOnExit();

      // Write the set of beans out to the file ...
      BufferedWriter aWriter = new BufferedWriter(new FileWriter(aDelimitedFile));
      for (TestBean aBean : theBeans) {

        StringBuilder aStringBuilder = new StringBuilder();

        aStringBuilder.append(aBean.getFirstName());
        aStringBuilder.append(DEFAULT_DELIMITER);
        aStringBuilder.append(aBean.getLastName());
        aStringBuilder.append(DEFAULT_DELIMITER);
        aStringBuilder.append(aBean.getFavoriteColor());

        aWriter.append(aStringBuilder);
        aWriter.newLine();
      }

      // File all buffers and close up shop ...
      aWriter.flush();
      aWriter.close();

    } catch (IOException e) {

      fail("Failed to create test delimited file.", e);
    }

    return aDelimitedFile;
  }
  @Test
  public void shouldLookForClassesInTargetDirectories() throws Exception {
    newDir = new File("tempClassDir");
    List<File> buildPaths = asList(newDir);
    ClasspathProvider classpath =
        new StandaloneClasspath(
            buildPaths,
            FakeEnvironments.systemClasspath() + pathSeparator + newDir.getAbsolutePath());

    String classname = "org.fakeco.Foobar";
    createClass(classname);

    builder = new JavaClassBuilder(classpath);
    JavaClass javaClass = builder.createClass(classname);
    assertEquals(classname, javaClass.getName());
    assertFalse(javaClass.isATest());
  }
 private void createClass(String classname) throws CannotCompileException, IOException {
   ClassPool pool = ClassPool.getDefault();
   CtClass foobarClass = pool.makeClass(classname);
   foobarClass.writeFile(newDir.getAbsolutePath());
 }