org.opengis.test.Assert类的使用及代码示例

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

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

Assert介绍

[英]Extension to JUnit assertion methods. This class inherits all assertion methods from the org.junit.Assert class. Consequently, developers can replace the following statement:

import static org.junit.Assert.*;

by

import static org.opengis.test.Assert.*;

if they wish to use the assertion methods defined here in addition of JUnit methods.
[中]JUnit断言方法的扩展。此类从组织继承所有断言方法。朱尼特。断言类。因此,如果开发人员希望在JUnit方法之外使用此处定义的断言方法,则可以将以下语句替换为:

import static org.junit.Assert.*;

代码示例

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

/**
 * Checks if a {@link Comparable} is a number identical to the supplied integer value.
 */
private static void assertBoundEquals(final String message, final int expected, final Comparable<?> actual) {
  assertInstanceOf(message, Integer.class, actual);
  assertEquals(message, expected, ((Number) actual).intValue());
}

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

/**
 * Validates the geographic bounding box.
 *
 * @param  object  the object to validate, or {@code null}.
 */
public void validate(final GeographicBoundingBox object) {
  if (object == null) {
    return;
  }
  final double west  = object.getWestBoundLongitude();
  final double east  = object.getEastBoundLongitude();
  final double south = object.getSouthBoundLatitude();
  final double north = object.getNorthBoundLatitude();
  assertBetween("GeographicBoundingBox: illegal west bound.",  -180, +180, west);
  assertBetween("GeographicBoundingBox: illegal east bound.",  -180, +180, east);
  assertBetween("GeographicBoundingBox: illegal south bound.", -90,   +90, south);
  assertBetween("GeographicBoundingBox: illegal north bound.", -90,   +90, north);
  assertFalse("GeographicBoundingBox: invalid range of latitudes.",  south > north);          // Accept NaN.
  // Do not require west <= east, as this condition is not specified in ISO 19115.
  // Some implementations may use west > east for box spanning the anti-meridian.
}

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

/**
 * Ensures that ISO 19103 or GeoAPI restrictions apply.
 *
 * @param object The object to validate, or {@code null}.
 */
public void validate(final LocalName object) {
  if (object == null) {
    return;
  }
  validate(object.scope());
  final List<? extends LocalName> parsedNames = object.getParsedNames();
  validate(object, parsedNames);
  if (parsedNames != null) {
    assertEquals("LocalName: should have exactly one parsed name.", 1, parsedNames.size());
    assertSame("LocalName: the parsed name element should be the enclosing local name.",
        object, parsedNames.get(0));
  }
}

代码示例来源: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 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: org.opengis/geoapi-conformance

/**
 * Validates the geographic bounding box.
 *
 * @param object The object to validate, or {@code null}.
 */
public void validate(final GeographicBoundingBox object) {
  if (object == null) {
    return;
  }
  final double west  = object.getWestBoundLongitude();
  final double east  = object.getEastBoundLongitude();
  final double south = object.getSouthBoundLatitude();
  final double north = object.getNorthBoundLatitude();
  assertBetween("GeographicBoundingBox: illegal west bound.",  -180, +180, west);
  assertBetween("GeographicBoundingBox: illegal east bound.",  -180, +180, east);
  assertBetween("GeographicBoundingBox: illegal south bound.", -90,   +90, south);
  assertBetween("GeographicBoundingBox: illegal north bound.", -90,   +90, north);
  assertTrue("GeographicBoundingBox: invalid range of longitudes.", west <= east);
  assertTrue("GeographicBoundingBox: invalid range of latitudes.",  south <= north);
}

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

assertNotSame    ("converse",           category, converse);
assertSame       ("converse.converse",  category, converse.converse);
assertSame       ("converted",          converse, category.converted());
assertSame       ("converted",          converse, converse.converted());
assertEquals     ("name",               "Random",            String.valueOf(category.name));
assertEquals     ("name",               "Random",            String.valueOf(converse.name));
assertEquals     ("name",               "Random",            String.valueOf(category.getName()));
assertEquals     ("name",               "Random",            String.valueOf(converse.getName()));
assertEquals     ("minimum",            lower,               category.minimum, STRICT);
assertEquals     ("maximum",            upper,               category.maximum, STRICT);
assertEquals     ("minimum",            lower*scale+offset,  converse.minimum, EPS);
assertEquals     ("maximum",            upper*scale+offset,  converse.maximum, EPS);
assertBoundEquals("range.minValue",     lower,               category.range.getMinValue());
assertBoundEquals("range.maxValue",     upper,               category.range.getMaxValue());
assertBoundEquals("range.minValue",     converse.minimum,    converse.range.getMinValue());
assertBoundEquals("range.maxValue",     converse.maximum,    converse.range.getMaxValue());
assertSame       ("sampleRange",        category.range,      category.getSampleRange());
assertSame       ("sampleRange",        converse.range,      converse.getSampleRange());
assertSame       ("measurementRange",   converse.range,      category.getMeasurementRange().get());
assertSame       ("measurementRange",   converse.range,      converse.getMeasurementRange().get());
assertSame       ("transferFunction",   category.toConverse, category.getTransferFunction().get());
assertNotSame    ("transferFunction",   converse.toConverse, converse.getTransferFunction().get());
assertTrue       ("transferFunction",                        converse.getTransferFunction().get().isIdentity());
assertFalse      ("toConverse.isIdentity",                   category.toConverse.isIdentity());
assertFalse      ("toConverse.isIdentity",                   converse.toConverse.isIdentity());
assertTrue       ("isQuantitative",                          category.isQuantitative());
assertTrue       ("isQuantitative",                          converse.isQuantitative());
assertSame("inverse", inverse, category.toConverse.inverse());

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

final boolean  collision = toNaN.contains(sample);
final Category category  = new Category("Random", NumberRange.create(sample, true, sample, true), null, null, toNaN);
assertTrue("Allocated NaN ordinal", toNaN.contains(sample));
assertEquals     ("name",           "Random",       String.valueOf(category.name));
assertEquals     ("name",           "Random",       String.valueOf(category.getName()));
assertEquals     ("minimum",        sample,         category.minimum, STRICT);
assertEquals     ("maximum",        sample,         category.maximum, STRICT);
assertBoundEquals("range.minValue", sample,         category.range.getMinValue());
assertBoundEquals("range.maxValue", sample,         category.range.getMaxValue());
assertSame       ("sampleRange",    category.range, category.getSampleRange());
assertFalse      ("measurementRange",               category.getMeasurementRange().isPresent());
assertFalse      ("toConverse.isIdentity",          category.toConverse.isIdentity());
assertFalse      ("transferFunction",               category.getTransferFunction().isPresent());
assertFalse      ("isQuantitative",                 category.isQuantitative());
assertNotSame("converse",           category, converse);
assertSame   ("converse.converse",  category, converse.converse);
assertSame   ("converted",          converse, category.converted());
assertSame   ("converted",          converse, converse.converted());
assertEquals ("name",               "Random", String.valueOf(converse.name));
assertEquals ("name",               "Random", String.valueOf(converse.getName()));
assertTrue   ("minimum",                      Double.isNaN(converse.minimum));
assertTrue   ("maximum",                      Double.isNaN(converse.maximum));
assertNull   ("range",                        converse.range);
assertNotNull("sampleRange",                  converse.getSampleRange());
assertFalse  ("measurementRange",             category.getMeasurementRange().isPresent());
assertFalse  ("toConverse.isIdentity",        converse.toConverse.isIdentity());
assertFalse  ("transferFunction",             converse.getTransferFunction().isPresent());

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

/**
 * Implementation of {@link #testGetAsDataInputFromURL()} and {@link #testGetAsDataInputFromStream()}.
 */
private void testGetAsDataInput(final boolean asStream) throws DataStoreException, IOException {
  final StorageConnector connection = create(asStream);
  final DataInput input = connection.getStorageAs(DataInput.class);
  assertSame("Value shall be cached.", input, connection.getStorageAs(DataInput.class));
  assertInstanceOf("Needs the SIS implementation.", ChannelImageInputStream.class, input);
  assertSame("Instance shall be shared.", input, connection.getStorageAs(ChannelDataInput.class));
  /*
   * Reads a single integer for checking that the stream is at the right position, then close the stream.
   * Since the file is a compiled Java class, the integer that we read shall be the Java magic number.
   */
  final ReadableByteChannel channel = ((ChannelImageInputStream) input).channel;
  assertTrue("channel.isOpen()", channel.isOpen());
  assertEquals("First 4 bytes", MAGIC_NUMBER, input.readInt());
  connection.closeAllExcept(null);
  assertFalse("channel.isOpen()", channel.isOpen());
}

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

/**
 * Tests the {@link StorageConnector#getStorageAs(Class)} method for the {@link ChannelDataInput} type.
 * The initial value should not be an instance of {@link ChannelImageInputStream} in order to avoid initializing
 * the Image I/O classes. However after a call to {@code getStorageAt(ChannelImageInputStream.class)}, the type
 * should have been promoted.
 *
 * @throws DataStoreException if an error occurred while using the storage connector.
 * @throws IOException if an error occurred while reading the test file.
 */
@Test
public void testGetAsChannelDataInput() throws DataStoreException, IOException {
  final StorageConnector connection = create(true);
  final ChannelDataInput input = connection.getStorageAs(ChannelDataInput.class);
  assertFalse(input instanceof ChannelImageInputStream);
  assertEquals(MAGIC_NUMBER, input.buffer.getInt());
  /*
   * Get as an image input stream and ensure that the cached value has been replaced.
   */
  final DataInput stream = connection.getStorageAs(DataInput.class);
  assertInstanceOf("Needs the SIS implementation", ChannelImageInputStream.class, stream);
  assertNotSame("Expected a new instance.", input, stream);
  assertSame("Shall share the channel.", input.channel, ((ChannelDataInput) stream).channel);
  assertSame("Shall share the buffer.",  input.buffer,  ((ChannelDataInput) stream).buffer);
  assertSame("Cached valud shall have been replaced.", stream, connection.getStorageAs(ChannelDataInput.class));
  connection.closeAllExcept(null);
}

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

/**
   * Tests a category with a NaN value.
   */
  @Test
  public void testCategoryNaN() {
    final Category category = new Category("NaN", new NumberRange<>(Float.class, Float.NaN, true, Float.NaN, true), null, null, null);
    final NumberRange<?> range = category.getSampleRange();
    assertSame  ("converse",       category,   category.converse);
    assertEquals("name",           "NaN",      String.valueOf(category.name));
    assertEquals("name",           "NaN",      String.valueOf(category.getName()));
    assertEquals("minimum",        Double.NaN, category.minimum, STRICT);
    assertEquals("maximum",        Double.NaN, category.maximum, STRICT);
    assertNull  ("sampleRange",                category.range);
    assertEquals("range.minValue", Float.NaN,  range.getMinValue());
    assertEquals("range.maxValue", Float.NaN,  range.getMaxValue());
    assertFalse ("measurementRange",           category.getMeasurementRange().isPresent());
    assertFalse ("transferFunction",           category.getTransferFunction().isPresent());
    assertTrue  ("toConverse.isIdentity",      category.toConverse.isIdentity());
    assertFalse ("isQuantitative",             category.isQuantitative());
  }
}

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

/**
 * Tests the {@link StorageConnector#getStorageAs(Class)} method for the {@link InputStream} type.
 * The {@code InputStream} was specified as a URL.
 *
 * @throws DataStoreException if an error occurred while using the storage connector.
 * @throws IOException if an error occurred while reading the test file.
 */
@Test
@DependsOnMethod("testGetAsImageInputStream")
public void testGetAsInputStream() throws DataStoreException, IOException {
  final StorageConnector connection = create(false);
  final InputStream in = connection.getStorageAs(InputStream.class);
  assertNotSame(connection.getStorage(), in);
  assertSame("Expected cached value.", in, connection.getStorageAs(InputStream.class));
  assertInstanceOf("Expected Channel backend.", InputStreamAdapter.class, in);
  final ImageInputStream input = ((InputStreamAdapter) in).input;
  assertInstanceOf("Expected Channel backend.", ChannelImageInputStream.class, input);
  assertSame(input, connection.getStorageAs(DataInput.class));
  assertSame(input, connection.getStorageAs(ImageInputStream.class));
  final ReadableByteChannel channel = ((ChannelImageInputStream) input).channel;
  assertTrue(channel.isOpen());
  connection.closeAllExcept(null);
  assertFalse(channel.isOpen());
}

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

final char[] actual = new char[expected.length];
in.mark(1000);
assertEquals("Number of characters read.", expected.length, in.read(actual));
assertArrayEquals("First sentence.", expected, actual);
assertSame("Expected cached value.", in, connection.getStorageAs(Reader.class));
in.reset();
assertInstanceOf("Needs the SIS implementation.", ChannelImageInputStream.class, im);
im.mark();
assertEquals("First 4 bytes", MAGIC_NUMBER, im.readInt());
im.reset();
assertNotSame("Expected a new Reader instance.", in, in2);
assertEquals("Number of characters read.", expected.length, in.read(actual));
assertArrayEquals("First sentence.", expected, actual);
assertSame("Expected cached value.", in2, connection.getStorageAs(Reader.class));
connection.closeAllExcept(null);

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

/**
 * Validates the current {@linkplain #transform transform}. This method verifies that
 * the transform implements {@link MathTransform1D} or {@link MathTransform2D} if the
 * transform dimension suggests that it should. In addition, all Apache SIS transforms
 * shall implement {@link Parameterized}.
 *
 * @see Validators#validate(MathTransform)
 */
protected final void validate() {
  assertNotNull("The 'transform' field shall be assigned a value.", transform);
  Validators.validate(transform);
  final int dimension = transform.getSourceDimensions();
  if (transform.getTargetDimensions() == dimension) {
    assertEquals("transform instanceof MathTransform1D:", (transform instanceof MathTransform1D), dimension == 1);
    assertEquals("transform instanceof MathTransform2D:", (transform instanceof MathTransform2D), dimension == 2);
  } else {
    assertFalse("transform instanceof MathTransform1D:", transform instanceof MathTransform1D);
    assertFalse("transform instanceof MathTransform2D:", transform instanceof MathTransform2D);
  }
  assertInstanceOf("The transform does not implement all expected interfaces.", Parameterized.class, transform);
}

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

/**
 * Tests the {@link ValueMap#entrySet()} method for the same metadata than {@link #testEntrySet()},
 * but asking for all non-null and non-nil entries including the empty collections.
 */
@Test
@DependsOnMethod("testEntrySet")
public void testEntrySetForNonNil() {
  final Map<String,Object> map = createCitation();
  final Map<String,Object> all = MetadataStandard.ISO_19115.asValueMap(citation,
      null, KeyNamePolicy.JAVABEANS_PROPERTY, ValueExistencePolicy.NON_NIL);
  assertFalse("Null values shall be excluded.", map.containsKey("alternateTitles"));
  assertTrue ("Null values shall be included.", all.containsKey("alternateTitles"));
  assertFalse("Nil objects shall be excluded.", map.containsKey("edition"));
  assertFalse("Nil objects shall be excluded.", all.containsKey("edition"));
  assertTrue ("'all' shall be a larger map than 'map'.", all.entrySet().containsAll(map.entrySet()));
  assertFalse("'all' shall be a larger map than 'map'.", map.entrySet().containsAll(all.entrySet()));
  assertArrayEquals(new SimpleEntry<?,?>[] {
    new SimpleEntry<>("title",                   title),
    new SimpleEntry<>("alternateTitles",         emptyList()),
    new SimpleEntry<>("dates",                   emptyList()),
    new SimpleEntry<>("identifiers",             citation.getIdentifiers()),
    new SimpleEntry<>("citedResponsibleParties", singletonList(author)),
    new SimpleEntry<>("presentationForms",       emptySet()),
    new SimpleEntry<>("ISBN",                    "9782505004509"),
    new SimpleEntry<>("onlineResources",         emptyList()),
    new SimpleEntry<>("graphics",                emptyList())
  }, all.entrySet().toArray());
}

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

/**
 * Tests {@link Variable#getAttributeValues(String, boolean)}.
 *
 * @throws IOException if an I/O error occurred while opening the file.
 * @throws DataStoreException if a logical error occurred.
 */
@Test
public void testGetAttributes() throws IOException, DataStoreException {
  final Variable[] variables = getVariablesCIP(selectDataset(TestData.NETCDF_4D_PROJECTED));
  Variable variable = variables[6];
  assertEquals("CIP", variable.getName());
  assertArrayEquals("CIP:_FillValue", new Number[] { -1f  }, variable.getAttributeValues("_FillValue", true));
  assertArrayEquals("CIP:_FillValue", new String[] {"-1.0"}, variable.getAttributeValues("_FillValue", false));
  assertArrayEquals("CIP:units",      new String[] {   "%"}, variable.getAttributeValues("units",      false));
  assertArrayEquals("CIP:units",      new Number[] {      }, variable.getAttributeValues("units",      true));
  variable = variables[0];
  assertEquals("grid_mapping_0", variable.getName());
  assertArrayEquals("standard_parallel", new Number[] { 25.f,   25.05f}, variable.getAttributeValues("standard_parallel", true));
  assertArrayEquals("standard_parallel", new String[] {"25.0", "25.05"}, variable.getAttributeValues("standard_parallel", false));
}

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

/**
 * Tests {@link Java2D#createPolyline(int, Vector...)}.
 */
@Test
@Override
public void testCreatePolyline() {
  super.testCreatePolyline();
  assertInstanceOf("geometry", Path2D.class, geometry);
}

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

/**
 * Tests {@link Quantities#castOrCopy(Quantity)}.
 */
@Test
public void testCastOrCopy() {
  Quantity<Length> q = Quantities.create(5, Units.KILOMETRE);
  assertSame(q, Quantities.castOrCopy(q));
  q = new Quantity<Length>() {
    @Override public Number           getValue()                         {return 8;}
    @Override public Unit<Length>     getUnit ()                         {return Units.CENTIMETRE;}
    @Override public Quantity<Length> add     (Quantity<Length> ignored) {return null;}
    @Override public Quantity<Length> subtract(Quantity<Length> ignored) {return null;}
    @Override public Quantity<?>      multiply(Quantity<?>      ignored) {return null;}
    @Override public Quantity<?>      divide  (Quantity<?>      ignored) {return null;}
    @Override public Quantity<Length> multiply(Number           ignored) {return null;}
    @Override public Quantity<Length> divide  (Number           ignored) {return null;}
    @Override public Quantity<?>      inverse ()                         {return null;}
    @Override public Quantity<Length> to      (Unit<Length>     ignored) {return null;}
    @Override public <T extends Quantity<T>> Quantity<T> asType(Class<T> ignored) {return null;}
  };
  final Length c = Quantities.castOrCopy(q);
  assertNotSame(q, c);
  assertEquals("value", 8, c.getValue().doubleValue(), STRICT);
  assertSame  ("unit", Units.CENTIMETRE, c.getUnit());
}

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

validate(scope);
if (scope != null) {
  assertSame("ScopedName: head.scope should be same than scope.", scope, object.head().scope());
    assertNotNull("ScopedName: getParsedNames() can not contain null element.", name);
    assertNotSame("ScopedName: the enclosing scoped name can not be in any parsed name.", object, name);
    assertEquals("ScopedName: inconsistent value of isGlobal().", global, name.scope().isGlobal());
    global = false; // Only the first name may be global.
    validate(name);
mandatory("ScopedName: tail() should not return null.", tail);
if (tail != null) {
  assertEquals("ScopedName: tail() should have one less element than the enclosing scoped name.",
      depth-1, tail.depth());
  assertSame("ScopedName: tip() and tail.tip() should be the same.",
      object.tip(), tail.tip());
  if (parsedNames != null) {
    assertEquals("ScopedName: tail() should be defined as subList(1, depth).",
        parsedNames.subList(1, depth), tail.getParsedNames());
mandatory("ScopedName: the path should not be null.", path);
if (path != null) {
  assertEquals("ScopedName: path() should have one less element than the enclosing scoped name.",
      depth-1, path.depth());
  assertSame("ScopedName: head() and path.head() should be the same.",
      object.head(), path.head());
  if (parsedNames != null) {
    assertEquals("ScopedName: path() should be defined as subList(0, depth-1).",
        parsedNames.subList(0, depth-1), path.getParsedNames());

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

/**
 * Creates a "Geographic 2D to 3D → Geocentric → Affine → Geographic → Geographic 3D to 2D" chain
 * using EPSG or OGC standard operation methods and parameters. This is used for integration tests.
 *
 * @param  factory  the math transform factory to use for creating and concatenating the transform.
 * @return the chain of transforms.
 * @throws FactoryException if an error occurred while creating a transform.
 */
public static MathTransform createDatumShiftForGeographic2D(final MathTransformFactory factory) throws FactoryException {
  final Parameters values = Parameters.castOrWrap(factory.getDefaultParameters("Geocentric translations (geog2D domain)"));
  setTranslation(values);
  setEllipsoids(values, CommonCRS.WGS84.ellipsoid(), CommonCRS.ED50.ellipsoid());
  final MathTransform gt = new GeocentricTranslation().createMathTransform(factory, values);
  assertFalse("isIdentity", gt.isIdentity());
  assertEquals("sourceDimensions", 3, gt.getSourceDimensions());
  assertEquals("targetDimensions", 3, gt.getTargetDimensions());
  assertInstanceOf("Geocentric translation", LinearTransform.class, gt);
  return Geographic3Dto2DTest.createDatumShiftForGeographic2D(factory, gt, values);
}

相关文章