|
2 | 2 |
|
3 | 3 | import org.junit.Test; |
4 | 4 |
|
| 5 | +import java.util.Map; |
| 6 | + |
5 | 7 | import static com.cleancoder.args.ArgsException.ErrorCode.*; |
6 | 8 | import static org.junit.Assert.*; |
7 | 9 |
|
@@ -184,7 +186,28 @@ public void manyStringArrayElements() throws Exception { |
184 | 186 | assertEquals("alpha", result[0]); |
185 | 187 | assertEquals("beta", result[1]); |
186 | 188 | assertEquals("gamma", result[2]); |
| 189 | + } |
| 190 | + |
| 191 | + @Test |
| 192 | + public void MapArgument() throws Exception { |
| 193 | + Args args = new Args("f&", new String[] {"-f", "key1:val1,key2:val2"}); |
| 194 | + assertTrue(args.has('f')); |
| 195 | + Map<String, String> map = args.getMap('f'); |
| 196 | + assertEquals("val1", map.get("key1")); |
| 197 | + assertEquals("val2", map.get("key2")); |
| 198 | + } |
| 199 | + |
| 200 | + @Test(expected=ArgsException.class) |
| 201 | + public void malFormedMapArgument() throws Exception { |
| 202 | + Args args = new Args("f&", new String[] {"-f", "key1:val1,key2"}); |
| 203 | + } |
187 | 204 |
|
| 205 | + @Test |
| 206 | + public void oneMapArgument() throws Exception { |
| 207 | + Args args = new Args("f&", new String[] {"-f", "key1:val1"}); |
| 208 | + assertTrue(args.has('f')); |
| 209 | + Map<String, String> map = args.getMap('f'); |
| 210 | + assertEquals("val1", map.get("key1")); |
188 | 211 | } |
189 | 212 |
|
190 | 213 | @Test |
|
0 commit comments