@Test
  public void testTerminateQueueCannotDeleteDirectory() throws IOException {
    String queueName = "queueCannotDelete";
    File queueDir = new File("target", queueName);
    ReportExporter exporter = mock(ReportExporter.class);
    BatchProcessorConfig config = mock(BatchProcessorConfig.class);
    when(config.getDataDirectory()).thenReturn("target");
    when(config.getQueueSize()).thenReturn(5);
    FileUtil.deleteDirectory(queueDir);

    queueFactory = new QueueFactory(config, exporter);

    Set<PosixFilePermission> permissions = new HashSet<>();
    permissions.add(PosixFilePermission.OWNER_READ);

    queueFactory.create(queueName);
    assertTrue(queueDir.exists());
    Files.setPosixFilePermissions(queueDir.toPath(), permissions);

    try {
      queueFactory.terminate(queueName);
      fail("Expected IllegalStateException");
    } catch (IllegalStateException e) {
      assertTrue(true);
    }

    permissions = new HashSet<>();
    permissions.add(PosixFilePermission.OWNER_WRITE);
    permissions.add(PosixFilePermission.OWNER_READ);
    permissions.add(PosixFilePermission.OWNER_EXECUTE);
    Files.setPosixFilePermissions(queueDir.toPath(), permissions);
    FileUtil.deleteDirectory(queueDir);
  }
  @SuppressWarnings("ResultOfMethodCallIgnored")
  @Test
  public void testTerminate() throws IOException {
    String queueName = "queueTerminate";
    File queueDir = new File("target", queueName);
    FileUtil.deleteDirectory(queueDir);
    assertFalse(queueDir.exists());

    ReportExporter exporter = mock(ReportExporter.class);
    BatchProcessorConfig config = mock(BatchProcessorConfig.class);
    when(config.getDataDirectory()).thenReturn("target");
    when(config.getQueueSize()).thenReturn(5);

    queueFactory = new QueueFactory(config, exporter);

    Queue queue = queueFactory.create(queueName);
    assertTrue(queueDir.exists());

    queueFactory.terminate(queueName);
    assertFalse(queueDir.exists());
    verify(exporter).unexport(QueueFactory.getMetricName(queue.getName()));
  }