| 462 | |
| 463 | #[test] |
| 464 | fn test_panic_exception_string() { |
| 465 | test_utils::JVM_ENV.with(|env| { |
| 466 | use jni::{objects::JString, strings::JavaStr}; |
| 467 | use std::any::Any; |
| 468 | |
| 469 | const STRING_MSG: &'static str = "This is a String"; |
| 470 | let ex = super::JPanicException::new(env, Box::new(STRING_MSG.to_string())).unwrap(); |
| 471 | |
| 472 | { |
| 473 | let any = ex.get().unwrap(); |
| 474 | assert_eq!(*any.downcast_ref::<String>().unwrap(), STRING_MSG); |
| 475 | } |
| 476 | |
| 477 | let msg: JString = env |
| 478 | .call_method(ex.clone(), "getMessage", "()Ljava/lang/String;", &[]) |
| 479 | .unwrap() |
| 480 | .l() |
| 481 | .unwrap() |
| 482 | .into(); |
| 483 | let str = JavaStr::from_env(env, msg).unwrap(); |
| 484 | assert_eq!(str.to_str().unwrap(), STRING_MSG); |
| 485 | |
| 486 | let any: Box<dyn Any + Send> = ex.take().unwrap(); |
| 487 | assert_eq!(*any.downcast::<String>().unwrap(), STRING_MSG); |
| 488 | }); |
| 489 | } |
| 490 | |
| 491 | #[test] |
| 492 | fn test_panic_exception_other() { |