Strengthen tests by checking the correct error code is returned