#110 - Fixed the collection of values in HalEmbeddedBuilder.
HalEmbeddedBuilder now favors the collection rel to lookup already registered embeddeds.
This commit is contained in:
@@ -62,16 +62,21 @@ class HalEmbeddedBuilder {
|
||||
return;
|
||||
}
|
||||
|
||||
String singleRel = getDefaultedRelFor(type, false);
|
||||
List<Object> currentValue = embeddeds.get(singleRel);
|
||||
String rel = getDefaultedRelFor(type, true);
|
||||
|
||||
if (!embeddeds.containsKey(rel)) {
|
||||
rel = getDefaultedRelFor(type, false);
|
||||
}
|
||||
|
||||
List<Object> currentValue = embeddeds.get(rel);
|
||||
|
||||
if (currentValue == null) {
|
||||
ArrayList<Object> arrayList = new ArrayList<Object>();
|
||||
arrayList.add(value);
|
||||
embeddeds.put(singleRel, arrayList);
|
||||
embeddeds.put(rel, arrayList);
|
||||
} else if (currentValue.size() == 1) {
|
||||
currentValue.add(value);
|
||||
embeddeds.remove(singleRel);
|
||||
embeddeds.remove(rel);
|
||||
embeddeds.put(getDefaultedRelFor(type, true), currentValue);
|
||||
} else {
|
||||
currentValue.add(value);
|
||||
|
||||
@@ -63,6 +63,20 @@ public class HalEmbeddedBuilderUnitTest {
|
||||
assertThat(map.get("long"), Matchers.<List<Object>> allOf(hasSize(1), hasItem(1L)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #110
|
||||
*/
|
||||
@Test
|
||||
public void correctlyPilesUpResourcesInCollectionRel() {
|
||||
|
||||
Map<String, List<Object>> map = setUpBuilder("foo", "bar", "foobar", 1L);
|
||||
|
||||
assertThat(map.containsKey("string"), is(false));
|
||||
assertThat(map.get("strings"),
|
||||
Matchers.<List<Object>> allOf(hasSize(3), Matchers.<Object> hasItems("foo", "bar", "foobar")));
|
||||
assertThat(map.get("long"), Matchers.<List<Object>> allOf(hasSize(1), hasItem(1L)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #81, #83
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user