aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-09-26 19:46:15 +0200
committerHampusM <hampus@hampusmat.com>2023-09-26 19:46:15 +0200
commitfe4255d765d24b3a62094a02d35077a1022887bb (patch)
treeee47f81339f569ec3b42d56778c9be514cb80ae4
parent267ab1dc45c7e2cb68d8238c04376a258dcf61c9 (diff)
test: make unit tests not return Result
-rw-r--r--macros/src/declare_interface_args.rs14
-rw-r--r--macros/src/factory/declare_default_args.rs23
-rw-r--r--macros/src/factory/macro_args.rs8
-rw-r--r--macros/src/factory/type_alias.rs8
-rw-r--r--macros/src/fn_trait.rs9
-rw-r--r--macros/src/injectable/implementation.rs49
-rw-r--r--macros/src/injectable/macro_args.rs42
-rw-r--r--src/di_container/asynchronous/binding/builder.rs39
-rw-r--r--src/di_container/asynchronous/mod.rs74
-rw-r--r--src/di_container/blocking/binding/builder.rs44
-rw-r--r--src/di_container/blocking/mod.rs75
-rw-r--r--src/provider/async.rs29
-rw-r--r--src/provider/blocking.rs30
13 files changed, 199 insertions, 245 deletions
diff --git a/macros/src/declare_interface_args.rs b/macros/src/declare_interface_args.rs
index fea6c7b..6556153 100644
--- a/macros/src/declare_interface_args.rs
+++ b/macros/src/declare_interface_args.rs
@@ -60,8 +60,6 @@ impl Parse for DeclareInterfaceArgs
#[cfg(test)]
mod tests
{
- use std::error::Error;
-
use proc_macro2::Span;
use quote::{format_ident, quote};
use syn::{parse2, Lit, LitBool};
@@ -71,13 +69,13 @@ mod tests
use crate::test_utils;
#[test]
- fn can_parse_with_no_flags() -> Result<(), Box<dyn Error>>
+ fn can_parse_with_no_flags()
{
let input_args = quote! {
Foo -> IFoo
};
- let decl_interface_args = parse2::<DeclareInterfaceArgs>(input_args)?;
+ let decl_interface_args = parse2::<DeclareInterfaceArgs>(input_args).unwrap();
assert_eq!(
decl_interface_args.implementation,
@@ -102,18 +100,16 @@ mod tests
);
assert!(decl_interface_args.flags.is_empty());
-
- Ok(())
}
#[test]
- fn can_parse_with_flags() -> Result<(), Box<dyn Error>>
+ fn can_parse_with_flags()
{
let input_args = quote! {
Foobar -> IFoobar, threadsafe_sharable = true
};
- let decl_interface_args = parse2::<DeclareInterfaceArgs>(input_args)?;
+ let decl_interface_args = parse2::<DeclareInterfaceArgs>(input_args).unwrap();
assert_eq!(
decl_interface_args.implementation,
@@ -147,8 +143,6 @@ mod tests
)))
}])
);
-
- Ok(())
}
#[test]
diff --git a/macros/src/factory/declare_default_args.rs b/macros/src/factory/declare_default_args.rs
index f93d29d..9930f4f 100644
--- a/macros/src/factory/declare_default_args.rs
+++ b/macros/src/factory/declare_default_args.rs
@@ -57,8 +57,6 @@ impl Parse for DeclareDefaultFactoryMacroArgs
#[cfg(test)]
mod tests
{
- use std::error::Error;
-
use proc_macro2::Span;
use quote::{format_ident, quote};
use syn::token::Dyn;
@@ -80,13 +78,14 @@ mod tests
use crate::macro_flag::MacroFlagValue;
#[test]
- fn can_parse_with_interface_only() -> Result<(), Box<dyn Error>>
+ fn can_parse_with_interface_only()
{
let input_args = quote! {
dyn IFoo
};
- let dec_def_fac_args = parse2::<DeclareDefaultFactoryMacroArgs>(input_args)?;
+ let dec_def_fac_args =
+ parse2::<DeclareDefaultFactoryMacroArgs>(input_args).unwrap();
assert_eq!(
dec_def_fac_args.interface,
@@ -108,18 +107,17 @@ mod tests
);
assert!(dec_def_fac_args.flags.is_empty());
-
- Ok(())
}
#[test]
- fn can_parse_with_interface_and_single_flag() -> Result<(), Box<dyn Error>>
+ fn can_parse_with_interface_and_single_flag()
{
let input_args = quote! {
dyn IBar, threadsafe = true
};
- let dec_def_fac_args = parse2::<DeclareDefaultFactoryMacroArgs>(input_args)?;
+ let dec_def_fac_args =
+ parse2::<DeclareDefaultFactoryMacroArgs>(input_args).unwrap();
assert_eq!(
dec_def_fac_args.interface,
@@ -150,18 +148,17 @@ mod tests
)))
}])
);
-
- Ok(())
}
#[test]
- fn can_parse_with_interface_and_multiple_flags() -> Result<(), Box<dyn Error>>
+ fn can_parse_with_interface_and_multiple_flags()
{
let input_args = quote! {
dyn IBar, threadsafe = true, async = false
};
- let dec_def_fac_args = parse2::<DeclareDefaultFactoryMacroArgs>(input_args)?;
+ let dec_def_fac_args =
+ parse2::<DeclareDefaultFactoryMacroArgs>(input_args).unwrap();
assert_eq!(
dec_def_fac_args.interface,
@@ -201,8 +198,6 @@ mod tests
}
])
);
-
- Ok(())
}
#[test]
diff --git a/macros/src/factory/macro_args.rs b/macros/src/factory/macro_args.rs
index 76b29a2..676b412 100644
--- a/macros/src/factory/macro_args.rs
+++ b/macros/src/factory/macro_args.rs
@@ -46,8 +46,6 @@ impl Parse for FactoryMacroArgs
#[cfg(test)]
mod tests
{
- use std::error::Error;
-
use proc_macro2::Span;
use quote::{format_ident, quote};
use syn::{parse2, Lit, LitBool};
@@ -56,13 +54,13 @@ mod tests
use crate::macro_flag::MacroFlagValue;
#[test]
- fn can_parse_with_single_flag() -> Result<(), Box<dyn Error>>
+ fn can_parse_with_single_flag()
{
let input_args = quote! {
threadsafe = true
};
- let factory_macro_args = parse2::<FactoryMacroArgs>(input_args)?;
+ let factory_macro_args = parse2::<FactoryMacroArgs>(input_args).unwrap();
assert_eq!(
factory_macro_args.flags,
@@ -74,8 +72,6 @@ mod tests
)))
}])
);
-
- Ok(())
}
#[test]
diff --git a/macros/src/factory/type_alias.rs b/macros/src/factory/type_alias.rs
index fafcd54..cfa254f 100644
--- a/macros/src/factory/type_alias.rs
+++ b/macros/src/factory/type_alias.rs
@@ -31,8 +31,6 @@ impl Parse for FactoryTypeAlias
#[cfg(test)]
mod tests
{
- use std::error::Error;
-
use quote::{format_ident, quote};
use syn::punctuated::Punctuated;
use syn::token::And;
@@ -42,13 +40,13 @@ mod tests
use crate::test_utils;
#[test]
- fn can_parse() -> Result<(), Box<dyn Error>>
+ fn can_parse()
{
let input_args = quote! {
type FooFactory = dyn Fn(String, &u32) -> Foo;
};
- let factory_type_alias = parse2::<FactoryTypeAlias>(input_args)?;
+ let factory_type_alias = parse2::<FactoryTypeAlias>(input_args).unwrap();
assert_eq!(
factory_type_alias.factory_interface.inputs,
@@ -66,7 +64,5 @@ mod tests
})
])
);
-
- Ok(())
}
}
diff --git a/macros/src/fn_trait.rs b/macros/src/fn_trait.rs
index 31d7d95..0858cca 100644
--- a/macros/src/fn_trait.rs
+++ b/macros/src/fn_trait.rs
@@ -88,8 +88,6 @@ impl ToTokens for FnTrait
#[cfg(test)]
mod tests
{
- use std::error::Error;
-
use quote::{format_ident, quote};
use syn::token::{Dyn, RArrow};
use syn::{parse2, PathSegment};
@@ -98,12 +96,13 @@ mod tests
use crate::test_utils;
#[test]
- fn can_parse_fn_trait() -> Result<(), Box<dyn Error>>
+ fn can_parse_fn_trait()
{
assert_eq!(
parse2::<FnTrait>(quote! {
dyn Fn(String, u32) -> Handle
- })?,
+ })
+ .unwrap(),
FnTrait {
dyn_token: Dyn::default(),
trait_ident: format_ident!("Fn"),
@@ -128,8 +127,6 @@ mod tests
Fn(u32) -> Handle
})
.is_err());
-
- Ok(())
}
#[test]
diff --git a/macros/src/injectable/implementation.rs b/macros/src/injectable/implementation.rs
index b3e57c2..74a907e 100644
--- a/macros/src/injectable/implementation.rs
+++ b/macros/src/injectable/implementation.rs
@@ -870,7 +870,7 @@ mod tests
}
#[test]
- fn can_create_single_get_dep_method_call() -> Result<(), Box<dyn Error>>
+ fn can_create_single_get_dep_method_call()
{
let mut mock_dependency = MockIDependency::new();
@@ -893,10 +893,11 @@ mod tests
InjectableImpl::<MockIDependency>::create_single_get_dep_method_call(
&mock_dependency,
false,
- )?;
+ )
+ .unwrap();
assert_eq!(
- parse2::<Expr>(output)?,
+ parse2::<Expr>(output).unwrap(),
parse2::<Expr>(quote! {
#di_container_var_ident
.get_bound::<Foo>(
@@ -912,14 +913,13 @@ mod tests
reason: err,
dependency_name: "Foo"
})?
- })?
+ })
+ .unwrap()
);
-
- Ok(())
}
#[test]
- fn can_create_single_get_dep_method_call_with_name() -> Result<(), Box<dyn Error>>
+ fn can_create_single_get_dep_method_call_with_name()
{
let mut mock_dependency = MockIDependency::new();
@@ -944,10 +944,11 @@ mod tests
InjectableImpl::<MockIDependency>::create_single_get_dep_method_call(
&mock_dependency,
false,
- )?;
+ )
+ .unwrap();
assert_eq!(
- parse2::<Expr>(output)?,
+ parse2::<Expr>(output).unwrap(),
parse2::<Expr>(quote! {
#di_container_var_ident
.get_bound::<Foo>(
@@ -963,14 +964,13 @@ mod tests
reason: err,
dependency_name: "Foo"
})?
- })?
+ })
+ .unwrap()
);
-
- Ok(())
}
#[test]
- fn can_create_single_get_dep_method_call_async() -> Result<(), Box<dyn Error>>
+ fn can_create_single_get_dep_method_call_async()
{
let mut mock_dependency = MockIDependency::new();
@@ -993,10 +993,11 @@ mod tests
InjectableImpl::<MockIDependency>::create_single_get_dep_method_call(
&mock_dependency,
true,
- )?;
+ )
+ .unwrap();
assert_eq!(
- parse2::<Expr>(output)?,
+ parse2::<Expr>(output).unwrap(),
parse2::<Expr>(quote! {
#di_container_var_ident
.get_bound::<Foo>(
@@ -1013,15 +1014,13 @@ mod tests
reason: err,
dependency_name: "Foo"
})?
- })?
+ })
+ .unwrap()
);
-
- Ok(())
}
#[test]
- fn can_create_single_get_dep_method_call_async_with_name(
- ) -> Result<(), Box<dyn Error>>
+ fn can_create_single_get_dep_method_call_async_with_name()
{
let mut mock_dependency = MockIDependency::new();
@@ -1046,10 +1045,11 @@ mod tests
InjectableImpl::<MockIDependency>::create_single_get_dep_method_call(
&mock_dependency,
true,
- )?;
+ )
+ .unwrap();
assert_eq!(
- parse2::<Expr>(output)?,
+ parse2::<Expr>(output).unwrap(),
parse2::<Expr>(quote! {
#di_container_var_ident
.get_bound::<Foo>(
@@ -1066,9 +1066,8 @@ mod tests
reason: err,
dependency_name: "Foo"
})?
- })?
+ })
+ .unwrap()
);
-
- Ok(())
}
}
diff --git a/macros/src/injectable/macro_args.rs b/macros/src/injectable/macro_args.rs
index ee398fc..719d551 100644
--- a/macros/src/injectable/macro_args.rs
+++ b/macros/src/injectable/macro_args.rs
@@ -111,8 +111,6 @@ pub enum InjectableMacroArgsError
#[cfg(test)]
mod tests
{
- use std::error::Error;
-
use proc_macro2::Span;
use quote::{format_ident, quote};
use syn::{parse2, Lit, LitBool};
@@ -122,13 +120,13 @@ mod tests
use crate::test_utils;
#[test]
- fn can_parse_with_only_interface() -> Result<(), Box<dyn Error>>
+ fn can_parse_with_only_interface()
{
let input_args = quote! {
IFoo
};
- let injectable_macro_args = parse2::<InjectableMacroArgs>(input_args)?;
+ let injectable_macro_args = parse2::<InjectableMacroArgs>(input_args).unwrap();
assert!(matches!(injectable_macro_args.interface, Some(interface)
if interface == TypePath {
@@ -140,31 +138,27 @@ mod tests
));
assert!(injectable_macro_args.flags.is_empty());
-
- Ok(())
}
#[test]
- fn can_parse_with_nothing() -> Result<(), Box<dyn Error>>
+ fn can_parse_with_nothing()
{
let input_args = quote! {};
- let injectable_macro_args = parse2::<InjectableMacroArgs>(input_args)?;
+ let injectable_macro_args = parse2::<InjectableMacroArgs>(input_args).unwrap();
assert!(injectable_macro_args.interface.is_none());
assert!(injectable_macro_args.flags.is_empty());
-
- Ok(())
}
#[test]
- fn can_parse_with_interface_and_flags() -> Result<(), Box<dyn Error>>
+ fn can_parse_with_interface_and_flags()
{
let input_args = quote! {
IFoo, no_doc_hidden = true, async = false
};
- let injectable_macro_args = parse2::<InjectableMacroArgs>(input_args)?;
+ let injectable_macro_args = parse2::<InjectableMacroArgs>(input_args).unwrap();
assert!(matches!(injectable_macro_args.interface, Some(interface)
if interface == TypePath {
@@ -194,18 +188,16 @@ mod tests
}
])
);
-
- Ok(())
}
#[test]
- fn can_parse_with_flags_only() -> Result<(), Box<dyn Error>>
+ fn can_parse_with_flags_only()
{
let input_args = quote! {
async = false, no_declare_concrete_interface = false
};
- let injectable_macro_args = parse2::<InjectableMacroArgs>(input_args)?;
+ let injectable_macro_args = parse2::<InjectableMacroArgs>(input_args).unwrap();
assert!(injectable_macro_args.interface.is_none());
@@ -228,8 +220,6 @@ mod tests
}
])
);
-
- Ok(())
}
#[test]
@@ -257,34 +247,32 @@ mod tests
}
#[test]
- fn check_flags_fail_with_unknown_flag() -> Result<(), Box<dyn Error>>
+ fn check_flags_fail_with_unknown_flag()
{
let input_args = quote! {
IFoo, haha = true, async = false
};
- let injectable_macro_args = parse2::<InjectableMacroArgs>(input_args)?;
+ let injectable_macro_args = parse2::<InjectableMacroArgs>(input_args).unwrap();
assert!(injectable_macro_args.check_flags().is_err());
-
- Ok(())
}
#[test]
- fn check_flags_fail_with_duplicate_flag() -> Result<(), Box<dyn Error>>
+ fn check_flags_fail_with_duplicate_flag()
{
let macro_args = parse2::<InjectableMacroArgs>(quote! {
IFoo, async = false, no_doc_hidden = true, async = false
- })?;
+ })
+ .unwrap();
assert!(macro_args.check_flags().is_err());
let macro_args_two = parse2::<InjectableMacroArgs>(quote! {
IFoo, async = true , no_doc_hidden = true, async = false
- })?;
+ })
+ .unwrap();
assert!(macro_args_two.check_flags().is_err());
-
- Ok(())
}
}
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<dyn Error>>
+ async fn can_bind_to()
{
let mut di_container_mock = MockAsyncDIContainer::new();
@@ -534,14 +532,15 @@ mod tests
MockDependencyHistory::new,
);
- binding_builder.to::<subjects_async::UserManager>().await?;
-
- Ok(())
+ binding_builder
+ .to::<subjects_async::UserManager>()
+ .await
+ .unwrap();
}
#[tokio::test]
#[cfg(feature = "factory")]
- async fn can_bind_to_factory() -> Result<(), Box<dyn Error>>
+ 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<dyn Error>>
+ 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<dyn Error>>
+ 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<dyn Error>>
+ 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<dyn Error>>
+ async fn can_get()
{
let di_container = AsyncDIContainer::new();
@@ -535,14 +533,14 @@ mod tests
di_container
.get::<dyn subjects_async::IUserManager>()
- .await?
- .transient()?;
-
- Ok(())
+ .await
+ .unwrap()
+ .transient()
+ .unwrap();
}
#[tokio::test]
- async fn can_get_named() -> Result<(), Box<dyn Error>>
+ async fn can_get_named()
{
let di_container = AsyncDIContainer::new();
@@ -573,14 +571,14 @@ mod tests
di_container
.get_named::<dyn subjects_async::IUserManager>("special")
- .await?
- .transient()?;
-
- Ok(())
+ .await
+ .unwrap()
+ .transient()
+ .unwrap();
}
#[tokio::test]
- async fn can_get_singleton() -> Result<(), Box<dyn Error>>
+ async fn can_get_singleton()
{
let di_container = AsyncDIContainer::new();
@@ -615,23 +613,25 @@ mod tests
let first_number_rc = di_container
.get::<dyn subjects_async::INumber>()
- .await?
- .threadsafe_singleton()?;
+ .await
+ .unwrap()
+ .threadsafe_singleton()
+ .unwrap();
assert_eq!(first_number_rc.get(), 2820);
let second_number_rc = di_container
.get::<dyn subjects_async::INumber>()
- .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<dyn Error>>
+ 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::<dyn subjects_async::INumber>("cool")
- .await?
- .threadsafe_singleton()?;
+ .await
+ .unwrap()
+ .threadsafe_singleton()
+ .unwrap();
assert_eq!(first_number_rc.get(), 2820);
let second_number_rc = di_container
.get_named::<dyn subjects_async::INumber>("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<dyn Error>>
+ async fn can_get_factory()
{
trait IUserManager: Send + Sync
{
@@ -761,15 +763,15 @@ mod tests
di_container
.get::<IUserManagerFactory>()
- .await?
- .threadsafe_factory()?;
-
- Ok(())
+ .await
+ .unwrap()
+ .threadsafe_factory()
+ .unwrap();
}
#[tokio::test]
#[cfg(feature = "factory")]
- async fn can_get_factory_named() -> Result<(), Box<dyn Error>>
+ async fn can_get_factory_named()
{
trait IUserManager: Send + Sync
{
@@ -852,10 +854,10 @@ mod tests
di_container
.get_named::<IUserManagerFactory>("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<dyn Error>>
+ fn can_bind_to()
{
let mut mock_di_container = MockDIContainer::new();
@@ -330,14 +328,12 @@ mod tests
MockDependencyHistory::new,
);
- binding_builder.to::<subjects::Number>()?;
-
- Ok(())
+ binding_builder.to::<subjects::Number>().unwrap();
}
#[test]
#[cfg(feature = "factory")]
- fn can_bind_to_factory() -> Result<(), Box<dyn Error>>
+ 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<dyn subjects::IUserManager> =
- TransientPtr::new(subjects::UserManager::new());
+ binding_builder
+ .to_factory(&|_| {
+ Box::new(move |_num, _text| {
+ let user_manager: TransientPtr<dyn subjects::IUserManager> =
+ TransientPtr::new(subjects::UserManager::new());
- user_manager
+ user_manager
+ })
})
- })?;
-
- Ok(())
+ .unwrap();
}
#[test]
#[cfg(feature = "factory")]
- fn can_bind_to_default_factory() -> Result<(), Box<dyn Error>>
+ 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<dyn subjects::IUserManager> =
- TransientPtr::new(subjects::UserManager::new());
+ binding_builder
+ .to_default_factory(&|_| {
+ Box::new(move || {
+ let user_manager: TransientPtr<dyn subjects::IUserManager> =
+ 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<dyn Error>>
+ fn can_get()
{
let di_container = DIContainer::new();
@@ -417,14 +415,14 @@ mod tests
);
di_container
- .get::<dyn subjects::IUserManager>()?
- .transient()?;
-
- Ok(())
+ .get::<dyn subjects::IUserManager>()
+ .unwrap()
+ .transient()
+ .unwrap();
}
#[test]
- fn can_get_named() -> Result<(), Box<dyn Error>>
+ fn can_get_named()
{
let di_container = DIContainer::new();
@@ -445,14 +443,14 @@ mod tests
);
di_container
- .get_named::<dyn subjects::IUserManager>("special")?
- .transient()?;
-
- Ok(())
+ .get_named::<dyn subjects::IUserManager>("special")
+ .unwrap()
+ .transient()
+ .unwrap();
}
#[test]
- fn can_get_singleton() -> Result<(), Box<dyn Error>>
+ fn can_get_singleton()
{
let di_container = DIContainer::new();
@@ -471,20 +469,25 @@ mod tests
.borrow_mut()
.set::<dyn subjects::INumber>(BindingOptions::new(), Box::new(mock_provider));
- let first_number_rc = di_container.get::<dyn subjects::INumber>()?.singleton()?;
+ let first_number_rc = di_container
+ .get::<dyn subjects::INumber>()
+ .unwrap()
+ .singleton()
+ .unwrap();
assert_eq!(first_number_rc.get(), 2820);
- let second_number_rc =
- di_container.get::<dyn subjects::INumber>()?.singleton()?;
+ let second_number_rc = di_container
+ .get::<dyn subjects::INumber>()
+ .unwrap()
+ .singleton()
+ .unwrap();
assert_eq!(first_number_rc.as_ref(), second_number_rc.as_ref());
-
- Ok(())
}
#[test]
- fn can_get_singleton_named() -> Result<(), Box<dyn Error>>
+ fn can_get_singleton_named()
{
let di_container = DIContainer::new();
@@ -507,23 +510,25 @@ mod tests
);
let first_number_rc = di_container
- .get_named::<dyn subjects::INumber>("cool")?
- .singleton()?;
+ .get_named::<dyn subjects::INumber>("cool")
+ .unwrap()
+ .singleton()
+ .unwrap();
assert_eq!(first_number_rc.get(), 2820);
let second_number_rc = di_container
- .get_named::<dyn subjects::INumber>("cool")?
- .singleton()?;
+ .get_named::<dyn subjects::INumber>("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<dyn Error>>
+ fn can_get_factory()
{
use crate::private::castable_factory::CastableFactory;
use crate::ptr::FactoryPtr;
@@ -593,14 +598,16 @@ mod tests
.borrow_mut()
.set::<IUserManagerFactory>(BindingOptions::new(), Box::new(mock_provider));
- di_container.get::<IUserManagerFactory>()?.factory()?;
-
- Ok(())
+ di_container
+ .get::<IUserManagerFactory>()
+ .unwrap()
+ .factory()
+ .unwrap();
}
#[test]
#[cfg(feature = "factory")]
- fn can_get_factory_named() -> Result<(), Box<dyn Error>>
+ 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::<IUserManagerFactory>("special")?
- .factory()?;
-
- Ok(())
+ .get_named::<IUserManagerFactory>("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<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(())
}
}