Skip to content

Add comprehensive test coverage for Java/Kotlin codebase#45

Open
MannyLama wants to merge 4 commits intomainfrom
claude/increase-java-test-coverage-011CUoZ5SwfxzTDwBd2zPhqJ
Open

Add comprehensive test coverage for Java/Kotlin codebase#45
MannyLama wants to merge 4 commits intomainfrom
claude/increase-java-test-coverage-011CUoZ5SwfxzTDwBd2zPhqJ

Conversation

@MannyLama
Copy link
Contributor

  • Add JaCoCo plugin to pom.xml for test coverage reporting
  • Add ORGANIZATION_NAME to SettingId enum
  • Add extensive unit tests for utility classes:
    • TextUtils: 10 tests covering string manipulation, date formatting, price handling
    • ValidationUtils: 27 tests for PhoneNumber, NIS, CountryCode, KBO, StartEndTime/Date validators
    • UrlUtils: 9 tests for URL parameter appending and encoding
    • Conditionals: 9 tests for WhenNotBlank condition logic
    • ZipUtils: 7 tests for zip file creation
  • Add entity tests:
    • Address: 10 tests for address formatting and properties
    • Payment: 7 tests for payment entity behavior
    • SimplifiedPaymentStatus: 7 tests for enum values
    • Setting: 8 tests for setting entity
    • All enum types: 30+ tests covering BranchStatus, RoleLevel, Sex, BloodGroup, ContactMethodType, etc.
    • RegistrableStatus: 9 tests including companion object logic
  • Add service tests:
    • SettingService: 11 tests covering CRUD operations
    • AlertLogger: 5 tests for alert notification system
  • Add controller tests:
    • SettingController: 6 tests for REST endpoints
  • Add DTO tests:
    • Customer: 8 tests for data class behavior
    • Various DTOs: 12 tests for PaymentUrl, RemoteFile, ContactDTO
  • Add exception tests:
    • NotFoundException: 17 tests for all exception types
    • ImageException: 7 tests for image-related exceptions
    • AlertCode: 4 tests for alert codes
  • Add configuration tests:
    • CustomUserDetails: 11 tests for JWT-based user details

Total: 180+ comprehensive tests covering utilities, entities, services, controllers, DTOs, and exceptions.

- Add JaCoCo plugin to pom.xml for test coverage reporting
- Add ORGANIZATION_NAME to SettingId enum
- Add extensive unit tests for utility classes:
  * TextUtils: 10 tests covering string manipulation, date formatting, price handling
  * ValidationUtils: 27 tests for PhoneNumber, NIS, CountryCode, KBO, StartEndTime/Date validators
  * UrlUtils: 9 tests for URL parameter appending and encoding
  * Conditionals: 9 tests for WhenNotBlank condition logic
  * ZipUtils: 7 tests for zip file creation
- Add entity tests:
  * Address: 10 tests for address formatting and properties
  * Payment: 7 tests for payment entity behavior
  * SimplifiedPaymentStatus: 7 tests for enum values
  * Setting: 8 tests for setting entity
  * All enum types: 30+ tests covering BranchStatus, RoleLevel, Sex, BloodGroup, ContactMethodType, etc.
  * RegistrableStatus: 9 tests including companion object logic
- Add service tests:
  * SettingService: 11 tests covering CRUD operations
  * AlertLogger: 5 tests for alert notification system
- Add controller tests:
  * SettingController: 6 tests for REST endpoints
- Add DTO tests:
  * Customer: 8 tests for data class behavior
  * Various DTOs: 12 tests for PaymentUrl, RemoteFile, ContactDTO
- Add exception tests:
  * NotFoundException: 17 tests for all exception types
  * ImageException: 7 tests for image-related exceptions
  * AlertCode: 4 tests for alert codes
- Add configuration tests:
  * CustomUserDetails: 11 tests for JWT-based user details

Total: 180+ comprehensive tests covering utilities, entities, services, controllers, DTOs, and exceptions.
Removed trivial constructor, enum, and DTO tests (849 lines) and replaced
with comprehensive integration and Spring tests (3253 lines) focusing on
real business logic and database interactions.

Removed Tests:
- AlertCodeTest, CustomerTest, DTOTest - simple constructor tests
- EnumTest, OrganizationEnumTest, SimplifiedPaymentStatusTest - enum value tests
- SettingTest - basic entity tests
- ImageExceptionTest, NotFoundExceptionTest - exception message tests

Added Comprehensive Integration Tests:

Use Case Tests:
- ValidateAndCreateMembershipTest (323 lines, 13 tests)
  * Base price calculation
  * Reduction factor application
  * Sibling reduction logic
  * Period and branch registration limits
  * Time-based pricing restrictions
  * Age and sex-based branch matching
  * Complex pricing scenarios

Service Integration Tests:
- ActivityServiceIntegrationTest (347 lines, 13 tests)
  * Activity lifecycle management
  * Registration limits enforcement
  * Status-based edit restrictions
  * Cancellation with refund handling
- BranchServiceIntegrationTest (282 lines, 7 tests)
  * Branch visibility filtering
  * Age and sex-based matching
  * Property updates and persistence
- NewsItemServiceIntegrationTest (128 lines, 6 tests)
  * Visibility filtering
  * CRUD operations with database
- RoleServiceIntegrationTest (284 lines, 11 tests)
  * Role CRUD with persistence
  * Branch associations
  * External ID handling
- SettingServiceIntegrationTest (161 lines, 12 tests)
  * Database persistence verification
  * Type conversion (String, Double)
  * Update and delete operations

Repository Integration Tests:
- MembershipRepositoryIntegrationTest (276 lines, 8 tests)
  * Custom query methods with real database
  * Period and branch filtering
  * Current membership queries
  * Existence checks
- BranchRepositoryIntegrationTest (330 lines, 7 tests)
  * Calendar association queries
  * Visibility filtering with multiple statuses
  * Age and sex matching logic
  * Status-based filtering

Controller Integration Tests:
- SettingControllerIntegrationTest (153 lines, 9 tests)
  * Spring MVC integration with MockMvc
  * Security role enforcement (@WithMockUser)
  * Public endpoint access
  * Request parameter handling
  * Database state verification

Mapper Integration Tests:
- MapperIntegrationTest (227 lines, 9 tests)
  * MapStruct mapper functionality
  * Entity to DTO bidirectional mapping
  * Data integrity in round-trip conversions
  * Null handling
  * Thread-safety with parallel streams

Entity Business Logic Tests:
- UserEntityTest (261 lines, 12 tests)
  * Age calculation with edge cases
  * Home address resolution
  * Full name generation
  * Staff branch determination
- PayableAndRegistrableTest (198 lines, 13 tests)
  * Inheritance hierarchy verification
  * JSONata expression evaluation for additional pricing
  * Boolean flag defaults and mutations
  * Address and communication settings
- MembershipPeriodTest (283 lines, 10 tests)
  * Branch limit resolution
  * Restriction validation logic
  * Belgian date formatting
  * Multiple restriction scenarios

Test Coverage Improvements:
- Real database integration with H2
- Spring context loading and dependency injection
- Transaction management and rollback
- Complex business logic scenarios
- Edge cases and error handling
- Data persistence verification
- Security and authorization testing

All tests use @IntegrationTEST annotation with proper Spring configuration,
transaction management, and use actual services/repositories instead of mocks
where appropriate for more realistic testing.
Created integration tests for key service classes:
- ActivityRegistrationService (22 tests): registration status, limits, pricing, completion
- MembershipService (14 tests): CRUD operations, branch filtering, period management
- MembershipPeriodService (15 tests): period creation, restrictions, validation
- UserService (17 tests): profile management, search, staff branch association
- OrganizationService (22 tests): owner/certifier management, contact methods, representative
- CalendarService (13 tests): period management, overlap detection, item sharing
- EventService (11 tests): event lifecycle, validation, status transitions
- EventRegistrationService (17 tests): registration creation, JSONata pricing, completion

Total: 131 new integration tests focusing on business logic, database persistence,
complex scenarios, and Spring component integration.
Created comprehensive REST endpoint tests with Spring MockMvc:
- BranchControllerIntegrationTest (17 tests): CRUD operations, security roles, visibility filtering
- NewsItemControllerIntegrationTest (20 tests): CRUD operations, visibility, ordering, security

Tests verify HTTP status codes, JSON responses, security annotations (@public, @OnlyStaff, @onlyadmin),
and proper authorization with @WithMockUser.
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.

2 participants