Serializer { String serialize(Object obj) { return gson.toJson(obj); }  Serializer withToStringSerialization(Class<T> clazz); Serializer withDoublePrecision(final int places); Serializer withFloatPrecision(final int places); Serializer withTypeAdapter(Type type, Object typeAdapter); Serializer withTypeHierarchyAdapter(Class<?> baseType, Object typeAdapter);  }
@Test public void testMapSorting() { Map<String, String> stringOnlyHashMap = new HashMap<>(); stringOnlyHashMap.put("b", "bar"); stringOnlyHashMap.put("a", "foo"); stringOnlyHashMap.put("z", "baz"); stringOnlyHashMap.put("g", "test"); Map<StringObject, String> stringObjectHashMap = new HashMap<>(); stringObjectHashMap.put(new StringObject("b"), "bar"); stringObjectHashMap.put(new StringObject("a"), "foo"); stringObjectHashMap.put(new StringObject("z"), "baz"); stringObjectHashMap.put(new StringObject("g"), "test"); Bond.obs("stringOnlyHashMap", serializer.serialize(stringOnlyHashMap)) .obs("stringObjectHashMap", serializer.serialize(stringObjectHashMap)) .spy("hash maps"); Map<String, String> stringOnlyTreeMap = new TreeMap<>(REVERSE_SORT_COMPARATOR); stringOnlyTreeMap.put("b", "bar"); stringOnlyTreeMap.put("a", "foo"); stringOnlyTreeMap.put("z", "baz"); stringOnlyTreeMap.put("g", "test"); Bond.obs("stringOnlyTreeMap", serializer.serialize(stringOnlyTreeMap)).spy("tree maps"); }
@Test public void testSetSorting() { Set<String> stringHashSet = Sets.newHashSet("b", "a", "z", "g"); Set<StringObject> stringObjectHashSet = Sets.newHashSet(new StringObject("b"), new StringObject("a"), new StringObject("z"), new StringObject("g")); Bond.obs("stringHashSet", serializer.serialize(stringHashSet)) .obs("stringObjectHashSet", serializer.serialize(stringObjectHashSet)) .spy("hash sets"); Set<String> stringOnlyTreeSet = new TreeSet<>(REVERSE_SORT_COMPARATOR); stringOnlyTreeSet.add("b"); stringOnlyTreeSet.add("a"); stringOnlyTreeSet.add("z"); stringOnlyTreeSet.add("g"); Bond.obs("stringOnlyTreeSet", serializer.serialize(stringOnlyTreeSet)).spy("tree sets"); }
@Test public void testNestedSorting() { Set<String> stringHashSet = Sets.newHashSet("b", "a", "z", "g"); Map<String, String> stringHashMap = new HashMap<>(); stringHashMap.put("b", "bar"); stringHashMap.put("a", "foo"); stringHashMap.put("z", "baz"); stringHashMap.put("g", "test"); NestingObject no = new NestingObject(); no.stringMap = stringHashMap; no.stringSet = stringHashSet; Map<String, Object> objectMap = new HashMap<>(); objectMap.put("nestingObject", no); objectMap.put("hashSet", stringHashSet); objectMap.put("hashMap", stringHashMap); Set<Object> objectSet = Sets.newHashSet(stringHashSet, stringHashMap, no); Bond.obs("objectMap", serializer.serialize(objectMap)) .obs("objectSet", serializer.serialize(objectSet)).spy(); }