adapting swap_code to mock objects