diff options
author | HampusM <hampus@hampusmat.com> | 2023-09-26 19:46:15 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-09-26 19:46:15 +0200 |
commit | fe4255d765d24b3a62094a02d35077a1022887bb (patch) | |
tree | ee47f81339f569ec3b42d56778c9be514cb80ae4 /src/provider | |
parent | 267ab1dc45c7e2cb68d8238c04376a258dcf61c9 (diff) |
test: make unit tests not return Result
Diffstat (limited to 'src/provider')
-rw-r--r-- | src/provider/async.rs | 29 | ||||
-rw-r--r-- | src/provider/blocking.rs | 30 |
2 files changed, 24 insertions, 35 deletions
diff --git a/src/provider/async.rs b/src/provider/async.rs index 2bf7be1..a3db57e 100644 --- a/src/provider/async.rs +++ b/src/provider/async.rs @@ -252,15 +252,13 @@ impl Clone for AsyncFactoryProvider #[cfg(test)] mod tests { - use std::error::Error; - use super::*; use crate::dependency_history::MockDependencyHistory; use crate::di_container::asynchronous::MockAsyncDIContainer; use crate::test_utils::subjects_async; #[tokio::test] - async fn async_transient_type_provider_works() -> Result<(), Box<dyn Error>> + async fn async_transient_type_provider_works() { let transient_type_provider = AsyncTransientTypeProvider::< subjects_async::UserManager, @@ -273,17 +271,16 @@ mod tests matches!( transient_type_provider .provide(&di_container, MockDependencyHistory::new()) - .await?, + .await + .unwrap(), AsyncProvidable::Transient(_) ), "The provided type is not transient" ); - - Ok(()) } #[tokio::test] - async fn async_singleton_provider_works() -> Result<(), Box<dyn Error>> + async fn async_singleton_provider_works() { let singleton_provider = AsyncSingletonProvider::< subjects_async::UserManager, @@ -298,18 +295,17 @@ mod tests matches!( singleton_provider .provide(&di_container, MockDependencyHistory::new()) - .await?, + .await + .unwrap(), AsyncProvidable::Singleton(_) ), "The provided type is not a singleton" ); - - Ok(()) } #[tokio::test] #[cfg(feature = "factory")] - async fn async_factory_provider_works() -> Result<(), Box<dyn Error>> + async fn async_factory_provider_works() { use crate::private::any_factory::AnyThreadsafeFactory; use crate::ptr::ThreadsafeFactoryPtr; @@ -340,7 +336,8 @@ mod tests matches!( factory_provider .provide(&di_container, MockDependencyHistory::new()) - .await?, + .await + .unwrap(), AsyncProvidable::Factory(_) ), "The provided type is not a factory" @@ -350,7 +347,8 @@ mod tests matches!( default_factory_provider .provide(&di_container, MockDependencyHistory::new()) - .await?, + .await + .unwrap(), AsyncProvidable::DefaultFactory(_) ), "The provided type is not a default factory" @@ -360,12 +358,11 @@ mod tests matches!( async_default_factory_provider .provide(&di_container, MockDependencyHistory::new()) - .await?, + .await + .unwrap(), AsyncProvidable::AsyncDefaultFactory(_) ), "The provided type is not a async default factory" ); - - Ok(()) } } diff --git a/src/provider/blocking.rs b/src/provider/blocking.rs index 1533f68..5710a65 100644 --- a/src/provider/blocking.rs +++ b/src/provider/blocking.rs @@ -147,15 +147,13 @@ impl<DIContainerType> IProvider<DIContainerType> for FactoryProvider #[cfg(test)] mod tests { - use std::error::Error; - use super::*; use crate::dependency_history::MockDependencyHistory; use crate::di_container::blocking::MockDIContainer; use crate::test_utils::subjects; #[test] - fn transient_type_provider_works() -> Result<(), Box<dyn Error>> + fn transient_type_provider_works() { let transient_type_provider = TransientTypeProvider::<subjects::UserManager, MockDIContainer>::new(); @@ -166,18 +164,15 @@ mod tests assert!( matches!( - transient_type_provider - .provide(&di_container, dependency_history_mock)?, - Providable::Transient(_) + transient_type_provider.provide(&di_container, dependency_history_mock), + Ok(Providable::Transient(_)) ), "The provided type is not transient" ); - - Ok(()) } #[test] - fn singleton_provider_works() -> Result<(), Box<dyn Error>> + fn singleton_provider_works() { let singleton_provider = SingletonProvider::<subjects::UserManager, MockDIContainer>::new( @@ -189,18 +184,17 @@ mod tests assert!( matches!( singleton_provider - .provide(&di_container, MockDependencyHistory::new())?, + .provide(&di_container, MockDependencyHistory::new()) + .unwrap(), Providable::Singleton(_) ), "The provided type is not a singleton" ); - - Ok(()) } #[test] #[cfg(feature = "factory")] - fn factory_provider_works() -> Result<(), Box<dyn Error>> + fn factory_provider_works() { use crate::private::any_factory::AnyFactory; use crate::ptr::FactoryPtr; @@ -218,8 +212,8 @@ mod tests assert!( matches!( - factory_provider.provide(&di_container, MockDependencyHistory::new())?, - Providable::Factory(_) + factory_provider.provide(&di_container, MockDependencyHistory::new()), + Ok(Providable::Factory(_)) ), "The provided type is not a factory" ); @@ -227,12 +221,10 @@ mod tests assert!( matches!( default_factory_provider - .provide(&di_container, MockDependencyHistory::new())?, - Providable::DefaultFactory(_) + .provide(&di_container, MockDependencyHistory::new()), + Ok(Providable::DefaultFactory(_)) ), "The provided type is not a default factory" ); - - Ok(()) } } |