From fe4255d765d24b3a62094a02d35077a1022887bb Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 26 Sep 2023 19:46:15 +0200 Subject: test: make unit tests not return Result --- src/di_container/asynchronous/binding/builder.rs | 39 ++++++------ src/di_container/asynchronous/mod.rs | 74 +++++++++++------------ src/di_container/blocking/binding/builder.rs | 44 +++++++------- src/di_container/blocking/mod.rs | 75 +++++++++++++----------- src/provider/async.rs | 29 ++++----- src/provider/blocking.rs | 30 ++++------ 6 files changed, 140 insertions(+), 151 deletions(-) (limited to 'src') diff --git a/src/di_container/asynchronous/binding/builder.rs b/src/di_container/asynchronous/binding/builder.rs index acb1c69..db73ad2 100644 --- a/src/di_container/asynchronous/binding/builder.rs +++ b/src/di_container/asynchronous/binding/builder.rs @@ -502,8 +502,6 @@ where #[cfg(test)] mod tests { - use std::error::Error; - use mockall::predicate::eq; use super::*; @@ -512,7 +510,7 @@ mod tests use crate::test_utils::subjects_async; #[tokio::test] - async fn can_bind_to() -> Result<(), Box> + async fn can_bind_to() { let mut di_container_mock = MockAsyncDIContainer::new(); @@ -534,14 +532,15 @@ mod tests MockDependencyHistory::new, ); - binding_builder.to::().await?; - - Ok(()) + binding_builder + .to::() + .await + .unwrap(); } #[tokio::test] #[cfg(feature = "factory")] - async fn can_bind_to_factory() -> Result<(), Box> + async fn can_bind_to_factory() { use crate as syrette; use crate::factory; @@ -584,14 +583,13 @@ mod tests user_manager }) }) - .await?; - - Ok(()) + .await + .unwrap(); } #[tokio::test] #[cfg(feature = "factory")] - async fn can_bind_to_async_factory() -> Result<(), Box> + async fn can_bind_to_async_factory() { use crate::future::BoxFuture; use crate::ptr::TransientPtr; @@ -633,14 +631,13 @@ mod tests user_manager }) }) - .await?; - - Ok(()) + .await + .unwrap(); } #[tokio::test] #[cfg(feature = "factory")] - async fn can_bind_to_default_factory() -> Result<(), Box> + async fn can_bind_to_default_factory() { use syrette_macros::declare_default_factory; @@ -678,14 +675,13 @@ mod tests user_manager }) }) - .await?; - - Ok(()) + .await + .unwrap(); } #[tokio::test] #[cfg(feature = "factory")] - async fn can_bind_to_async_default_factory() -> Result<(), Box> + async fn can_bind_to_async_default_factory() { use syrette_macros::declare_default_factory; @@ -724,8 +720,7 @@ mod tests user_manager }) }) - .await?; - - Ok(()) + .await + .unwrap(); } } diff --git a/src/di_container/asynchronous/mod.rs b/src/di_container/asynchronous/mod.rs index 929e2c0..13d4df0 100644 --- a/src/di_container/asynchronous/mod.rs +++ b/src/di_container/asynchronous/mod.rs @@ -496,15 +496,13 @@ impl AsyncDIContainer #[cfg(test)] mod tests { - use std::error::Error; - use super::*; use crate::ptr::{ThreadsafeSingletonPtr, TransientPtr}; use crate::test_utils::mocks::async_provider::MockAsyncProvider; use crate::test_utils::subjects_async; #[tokio::test] - async fn can_get() -> Result<(), Box> + async fn can_get() { let di_container = AsyncDIContainer::new(); @@ -535,14 +533,14 @@ mod tests di_container .get::() - .await? - .transient()?; - - Ok(()) + .await + .unwrap() + .transient() + .unwrap(); } #[tokio::test] - async fn can_get_named() -> Result<(), Box> + async fn can_get_named() { let di_container = AsyncDIContainer::new(); @@ -573,14 +571,14 @@ mod tests di_container .get_named::("special") - .await? - .transient()?; - - Ok(()) + .await + .unwrap() + .transient() + .unwrap(); } #[tokio::test] - async fn can_get_singleton() -> Result<(), Box> + async fn can_get_singleton() { let di_container = AsyncDIContainer::new(); @@ -615,23 +613,25 @@ mod tests let first_number_rc = di_container .get::() - .await? - .threadsafe_singleton()?; + .await + .unwrap() + .threadsafe_singleton() + .unwrap(); assert_eq!(first_number_rc.get(), 2820); let second_number_rc = di_container .get::() - .await? - .threadsafe_singleton()?; + .await + .unwrap() + .threadsafe_singleton() + .unwrap(); assert_eq!(first_number_rc.as_ref(), second_number_rc.as_ref()); - - Ok(()) } #[tokio::test] - async fn can_get_singleton_named() -> Result<(), Box> + async fn can_get_singleton_named() { let di_container = AsyncDIContainer::new(); @@ -666,24 +666,26 @@ mod tests let first_number_rc = di_container .get_named::("cool") - .await? - .threadsafe_singleton()?; + .await + .unwrap() + .threadsafe_singleton() + .unwrap(); assert_eq!(first_number_rc.get(), 2820); let second_number_rc = di_container .get_named::("cool") - .await? - .threadsafe_singleton()?; + .await + .unwrap() + .threadsafe_singleton() + .unwrap(); assert_eq!(first_number_rc.as_ref(), second_number_rc.as_ref()); - - Ok(()) } #[tokio::test] #[cfg(feature = "factory")] - async fn can_get_factory() -> Result<(), Box> + async fn can_get_factory() { trait IUserManager: Send + Sync { @@ -761,15 +763,15 @@ mod tests di_container .get::() - .await? - .threadsafe_factory()?; - - Ok(()) + .await + .unwrap() + .threadsafe_factory() + .unwrap(); } #[tokio::test] #[cfg(feature = "factory")] - async fn can_get_factory_named() -> Result<(), Box> + async fn can_get_factory_named() { trait IUserManager: Send + Sync { @@ -852,10 +854,10 @@ mod tests di_container .get_named::("special") - .await? - .threadsafe_factory()?; - - Ok(()) + .await + .unwrap() + .threadsafe_factory() + .unwrap(); } #[tokio::test] diff --git a/src/di_container/blocking/binding/builder.rs b/src/di_container/blocking/binding/builder.rs index 6f873d0..cd547d4 100644 --- a/src/di_container/blocking/binding/builder.rs +++ b/src/di_container/blocking/binding/builder.rs @@ -299,8 +299,6 @@ where #[cfg(test)] mod tests { - use std::error::Error; - use mockall::predicate::eq; use super::*; @@ -309,7 +307,7 @@ mod tests use crate::test_utils::subjects; #[test] - fn can_bind_to() -> Result<(), Box> + fn can_bind_to() { let mut mock_di_container = MockDIContainer::new(); @@ -330,14 +328,12 @@ mod tests MockDependencyHistory::new, ); - binding_builder.to::()?; - - Ok(()) + binding_builder.to::().unwrap(); } #[test] #[cfg(feature = "factory")] - fn can_bind_to_factory() -> Result<(), Box> + fn can_bind_to_factory() { use crate as syrette; use crate::factory; @@ -366,21 +362,21 @@ mod tests MockDependencyHistory::new, ); - binding_builder.to_factory(&|_| { - Box::new(move |_num, _text| { - let user_manager: TransientPtr = - TransientPtr::new(subjects::UserManager::new()); + binding_builder + .to_factory(&|_| { + Box::new(move |_num, _text| { + let user_manager: TransientPtr = + TransientPtr::new(subjects::UserManager::new()); - user_manager + user_manager + }) }) - })?; - - Ok(()) + .unwrap(); } #[test] #[cfg(feature = "factory")] - fn can_bind_to_default_factory() -> Result<(), Box> + fn can_bind_to_default_factory() { use syrette_macros::declare_default_factory; @@ -408,15 +404,15 @@ mod tests MockDependencyHistory::new, ); - binding_builder.to_default_factory(&|_| { - Box::new(move || { - let user_manager: TransientPtr = - TransientPtr::new(subjects::UserManager::new()); + binding_builder + .to_default_factory(&|_| { + Box::new(move || { + let user_manager: TransientPtr = + TransientPtr::new(subjects::UserManager::new()); - user_manager + user_manager + }) }) - })?; - - Ok(()) + .unwrap(); } } diff --git a/src/di_container/blocking/mod.rs b/src/di_container/blocking/mod.rs index df6e68c..ce3edca 100644 --- a/src/di_container/blocking/mod.rs +++ b/src/di_container/blocking/mod.rs @@ -388,15 +388,13 @@ impl DIContainer #[cfg(test)] mod tests { - use std::error::Error; - use super::*; use crate::provider::blocking::MockIProvider; use crate::ptr::{SingletonPtr, TransientPtr}; use crate::test_utils::subjects; #[test] - fn can_get() -> Result<(), Box> + fn can_get() { let di_container = DIContainer::new(); @@ -417,14 +415,14 @@ mod tests ); di_container - .get::()? - .transient()?; - - Ok(()) + .get::() + .unwrap() + .transient() + .unwrap(); } #[test] - fn can_get_named() -> Result<(), Box> + fn can_get_named() { let di_container = DIContainer::new(); @@ -445,14 +443,14 @@ mod tests ); di_container - .get_named::("special")? - .transient()?; - - Ok(()) + .get_named::("special") + .unwrap() + .transient() + .unwrap(); } #[test] - fn can_get_singleton() -> Result<(), Box> + fn can_get_singleton() { let di_container = DIContainer::new(); @@ -471,20 +469,25 @@ mod tests .borrow_mut() .set::(BindingOptions::new(), Box::new(mock_provider)); - let first_number_rc = di_container.get::()?.singleton()?; + let first_number_rc = di_container + .get::() + .unwrap() + .singleton() + .unwrap(); assert_eq!(first_number_rc.get(), 2820); - let second_number_rc = - di_container.get::()?.singleton()?; + let second_number_rc = di_container + .get::() + .unwrap() + .singleton() + .unwrap(); assert_eq!(first_number_rc.as_ref(), second_number_rc.as_ref()); - - Ok(()) } #[test] - fn can_get_singleton_named() -> Result<(), Box> + fn can_get_singleton_named() { let di_container = DIContainer::new(); @@ -507,23 +510,25 @@ mod tests ); let first_number_rc = di_container - .get_named::("cool")? - .singleton()?; + .get_named::("cool") + .unwrap() + .singleton() + .unwrap(); assert_eq!(first_number_rc.get(), 2820); let second_number_rc = di_container - .get_named::("cool")? - .singleton()?; + .get_named::("cool") + .unwrap() + .singleton() + .unwrap(); assert_eq!(first_number_rc.as_ref(), second_number_rc.as_ref()); - - Ok(()) } #[test] #[cfg(feature = "factory")] - fn can_get_factory() -> Result<(), Box> + fn can_get_factory() { use crate::private::castable_factory::CastableFactory; use crate::ptr::FactoryPtr; @@ -593,14 +598,16 @@ mod tests .borrow_mut() .set::(BindingOptions::new(), Box::new(mock_provider)); - di_container.get::()?.factory()?; - - Ok(()) + di_container + .get::() + .unwrap() + .factory() + .unwrap(); } #[test] #[cfg(feature = "factory")] - fn can_get_factory_named() -> Result<(), Box> + fn can_get_factory_named() { use crate::private::castable_factory::CastableFactory; use crate::ptr::FactoryPtr; @@ -674,10 +681,10 @@ mod tests ); di_container - .get_named::("special")? - .factory()?; - - Ok(()) + .get_named::("special") + .unwrap() + .factory() + .unwrap(); } #[test] 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> + 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> + 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> + 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 IProvider 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> + fn transient_type_provider_works() { let transient_type_provider = TransientTypeProvider::::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> + fn singleton_provider_works() { let singleton_provider = SingletonProvider::::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> + 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(()) } } -- cgit v1.2.3-18-g5258