当前位置: 首页>>代码示例>>Java>>正文


Java EqualsTester类代码示例

本文整理汇总了Java中com.google.common.testing.EqualsTester的典型用法代码示例。如果您正苦于以下问题:Java EqualsTester类的具体用法?Java EqualsTester怎么用?Java EqualsTester使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


EqualsTester类属于com.google.common.testing包,在下文中一共展示了EqualsTester类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMultimapEquals

import com.google.common.testing.EqualsTester; //导入依赖的package包/类
public void testMultimapEquals() {
  Multimap<String, Integer> multimap = createMultimap();
  Multimap<String, Integer> arrayListMultimap
      = ArrayListMultimap.create();
  arrayListMultimap.putAll("foo", Arrays.asList(1, 3));
  arrayListMultimap.put("bar", 2);

  new EqualsTester()
      .addEqualityGroup(multimap, createMultimap(), arrayListMultimap,
          ImmutableListMultimap.<String, Integer>builder()
              .put("bar", 2).put("foo", 1).put("foo", 3).build())
      .addEqualityGroup(ImmutableListMultimap.<String, Integer>builder()
          .put("bar", 2).put("foo", 3).put("foo", 1).build())
      .addEqualityGroup(ImmutableListMultimap.<String, Integer>builder()
          .put("foo", 2).put("foo", 3).put("foo", 1).build())
      .addEqualityGroup(ImmutableListMultimap.<String, Integer>builder()
          .put("bar", 2).put("foo", 3).build())
      .testEquals();
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:20,代码来源:ImmutableListMultimapTest.java

示例2: testForMapWithDefault

import com.google.common.testing.EqualsTester; //导入依赖的package包/类
public void testForMapWithDefault() {
  Map<String, Integer> map = Maps.newHashMap();
  map.put("One", 1);
  map.put("Three", 3);
  map.put("Null", null);
  Function<String, Integer> function = Functions.forMap(map, 42);

  assertEquals(1, function.apply("One").intValue());
  assertEquals(42, function.apply("Two").intValue());
  assertEquals(3, function.apply("Three").intValue());
  assertNull(function.apply("Null"));

  new EqualsTester()
      .addEqualityGroup(function, Functions.forMap(map, 42))
      .addEqualityGroup(Functions.forMap(map))
      .addEqualityGroup(Functions.forMap(map, null))
      .addEqualityGroup(Functions.forMap(map, 43))
      .testEquals();
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:20,代码来源:FunctionsTest.java

示例3: testOnResultOf_natural

import com.google.common.testing.EqualsTester; //导入依赖的package包/类
public void testOnResultOf_natural() {
  Comparator<String> comparator
      = Ordering.natural().onResultOf(StringLengthFunction.StringLength);
  assertTrue(comparator.compare("to", "be") == 0);
  assertTrue(comparator.compare("or", "not") < 0);
  assertTrue(comparator.compare("that", "to") > 0);

  new EqualsTester()
      .addEqualityGroup(
          comparator,
          Ordering.natural().onResultOf(StringLengthFunction.StringLength))
      .addEqualityGroup(DECREASING_INTEGER)
      .testEquals();
  reserializeAndAssert(comparator);
  assertEquals("Ordering.natural().onResultOf(StringLength)",
      comparator.toString());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:18,代码来源:OrderingTest.java

示例4: assertSeedlessHashFunctionEquals

import com.google.common.testing.EqualsTester; //导入依赖的package包/类
static void assertSeedlessHashFunctionEquals(Class<?> clazz) throws Exception {
  for (Method method : clazz.getDeclaredMethods()) {
    if (method.getReturnType().equals(HashFunction.class) // must return HashFunction
        && Modifier.isPublic(method.getModifiers()) // only the public methods
        && method.getParameterTypes().length == 0) { // only the seed-less hash functions
      HashFunction hashFunction1a = (HashFunction) method.invoke(clazz);
      HashFunction hashFunction1b = (HashFunction) method.invoke(clazz);

      new EqualsTester()
          .addEqualityGroup(hashFunction1a, hashFunction1b)
          .testEquals();

      // Make sure we're returning not only equal instances, but constants.
      assertSame(hashFunction1a, hashFunction1b);

      assertEquals(hashFunction1a.toString(), hashFunction1b.toString());
    }
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:20,代码来源:HashingTest.java

示例5: testEquality

import com.google.common.testing.EqualsTester; //导入依赖的package包/类
@Test
public void testEquality() {
    String deviceId1 = "of:001";
    String deviceId2 = "of:002";
    long labelResourceId1 = 100;
    long labelResourceId2 = 200;
    DefaultLabelResource h1 = new DefaultLabelResource(deviceId1,
                                                       labelResourceId1);
    DefaultLabelResource h2 = new DefaultLabelResource(deviceId1,
                                                       labelResourceId1);
    DefaultLabelResource h3 = new DefaultLabelResource(deviceId2,
                                                       labelResourceId2);
    DefaultLabelResource h4 = new DefaultLabelResource(deviceId2,
                                                       labelResourceId2);

    new EqualsTester().addEqualityGroup(h1, h2).addEqualityGroup(h3, h4)
            .testEquals();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:19,代码来源:DefaultLabelResourceTest.java

示例6: testOnResultOf_chained

import com.google.common.testing.EqualsTester; //导入依赖的package包/类
public void testOnResultOf_chained() {
  Comparator<String> comparator = DECREASING_INTEGER.onResultOf(
      StringLengthFunction.StringLength);
  assertTrue(comparator.compare("to", "be") == 0);
  assertTrue(comparator.compare("not", "or") < 0);
  assertTrue(comparator.compare("to", "that") > 0);

  new EqualsTester()
      .addEqualityGroup(
          comparator,
          DECREASING_INTEGER.onResultOf(StringLengthFunction.StringLength))
      .addEqualityGroup(
          DECREASING_INTEGER.onResultOf(Functions.constant(1)))
      .addEqualityGroup(Ordering.natural())
      .testEquals();
  reserializeAndAssert(comparator);
  assertEquals("Ordering.natural().reverse().onResultOf(StringLength)",
      comparator.toString());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:20,代码来源:OrderingTest.java

示例7: assertDifferent

import com.google.common.testing.EqualsTester; //导入依赖的package包/类
public static void assertDifferent(Key first, Key second, boolean checkDiskCacheKey)
    throws NoSuchAlgorithmException {
  new EqualsTester()
      .addEqualityGroup(first)
      .addEqualityGroup(second)
      .testEquals();

  if (checkDiskCacheKey) {
    MessageDigest firstDigest = MessageDigest.getInstance("SHA-1");
    first.updateDiskCacheKey(firstDigest);
    MessageDigest secondDigest = MessageDigest.getInstance("SHA-1");
    second.updateDiskCacheKey(secondDigest);

    assertThat(getDigest(first)).isNotEqualTo(getDigest(second));
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:KeyAssertions.java

示例8: testNewParameterizedType

import com.google.common.testing.EqualsTester; //导入依赖的package包/类
public void testNewParameterizedType() {
  ParameterizedType jvmType = (ParameterizedType)
      new TypeCapture<HashMap<String, int[][]>>() {}.capture();
  ParameterizedType ourType = Types.newParameterizedType(
      HashMap.class, String.class, int[][].class);

  new EqualsTester()
      .addEqualityGroup(jvmType, ourType)
      .testEquals();
  assertEquals(jvmType.toString(), ourType.toString());
  assertEquals(jvmType.hashCode(), ourType.hashCode());
  assertEquals(HashMap.class, ourType.getRawType());
  assertThat(ourType.getActualTypeArguments())
      .asList()
      .containsExactlyElementsIn(asList(jvmType.getActualTypeArguments()))
      .inOrder();
  assertEquals(Arrays.asList(String.class, Types.newArrayType(Types.newArrayType(int.class))),
               Arrays.asList(ourType.getActualTypeArguments()));
  assertEquals(null, ourType.getOwnerType());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:21,代码来源:TypesTest.java

示例9: testEquality

import com.google.common.testing.EqualsTester; //导入依赖的package包/类
@Test
public void testEquality() {
    operatorValue1.add(new BgpFsOperatorValue((byte) 1, new byte[100]));
    operatorValue1.add(new BgpFsOperatorValue((byte) 1, new byte[100]));
    operatorValue2.add(new BgpFsOperatorValue((byte) 2, new byte[100]));
    operatorValue2.add(new BgpFsOperatorValue((byte) 1, new byte[100]));

    BgpFsPacketLength tlv1 = new BgpFsPacketLength(operatorValue1);
    BgpFsPacketLength sameAsTlv1 = new BgpFsPacketLength(operatorValue1);
    BgpFsPacketLength tlv2 = new BgpFsPacketLength(operatorValue2);

    new EqualsTester()
    .addEqualityGroup(tlv1, sameAsTlv1)
    .addEqualityGroup(tlv2)
    .testEquals();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:17,代码来源:BgpFsPacketLengthTest.java

示例10: testEquals

import com.google.common.testing.EqualsTester; //导入依赖的package包/类
@Test
public void testEquals() throws MalformedURLException {
  Headers headers = mock(Headers.class);
  Headers otherHeaders = mock(Headers.class);
  String url = "http://www.google.com";
  String otherUrl = "http://mail.google.com";
  new EqualsTester()
      .addEqualityGroup(
          new GlideUrl(url),
          new GlideUrl(url),
          new GlideUrl(new URL(url)),
          new GlideUrl(new URL(url))
      )
      .addEqualityGroup(
          new GlideUrl(otherUrl),
          new GlideUrl(new URL(otherUrl))
      )
      .addEqualityGroup(
          new GlideUrl(url, headers),
          new GlideUrl(new URL(url), headers)
      )
      .addEqualityGroup(
          new GlideUrl(url, otherHeaders),
          new GlideUrl(new URL(url), otherHeaders)
      ).testEquals();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:GlideUrlTest.java

示例11: testNewParameterizedTypeWithOwner

import com.google.common.testing.EqualsTester; //导入依赖的package包/类
public void testNewParameterizedTypeWithOwner() {
  ParameterizedType jvmType = (ParameterizedType)
      new TypeCapture<Map.Entry<String, int[][]>>() {}.capture();
  ParameterizedType ourType = Types.newParameterizedTypeWithOwner(
      Map.class, Map.Entry.class, String.class, int[][].class);

  new EqualsTester()
      .addEqualityGroup(jvmType, ourType)
      .addEqualityGroup(new TypeCapture<Map.Entry<String, String>>() {}.capture())
      .addEqualityGroup(new TypeCapture<Map<String, Integer>>() {}.capture())
      .testEquals();
  assertEquals(jvmType.toString(), ourType.toString());
  assertEquals(Map.class, ourType.getOwnerType());
  assertEquals(Map.Entry.class, ourType.getRawType());
  assertThat(ourType.getActualTypeArguments())
      .asList()
      .containsExactlyElementsIn(asList(jvmType.getActualTypeArguments()))
      .inOrder();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:20,代码来源:TypesTest.java

示例12: testEquality

import com.google.common.testing.EqualsTester; //导入依赖的package包/类
@Test
public void testEquality() {
    operatorValue1.add(new BgpFsOperatorValue((byte) 1, new byte[100]));
    operatorValue1.add(new BgpFsOperatorValue((byte) 1, new byte[100]));
    operatorValue2.add(new BgpFsOperatorValue((byte) 2, new byte[100]));
    operatorValue2.add(new BgpFsOperatorValue((byte) 1, new byte[100]));

    BgpFsIcmpType tlv1 = new BgpFsIcmpType(operatorValue1);
    BgpFsIcmpType sameAsTlv1 = new BgpFsIcmpType(operatorValue1);
    BgpFsIcmpType tlv2 = new BgpFsIcmpType(operatorValue2);

    new EqualsTester()
    .addEqualityGroup(tlv1, sameAsTlv1)
    .addEqualityGroup(tlv2)
    .testEquals();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:17,代码来源:BgpFsIcmpTypeTest.java

示例13: testEqualityIPv4

import com.google.common.testing.EqualsTester; //导入依赖的package包/类
/**
 * Tests equality of {@link Ip4Prefix} for IPv4.
 */
@Test
public void testEqualityIPv4() {
    new EqualsTester()
        .addEqualityGroup(Ip4Prefix.valueOf("1.2.0.0/24"),
                          Ip4Prefix.valueOf("1.2.0.0/24"),
                          Ip4Prefix.valueOf("1.2.0.4/24"))
        .addEqualityGroup(Ip4Prefix.valueOf("1.2.0.0/16"),
                          Ip4Prefix.valueOf("1.2.0.0/16"))
        .addEqualityGroup(Ip4Prefix.valueOf("1.2.0.0/32"),
                          Ip4Prefix.valueOf("1.2.0.0/32"))
        .addEqualityGroup(Ip4Prefix.valueOf("1.3.0.0/24"),
                          Ip4Prefix.valueOf("1.3.0.0/24"))
        .addEqualityGroup(Ip4Prefix.valueOf("0.0.0.0/0"),
                          Ip4Prefix.valueOf("0.0.0.0/0"))
        .addEqualityGroup(Ip4Prefix.valueOf("255.255.255.255/32"),
                          Ip4Prefix.valueOf("255.255.255.255/32"))
        .testEquals();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:22,代码来源:Ip4PrefixTest.java

示例14: testEquals

import com.google.common.testing.EqualsTester; //导入依赖的package包/类
/**
 * Tests the equals(), hashCode() and toString() operations.
 */
@Test
public void testEquals() {
    final List<TestEntry> ops1 = new LinkedList<>();
    ops1.add(entry1);
    final List<TestEntry> ops2 = new LinkedList<>();
    ops2.add(entry2);

    final TestOperation op1 = new TestOperation(ops1);
    final TestOperation sameAsOp1 = new TestOperation(ops1);
    final TestOperation op2 = new TestOperation(ops2);

    new EqualsTester()
            .addEqualityGroup(op1, sameAsOp1)
            .addEqualityGroup(op2)
            .testEquals();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:20,代码来源:BatchOperationTest.java

示例15: testEquals

import com.google.common.testing.EqualsTester; //导入依赖的package包/类
public void testEquals() {
  BloomFilter<String> bf1 = BloomFilter.create(Funnels.unencodedCharsFunnel(), 100);
  bf1.put("1");
  bf1.put("2");

  BloomFilter<String> bf2 = BloomFilter.create(Funnels.unencodedCharsFunnel(), 100);
  bf2.put("1");
  bf2.put("2");

  new EqualsTester()
      .addEqualityGroup(bf1, bf2)
      .testEquals();

  bf2.put("3");

  new EqualsTester()
      .addEqualityGroup(bf1)
      .addEqualityGroup(bf2)
      .testEquals();
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:21,代码来源:BloomFilterTest.java


注:本文中的com.google.common.testing.EqualsTester类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。