use std::any::Any;
use std::sync::{Arc, Mutex};
use crate::channel::{SendError, Sender};
#[derive(Clone)]
pub struct MockSender<T: Clone> {
sent: Arc<Mutex<Vec<T>>>,
}
impl<T: Clone> Default for MockSender<T> {
fn default() -> Self {
MockSender {
sent: Arc::new(Mutex::new(Vec::new())),
}
}
}
impl<T: Any + Clone + Send> Sender<T> for MockSender<T> {
fn send(&self, message: T) -> Result<(), SendError> {
self.sent.lock().unwrap().push(message);
Ok(())
}
fn box_clone(&self) -> Box<dyn Sender<T>> {
Box::new(MockSender {
sent: self.sent.clone(),
})
}
}