Open
Conversation
- Added comprehensive controller tests (96% coverage) - Added service layer tests (100% coverage) - Enhanced exception handling - Fixed test configuration to avoid database conflicts - Added separate database configurations for test isolation
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Description: This pull request improves the test coverage of the
supplier-apimodule from 51% to 89%. It introduces new unit tests for utility classes, services, and controllers, adds the JaCoCo Maven plugin for code coverage reporting, refines exception handling, and enhances validation logic for CNPJ values.Summary:
File: supplier-api/pom.xml (modified)
prepare-agentandreportgoals to generate coverage reports during the test phase.File: supplier-api/src/main/java/com/example/supplier/GlobalExceptionHandler.java (modified)
RuntimeException. This handler checks for specific error messages (e.g., "Supplier not found") and returns appropriate HTTP status codes (404 NOT FOUNDor500 INTERNAL SERVER ERROR).File: supplier-api/src/main/java/com/example/supplier/util/CodigoUtil.java (modified)
isValidCNPJmethod to include a check for CNPJ values that are all zeros, which are invalid. This improves validation robustness.File: supplier-api/src/test/java/com/example/supplier/controller/SupplierControllerTest.java (added)
SupplierController. These tests cover all major endpoints, includingGET,POST,PUT, andDELETEoperations, as well as edge cases like invalid CNPJ values and non-existent suppliers.File: supplier-api/src/test/java/com/example/supplier/service/SupplierServiceTest.java (added)
SupplierService. These tests validate the service's behavior for creating, updating, retrieving, and deleting suppliers, including handling invalid CNPJ values and non-existent suppliers.File: supplier-api/src/test/java/com/example/supplier/util/CodigoUtilTest.java (added)
CodigoUtilutility class. These tests cover various edge cases for theisValidCNPJmethod, including short, long, negative, and all-zero CNPJ values.Recommendation:
Code Quality:
isValidCNPJmethod to explain the logic behind the validation checks, especially the new check for all-zero CNPJ values. This will improve code readability for future developers.GlobalExceptionHandlerclass, as the indentation of the newhandleRuntimeExceptionmethod is slightly misaligned.Testing:
Documentation:
Explanation of vulnerabilities:
Potential Information Disclosure in Exception Handling:
handleRuntimeExceptionmethod inGlobalExceptionHandlerprints the stack trace of exceptions usinge.printStackTrace(). This could expose sensitive information in production environments.Suggested Fix: Replace
e.printStackTrace()with a logging mechanism that writes to a secure log file. For example:Validation Weakness in
isValidCNPJ:isValidCNPJmethod does not handle cases where the input CNPJ contains non-numeric characters. While this is unlikely due to the method's signature (long cnpj), it is worth considering additional validation for robustness.Suggested Fix: Add a check to ensure the CNPJ string contains only numeric characters before proceeding with validation.
Test Property Source Configuration:
TestPropertySourceannotations in the test classes use an in-memory H2 database with default credentials (username=sa,password=). While this is acceptable for testing, ensure that these credentials are not accidentally used in production environments.Suggested Fix: Add a comment or configuration check to ensure these properties are strictly limited to test environments.
By addressing these recommendations and vulnerabilities, the pull request will achieve higher quality and security standards.