Skip to content

Commit

Permalink
multi select metadata field (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
carycheng authored May 24, 2018
1 parent 6689b91 commit b642393
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/java/com/box/sdk/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,22 @@ public Metadata test(String path, String value) {
return this;
}

/**
* Tests that a list of properties has the expected value.
* The values passed in will have to be an exact match with no extra elements.
* @param path the path that designates the key. Must be prefixed with a "/".
* @param values the list of expected values.
* @return this metadata object.
*/
public Metadata test(String path, List<String> values) {
JsonArray arr = new JsonArray();
for (String value : values) {
arr.add(value);
}
this.addOp("test", path, arr);
return this;
}

/**
* Returns a value.
* @param path the path that designates the key. Must be prefixed with a "/".
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/com/box/sdk/MetadataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ public void testTest() {
Assert.assertEquals("bar", op.get("value").asString());
}

@Test
@Category(UnitTest.class)
public void testMultiSelect() {
String expectedList = "[\"public test 1\",\"public test 2\",\"public test 3\"]";
List<String> list = new ArrayList<>();
list.add("public test 1");
list.add("public test 2");
list.add("public test 3");
Metadata m = new Metadata().test("/foo", list);
JsonArray operations = JsonArray.readFrom(m.getPatch());
JsonObject op = operations.get(0).asObject();
Assert.assertEquals("test", op.get("op").asString());
Assert.assertEquals("/foo", op.get("path").asString());
Assert.assertEquals(expectedList, op.get("value").toString());
}

@Test
@Category(UnitTest.class)
public void testRemove() {
Expand Down

0 comments on commit b642393

Please sign in to comment.