Skip to content

Commit

Permalink
Added unit test for Utils.buildMapFromKeyValuePairs
Browse files Browse the repository at this point in the history
- Fixed a bug in buildMapFromKeyValuePairs
  • Loading branch information
aforcier committed Apr 20, 2015
1 parent bbba60a commit 570ae57
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Set;

import static org.junit.Assert.assertEquals;
import static org.wordpress.android.editor.Utils.buildMapFromKeyValuePairs;
import static org.wordpress.android.editor.Utils.getChangeMapFromSets;
import static org.wordpress.android.editor.Utils.splitDelimitedString;

Expand All @@ -34,6 +35,40 @@ public void testSplitDelimitedString() {
assertEquals(Collections.emptySet(), splitDelimitedString("", "~"));
}

@Test
public void testBuildMapFromKeyValuePairs() {
Set<String> keyValueSet = new HashSet<>();
Map<String, String> expectedMap = new HashMap<>();

// Test normal usage
keyValueSet.add("id=test");
keyValueSet.add("name=example");

expectedMap.put("id", "test");
expectedMap.put("name", "example");

assertEquals(expectedMap, buildMapFromKeyValuePairs(keyValueSet));

// Test mixed valid and invalid entries
keyValueSet.clear();
keyValueSet.add("test");
keyValueSet.add("name=example");

expectedMap.clear();
expectedMap.put("name", "example");

assertEquals(expectedMap, buildMapFromKeyValuePairs(keyValueSet));

// Test invalid entry
keyValueSet.clear();
keyValueSet.add("test");

assertEquals(Collections.emptyMap(), buildMapFromKeyValuePairs(keyValueSet));

// Test empty sets
assertEquals(Collections.emptyMap(), buildMapFromKeyValuePairs(Collections.<String>emptySet()));
}

@Test
public void testGetChangeMapFromSets() {
Set<String> oldSet = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public static Map<String, String> buildMapFromKeyValuePairs(Set<String> keyValue
Map<String, String> selectionArgs = new HashMap<>();
for (String pair : keyValueSet) {
String[] splitString = pair.split("=");
selectionArgs.put(splitString[0], splitString[1]);
if (splitString.length == 2) {
selectionArgs.put(splitString[0], splitString[1]);
}
}
return selectionArgs;
}
Expand Down

0 comments on commit 570ae57

Please sign in to comment.