From: Simon Brandhof Date: Tue, 29 Apr 2014 16:31:17 +0000 (+0200) Subject: SONAR-5254 add missing test X-Git-Tag: 4.4-RC1~1338 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bb5e58f28631466a3acc512ea3159a917c259769;p=sonarqube.git SONAR-5254 add missing test --- diff --git a/sonar-server/src/test/java/org/sonar/server/source/ws/ScmActionTest.java b/sonar-server/src/test/java/org/sonar/server/source/ws/ScmActionTest.java new file mode 100644 index 00000000000..b768a80bbef --- /dev/null +++ b/sonar-server/src/test/java/org/sonar/server/source/ws/ScmActionTest.java @@ -0,0 +1,89 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.source.ws; + +import org.junit.Before; +import org.junit.Test; +import org.sonar.api.utils.text.JsonWriter; +import org.sonar.server.source.SourceService; +import org.sonar.server.ws.WsTester; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class ScmActionTest { + + SourceService sourceService = mock(SourceService.class); + ScmWriter scmWriter = mock(ScmWriter.class); + + WsTester tester; + + @Before + public void setUp() throws Exception { + tester = new WsTester(new SourcesWs(mock(ShowAction.class), new ScmAction(sourceService, scmWriter))); + } + + @Test + public void get_scm() throws Exception { + String fileKey = "src/Foo.java"; + when(sourceService.getScmAuthorData(fileKey)).thenReturn("1=julien"); + when(sourceService.getScmDateData(fileKey)).thenReturn("1=2013-01-01"); + + WsTester.TestRequest request = tester.newRequest("scm").setParam("key", fileKey); + request.execute(); + verify(scmWriter).write(eq("1=julien"), eq("1=2013-01-01"), eq(1), eq(Integer.MAX_VALUE), eq(true), any(JsonWriter.class)); + } + + @Test + public void do_not_group_lines_by_commit() throws Exception { + String fileKey = "src/Foo.java"; + when(sourceService.getScmAuthorData(fileKey)).thenReturn("1=julien"); + when(sourceService.getScmDateData(fileKey)).thenReturn("1=2013-01-01"); + + WsTester.TestRequest request = tester.newRequest("scm").setParam("key", fileKey).setParam("groupCommits", "false"); + request.execute(); + verify(scmWriter).write(eq("1=julien"), eq("1=2013-01-01"), eq(1), eq(Integer.MAX_VALUE), eq(false), any(JsonWriter.class)); + } + + @Test + public void range_of_lines() throws Exception { + String fileKey = "src/Foo.java"; + when(sourceService.getScmAuthorData(fileKey)).thenReturn("1=julien"); + when(sourceService.getScmDateData(fileKey)).thenReturn("1=2013-01-01"); + + WsTester.TestRequest request = tester.newRequest("scm").setParam("key", fileKey).setParam("from", "3").setParam("to", "20"); + request.execute(); + verify(scmWriter).write(eq("1=julien"), eq("1=2013-01-01"), eq(3), eq(20), eq(true), any(JsonWriter.class)); + } + + @Test + public void accept_negative_from_line() throws Exception { + String fileKey = "src/Foo.java"; + when(sourceService.getScmAuthorData(fileKey)).thenReturn("1=julien"); + when(sourceService.getScmDateData(fileKey)).thenReturn("1=2013-01-01"); + + WsTester.TestRequest request = tester.newRequest("scm").setParam("key", fileKey).setParam("from", "-3").setParam("to", "20"); + request.execute(); + verify(scmWriter).write(eq("1=julien"), eq("1=2013-01-01"), eq(1), eq(20), eq(true), any(JsonWriter.class)); + } +}