The current situation is likely to be that no one dares to change anything in the code, because it may break unexpectedly. Make sure everyone understands that you are improving the situation: your changes may break the code, but unlike the previous ones, these breakdowns will be found, and as soon as they are found, they will be fixed forever.
However, the next step depends on your experience and your credit with the team. If you want to play it safe, use this code (Java syntax):
Mapper { public static Mapper INSTANCE = new Mapper(); // NEW code protected void doImpl() { // NEW CODE ... code copied from impl()... // OLD code, NEW PLACE } public static void impl() { // OLD code INSTANCE.doImpl(); // NEW code } // OLD code ... }
This is a very simple change that allows you to overwrite INSTANCE from your tests. You do nothing for production code, and by default the code will behave exactly the same as before.
This way you can replace one method at a time. You can stop following this path at any time - each change takes only a couple of minutes, and this is refactoring: the code does exactly what it did before. Since each change is so small and can not break anything, you can replace one method, write all unit tests that you could not write before, rinse, repeat. Finally, if you do not want / do not have to process all static methods, this approach gives you all the freedom of action you could ask for.
In the second step, you can introduce DI or any other technology that will make you happy. The advantage of this approach: when you come to complex changes, you will already have unit tests that protect you.
If you started with DI, you would have to change a lot of code in all places - without proper unit tests that could protect you.
Aaron digulla
source share