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

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

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

Assert.fail介绍

[英]Fails a test with no message.
[中]没有消息的测试失败。

代码示例

代码示例来源:origin: spring-projects/spring-framework

private void assertIsCompiled(Expression expression) {
  try {
    Field field = SpelExpression.class.getDeclaredField("compiledAst");
    field.setAccessible(true);
    Object object = field.get(expression);
    assertNotNull(object);
  }
  catch (Exception ex) {
    fail(ex.toString());
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void customInterceptorAppliesWithCheckedException() {
  try {
    this.cs.throwChecked(0L);
    fail("Should have failed");
  }
  catch (RuntimeException e) {
    assertNotNull("missing original exception", e.getCause());
    assertEquals(IOException.class, e.getCause().getClass());
  }
  catch (Exception e) {
    fail("Wrong exception type " + e);
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void negativeCount() {
  try {
    Observable.rangeLong(1L, -1L);
    fail("Should have thrown IllegalArgumentException");
  } catch (IllegalArgumentException ex) {
    assertEquals("count >= 0 required but it was -1", ex.getMessage());
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test(timeout = 5000)
public void blockingFirstTimeout() {
  BlockingFirstSubscriber<Integer> bf = new BlockingFirstSubscriber<Integer>();
  Thread.currentThread().interrupt();
  try {
    bf.blockingGet();
    fail("Should have thrown!");
  } catch (RuntimeException ex) {
    assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void getBeanByTypeRaisesNoSuchBeanDefinitionException() {
  ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
  // attempt to retrieve a bean that does not exist
  Class<?> targetType = Pattern.class;
  try {
    context.getBean(targetType);
    fail("Should have thrown NoSuchBeanDefinitionException");
  }
  catch (NoSuchBeanDefinitionException ex) {
    assertThat(ex.getMessage(), containsString(format("No qualifying bean of type '%s'", targetType.getName())));
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testWithThreeArgsShouldFail() {
  AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean");
  assertNotNull(bean);
  try {
    bean.getThreeArguments("name", 1, 2);
    fail("TestBean does not have a three arg constructor so this should not have worked");
  }
  catch (AbstractMethodError ex) {
  }
}

代码示例来源:origin: ReactiveX/RxJava

public static void assertError(TestObserver<?> to, int index, Class<? extends Throwable> clazz, String message) {
  Throwable ex = to.errors().get(0);
  if (ex instanceof CompositeException) {
    CompositeException ce = (CompositeException) ex;
    List<Throwable> cel = ce.getExceptions();
    assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index)));
    assertEquals(message, cel.get(index).getMessage());
  } else {
    fail(ex.toString() + ": not a CompositeException");
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testNoIterators() {
  CompositeIterator<String> it = new CompositeIterator<>();
  assertFalse(it.hasNext());
  try {
    it.next();
    fail();
  }
  catch (NoSuchElementException ex) {
    // expected
  }
}

代码示例来源:origin: ReactiveX/RxJava

public static void assertError(TestSubscriber<?> ts, int index, Class<? extends Throwable> clazz) {
  Throwable ex = ts.errors().get(0);
  if (ex instanceof CompositeException) {
    CompositeException ce = (CompositeException) ex;
    List<Throwable> cel = ce.getExceptions();
    assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index)));
  } else {
    fail(ex.toString() + ": not a CompositeException");
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void customInterceptorAppliesWithCheckedException() {
  try {
    cs.cacheWithCheckedException("id", true);
    fail("Should have failed");
  }
  catch (RuntimeException e) {
    assertNotNull("missing original exception", e.getCause());
    assertEquals(IOException.class, e.getCause().getClass());
  }
  catch (Exception e) {
    fail("Wrong exception type " + e);
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void countNegative() {
  try {
    Flowable.intervalRange(1, -1, 1, 1, TimeUnit.MILLISECONDS);
    fail("Should have thrown!");
  } catch (IllegalArgumentException ex) {
    assertEquals("count >= 0 required but it was -1", ex.getMessage());
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void blockingGetErrorTimeoutInterrupt() {
  final BlockingMultiObserver<Integer> bmo = new BlockingMultiObserver<Integer>();
  Thread.currentThread().interrupt();
  try {
    bmo.blockingGetError(1, TimeUnit.MINUTES);
    fail("Should have thrown");
  } catch (RuntimeException ex) {
    assertTrue(ex.getCause() instanceof InterruptedException);
  } finally {
    Thread.interrupted();
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void getRequiredProperty() {
  testProperties.put("exists", "xyz");
  assertThat(propertyResolver.getRequiredProperty("exists"), is("xyz"));
  try {
    propertyResolver.getRequiredProperty("bogus");
    fail("expected IllegalStateException");
  }
  catch (IllegalStateException ex) {
    // expected
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testWithThreeArgsShouldFail() {
  AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean");
  assertNotNull(bean);
  try {
    bean.getThreeArguments("name", 1, 2);
    fail("TestBean does not have a three arg constructor so this should not have worked");
  }
  catch (AbstractMethodError ex) {
  }
  assertSame(bean, beanFactory.getBean(BeanConsumer.class).abstractBean);
}

代码示例来源:origin: ReactiveX/RxJava

public static void assertError(TestSubscriber<?> ts, int index, Class<? extends Throwable> clazz, String message) {
  Throwable ex = ts.errors().get(0);
  if (ex instanceof CompositeException) {
    CompositeException ce = (CompositeException) ex;
    List<Throwable> cel = ce.getExceptions();
    assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index)));
    assertEquals(message, cel.get(index).getMessage());
  } else {
    fail(ex.toString() + ": not a CompositeException");
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test  // SPR-16051
public void exceptionAfterSeveralItems() {
  try {
    performGet("/SPR-16051", new HttpHeaders(), String.class).getBody();
    fail();
  }
  catch (Throwable ex) {
    String message = ex.getMessage();
    assertNotNull(message);
    assertTrue("Actual: " + message, message.startsWith("Error while extracting response"));
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void invalidSpan() {
  try {
    Observable.just(1).window(-99, 1, TimeUnit.SECONDS);
    fail("Should have thrown!");
  } catch (IllegalArgumentException ex) {
    assertEquals("timespan > 0 required but it was -99", ex.getMessage());
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void blockingGetDefaultInterrupt() {
  final BlockingMultiObserver<Integer> bmo = new BlockingMultiObserver<Integer>();
  Thread.currentThread().interrupt();
  try {
    bmo.blockingGet(0);
    fail("Should have thrown");
  } catch (RuntimeException ex) {
    assertTrue(ex.getCause() instanceof InterruptedException);
  } finally {
    Thread.interrupted();
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void startAsyncNotSupported() throws Exception {
  this.request.setAsyncSupported(false);
  try {
    this.asyncRequest.startAsync();
    fail("expected exception");
  }
  catch (IllegalStateException ex) {
    assertThat(ex.getMessage(), containsString("Async support must be enabled"));
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void removeAllWithExceptionVetoRemove() {
  Cache cache = getCache(DEFAULT_CACHE);
  Object key = createKey(name.getMethodName());
  cache.put(key, new Object());
  try {
    service.removeAllWithException(false);
    fail("Should have thrown an exception");
  }
  catch (NullPointerException e) {
    // This is what we expect
  }
  assertNotNull(cache.get(key));
}

相关文章