[Git] Rework GitChangeProviderTest
[idea/community.git] / platform / testFramework / src / com / intellij / testFramework / vcs / MockDirtyScope.java
1 /*
2  * Copyright 2000-2011 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.intellij.testFramework.vcs;
17
18 import com.intellij.openapi.project.Project;
19 import com.intellij.openapi.vcs.AbstractVcs;
20 import com.intellij.openapi.vcs.FilePath;
21 import com.intellij.openapi.vcs.ProjectLevelVcsManager;
22 import com.intellij.openapi.vcs.changes.VcsModifiableDirtyScope;
23 import com.intellij.openapi.vfs.VirtualFile;
24 import com.intellij.util.Processor;
25 import org.jetbrains.annotations.NotNull;
26 import org.jetbrains.annotations.Nullable;
27
28 import java.util.Collection;
29 import java.util.HashSet;
30 import java.util.Set;
31
32 /**
33  * Mock implementation of {@link com.intellij.openapi.vcs.changes.VcsDirtyScope}.
34  * Stores files and dirs separately without any check.
35  * Not all operations may be supported.
36  *
37  * @author Kirill Likhodedov
38  */
39 public class MockDirtyScope extends VcsModifiableDirtyScope {
40
41   private final Project myProject;
42   private final AbstractVcs myVcs;
43   private final ProjectLevelVcsManager myVcsManager;
44
45   private final Set<FilePath> myDirtyFiles = new HashSet<FilePath>();
46   private final Set<FilePath> myDirtyDirs = new HashSet<FilePath>();
47   private final Set<VirtualFile> myContentRoots = new HashSet<VirtualFile>();
48
49   public MockDirtyScope(@NotNull Project project, @NotNull AbstractVcs vcs) {
50     myProject = project;
51     myVcs = vcs;
52     myVcsManager = ProjectLevelVcsManager.getInstance(myProject);
53   }
54
55   @Override
56   public void addDirtyFile(@Nullable FilePath newcomer) {
57     myDirtyFiles.add(newcomer);
58     myContentRoots.add(myVcsManager.getVcsRootFor(newcomer.getVirtualFile()));
59   }
60
61   @Override
62   public void addDirtyDirRecursively(@Nullable FilePath newcomer) {
63     myDirtyDirs.add(newcomer);
64     myContentRoots.add(myVcsManager.getVcsRootFor(newcomer.getVirtualFile()));
65   }
66
67   @Override
68   @NotNull
69   public Collection<VirtualFile> getAffectedContentRoots() {
70     return myContentRoots;
71   }
72
73   @Override
74   @NotNull
75   public Project getProject() {
76     return myProject;
77   }
78
79   @Override
80   @NotNull
81   public AbstractVcs getVcs() {
82     return myVcs;
83   }
84
85   @Override
86   @NotNull
87   public Set<FilePath> getDirtyFiles() {
88     return myDirtyFiles;
89   }
90
91   @Override
92   @NotNull
93   public Set<FilePath> getDirtyFilesNoExpand() {
94     return myDirtyFiles;
95   }
96
97   @Override
98   @NotNull
99   public Set<FilePath> getRecursivelyDirtyDirectories() {
100     return myDirtyDirs;
101   }
102
103   @Override
104   public boolean isRecursivelyDirty(VirtualFile vf) {
105     throw new UnsupportedOperationException();
106   }
107
108   @Override
109   public void iterate(Processor<FilePath> iterator) {
110     throw new UnsupportedOperationException();
111   }
112
113   @Override
114   public boolean isEmpty() {
115     return myDirtyFiles.isEmpty();
116   }
117
118   @Override
119   public boolean belongsTo(FilePath path) {
120     throw new UnsupportedOperationException();
121   }
122 }