2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2013 SonarSource
4 * mailto:contact AT sonarsource DOT com
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.
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.
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.
21 package org.sonar.plugins.core.issue;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.sonar.core.issue.db.IssueDto;
27 import java.util.Date;
28 import java.util.List;
30 import static com.google.common.collect.Lists.newArrayList;
31 import static org.fest.assertions.Assertions.assertThat;
33 public class InitialOpenIssuesStackTest {
35 private InitialOpenIssuesStack initialOpenIssuesStack;
38 public void before() {
39 initialOpenIssuesStack = new InitialOpenIssuesStack();
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);
48 List<IssueDto> issueDtos = initialOpenIssuesStack.selectAndRemove(10);
49 assertThat(issueDtos).hasSize(1);
50 assertThat(issueDtos.get(0).getId()).isEqualTo(1L);
52 assertThat(initialOpenIssuesStack.getAllIssues()).isEmpty();
53 assertThat(initialOpenIssuesStack.getLoadedDate()).isEqualTo(loadedDate);
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)
63 List<IssueDto> issueDtos = initialOpenIssuesStack.selectAndRemove(10);
64 assertThat(issueDtos).hasSize(2);
66 assertThat(initialOpenIssuesStack.getAllIssues()).isEmpty();
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());
74 List<IssueDto> issueDtos = initialOpenIssuesStack.selectAndRemove(999);
75 assertThat(issueDtos).hasSize(0);
77 assertThat(initialOpenIssuesStack.getAllIssues()).hasSize(1);