@Before
  public void setup() throws IOException {
    artifact = new DefaultArtifact("gid", "aid", "jar", "ver");
    artifact = artifact.setFile(TestFileUtils.createTempFile("artifact".getBytes(), 1));
    metadata =
        new DefaultMetadata(
            "gid",
            "aid",
            "ver",
            "type",
            Nature.RELEASE_OR_SNAPSHOT,
            TestFileUtils.createTempFile("metadata".getBytes(), 1));

    session = TestUtils.newSession();
    localArtifactPath = session.getLocalRepositoryManager().getPathForLocalArtifact(artifact);
    localMetadataPath = session.getLocalRepositoryManager().getPathForLocalMetadata(metadata);

    localArtifactFile = new File(session.getLocalRepository().getBasedir(), localArtifactPath);

    installer = new DefaultInstaller();
    installer.setFileProcessor(new TestFileProcessor());
    installer.setRepositoryEventDispatcher(new StubRepositoryEventDispatcher());
    installer.setSyncContextFactory(new StubSyncContextFactory());
    request = new InstallRequest();
    listener = new RecordingRepositoryListener();
    session.setRepositoryListener(listener);

    lrm = (TestLocalRepositoryManager) session.getLocalRepositoryManager();

    TestFileUtils.deleteFile(session.getLocalRepository().getBasedir());
  }
 @Test
 public void testFailingEventsMetadataExistsAsDir() {
   String path = session.getLocalRepositoryManager().getPathForLocalMetadata(metadata);
   assertTrue(
       "failed to setup test: could not create " + path,
       new File(session.getLocalRepository().getBasedir(), path).mkdirs());
   checkFailedEvents("target exists as dir", metadata);
 }
  @Test(expected = InstallationException.class)
  public void testMetadataDestinationEqualsSource() throws Exception {
    String path = session.getLocalRepositoryManager().getPathForLocalMetadata(metadata);
    File file = new File(session.getLocalRepository().getBasedir(), path);
    metadata = metadata.setFile(file);
    TestFileUtils.writeString(file, "test");

    request.addMetadata(metadata);
    installer.install(session, request);
  }
  @Test(expected = InstallationException.class)
  public void testMetadataExistsAsDir() throws InstallationException {
    String path = session.getLocalRepositoryManager().getPathForLocalMetadata(metadata);
    assertTrue(
        "failed to setup test: could not create " + path,
        new File(session.getLocalRepository().getBasedir(), path).mkdirs());

    request.addMetadata(metadata);
    installer.install(session, request);
  }
  @Test(expected = InstallationException.class)
  public void testArtifactExistsAsDir() throws InstallationException {
    String path = session.getLocalRepositoryManager().getPathForLocalArtifact(artifact);
    File file = new File(session.getLocalRepository().getBasedir(), path);
    assertFalse(file.getAbsolutePath() + " is a file, not directory", file.isFile());
    assertFalse(file.getAbsolutePath() + " already exists", file.exists());
    assertTrue(
        "failed to setup test: could not create " + file.getAbsolutePath(),
        file.mkdirs() || file.isDirectory());

    request.addArtifact(artifact);
    installer.install(session, request);
  }
 @After
 public void teardown() throws Exception {
   TestFileUtils.deleteFile(session.getLocalRepository().getBasedir());
 }