@Test
  public void testReadOnlyTempFolderWithoutLog() {
    if (!_shouldTest()) {
      return;
    }

    List<LogRecord> logRecords =
        JDKLoggerTestUtil.configureJDKLogger(FIFOUtil.class.getName(), Level.OFF);

    File tempFolder = new File("tempFolder");

    tempFolder.mkdirs();

    tempFolder.setReadOnly();

    String oldTempFolder = System.getProperty("java.io.tmpdir");

    System.setProperty("java.io.tmpdir", tempFolder.getAbsolutePath());

    try {
      Assert.assertFalse(FIFOUtil.isFIFOSupported());
    } finally {
      System.setProperty("java.io.tmpdir", oldTempFolder);
    }

    Assert.assertTrue(logRecords.isEmpty());
  }
  @Test
  public void testIsFIFOSupported() {
    if (!_shouldTest()) {
      return;
    }

    Assert.assertTrue(FIFOUtil.isFIFOSupported());
  }
  @Test
  public void testPhantomDeleteOnDetecting() {
    if (!_shouldTest()) {
      return;
    }

    final AtomicInteger checkDeleteCount = new AtomicInteger();
    final AtomicBoolean checkFlag = new AtomicBoolean();

    SecurityManager securityManager =
        new SecurityManager() {

          @Override
          public void checkDelete(String file) {
            if (!checkFlag.get() && file.contains("temp-fifo-")) {
              checkFlag.set(true);

              if (checkDeleteCount.getAndIncrement() == 0) {
                Assert.assertTrue(new File(file).delete());
              }

              checkFlag.set(false);
            }
          }

          @Override
          public void checkRead(String file) {
            if (!checkFlag.get() && file.contains("temp-fifo-")) {
              try {
                checkFlag.set(true);

                new File(file).createNewFile();

                checkFlag.set(false);
              } catch (IOException ioe) {
                Assert.fail(ioe.getMessage());
              }
            }
          }

          @Override
          public void checkPermission(Permission permission) {}
        };

    System.setSecurityManager(securityManager);

    try {
      Assert.assertTrue(FIFOUtil.isFIFOSupported());
    } finally {
      System.setSecurityManager(null);
    }

    Assert.assertEquals(2, checkDeleteCount.get());
  }
  @Test
  public void testCreateFIFOWithBrokenFile() throws Exception {
    if (!_shouldTest()) {
      return;
    }

    try {
      FIFOUtil.createFIFO(
          new File("") {

            @Override
            public String getAbsolutePath() {
              return null;
            }
          });

      Assert.fail();
    } catch (NullPointerException npe) {
    }
  }
  @Test
  public void testReadOnlyTempFolderWithLog() {
    if (!_shouldTest()) {
      return;
    }

    List<LogRecord> logRecords =
        JDKLoggerTestUtil.configureJDKLogger(FIFOUtil.class.getName(), Level.WARNING);

    File tempFolder = new File("tempFolder");

    tempFolder.mkdirs();

    tempFolder.setReadOnly();

    String oldTempFolder = System.getProperty("java.io.tmpdir");

    System.setProperty("java.io.tmpdir", tempFolder.getAbsolutePath());

    try {
      Assert.assertFalse(FIFOUtil.isFIFOSupported());
    } finally {
      System.setProperty("java.io.tmpdir", oldTempFolder);
    }

    Assert.assertEquals(1, logRecords.size());

    LogRecord logRecord = logRecords.get(0);

    Assert.assertEquals("Unable to detect FIFO support", logRecord.getMessage());

    Throwable throwable = logRecord.getThrown();

    Assert.assertEquals(Exception.class, throwable.getClass());

    String message = throwable.getMessage();

    Assert.assertTrue(
        message.startsWith(
            "Unable to create FIFO with command \"mkfifo\", external " + "process returned "));
  }