use of com.google.common.testing.EqualsTester in project guava by hceylan.
the class FunctionsTest method testForMapWithDefault_null_compareWithSerializable.
@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();
}
use of com.google.common.testing.EqualsTester in project guava by hceylan.
the class FunctionsTest method testForSupplier.
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();
}
use of com.google.common.testing.EqualsTester in project guava by hceylan.
the class FunctionsTest method testForMapWithDefault_includeSerializable.
@GwtIncompatible("SerializableTester")
public void testForMapWithDefault_includeSerializable() {
Map<String, Integer> map = Maps.newHashMap();
map.put("One", 1);
map.put("Three", 3);
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());
new EqualsTester().addEqualityGroup(function, Functions.forMap(map, 42), SerializableTester.reserialize(function)).addEqualityGroup(Functions.forMap(map)).addEqualityGroup(Functions.forMap(map, null)).addEqualityGroup(Functions.forMap(map, 43)).testEquals();
}
use of com.google.common.testing.EqualsTester in project guava by hceylan.
the class TypesTest method testNewArrayTypeOfArray.
public void testNewArrayTypeOfArray() {
Type jvmType = new TypeCapture<int[][]>() {
}.capture();
Type ourType = Types.newArrayType(int[].class);
assertEquals(jvmType.toString(), ourType.toString());
new EqualsTester().addEqualityGroup(jvmType, ourType).testEquals();
}
use of com.google.common.testing.EqualsTester in project guava by hceylan.
the class TypesTest method testNewWildcardType.
public void testNewWildcardType() throws Exception {
WildcardType noBoundJvmType = WithWildcardType.getWildcardType("withoutBound");
WildcardType objectBoundJvmType = WithWildcardType.getWildcardType("withObjectBound");
WildcardType upperBoundJvmType = WithWildcardType.getWildcardType("withUpperBound");
WildcardType lowerBoundJvmType = WithWildcardType.getWildcardType("withLowerBound");
WildcardType objectBound = Types.subtypeOf(Object.class);
WildcardType upperBound = Types.subtypeOf(int[][].class);
WildcardType lowerBound = Types.supertypeOf(String[][].class);
assertEqualWildcardType(noBoundJvmType, objectBound);
assertEqualWildcardType(objectBoundJvmType, objectBound);
assertEqualWildcardType(upperBoundJvmType, upperBound);
assertEqualWildcardType(lowerBoundJvmType, lowerBound);
new EqualsTester().addEqualityGroup(noBoundJvmType, objectBoundJvmType, objectBound).addEqualityGroup(upperBoundJvmType, upperBound).addEqualityGroup(lowerBoundJvmType, lowerBound).testEquals();
}
Aggregations