View Javadoc

    1   /*
    2    * This file is part of dependency-check-core.
    3    *
    4    * Dependency-check-core is free software: you can redistribute it and/or modify it
    5    * under the terms of the GNU General Public License as published by the Free
    6    * Software Foundation, either version 3 of the License, or (at your option) any
    7    * later version.
    8    *
    9    * Dependency-check-core is distributed in the hope that it will be useful, but
    10   * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11   * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    12   * details.
    13   *
    14   * You should have received a copy of the GNU General Public License along with
    15   * dependency-check-core. If not, see http://www.gnu.org/licenses/.
    16   *
    17   * Copyright (c) 2012 Jeremy Long. All Rights Reserved.
    18   */
    19  package org.owasp.dependencycheck.utils;
    20
    21  import java.io.File;
    22  import org.junit.After;
    23  import org.junit.AfterClass;
    24  import org.junit.Before;
    25  import org.junit.BeforeClass;
    26  import org.junit.Test;
    27  import static org.junit.Assert.*;
    28
    29  /**
    30   *
    31   * @author Jeremy Long (jeremy.long@owasp.org)
    32   */
    33  public class FileUtilsTest {
    34
    35      public FileUtilsTest() {
    36      }
    37
    38      @BeforeClass
    39      public static void setUpClass() throws Exception {
    40      }
    41
    42      @AfterClass
    43      public static void tearDownClass() throws Exception {
    44      }
    45
    46      @Before
    47      public void setUp() {
    48      }
    49
    50      @After
    51      public void tearDown() {
    52      }
    53
    54      /**
    55       * Test of getFileExtension method, of class FileUtils.
    56       */
    57      @Test
    58      public void testGetFileExtension() {
    59          String[] fileName = {"something-0.9.5.jar", "lib2-1.1.js"};
    60          String[] expResult = {"jar", "js"};
    61
    62          for (int i = 0; i < fileName.length; i++) {
    63              String result = FileUtils.getFileExtension(fileName[i]);
    64              assertEquals("Failed extraction on \"" + fileName[i] + "\".", expResult[i], result);
    65          }
    66      }
    67
    68      /**
    69       * Test of delete method, of class FileUtils.
    70       */
    71      @Test
    72      public void testDelete() throws Exception {
    73
    74          File file = File.createTempFile("tmp", "deleteme");
    75          if (!file.exists()) {
    76              fail("Unable to create a temporary file.");
    77          }
    78          FileUtils.delete(file);
    79          assertFalse("Temporary file exists after attempting deletion", file.exists());
    80      }
    81  }