]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3755 complete EncodingUtilsTest
authorSimon Brandhof <simon.brandhof@gmail.com>
Tue, 30 Apr 2013 10:04:14 +0000 (12:04 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Tue, 30 Apr 2013 10:04:14 +0000 (12:04 +0200)
sonar-ws-client/src/main/java/org/sonar/wsclient/internal/EncodingUtils.java
sonar-ws-client/src/test/java/org/sonar/wsclient/internal/EncodingUtilsTest.java

index 1e1631c66980007fe3ad4ef33543f7cdd19ba9f7..698500541ec00f6d003627c199ccdf6d59e99ffd 100644 (file)
@@ -37,6 +37,9 @@ public class EncodingUtils {
   }
 
   public static Map<String, Object> toMap(String... array) {
+    if (array.length%2==1) {
+      throw new IllegalArgumentException("Not an even number of arguments");
+    }
     Map<String, Object> map = new LinkedHashMap<String, Object>();
     for (int i = 0; i < array.length; i += 2) {
       Object value = array[i + 1];
index 1fa30efa8360b2e16b39d43717d123c66f5f4910..6e1f6a8e1a38f278db749a4672f0c483abd11941 100644 (file)
@@ -24,6 +24,7 @@ import org.junit.Test;
 import java.util.Date;
 
 import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
 import static org.fest.assertions.MapAssert.entry;
 
 public class EncodingUtilsTest {
@@ -48,4 +49,14 @@ public class EncodingUtilsTest {
     assertThat(EncodingUtils.toMap("1", "one", "2", "two")).hasSize(2).includes(entry("1", "one"), entry("2", "two"));
     assertThat(EncodingUtils.toMap("foo", null)).isEmpty();
   }
+
+  @Test
+  public void toMap_should_fail_if_odd_arguments() {
+    try {
+      EncodingUtils.toMap("foo");
+      fail();
+    } catch (IllegalArgumentException e) {
+      assertThat(e).hasMessage("Not an even number of arguments");
+    }
+  }
 }