aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-02-25 09:44:39 +0100
committersimonbrandhof <simon.brandhof@gmail.com>2011-02-25 09:44:39 +0100
commitd12576c5f486791bf80450f54a98dec2c6bb6a4b (patch)
tree36550e8a0cd40618089924d5c5335564809c705d
parente768a3bcd80cd35f06fca377321a6c5897252f8a (diff)
downloadsonarqube-d12576c5f486791bf80450f54a98dec2c6bb6a4b.tar.gz
sonarqube-d12576c5f486791bf80450f54a98dec2c6bb6a4b.zip
Fix unit test
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java48
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/DeprecatedKeyValueFormatTest.java12
2 files changed, 24 insertions, 36 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java
index e2d198fc387..c6786cf79de 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java
@@ -72,6 +72,23 @@ public final class KeyValueFormat {
}
}
+ public static final class ToStringConverter extends Converter<Object> {
+ static final ToStringConverter INSTANCE = new ToStringConverter();
+
+ private ToStringConverter() {
+ }
+
+ @Override
+ String format(Object o) {
+ return o.toString();
+ }
+
+ @Override
+ String parse(String s) {
+ throw new IllegalStateException("Can not parse with ToStringConverter: " + s);
+ }
+ }
+
public static final class IntegerConverter extends Converter<Integer> {
static final IntegerConverter INSTANCE = new IntegerConverter();
@@ -169,7 +186,7 @@ public final class KeyValueFormat {
return map;
}
- public static Map<String, String> parse(String data) {
+ public static Map parse(String data) {
return parse(data, StringConverter.INSTANCE, StringConverter.INSTANCE);
}
@@ -316,8 +333,8 @@ public final class KeyValueFormat {
/**
* @since 2.7
*/
- public static String format(Map<String, String> map) {
- return format(map, StringConverter.INSTANCE, StringConverter.INSTANCE);
+ public static String format(Map map) {
+ return format(map, ToStringConverter.INSTANCE, ToStringConverter.INSTANCE);
}
/**
@@ -408,31 +425,6 @@ public final class KeyValueFormat {
}
- /**
- * Transforms a Object... into a string with the format : "object1=object2;object3=object4..."
- *
- * @param objects the object list to transform
- * @return the formatted string
- * @deprecated since 2.7 because there's not the inverse method to parse.
- */
- @Deprecated
- public static String format(Object... objects) {
- StringBuilder sb = new StringBuilder();
- boolean first = true;
- if (objects != null) {
- for (int i = 0; i < objects.length; i++) {
- if (!first) {
- sb.append(PAIR_SEPARATOR);
- }
- sb.append(objects[i++].toString());
- sb.append(FIELD_SEPARATOR);
- sb.append(objects[i]);
- first = false;
- }
- }
- return sb.toString();
- }
-
@Deprecated
public interface Transformer<KEY, VALUE> {
KeyValue<KEY, VALUE> transform(String key, String value);
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/DeprecatedKeyValueFormatTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/DeprecatedKeyValueFormatTest.java
index 8c2a1a1a8c0..2e041641146 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/DeprecatedKeyValueFormatTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/DeprecatedKeyValueFormatTest.java
@@ -21,16 +21,17 @@ package org.sonar.api.utils;
import com.google.common.collect.Multiset;
import com.google.common.collect.TreeMultiset;
-import static junit.framework.Assert.assertEquals;
import org.apache.commons.collections.bag.TreeBag;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
import org.junit.Test;
import org.sonar.api.rules.RulePriority;
import java.util.Map;
import java.util.TreeMap;
+import static junit.framework.Assert.assertEquals;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
public class DeprecatedKeyValueFormatTest {
@Test
@@ -68,11 +69,6 @@ public class DeprecatedKeyValueFormatTest {
}
@Test
- public void formatVarargs() {
- assertThat(KeyValueFormat.format("hello", 1, "key", 3), is("hello=1;key=3"));
- }
-
- @Test
public void parse() {
Map<String, String> map = KeyValueFormat.parse("hello=world;key1=val1;key2=;key3=val3");
assertThat(map.size(), is(4));