Skip to content

Feature/policy-unit-test#1476

Closed
ds-vlisenco wants to merge 13 commits intoeclipse-tractusx:mainfrom
ds-vlisenco:feature/policy-unit-test
Closed

Feature/policy-unit-test#1476
ds-vlisenco wants to merge 13 commits intoeclipse-tractusx:mainfrom
ds-vlisenco:feature/policy-unit-test

Conversation

@ds-vlisenco
Copy link

Description

feat: Add Unit Tests for the PolicyServiceImpl Class

This PR introduces comprehensive unit tests for the PolicyServiceImpl class in the Traceability backend. The class contains business logic for managing policies and interacts with PolicyRepository and EdcNotificationContractService.

The new tests improve code reliability and ensure correct interaction with the dependent components.

Fixes: [add issue number if applicable]


Pre-Review Checks

Please ensure that the following points are completed:

  • Dependencies checked (Dash License Tool)
  • License header present
  • Project coding standards adhered to

Background

The PolicyServiceImpl class previously lacked dedicated unit tests. The goal is to ensure its correctness and maintainability through full test coverage of all public methods.


Scope

Tested Methods:

  • getIrsPolicies(): Returns the raw data map
  • getPolicies(): Returns a flat list of PolicyResponse
  • getPolicy(String id): Success and failure scenarios (PolicyNotFoundException)
  • createPolicy(RegisterPolicyRequest): Creates policy and updates EDC
  • updatePolicy(UpdatePolicyRequest): Updates policy and updates EDC
  • deletePolicy(String id): Deletes policy and updates EDC

Covered Scenarios:

  • Success cases (Happy Path)
  • Error and edge cases (e.g. null, empty values, missing entries)
  • Interaction with dependent components (Mockito verify)

Test Strategy

  • Test class: PolicyServiceImplTest.java
  • Frameworks: JUnit 5, Mockito
  • Setup: @ExtendWith(MockitoExtension.class)
  • Exception assertions: assertThrows(...)
  • Dependency verification: verify(...)
  • Test coverage: > 90%

Acceptance Criteria

  • PolicyServiceImplTest.java created
  • All public methods of the class are tested
  • Test coverage ≥ 90%
  • Tests cover both normal and error paths
  • All tests pass successfully
  • Code review has been completed

Notes

  • Existing test classes in the project were used as a reference
  • No changes to business logic were made

Added input validation to PolicyServiceImpl#getPolicy to throw IllegalArgumentException
when policy ID is null or blank. This ensures consistent error handling and aligns with
unit test expectations.

Also resolves failing test cases in PolicyServiceImplTest that check for invalid inputs.
Added input validation to PolicyServiceImpl#getPolicy to throw IllegalArgumentException
when policy ID is null or blank. This ensures consistent error handling and aligns with
unit test expectations.

Also resolves failing test cases in PolicyServiceImplTest that check for invalid inputs.
license header is provided
@ds-vlisenco ds-vlisenco deleted the feature/policy-unit-test branch June 25, 2025 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant