3 * Copyright (C) 2009-2019 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.scanner.bootstrap.GlobalAnalysisMode;
30 import org.sonar.scanner.bootstrap.ScannerProperties;
31 import org.sonar.scanner.scan.branch.BranchConfiguration;
33 import static org.assertj.core.api.Assertions.assertThat;
34 import static org.mockito.ArgumentMatchers.any;
35 import static org.mockito.ArgumentMatchers.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 ScannerProperties props;
50 private GlobalAnalysisMode mode;
52 private BranchConfiguration branchConfiguration;
56 MockitoAnnotations.initMocks(this);
58 Table<String, String, FileData> t2 = HashBasedTable.create();
60 project = new ProjectRepositories(t2, new Date());
61 provider = new ProjectRepositoriesProvider();
63 when(props.getKeyWithBranch()).thenReturn("key");
67 public void testValidation() {
68 when(mode.isIssues()).thenReturn(true);
69 when(loader.load(eq("key"), eq(true), any())).thenReturn(project);
71 provider.provide(loader, props, mode, branchConfiguration);
75 public void testAssociated() {
76 when(mode.isIssues()).thenReturn(false);
77 when(loader.load(eq("key"), eq(false), any())).thenReturn(project);
79 ProjectRepositories repo = provider.provide(loader, props, mode, branchConfiguration);
81 assertThat(repo.exists()).isEqualTo(true);
82 assertThat(repo.lastAnalysisDate()).isNotNull();
84 verify(mode, times(1)).isIssues();
85 verify(props).getKeyWithBranch();
86 verify(loader).load(eq("key"), eq(false), eq(null));
87 verifyNoMoreInteractions(loader, props, mode);