forked from eclipse-platform/eclipse.platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify and correct FileSystemTests eclipse-platform#783
Several test classes extend the FileSystemTest. This class only provides some utility functions and always creates a local and an in-memory file store, even if the actual test does not need it. This change simplifies the test classes by removing the FileSystemTest super class. The necessary utilities are moved to a utility class. The file store creation logic is moved to an according JUnit test rule that can be instantiated for a local or in-memory file store and keeps track of setup and teardown. This also fixes a bug in interwoven, inherited setup and teardown functions (eclipse-platform#783) Fixes eclipse-platform#783.
- Loading branch information
1 parent
a4bdcd1
commit e24b0f1
Showing
12 changed files
with
253 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...pse.core.tests.resources/src/org/eclipse/core/tests/filesystem/FileStoreCreationRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/******************************************************************************* | ||
* Copyright (c) Vector Informatik GmbH and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
*******************************************************************************/ | ||
package org.eclipse.core.tests.filesystem; | ||
|
||
import java.net.URI; | ||
import org.eclipse.core.filesystem.EFS; | ||
import org.eclipse.core.filesystem.IFileStore; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.IPath; | ||
import org.eclipse.core.runtime.IStatus; | ||
import org.eclipse.core.tests.harness.FileSystemHelper; | ||
import org.eclipse.core.tests.internal.filesystem.ram.MemoryTree; | ||
import org.eclipse.core.tests.resources.TestUtil; | ||
import org.junit.rules.ExternalResource; | ||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
|
||
/** | ||
* A test rule for automatically creating and disposing a file store for the | ||
* local file system or in memory. | ||
*/ | ||
public class FileStoreCreationRule extends ExternalResource { | ||
public enum FileSystemType { | ||
LOCAL, IN_MEMORY | ||
} | ||
|
||
private final FileSystemType fileSystemType; | ||
|
||
private String testName; | ||
|
||
private IFileStore fileStore; | ||
|
||
public FileStoreCreationRule(FileSystemType fileSystemType) { | ||
this.fileSystemType = fileSystemType; | ||
} | ||
|
||
public IFileStore getFileStore() { | ||
return fileStore; | ||
} | ||
|
||
@Override | ||
public Statement apply(Statement base, Description description) { | ||
testName = description.getDisplayName(); | ||
return super.apply(base, description); | ||
} | ||
|
||
@Override | ||
protected void before() throws Throwable { | ||
switch(fileSystemType) { | ||
case LOCAL: | ||
var fileStoreLocation = FileSystemHelper | ||
.getRandomLocation(FileSystemHelper.getTempDir()).append(IPath.SEPARATOR + testName); | ||
fileStore = EFS.getLocalFileSystem().getStore(fileStoreLocation); | ||
break; | ||
case IN_MEMORY: | ||
MemoryTree.TREE.deleteAll(); | ||
fileStore = EFS.getStore(URI.create("mem:/baseStore")); | ||
break; | ||
} | ||
fileStore.mkdir(EFS.NONE, null); | ||
} | ||
|
||
@Override | ||
protected void after() { | ||
try { | ||
fileStore.delete(EFS.NONE, null); | ||
} catch (CoreException e) { | ||
TestUtil.log(IStatus.ERROR, testName, "Could not delete file store: " + fileStore, e); | ||
} | ||
switch (fileSystemType) { | ||
case IN_MEMORY: | ||
MemoryTree.TREE.deleteAll(); | ||
break; | ||
case LOCAL: | ||
// Nothing to do | ||
} | ||
} | ||
} |
131 changes: 0 additions & 131 deletions
131
...rg.eclipse.core.tests.resources/src/org/eclipse/core/tests/filesystem/FileSystemTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.