write unit tests for Defer