cleaning up test dependencies

This commit is contained in:
Dmitry Jemerov
2011-12-16 18:21:31 +01:00
parent 14746f95f3
commit edc378071f
3 changed files with 235 additions and 0 deletions
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved.
*/
package com.intellij.mock;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.intellij.codeInspection.ex.InspectionProfileImpl;
import com.intellij.openapi.util.Condition;
import com.intellij.psi.PsiElement;
import com.intellij.util.containers.ContainerUtil;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
/**
* @author peter
*/
public class MockInspectionProfile extends InspectionProfileImpl {
private InspectionProfileEntry[] myInspectionTools = new InspectionProfileEntry[0];
private final Set<InspectionProfileEntry> myDisabledTools = new THashSet<InspectionProfileEntry>();
public MockInspectionProfile() {
super("a");
}
public void setEnabled(InspectionProfileEntry tool, boolean enabled) {
if (enabled) {
myDisabledTools.remove(tool);
} else {
myDisabledTools.add(tool);
}
}
@Override
public boolean isToolEnabled(final HighlightDisplayKey key, PsiElement element) {
final InspectionProfileEntry entry = ContainerUtil.find(myInspectionTools, new Condition<InspectionProfileEntry>() {
@Override
public boolean value(final InspectionProfileEntry inspectionProfileEntry) {
return key.equals(HighlightDisplayKey.find(inspectionProfileEntry.getShortName()));
}
});
assert entry != null;
return !myDisabledTools.contains(entry);
}
public void setInspectionTools(final InspectionProfileEntry... entries) {
myInspectionTools = entries;
}
@Override
@NotNull
public InspectionProfileEntry[] getInspectionTools(PsiElement element) {
return myInspectionTools;
}
}
@@ -0,0 +1,136 @@
/*
* Copyright (c) 2000-2007 JetBrains s.r.o. All Rights Reserved.
*/
package com.intellij.mock;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileSystem;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
/**
* @author peter
*/
public class MockVirtualFile extends VirtualFile {
private VirtualFile myParent;
private final String myName;
private final boolean myDirectory;
private final List<VirtualFile> myChildren = new SmartList<VirtualFile>();
private String myText;
private FileType myFileType;
private final MockVirtualFileSystem myFileSystem = new MockVirtualFileSystem();
public MockVirtualFile(final String name) {
this(false, name);
}
public MockVirtualFile(final boolean directory, final String name) {
myDirectory = directory;
myName = name;
}
public void setText(final String text) {
myText = text;
}
@Override
@NotNull
@NonNls
public String getName() {
return myName;
}
public void setParent(final VirtualFile parent) {
myParent = parent;
}
@Override
public VirtualFile createChildData(final Object requestor, @NotNull @NonNls final String name) {
final MockVirtualFile file = new MockVirtualFile(name);
file.setParent(this);
myChildren.add(file);
return file;
}
@Override
@NotNull
public VirtualFileSystem getFileSystem() {
return myFileSystem;
}
@Override
public String getPath() {
String prefix = myParent == null ? "MOCK_ROOT:" : myParent.getPath();
return prefix + "/" + myName;
}
@Override
public boolean isWritable() {
throw new UnsupportedOperationException("Method isWritable is not yet implemented in " + getClass().getName());
}
@Override
public boolean isDirectory() {
return myDirectory;
}
@Override
public boolean isValid() {
return true;
}
@Override
@Nullable
public VirtualFile getParent() {
return myParent;
}
@Override
public VirtualFile[] getChildren() {
return (VirtualFile[])VfsUtil.toVirtualFileArray(myChildren);
}
@Override
@NotNull
public OutputStream getOutputStream(Object requestor, long newModificationStamp, long newTimeStamp) throws IOException {
throw new UnsupportedOperationException("Method getOutputStream is not yet implemented in " + getClass().getName());
}
@Override
@NotNull
public byte[] contentsToByteArray() throws IOException {
return myText.getBytes();
}
@Override
public long getTimeStamp() {
throw new UnsupportedOperationException("Method getTimeStamp is not yet implemented in " + getClass().getName());
}
@Override
public long getLength() {
throw new UnsupportedOperationException("Method getLength is not yet implemented in " + getClass().getName());
}
@Override
public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) {
throw new UnsupportedOperationException("Method refresh is not yet implemented in " + getClass().getName());
}
@Override
public InputStream getInputStream() throws IOException {
throw new UnsupportedOperationException("Method getInputStream is not yet implemented in " + getClass().getName());
}
}
@@ -0,0 +1,42 @@
package com.intellij.util.xml;
import junit.framework.Assert;
/**
* @author peter
*/
public class CallRegistry<T> {
private int mySize;
private final StringBuilder myExpected = new StringBuilder();
private final StringBuilder myActual = new StringBuilder();
public void putActual(T o) {
myActual.append(o);
myActual.append("\n");
mySize++;
}
public void putExpected(T o) {
myExpected.append(o);
myExpected.append("\n");
}
public void clear() {
mySize = 0;
myExpected.setLength(0);
myActual.setLength(0);
}
public void assertResultsAndClear() {
Assert.assertEquals(myExpected.toString(), myActual.toString());
clear();
}
public String toString() {
return myActual.toString();
}
public int getSize() {
return mySize;
}
}