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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/*
* SonarQube :: Plugin API
* Copyright (C) 2009-2016 SonarSource SA
* mailto:contact AT sonarsource DOT com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.resources;
import org.junit.Test;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
public class QualifiersTest {
@Test
public void testRootView() {
View root = View.createRootView();
assertThat(Qualifiers.isView(root, true), is(true));
assertThat(Qualifiers.isView(root, false), is(true));
assertThat(Qualifiers.isProject(root, true), is(false));
assertThat(Qualifiers.isProject(root, false), is(false));
}
@Test
public void testSubView() {
View subview = View.createSubView();
assertThat(Qualifiers.isView(subview, true), is(true));
assertThat(Qualifiers.isView(subview, false), is(false));
assertThat(Qualifiers.isProject(subview, true), is(false));
assertThat(Qualifiers.isProject(subview, false), is(false));
}
@Test
public void testProject() {
Resource root = new Project("foo");
assertThat(Qualifiers.isView(root, true), is(false));
assertThat(Qualifiers.isView(root, false), is(false));
assertThat(Qualifiers.isProject(root, true), is(true));
assertThat(Qualifiers.isProject(root, false), is(true));
}
@Test
public void testModule() {
Resource sub = new Project("sub").setParent(new Project("root"));
assertThat(Qualifiers.isView(sub, true), is(false));
assertThat(Qualifiers.isView(sub, false), is(false));
assertThat(Qualifiers.isProject(sub, true), is(true));
assertThat(Qualifiers.isProject(sub, false), is(false));
}
private static class View extends Resource {
private String qualifier;
private View(String qualifier) {
this.qualifier = qualifier;
}
static View createRootView() {
return new View(Qualifiers.VIEW);
}
static View createSubView() {
return new View(Qualifiers.SUBVIEW);
}
@Override
public String getName() {
return null;
}
@Override
public String getLongName() {
return null;
}
@Override
public String getDescription() {
return null;
}
@Override
public Language getLanguage() {
return null;
}
@Override
public String getScope() {
return Scopes.PROJECT;
}
@Override
public String getQualifier() {
return qualifier;
}
@Override
public Resource getParent() {
return null;
}
@Override
public boolean matchFilePattern(String antPattern) {
return false;
}
}
}
|