public void testIdentity_same() { Function<String, String> identity = Functions.identity(); assertNull(identity.apply(null)); assertSame("foo", identity.apply("foo")); }
public void testForMapWithoutDefault() { Map<String, Integer> map = Maps.newHashMap(); map.put("One", 1); map.put("Three", 3); map.put("Null", null); Function<String, Integer> function = Functions.forMap(map); assertEquals(1, function.apply("One").intValue()); assertEquals(3, function.apply("Three").intValue()); assertNull(function.apply("Null")); try { function.apply("Two"); fail(); } catch (IllegalArgumentException expected) { } new EqualsTester() .addEqualityGroup(function, Functions.forMap(map)) .addEqualityGroup(Functions.forMap(map, 42)) .testEquals(); }
public void testForMapWithDefault_null() { ImmutableMap<String, Integer> map = ImmutableMap.of("One", 1); Function<String, Integer> function = Functions.forMap(map, null); assertEquals((Integer) 1, function.apply("One")); assertNull(function.apply("Two")); // check basic sanity of equals and hashCode new EqualsTester() .addEqualityGroup(function) .addEqualityGroup(Functions.forMap(map, 1)) .testEquals(); }
public void testForMapWithDefault() { Map<String, Integer> map = Maps.newHashMap(); map.put("One", 1); map.put("Three", 3); map.put("Null", null); Function<String, Integer> function = Functions.forMap(map, 42); assertEquals(1, function.apply("One").intValue()); assertEquals(42, function.apply("Two").intValue()); assertEquals(3, function.apply("Three").intValue()); assertNull(function.apply("Null")); new EqualsTester() .addEqualityGroup(function, Functions.forMap(map, 42)) .addEqualityGroup(Functions.forMap(map)) .addEqualityGroup(Functions.forMap(map, null)) .addEqualityGroup(Functions.forMap(map, 43)) .testEquals(); }
@GwtIncompatible // SerializableTester public void testForMapWithDefault_null_compareWithSerializable() { ImmutableMap<String, Integer> map = ImmutableMap.of("One", 1); Function<String, Integer> function = Functions.forMap(map, null); assertEquals((Integer) 1, function.apply("One")); assertNull(function.apply("Two")); // check basic sanity of equals and hashCode new EqualsTester() .addEqualityGroup(function, SerializableTester.reserialize(function)) .addEqualityGroup(Functions.forMap(map, 1)) .testEquals(); }
public void testIdentity_same() { Function<String, String> identity = Functions.identity(); assertNull(identity.apply(null)); assertSame("foo", identity.apply("foo")); }
public void testForMapWithoutDefault() { Map<String, Integer> map = Maps.newHashMap(); map.put("One", 1); map.put("Three", 3); map.put("Null", null); Function<String, Integer> function = Functions.forMap(map); assertEquals(1, function.apply("One").intValue()); assertEquals(3, function.apply("Three").intValue()); assertNull(function.apply("Null")); try { function.apply("Two"); fail(); } catch (IllegalArgumentException expected) { } new EqualsTester() .addEqualityGroup(function, Functions.forMap(map)) .addEqualityGroup(Functions.forMap(map, 42)) .testEquals(); }
public void testForMapWithDefault_null() { ImmutableMap<String, Integer> map = ImmutableMap.of("One", 1); Function<String, Integer> function = Functions.forMap(map, null); assertEquals((Integer) 1, function.apply("One")); assertNull(function.apply("Two")); // check basic sanity of equals and hashCode new EqualsTester() .addEqualityGroup(function) .addEqualityGroup(Functions.forMap(map, 1)) .testEquals(); }
public void testForMapWithDefault() { Map<String, Integer> map = Maps.newHashMap(); map.put("One", 1); map.put("Three", 3); map.put("Null", null); Function<String, Integer> function = Functions.forMap(map, 42); assertEquals(1, function.apply("One").intValue()); assertEquals(42, function.apply("Two").intValue()); assertEquals(3, function.apply("Three").intValue()); assertNull(function.apply("Null")); new EqualsTester() .addEqualityGroup(function, Functions.forMap(map, 42)) .addEqualityGroup(Functions.forMap(map)) .addEqualityGroup(Functions.forMap(map, null)) .addEqualityGroup(Functions.forMap(map, 43)) .testEquals(); }
@GwtIncompatible // SerializableTester public void testForMapWithDefault_null_compareWithSerializable() { ImmutableMap<String, Integer> map = ImmutableMap.of("One", 1); Function<String, Integer> function = Functions.forMap(map, null); assertEquals((Integer) 1, function.apply("One")); assertNull(function.apply("Two")); // check basic sanity of equals and hashCode new EqualsTester() .addEqualityGroup(function, SerializableTester.reserialize(function)) .addEqualityGroup(Functions.forMap(map, 1)) .testEquals(); }