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

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

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

Assert.assertSame介绍

暂无

代码示例

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

/**
 * 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: shall have exactly one parsed name.", 1, parsedNames.size());
    assertSame("LocalName: the parsed name element shall be the enclosing local name.",
        object, parsedNames.get(0));
  }
}

代码示例来源: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: apache/sis

/**
 * Tests the {@link Types#forCodeName(Class, String, boolean)} method.
 */
@Test
public void testForCodeName() {
  assertSame(ImagingCondition.SEMI_DARKNESS, Types.forCodeName(ImagingCondition.class, "SEMI_DARKNESS", false));
  assertSame(ImagingCondition.SEMI_DARKNESS, Types.forCodeName(ImagingCondition.class, "SEMIDARKNESS",  false));
  assertSame(ImagingCondition.SEMI_DARKNESS, Types.forCodeName(ImagingCondition.class, "semi darkness", false));
  assertSame(ImagingCondition.SEMI_DARKNESS, Types.forCodeName(ImagingCondition.class, "semi-darkness", false));
  assertNull(Types.forCodeName(ImagingCondition.class, "darkness", false));
  assertSame(PixelInCell.CELL_CORNER, Types.forCodeName(PixelInCell.class, "cell corner", false));
  assertSame(PixelInCell.CELL_CORNER, Types.forCodeName(PixelInCell.class, "cellCorner",  false));
  assertSame(PixelInCell.CELL_CENTER, Types.forCodeName(PixelInCell.class, "cell center", false));
  assertSame(PixelInCell.CELL_CENTER, Types.forCodeName(PixelInCell.class, "cellCenter",  false));
  if (PENDING_NEXT_GEOAPI_RELEASE) {
    assertSame(PixelInCell.CELL_CENTER, Types.forCodeName(PixelInCell.class, "cell centre", false));
    assertSame(PixelInCell.CELL_CENTER, Types.forCodeName(PixelInCell.class, "cellCentre",  false));
  }
}

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

/**
 * Tests the {@link Types#forEnumName(Class, String)} method with an enumeration from the JDK.
 * Such enumerations do not implement the {@code org.opengis.util.ControlledVocabulary} interface.
 *
 * @since 0.5
 */
@Test
public void testForStandardEnumName() {
  assertSame(ElementType.LOCAL_VARIABLE, Types.forEnumName(ElementType.class, "LOCAL_VARIABLE"));
  assertSame(ElementType.LOCAL_VARIABLE, Types.forEnumName(ElementType.class, "LOCALVARIABLE"));
  assertSame(ElementType.LOCAL_VARIABLE, Types.forEnumName(ElementType.class, "local variable"));
  assertSame(ElementType.LOCAL_VARIABLE, Types.forEnumName(ElementType.class, "local-variable"));
  assertNull(Types.forEnumName(ElementType.class, "variable"));
}

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

/**
 * Asserts that the parameters of current {@linkplain #transform transform} are equal to the given ones.
 * This method can check the descriptor separately, for easier isolation of mismatch in case of failure.
 *
 * @param descriptor
 *          the expected parameter descriptor, or {@code null} for bypassing this check.
 *          The descriptor is required to be strictly the same instance, since Apache SIS
 *          implementation returns constant values.
 * @param values
 *          the expected parameter values, or {@code null} for bypassing this check.
 *          Floating points values are compared in the units of the expected value,
 *          tolerating a difference up to the {@linkplain #tolerance(double) tolerance threshold}.
 */
protected final void assertParameterEquals(final ParameterDescriptorGroup descriptor, final ParameterValueGroup values) {
  assertInstanceOf("The transform does not implement all expected interfaces.", Parameterized.class, transform);
  if (descriptor != null) {
    assertSame("transform.getParameterDescriptors():", descriptor,
        ((Parameterized) transform).getParameterDescriptors());
  }
  if (values != null) {
    assertSame(descriptor, values.getDescriptor());
    ReferencingAssert.assertParameterEquals(values,
        ((Parameterized) transform).getParameterValues(), tolerance);
  }
}

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

/**
 * Tests {@link Quantities#create(double, String)}.
 */
@Test
public void testCreate() {
  final Quantity<?> q = Quantities.create(5, "km");
  assertEquals("value", 5, q.getValue().doubleValue(), STRICT);
  assertSame  ("unit", Units.KILOMETRE, q.getUnit());
}

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

/**
 * Tests <var>x</var> values equal to indices and <var>y</var> values in decreasing order.
 *
 * @throws TransformException if an error occurred while testing a value.
 */
@Test
public void testIndicesToDecreasingValues() throws TransformException {
  preimage = new double[] {0,   1,  2, 3};
  values   = new double[] {35, 27, 22, 5};
  verifyConsistency(-2, 5, 6445394511592290678L);
  assertInstanceOf("Expected y = -f(-i)", ConcatenatedTransformDirect1D.class, transform);
  assertInstanceOf("Expected y = -f(-i)", LinearInterpolator1D.class, ((ConcatenatedTransform) transform).transform1);
  assertSame      ("Expected y = -f(-i)", LinearTransform1D.NEGATE,   ((ConcatenatedTransform) transform).transform2);
}

代码示例来源: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: apache/sis

/**
 * Tests {@link NetcdfStore#getMetadata()}.
 *
 * @throws DataStoreException if an error occurred while reading the netCDF file.
 */
@Test
public void testGetMetadata() throws DataStoreException {
  final Metadata metadata;
  try (NetcdfStore store = create(TestData.NETCDF_2D_GEOGRAPHIC)) {
    metadata = store.getMetadata();
    assertSame("Should be cached.", metadata, store.getMetadata());
  }
  MetadataReaderTest.compareToExpected(metadata);
}

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

/**
   * Tests {@link FrenchProfile#toAFNOR(ReferenceSystem, boolean)}.
   */
  @Test
  public void testReferenceSystemToAFNOR() {
    ReferenceSystem std, fra;

    std = new ReferenceSystemMetadata(new ImmutableIdentifier(null, "EPSG", "4326"));
    fra = FrenchProfile.toAFNOR(std, false);
    assertInstanceOf("Expected AFNOR instance.", DirectReferenceSystem.class, fra);
    assertSame("Already an AFNOR instance.", fra, FrenchProfile.toAFNOR(fra));

    fra = FrenchProfile.toAFNOR(std, true);
    assertInstanceOf("Expected AFNOR instance.", IndirectReferenceSystem.class, fra);
    assertSame("Already an AFNOR instance.", fra, FrenchProfile.toAFNOR(fra));
  }
}

代码示例来源: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 ImageInputStream} type.
 * This is basically a synonymous of {@code getStorageAs(DataInput.class)}.
 *
 * @throws DataStoreException if an error occurred while using the storage connector.
 * @throws IOException if an error occurred while reading the test file.
 */
@Test
@DependsOnMethod("testGetAsDataInputFromURL")
public void testGetAsImageInputStream() throws DataStoreException, IOException {
  final StorageConnector connection = create(false);
  final ImageInputStream in = connection.getStorageAs(ImageInputStream.class);
  assertSame(connection.getStorageAs(DataInput.class), in);
  connection.closeAllExcept(null);
}

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

/**
 * Tests the {@link StorageConnector#getStorageAs(Class)} method for the {@link ByteBuffer} type when
 * the buffer is only temporary. The difference between this test and {@link #testGetAsByteBuffer()} is
 * that the buffer created in this test will not be used for the "real" reading process in the data store.
 * Consequently, it should be a smaller, only temporary, buffer.
 *
 * @throws DataStoreException if an error occurred while using the storage connector.
 * @throws IOException if an error occurred while reading the test file.
 */
@Test
@DependsOnMethod("testGetAsDataInputFromStream")
public void testGetAsTemporaryByteBuffer() throws DataStoreException, IOException {
  StorageConnector connection = create(true);
  final DataInput in = ImageIO.createImageInputStream(connection.getStorage());
  assertNotNull("ImageIO.createImageInputStream(InputStream)", in);                   // Sanity check.
  connection = new StorageConnector(in);
  assertSame(in, connection.getStorageAs(DataInput.class));
  final ByteBuffer buffer = connection.getStorageAs(ByteBuffer.class);
  assertNotNull("getStorageAs(ByteBuffer.class)", buffer);
  assertEquals(StorageConnector.MINIMAL_BUFFER_SIZE, buffer.capacity());
  assertEquals(MAGIC_NUMBER, buffer.getInt());
  connection.closeAllExcept(null);
}

代码示例来源: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

/**
 * Tests {@link ArrayVector} backed by an array of double type.
 */
@Test
public void testDoubleArray() {
  final double[] array = new double[400];
  for (int i=0; i<array.length; i++) {
    array[i] = (i + 100) * 10;
  }
  vector = Vector.create(array, false);
  assertEquals("Doubles", vector.getClass().getSimpleName());
  assertSame(vector, Vector.create(vector, false));
  assertEquals(array.length, vector.size());
  assertEquals(Double.class, vector.getElementType());
  /*
   * Tests element values.
   */
  for (int i=0; i<array.length; i++) {
    assertEquals(array[i], vector.floatValue (i), 0f);
    assertEquals(array[i], vector.doubleValue(i), STRICT);
  }
}

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

/**
 * Tests {@link ArrayVector} backed by an array of float type.
 */
@Test
public void testFloatArray() {
  final float[] array = new float[400];
  for (int i=0; i<array.length; i++) {
    array[i] = (i + 100) * 10;
  }
  vector = Vector.create(array, false);
  assertEquals("Floats", vector.getClass().getSimpleName());
  assertSame(vector, Vector.create(vector, false));
  assertEquals(array.length, vector.size());
  assertEquals(Float.class, vector.getElementType());
  /*
   * Tests element values.
   */
  for (int i=0; i<array.length; i++) {
    assertEquals(array[i], vector.floatValue (i), 0f);
    assertEquals(array[i], vector.doubleValue(i), STRICT);
  }
}

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

/**
 * Tests {@code Types.getCodeTitle(ControlledVocabulary)}.
 * Also opportunistically tests {@link Types#forCodeTitle(CharSequence)}.
 */
@Test
public void testGetCodeTitle() {
  final InternationalString title = Types.getCodeTitle(OnLineFunction.DOWNLOAD);
  assertSame("forCodeTitle", OnLineFunction.DOWNLOAD, Types.forCodeTitle(title));
  assertEquals("Download",       title.toString(Locale.ROOT));
  assertEquals("Download",       title.toString(Locale.ENGLISH));
  assertEquals("Téléchargement", title.toString(Locale.FRENCH));
}

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

/**
   * Tests {@link Store#getMetadata()}.
   *
   * @throws DataStoreException if en error occurred while reading the XML.
   */
  @Test
  public void testMetadata() throws DataStoreException {
    final Metadata metadata;
    try (Store store = new Store(null, new StorageConnector(new StringReader(XML)))) {
      metadata = store.getMetadata();
      assertSame("Expected cached value.", metadata, store.getMetadata());
    }
    final ResponsibleParty resp     = getSingleton(metadata.getContacts());
    final Contact          contact  = resp.getContactInfo();
    final OnlineResource   resource = contact.getOnlineResource();

    assertEquals(Locale.ENGLISH,              metadata.getLanguage());
    if (!REGRESSION)
      assertEquals(CharacterSet.UTF_8,      metadata.getCharacterSet());
    assertEquals(Role.PRINCIPAL_INVESTIGATOR, resp.getRole());
    assertEquals("Apache SIS",                String.valueOf(resp.getOrganisationName()));
    assertEquals("http://sis.apache.org",     String.valueOf(resource.getLinkage()));
    assertEquals(OnLineFunction.INFORMATION,  resource.getFunction());
  }
}

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

/**
   * Tests the {@link FranceGeocentricInterpolation#getOrLoad(Path, double[], double)} method and its cache.
   *
   * @throws URISyntaxException if the URL to the test file can not be converted to a path.
   * @throws FactoryException if an error occurred while computing the grid.
   * @throws TransformException if an error occurred while computing the envelope.
   */
  @Test
  @DependsOnMethod("testGrid")
  public void testGetOrLoad() throws URISyntaxException, FactoryException, TransformException {
    final DatumShiftGridFile<Angle,Length> grid = FranceGeocentricInterpolation.getOrLoad(
        getResource(TEST_FILE), new double[] {
            FranceGeocentricInterpolation.TX,
            FranceGeocentricInterpolation.TY,
            FranceGeocentricInterpolation.TZ},
            FranceGeocentricInterpolation.PRECISION);
    verifyGrid(grid);
    assertSame("Expected a cached value.", grid, FranceGeocentricInterpolation.getOrLoad(
        getResource(TEST_FILE), new double[] {
            FranceGeocentricInterpolation.TX,
            FranceGeocentricInterpolation.TY,
            FranceGeocentricInterpolation.TZ},
            FranceGeocentricInterpolation.PRECISION));
  }
}

代码示例来源: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());
  }
}

相关文章