Lines 44-49
Link Here
|
44 |
|
44 |
|
45 |
import java.util.ArrayList; |
45 |
import java.util.ArrayList; |
46 |
import java.util.List; |
46 |
import java.util.List; |
|
|
47 |
import java.util.concurrent.Semaphore; |
47 |
import org.netbeans.api.annotations.common.SuppressWarnings; |
48 |
import org.netbeans.api.annotations.common.SuppressWarnings; |
48 |
import org.netbeans.api.project.ProjectManager; |
49 |
import org.netbeans.api.project.ProjectManager; |
49 |
import org.netbeans.junit.NbTestCase; |
50 |
import org.netbeans.junit.NbTestCase; |
Lines 52-60
Link Here
|
52 |
import org.openide.filesystems.FileObject; |
53 |
import org.openide.filesystems.FileObject; |
53 |
import org.openide.filesystems.FileUtil; |
54 |
import org.openide.filesystems.FileUtil; |
54 |
import org.openide.util.Lookup; |
55 |
import org.openide.util.Lookup; |
|
|
56 |
import org.openide.util.lookup.AbstractLookup; |
57 |
import org.openide.util.lookup.InstanceContent; |
55 |
import org.openide.util.lookup.Lookups; |
58 |
import org.openide.util.lookup.Lookups; |
56 |
import org.openide.util.test.MockLookup; |
59 |
import org.openide.util.test.MockLookup; |
57 |
|
60 |
|
|
|
61 |
@SuppressWarnings({"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "SIC_INNER_SHOULD_BE_STATIC_ANON"}) |
58 |
public class MainProjectActionTest extends NbTestCase { |
62 |
public class MainProjectActionTest extends NbTestCase { |
59 |
|
63 |
|
60 |
public MainProjectActionTest(String name) { |
64 |
public MainProjectActionTest(String name) { |
Lines 77-83
Link Here
|
77 |
prj2 = (TestSupport.TestProject) ProjectManager.getDefault().findProject(p2); |
81 |
prj2 = (TestSupport.TestProject) ProjectManager.getDefault().findProject(p2); |
78 |
} |
82 |
} |
79 |
|
83 |
|
80 |
@SuppressWarnings({"UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", "SIC_INNER_SHOULD_BE_STATIC_ANON"}) |
|
|
81 |
public void testSeqRun() throws Exception { |
84 |
public void testSeqRun() throws Exception { |
82 |
final String CMD = "cmd"; |
85 |
final String CMD = "cmd"; |
83 |
final List<Integer> invocations = new ArrayList<Integer>(); |
86 |
final List<Integer> invocations = new ArrayList<Integer>(); |
Lines 117-120
Link Here
|
117 |
assertEquals("[1, 2, 1, 2, 1]", invocations.toString()); |
120 |
assertEquals("[1, 2, 1, 2, 1]", invocations.toString()); |
118 |
} |
121 |
} |
119 |
|
122 |
|
|
|
123 |
public void testDisableMultiRun() throws Exception { |
124 |
final String CMD = "cmd"; |
125 |
final Semaphore s1 = new Semaphore(0); |
126 |
final Semaphore s2 = new Semaphore(0); |
127 |
class SlowRun implements ActionProvider { |
128 |
@Override public String[] getSupportedActions() { |
129 |
return new String[] {CMD}; |
130 |
} |
131 |
@Override public boolean isActionEnabled(String command, Lookup context) { |
132 |
return true; |
133 |
} |
134 |
@Override public void invokeAction(String command, Lookup context) { |
135 |
final ActionProgress listener = ActionProgress.start(context); |
136 |
new Thread() { |
137 |
@Override public void run() { |
138 |
s1.acquireUninterruptibly(); |
139 |
listener.finished(true); |
140 |
s2.release(); |
141 |
} |
142 |
}.start(); |
143 |
} |
144 |
} |
145 |
InstanceContent ic = new InstanceContent(); |
146 |
Lookup context = new AbstractLookup(ic); |
147 |
prj1.setLookup(Lookups.singleton(new SlowRun())); |
148 |
LookupSensitiveAction a = new MainProjectAction(CMD, null, "a", null, context); |
149 |
assertFalse(a.isEnabled()); |
150 |
ic.add(prj1); |
151 |
a.refresh(context, true); |
152 |
assertTrue(a.isEnabled()); |
153 |
a.actionPerformed(context); |
154 |
assertFalse(a.isEnabled()); |
155 |
s1.release(); |
156 |
s2.acquireUninterruptibly(); |
157 |
assertTrue(a.isEnabled()); |
158 |
a.actionPerformed(context); |
159 |
assertFalse(a.isEnabled()); |
160 |
prj2.setLookup(Lookups.singleton(new SlowRun())); |
161 |
ic.remove(prj1); |
162 |
ic.add(prj2); |
163 |
a.refresh(context, true); |
164 |
assertTrue(a.isEnabled()); |
165 |
} |
166 |
|
120 |
} |
167 |
} |