Skip to content
Permalink
Browse files
JUnit v5 upgrade reducing usage of TestCase (#241)
* JUnit v5 refactoring AbstractVfsTestCase usage removal

* JUnit v5 refactor Util Methods into VfsTestUtils

* JUnit v5 refactor due to deleting AbstractVfsTestCase

* JUnit v5 Bzip2Test upgrade

* JUnit v5 Http5sGetContentInfoTest upgrade

* JUnit v5 GenericFileNameTest upgrade

* JUnit v5 FileSystemManagerFactoryTest upgrade

* JUnit v5 FileNameTest upgrade

* JUnit v5 HttpProviderTestCase update

* JUnit v5 Http4ProviderTestCase update

* JUnit v5 Http5ProviderTestCase update

* Java Code Style remove empty space before package
  • Loading branch information
nhojpatrick committed Feb 21, 2022
1 parent 8a76ba3 commit 8e8af8546e5903779806259f0125fe88628b28ad
Showing 77 changed files with 186 additions and 130 deletions.
@@ -16,6 +16,8 @@
*/
package org.apache.commons.vfs2.provider.webdav.test;

import static org.apache.commons.vfs2.VfsTestUtils.getTestDirectory;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -16,6 +16,8 @@
*/
package org.apache.commons.vfs2.provider.webdav4.test;

import static org.apache.commons.vfs2.VfsTestUtils.getTestDirectory;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -16,16 +16,20 @@
*/
package org.apache.commons.vfs2.provider.smb.test;

import org.apache.commons.vfs2.AbstractVfsTestCase;
import static org.apache.commons.vfs2.VfsTestUtils.assertSameMessage;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.fail;

import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.provider.smb.SmbFileName;
import org.apache.commons.vfs2.provider.smb.SmbFileNameParser;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Some additional SMB file name test cases.
*/
public class FileNameTestCase extends AbstractVfsTestCase {
public class FileNameTest {

/**
* Tests parsing a URI into its parts.
@@ -38,7 +38,8 @@
* <p>
* Works from a base folder, and assumes a particular structure under that base folder.
*/
public abstract class AbstractProviderTestCase extends AbstractVfsTestCase {
public abstract class AbstractProviderTestCase extends TestCase {

// Expected contents of "file1.txt"
public static final String FILE1_CONTENT = "This is a test file.";
// Expected contents of test files
@@ -16,6 +16,8 @@
*/
package org.apache.commons.vfs2;

import static org.apache.commons.vfs2.VfsTestUtils.getTestDirectory;

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -242,7 +244,7 @@ protected void setUp() throws Exception {
startThreadSnapshot = createThreadSnapshot();

// Locate the temp directory, and clean it up
tempDir = AbstractVfsTestCase.getTestDirectory("temp");
tempDir = getTestDirectory("temp");
FileUtils.cleanDirectory(tempDir);
checkTempDir("Temp dir not empty before test");

@@ -16,6 +16,8 @@
*/
package org.apache.commons.vfs2;

import static org.apache.commons.vfs2.VfsTestUtils.assertSameMessage;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.commons.vfs2;

import java.io.File;
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.commons.vfs2;

import java.io.BufferedOutputStream;
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.commons.vfs2;

import static org.junit.Assert.assertEquals;
@@ -16,14 +16,19 @@
*/
package org.apache.commons.vfs2;

import static org.apache.commons.vfs2.VfsTestUtils.getTestResource;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;

import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Test cases for the VFS factory.
*/
public class FileSystemManagerFactoryTestCase extends AbstractVfsTestCase {
public class FileSystemManagerFactoryTest {

private void check(final FileSystemManager manager, FileObject file) throws FileSystemException {
assertNotNull(file);
@@ -16,6 +16,8 @@
*/
package org.apache.commons.vfs2;

import static org.apache.commons.vfs2.VfsTestUtils.assertSameMessage;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
@@ -16,6 +16,8 @@
*/
package org.apache.commons.vfs2;

import static org.apache.commons.vfs2.VfsTestUtils.assertSameMessage;

import java.io.IOException;
import java.io.InputStream;

@@ -16,6 +16,8 @@
*/
package org.apache.commons.vfs2;

import static org.apache.commons.vfs2.VfsTestUtils.assertSameMessage;

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.commons.vfs2;

import static org.junit.Assert.assertNotEquals;
@@ -16,6 +16,10 @@
*/
package org.apache.commons.vfs2;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.net.URI;
@@ -25,12 +29,10 @@

import org.apache.commons.vfs2.util.Messages;

import junit.framework.TestCase;

/**
* A base class for VFS tests. Provides utility methods for locating test resources.
* Provides utility methods for locating test resources.
*/
public abstract class AbstractVfsTestCase extends TestCase {
public abstract class VfsTestUtils {

private static File baseDir;

@@ -174,4 +176,5 @@ public static File getTestResource(final String name, final boolean mustExist) {

return file;
}

}
@@ -16,10 +16,9 @@
*/
package org.apache.commons.vfs2.cache;

import java.io.File;
import static org.apache.commons.vfs2.VfsTestUtils.getTestDirectoryFile;

import org.apache.commons.vfs2.AbstractProviderTestConfig;
import org.apache.commons.vfs2.AbstractVfsTestCase;
import org.apache.commons.vfs2.CacheTestSuite;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemManager;
@@ -44,7 +43,6 @@ public FilesCache createFilesCache() {

@Override
public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
final File testDir = AbstractVfsTestCase.getTestDirectoryFile();
return manager.toFileObject(testDir);
return manager.toFileObject(getTestDirectoryFile());
}
}
@@ -16,8 +16,9 @@
*/
package org.apache.commons.vfs2.cache;

import static org.apache.commons.vfs2.VfsTestUtils.getTestDirectoryFile;

import org.apache.commons.vfs2.AbstractProviderTestConfig;
import org.apache.commons.vfs2.AbstractVfsTestCase;
import org.apache.commons.vfs2.CacheTestSuite;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemManager;
@@ -43,6 +44,6 @@ public FilesCache createFilesCache() {

@Override
public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
return manager.toFileObject(AbstractVfsTestCase.getTestDirectoryFile());
return manager.toFileObject(getTestDirectoryFile());
}
}
@@ -16,10 +16,9 @@
*/
package org.apache.commons.vfs2.cache;

import java.io.File;
import static org.apache.commons.vfs2.VfsTestUtils.getTestDirectoryFile;

import org.apache.commons.vfs2.AbstractProviderTestConfig;
import org.apache.commons.vfs2.AbstractVfsTestCase;
import org.apache.commons.vfs2.CacheTestSuite;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemManager;
@@ -44,7 +43,6 @@ public FilesCache createFilesCache() {

@Override
public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
final File testDir = AbstractVfsTestCase.getTestDirectoryFile();
return manager.toFileObject(testDir);
return manager.toFileObject(getTestDirectoryFile());
}
}
@@ -16,8 +16,9 @@
*/
package org.apache.commons.vfs2.cache;

import static org.apache.commons.vfs2.VfsTestUtils.getTestDirectoryFile;

import org.apache.commons.vfs2.AbstractProviderTestConfig;
import org.apache.commons.vfs2.AbstractVfsTestCase;
import org.apache.commons.vfs2.CacheTestSuite;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemManager;
@@ -42,6 +43,6 @@ public FilesCache createFilesCache() {

@Override
public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
return manager.toFileObject(AbstractVfsTestCase.getTestDirectoryFile());
return manager.toFileObject(getTestDirectoryFile());
}
}
@@ -16,10 +16,9 @@
*/
package org.apache.commons.vfs2.cache;

import java.io.File;
import static org.apache.commons.vfs2.VfsTestUtils.getTestDirectoryFile;

import org.apache.commons.vfs2.AbstractProviderTestConfig;
import org.apache.commons.vfs2.AbstractVfsTestCase;
import org.apache.commons.vfs2.CacheTestSuite;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemManager;
@@ -44,7 +43,6 @@ public FilesCache createFilesCache() {

@Override
public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
final File testDir = AbstractVfsTestCase.getTestDirectoryFile();
return manager.toFileObject(testDir);
return manager.toFileObject(getTestDirectoryFile());
}
}
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.commons.vfs2.function;

import java.nio.file.Paths;
@@ -16,6 +16,7 @@
*/
package org.apache.commons.vfs2.impl;

import static org.apache.commons.vfs2.VfsTestUtils.getTestDirectoryFile;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -30,7 +31,6 @@
import java.util.Objects;
import java.util.concurrent.atomic.AtomicLong;

import org.apache.commons.vfs2.AbstractVfsTestCase;
import org.apache.commons.vfs2.FileChangeEvent;
import org.apache.commons.vfs2.FileListener;
import org.apache.commons.vfs2.FileObject;
@@ -193,7 +193,7 @@ private void resetStatus() {
@BeforeEach
public void setUp() throws Exception {
fileSystemManager = VFS.getManager();
testDir = AbstractVfsTestCase.getTestDirectoryFile();
testDir = getTestDirectoryFile();
resetStatus();
testFile = new File(testDir, "testReload.properties");
deleteTestFileIfPresent();
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.commons.vfs2.impl;

import java.io.File;
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.commons.vfs2.impl;

import java.nio.file.Paths;
@@ -16,6 +16,8 @@
*/
package org.apache.commons.vfs2.impl;

import static org.apache.commons.vfs2.VfsTestUtils.getTestDirectoryFile;

import java.io.File;
import java.io.IOException;
import java.net.URL;
@@ -24,7 +26,6 @@
import java.util.Enumeration;

import org.apache.commons.vfs2.AbstractProviderTestCase;
import org.apache.commons.vfs2.AbstractVfsTestCase;
import org.apache.commons.vfs2.Capability;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
@@ -95,7 +96,7 @@ public void testGetResourcesJARs() throws Exception {

// build search path without using #getBaseFolder()
// because NestedJarTestCase redefines it
final File baseDir = AbstractVfsTestCase.getTestDirectoryFile();
final File baseDir = getTestDirectoryFile();
final FileObject nestedJar = manager.resolveFile(baseDir, "nested.jar");
final FileObject testJar = manager.resolveFile(baseDir, "test.jar");

@@ -142,7 +143,7 @@ public void testGetResourcesNoLayerLocal() throws Exception {
System.out.println("VfsClassLoaderTests no local file provider, skipping.");
return;
}
final File baseDir = AbstractVfsTestCase.getTestDirectoryFile();
final File baseDir = getTestDirectoryFile();

// setup test folder
final FileObject dir = manager.resolveFile(baseDir, "read-tests/dir1/subdir4.jar");

0 comments on commit 8e8af85

Please sign in to comment.