Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8359449

[TEST] open/test/jdk/java/io/File/SymLinks.java Refactor extract method for Windows specific test

XMLWordPrintable

    • b03

      The test open/test/jdk/java/io/File/SymLinks.java has some logic to test Windows specific functionality. A refactor extract method will make the code cleaner and highlight the Windows specific tests more clearly

              // on Windows we test with the DOS hidden attribute set
              if (System.getProperty("os.name").startsWith("Windows")) {
                  DosFileAttributeView view = Files
                      .getFileAttributeView(file.toPath(), DosFileAttributeView.class);
                  view.setHidden(true);
                  try {
                      assertTrue(file.isHidden());
                      assertTrue(link2file.isHidden());
                      assertTrue(link2link2file.isHidden());
                  } finally {
                      view.setHidden(false);
                  }
                  assertFalse(file.isHidden());
                  assertFalse(link2file.isHidden());
                  assertFalse(link2link2file.isHidden());
              }

      refactor extract method -- extract the inline code to DOS specific test

          static void testDOSHiddenAttributes() throws IOException {
              // on Windows we test with the DOS hidden attribute set
              if (System.getProperty("os.name").startsWith("Windows")) {
                  DosFileAttributeView view = Files
                      .getFileAttributeView(file.toPath(), DosFileAttributeView.class);
                  view.setHidden(true);
                  try {
                      assertTrue(file.isHidden());
                      assertTrue(link2file.isHidden());
                      assertTrue(link2link2file.isHidden());
                  } finally {
                      view.setHidden(false);
                  }
                  assertFalse(file.isHidden());
                  assertFalse(link2file.isHidden());
                  assertFalse(link2link2file.isHidden());
              }
          }

            dboyle Dermot Boyle
            msheppar Mark Sheppard
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: