public void cleanupBeforeRelaunch(Container container)
      throws IOException, InterruptedException {
    if (container.getLocalizedResources() != null) {

      Map<Path, Path> symLinks = resolveSymLinks(
          container.getLocalizedResources(), container.getUser());

      for (Map.Entry<Path, Path> symLink : symLinks.entrySet()) {
        LOG.debug("{} deleting {}", container.getContainerId(),
            symLink.getValue());
        deleteAsUser(new DeletionAsUserContext.Builder()
            .setUser(container.getUser())
            .setSubDir(symLink.getValue())
            .build());
      }
    }
  }
@Test
  public void testCleanupBeforeLaunch() throws Exception {
    Container container = mock(Container.class);
    java.nio.file.Path linkName = Paths.get("target/linkName");
    java.nio.file.Path target = Paths.get("target");
    //deletes the link if it already exists because of previous test failures
    FileUtils.deleteQuietly(linkName.toFile());
    Files.createSymbolicLink(linkName.toAbsolutePath(),
        target.toAbsolutePath());

    Map<Path, List<String>> localResources = new HashMap<>();
    localResources.put(new Path(target.toFile().getAbsolutePath()),
        Lists.newArrayList(linkName.toFile().getAbsolutePath()));

    when(container.getLocalizedResources())
        .thenReturn(localResources);
    when(container.getUser()).thenReturn(System.getProperty("user.name"));
    containerExecutor.cleanupBeforeRelaunch(container);
    Assert.assertTrue(!Files.exists(linkName));
  }