java.lang.IllegalStateException.getMessage()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(145)

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

IllegalStateException.getMessage介绍

暂无

代码示例

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

@MessageExceptionHandler
public void handleExceptionWithHandlerMethodArg(IllegalStateException ex, HandlerMethod handlerMethod) {
  this.method = "handleExceptionWithHandlerMethodArg";
  this.arguments.put("handlerMethod", handlerMethod);
  assertEquals("my cause", ex.getMessage());
}

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

@Test
void invalidExpressionEvaluationType() {
  String methodName = "nonBooleanOrStringExpression";
  IllegalStateException exception = assertThrows(IllegalStateException.class,
    () -> condition.evaluateExecutionCondition(buildExtensionContext(methodName)));
  Method method = ReflectionUtils.findMethod(getClass(), methodName);
  assertThat(exception.getMessage(),
    is(equalTo("@DisabledIf(\"#{6 * 7}\") on " + method + " must evaluate to a String or a Boolean, not java.lang.Integer")));
}

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

@Test
void unsupportedStringEvaluationValue() {
  String methodName = "stringExpressionThatIsNeitherTrueNorFalse";
  IllegalStateException exception = assertThrows(IllegalStateException.class,
    () -> condition.evaluateExecutionCondition(buildExtensionContext(methodName)));
  Method method = ReflectionUtils.findMethod(getClass(), methodName);
  assertThat(exception.getMessage(),
    is(equalTo("@DisabledIf(\"#{'enigma'}\") on " + method + " must evaluate to \"true\" or \"false\", not \"enigma\"")));
}

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

private void testMetaClass(String xmlFile) {
  // expect the exception we threw in the custom metaclass to show it got invoked
  try {
    ApplicationContext ctx = new ClassPathXmlApplicationContext(xmlFile);
    Calculator calc = (Calculator) ctx.getBean("delegatingCalculator");
    calc.add(1, 2);
    fail("expected IllegalStateException");
  }
  catch (IllegalStateException ex) {
    assertEquals("Gotcha", ex.getMessage());
  }
}

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

private void assertContextConfigEntriesAreNotUnique(Class<?> testClass) {
  try {
    buildContextHierarchyMap(testClass);
    fail("Should throw an IllegalStateException");
  }
  catch (IllegalStateException e) {
    String msg = String.format(
      "The @ContextConfiguration elements configured via @ContextHierarchy in test class [%s] and its superclasses must define unique contexts per hierarchy level.",
      testClass.getName());
    assertEquals(msg, e.getMessage());
  }
}

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

@Test
public void noCacheResolved() {
  Method method = ReflectionUtils.findMethod(SimpleService.class, "noCacheResolved", Object.class);
  try {
    this.simpleService.noCacheResolved(new Object());
    fail("Should have failed, no cache resolved");
  }
  catch (IllegalStateException ex) {
    assertTrue("Reference to the method must be contained in the message", ex.getMessage().contains(method.toString()));
  }
}

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

private void assertExpressionIsBlank(String methodName) {
  IllegalStateException exception = assertThrows(IllegalStateException.class,
    () -> condition.evaluateExecutionCondition(buildExtensionContext(methodName)));
  assertThat(exception.getMessage(), containsString("must not be blank"));
}

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

@Test
public void multipleCacheManagerBeans() {
  try {
    load(MultiCacheManagerConfig.class);
  }
  catch (IllegalStateException ex) {
    assertTrue(ex.getMessage().contains("bean of type CacheManager"));
  }
}

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

@Test
public void noCacheManagerBeans() {
  try {
    load(EmptyConfig.class);
  }
  catch (IllegalStateException ex) {
    assertTrue(ex.getMessage().contains("no bean of type CacheManager"));
  }
}

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

private void assertExceptionContains(String msg) throws Exception {
  try {
    listener.beforeTestMethod(testContext);
    fail("Should have thrown an IllegalStateException.");
  }
  catch (IllegalStateException e) {
    // System.err.println(e.getMessage());
    assertTrue("Exception message should contain: " + msg, e.getMessage().contains(msg));
  }
}

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

@Test
public void noCacheManagerBeans() {
  AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
  ctx.register(EmptyConfig.class);
  try {
    ctx.refresh();
  }
  catch (IllegalStateException ex) {
    assertTrue(ex.getMessage().contains("no bean of type CacheManager"));
  }
}

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

@Test
public void multipleCacheManagerBeans() {
  AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
  ctx.register(MultiCacheManagerConfig.class);
  try {
    ctx.refresh();
  }
  catch (IllegalStateException ex) {
    assertTrue(ex.getMessage().contains("no unique bean of type CacheManager"));
  }
}

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

@Test
public void maxSessions() {
  IntStream.range(0, 10000).forEach(i -> insertSession());
  try {
    insertSession();
    fail();
  }
  catch (IllegalStateException ex) {
    assertEquals("Max sessions limit reached: 10000", ex.getMessage());
  }
}

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

@Test
public void cannotResolveArg() throws Exception {
  try {
    getInvocable(Integer.class, String.class).invokeForRequest(request, null);
    fail("Expected exception");
  }
  catch (IllegalStateException ex) {
    assertTrue(ex.getMessage().contains("Could not resolve parameter [0]"));
  }
}

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

@Test
public void testFriendlyErrorOnNoLocationClassMatching() {
  AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
  try {
    pc.matches(ITestBean.class);
    fail();
  }
  catch (IllegalStateException ex) {
    assertTrue(ex.getMessage().contains("expression"));
  }
}

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

@Test
public void testFriendlyErrorOnNoLocation2ArgMatching() {
  AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
  try {
    pc.matches(getAge, ITestBean.class);
    fail();
  }
  catch (IllegalStateException ex) {
    assertTrue(ex.getMessage().contains("expression"));
  }
}

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

@Test
public void testFriendlyErrorOnNoLocation3ArgMatching() {
  AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
  try {
    pc.matches(getAge, ITestBean.class, (Object[]) null);
    fail();
  }
  catch (IllegalStateException ex) {
    assertTrue(ex.getMessage().contains("expression"));
  }
}

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

@Test
public void shouldNotSupportNullConvertibleTypesFromNonConditionalGenericConverter() {
  GenericConverter converter = new NonConditionalGenericConverter();
  try {
    conversionService.addConverter(converter);
    fail("Did not throw IllegalStateException");
  }
  catch (IllegalStateException ex) {
    assertEquals("Only conditional converters may return null convertible types", ex.getMessage());
  }
}

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

@Test  // Based on SPR-13917 (spring-web)
public void invocationErrorMessage() throws Exception {
  this.resolvers.addResolver(new StubArgumentResolver(double.class));
  try {
    Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0.0)).method();
    invoke(new Handler(), method);
    fail();
  }
  catch (IllegalStateException ex) {
    assertThat(ex.getMessage(), containsString("Illegal argument"));
  }
}

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

@Test
public void startAsyncAfterCompleted() throws Exception {
  this.asyncRequest.onComplete(new AsyncEvent(new MockAsyncContext(this.request, this.response)));
  try {
    this.asyncRequest.startAsync();
    fail("expected exception");
  }
  catch (IllegalStateException ex) {
    assertEquals("Async processing has already completed", ex.getMessage());
  }
}

相关文章