refactor mock and stub APIs