Hi @nitish_mishra
Don't get confused with unit testing for the AEM component. The code snippet you shared seems to be normal java code and you can easily write the Junits for the same with the help of Junits with the mockito framework. These two are very popular dependencies and ideally, your project should have already used this dependency.
Based on the JUnit version used in the project, you can understand what features you can use in test cases. There are plenty of blogs available, you can refer to this https://www.vogella.com/tutorials/Mockito/article.html
And Just for your information, There is an Open Source project "wcm.io" which provides libraries and extensions for AEM-based applications which give us an easy way to mock things such as resources, AEM pages, OSGi services, and many other things but that can be used when it's required. You can find in-depth detail here https://wcm.io/testing/aem-mock/
Regards,
Arpit Varshney