Search in sources :

Example 66 with EqualsTester

use of com.google.common.testing.EqualsTester in project guava by hceylan.

the class TypesTest method testNewArrayType.

public void testNewArrayType() {
    Type jvmType1 = new TypeCapture<List<String>[]>() {
    }.capture();
    GenericArrayType ourType1 = (GenericArrayType) Types.newArrayType(Types.newParameterizedType(List.class, String.class));
    Type jvmType2 = new TypeCapture<List[]>() {
    }.capture();
    Type ourType2 = Types.newArrayType(List.class);
    new EqualsTester().addEqualityGroup(jvmType1, ourType1).addEqualityGroup(jvmType2, ourType2).testEquals();
    assertEquals(new TypeCapture<List<String>>() {
    }.capture(), ourType1.getGenericComponentType());
    assertEquals(jvmType1.toString(), ourType1.toString());
    assertEquals(jvmType2.toString(), ourType2.toString());
}
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) GenericArrayType(java.lang.reflect.GenericArrayType)

Example 67 with EqualsTester

use of com.google.common.testing.EqualsTester in project guava by hceylan.

the class TypesTest method testNewParameterizedType.

public void testNewParameterizedType() {
    ParameterizedType jvmType = (ParameterizedType) new TypeCapture<HashMap<String, int[][]>>() {
    }.capture();
    ParameterizedType ourType = Types.newParameterizedType(HashMap.class, String.class, int[][].class);
    new EqualsTester().addEqualityGroup(jvmType, ourType).testEquals();
    assertEquals(jvmType.toString(), ourType.toString());
    assertEquals(jvmType.hashCode(), ourType.hashCode());
    assertEquals(HashMap.class, ourType.getRawType());
    ASSERT.that(ourType.getActualTypeArguments()).hasContentsInOrder(jvmType.getActualTypeArguments());
    assertEquals(Arrays.asList(String.class, Types.newArrayType(Types.newArrayType(int.class))), Arrays.asList(ourType.getActualTypeArguments()));
    assertEquals(null, ourType.getOwnerType());
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) EqualsTester(com.google.common.testing.EqualsTester)

Example 68 with EqualsTester

use of com.google.common.testing.EqualsTester in project guava by hceylan.

the class UnsignedLongTest method testEqualsAndValueOf.

@GwtIncompatible("too slow")
public void testEqualsAndValueOf() {
    EqualsTester equalsTester = new EqualsTester();
    for (long a : TEST_LONGS) {
        BigInteger big = (a >= 0) ? BigInteger.valueOf(a) : BigInteger.valueOf(a).add(BigInteger.ZERO.setBit(64));
        equalsTester.addEqualityGroup(UnsignedLong.asUnsigned(a), UnsignedLong.valueOf(big), UnsignedLong.valueOf(big.toString()), UnsignedLong.valueOf(big.toString(16), 16));
    }
    equalsTester.testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) BigInteger(java.math.BigInteger) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 69 with EqualsTester

use of com.google.common.testing.EqualsTester in project guava by google.

the class ImmutableListMultimapTest method testMultimapEquals.

public void testMultimapEquals() {
    Multimap<String, Integer> multimap = createMultimap();
    Multimap<String, Integer> arrayListMultimap = ArrayListMultimap.create();
    arrayListMultimap.putAll("foo", Arrays.asList(1, 3));
    arrayListMultimap.put("bar", 2);
    new EqualsTester().addEqualityGroup(multimap, createMultimap(), arrayListMultimap, ImmutableListMultimap.<String, Integer>builder().put("bar", 2).put("foo", 1).put("foo", 3).build()).addEqualityGroup(ImmutableListMultimap.<String, Integer>builder().put("bar", 2).put("foo", 3).put("foo", 1).build()).addEqualityGroup(ImmutableListMultimap.<String, Integer>builder().put("foo", 2).put("foo", 3).put("foo", 1).build()).addEqualityGroup(ImmutableListMultimap.<String, Integer>builder().put("bar", 2).put("foo", 3).build()).testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester)

Example 70 with EqualsTester

use of com.google.common.testing.EqualsTester in project guava by google.

the class SetsTest method testPowerSetEqualsAndHashCode_verifyAgainstHashSet.

public void testPowerSetEqualsAndHashCode_verifyAgainstHashSet() {
    ImmutableList<Integer> allElements = ImmutableList.of(4233352, 3284593, 3794208, 3849533, 4013967, 2902658, 1886275, 2131109, 985872, 1843868);
    for (int i = 0; i < allElements.size(); i++) {
        Set<Integer> elements = newHashSet(allElements.subList(0, i));
        Set<Set<Integer>> powerSet1 = powerSet(elements);
        Set<Set<Integer>> powerSet2 = powerSet(elements);
        new EqualsTester().addEqualityGroup(powerSet1, powerSet2, toHashSets(powerSet1)).addEqualityGroup(ImmutableSet.of()).addEqualityGroup(ImmutableSet.of(9999999)).addEqualityGroup("notASet").testEquals();
        assertEquals(toHashSets(powerSet1).hashCode(), powerSet1.hashCode());
    }
}
Also used : SortedSet(java.util.SortedSet) Sets.unmodifiableNavigableSet(com.google.common.collect.Sets.unmodifiableNavigableSet) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) Sets.newEnumSet(com.google.common.collect.Sets.newEnumSet) EnumSet(java.util.EnumSet) Set(java.util.Set) NavigableSet(java.util.NavigableSet) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Sets.powerSet(com.google.common.collect.Sets.powerSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Collections.emptySet(java.util.Collections.emptySet) Sets.newLinkedHashSet(com.google.common.collect.Sets.newLinkedHashSet) SafeTreeSet(com.google.common.collect.testing.SafeTreeSet) 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