Search in sources :

Example 81 with EqualsTester

use of com.google.common.testing.EqualsTester in project instrumentation-java by census-instrumentation.

the class TraceOptionsTest method traceOptions_EqualsAndHashCode.

@Test
public void traceOptions_EqualsAndHashCode() {
    EqualsTester tester = new EqualsTester();
    tester.addEqualityGroup(TraceOptions.DEFAULT);
    tester.addEqualityGroup(TraceOptions.fromBytes(secondBytes), TraceOptions.builder().setIsSampled().build());
    tester.addEqualityGroup(TraceOptions.fromBytes(firstBytes));
    tester.testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) Test(org.junit.Test)

Example 82 with EqualsTester

use of com.google.common.testing.EqualsTester in project instrumentation-java by census-instrumentation.

the class SpanDataTest method spanDataEquals.

@Test
public void spanDataEquals() {
    SpanData allSpanData1 = SpanData.create(spanContext, parentSpanId, false, DISPLAY_NAME, startTimestamp, attributes, annotations, networkEvents, links, status, endTimestamp);
    SpanData allSpanData2 = SpanData.create(spanContext, parentSpanId, false, DISPLAY_NAME, startTimestamp, attributes, annotations, networkEvents, links, status, endTimestamp);
    SpanData emptySpanData = SpanData.create(spanContext, parentSpanId, false, DISPLAY_NAME, startTimestamp, Attributes.create(Collections.<String, AttributeValue>emptyMap(), 0), TimedEvents.create(Collections.<SpanData.TimedEvent<Annotation>>emptyList(), 0), TimedEvents.create(Collections.<SpanData.TimedEvent<NetworkEvent>>emptyList(), 0), Links.create(Collections.<Link>emptyList(), 0), status, endTimestamp);
    new EqualsTester().addEqualityGroup(allSpanData1, allSpanData2).addEqualityGroup(emptySpanData).testEquals();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) TimedEvent(com.google.instrumentation.trace.SpanData.TimedEvent) Test(org.junit.Test)

Example 83 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 84 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 85 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)

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