Officer who mistook detective for gunman testifies at trial