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

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

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

IllegalStateException.getMessage介绍

暂无

代码示例

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. @Test
  2. public void multipleCacheManagerBeans() {
  3. try {
  4. load(MultiCacheManagerConfig.class);
  5. }
  6. catch (IllegalStateException ex) {
  7. assertTrue(ex.getMessage().contains("bean of type CacheManager"));
  8. }
  9. }

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

  1. @Test
  2. public void noCacheManagerBeans() {
  3. try {
  4. load(EmptyConfig.class);
  5. }
  6. catch (IllegalStateException ex) {
  7. assertTrue(ex.getMessage().contains("no bean of type CacheManager"));
  8. }
  9. }

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

  1. private void assertExceptionContains(String msg) throws Exception {
  2. try {
  3. listener.beforeTestMethod(testContext);
  4. fail("Should have thrown an IllegalStateException.");
  5. }
  6. catch (IllegalStateException e) {
  7. // System.err.println(e.getMessage());
  8. assertTrue("Exception message should contain: " + msg, e.getMessage().contains(msg));
  9. }
  10. }

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

  1. @Test
  2. public void noCacheManagerBeans() {
  3. AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
  4. ctx.register(EmptyConfig.class);
  5. try {
  6. ctx.refresh();
  7. }
  8. catch (IllegalStateException ex) {
  9. assertTrue(ex.getMessage().contains("no bean of type CacheManager"));
  10. }
  11. }

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

  1. @Test
  2. public void multipleCacheManagerBeans() {
  3. AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
  4. ctx.register(MultiCacheManagerConfig.class);
  5. try {
  6. ctx.refresh();
  7. }
  8. catch (IllegalStateException ex) {
  9. assertTrue(ex.getMessage().contains("no unique bean of type CacheManager"));
  10. }
  11. }

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

  1. @Test
  2. public void maxSessions() {
  3. IntStream.range(0, 10000).forEach(i -> insertSession());
  4. try {
  5. insertSession();
  6. fail();
  7. }
  8. catch (IllegalStateException ex) {
  9. assertEquals("Max sessions limit reached: 10000", ex.getMessage());
  10. }
  11. }

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

  1. @Test
  2. public void cannotResolveArg() throws Exception {
  3. try {
  4. getInvocable(Integer.class, String.class).invokeForRequest(request, null);
  5. fail("Expected exception");
  6. }
  7. catch (IllegalStateException ex) {
  8. assertTrue(ex.getMessage().contains("Could not resolve parameter [0]"));
  9. }
  10. }

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

  1. @Test
  2. public void testFriendlyErrorOnNoLocationClassMatching() {
  3. AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
  4. try {
  5. pc.matches(ITestBean.class);
  6. fail();
  7. }
  8. catch (IllegalStateException ex) {
  9. assertTrue(ex.getMessage().contains("expression"));
  10. }
  11. }

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

  1. @Test
  2. public void testFriendlyErrorOnNoLocation2ArgMatching() {
  3. AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
  4. try {
  5. pc.matches(getAge, ITestBean.class);
  6. fail();
  7. }
  8. catch (IllegalStateException ex) {
  9. assertTrue(ex.getMessage().contains("expression"));
  10. }
  11. }

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

  1. @Test
  2. public void testFriendlyErrorOnNoLocation3ArgMatching() {
  3. AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
  4. try {
  5. pc.matches(getAge, ITestBean.class, (Object[]) null);
  6. fail();
  7. }
  8. catch (IllegalStateException ex) {
  9. assertTrue(ex.getMessage().contains("expression"));
  10. }
  11. }

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

  1. @Test
  2. public void shouldNotSupportNullConvertibleTypesFromNonConditionalGenericConverter() {
  3. GenericConverter converter = new NonConditionalGenericConverter();
  4. try {
  5. conversionService.addConverter(converter);
  6. fail("Did not throw IllegalStateException");
  7. }
  8. catch (IllegalStateException ex) {
  9. assertEquals("Only conditional converters may return null convertible types", ex.getMessage());
  10. }
  11. }

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

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

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

  1. @Test
  2. public void startAsyncAfterCompleted() throws Exception {
  3. this.asyncRequest.onComplete(new AsyncEvent(new MockAsyncContext(this.request, this.response)));
  4. try {
  5. this.asyncRequest.startAsync();
  6. fail("expected exception");
  7. }
  8. catch (IllegalStateException ex) {
  9. assertEquals("Async processing has already completed", ex.getMessage());
  10. }
  11. }

相关文章