org.opengis.test.Assert.fail()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(12.3k)|赞(0)|评价(0)|浏览(185)

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

Assert.fail介绍

暂无

代码示例

代码示例来源:origin: org.opengis/geoapi-conformance

/**
 * Asserts that the given integer value is positive, including zero.
 *
 * @param message The message to send in case of failure.
 * @param value   The value to test.
 */
public static void assertPositive(String message, int value) {
  if (value < 0) {
    fail(message + " Value is " + value + '.');
  }
}

代码示例来源:origin: org.opengis/geoapi-conformance

/**
 * Asserts that the given integer value is strictly positive, excluding zero.
 *
 * @param message The message to send in case of failure.
 * @param value   The value to test.
 */
public static void assertStrictlyPositive(String message, int value) {
  if (value <= 0) {
    fail(message + " Value is " + value + '.');
  }
}

代码示例来源:origin: org.opengis/geoapi-conformance

/**
 * Asserts that the given minimum and maximum values make a valid range. More specifically
 * asserts that the minimum value is not greater than the maximum value.
 *
 * @param message The message to send in case of failure.
 * @param minimum The lower bound of the range to test.
 * @param maximum The upper bound of the range to test.
 */
public static void assertValidRange(String message, int minimum, int maximum) {
  if (minimum > maximum) {
    fail(message + " Range found is [" + minimum + " ... " + maximum + "].");
  }
}

代码示例来源:origin: org.opengis/geoapi-conformance

/**
 * Asserts that the given minimum and maximum values make a valid range. More specifically
 * asserts that the minimum value is not greater than the maximum value. If one bound is or
 * both bounds are {@linkplain Double#NaN NaN}, then the test fails.
 *
 * @param message The message to send in case of failure.
 * @param minimum The lower bound of the range to test.
 * @param maximum The upper bound of the range to test.
 */
public static void assertValidRange(String message, double minimum, double maximum) {
  if (!(minimum <= maximum)) { // Use '!' for catching NaN.
    fail(message + " Range found is [" + minimum + " ... " + maximum + "].");
  }
}

代码示例来源:origin: org.opengis/geoapi-conformance

/**
 * Asserts that the given value is between the given range. If the value is
 * {@linkplain Double#NaN NaN}, then this test passes silently. This method
 * do <strong>not</strong> tests the validity of the given range.
 *
 * @param message The message to send in case of failure.
 * @param minimum The lower bound of the range, inclusive.
 * @param maximum The upper bound of the range, inclusive.
 * @param value   The value to test.
 */
public static void assertBetween(String message, double minimum, double maximum, double value) {
  if (value < minimum) {
    fail(message + " Value is " + value + " is less than " + minimum + '.');
  }
  if (value > maximum) {
    fail(message + " Value is " + value + " is greater than " + maximum + '.');
  }
}

代码示例来源:origin: org.opengis/geoapi-conformance

/**
 * Asserts that the given value is between the given range. This method do <strong>not</strong>
 * tests the validity of the given range.
 *
 * @param message The message to send in case of failure.
 * @param minimum The lower bound of the range, inclusive.
 * @param maximum The upper bound of the range, inclusive.
 * @param value   The value to test.
 */
public static void assertBetween(String message, int minimum, int maximum, int value) {
  if (value < minimum) {
    fail(message + " Value is " + value + " is less than " + minimum + '.');
  }
  if (value > maximum) {
    fail(message + " Value is " + value + " is greater than " + maximum + '.');
  }
}

代码示例来源:origin: org.opengis/geoapi-conformance

/**
 * Asserts that the given minimum and maximum values make a valid range. More specifically
 * asserts that if both values are non-null, then the minimum value is not greater than the
 * maximum value.
 *
 * @param <T>     The type of values being compared.
 * @param message The message to send in case of failure.
 * @param minimum The lower bound of the range to test, or {@code null} if unbounded.
 * @param maximum The upper bound of the range to test, or {@code null} if unbounded.
 */
@SuppressWarnings("unchecked")
public static <T> void assertValidRange(String message, Comparable<T> minimum, Comparable<T> maximum) {
  if (minimum != null && maximum != null) {
    if (minimum.compareTo((T) maximum) > 0) {
      fail(message + " Range found is [" + minimum + " ... " + maximum + "].");
    }
  }
}

代码示例来源:origin: org.opengis/geoapi-conformance

/**
   * Asserts that the given value is contained in the given collection. If the given collection
   * is null, then this test passes silently (a null collection is considered as "unknown", not
   * empty). If the given value is null, then the test passes only if the given collection
   * contains the null element.
   *
   * @param message    The message to send in case of failure.
   * @param collection The collection where to look for inclusion, or {@code null}.
   * @param value      The value to test for inclusion.
   */
  public static void assertContains(String message, Collection<?> collection, Object value) {
    if (collection != null) {
      if (!collection.contains(value)) {
        fail(message + " Looked for value \"" + value + "\" in a collection of " +
            collection.size() + "elements.");
      }
    }
  }
}

代码示例来源:origin: org.opengis/geoapi-conformance

/**
 * Asserts that the given value is an instance of the given class. No tests are performed if
 * the type is {@code null}. If the type is not-null but the value is null, this is considered
 * as a failure.
 *
 * @param message      The message to send in case of failure.
 * @param expectedType The expected parent class of the value, or {@code null}.
 * @param value        The value to test, or {@code null} (which is a failure).
 */
public static void assertInstanceOf(String message, Class<?> expectedType, Object value) {
  if (expectedType != null) {
    if (!expectedType.isInstance(value)) {
      fail(message + " Value \"" + value + "\" is of type " + value.getClass().getSimpleName() +
          " while the expected type was " + expectedType.getSimpleName() + '.');
    }
  }
}

代码示例来源:origin: opengeospatial/geoapi

/**
 * Verifies if we expected a null value, then returns {@code true} if the value is null as expected.
 */
private static boolean isNull(final String message, final Object expected, final Object actual) {
  final boolean isNull = (actual == null);
  if (isNull != (expected == null)) {
    fail(concat(message, isNull ? "Value is null." : "Expected null."));
  }
  return isNull;
}

代码示例来源:origin: opengeospatial/geoapi

/**
 * Asserts that the given minimum is smaller or equals to the given maximum.
 * If one bound is or both bounds are {@linkplain Double#NaN NaN}, then the test fails.
 *
 * @param message  header of the exception message in case of failure, or {@code null} if none.
 * @param minimum  the lower bound of the range to test.
 * @param maximum  the upper bound of the range to test.
 */
public static void assertValidRange(final String message, final double minimum, final double maximum) {
  if (!(minimum <= maximum)) { // Use '!' for catching NaN.
    fail(nonNull(message) + "Range found is [" + minimum + " ... " + maximum + "].");
  }
}

代码示例来源:origin: opengeospatial/geoapi

/**
 * Asserts that the given integer value is positive, including zero.
 *
 * @param message  header of the exception message in case of failure, or {@code null} if none.
 * @param value   The value to test.
 */
public static void assertPositive(final String message, final int value) {
  if (value < 0) {
    fail(nonNull(message) + "Value is " + value + '.');
  }
}

代码示例来源:origin: opengeospatial/geoapi

/**
 * Asserts that the given integer value is strictly positive, excluding zero.
 *
 * @param message  header of the exception message in case of failure, or {@code null} if none.
 * @param value    the value to test.
 */
public static void assertStrictlyPositive(final String message, final int value) {
  if (value <= 0) {
    fail(nonNull(message) + "Value is " + value + '.');
  }
}

代码示例来源:origin: opengeospatial/geoapi

/**
 * Asserts that the given minimum is smaller or equals to the given maximum.
 *
 * @param message  header of the exception message in case of failure, or {@code null} if none.
 * @param minimum  the lower bound of the range to test.
 * @param maximum  the upper bound of the range to test.
 */
public static void assertValidRange(final String message, final int minimum, final int maximum) {
  if (minimum > maximum) {
    fail(nonNull(message) + "Range found is [" + minimum + " ... " + maximum + "].");
  }
}

代码示例来源:origin: opengeospatial/geoapi

/**
 * Asserts that the given value is inside the given range. This method does <strong>not</strong>
 * test the validity of the given [{@code minimum} … {@code maximum}] range.
 *
 * @param message  header of the exception message in case of failure, or {@code null} if none.
 * @param minimum  the lower bound of the range, inclusive.
 * @param maximum  the upper bound of the range, inclusive.
 * @param value    the value to test.
 */
public static void assertBetween(final String message, final int minimum, final int maximum, final int value) {
  if (value < minimum) {
    fail(nonNull(message) + "Value " + value + " is less than " + minimum + '.');
  }
  if (value > maximum) {
    fail(nonNull(message) + "Value " + value + " is greater than " + maximum + '.');
  }
}

代码示例来源:origin: opengeospatial/geoapi

/**
 * Asserts that the given value is contained in the given collection. If the given collection
 * is null, then this test passes silently (a null collection is considered as "unknown", not
 * empty). If the given value is null, then the test passes only if the given collection
 * contains the null element.
 *
 * @param message     header of the exception message in case of failure, or {@code null} if none.
 * @param collection  the collection where to look for inclusion, or {@code null} if unrestricted.
 * @param value       the value to test for inclusion.
 */
public static void assertContains(final String message, final Collection<?> collection, final Object value) {
  if (collection != null) {
    if (!collection.contains(value)) {
      fail(nonNull(message) + "Looked for value \"" + value + "\" in a collection of " +
          collection.size() + "elements.");
    }
  }
}

代码示例来源:origin: opengeospatial/geoapi

/**
 * Asserts that the given minimum and maximum values make a valid range. More specifically
 * asserts that if both values are non-null, then the minimum value is not greater than the
 * maximum value.
 *
 * @param <T>      the type of values being compared.
 * @param message  header of the exception message in case of failure, or {@code null} if none.
 * @param minimum  the lower bound of the range to test, or {@code null} if unbounded.
 * @param maximum  the upper bound of the range to test, or {@code null} if unbounded.
 */
@SuppressWarnings("unchecked")
public static <T> void assertValidRange(final String message, final Comparable<T> minimum, final Comparable<T> maximum) {
  if (minimum != null && maximum != null) {
    if (minimum.compareTo((T) maximum) > 0) {
      fail(nonNull(message) + "Range found is [" + minimum + " ... " + maximum + "].");
    }
  }
}

代码示例来源:origin: opengeospatial/geoapi

/**
 * Asserts that the given value is inside the given range. If the given {@code value} is
 * {@linkplain Double#NaN NaN}, then this test passes silently. This method does <strong>not</strong>
 * test the validity of the given [{@code minimum} … {@code maximum}] range.
 *
 * @param message  header of the exception message in case of failure, or {@code null} if none.
 * @param minimum  the lower bound of the range, inclusive.
 * @param maximum  the upper bound of the range, inclusive.
 * @param value    the value to test.
 */
public static void assertBetween(final String message, final double minimum, final double maximum, final double value) {
  if (value < minimum) {
    fail(nonNull(message) + "Value " + value + " is less than " + minimum + '.');
  }
  if (value > maximum) {
    fail(nonNull(message) + "Value " + value + " is greater than " + maximum + '.');
  }
}

代码示例来源:origin: opengeospatial/geoapi

/**
 * Creates a geodetic CRS for the given code and verify its properties.
 *
 * @param  crsCode  the code of the CRS to create.
 * @throws FactoryException if an error occurred while creating the CRS instance.
 */
private void createAndVerifyGeocentricCRS(final int crsCode) throws FactoryException {
  if (crsAuthorityFactory != null) {
    final GeocentricCRS crs;
    try {
      crs = crsAuthorityFactory.createGeocentricCRS(String.valueOf(crsCode));
    } catch (NoSuchAuthorityCodeException e) {
      unsupportedCode(GeocentricCRS.class, crsCode);
      throw e;
    }
    if (crs == null) {
      fail("CRSAuthorityFactory.createGeocentricCRS(\"" + code + "\") shall not return null.");
    }
    validators.validate(crs);
    verifyGeodeticCRS(crsCode, crs, GEOCENTRIC);
  }
}

代码示例来源:origin: apache/sis

/**
 * Verifies that {@link StorageConnector#getStorageAs(Class)} returns {@code null} for unavailable
 * target classes, and throws an exception for illegal target classes.
 *
 * @throws DataStoreException if an error occurred while using the storage connector.
 */
@Test
public void testGetInvalidObject() throws DataStoreException {
  final StorageConnector connection = create(true);
  assertNotNull("getStorageAs(InputStream.class)", connection.getStorageAs(InputStream.class));
  assertNull   ("getStorageAs(URI.class)",         connection.getStorageAs(URI.class));
  assertNull   ("getStorageAs(String.class)",      connection.getStorageAs(String.class));
  try {
    connection.getStorageAs(Float.class);       // Any unconvertible type.
    fail("Should not have accepted Float.class");
  } catch (UnconvertibleObjectException e) {
    final String message = e.getMessage();
    assertTrue(message, message.contains("Float"));
  }
  connection.closeAllExcept(null);
}

相关文章