Search in sources :

Example 31 with EqualsTester

use of com.google.common.testing.EqualsTester in project google-cloud-java by GoogleCloudPlatform.

the class MutationTest method equalsAndHashCode.

@Test
public void equalsAndHashCode() {
    EqualsTester tester = new EqualsTester();
    // Equality, not identity.
    tester.addEqualityGroup(Mutation.newInsertBuilder("T1").build(), Mutation.newInsertBuilder("T1").build());
    // Operation types are distinguished.
    tester.addEqualityGroup(Mutation.newInsertOrUpdateBuilder("T1").build());
    tester.addEqualityGroup(Mutation.newUpdateBuilder("T1").build());
    tester.addEqualityGroup(Mutation.newReplaceBuilder("T1").build());
    // Table is distinguished.
    tester.addEqualityGroup(Mutation.newInsertBuilder("T2").build());
    // Columns/values are distinguished (but by equality, not identity).
    tester.addEqualityGroup(Mutation.newInsertBuilder("T1").set("C").to("V").build(), Mutation.newInsertBuilder("T1").set("C").to("V").build());
    // Deletes consider the key set.
    tester.addEqualityGroup(Mutation.delete("T1", KeySet.all()));
    tester.addEqualityGroup(Mutation.delete("T1", KeySet.singleKey(Key.of("k"))), Mutation.delete("T1", Key.of("k")));
    tester.testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Example 32 with EqualsTester

use of com.google.common.testing.EqualsTester in project google-cloud-java by GoogleCloudPlatform.

the class InstanceTest method equality.

@Test
public void equality() {
    InstanceId id = new InstanceId("test-project", "test-instance");
    InstanceConfigId configId = new InstanceConfigId("test-project", "test-instance-config");
    Instance instance = new Instance.Builder(instanceClient, dbClient, id).setInstanceConfigId(configId).setDisplayName("test instance").setNodeCount(1).setState(InstanceInfo.State.READY).addLabel("env", "prod").addLabel("region", "us").build();
    Instance instance2 = new Instance.Builder(instanceClient, dbClient, id).setInstanceConfigId(configId).setDisplayName("test instance").setNodeCount(1).setState(InstanceInfo.State.READY).addLabel("region", "us").addLabel("env", "prod").build();
    Instance instance3 = new Instance.Builder(instanceClient, dbClient, id).setInstanceConfigId(configId).setDisplayName("test instance").setNodeCount(1).setState(InstanceInfo.State.READY).addLabel("env", "prod").build();
    EqualsTester tester = new EqualsTester();
    tester.addEqualityGroup(instance, instance2);
    tester.addEqualityGroup(instance3);
    tester.testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Example 33 with EqualsTester

use of com.google.common.testing.EqualsTester in project google-cloud-java by GoogleCloudPlatform.

the class KeyRangeTest method equalsAndHashCode.

@Test
public void equalsAndHashCode() {
    EqualsTester tester = new EqualsTester();
    // Test factory method vs builder with defaults vs builder with all parts explicit.
    tester.addEqualityGroup(KeyRange.closedOpen(Key.of(1), Key.of(2)), KeyRange.newBuilder().setStart(Key.of(1)).setEnd(Key.of(2)).build(), KeyRange.newBuilder().setStart(Key.of(1)).setStartType(CLOSED).setEnd(Key.of(2)).setEndType(OPEN).build());
    // Differing endpoint types.
    tester.addEqualityGroup(KeyRange.closedClosed(Key.of(1), Key.of(2)));
    tester.addEqualityGroup(KeyRange.openOpen(Key.of(1), Key.of(2)));
    tester.addEqualityGroup(KeyRange.openClosed(Key.of(1), Key.of(2)));
    // Differing start/end keys.
    tester.addEqualityGroup(KeyRange.closedOpen(Key.of(2), Key.of(1)));
    tester.addEqualityGroup(KeyRange.closedClosed(Key.of(), Key.of()));
    // Prefix range.
    tester.addEqualityGroup(KeyRange.prefix(Key.of(1, 2)), KeyRange.closedClosed(Key.of(1, 2), Key.of(1, 2)));
    tester.testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Example 34 with EqualsTester

use of com.google.common.testing.EqualsTester in project google-cloud-java by GoogleCloudPlatform.

the class TimestampTest method equalsAndHashCode.

@Test
public void equalsAndHashCode() {
    EqualsTester tester = new EqualsTester();
    tester.addEqualityGroup(Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 0), Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 0), Timestamp.of(new java.sql.Timestamp(TEST_TIME_SECONDS * 1000)));
    tester.addEqualityGroup(Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS + 1, 0));
    tester.addEqualityGroup(Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 1));
    tester.testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Example 35 with EqualsTester

use of com.google.common.testing.EqualsTester in project core-java by SpineEventEngine.

the class MessageEnvelopeShould method support_equality.

@Test
public void support_equality() {
    final O oneMessage = outerObject();
    final O anotherMessage = outerObject();
    final E oneEnvelope = toEnvelope(oneMessage);
    final E anotherEnvelope = toEnvelope(anotherMessage);
    new EqualsTester().addEqualityGroup(oneEnvelope).addEqualityGroup(anotherEnvelope).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