Search in sources :

Example 6 with EqualsTester

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

the class PackageLookupFunctionTest method testPackageLookupValueHashCodeAndEqualsContract.

@Test
public void testPackageLookupValueHashCodeAndEqualsContract() throws Exception {
    Path root1 = rootDirectory.getRelative("root1");
    Path root2 = rootDirectory.getRelative("root2");
    // Our (seeming) duplication of parameters here is intentional. Some of the subclasses of
    // PackageLookupValue are supposed to have reference equality semantics, and some are supposed
    // to have logical equality semantics.
    new EqualsTester().addEqualityGroup(PackageLookupValue.success(root1, BuildFileName.BUILD), PackageLookupValue.success(root1, BuildFileName.BUILD)).addEqualityGroup(PackageLookupValue.success(root2, BuildFileName.BUILD), PackageLookupValue.success(root2, BuildFileName.BUILD)).addEqualityGroup(PackageLookupValue.NO_BUILD_FILE_VALUE, PackageLookupValue.NO_BUILD_FILE_VALUE).addEqualityGroup(PackageLookupValue.DELETED_PACKAGE_VALUE, PackageLookupValue.DELETED_PACKAGE_VALUE).addEqualityGroup(PackageLookupValue.invalidPackageName("nope1"), PackageLookupValue.invalidPackageName("nope1")).addEqualityGroup(PackageLookupValue.invalidPackageName("nope2"), PackageLookupValue.invalidPackageName("nope2")).testEquals();
}
Also used : RootedPath(com.google.devtools.build.lib.vfs.RootedPath) Path(com.google.devtools.build.lib.vfs.Path) EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Example 7 with EqualsTester

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

the class AspectValueTest method keyEquality.

@Test
public void keyEquality() throws Exception {
    update();
    BuildConfiguration c1 = getTargetConfiguration();
    BuildConfiguration c2 = getHostConfiguration();
    Label l1 = Label.parseAbsolute("//a:l1");
    Label l1b = Label.parseAbsolute("//a:l1");
    Label l2 = Label.parseAbsolute("//a:l2");
    AspectParameters i1 = new AspectParameters.Builder().addAttribute("foo", "bar").build();
    AspectParameters i1b = new AspectParameters.Builder().addAttribute("foo", "bar").build();
    AspectParameters i2 = new AspectParameters.Builder().addAttribute("foo", "baz").build();
    AttributeAspect a1 = TestAspects.ATTRIBUTE_ASPECT;
    AttributeAspect a1b = TestAspects.ATTRIBUTE_ASPECT;
    ExtraAttributeAspect a2 = TestAspects.EXTRA_ATTRIBUTE_ASPECT;
    // label: //a:l1 or //a:l2
    // aspectConfiguration: target or host
    // baseConfiguration: target or host
    // aspect: Attribute or ExtraAttribute
    // parameters: bar or baz
    new EqualsTester().addEqualityGroup(createKey(l1, c1, a1, i1, c1), createKey(l1, c1, a1, i1b, c1), createKey(l1, c1, a1b, i1, c1), createKey(l1, c1, a1b, i1b, c1), createKey(l1b, c1, a1, i1, c1), createKey(l1b, c1, a1, i1b, c1), createKey(l1b, c1, a1b, i1, c1), createKey(l1b, c1, a1b, i1b, c1)).addEqualityGroup(createKey(l1, c1, a1, i2, c1), createKey(l1, c1, a1b, i2, c1), createKey(l1b, c1, a1, i2, c1), createKey(l1b, c1, a1b, i2, c1)).addEqualityGroup(createKey(l1, c1, a2, i1, c1), createKey(l1, c1, a2, i1b, c1), createKey(l1b, c1, a2, i1, c1), createKey(l1b, c1, a2, i1b, c1)).addEqualityGroup(createKey(l1, c1, a2, i2, c1), createKey(l1b, c1, a2, i2, c1)).addEqualityGroup(createKey(l1, c2, a1, i1, c1), createKey(l1, c2, a1, i1b, c1), createKey(l1, c2, a1b, i1, c1), createKey(l1, c2, a1b, i1b, c1), createKey(l1b, c2, a1, i1, c1), createKey(l1b, c2, a1, i1b, c1), createKey(l1b, c2, a1b, i1, c1), createKey(l1b, c2, a1b, i1b, c1)).addEqualityGroup(createKey(l1, c2, a1, i2, c1), createKey(l1, c2, a1b, i2, c1), createKey(l1b, c2, a1, i2, c1), createKey(l1b, c2, a1b, i2, c1)).addEqualityGroup(createKey(l1, c2, a2, i1, c1), createKey(l1, c2, a2, i1b, c1), createKey(l1b, c2, a2, i1, c1), createKey(l1b, c2, a2, i1b, c1)).addEqualityGroup(createKey(l1, c2, a2, i2, c1), createKey(l1b, c2, a2, i2, c1)).addEqualityGroup(createKey(l1, c1, a1, i1, c2), createKey(l1, c1, a1, i1b, c2), createKey(l1, c1, a1b, i1, c2), createKey(l1, c1, a1b, i1b, c2), createKey(l1b, c1, a1, i1, c2), createKey(l1b, c1, a1, i1b, c2), createKey(l1b, c1, a1b, i1, c2), createKey(l1b, c1, a1b, i1b, c2)).addEqualityGroup(createKey(l1, c1, a1, i2, c2), createKey(l1, c1, a1b, i2, c2), createKey(l1b, c1, a1, i2, c2), createKey(l1b, c1, a1b, i2, c2)).addEqualityGroup(createKey(l1, c1, a2, i1, c2), createKey(l1, c1, a2, i1b, c2), createKey(l1b, c1, a2, i1, c2), createKey(l1b, c1, a2, i1b, c2)).addEqualityGroup(createKey(l1, c1, a2, i2, c2), createKey(l1b, c1, a2, i2, c2)).addEqualityGroup(createKey(l1, c2, a1, i1, c2), createKey(l1, c2, a1, i1b, c2), createKey(l1, c2, a1b, i1, c2), createKey(l1, c2, a1b, i1b, c2), createKey(l1b, c2, a1, i1, c2), createKey(l1b, c2, a1, i1b, c2), createKey(l1b, c2, a1b, i1, c2), createKey(l1b, c2, a1b, i1b, c2)).addEqualityGroup(createKey(l1, c2, a1, i2, c2), createKey(l1, c2, a1b, i2, c2), createKey(l1b, c2, a1, i2, c2), createKey(l1b, c2, a1b, i2, c2)).addEqualityGroup(createKey(l1, c2, a2, i1, c2), createKey(l1, c2, a2, i1b, c2), createKey(l1b, c2, a2, i1, c2), createKey(l1b, c2, a2, i1b, c2)).addEqualityGroup(createKey(l1, c2, a2, i2, c2), createKey(l1b, c2, a2, i2, c2)).addEqualityGroup(createKey(l2, c1, a1, i1, c1), createKey(l2, c1, a1, i1b, c1), createKey(l2, c1, a1b, i1, c1), createKey(l2, c1, a1b, i1b, c1)).addEqualityGroup(createKey(l2, c1, a1, i2, c1), createKey(l2, c1, a1b, i2, c1)).addEqualityGroup(createKey(l2, c1, a2, i1, c1), createKey(l2, c1, a2, i1b, c1)).addEqualityGroup(createKey(l2, c1, a2, i2, c1)).addEqualityGroup(createKey(l2, c2, a1, i1, c1), createKey(l2, c2, a1, i1b, c1), createKey(l2, c2, a1b, i1, c1), createKey(l2, c2, a1b, i1b, c1)).addEqualityGroup(createKey(l2, c2, a1, i2, c1), createKey(l2, c2, a1b, i2, c1)).addEqualityGroup(createKey(l2, c2, a2, i1, c1), createKey(l2, c2, a2, i1b, c1)).addEqualityGroup(createKey(l2, c2, a2, i2, c1)).addEqualityGroup(createKey(l2, c1, a1, i1, c2), createKey(l2, c1, a1, i1b, c2), createKey(l2, c1, a1b, i1, c2), createKey(l2, c1, a1b, i1b, c2)).addEqualityGroup(createKey(l2, c1, a1, i2, c2), createKey(l2, c1, a1b, i2, c2)).addEqualityGroup(createKey(l2, c1, a2, i1, c2), createKey(l2, c1, a2, i1b, c2)).addEqualityGroup(createKey(l2, c1, a2, i2, c2)).addEqualityGroup(createKey(l2, c2, a1, i1, c2), createKey(l2, c2, a1, i1b, c2), createKey(l2, c2, a1b, i1, c2), createKey(l2, c2, a1b, i1b, c2)).addEqualityGroup(createKey(l2, c2, a1, i2, c2), createKey(l2, c2, a1b, i2, c2)).addEqualityGroup(createKey(l2, c2, a2, i1, c2), createKey(l2, c2, a2, i1b, c2)).addEqualityGroup(createKey(l2, c2, a2, i2, c2)).addEqualityGroup(createDerivedKey(l1, c1, a1, i1, c1, a2, i2, c2), createDerivedKey(l1, c1, a1, i1b, c1, a2, i2, c2)).addEqualityGroup(createDerivedKey(l1, c1, a2, i1, c1, a1, i2, c2), createDerivedKey(l1, c1, a2, i1b, c1, a1, i2, c2)).testEquals();
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) AspectParameters(com.google.devtools.build.lib.packages.AspectParameters) EqualsTester(com.google.common.testing.EqualsTester) ExtraAttributeAspect(com.google.devtools.build.lib.analysis.util.TestAspects.ExtraAttributeAspect) AttributeAspect(com.google.devtools.build.lib.analysis.util.TestAspects.AttributeAspect) ExtraAttributeAspect(com.google.devtools.build.lib.analysis.util.TestAspects.ExtraAttributeAspect) Label(com.google.devtools.build.lib.cmdline.Label) Test(org.junit.Test)

Example 8 with EqualsTester

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

the class LicensingTests method testTargetLicenseEquality.

@Test
public void testTargetLicenseEquality() throws Exception {
    Label label1 = Label.parseAbsolute("//foo");
    Label label2 = Label.parseAbsolute("//bar");
    License restricted = License.parseLicense(ImmutableList.of("restricted"));
    License unencumbered = License.parseLicense(ImmutableList.of("unencumbered"));
    new EqualsTester().addEqualityGroup(new TargetLicense(label1, restricted), new TargetLicense(label1, restricted)).addEqualityGroup(new TargetLicense(label2, restricted), new TargetLicense(label2, restricted)).addEqualityGroup(new TargetLicense(label2, unencumbered), new TargetLicense(label2, unencumbered)).testEquals();
}
Also used : TargetLicense(com.google.devtools.build.lib.analysis.LicensesProvider.TargetLicense) EqualsTester(com.google.common.testing.EqualsTester) Label(com.google.devtools.build.lib.cmdline.Label) License(com.google.devtools.build.lib.packages.License) TargetLicense(com.google.devtools.build.lib.analysis.LicensesProvider.TargetLicense) Test(org.junit.Test)

Example 9 with EqualsTester

use of com.google.common.testing.EqualsTester in project caffeine by ben-manes.

the class CacheTesting method checkEmpty.

static void checkEmpty(Collection<?> collection) {
    assertTrue(collection.isEmpty());
    assertEquals(0, collection.size());
    assertFalse(collection.iterator().hasNext());
    assertEquals(0, collection.toArray().length);
    assertEquals(0, collection.toArray(new Object[0]).length);
    if (collection instanceof Set) {
        new EqualsTester().addEqualityGroup(ImmutableSet.of(), collection).addEqualityGroup(ImmutableSet.of("")).testEquals();
    } else if (collection instanceof List) {
        new EqualsTester().addEqualityGroup(ImmutableList.of(), collection).addEqualityGroup(ImmutableList.of("")).testEquals();
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) EqualsTester(com.google.common.testing.EqualsTester) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Example 10 with EqualsTester

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

the class UUnaryTest method equality.

@Test
public void equality() {
    ULiteral sevenLit = ULiteral.intLit(7);
    ULiteral threeLit = ULiteral.intLit(3);
    ULiteral falseLit = ULiteral.booleanLit(false);
    new EqualsTester().addEqualityGroup(UUnary.create(Kind.UNARY_MINUS, sevenLit)).addEqualityGroup(UUnary.create(Kind.UNARY_MINUS, threeLit)).addEqualityGroup(UUnary.create(Kind.BITWISE_COMPLEMENT, sevenLit)).addEqualityGroup(UUnary.create(Kind.LOGICAL_COMPLEMENT, falseLit)).testEquals();
}
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