aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2011-12-23 14:55:14 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2011-12-23 14:55:23 +0100
commitaedff4f36398cc1c24b65d21b94c9c45631d83d8 (patch)
tree99b7ef3d8e527d88df99d6445e4dff319fef3566
parentf018647e4a4e093ce27d8b49de789dfa4801d542 (diff)
downloadsonarqube-aedff4f36398cc1c24b65d21b94c9c45631d83d8.tar.gz
sonarqube-aedff4f36398cc1c24b65d21b94c9c45631d83d8.zip
SONAR-983 add unit tests
-rw-r--r--sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexer.java2
-rw-r--r--sonar-core/src/test/java/org/sonar/core/resource/ResourceIndexerTest.java65
2 files changed, 66 insertions, 1 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexer.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexer.java
index 32c8df9a261..d184792df99 100644
--- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexer.java
+++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexer.java
@@ -40,7 +40,7 @@ public class ResourceIndexer implements BatchComponent, ServerComponent {
* Hardcoded list of qualifiers to index. Need to be configurable.
* Directories and packages are explicitly excluded.
*/
- private String[] INDEXABLE_QUALIFIERS = {
+ static final String[] INDEXABLE_QUALIFIERS = {
Qualifiers.VIEW,
Qualifiers.SUBVIEW,
Qualifiers.PROJECT,
diff --git a/sonar-core/src/test/java/org/sonar/core/resource/ResourceIndexerTest.java b/sonar-core/src/test/java/org/sonar/core/resource/ResourceIndexerTest.java
new file mode 100644
index 00000000000..7e6d2e5fc0a
--- /dev/null
+++ b/sonar-core/src/test/java/org/sonar/core/resource/ResourceIndexerTest.java
@@ -0,0 +1,65 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.resource;
+
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.junit.Test;
+import org.sonar.api.resources.Qualifiers;
+
+import static org.mockito.Mockito.*;
+
+public class ResourceIndexerTest {
+
+ @Test
+ public void shouldNotIndexDirectories() {
+ ResourceIndexerDao dao = mock(ResourceIndexerDao.class);
+ ResourceIndexer indexer = new ResourceIndexer(dao);
+ indexer.index("org.foo", Qualifiers.DIRECTORY, 12, 9);
+
+ verifyZeroInteractions(dao);
+ }
+
+ @Test
+ public void shouldIndexResource() {
+ ResourceIndexerDao dao = mock(ResourceIndexerDao.class);
+ ResourceIndexer indexer = new ResourceIndexer(dao);
+ indexer.index("org.foo.Bar", Qualifiers.FILE, 12, 9);
+
+ verify(dao).index("org.foo.Bar", Qualifiers.FILE, 12, 9);
+ }
+
+ @Test
+ public void shouldIndexAll() {
+ ResourceIndexerDao dao = mock(ResourceIndexerDao.class);
+ ResourceIndexer indexer = new ResourceIndexer(dao);
+ indexer.indexAll();
+
+ verify(dao).index(argThat(new BaseMatcher<ResourceIndexerFilter>() {
+ public boolean matches(Object o) {
+ ResourceIndexerFilter filter = (ResourceIndexerFilter) o;
+ return filter.isEnabled() && filter.getScopes().length == 2 && filter.getQualifiers().length == ResourceIndexer.INDEXABLE_QUALIFIERS.length;
+ }
+
+ public void describeTo(Description description) {
+ }
+ }));
+ }
+}