2 * Copyright 2000-2009 JetBrains s.r.o.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package com
.intellij
.module
;
18 import com
.intellij
.openapi
.Disposable
;
19 import com
.intellij
.openapi
.application
.Result
;
20 import com
.intellij
.openapi
.application
.WriteAction
;
21 import com
.intellij
.openapi
.module
.*;
22 import com
.intellij
.testFramework
.PlatformTestCase
;
27 public class ModulePointerTest
extends PlatformTestCase
{
28 public void testCreateByName() throws Exception
{
29 final ModulePointer pointer
= getPointerManager().create("m");
30 assertNull(pointer
.getModule());
31 assertEquals("m", pointer
.getModuleName());
33 final Module module
= addModule("m");
35 assertSame(module
, pointer
.getModule());
36 assertEquals("m", pointer
.getModuleName());
39 public void testCreateByModule() throws Exception
{
40 final Module module
= addModule("x");
41 final ModulePointer pointer
= getPointerManager().create(module
);
42 assertSame(module
, pointer
.getModule());
43 assertEquals("x", pointer
.getModuleName());
45 ModifiableModuleModel model
= getModuleManager().getModifiableModel();
46 model
.disposeModule(module
);
49 assertNull(pointer
.getModule());
50 assertEquals("x", pointer
.getModuleName());
53 public void testRenameModule() throws Exception
{
54 final ModulePointer pointer
= getPointerManager().create("abc");
55 final Module module
= addModule("abc");
56 ModifiableModuleModel model
= getModuleManager().getModifiableModel();
57 model
.renameModule(module
, "xyz");
59 assertSame(module
, pointer
.getModule());
60 assertEquals("xyz", pointer
.getModuleName());
63 public void testDisposePointerFromUncommitedModifiableModel() throws Exception
{
64 final ModifiableModuleModel modifiableModel
= getModuleManager().getModifiableModel();
65 final Module module
= modifiableModel
.newModule(myProject
.getBaseDir().getPath() + "/xxx.iml", EmptyModuleType
.getInstance());
66 final ModulePointer pointer
= getPointerManager().create(module
);
68 assertSame(module
, pointer
.getModule());
69 assertEquals("xxx", pointer
.getModuleName());
71 modifiableModel
.dispose();
73 assertNull(pointer
.getModule());
74 assertEquals("xxx", pointer
.getModuleName());
77 private ModuleManager
getModuleManager() {
78 return ModuleManager
.getInstance(myProject
);
81 private Module
addModule(final String name
) {
82 final ModifiableModuleModel model
= getModuleManager().getModifiableModel();
83 final Module module
= model
.newModule(myProject
.getBaseDir().getPath() + "/" + name
+ ".iml", EmptyModuleType
.getInstance());
85 disposeOnTearDown(new Disposable() {
86 public void dispose() {
87 if (!module
.isDisposed()) {
88 getModuleManager().disposeModule(module
);
95 private static void commitModel(final ModifiableModuleModel model
) {
97 protected void run(final Result result
) {
103 private ModulePointerManager
getPointerManager() {
104 return ModulePointerManager
.getInstance(myProject
);