|
17 | 17 |
|
18 | 18 | package org.openqa.selenium.remote;
|
19 | 19 |
|
| 20 | +import com.google.common.collect.ImmutableList; |
20 | 21 | import com.google.common.collect.ImmutableMap;
|
21 | 22 | import com.google.common.collect.Lists;
|
22 | 23 | import com.google.common.collect.Maps;
|
@@ -242,6 +243,18 @@ public void testShouldCallToMapMethodIfPresent() {
|
242 | 243 | assertEquals("{\"a key\":\"a value\"}", json);
|
243 | 244 | }
|
244 | 245 |
|
| 246 | + @Test |
| 247 | + public void testShouldCallAsListMethodIfPresent() { |
| 248 | + String json = new BeanToJsonConverter().convert(new Listable1("item1", "item2")); |
| 249 | + assertEquals("[\"item1\",\"item2\"]", json); |
| 250 | + } |
| 251 | + |
| 252 | + @Test |
| 253 | + public void testShouldCallToListMethodIfPresent() { |
| 254 | + String json = new BeanToJsonConverter().convert(new Listable2("item1", "item2")); |
| 255 | + assertEquals("[\"item1\",\"item2\"]", json); |
| 256 | + } |
| 257 | + |
245 | 258 | @Test
|
246 | 259 | public void testConvertsToJsonMethodResultToPrimitiveIfItIsNotJson() {
|
247 | 260 | // We want this parsed as a string primitive, but JsonParser will reject it
|
@@ -562,4 +575,29 @@ public Map<String, Object> toMap() {
|
562 | 575 | return ImmutableMap.of(key, value);
|
563 | 576 | }
|
564 | 577 | }
|
| 578 | + |
| 579 | + public class Listable1 { |
| 580 | + private List<String> items; |
| 581 | + |
| 582 | + public Listable1(String... items) { |
| 583 | + this.items = ImmutableList.copyOf(items); |
| 584 | + } |
| 585 | + |
| 586 | + public List<String> asList() { |
| 587 | + return items; |
| 588 | + } |
| 589 | + } |
| 590 | + |
| 591 | + public class Listable2 { |
| 592 | + private List<String> items; |
| 593 | + |
| 594 | + public Listable2(String... items) { |
| 595 | + this.items = ImmutableList.copyOf(items); |
| 596 | + } |
| 597 | + |
| 598 | + public List<String> toList() { |
| 599 | + return items; |
| 600 | + } |
| 601 | + } |
| 602 | + |
565 | 603 | }
|
0 commit comments