cleanup + lighter tests

This commit is contained in:
Sergey Ignatov
2019-01-20 00:05:03 +03:00
parent 7aec666941
commit 7980076b39
15 changed files with 39 additions and 71 deletions
@@ -20,7 +20,7 @@ import com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot;
import com.intellij.ide.util.projectWizard.importSources.JavaSourceRootDetectionUtil;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.LightPlatformTestCase;
import java.io.File;
import java.util.ArrayList;
@@ -29,7 +29,7 @@ import java.util.List;
/**
* @author nik
*/
public class JavaSourceRootDetectionTest extends PlatformTestCase {
public class JavaSourceRootDetectionTest extends LightPlatformTestCase {
public void testSimple() {
doTest("src", "");
}
@@ -227,7 +227,7 @@ public class AnsiEscapeDecoderTest extends PlatformTestCase {
});
}
public static void withProcessHandlerFrom(@NotNull Process testProcess, @NotNull Consumer<ProcessHandler> actionToTest) {
public static void withProcessHandlerFrom(@NotNull Process testProcess, @NotNull Consumer<? super ProcessHandler> actionToTest) {
KillableColoredProcessHandler handler = new KillableColoredProcessHandler(testProcess, "testProcess");
handler.setShouldDestroyProcessRecursively(false);
handler.setShouldKillProcessSoftly(false);
@@ -15,7 +15,7 @@ public abstract class FileSetTestCase extends PlatformTestCase {
protected VirtualFile createFile(@NotNull String path) {
String[] dirNames = path.split("/");
VirtualFile baseDir = getProject().getBaseDir();
for (int i = 0; i < dirNames.length - 1; i ++) {
for (int i = 0; i < dirNames.length - 1; i++) {
VirtualFile existing = VfsUtilCore.findRelativeFile(dirNames[i], baseDir);
if (existing == null) {
baseDir = createChildDirectory(baseDir, dirNames[i]);
@@ -30,8 +30,7 @@ public abstract class FileSetTestCase extends PlatformTestCase {
protected VirtualFile createFile(@NotNull String path, @NotNull String content) throws IOException {
VirtualFile file = createFile(path);
WriteAction.run(()->VfsUtil.saveText(file, content));
WriteAction.run(() -> VfsUtil.saveText(file, content));
return file;
}
}
@@ -16,7 +16,6 @@
package com.intellij.history.integration;
import com.intellij.history.core.changes.Change;
import com.intellij.history.core.changes.DeleteChange;
import com.intellij.history.core.changes.StructuralChange;
@@ -40,10 +39,7 @@ import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.*;
public class FileListeningTest extends IntegrationTestCase {
public void testCreatingFiles() throws Exception {
@@ -82,7 +78,7 @@ public class FileListeningTest extends IntegrationTestCase {
String subsubdir1_file = createFileExternally("dir/subdir/subsubdir1/f.txt");
createDirectoryExternally("dir/subdir/subsubdir2");
createFileExternally("dir/subdir/subsubdir2/f.txt");
myRoot.refresh(false, true);
List<Change> changes = getVcs().getChangeListInTests().getChangesInTests().get(0).getChanges();
@@ -110,7 +106,7 @@ public class FileListeningTest extends IntegrationTestCase {
private static StringBuilder buildDBFileStructure(@NotNull VirtualFile from, int level, @NotNull StringBuilder builder) {
List<VirtualFile> children = ContainerUtil.newArrayList(((NewVirtualFile)from).getCachedChildren());
Collections.sort(children, (o1, o2) -> o1.getName().compareTo(o2.getName()));
Collections.sort(children, Comparator.comparing(VirtualFile::getName));
for (VirtualFile eachChild : children) {
builder.append(StringUtil.repeat(" ", level)).append(eachChild.getName()).append("\n");
buildDBFileStructure(eachChild, level + 1, builder);
@@ -122,10 +118,10 @@ public class FileListeningTest extends IntegrationTestCase {
VirtualFile f = createFile("file.txt");
assertEquals(2, getRevisionsFor(f).size());
setBinaryContent(f,new byte[]{1});
setBinaryContent(f, new byte[]{1});
assertEquals(3, getRevisionsFor(f).size());
setBinaryContent(f,new byte[]{2});
setBinaryContent(f, new byte[]{2});
assertEquals(4, getRevisionsFor(f).size());
}
@@ -225,7 +221,7 @@ public class FileListeningTest extends IntegrationTestCase {
assertEquals(before, getRevisionsFor(myRoot).size());
}
private void setReadOnlyAttribute(VirtualFile f, boolean status) throws IOException {
private static void setReadOnlyAttribute(VirtualFile f, boolean status) throws IOException {
ApplicationManager.getApplication().runWriteAction(new ThrowableComputable<Object, IOException>() {
@Override
public Object compute() throws IOException {
@@ -328,6 +324,6 @@ public class FileListeningTest extends IntegrationTestCase {
}
private static void sortEntries(final List<Entry> entries) {
Collections.sort(entries, (o1, o2) -> o1.getName().compareTo(o2.getName()));
Collections.sort(entries, Comparator.comparing(Entry::getName));
}
}
@@ -16,7 +16,6 @@
package com.intellij.history.integration;
import com.intellij.history.FileRevisionTimestampComparator;
import com.intellij.history.LocalHistory;
import com.intellij.history.LocalHistoryAction;
@@ -30,6 +30,7 @@ import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@@ -70,7 +71,7 @@ public class SelectionReverterTest extends IntegrationTestCase {
}
public void testChangeSetName() throws Exception {
long time = new Date(2001, 1, 11, 12, 30).getTime();
long time = new Date(2001, Calendar.FEBRUARY, 11, 12, 30).getTime();
Clock.setTime(time);
setBinaryContent(f, "one".getBytes(StandardCharsets.UTF_8));
@@ -27,7 +27,6 @@ import com.intellij.openapi.vfs.VirtualFile;
import java.io.IOException;
import java.util.List;
public class DirectoryChangeModelTest extends IntegrationTestCase {
public void testNames() {
VirtualFile f = createDirectory("foo");
@@ -22,7 +22,6 @@ import com.intellij.history.integration.revertion.Reverter;
import com.intellij.history.integration.ui.models.HistoryDialogModel;
import com.intellij.history.integration.ui.models.RevisionItem;
import com.intellij.openapi.vfs.VirtualFile;
import org.junit.Test;
import java.util.List;
@@ -49,7 +48,6 @@ public class HistoryDialogModelTest extends IntegrationTestCase {
initModelFor();
}
@Test
public void testRevisionsList() {
List<RevisionItem> rr = m.getRevisions();
@@ -59,7 +57,6 @@ public class HistoryDialogModelTest extends IntegrationTestCase {
assertEquals("1", rr.get(2).revision.getChangeSetName());
}
@Test
public void testDoesNotRecomputeRevisionsEveryTime() {
assertEquals(3, m.getRevisions().size());
@@ -67,7 +64,6 @@ public class HistoryDialogModelTest extends IntegrationTestCase {
assertEquals(3, m.getRevisions().size());
}
@Test
public void testRegisteringUnsavedDocumentsBeforeBuildingRevisionsList() {
setDocumentTextFor(f, "unsaved");
initModelFor();
@@ -79,14 +75,12 @@ public class HistoryDialogModelTest extends IntegrationTestCase {
assertContent("unsaved", rr.get(0).findEntry());
}
@Test
public void testSelectingLastRevisionByDefault() {
String leftChangeName = "3";
String rightChangeName = "3";
assertSelectedRevisins(leftChangeName, rightChangeName);
}
@Test
public void testSelectingOnlyOneRevisionSetsRightToLastOne() {
m.selectRevisions(0, 0);
assertSelectedRevisins("3", null);
@@ -95,7 +89,6 @@ public class HistoryDialogModelTest extends IntegrationTestCase {
assertSelectedRevisins("2", null);
}
@Test
public void testSelectingTwoRevisions() {
m.selectRevisions(0, 1);
assertSelectedRevisins("2", "3");
@@ -104,13 +97,11 @@ public class HistoryDialogModelTest extends IntegrationTestCase {
assertSelectedRevisins("1", "2");
}
@Test
public void testClearingSelectionSetsRevisionsToLastOnes() {
m.selectRevisions(-1, -1);
assertSelectedRevisins("3", null);
}
@Test
public void testIsCurrentRevisionSelected() {
m.selectRevisions(1, 2);
assertFalse(m.isCurrentRevisionSelected());
@@ -122,7 +113,6 @@ public class HistoryDialogModelTest extends IntegrationTestCase {
assertTrue(m.isCurrentRevisionSelected());
}
@Test
public void testIsRevertEnabledForRevision() {
m.selectRevisions(1, 1);
assertTrue(m.isRevertEnabled());
@@ -143,7 +133,6 @@ public class HistoryDialogModelTest extends IntegrationTestCase {
assertTrue(m.isRevertEnabled());
}
@Test
public void testIsCreatePatchEnabledForRevision() {
m.selectRevisions(1, 1);
assertTrue(m.isCreatePatchEnabled());
@@ -225,8 +225,7 @@ public class FileDocumentManagerImplTest extends PlatformTestCase {
//noinspection UnusedAssignment
document = null;
System.gc();
System.gc();
GCUtil.tryGcSoftlyReachableObjects();
document = myDocumentManager.getDocument(file);
assertEquals(idCode, System.identityHashCode(document));
@@ -244,8 +243,7 @@ public class FileDocumentManagerImplTest extends PlatformTestCase {
myDocumentManager.saveAllDocuments();
System.gc();
System.gc();
GCUtil.tryGcSoftlyReachableObjects();
document = myDocumentManager.getDocument(file);
assertTrue(idCode != System.identityHashCode(document));
@@ -450,7 +448,7 @@ public class FileDocumentManagerImplTest extends PlatformTestCase {
assertEquals(0, myDocumentManager.getUnsavedDocuments().length);
}
public void testContentChanged_doNotReloadChangedDocumentOnSave() throws Exception {
public void testContentChanged_doNotReloadChangedDocumentOnSave() {
final MockVirtualFile file =
new MockVirtualFile("test.txt", "test") {
@Override
@@ -534,7 +532,7 @@ public class FileDocumentManagerImplTest extends PlatformTestCase {
renameFile(file, "test.wtf");
Document afterRename = documentManager.getDocument(file);
assertTrue(afterRename + " != " + original, afterRename == original);
assertSame(afterRename + " != " + original, afterRename, original);
}
public void testFileTypeChangeDocumentDetach() throws Exception {
@@ -1,10 +1,10 @@
package com.intellij.util;
import com.intellij.testFramework.PlatformTestCase;
import com.intellij.testFramework.LightPlatformTestCase;
import java.util.EventListener;
public class EventDispatcherTest extends PlatformTestCase {
public class EventDispatcherTest extends LightPlatformTestCase {
private StringBuffer myBuffer;
private PendingEventDispatcher<Listener> myDispatcher;
@@ -22,6 +22,7 @@ public class EventDispatcherTest extends PlatformTestCase {
@Override
protected void tearDown() throws Exception {
myDispatcher = null;
myBuffer = null;
super.tearDown();
}
@@ -124,8 +124,7 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
final FileStatusManager manager,
final FileIndexFacade excludedFileIndex,
ProjectManager projectManager,
DefaultVcsRootPolicy defaultVcsRootPolicy,
VcsFileListenerContextHelper vcsFileListenerContextHelper) {
DefaultVcsRootPolicy defaultVcsRootPolicy) {
myProject = project;
mySerialization = new ProjectLevelVcsManagerSerialization();
myOptionsAndConfirmations = new OptionsAndConfirmations();
@@ -155,9 +154,7 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
myVcsHistoryCache = new VcsHistoryCache();
myContentRevisionCache = new ContentRevisionCache();
VcsListener vcsListener = () -> {
myVcsHistoryCache.clearHistory();
};
VcsListener vcsListener = () -> myVcsHistoryCache.clearHistory();
myExcludedIndex = excludedFileIndex;
MessageBusConnection connection = myProject.getMessageBus().connect();
connection.subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED, vcsListener);
@@ -416,7 +413,7 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
}, ModalityState.defaultModalityState());
}
private Content getOrCreateConsoleContent(final ContentManager contentManager) {
private void getOrCreateConsoleContent(final ContentManager contentManager) {
final String displayName = VcsBundle.message("vcs.console.toolwindow.display.name");
Content content = contentManager.findContent(displayName);
if (content == null) {
@@ -442,7 +439,6 @@ public class ProjectLevelVcsManagerImpl extends ProjectLevelVcsManagerEx impleme
}
myPendingOutput.clear();
}
return content;
}
private void printToConsole(@NotNull String message, @NotNull ConsoleViewContentType contentType) {
@@ -29,10 +29,7 @@ public class TodoCheckinHandlerWorkerTest extends PlatformTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
WriteAction.run(() -> {
myRootFile = createTestProjectStructure();
});
WriteAction.run(() -> myRootFile = createTestProjectStructure());
}
public void testInEditedSingle() {
@@ -22,27 +22,23 @@ import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.testFramework.PlatformTestCase;
import junit.framework.Assert;
import org.junit.Test;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class FilterDescendantFilesTest extends PlatformTestCase {
@Test
public void testSecondModuleSameLevelAsProject() {
final File tmpDir = createDir(new File(FileUtil.getTempDirectory()), "tmpDir");
final File child1 = createDir(tmpDir, "child1");
final File child2 = createDir(tmpDir, "child2");
final List<VirtualFile> list = convert(new File[]{child2, child2, child1});
Assert.assertEquals(3, list.size());
assertEquals(3, list.size());
FilterDescendantVirtualFiles.filter(list);
Assert.assertEquals(2, list.size());
assertEquals(2, list.size());
}
@Test
public void testUsual() {
File tmp = new File(FileUtil.getTempDirectory());
final File tmpDir = createDir(tmp, "tmpDir");
@@ -50,12 +46,12 @@ public class FilterDescendantFilesTest extends PlatformTestCase {
final File child2 = createDir(tmp, "child2");
final List<VirtualFile> list = convert(new File[]{tmpDir, child2, child1});
Assert.assertEquals(3, list.size());
assertEquals(3, list.size());
FilterDescendantVirtualFiles.filter(list);
Assert.assertEquals(2, list.size());
assertEquals(2, list.size());
}
private List<VirtualFile> convert(final File[] files) {
private static List<VirtualFile> convert(final File[] files) {
final List<VirtualFile> result = new ArrayList<>();
final LocalFileSystem lfs = LocalFileSystem.getInstance();
for (File file : files) {
@@ -23,7 +23,6 @@ import com.intellij.testFramework.PlatformTestCase;
import com.intellij.util.containers.Convertor;
import com.intellij.util.treeWithCheckedNodes.SelectionManager;
import com.intellij.util.treeWithCheckedNodes.TreeNodeState;
import junit.framework.Assert;
import org.jetbrains.annotations.NotNull;
import javax.swing.tree.DefaultMutableTreeNode;
@@ -152,7 +151,7 @@ public class SelectionManagerTest extends PlatformTestCase {
}
public void testTwoTrees() {
final Map<VirtualFile, DefaultMutableTreeNode> middle1map = myFs.createNodeMap(myFs.myMiddle1);
final Map<VirtualFile, DefaultMutableTreeNode> middle1map = FileStructure.createNodeMap(myFs.myMiddle1);
assertClear();
myCm.toggleSelection(middle1map.get(myFs.myInner11));
afterInner11(); // though selected in smaller subtree
@@ -167,8 +166,8 @@ public class SelectionManagerTest extends PlatformTestCase {
private void assertNodeState(@NotNull final VirtualFile vf, final TreeNodeState state, final boolean recursively) {
Assert.assertNotNull(myFs.getNode(vf));
Assert.assertEquals(state, myCm.getState(myFs.getNode(vf)));
assertNotNull(myFs.getNode(vf));
assertEquals(state, myCm.getState(myFs.getNode(vf)));
// not deep, ok recursion
if (recursively) {
for (VirtualFile child : vf.getChildren()) {
@@ -184,15 +183,12 @@ public class SelectionManagerTest extends PlatformTestCase {
private final VirtualFile myInner11;
private final VirtualFile myInner12;
private final VirtualFile myInner21;
private final VirtualFile myInner22;
private final VirtualFile myLeaf1;
private final VirtualFile myLeaf2;
private final Map<VirtualFile, DefaultMutableTreeNode> myMap;
private final Project myProject;
private FileStructure(final Project project) throws IOException {
myProject = project;
private FileStructure(Project project) throws IOException {
final VirtualFile baseDir = project.getBaseDir();
myParent = baseDir.createChildDirectory(this, "parent");
@@ -202,7 +198,6 @@ public class SelectionManagerTest extends PlatformTestCase {
myInner11 = myMiddle1.createChildDirectory(this, "inner11");
myInner12 = myMiddle1.createChildDirectory(this, "inner12");
myInner21 = myMiddle2.createChildDirectory(this, "inner21");
myInner22 = myMiddle2.createChildDirectory(this, "inner22");
myLeaf1 = myInner11.createChildDirectory(this, "leaf1");
myLeaf2 = myInner11.createChildDirectory(this, "leaf2");
@@ -214,7 +209,7 @@ public class SelectionManagerTest extends PlatformTestCase {
return myMap.get(vf);
}
Map<VirtualFile, DefaultMutableTreeNode> createNodeMap(final VirtualFile parentFile) {
static Map<VirtualFile, DefaultMutableTreeNode> createNodeMap(final VirtualFile parentFile) {
Map<VirtualFile, DefaultMutableTreeNode> result = new HashMap<>();
final LinkedList<VirtualFile> queue = new LinkedList<>();
queue.add(parentFile);
@@ -233,7 +228,7 @@ public class SelectionManagerTest extends PlatformTestCase {
return result;
}
private void parentChild(final DefaultMutableTreeNode parent, final DefaultMutableTreeNode child) {
private static void parentChild(final DefaultMutableTreeNode parent, final DefaultMutableTreeNode child) {
parent.add(child);
child.setParent(parent);
}
@@ -41,7 +41,9 @@ public class AttachToProcessActionTest extends PlatformTestCase {
}
@NotNull
private RecentItem fixtureCreateHistoryItem(@NotNull ProcessInfo info, @NotNull XAttachPresentationGroup group, @NotNull String debuggerName) {
private static RecentItem fixtureCreateHistoryItem(@NotNull ProcessInfo info,
@NotNull XAttachPresentationGroup group,
@NotNull String debuggerName) {
return RecentItem.createRecentItem(LocalAttachHost.INSTANCE, info, group, debuggerName);
}