public void testRemoveFromBuildpath01RemoveLibs() throws Exception {
    fJavaProject = createProject(DEFAULT_OUTPUT_FOLDER_NAME);

    IPath[] jarPaths =
        new IPath[] {
          JavaProjectHelper.MYLIB.makeAbsolute(), JavaProjectHelper.JUNIT_SRC_381.makeAbsolute()
        };

    CPJavaProject cpProject = CPJavaProject.createFromExisting(fJavaProject);
    BuildpathDelta delta = ClasspathModifier.addExternalJars(jarPaths, cpProject);
    ClasspathModifier.commitClassPath(cpProject, null);

    CPListElement[] toRemove = {delta.getAddedEntries().get(0), delta.getAddedEntries().get(1)};

    delta = ClasspathModifier.removeFromBuildpath(toRemove, cpProject);
    assertDeltaResources(delta, new IPath[0], new IPath[0], new IPath[0], new IPath[0]);
    assertDeltaDefaultOutputFolder(
        delta, fJavaProject.getPath().append(DEFAULT_OUTPUT_FOLDER_NAME));
    assertDeltaRemovedEntries(delta, new IPath[] {toRemove[0].getPath(), toRemove[1].getPath()});
    assertDeltaAddedEntries(delta, new IPath[0]);

    ClasspathModifier.commitClassPath(cpProject, null);

    IClasspathEntry[] classpathEntries = fJavaProject.getRawClasspath();
    assertNumberOfEntries(classpathEntries, 1);
  }
 private static void assertDeltaAddedEntries(BuildpathDelta delta, IPath[] paths) {
   List addedEntries = delta.getAddedEntries();
   assertTrue(
       "Expected " + paths.length + " is " + addedEntries.size(),
       addedEntries.size() == paths.length);
   IPath[] added = new IPath[addedEntries.size()];
   int i = 0;
   for (Iterator iterator = addedEntries.iterator(); iterator.hasNext(); ) {
     CPListElement element = (CPListElement) iterator.next();
     added[i] = element.getPath();
     i++;
   }
   for (int j = 0; j < paths.length; j++) {
     assertTrue("Entry " + paths[j] + " was not added", contains(added, paths[j]));
   }
   for (int j = 0; j < added.length; j++) {
     assertTrue("Entry " + added[j] + " was added", contains(paths, added[j]));
   }
 }
  private static void assertDeltaResources(
      BuildpathDelta delta,
      IPath[] createdFolders,
      IPath[] removedFolders,
      IPath[] createdFiles,
      IPath[] removedFiles) {
    IResource[] createdResources = delta.getCreatedResources();
    IPath[] createdPaths = new IPath[createdResources.length];
    for (int i = 0; i < createdResources.length; i++) {
      createdPaths[i] = createdResources[i].getFullPath();
    }

    for (int i = 0; i < createdPaths.length; i++) {
      IPath path = createdPaths[i];
      if (createdResources[i] instanceof IFile) {
        assertTrue(
            "File " + createdResources[i] + " is unexpected created", contains(createdFiles, path));
      } else if (createdResources[i] instanceof IFolder) {
        assertTrue(
            "Folder " + createdResources[i] + " is unexpected created",
            contains(createdFolders, path));
      } else {
        assertTrue("Resource " + createdResources[i] + " is nor file nor folder.", false);
      }
    }
    for (int i = 0; i < createdFolders.length; i++) {
      assertTrue(
          "Folder at " + createdFolders[i] + " was not created",
          contains(createdPaths, createdFolders[i]));
    }
    for (int i = 0; i < createdFiles.length; i++) {
      assertTrue(
          "File at " + createdFiles[i] + " was not created",
          contains(createdPaths, createdFiles[i]));
    }

    IResource[] deletedResources = delta.getDeletedResources();
    IPath[] deletedPaths = new IPath[deletedResources.length];
    for (int i = 0; i < deletedResources.length; i++) {
      deletedPaths[i] = deletedResources[i].getFullPath();
    }

    for (int i = 0; i < deletedPaths.length; i++) {
      IPath path = deletedPaths[i];
      if (deletedResources[i] instanceof IFile) {
        assertTrue(
            "File " + deletedResources[i] + " is unexpected removed", contains(removedFiles, path));
      } else if (deletedResources[i] instanceof IFolder) {
        assertTrue(
            "Folder " + deletedResources[i] + " is unexpected removed",
            contains(removedFolders, path));
      } else {
        assertTrue("Resource " + deletedResources[i] + " is nor file nor folder.", false);
      }
    }
    for (int i = 0; i < removedFolders.length; i++) {
      assertTrue(
          "Folder at " + removedFolders[i] + " was not removed",
          contains(deletedPaths, removedFolders[i]));
    }
    for (int i = 0; i < removedFiles.length; i++) {
      assertTrue(
          "File at " + removedFiles[i] + " was not removed",
          contains(deletedPaths, removedFiles[i]));
    }
  }
 private static void assertDeltaDefaultOutputFolder(BuildpathDelta delta, IPath expectedLocation) {
   IPath location = delta.getDefaultOutputLocation();
   assertTrue(
       "Default output location is " + location + " expected was " + expectedLocation,
       location.equals(expectedLocation));
 }