Search in sources :

Example 11 with EqualsTester

use of com.google.common.testing.EqualsTester in project error-prone by google.

the class UWildcardTypeTest method equality.

@Test
public void equality() {
    UType objectType = UClassType.create("java.lang.Object", ImmutableList.<UType>of());
    UType setType = UClassType.create("java.util.Set", ImmutableList.<UType>of(objectType));
    new EqualsTester().addEqualityGroup(// ?
    UWildcardType.create(BoundKind.UNBOUND, objectType)).addEqualityGroup(// ? extends Object
    UWildcardType.create(BoundKind.EXTENDS, objectType)).addEqualityGroup(// ? extends Set<Object>
    UWildcardType.create(BoundKind.EXTENDS, setType)).addEqualityGroup(// ? super Set<Object>
    UWildcardType.create(BoundKind.SUPER, setType)).testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Example 12 with EqualsTester

use of com.google.common.testing.EqualsTester in project bazel by bazelbuild.

the class PathTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    FileSystem oldFileSystem = Path.getFileSystemForSerialization();
    try {
        Path.setFileSystemForSerialization(filesystem);
        Path root = filesystem.getPath("/");
        Path p1 = filesystem.getPath("/foo");
        Path p2 = filesystem.getPath("/foo/bar");
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(root);
        oos.writeObject(p1);
        oos.writeObject(p2);
        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bis);
        Path dsRoot = (Path) ois.readObject();
        Path dsP1 = (Path) ois.readObject();
        Path dsP2 = (Path) ois.readObject();
        new EqualsTester().addEqualityGroup(root, dsRoot).addEqualityGroup(p1, dsP1).addEqualityGroup(p2, dsP2).testEquals();
        assertTrue(p2.startsWith(p1));
        assertTrue(p2.startsWith(dsP1));
        assertTrue(dsP2.startsWith(p1));
        assertTrue(dsP2.startsWith(dsP1));
        // Regression test for a very specific bug in compareTo involving our incorrect usage of
        // reference equality rather than logical equality.
        String relativePathStringA = "child/grandchildA";
        String relativePathStringB = "child/grandchildB";
        assertEquals(p1.getRelative(relativePathStringA).compareTo(p1.getRelative(relativePathStringB)), p1.getRelative(relativePathStringA).compareTo(dsP1.getRelative(relativePathStringB)));
    } finally {
        Path.setFileSystemForSerialization(oldFileSystem);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) EqualsTester(com.google.common.testing.EqualsTester) InMemoryFileSystem(com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 13 with EqualsTester

use of com.google.common.testing.EqualsTester in project bazel by bazelbuild.

the class RootedPathTest method testEqualsAndHashCodeContract.

@Test
public void testEqualsAndHashCodeContract() throws Exception {
    Path pkgRoot1 = root.getRelative("pkgroot1");
    Path pkgRoot2 = root.getRelative("pkgroot2");
    RootedPath rootedPathA1 = RootedPath.toRootedPath(pkgRoot1, new PathFragment("foo/bar"));
    RootedPath rootedPathA2 = RootedPath.toRootedPath(pkgRoot1, new PathFragment("foo/bar"));
    RootedPath absolutePath1 = RootedPath.toRootedPath(root, new PathFragment("pkgroot1/foo/bar"));
    RootedPath rootedPathB1 = RootedPath.toRootedPath(pkgRoot2, new PathFragment("foo/bar"));
    RootedPath rootedPathB2 = RootedPath.toRootedPath(pkgRoot2, new PathFragment("foo/bar"));
    RootedPath absolutePath2 = RootedPath.toRootedPath(root, new PathFragment("pkgroot2/foo/bar"));
    new EqualsTester().addEqualityGroup(rootedPathA1, rootedPathA2).addEqualityGroup(rootedPathB1, rootedPathB2).addEqualityGroup(absolutePath1).addEqualityGroup(absolutePath2).testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Example 14 with EqualsTester

use of com.google.common.testing.EqualsTester in project bazel by bazelbuild.

the class ImmutableSortedKeyListMultimapTest method multimapEquals.

@Test
public void multimapEquals() {
    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, ImmutableSortedKeyListMultimap.<String, Integer>builder().put("bar", 2).put("foo", 1).put("foo", 3).build()).addEqualityGroup(ImmutableSortedKeyListMultimap.<String, Integer>builder().put("bar", 2).put("foo", 3).put("foo", 1).build()).addEqualityGroup(ImmutableSortedKeyListMultimap.<String, Integer>builder().put("foo", 2).put("foo", 3).put("foo", 1).build()).addEqualityGroup(ImmutableSortedKeyListMultimap.<String, Integer>builder().put("bar", 2).put("foo", 3).build()).testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Example 15 with EqualsTester

use of com.google.common.testing.EqualsTester in project bazel by bazelbuild.

the class NestedSetImplTest method shallowEquality.

@Test
public void shallowEquality() {
    // Used below to check that inner nested sets can be compared by reference equality.
    SetWrapper<Integer> myRef = nest(nest(flat(7, 8)), flat(9));
    // Each "equality group" contains elements that are equal to one another
    // (according to equals() and hashCode()), yet distinct from all elements
    // of all other equality groups.
    new EqualsTester().addEqualityGroup(flat(), flat(), // Empty set elision.
    nest(flat())).addEqualityGroup(NestedSetBuilder.<Integer>linkOrder().build()).addEqualityGroup(flat(3), flat(3), // Element de-duplication.
    flat(3, 3)).addEqualityGroup(flat(4), // Automatic elision of one-element nested sets.
    nest(flat(4))).addEqualityGroup(NestedSetBuilder.<Integer>linkOrder().add(4).build()).addEqualityGroup(// Like flat("4").
    nestedSetBuilder("4").build()).addEqualityGroup(flat(3, 4), flat(3, 4)).addEqualityGroup(nest(nest(flat(3, 4), flat(5)), nest(flat(6, 7), flat(8)))).addEqualityGroup(nest(nest(flat(3, 4), flat(5)), nest(flat(6, 7), flat(8)))).addEqualityGroup(nest(myRef), nest(myRef), // Set de-duplication.
    nest(myRef, myRef)).addEqualityGroup(nest(3, myRef)).addEqualityGroup(nest(4, myRef)).testEquals();
// Some things that are not tested by the above:
//  - ordering among direct members
//  - ordering among transitive sets
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Aggregations

EqualsTester (com.google.common.testing.EqualsTester)225 Test (org.junit.Test)118 GwtIncompatible (com.google.common.annotations.GwtIncompatible)10 ParameterizedType (java.lang.reflect.ParameterizedType)10 Test (org.junit.jupiter.api.Test)9 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 HashMap (java.util.HashMap)6 ImmutableList (com.google.common.collect.ImmutableList)5 Path (com.google.devtools.build.lib.vfs.Path)5 List (java.util.List)5 DisplayName (org.junit.jupiter.api.DisplayName)5 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 Label (com.google.devtools.build.lib.cmdline.Label)3