QuestionQ15

Given a scenario, identify how to implement OSGi services and servlets

A developer is working on an AEM application used to calculate an employee's salary. The calculation is performed by an OSGi service named CalculationService. This service class depends on one other service, named EmployeeService.

How should the developer ensure that the critical code in CalculationService receives high unit-test coverage?

Explanation

Unit tests should isolate CalculationService by mocking its EmployeeService dependency. Controlled mock behavior lets tests exercise the calculation logic and its edge cases independently of the dependent service. Adobe’s AEM unit-testing guidance uses Mockito mocks and registers mocked OSGi services so injected dependencies can be controlled during testing.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!