]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5254 add missing test
authorSimon Brandhof <simon.brandhof@gmail.com>
Tue, 29 Apr 2014 16:31:17 +0000 (18:31 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Tue, 29 Apr 2014 16:31:17 +0000 (18:31 +0200)
sonar-server/src/test/java/org/sonar/server/source/ws/ScmActionTest.java [new file with mode: 0644]

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 (file)
index 0000000..b768a80
--- /dev/null
@@ -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));
+  }
+}