Saifulhuq01 commented on code in PR #5417:
URL: https://github.com/apache/fineract/pull/5417#discussion_r2759466030


##########
fineract-provider/src/test/java/org/apache/fineract/infrastructure/campaigns/email/service/EmailReadPlatformServiceImplTest.java:
##########
@@ -0,0 +1,107 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.infrastructure.campaigns.email.service;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import 
org.apache.fineract.infrastructure.campaigns.email.domain.EmailMessageStatusType;
+import org.apache.fineract.infrastructure.core.service.PaginationHelper;
+import org.apache.fineract.infrastructure.core.service.SearchParameters;
+import 
org.apache.fineract.infrastructure.core.service.database.DatabaseSpecificSQLGenerator;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
+
+@ExtendWith(MockitoExtension.class)
+class EmailReadPlatformServiceImplTest {
+
+    @Mock
+    private JdbcTemplate jdbcTemplate;
+
+    @Mock
+    private DatabaseSpecificSQLGenerator sqlGenerator;

Review Comment:
   > Please dont mock the `sqlGenerator`. Mocking this makes the tests are 
completely useless...
   > 
   > You can mock the `DatabaseTypeResolver` only... and you can easily test 
for Mysql and Postgres as well.
   > 
   > Please make sure to test for positive test cases, like limit is "10" and 
"1" and for negative where limit is "random text", "-5", "5.6"
   
   Thanks for the detailed feedback, Adam. I have updated the PR with the 
following changes:
   
   Refactoring: EmailReadPlatformServiceImpl now passes the Integer limit 
directly to the helper method instead of concatenating strings. This ensures 
limit is strictly an Integer, preventing injection of random text or floats by 
the compiler itself.
   
   Testing Strategy: I removed the mock for DatabaseSpecificSQLGenerator. The 
new tests use the real generator and mock only the underlying 
DatabaseTypeResolver to simulate database dialects accurately.
   
   Test Coverage: I added comprehensive test cases:
   
   testRetrieveAllPendingWithMySQL: Verifies LIMIT 10 syntax for MySQL.
   
   testRetrieveAllSentWithPostgres: Verifies LIMIT 5 syntax for PostgreSQL.
   
   testRetrieveWithNegativeLimit & testRetrieveWithZeroLimit: Verifies that 
invalid limits (-5, 0) result in no LIMIT clause being appended.
   
   Status: All 5 tests passed locally.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to