3 * Copyright (C) 2009-2017 SonarSource SA
4 * mailto:info 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.scanner.repository;
22 import com.google.common.collect.HashBasedTable;
23 import com.google.common.collect.Table;
24 import java.util.Date;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.Mock;
28 import org.mockito.MockitoAnnotations;
29 import org.sonar.api.batch.bootstrap.ProjectKey;
30 import org.sonar.scanner.analysis.DefaultAnalysisMode;
31 import org.sonar.scanner.scan.BranchConfiguration;
33 import static org.assertj.core.api.Assertions.assertThat;
34 import static org.mockito.Matchers.any;
35 import static org.mockito.Matchers.eq;
36 import static org.mockito.Mockito.times;
37 import static org.mockito.Mockito.verify;
38 import static org.mockito.Mockito.verifyNoMoreInteractions;
39 import static org.mockito.Mockito.when;
41 public class ProjectRepositoriesProviderTest {
42 private ProjectRepositoriesProvider provider;
43 private ProjectRepositories project;
46 private ProjectRepositoriesLoader loader;
48 private ProjectKey projectKey;
50 private DefaultAnalysisMode mode;
52 private BranchConfiguration branchConfiguration;
56 MockitoAnnotations.initMocks(this);
58 Table<String, String, String> t1 = HashBasedTable.create();
59 Table<String, String, FileData> t2 = HashBasedTable.create();
61 project = new ProjectRepositories(t1, t2, new Date());
62 provider = new ProjectRepositoriesProvider();
64 when(projectKey.get()).thenReturn("key");
68 public void testValidation() {
69 when(mode.isIssues()).thenReturn(true);
70 when(loader.load(eq("key"), eq(true), any())).thenReturn(project);
72 provider.provide(loader, projectKey, mode, branchConfiguration);
76 public void testAssociated() {
77 when(mode.isIssues()).thenReturn(false);
78 when(loader.load(eq("key"), eq(false), any())).thenReturn(project);
80 ProjectRepositories repo = provider.provide(loader, projectKey, mode, branchConfiguration);
82 assertThat(repo.exists()).isEqualTo(true);
83 assertThat(repo.lastAnalysisDate()).isNotNull();
85 verify(mode, times(1)).isIssues();
86 verify(projectKey).get();
87 verify(loader).load(eq("key"), eq(false), eq(null));
88 verifyNoMoreInteractions(loader, projectKey, mode);