Java Code Examples for com.google.common.testing.EqualsTester#testEquals()

The following examples show how to use com.google.common.testing.EqualsTester#testEquals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InstanceDataTest.java    From batfish with Apache License 2.0 6 votes vote down vote up
@Test
public void testEquals() {
  InstanceData instanceData = new InstanceData();
  InstanceData initialInstance = clone(instanceData);
  EqualsTester equalsTester = new EqualsTester();
  equalsTester.addEqualityGroup(initialInstance, initialInstance).addEqualityGroup(new Object());
  instanceData.setInstanceName("instanceName");
  equalsTester.addEqualityGroup(clone(instanceData));
  instanceData.setDescription("The description");
  equalsTester.addEqualityGroup(clone(instanceData));
  instanceData.setLongDescription("The long description");
  equalsTester.addEqualityGroup(clone(instanceData));
  instanceData.setOrderedVariableNames(ImmutableList.of("b", "a"));
  equalsTester.addEqualityGroup(clone(instanceData));
  instanceData.setTags(new TreeSet<>(Arrays.asList("tag1", "tag2")));
  equalsTester.addEqualityGroup(clone(instanceData));
  Variable variable = new Variable();
  variable.setType(Type.INTEGER);
  instanceData.setVariables(ImmutableSortedMap.of("v", variable));
  equalsTester.addEqualityGroup(clone(instanceData));
  equalsTester.testEquals();
}
 
Example 2
Source File: PCollectionTupleTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void testEquals() {
  TestPipeline p = TestPipeline.create();
  TupleTag<Long> longTag = new TupleTag<>();
  PCollection<Long> longs = p.apply(GenerateSequence.from(0));
  TupleTag<String> strTag = new TupleTag<>();
  PCollection<String> strs = p.apply(Create.of("foo", "bar"));

  EqualsTester tester = new EqualsTester();
  // Empty tuples in the same pipeline are equal
  tester.addEqualityGroup(PCollectionTuple.empty(p), PCollectionTuple.empty(p));

  tester.addEqualityGroup(
      PCollectionTuple.of(longTag, longs).and(strTag, strs),
      PCollectionTuple.of(longTag, longs).and(strTag, strs));

  tester.addEqualityGroup(PCollectionTuple.of(longTag, longs));
  tester.addEqualityGroup(PCollectionTuple.of(strTag, strs));

  TestPipeline otherPipeline = TestPipeline.create();
  // Empty tuples in different pipelines are not equal
  tester.addEqualityGroup(PCollectionTuple.empty(otherPipeline));
  tester.testEquals();
}
 
Example 3
Source File: PCollectionListTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void testEquals() {
  Pipeline p = TestPipeline.create();
  PCollection<String> first = p.apply("Meta", Create.of("foo", "bar"));
  PCollection<String> second = p.apply("Pythonic", Create.of("spam, ham"));
  PCollection<String> third = p.apply("Syntactic", Create.of("eggs", "baz"));

  EqualsTester tester = new EqualsTester();
  //    tester.addEqualityGroup(PCollectionList.empty(p), PCollectionList.empty(p));
  //    tester.addEqualityGroup(PCollectionList.of(first).and(second));
  // Constructors should all produce equivalent
  tester.addEqualityGroup(
      PCollectionList.of(first).and(second).and(third),
      PCollectionList.of(first).and(second).and(third),
      //        PCollectionList.<String>empty(p).and(first).and(second).and(third),
      //        PCollectionList.of(ImmutableList.of(first, second, third)),
      //        PCollectionList.of(first).and(ImmutableList.of(second, third)),
      PCollectionList.of(ImmutableList.of(first, second)).and(third));
  // Order is considered
  tester.addEqualityGroup(PCollectionList.of(first).and(third).and(second));
  tester.addEqualityGroup(PCollectionList.empty(TestPipeline.create()));

  tester.testEquals();
}
 
Example 4
Source File: CiscoIosDynamicNatTest.java    From batfish with Apache License 2.0 6 votes vote down vote up
@Test
public void testEquals() {
  EqualsTester et =
      new EqualsTester().addEqualityGroup(Boolean.FALSE).addEqualityGroup(baseNat(), baseNat());
  {
    CiscoIosDynamicNat diffAction = baseNat();
    diffAction.setAction(RuleAction.DESTINATION_INSIDE);
    et.addEqualityGroup(diffAction);
  }
  {
    CiscoIosDynamicNat diffName = baseNat();
    diffName.setAclName("diffacl");
    et.addEqualityGroup(diffName);
  }
  {
    CiscoIosDynamicNat diffPool = baseNat();
    diffPool.setNatPool("diffpool");
    et.addEqualityGroup(diffPool);
  }
  et.testEquals();
}
 
Example 5
Source File: AnnotationTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void annotation_EqualsAndHashCode() {
  EqualsTester tester = new EqualsTester();
  Map<String, AttributeValue> attributes = new HashMap<String, AttributeValue>();
  attributes.put(
      "MyStringAttributeKey", AttributeValue.stringAttributeValue("MyStringAttributeValue"));
  tester
      .addEqualityGroup(
          Annotation.fromDescription("MyAnnotationText"),
          Annotation.fromDescriptionAndAttributes(
              "MyAnnotationText", Collections.<String, AttributeValue>emptyMap()))
      .addEqualityGroup(
          Annotation.fromDescriptionAndAttributes("MyAnnotationText", attributes),
          Annotation.fromDescriptionAndAttributes("MyAnnotationText", attributes))
      .addEqualityGroup(Annotation.fromDescription("MyAnnotationText2"));
  tester.testEquals();
}
 
Example 6
Source File: SpanContextTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void spanContext_EqualsAndHashCode() {
  EqualsTester tester = new EqualsTester();
  tester.addEqualityGroup(
      first,
      SpanContext.create(
          TraceId.fromBytes(firstTraceIdBytes),
          SpanId.fromBytes(firstSpanIdBytes),
          TraceOptions.DEFAULT),
      SpanContext.create(
          TraceId.fromBytes(firstTraceIdBytes),
          SpanId.fromBytes(firstSpanIdBytes),
          TraceOptions.builder().setIsSampled(false).build(),
          firstTracestate));
  tester.addEqualityGroup(
      second,
      SpanContext.create(
          TraceId.fromBytes(secondTraceIdBytes),
          SpanId.fromBytes(secondSpanIdBytes),
          TraceOptions.builder().setIsSampled(true).build(),
          secondTracestate));
  tester.testEquals();
}
 
Example 7
Source File: LinkTest.java    From opencensus-java with Apache License 2.0 6 votes vote down vote up
@Test
public void link_EqualsAndHashCode() {
  EqualsTester tester = new EqualsTester();
  tester
      .addEqualityGroup(
          Link.fromSpanContext(spanContext, Type.PARENT_LINKED_SPAN),
          Link.fromSpanContext(spanContext, Type.PARENT_LINKED_SPAN))
      .addEqualityGroup(
          Link.fromSpanContext(spanContext, Type.CHILD_LINKED_SPAN),
          Link.fromSpanContext(spanContext, Type.CHILD_LINKED_SPAN))
      .addEqualityGroup(Link.fromSpanContext(SpanContext.INVALID, Type.CHILD_LINKED_SPAN))
      .addEqualityGroup(Link.fromSpanContext(SpanContext.INVALID, Type.PARENT_LINKED_SPAN))
      .addEqualityGroup(
          Link.fromSpanContext(spanContext, Type.PARENT_LINKED_SPAN, attributesMap),
          Link.fromSpanContext(spanContext, Type.PARENT_LINKED_SPAN, attributesMap));
  tester.testEquals();
}
 
Example 8
Source File: TracestateTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Test
public void tracestate_EqualsAndHashCode() {
  EqualsTester tester = new EqualsTester();
  tester.addEqualityGroup(EMPTY, EMPTY);
  tester.addEqualityGroup(firstTracestate, EMPTY.toBuilder().set(FIRST_KEY, FIRST_VALUE).build());
  tester.addEqualityGroup(
      secondTracestate, EMPTY.toBuilder().set(SECOND_KEY, SECOND_VALUE).build());
  tester.testEquals();
}
 
Example 9
Source File: TraceIdTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Test
public void traceId_EqualsAndHashCode() {
  EqualsTester tester = new EqualsTester();
  tester.addEqualityGroup(TraceId.INVALID, TraceId.INVALID);
  tester.addEqualityGroup(first, TraceId.fromBytes(Arrays.copyOf(firstBytes, firstBytes.length)));
  tester.addEqualityGroup(
      second, TraceId.fromBytes(Arrays.copyOf(secondBytes, secondBytes.length)));
  tester.testEquals();
}
 
Example 10
Source File: AttributeValueTest.java    From opentelemetry-java with Apache License 2.0 5 votes vote down vote up
@Test
public void attributeValue_EqualsAndHashCode() {
  EqualsTester tester = new EqualsTester();
  tester.addEqualityGroup(
      AttributeValue.stringAttributeValue("MyStringAttributeValue"),
      AttributeValue.stringAttributeValue("MyStringAttributeValue"));
  tester.addEqualityGroup(AttributeValue.stringAttributeValue("MyStringAttributeDiffValue"));
  tester.addEqualityGroup(
      AttributeValue.booleanAttributeValue(true), AttributeValue.booleanAttributeValue(true));
  tester.addEqualityGroup(AttributeValue.booleanAttributeValue(false));
  tester.addEqualityGroup(
      AttributeValue.longAttributeValue(123456L), AttributeValue.longAttributeValue(123456L));
  tester.addEqualityGroup(AttributeValue.longAttributeValue(1234567L));
  tester.addEqualityGroup(
      AttributeValue.doubleAttributeValue(1.23456), AttributeValue.doubleAttributeValue(1.23456));
  tester.addEqualityGroup(AttributeValue.doubleAttributeValue(1.234567));
  tester.addEqualityGroup(
      AttributeValue.arrayAttributeValue(
          "MyArrayStringAttributeValue1", "MyArrayStringAttributeValue2"),
      AttributeValue.arrayAttributeValue(
          "MyArrayStringAttributeValue1", "MyArrayStringAttributeValue2"));
  tester.addEqualityGroup(AttributeValue.arrayAttributeValue("MyArrayStringAttributeDiffValue"));
  tester.addEqualityGroup(
      AttributeValue.arrayAttributeValue(true, false, true),
      AttributeValue.arrayAttributeValue(true, false, true));
  tester.addEqualityGroup(AttributeValue.arrayAttributeValue(false));
  tester.addEqualityGroup(
      AttributeValue.arrayAttributeValue(123456L, 7890L),
      AttributeValue.arrayAttributeValue(123456L, 7890L));
  tester.addEqualityGroup(AttributeValue.arrayAttributeValue(1234567L));
  tester.addEqualityGroup(
      AttributeValue.arrayAttributeValue(1.23456, 7.890),
      AttributeValue.arrayAttributeValue(1.23456, 7.890));
  tester.addEqualityGroup(AttributeValue.arrayAttributeValue(1.234567));
  tester.testEquals();
}
 
Example 11
Source File: SpanIdTest.java    From opentelemetry-java with Apache License 2.0 5 votes vote down vote up
@Test
public void spanId_EqualsAndHashCode() {
  EqualsTester tester = new EqualsTester();
  tester.addEqualityGroup(SpanId.getInvalid(), SpanId.getInvalid());
  tester.addEqualityGroup(
      first, SpanId.fromBytes(Arrays.copyOf(firstBytes, firstBytes.length), 0));
  tester.addEqualityGroup(
      second, SpanId.fromBytes(Arrays.copyOf(secondBytes, secondBytes.length), 0));
  tester.testEquals();
}
 
Example 12
Source File: TraceOptionsTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Test
public void traceOptions_EqualsAndHashCode() {
  EqualsTester tester = new EqualsTester();
  tester.addEqualityGroup(TraceOptions.DEFAULT);
  tester.addEqualityGroup(
      TraceOptions.fromByte(SECOND_BYTE), TraceOptions.builder().setIsSampled(true).build());
  tester.addEqualityGroup(TraceOptions.fromByte(FIRST_BYTE));
  tester.testEquals();
}
 
Example 13
Source File: StatusTest.java    From opentelemetry-java with Apache License 2.0 5 votes vote down vote up
@Test
public void status_EqualsAndHashCode() {
  EqualsTester tester = new EqualsTester();
  tester.addEqualityGroup(Status.OK, Status.OK.withDescription(null));
  tester.addEqualityGroup(
      Status.CANCELLED.withDescription("ThisIsAnError"),
      Status.CANCELLED.withDescription("ThisIsAnError"));
  tester.addEqualityGroup(Status.UNKNOWN.withDescription("This is an error."));
  tester.testEquals();
}
 
Example 14
Source File: SpanIdTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Test
public void spanId_EqualsAndHashCode() {
  EqualsTester tester = new EqualsTester();
  tester.addEqualityGroup(SpanId.INVALID, SpanId.INVALID);
  tester.addEqualityGroup(first, SpanId.fromBytes(Arrays.copyOf(firstBytes, firstBytes.length)));
  tester.addEqualityGroup(
      second, SpanId.fromBytes(Arrays.copyOf(secondBytes, secondBytes.length)));
  tester.testEquals();
}
 
Example 15
Source File: ValueTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Test
public void equality() {
  EqualsTester tester = new EqualsTester();
  for (NameData what : NameData.values()) {
    tester.addEqualityGroup(make(what), make(what));
  }
  tester.testEquals();
}
 
Example 16
Source File: EndSpanOptionsTest.java    From opencensus-java with Apache License 2.0 5 votes vote down vote up
@Test
public void endSpanOptions_EqualsAndHashCode() {
  EqualsTester tester = new EqualsTester();
  tester.addEqualityGroup(
      EndSpanOptions.builder()
          .setStatus(Status.CANCELLED.withDescription("ThisIsAnError"))
          .build(),
      EndSpanOptions.builder()
          .setStatus(Status.CANCELLED.withDescription("ThisIsAnError"))
          .build());
  tester.addEqualityGroup(EndSpanOptions.builder().build(), EndSpanOptions.DEFAULT);
  tester.testEquals();
}
 
Example 17
Source File: VariableTest.java    From batfish with Apache License 2.0 5 votes vote down vote up
@Test
public void testEquals() {
  Variable variable = new Variable();
  variable.setType(Type.INTEGER);
  Variable initialInstance = clone(variable);
  EqualsTester equalsTester = new EqualsTester();
  equalsTester.addEqualityGroup(initialInstance, initialInstance).addEqualityGroup(new Object());
  variable.setDescription("description");
  equalsTester.addEqualityGroup(clone(variable));
  variable.setDisplayName("display name");
  equalsTester.addEqualityGroup(clone(variable));
  variable.setFields(ImmutableMap.of("f", new Field()));
  equalsTester.addEqualityGroup(clone(variable));
  variable.setLongDescription("long description");
  equalsTester.addEqualityGroup(clone(variable));
  variable.setMinElements(1);
  equalsTester.addEqualityGroup(clone(variable));
  variable.setMinLength(1);
  equalsTester.addEqualityGroup(clone(variable));
  variable.setOptional(true);
  equalsTester.addEqualityGroup(clone(variable));
  variable.setType(Type.BOOLEAN);
  equalsTester.addEqualityGroup(clone(variable));
  variable.setValue(BooleanNode.TRUE);
  equalsTester.addEqualityGroup(clone(variable));
  variable.setValues(ImmutableList.of());
  equalsTester.addEqualityGroup(clone(variable));
  equalsTester.testEquals();
}
 
Example 18
Source File: TraceFlagsTest.java    From opentelemetry-java with Apache License 2.0 5 votes vote down vote up
@Test
public void traceFlags_EqualsAndHashCode() {
  EqualsTester tester = new EqualsTester();
  tester.addEqualityGroup(TraceFlags.getDefault());
  tester.addEqualityGroup(
      TraceFlags.fromByte(SECOND_BYTE), TraceFlags.builder().setIsSampled(true).build());
  tester.addEqualityGroup(TraceFlags.fromByte(FIRST_BYTE));
  tester.testEquals();
}
 
Example 19
Source File: TraceIdTest.java    From opentelemetry-java with Apache License 2.0 5 votes vote down vote up
@Test
public void traceId_EqualsAndHashCode() {
  EqualsTester tester = new EqualsTester();
  tester.addEqualityGroup(TraceId.getInvalid(), TraceId.getInvalid());
  tester.addEqualityGroup(
      first, TraceId.fromBytes(Arrays.copyOf(firstBytes, firstBytes.length), 0));
  tester.addEqualityGroup(
      second, TraceId.fromBytes(Arrays.copyOf(secondBytes, secondBytes.length), 0));
  tester.testEquals();
}
 
Example 20
Source File: ValueTypeTest.java    From FreeBuilder with Apache License 2.0 5 votes vote down vote up
@Test
public void hashAndEquals() {
  EqualsTester tester = new EqualsTester();
  tester.addEqualityGroup(new Empty(), new Empty());
  tester.addEqualityGroup(new Name("Foo", "Bar"), new Name("Foo", "Bar"));
  tester.addEqualityGroup(new Name("Foo", "NotBar"));
  tester.addEqualityGroup(new Name("NotFoo", "Bar"));
  tester.addEqualityGroup(new Name("Foo", null), new Name("Foo", null));
  tester.addEqualityGroup(new Name(null, "Bar"), new Name(null, "Bar"));
  tester.addEqualityGroup(new PairThatOmitsNull(null, 42), new PairThatOmitsNull(null, 42));
  tester.addEqualityGroup(new PairThatOmitsNull(42, null), new PairThatOmitsNull(42, null));
  tester.addEqualityGroup(new PairThatOmitsNull(42, 42), new PairThatOmitsNull(42, 42));
  tester.testEquals();
}