extern crate pseudo; use pseudo::Mock; trait Dependency: Clone { fn greet>(&self, name: S) { println!("Hello, {}", name.as_ref()) } } struct Consumer { dependency: T, } impl Consumer { fn new(dependency: &T) -> Self { Consumer { dependency: dependency.clone(), } } fn greet_everyone>(&self, names: Vec) { for name in names { self.dependency.greet(name) } } } #[derive(Debug, Clone)] struct MockDependency { pub greet: Mock, } impl Dependency for MockDependency { fn greet>(&self, name: S) { self.greet.call(name.as_ref().to_string()) } } impl Default for MockDependency { fn default() -> Self { MockDependency { greet: Mock::default(), } } } fn main() { let mock = MockDependency::default(); let consumer = Consumer::new(&mock); consumer.greet_everyone(vec!["Fido", "Spot", "Princess"]); assert_eq!(mock.greet.num_calls(), 3); assert!(mock.greet.called_with("Fido")); assert!(mock.greet.called_with("Spot")); assert!(mock.greet.called_with("Princess")); }