Testicular pain can be due to injury, infection (Epididymitis or Orchitis) or inflammation, testicular torsion -- most common in young men between 10 and 20 years old, excessive bicycle riding, hernia or kidney or ureteric stones.
In your case, infection is an important possibility and should be ruled out. The final diagnosis can only be made after a thorough physical examination including examination of the abdomen, scrotum, testicles and rectum.
Lab investigations like complete blood examination, urine examination, ultrasound lower abdomen and sometimes a urethral swab will help in diagnosis. Treatment will be started thereafter.
I hope it helps. Take care and regards