To maintain legacy code for a longer period of time, it is best to write automated Unit testing,
This will maintains product quality from the situation where the fresher/ new developer has added code without understanding.In case of UT, we can mock objects instead of testing with real object. I encountered the problem in getting an IP address when wifi and wifi direct is on.
So To solve this problem, I mocked the wifi, wifi direct scenario in UT cases, so that it wont never happen again and if some one is modifying the source code, his source code should pass my testcase,Then only he can submit the source code to repository.