This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-vfs.git
commit b3a55d48838bdc2183224351372ca5dfb85dfc9a Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sat Mar 6 14:57:12 2021 -0500 Sort members. --- .../org/apache/commons/AbstractVfsTestCase.java | 161 +++++++++++---------- 1 file changed, 81 insertions(+), 80 deletions(-) diff --git a/commons-vfs2/src/test/java/org/apache/commons/AbstractVfsTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/AbstractVfsTestCase.java index a4e1dc9..1a8d245 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/AbstractVfsTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/AbstractVfsTestCase.java @@ -32,6 +32,7 @@ import junit.framework.TestCase; * A base class for VFS tests. Provides utility methods for locating test resources. */ public abstract class AbstractVfsTestCase extends TestCase { + private static File baseDir; /** URL pattern */ @@ -41,49 +42,68 @@ public abstract class AbstractVfsTestCase extends TestCase { private static final Pattern PASSWORD_PATTERN = Pattern.compile(":(?:[^/]+)@"); /** - * Locates a test resource, and asserts that the resource exists - * - * @param name path of the resource, relative to this test's base directory. + * Asserts that an exception contains the expected message. */ - public static File getTestResource(final String name) { - return getTestResource(name, true); + public static void assertSameMessage(final String code, final Object param, final Throwable throwable) { + assertSameMessage(code, new Object[] { param }, throwable); } /** - * Locates a test resource. - * - * @param name path of the resource, relative to this test's base directory. + * Asserts that an exception contains the expected message. */ - public static File getTestResource(final String name, final boolean mustExist) { - File file = new File(getTestDirectoryFile(), name); - file = getCanonicalFile(file); - if (mustExist) { - assertTrue("Test file \"" + file + "\" does not exist.", file.exists()); - } else { - assertFalse("Test file \"" + file + "\" should not exist.", file.exists()); + private static void assertSameMessage(final String code, final Object[] params, final Throwable throwable) { + Object[] parmArray = params; + if (throwable instanceof FileSystemException) { + final FileSystemException fse = (FileSystemException) throwable; + + // Compare message code and params + assertEquals(code, fse.getCode()); + assertEquals(params.length, fse.getInfo().length); + parmArray = new Object[params.length]; + for (int i = 0; i < params.length; i++) { + String value = String.valueOf(params[i]); + // mask passwords (VFS-169) + final Matcher urlMatcher = URL_PATTERN.matcher(value); + if (urlMatcher.find()) { + final Matcher pwdMatcher = PASSWORD_PATTERN.matcher(value); + value = pwdMatcher.replaceFirst(":***@"); + } + assertEquals(value, fse.getInfo()[i]); + parmArray[i] = value; + } } - return file; + // Compare formatted message + final String message = Messages.getString(code, parmArray); + assertEquals(message, throwable.getMessage()); } /** - * Locates the base directory for this test. + * Compares 2 objects for equality, nulls are equal. Used by the test classes' equals() methods. */ - public static File getTestDirectoryFile() { - if (baseDir == null) { - final String baseDirProp = getTestDirectory(); - // the directory maybe expressed as URI in certain environments - if (baseDirProp.startsWith("file://")) { - try { - baseDir = getCanonicalFile(new File(new URI(baseDirProp))); - } catch (final URISyntaxException e) { - baseDir = getCanonicalFile(new File(baseDirProp)); - } - } else { - baseDir = getCanonicalFile(new File(baseDirProp)); - } + public static boolean equals(final Object o1, final Object o2) { + if (o1 == null && o2 == null) { + return true; } - return baseDir; + if (o1 == null || o2 == null) { + return false; + } + return o1.equals(o2); + } + + /** + * Makes a file canonical + */ + public static File getCanonicalFile(final File file) { + try { + return file.getCanonicalFile(); + } catch (final IOException e) { + return file.getAbsoluteFile(); + } + } + + public static String getResourceTestDirectory() { + return System.getProperty("test.basedir.res", "test-data"); } /** @@ -97,10 +117,6 @@ public abstract class AbstractVfsTestCase extends TestCase { return System.getProperty("test.basedir", "target/test-classes/test-data"); } - public static String getResourceTestDirectory() { - return System.getProperty("test.basedir.res", "test-data"); - } - /** * Locates a test directory, creating it if it does not exist. * @@ -115,63 +131,48 @@ public abstract class AbstractVfsTestCase extends TestCase { } /** - * Makes a file canonical - */ - public static File getCanonicalFile(final File file) { - try { - return file.getCanonicalFile(); - } catch (final IOException e) { - return file.getAbsoluteFile(); - } - } - - /** - * Asserts that an exception contains the expected message. + * Locates the base directory for this test. */ - private static void assertSameMessage(final String code, final Object[] params, final Throwable throwable) { - Object[] parmArray = params; - if (throwable instanceof FileSystemException) { - final FileSystemException fse = (FileSystemException) throwable; - - // Compare message code and params - assertEquals(code, fse.getCode()); - assertEquals(params.length, fse.getInfo().length); - parmArray = new Object[params.length]; - for (int i = 0; i < params.length; i++) { - String value = String.valueOf(params[i]); - // mask passwords (VFS-169) - final Matcher urlMatcher = URL_PATTERN.matcher(value); - if (urlMatcher.find()) { - final Matcher pwdMatcher = PASSWORD_PATTERN.matcher(value); - value = pwdMatcher.replaceFirst(":***@"); + public static File getTestDirectoryFile() { + if (baseDir == null) { + final String baseDirProp = getTestDirectory(); + // the directory maybe expressed as URI in certain environments + if (baseDirProp.startsWith("file://")) { + try { + baseDir = getCanonicalFile(new File(new URI(baseDirProp))); + } catch (final URISyntaxException e) { + baseDir = getCanonicalFile(new File(baseDirProp)); } - assertEquals(value, fse.getInfo()[i]); - parmArray[i] = value; + } else { + baseDir = getCanonicalFile(new File(baseDirProp)); } } - - // Compare formatted message - final String message = Messages.getString(code, parmArray); - assertEquals(message, throwable.getMessage()); + return baseDir; } /** - * Asserts that an exception contains the expected message. + * Locates a test resource, and asserts that the resource exists + * + * @param name path of the resource, relative to this test's base directory. */ - public static void assertSameMessage(final String code, final Object param, final Throwable throwable) { - assertSameMessage(code, new Object[] { param }, throwable); + public static File getTestResource(final String name) { + return getTestResource(name, true); } /** - * Compares 2 objects for equality, nulls are equal. Used by the test classes' equals() methods. + * Locates a test resource. + * + * @param name path of the resource, relative to this test's base directory. */ - public static boolean equals(final Object o1, final Object o2) { - if (o1 == null && o2 == null) { - return true; - } - if (o1 == null || o2 == null) { - return false; + public static File getTestResource(final String name, final boolean mustExist) { + File file = new File(getTestDirectoryFile(), name); + file = getCanonicalFile(file); + if (mustExist) { + assertTrue("Test file \"" + file + "\" does not exist.", file.exists()); + } else { + assertFalse("Test file \"" + file + "\" should not exist.", file.exists()); } - return o1.equals(o2); + + return file; } }