aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-09-11 22:39:21 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-09-11 22:39:21 +0200
commite7e6e5a30984f3c5b154da7885647a1d0d7229fb (patch)
treed1b579e78beb6cd8dcaf4055e1ea0b378ebb6b25 /src/test
parentef12da86339cd8225b8b774c9cd8412ddd550421 (diff)
downloadsonar-scanner-cli-e7e6e5a30984f3c5b154da7885647a1d0d7229fb.tar.gz
sonar-scanner-cli-e7e6e5a30984f3c5b154da7885647a1d0d7229fb.zip
Refactor org.sonar.runner.Main
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/sonar/runner/MainTest.java42
-rw-r--r--src/test/java/org/sonar/runner/StatsTest.java42
2 files changed, 59 insertions, 25 deletions
diff --git a/src/test/java/org/sonar/runner/MainTest.java b/src/test/java/org/sonar/runner/MainTest.java
index 751fae5..4760b80 100644
--- a/src/test/java/org/sonar/runner/MainTest.java
+++ b/src/test/java/org/sonar/runner/MainTest.java
@@ -24,37 +24,36 @@ import org.junit.Test;
import java.io.File;
import java.util.Properties;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
+
public class MainTest {
@Test
public void shouldParseEmptyArguments() {
- Properties props = new Main().parseArguments(new String[] {});
- assertThat(props.isEmpty(), is(true));
+ Properties props = new Main().parseArguments(new String[]{});
+ assertThat(props).isEmpty();
}
@Test
public void shouldParseArguments() {
- Properties props = new Main().parseArguments(new String[] {"-D", "foo=bar", "--define", "hello=world", "-Dboolean"});
- assertThat(props.size(), is(3));
- assertThat(props.getProperty("foo"), is("bar"));
- assertThat(props.getProperty("hello"), is("world"));
- assertThat(props.getProperty("boolean"), is("true"));
+ Properties props = new Main().parseArguments(new String[]{"-D", "foo=bar", "--define", "hello=world", "-Dboolean"});
+ assertThat(props).hasSize(3);
+ assertThat(props.getProperty("foo")).isEqualTo("bar");
+ assertThat(props.getProperty("hello")).isEqualTo("world");
+ assertThat(props.getProperty("boolean")).isEqualTo("true");
}
@Test
public void shouldEnableDebugMode() {
Properties props = new Main().parseArguments(new String[]{"-X"});
- assertThat(props.getProperty(Runner.PROPERTY_VERBOSE), is("true"));
+ assertThat(props.getProperty(Runner.PROPERTY_VERBOSE)).isEqualTo("true");
}
@Test
public void shouldDisableDebugModeByDefault() {
Properties props = new Main().parseArguments(new String[]{});
- assertThat(props.getProperty(Runner.PROPERTY_VERBOSE), nullValue());
+ assertThat(props.getProperty(Runner.PROPERTY_VERBOSE)).isNull();
}
@Test
@@ -65,7 +64,7 @@ public class MainTest {
Properties props = new Main().loadRunnerProperties(args);
- assertThat(props.getProperty("sonar.host.url"), is("http://moon/sonar"));
+ assertThat(props.getProperty("sonar.host.url")).isEqualTo("http://moon/sonar");
}
@Test
@@ -73,7 +72,7 @@ public class MainTest {
Properties args = new Properties();
Properties props = new Main().loadRunnerProperties(args);
- assertThat(props.isEmpty(), is(true));
+ assertThat(props).isEmpty();
}
@Test
@@ -83,7 +82,7 @@ public class MainTest {
args.setProperty("runner.settings", settings.getCanonicalPath());
Properties props = new Main().loadRunnerProperties(args);
- assertThat(props.getProperty("sonar.host.url"), is("http://other/sonar"));
+ assertThat(props.getProperty("sonar.host.url")).isEqualTo("http://other/sonar");
}
@Test
@@ -95,16 +94,9 @@ public class MainTest {
"-D", "project.home=" + projectHome.getCanonicalPath()
});
- assertThat(props.getProperty("project.prop"), is("foo"));
- assertThat(props.getProperty("overridden.prop"), is("project scope"));
- assertThat(props.getProperty("global.prop"), is("jdbc:mysql:localhost/sonar"));
+ assertThat(props.getProperty("project.prop")).isEqualTo("foo");
+ assertThat(props.getProperty("overridden.prop")).isEqualTo("project scope");
+ assertThat(props.getProperty("global.prop")).isEqualTo("jdbc:mysql:localhost/sonar");
}
- @Test
- public void shouldFormatTime() {
- assertThat(Main.formatTime(1 * 60 * 60 * 1000 + 2 * 60 * 1000 + 3 * 1000 + 400), is("1:02:03.400s"));
- assertThat(Main.formatTime(2 * 60 * 1000 + 3 * 1000 + 400), is("2:03.400s"));
- assertThat(Main.formatTime(3 * 1000 + 400), is("3.400s"));
- assertThat(Main.formatTime(400), is("0.400s"));
- }
}
diff --git a/src/test/java/org/sonar/runner/StatsTest.java b/src/test/java/org/sonar/runner/StatsTest.java
new file mode 100644
index 0000000..21ad901
--- /dev/null
+++ b/src/test/java/org/sonar/runner/StatsTest.java
@@ -0,0 +1,42 @@
+/*
+ * Sonar Standalone Runner
+ * Copyright (C) 2011 SonarSource
+ * dev@sonar.codehaus.org
+ *
+ * This program 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.
+ *
+ * This program 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 02
+ */
+package org.sonar.runner;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+
+public class StatsTest {
+
+ @Test
+ public void shouldPrintStats() {
+ new Stats().start().stop();
+ //TODO mock Logs
+ }
+
+ @Test
+ public void shouldFormatTime() {
+ assertThat(Stats.formatTime(1 * 60 * 60 * 1000 + 2 * 60 * 1000 + 3 * 1000 + 400)).isEqualTo("1:02:03.400s");
+ assertThat(Stats.formatTime(2 * 60 * 1000 + 3 * 1000 + 400)).isEqualTo("2:03.400s");
+ assertThat(Stats.formatTime(3 * 1000 + 400)).isEqualTo("3.400s");
+ assertThat(Stats.formatTime(400)).isEqualTo("0.400s");
+ }
+}