Search in sources :

Example 51 with EqualsTester

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

the class AutoAnnotationTest method testSimpleVarArgs.

@Test
public void testSimpleVarArgs() {
    StringValues expectedStringValues = AnnotatedClass.class.getAnnotation(StringValues.class);
    StringValues actualStringValues = newStringValuesVarArgs("oops");
    StringValues otherStringValues = newStringValuesVarArgs(new String[] {});
    new EqualsTester().addEqualityGroup(expectedStringValues, actualStringValues).addEqualityGroup(otherStringValues).testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) StringValues(com.google.auto.value.annotations.StringValues) Test(org.junit.Test)

Example 52 with EqualsTester

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

the class AutoValueJava8Test method testPrimitiveArrays.

@Test
public void testPrimitiveArrays() {
    PrimitiveArrays object0 = PrimitiveArrays.create(new boolean[0], new int[0]);
    boolean[] booleans = { false, true, true, false };
    int[] ints = { 6, 28, 496, 8128, 33550336 };
    PrimitiveArrays object1 = PrimitiveArrays.create(booleans.clone(), ints.clone());
    PrimitiveArrays object2 = PrimitiveArrays.create(booleans.clone(), ints.clone());
    new EqualsTester().addEqualityGroup(object1, object2).addEqualityGroup(object0).testEquals();
    // EqualsTester also exercises hashCode(). We clone the arrays above to ensure that using the
    // default Object.hashCode() will fail.
    String expectedString = "PrimitiveArrays{booleans=" + Arrays.toString(booleans) + ", " + "ints=" + Arrays.toString(ints) + "}";
    assertThat(object1.toString()).isEqualTo(expectedString);
    assertThat(object1.ints()).isSameAs(object1.ints());
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Example 53 with EqualsTester

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

the class AutoValueTest method testFloatingEquality.

@Test
public void testFloatingEquality() {
    FloatProperty floatZero = FloatProperty.create(0.0f);
    FloatProperty floatMinusZero = FloatProperty.create(-0.0f);
    FloatProperty floatNaN = FloatProperty.create(Float.NaN);
    DoubleProperty doubleZero = DoubleProperty.create(0.0);
    DoubleProperty doubleMinusZero = DoubleProperty.create(-0.0);
    DoubleProperty doubleNaN = DoubleProperty.create(Double.NaN);
    new EqualsTester().addEqualityGroup(floatZero).addEqualityGroup(floatMinusZero).addEqualityGroup(floatNaN).addEqualityGroup(doubleZero).addEqualityGroup(doubleMinusZero).addEqualityGroup(doubleNaN).testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Example 54 with EqualsTester

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

the class AutoValueTest method testTwoPropertiesWithBuilderClass.

@Test
public void testTwoPropertiesWithBuilderClass() {
    TwoPropertiesWithBuilderClass a1 = TwoPropertiesWithBuilderClass.builder().string("23").integer(17).build();
    TwoPropertiesWithBuilderClass a2 = TwoPropertiesWithBuilderClass.builder("23").integer(17).build();
    TwoPropertiesWithBuilderClass a3 = TwoPropertiesWithBuilderClass.builder().integer(17).string("23").build();
    TwoPropertiesWithBuilderClass b = TwoPropertiesWithBuilderClass.builder().string("17").integer(17).build();
    new EqualsTester().addEqualityGroup(a1, a2, a3).addEqualityGroup(b).testEquals();
    try {
        TwoPropertiesWithBuilderClass.builder().string(null);
        fail("Did not get expected exception");
    } catch (NullPointerException expected) {
    }
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Example 55 with EqualsTester

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

the class AutoValueTest method testPrimitiveArrays.

@Test
public void testPrimitiveArrays() {
    PrimitiveArrays object0 = PrimitiveArrays.create(new boolean[0], new int[0]);
    boolean[] booleans = { false, true, true, false };
    int[] ints = { 6, 28, 496, 8128, 33550336 };
    PrimitiveArrays object1 = PrimitiveArrays.create(booleans.clone(), ints.clone());
    PrimitiveArrays object2 = PrimitiveArrays.create(booleans.clone(), ints.clone());
    new EqualsTester().addEqualityGroup(object1, object2).addEqualityGroup(object0).testEquals();
    // EqualsTester also exercises hashCode(). We clone the arrays above to ensure that using the
    // default Object.hashCode() will fail.
    String expectedString = "PrimitiveArrays{booleans=" + Arrays.toString(booleans) + ", " + "ints=" + Arrays.toString(ints) + "}";
    assertEquals(expectedString, object1.toString());
    assertThat(object1.ints()).isSameAs(object1.ints());
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

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