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?

  • A Use a mock framework in the unit test to inject the CalculationService
  • B Instantiate the EmployeeService in the unit test and pass it to the constructor of the CalculationService
  • C Use a mock framework in the unit test to inject the EmployeeService
  • D Use the feature flag in the unit test to disable the calls to the EmployeeService
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!