The rule java:S2325 is targetting only main code, it is not supposed to be executed on test code. You should probably check your analysis parameters, more specifically sonar.sources and sonar.tests.
The Maven scanner should indeed correctly set these properties correctly by default and you should not have to do it by yourself.
Can I ask you to verify your analysis parameters (or analysis context), or share them, anonymized, and double-check that (even if it might sound completely obvious):
The file is correctly placed in a test folder, included in what property sonar.tests defines
There is no override of the property sonar.sources.inclusions which might include test folders?