Code review and quality improvements across the codebase
...
- Validate apiKey in BaseService and add package-private SendGrid
override constructors so services can be unit-tested with Mockito.
- SendgridApi: make services final, add package-private constructor
for injection, add Javadoc, add getStatistics(int, Aggregation).
- EmailService: validate non-blank from/to/templateId, handle null
templateData, replace magic 202 with HttpURLConnection.HTTP_ACCEPTED,
preserve IOException as cause when wrapping into SendgridException.
- UsageService: tighten exception handling (catch IOException, not
Exception), validate response status before parsing, configure a
Jackson ObjectMapper with JavaTimeModule so LocalDate works,
validate negative days and null Aggregation.
- Add Aggregation enum (DAY/WEEK/MONTH) for the stats endpoint.
- SendgridException: add (String, Throwable) constructor and Javadoc.
- Statistics: migrate date from java.util.Date to java.time.LocalDate.
- pom.xml: declare Jackson annotations and jsr310 explicitly, pin
maven-compiler-plugin and maven-surefire-plugin, add Mockito for
tests.
- Tests: add SendgridApiTest, SendgridExceptionTest, AggregationTest,
BaseServiceTest, EmailServiceTest, UsageServiceTest, MetricsTest,
StatTest. Update StatisticsTest to assert LocalDate values, use
try-with-resources, and use a Charset instead of a string encoding.
Suite grew from 1 to 52 passing tests.
- README: rewrite to document the new API surface, error contract,
build/test instructions, and project layout.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>