Search in sources :

Example 61 with EqualsTester

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();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 62 with EqualsTester

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();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester)

Example 63 with EqualsTester

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();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 64 with EqualsTester

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();
}
Also used : GenericArrayType(java.lang.reflect.GenericArrayType) WildcardType(java.lang.reflect.WildcardType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) EqualsTester(com.google.common.testing.EqualsTester)

Example 65 with EqualsTester

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();
}
Also used : WildcardType(java.lang.reflect.WildcardType) EqualsTester(com.google.common.testing.EqualsTester)

Aggregations

EqualsTester (com.google.common.testing.EqualsTester)177 Test (org.junit.Test)83 GwtIncompatible (com.google.common.annotations.GwtIncompatible)10 ParameterizedType (java.lang.reflect.ParameterizedType)10 WildcardType (java.lang.reflect.WildcardType)8 Method (java.lang.reflect.Method)7 Entry (java.util.Map.Entry)7 GenericArrayType (java.lang.reflect.GenericArrayType)6 Type (java.lang.reflect.Type)6 ImmutableList (com.google.common.collect.ImmutableList)5 Path (com.google.devtools.build.lib.vfs.Path)5 List (java.util.List)5 Set (java.util.Set)5 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)4 HashMap (java.util.HashMap)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 Label (com.google.devtools.build.lib.cmdline.Label)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3