forked from flutter/flutter-intellij
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectWatchTest.java
57 lines (48 loc) · 2.2 KB
/
ProjectWatchTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Copyright 2017 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
package io.flutter.project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.ModuleRootModificationUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
import io.flutter.testing.ProjectFixture;
import io.flutter.testing.Testing;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.Assert.assertNotEquals;
public class ProjectWatchTest {
@Rule
public final ProjectFixture<IdeaProjectTestFixture> fixture = Testing.makeEmptyModule();
@Test
@Ignore
public void shouldSendEventWhenProjectCloses() throws Exception {
Testing.runOnDispatchThread(() -> {
final AtomicInteger callCount = new AtomicInteger();
final ProjectWatch listen = ProjectWatch.subscribe(fixture.getProject(), callCount::incrementAndGet);
ProjectManager.getInstance().closeProject(fixture.getProject());
// The number of events fired is an implementation detail of the project manager. We just need at least one.
assertNotEquals(0, callCount.get());
});
}
@Test @Ignore
public void shouldSendEventWhenModuleRootsChange() throws Exception {
Testing.runOnDispatchThread(() -> {
final AtomicInteger callCount = new AtomicInteger();
try (var listen = ProjectWatch.subscribe(fixture.getProject(), callCount::incrementAndGet)) {
VirtualFile[] contentRoots = ModuleRootManager.getInstance(fixture.getModule()).getContentRoots();
VirtualFile dir = contentRoots[0].createChildDirectory(this, "testDir");
ModuleRootModificationUtil.addContentRoot(fixture.getModule(), dir);
PlatformTestUtil.dispatchAllEventsInIdeEventQueue();
// The number of events fired is an implementation detail of the project manager. We just need at least one.
assertNotEquals(0, callCount.get());
}
});
}
}