Esempio n. 1
0
  /**
   * A unit test for <code>objectToBytes()</code>, and <code>bytesToObject()</code>
   *
   * @exception Exception Description of Exception
   * @since
   */
  public void testObjectToBytesBytesToObject() throws Exception {
    String test = "test";
    String expected = "test";

    String message = "Test " + "'" + test + "'";

    byte[] bytes = IOUtils.objectToBytes(test);
    String result = (String) IOUtils.bytesToObject(bytes);

    assertEquals(message, expected, result);
  }
Esempio n. 2
0
  /**
   * A unit test for <code>getContextFilePath()</code>
   *
   * @exception Exception Description of Exception
   * @since
   */
  public void testGetContextFilePath() throws Exception {
    Object[] test_values = {
      new String[] {"a", "a" + File.separator + "b", "b"},
      new String[] {"a\\b", "a\\b" + File.separator + "c/d", "c" + File.separator + "d"},
      new String[] {"a/b", "a/b" + File.separator + "c\\d", "c" + File.separator + "d"},
    };
    for (int i = 0; i < test_values.length; i++) {
      String tests[] = (String[]) test_values[i];
      String test_directory_path = tests[0];
      String test_file_path = tests[1];
      String expected = tests[2];

      String result = IOUtils.getContextFilePath(test_directory_path, test_file_path);
      String message =
          "Test " + "'" + test_directory_path + "'" + ", " + "'" + test_file_path + "'";
      assertEquals(message, expected, result);
    }
  }
Esempio n. 3
0
  /**
   * A unit test for <code>normalizedFilename()</code>
   *
   * @exception Exception Description of Exception
   * @since
   */
  public void testNormalizedFilename() throws Exception {
    Object[] test_values = {
      new String[] {".", "__"},
      new String[] {"", ""},
      new String[] {"file://", "file_"},
      // was new String[]{"file://", "file_" + File.separator + "_" + File.separator + "_"},
      new String[] {"/a/b/c", "a" + File.separator + "b" + File.separator + "c"},
      new String[] {"\\a\\b\\c", "a" + File.separator + "b" + File.separator + "c"},
      new String[] {"a/b/c", "a" + File.separator + "b" + File.separator + "c"},
      new String[] {"a\\b\\c", "a" + File.separator + "b" + File.separator + "c"},
      new String[] {"a/b/../c", "a" + File.separator + "c"},
      new String[] {"public/final.xml", "public_" + File.separator + "final_xml"},
      new String[] {"123", "_123"}
    };
    for (int i = 0; i < test_values.length; i++) {
      String tests[] = (String[]) test_values[i];
      String test = tests[0];
      String expected = tests[1];

      String result = IOUtils.normalizedFilename(test);
      String message = "Test " + "'" + test + "'";
      assertEquals(message, expected, result);
    }
  }