]> source.dussan.org Git - sonarqube.git/blob
df081dd358217b5214d1af0b1d2cda725086d397
[sonarqube.git] /
1 /*
2  * SonarQube, open source software quality management tool.
3  * Copyright (C) 2008-2013 SonarSource
4  * mailto:contact AT sonarsource DOT com
5  *
6  * SonarQube 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.
10  *
11  * SonarQube 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.
15  *
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.
19  */
20
21 package org.sonar.plugins.core.issue;
22
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.sonar.core.issue.db.IssueDto;
26
27 import java.util.Date;
28 import java.util.List;
29
30 import static com.google.common.collect.Lists.newArrayList;
31 import static org.fest.assertions.Assertions.assertThat;
32
33 public class InitialOpenIssuesStackTest {
34
35   private InitialOpenIssuesStack initialOpenIssuesStack;
36
37   @Before
38   public void before() {
39     initialOpenIssuesStack = new InitialOpenIssuesStack();
40   }
41
42   @Test
43   public void should_get_and_remove() {
44     Date loadedDate = new Date();
45     IssueDto issueDto = new IssueDto().setComponentId(10).setId(1L);
46     initialOpenIssuesStack.setIssues(newArrayList(issueDto), loadedDate);
47
48     List<IssueDto> issueDtos = initialOpenIssuesStack.selectAndRemove(10);
49     assertThat(issueDtos).hasSize(1);
50     assertThat(issueDtos.get(0).getId()).isEqualTo(1L);
51
52     assertThat(initialOpenIssuesStack.getAllIssues()).isEmpty();
53     assertThat(initialOpenIssuesStack.getLoadedDate()).isEqualTo(loadedDate);
54   }
55
56   @Test
57   public void should_get_and_remove_with_many_issues_on_same_resource() {
58     initialOpenIssuesStack.setIssues(newArrayList(
59         new IssueDto().setComponentId(10).setId(1L),
60         new IssueDto().setComponentId(10).setId(2L)
61     ), new Date());
62
63     List<IssueDto> issueDtos = initialOpenIssuesStack.selectAndRemove(10);
64     assertThat(issueDtos).hasSize(2);
65
66     assertThat(initialOpenIssuesStack.getAllIssues()).isEmpty();
67   }
68
69   @Test
70   public void should_do_nothing_if_resource_not_found() {
71     IssueDto issueDto = new IssueDto().setComponentId(10).setId(1L);
72     initialOpenIssuesStack.setIssues(newArrayList(issueDto), new Date());
73
74     List<IssueDto> issueDtos = initialOpenIssuesStack.selectAndRemove(999);
75     assertThat(issueDtos).hasSize(0);
76
77     assertThat(initialOpenIssuesStack.getAllIssues()).hasSize(1);
78   }
79 }