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

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

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

Assert.fail介绍

暂无

代码示例

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

/**
   * Asserts that we can not get add a date at the given index in the given list.
   */
  private static void assertCanNotAdd(final List<Date> dates, final int index, final Date date) {
    try {
      dates.add(index, date);
      fail("Should not be allowed to add an element at index " + index);
    } catch (IndexOutOfBoundsException e) {
      // This is the expected exception.
    }
  }
}

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

/**
 * Asserts that we can not get a date at the given index in the given list.
 */
private static void assertCanNotGet(final List<Date> dates, final int index) {
  try {
    dates.get(index);
    fail("Should not be allowed to get an element at index " + index);
  } catch (IndexOutOfBoundsException e) {
    // This is the expected exception.
  }
}

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

/**
 * Implementation of {@link #testAddWrongType()}, also shared by {@link #testAddWrongTypeToSublist()}.
 * Returns the exception message.
 */
@SuppressWarnings({"unchecked","rawtypes"})
private static String testAddWrongType(final List list) {
  try {
    list.add(Integer.valueOf(4));
    fail("Shall not be allowed to add an integer to the list.");
    return null;
  } catch (ClassCastException e) {
    return e.getMessage();
  }
}

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

/**
 * Asserts that the message of the given exception contains the given axis direction.
 */
private static void assertMessageContainsDirection(final Throwable e, final AxisDirection direction) {
  final String message = e.getMessage();
  final String label = Types.getCodeTitle(direction).toString();
  if (!message.contains(label)) {
    fail("Direction \"" + label + "\" not found in error message: " + message);
  }
}

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

/**
 * Ensures that the static constant is immutable.
 */
@Test
public void testImmutability() {
  try {
    Colors.DEFAULT.setName(ElementKind.METHOD, "blue");
    fail("Constant shall be immutable.");
  } catch (UnsupportedOperationException e) {
    // This is the expected exception.
    final String message = e.getMessage();
    assertTrue(message, message.contains("Colors"));
  }
}

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

/**
 * Tries to convert an unconvertible value.
 */
private static void tryUnconvertibleValue(final ObjectConverter<String,?> c) {
  try {
    c.apply("他の言葉");
    fail("Should not accept a text.");
  } catch (UnconvertibleObjectException e) {
    // This is the expected exception.
    assertTrue(e.getMessage().contains("他の言葉"));
  }
}

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

/**
 * Tries to convert a value which is expected to fail.
 */
private static <S extends Number> void tryUnconvertibleValue(final ObjectConverter<S,?> c, final S source) {
  try {
    c.apply(source);
    fail("Should not accept the value.");
  } catch (UnconvertibleObjectException e) {
    // This is the expected exception.
    assertTrue(e.getMessage().contains(c.getTargetClass().getSimpleName()));
  }
}

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

/**
 * Ensures that the current converters is also registered for the given target class.
 * The given target may not be the same than the {@link ObjectConverter#getTargetClass()}.
 *
 * @param  targetClass  the target class to ensure that the converter is registered for.
 */
private void assertSameConverterForTarget(final Class<?> targetClass) {
  final ObjectConverter<?,?> converter = converters.peekLast();
  final Class<?> sourceClass = converter.getSourceClass();
  final ObjectConverter<?,?> actual;
  try {
    actual = registry.find(sourceClass, targetClass);
  } catch (UnconvertibleObjectException e) {
    fail("Converter ‘" + converter + "‛ was expected to be applicable to ‘" +
        targetClass.getSimpleName() + "‛ but got " + e);
    return;
  }
  assertSame("Same converter shall be applicable to other target.", converter, actual);
}

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

/**
 * Tests {@link MetadataStandard#getInterface(Class)} for an invalid type.
 * A {@link ClassCastException} is expected.
 */
@Test
@DependsOnMethod("testGetInterface")
public void testGetWrongInterface() {
  standard = new MetadataStandard("SIS", "org.apache.sis.dummy.", null);
  try {
    getInterface(DefaultCitation.class);
    fail("No dummy interface expected.");
  } catch (ClassCastException e) {
    // This is the expected exception.
    assertTrue(e.getMessage().contains("DefaultCitation"));
  }
}

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

/**
 * Ensures that the native code correctly detects the case of index out of bounds.
 * This is important in order to ensure that we don't have a JVM crash.
 *
 * @throws FactoryException if the Proj.4 definition string used in this test is invalid.
 * @throws TransformException should never happen.
 */
@Test
public void testIndexOutOfBoundsException() throws FactoryException, TransformException {
  final PJ pj = new PJ("+proj=latlong +datum=WGS84");
  try {
    pj.transform(pj, 2, new double[5], 2, 2);
    fail("Expected an exception to be thrown.");
  } catch (IndexOutOfBoundsException e) {
    // This is the expected exception.
  }
}

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

/**
 * Ensures that the native code correctly detects the case of null pointers.
 * This is important in order to ensure that we don't have a JVM crash.
 *
 * @throws FactoryException if the Proj.4 definition string used in this test is invalid.
 * @throws TransformException should never happen.
 */
@Test
public void testNullPointerException() throws FactoryException, TransformException {
  final PJ pj = new PJ("+proj=latlong +datum=WGS84");
  try {
    pj.transform(null, 2, null, 0, 1);
    fail("Expected an exception to be thrown.");
  } catch (NullPointerException e) {
    // This is the expected exception.
  }
}

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

/**
 * Tests that {@link Matrices#createTransform(AxisDirection[], AxisDirection[])}
 * throw an exception if a destination axis is not in the source.
 *
 * <div class="note"><b>Note:</b>
 * {@code Matrices.createTransform(AxisDirection[], AxisDirection[])} needs to be tested with special care,
 * because this method will be the most frequently invoked one when building CRS.</div>
 */
@Test
public void testCreateTransformWithAxisNotInSource() {
  try {
    Matrices.createTransform(
        new AxisDirection[] {NORTH, EAST, UP},
        new AxisDirection[] {DOWN, GEOCENTRIC_X});
    fail("Expected an exception.");
  } catch (IllegalArgumentException e) {
    assertMessageContainsDirection(e, GEOCENTRIC_X);
  }
}

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

/**
 * Tests the {@link org.apache.sis.test.Assert#assertMultilinesEquals(CharSequence, CharSequence)} method.
 */
@Test
public void testAssertEqualsMultilines() {
  // Without trailing spaces.
  assertMultilinesEquals("Line 1\nLine 2\r\nLine 3\n\rLine 5",
              "Line 1\rLine 2\nLine 3\n\nLine 5");
  // With different trailing spaces.
  assertMultilinesEquals("Line 1\nLine 2\r\nLine 3\n\rLine 5",
              "Line 1\rLine 2\nLine 3\n\nLine 5  ");
  // With different leading spaces.
  try {
    assertMultilinesEquals("Line 1\nLine 2\r\nLine 3\n\rLine 5",
                "Line 1\rLine 2\n  Line 3\n\nLine 5");
    fail("Lines are not equal.");
  } catch (AssertionError e) {
    assertTrue(e.getMessage().startsWith("Line[2]"));
  }
}

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

/**
 * Test {@link CRS#forCode(String)} with values that should be invalid.
 *
 * @throws FactoryException if an error other than {@link NoSuchAuthorityCodeException} happened.
 */
@Test
public void testForInvalidCode() throws FactoryException {
  try {
    CRS.forCode("EPSG:4");
    fail("Should not find EPSG:4");
  } catch (NoSuchAuthorityCodeException e) {
    assertEquals("4", e.getAuthorityCode());
  }
}

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

/**
 * Tests non-existent operation method.
 */
@Test
@DependsOnMethod("testGetOperationMethod")
public void testNonExistentCode() {
  final DefaultMathTransformFactory factory = factory();
  try {
    factory.getOperationMethod("EPXX:9624");
    fail("Expected NoSuchIdentifierException");
  } catch (NoSuchIdentifierException e) {
    final String message = e.getLocalizedMessage();
    assertTrue(message, message.contains("EPXX:9624"));
  }
}

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

/**
 * Tests {@link CRS#compound(CoordinateReferenceSystem...)}.
 *
 * @throws FactoryException if an error occurred while creating a compound CRS.
 *
 * @since 0.8
 */
@Test
public void testCompound() throws FactoryException {
  try {
    CRS.compound();
    fail("Should not accept empty array.");
  } catch (IllegalArgumentException e) {
    final String message = e.getMessage();
    assertTrue(message, message.contains("components"));
  }
  assertSame(HardCodedCRS.WGS84, CRS.compound(HardCodedCRS.WGS84));
  assertEqualsIgnoreMetadata(HardCodedCRS.WGS84_3D, CRS.compound(HardCodedCRS.WGS84, HardCodedCRS.ELLIPSOIDAL_HEIGHT));
}

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

/**
 * Tests {@code DefaultParameterValueGroup.values().remove(…)}. In particular, tests that attempt to
 * remove a mandatory parameter causes an {@link InvalidParameterCardinalityException} to be thrown.
 */
@Test
@DependsOnMethod("testValuesAddAll")
public void testValuesRemove() {
  final GeneralParameterValue[]  negatives = createValues(-10);
  final DefaultParameterValueGroup   group = createGroup(10);
  final List<GeneralParameterValue> values = group.values();
  assertFalse(values.remove(negatives[0])); // Non-existant parameter.
  try {
    values.remove(values.get(0));
    fail("“Mandatory 1” is a mandatory parameter; it should not be removeable.");
  } catch (InvalidParameterCardinalityException e) {
    assertEquals("Mandatory 1", e.getParameterName());
    final String message = e.getMessage();
    assertTrue(message, message.contains("Mandatory 1"));
  }
}

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

/**
 * Tests that attempts to add an invalid parameter cause an {@link InvalidParameterNameException} to be thrown.
 */
@Test
@DependsOnMethod("testValuesAdd")
public void testValuesAddWrongParameter() {
  final DefaultParameterValueGroup    group = createGroup(10);
  final List<GeneralParameterValue>  values = group.values();
  final ParameterValue<Integer> nonExistent = new DefaultParameterDescriptor<>(
      singletonMap(NAME_KEY, "Optional 5"), 0, 1, Integer.class, null, null, null).createValue();
  try {
    values.add(nonExistent);
    fail("“Optional 5” is not a parameter for this group.");
  } catch (InvalidParameterNameException e) {
    assertEquals("Optional 5", e.getParameterName());
    final String message = e.getMessage();
    assertTrue(message, message.contains("Optional 5"));
    assertTrue(message, message.contains("Test group"));
  }
}

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

/**
 * Tests that an exception is thrown on attempt to grab a transformation between incompatible vertical CRS.
 *
 * @throws FactoryException if an exception other than the expected one occurred.
 */
@Test
@DependsOnMethod("testIdentityTransform")
public void testIncompatibleVerticalCRS() throws FactoryException {
  final VerticalCRS sourceCRS = CommonCRS.Vertical.NAVD88.crs();
  final VerticalCRS targetCRS = CommonCRS.Vertical.MEAN_SEA_LEVEL.crs();
  try {
    finder.createOperation(sourceCRS, targetCRS);
    fail("The operation should have failed.");
  } catch (OperationNotFoundException e) {
    final String message = e.getMessage();
    assertTrue(message, message.contains("North American Vertical Datum"));
    assertTrue(message, message.contains("Mean Sea Level"));
  }
}

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

/**
 * Ensures that we can not use two properties with the same name.
 */
@Test
@DependsOnMethod("testSimple")
public void testNameCollision() {
  final DefaultAttributeType<String>  city       = new DefaultAttributeType<>(name("name"),       String.class,  1, 1, null);
  final DefaultAttributeType<Integer> cityId     = new DefaultAttributeType<>(name("name"),       Integer.class, 1, 1, null);
  final DefaultAttributeType<Integer> population = new DefaultAttributeType<>(name("population"), Integer.class, 1, 1, null);
  try {
    final Object t = new DefaultFeatureType(name("City"), false, null, city, population, cityId);
    fail("Duplicated attribute names shall not be allowed:\n" + t);
  } catch (IllegalArgumentException e) {
    final String message = e.getMessage();
    assertTrue(message, message.contains("name"));      // Property name.
    assertTrue(message, message.contains("City"));      // Feature name.
  }
}

相关文章