org.testng.Assert.assertEqualsImpl()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(181)

本文整理了Java中org.testng.Assert.assertEqualsImpl()方法的一些代码示例,展示了Assert.assertEqualsImpl()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Assert.assertEqualsImpl()方法的具体详情如下:
包路径:org.testng.Assert
类名称:Assert
方法名:assertEqualsImpl

Assert.assertEqualsImpl介绍

[英]Differs from #assertEquals(Object,Object,String) by not taking arrays into special consideration hence comparing them by reference. Intended to be called directly to test equality of collections content.
[中]与#assertEquals(Object、Object、String)不同的是,没有特别考虑数组,因此通过引用对它们进行比较。用于直接调用以测试集合内容的相等性。

代码示例

代码示例来源:origin: org.testng/testng

/**
 * Asserts that two objects are equal. If they are not,
 * an AssertionError, with the given message, is thrown.
 * @param actual the actual value
 * @param expected the expected value
 * @param message the assertion error message
 */
public static void assertEquals(Object actual, Object expected, String message) {
 if (expected != null && expected.getClass().isArray()) {
   assertArrayEquals(actual, expected, message);
   return;
 }
 assertEqualsImpl(actual, expected, message);
}

代码示例来源:origin: org.testng/testng

/**
 * Asserts that two maps are equal.
 */
public static void assertEquals(Map<?, ?> actual, Map<?, ?> expected, String message) {
 if (actual == expected) {
  return;
 }
 if (actual == null || expected == null) {
  fail("Maps not equal: expected: " + expected + " and actual: " + actual);
 }
 if (actual.size() != expected.size()) {
  fail("Maps do not have the same size:" + actual.size() + " != " + expected.size());
 }
 Set<?> entrySet = actual.entrySet();
 for (Object anEntrySet : entrySet) {
  Map.Entry<?, ?> entry = (Map.Entry<?, ?>) anEntrySet;
  Object key = entry.getKey();
  Object value = entry.getValue();
  Object expectedValue = expected.get(key);
  String assertMessage = message != null ? message : "Maps do not match for key:"
    + key + " actual:" + value + " expected:" + expectedValue;
  assertEqualsImpl(value, expectedValue, assertMessage);
 }
}

代码示例来源:origin: org.testng/testng

String errorMessage = message == null ? explanation : message + ": " + explanation;
assertEqualsImpl(a, e, errorMessage);

代码示例来源:origin: org.testng/testng

public static void assertEqualsDeep(Map<?, ?> actual, Map<?, ?> expected, String message) {
 if (actual == expected) {
  return;
 }
 if (actual == null || expected == null) {
  fail("Maps not equal: expected: " + expected + " and actual: " + actual);
 }
 if (actual.size() != expected.size()) {
  fail("Maps do not have the same size:" + actual.size() + " != " + expected.size());
 }
 Set<?> entrySet = actual.entrySet();
 for (Object anEntrySet : entrySet) {
  Map.Entry<?, ?> entry = (Map.Entry<?, ?>) anEntrySet;
  Object key = entry.getKey();
  Object value = entry.getValue();
  Object expectedValue = expected.get(key);
  String assertMessage = message != null ? message : "Maps do not match for key:"
    + key + " actual:" + value + " expected:" + expectedValue;
  if (expectedValue.getClass().isArray()) {
   assertArrayEquals(value, expectedValue, assertMessage);
  } else {
   assertEqualsImpl(value, expectedValue, assertMessage);
  }
 }
}

代码示例来源:origin: cbeust/testng

/**
 * Asserts that two objects are equal. If they are not, an AssertionError, with the given message,
 * is thrown.
 *
 * @param actual the actual value
 * @param expected the expected value
 * @param message the assertion error message
 */
public static void assertEquals(Object actual, Object expected, String message) {
 if (expected != null && expected.getClass().isArray()) {
  assertArrayEquals(actual, expected, message);
  return;
 }
 assertEqualsImpl(actual, expected, message);
}

代码示例来源:origin: org.testng/testng

String errorMessage = message == null ? explanation : message + ": " + explanation;
assertEqualsImpl(a, e, errorMessage);

代码示例来源:origin: org.testng/testng

public static void assertEqualsDeep(Set<?> actual, Set<?> expected, String message) {
 if (actual == expected) {
  return;
 }
 if (actual == null || expected == null) {
  // Keep the back compatible
  if (message == null) {
   fail("Sets not equal: expected: " + expected + " and actual: " + actual);
  } else {
   failNotEquals(actual, expected, message);
  }
 }
 Iterator<?> actualIterator = actual.iterator();
 Iterator<?> expectedIterator = expected.iterator();
 while (expectedIterator.hasNext()) {
  Object expectedValue = expectedIterator.next();
  if (!actualIterator.hasNext()) {
   fail("Sets not equal: expected: " + expected + " and actual: " + actual);
  }
  Object value = actualIterator.next();
  if (expectedValue.getClass().isArray()) {
   assertArrayEquals(value, expectedValue, message);
  } else {
   assertEqualsImpl(value, expectedValue, message);
  }
 }
}

代码示例来源:origin: cbeust/testng

/** Asserts that two maps are equal. */
public static void assertEquals(Map<?, ?> actual, Map<?, ?> expected, String message) {
 if (actual == expected) {
  return;
 }
 if (actual == null || expected == null) {
  fail("Maps not equal: expected: " + expected + " and actual: " + actual);
 }
 if (actual.size() != expected.size()) {
  fail("Maps do not have the same size:" + actual.size() + " != " + expected.size());
 }
 Set<?> entrySet = actual.entrySet();
 for (Object anEntrySet : entrySet) {
  Map.Entry<?, ?> entry = (Map.Entry<?, ?>) anEntrySet;
  Object key = entry.getKey();
  Object value = entry.getValue();
  Object expectedValue = expected.get(key);
  String assertMessage =
    message != null
      ? message
      : "Maps do not match for key:"
        + key
        + " actual:"
        + value
        + " expected:"
        + expectedValue;
  assertEqualsImpl(value, expectedValue, assertMessage);
 }
}

代码示例来源:origin: cbeust/testng

String explanation = "Lists differ at element [" + i + "]: " + e + " != " + a;
String errorMessage = message == null ? explanation : message + ": " + explanation;
assertEqualsImpl(a, e, errorMessage);

代码示例来源:origin: cbeust/testng

assertArrayEquals(value, expectedValue, assertMessage);
} else {
 assertEqualsImpl(value, expectedValue, assertMessage);

代码示例来源:origin: cbeust/testng

String errorMessage = message == null ? explanation : message + ": " + explanation;
assertEqualsImpl(a, e, errorMessage);

代码示例来源:origin: cbeust/testng

assertArrayEquals(value, expectedValue, message);
} else {
 assertEqualsImpl(value, expectedValue, message);

代码示例来源:origin: cbeust/testng

assertEquals(a, e, errorMessage);
} else {
 assertEqualsImpl(a, e, errorMessage);

相关文章