From aedff4f36398cc1c24b65d21b94c9c45631d83d8 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 23 Dec 2011 14:55:14 +0100 Subject: [PATCH] SONAR-983 add unit tests --- .../sonar/core/resource/ResourceIndexer.java | 2 +- .../core/resource/ResourceIndexerTest.java | 65 +++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 sonar-core/src/test/java/org/sonar/core/resource/ResourceIndexerTest.java 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() { + 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) { + } + })); + } +} -- 2.39.5