3 * Copyright (C) 2009-2016 SonarSource SA
4 * mailto:contact AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.computation.task.projectanalysis.issue;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.mockito.Mockito;
25 import org.sonar.api.CoreProperties;
26 import org.sonar.api.config.Settings;
27 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolderRule;
28 import org.sonar.server.computation.task.projectanalysis.component.Component;
29 import org.sonar.server.computation.task.projectanalysis.component.SettingsRepository;
30 import org.sonar.server.user.index.UserDoc;
31 import org.sonar.server.user.index.UserIndex;
33 import static org.assertj.core.api.Assertions.assertThat;
34 import static org.mockito.Mockito.mock;
35 import static org.mockito.Mockito.when;
37 public class DefaultAssigneeTest {
39 public static final String PROJECT_KEY = "PROJECT_KEY";
41 TreeRootHolderRule rootHolder = mock(TreeRootHolderRule.class, Mockito.RETURNS_DEEP_STUBS);
42 UserIndex userIndex = mock(UserIndex.class);
43 Settings settings = new Settings();
44 SettingsRepository settingsRepository = mock(SettingsRepository.class);
46 DefaultAssignee underTest = new DefaultAssignee(rootHolder, userIndex, settingsRepository);
49 public void before() {
50 when(rootHolder.getRoot()).thenReturn(mock(Component.class));
51 when(settingsRepository.getSettings(rootHolder.getRoot())).thenReturn(settings);
55 public void no_default_assignee() {
56 assertThat(underTest.getLogin()).isNull();
60 public void default_assignee() {
61 settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik");
62 when(userIndex.getNullableByLogin("erik")).thenReturn(new UserDoc().setLogin("erik").setActive(true));
64 assertThat(underTest.getLogin()).isEqualTo("erik");
68 public void configured_login_does_not_exist() {
69 settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik");
70 when(userIndex.getNullableByLogin("erik")).thenReturn(null);
72 assertThat(underTest.getLogin()).isNull();
76 public void configured_login_is_disabled() {
77 settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik");
78 when(userIndex.getNullableByLogin("erik")).thenReturn(new UserDoc().setLogin("erik").setActive(false));
80 assertThat(underTest.getLogin()).isNull();