When practicing extract and override refactoring, I often examples of very skilled coaches and trainers where the access modifiers of the extracted method is changed from private to protected.
protected CollectResultReader loadRecordFromOutFile() {
return CollectResultReader.factory("../record.json");
}
In the example above the code was extracted, the IDE created a new method with a private modifier in the target code. That is desired behaviour. In order to be able to override the class under test, it was reedited being protected. That is undesired because it means that the production code lost its readeability and gained unwanted access.
Please note that I want to use pure Java and no mocking framework. I keep my Unit Tests in a different path in the same package.
My question: Why not make the method package private (no modifier)?
See the package private modifier in: Controlling Access to Members of a Class