import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.util.Collection;
-import java.util.List;
+import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingDataObjectCodecTreeNode;
private static final NodeIdentifier TOP_LEVEL_LIST_ARG = new NodeIdentifier(TopLevelList.QNAME);
private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
- private static final List<TopLevelList> TWO_LIST = createList(2);
- private static final List<TopLevelList> THREE_LIST = createList(3);
+ private static final Map<TopLevelListKey, TopLevelList> TWO_LIST = createList(2);
+ private static final Map<TopLevelListKey, TopLevelList> THREE_LIST = createList(3);
private static final Top TOP_TWO_LIST_DATA = new TopBuilder().setTopLevelList(TWO_LIST).build();
private static final Top TOP_THREE_LIST_DATA = new TopBuilder().setTopLevelList(THREE_LIST).build();
private static final NodeIdentifier LEAF_ARG = new NodeIdentifier(QName.create(Cont.QNAME, "caching"));
private static final InstanceIdentifier<Cont> CONT_PATH = InstanceIdentifier.create(Cont.class);
- // Note: '400' is assumed to not be interned by the JVM here
- private static final Cont CONT_DATA = new ContBuilder().setCaching(new MyType(400)).setNonCaching("test").build();
- private static final Cont CONT2_DATA = new ContBuilder().setCaching(new MyType(400)).setNonCaching("test2").build();
+ private static final Cont CONT_DATA = new ContBuilder().setCaching(new MyType(dataValue())).setNonCaching("test")
+ .build();
+ private static final Cont CONT2_DATA = new ContBuilder().setCaching(new MyType(dataValue())).setNonCaching("test2")
+ .build();
private BindingDataObjectCodecTreeNode<Top> topNode;
private BindingDataObjectCodecTreeNode<Cont> contNode;
+ private static String dataValue() {
+ // We are battling interning here
+ return new StringBuilder("foo").toString();
+ }
+
@Override
@Before
public void before() {
contNode = registry.getCodecContext().getSubtreeCodec(CONT_PATH);
}
- private static List<TopLevelList> createList(final int num) {
-
- final ImmutableList.Builder<TopLevelList> builder = ImmutableList.builder();
+ private static Map<TopLevelListKey, TopLevelList> createList(final int num) {
+ final ImmutableMap.Builder<TopLevelListKey, TopLevelList> builder = ImmutableMap.builder();
for (int i = 0; i < num; i++) {
final TopLevelListKey key = new TopLevelListKey("test-" + i);
- builder.add(new TopLevelListBuilder().withKey(key).build());
+ builder.put(key, new TopLevelListBuilder().withKey(key).build());
}
return builder.build();
}
final Top input = new TopBuilder().build();
assertNull(input.getTopLevelList());
- assertEquals(ImmutableList.of(), input.nonnullTopLevelList());
+ assertEquals(ImmutableMap.of(), input.nonnullTopLevelList());
final NormalizedNode<?, ?> dom = cachingCodec.serialize(input);
final Top output = cachingCodec.deserialize(dom);
assertTrue(output.equals(input));
assertNull(output.getTopLevelList());
- assertEquals(ImmutableList.of(), output.nonnullTopLevelList());
+ assertEquals(ImmutableMap.of(), output.nonnullTopLevelList());
}
@SafeVarargs