@Override protected Map<String, String> makePopulatedMap() { Map<String, Integer> underlying = Maps.newHashMap(); underlying.put("a", 1); underlying.put("b", 2); underlying.put("c", 3); return Maps.transformValues(underlying, Functions.toStringFunction()); }
@Override protected SortedMap<String, String> makePopulatedMap() { SortedMap<String, Integer> underlying = Maps.newTreeMap(); underlying.put("a", 1); underlying.put("b", 2); underlying.put("c", 3); return Maps.transformValues(underlying, Functions.toStringFunction()); } }
public void testSerialization_from() { Converter<String, String> dumb = Converter.from(toStringFunction(), toStringFunction()); SerializableTester.reserializeAndAssert(dumb); } }
public void testTransformEmptyMapEquality() { Map<String, String> map = Maps.transformValues(ImmutableMap.<String, Integer>of(), Functions.toStringFunction()); assertMapsEqual(Maps.newHashMap(), map); }
@Override protected Map<String, String> makeEmptyMap() { Map<String, Integer> underlying = Maps.newHashMap(); return Maps.transformValues( new UnmodifiableIteratorMap<String, Integer>(underlying), Functions.toStringFunction()); }
@Override protected Map<String, String> makePopulatedMap() { Map<String, Integer> underlying = Maps.newHashMap(); underlying.put("a", 1); underlying.put("b", 2); underlying.put("c", 3); return Maps.transformValues( new UnmodifiableIteratorMap<String, Integer>(underlying), Functions.toStringFunction()); }
public void testTransformEmptyMapEquality() { Map<String, String> map = Maps.transformValues(ImmutableMap.<String, Integer>of(), Functions.toStringFunction()); assertMapsEqual(Maps.newHashMap(), map); }
public void testTransformRemoveEntry() { Map<String, Integer> underlying = Maps.newHashMap(); underlying.put("a", 1); Map<String, String> map = Maps.transformValues(underlying, Functions.toStringFunction()); assertEquals("1", map.remove("a")); assertNull(map.remove("b")); }
public void testIndex() { final Multimap<String, Object> stringToObject = new ImmutableMultimap.Builder<String, Object>() .put("1", 1) .put("1", 1L) .put("1", "1") .put("2", 2) .put("2", 2L) .build(); ImmutableMultimap<String, Object> outputMap = Multimaps.index(stringToObject.values(), Functions.toStringFunction()); assertEquals(stringToObject, outputMap); }
public void testIndexIterator() { final Multimap<String, Object> stringToObject = new ImmutableMultimap.Builder<String, Object>() .put("1", 1) .put("1", 1L) .put("1", "1") .put("2", 2) .put("2", 2L) .build(); ImmutableMultimap<String, Object> outputMap = Multimaps.index(stringToObject.values().iterator(), Functions.toStringFunction()); assertEquals(stringToObject, outputMap); }
public void testTransformSingletonMapEquality() { Map<String, String> map = Maps.transformValues(ImmutableMap.of("a", 1), Functions.toStringFunction()); Map<String, String> expected = ImmutableMap.of("a", "1"); assertMapsEqual(expected, map); assertEquals(expected.get("a"), map.get("a")); }
public void testTransformSingletonMapEquality() { Map<String, String> map = Maps.transformValues(ImmutableMap.of("a", 1), Functions.toStringFunction()); Map<String, String> expected = ImmutableMap.of("a", "1"); assertMapsEqual(expected, map); assertEquals(expected.get("a"), map.get("a")); }
public void testTransformRemoveEntry() { Map<String, Integer> underlying = Maps.newHashMap(); underlying.put("a", 1); Map<String, String> map = Maps.transformValues(underlying, Functions.toStringFunction()); assertEquals("1", map.remove("a")); assertNull(map.remove("b")); }
public void testToMap() { assertThat(fluent(1, 2, 3).toMap(Functions.toStringFunction()).entrySet()) .containsExactly( Maps.immutableEntry(1, "1"), Maps.immutableEntry(2, "2"), Maps.immutableEntry(3, "3")) .inOrder(); }
@GwtIncompatible // SerializableTester public void testToStringFunctionSerializable() { checkCanReserializeSingleton(Functions.toStringFunction()); }
@Override protected Set<String> create(String[] elements) { Table<String, Integer, Character> table = HashBasedTable.create(); populateForRowKeySet(table, elements); return Tables.transformValues(table, Functions.toStringFunction()) .column(1) .keySet(); } })
public void testTransform_absent() { assertEquals(Optional.absent(), Optional.absent().transform(Functions.identity())); assertEquals(Optional.absent(), Optional.absent().transform(Functions.toStringFunction())); }
public void testOnResultOf_equals() { new EqualsTester() .addEqualityGroup( Equivalence.identity().onResultOf(Functions.toStringFunction()), Equivalence.identity().onResultOf(Functions.toStringFunction())) .addEqualityGroup(Equivalence.equals().onResultOf(Functions.toStringFunction())) .addEqualityGroup(Equivalence.identity().onResultOf(Functions.identity())) .testEquals(); }
public void testForSupplier() { Supplier<Integer> supplier = new CountingSupplier(); Function<Object, Integer> function = Functions.forSupplier(supplier); assertEquals(1, (int) function.apply(null)); assertEquals(2, (int) function.apply("foo")); new EqualsTester() .addEqualityGroup(function, Functions.forSupplier(supplier)) .addEqualityGroup(Functions.forSupplier(new CountingSupplier())) .addEqualityGroup(Functions.forSupplier(Suppliers.ofInstance(12))) .addEqualityGroup(Functions.toStringFunction()) .testEquals(); }
public void testOnResultOf() { EquivalenceTester.of(Equivalence.equals().onResultOf(Functions.toStringFunction())) .addEquivalenceGroup(new IntValue(1), new IntValue(1)) .addEquivalenceGroup(new IntValue(2)) .test(); }