Copilot commented on code in PR #10506:
URL: https://github.com/apache/cloudstack/pull/10506#discussion_r2371146023


##########
plugins/database/quota/src/test/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImplTest.java:
##########
@@ -892,4 +895,97 @@ public void 
injectUsageTypeVariablesTestReturnInjectedVariables() {
         Assert.assertTrue(formattedVariables.containsValue("accountname"));
         Assert.assertTrue(formattedVariables.containsValue("zonename"));
     }
+
+    @Test
+    public void 
createDummyRecordForEachQuotaTypeIfUsageTypeIsNotInformedTestUsageTypeDifferentFromNullDoNothing()
 {
+        List<QuotaUsageJoinVO> listUsage = new ArrayList<>();
+
+        
quotaResponseBuilderSpy.createDummyRecordForEachQuotaTypeIfUsageTypeIsNotInformed(listUsage,
 1);
+
+        Assert.assertTrue(listUsage.isEmpty());
+    }
+
+    @Test
+    public void 
createDummyRecordForEachQuotaTypeIfUsageTypeIsNotInformedTestUsageTypeIsNullAddDummyForAllQuotaTypes()
 {
+        List<QuotaUsageJoinVO> listUsage = new ArrayList<>();
+        listUsage.add(new QuotaUsageJoinVO());
+
+        
quotaResponseBuilderSpy.createDummyRecordForEachQuotaTypeIfUsageTypeIsNotInformed(listUsage,
 null);
+
+        Assert.assertEquals(QuotaTypes.listQuotaTypes().size() + 1, 
listUsage.size());
+
+        QuotaTypes.listQuotaTypes().entrySet().forEach(entry -> {
+            Assert.assertTrue(listUsage.stream().anyMatch(usage -> 
usage.getUsageType() == entry.getKey() && 
usage.getQuotaUsed().equals(BigDecimal.ZERO)));
+        });
+    }
+
+    private List<QuotaUsageJoinVO> getQuotaUsagesForTest() {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
+        List<QuotaUsageJoinVO> quotaUsages = new ArrayList<>();
+
+        QuotaUsageJoinVO quotaUsage = new QuotaUsageJoinVO();
+        quotaUsage.setAccountId(1l);
+        quotaUsage.setDomainId(2l);
+        quotaUsage.setUsageType(3);
+        quotaUsage.setQuotaUsed(BigDecimal.valueOf(10));
+        try {
+            quotaUsage.setStartDate(sdf.parse("2022-01-01"));
+            quotaUsage.setEndDate(sdf.parse("2022-01-02"));
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        quotaUsages.add(quotaUsage);
+
+        quotaUsage = new QuotaUsageJoinVO();
+        quotaUsage.setAccountId(4l);
+        quotaUsage.setDomainId(5l);
+        quotaUsage.setUsageType(3);
+        quotaUsage.setQuotaUsed(null);
+        try {
+            quotaUsage.setStartDate(sdf.parse("2022-01-03"));
+            quotaUsage.setEndDate(sdf.parse("2022-01-04"));
+        } catch (ParseException e) {
+            e.printStackTrace();

Review Comment:
   Using e.printStackTrace() in test code is not recommended. Consider using a 
proper logging mechanism or re-throwing the exception as a RuntimeException to 
fail the test properly.



##########
plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaStatementCmd.java:
##########
@@ -98,20 +102,22 @@ public void setDomainId(Long domainId) {
     }
 
     public Date getEndDate() {
-        return _responseBuilder.startOfNextDay(endDate == null ? new Date() : 
new Date(endDate.getTime()));
+        return endDate;
     }
 
     public void setEndDate(Date endDate) {
-        this.endDate = endDate == null ? null : new Date(endDate.getTime());
+        this.endDate = endDate;
     }
 
     public Date getStartDate() {
-        return startDate == null ? null : new Date(startDate.getTime());
+        return startDate;
     }
 
-    public void setStartDate(Date startDate) {
-        this.startDate = startDate == null ? null : new 
Date(startDate.getTime());
-    }
+    public void setStartDate(Date startDate) { this.startDate = startDate; }
+
+    public boolean isShowResources() { return showResources; }
+
+    public void setShowResources(boolean showResources) { this.showResources = 
showResources; }

Review Comment:
   Method declarations should be formatted consistently with proper spacing. 
Each method should be on separate lines with proper indentation for better 
readability.
   ```suggestion
       public void setStartDate(Date startDate) {
           this.startDate = startDate;
       }
   
       public boolean isShowResources() {
           return showResources;
       }
   
       public void setShowResources(boolean showResources) {
           this.showResources = showResources;
       }
   ```



##########
plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaStatementCmd.java:
##########
@@ -98,20 +102,22 @@ public void setDomainId(Long domainId) {
     }
 
     public Date getEndDate() {
-        return _responseBuilder.startOfNextDay(endDate == null ? new Date() : 
new Date(endDate.getTime()));
+        return endDate;
     }
 
     public void setEndDate(Date endDate) {
-        this.endDate = endDate == null ? null : new Date(endDate.getTime());
+        this.endDate = endDate;
     }
 
     public Date getStartDate() {
-        return startDate == null ? null : new Date(startDate.getTime());
+        return startDate;
     }
 
-    public void setStartDate(Date startDate) {
-        this.startDate = startDate == null ? null : new 
Date(startDate.getTime());
-    }
+    public void setStartDate(Date startDate) { this.startDate = startDate; }
+
+    public boolean isShowResources() { return showResources; }
+
+    public void setShowResources(boolean showResources) { this.showResources = 
showResources; }

Review Comment:
   Method declarations should be formatted consistently with proper spacing. 
Each method should be on separate lines with proper indentation for better 
readability.
   ```suggestion
       public void setStartDate(Date startDate) {
           this.startDate = startDate;
       }
   
       public boolean isShowResources() {
           return showResources;
       }
   
       public void setShowResources(boolean showResources) {
           this.showResources = showResources;
       }
   ```



##########
plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaStatementCmd.java:
##########
@@ -98,20 +102,22 @@ public void setDomainId(Long domainId) {
     }
 
     public Date getEndDate() {
-        return _responseBuilder.startOfNextDay(endDate == null ? new Date() : 
new Date(endDate.getTime()));
+        return endDate;
     }
 
     public void setEndDate(Date endDate) {
-        this.endDate = endDate == null ? null : new Date(endDate.getTime());
+        this.endDate = endDate;
     }
 
     public Date getStartDate() {
-        return startDate == null ? null : new Date(startDate.getTime());
+        return startDate;
     }
 
-    public void setStartDate(Date startDate) {
-        this.startDate = startDate == null ? null : new 
Date(startDate.getTime());
-    }
+    public void setStartDate(Date startDate) { this.startDate = startDate; }
+
+    public boolean isShowResources() { return showResources; }
+
+    public void setShowResources(boolean showResources) { this.showResources = 
showResources; }

Review Comment:
   Method declarations should be formatted consistently with proper spacing. 
Each method should be on separate lines with proper indentation for better 
readability.
   ```suggestion
       public void setStartDate(Date startDate) {
           this.startDate = startDate;
       }
   
       public boolean isShowResources() {
           return showResources;
       }
   
       public void setShowResources(boolean showResources) {
           this.showResources = showResources;
       }
   ```



##########
plugins/database/quota/src/test/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImplTest.java:
##########
@@ -892,4 +895,97 @@ public void 
injectUsageTypeVariablesTestReturnInjectedVariables() {
         Assert.assertTrue(formattedVariables.containsValue("accountname"));
         Assert.assertTrue(formattedVariables.containsValue("zonename"));
     }
+
+    @Test
+    public void 
createDummyRecordForEachQuotaTypeIfUsageTypeIsNotInformedTestUsageTypeDifferentFromNullDoNothing()
 {
+        List<QuotaUsageJoinVO> listUsage = new ArrayList<>();
+
+        
quotaResponseBuilderSpy.createDummyRecordForEachQuotaTypeIfUsageTypeIsNotInformed(listUsage,
 1);
+
+        Assert.assertTrue(listUsage.isEmpty());
+    }
+
+    @Test
+    public void 
createDummyRecordForEachQuotaTypeIfUsageTypeIsNotInformedTestUsageTypeIsNullAddDummyForAllQuotaTypes()
 {
+        List<QuotaUsageJoinVO> listUsage = new ArrayList<>();
+        listUsage.add(new QuotaUsageJoinVO());
+
+        
quotaResponseBuilderSpy.createDummyRecordForEachQuotaTypeIfUsageTypeIsNotInformed(listUsage,
 null);
+
+        Assert.assertEquals(QuotaTypes.listQuotaTypes().size() + 1, 
listUsage.size());
+
+        QuotaTypes.listQuotaTypes().entrySet().forEach(entry -> {
+            Assert.assertTrue(listUsage.stream().anyMatch(usage -> 
usage.getUsageType() == entry.getKey() && 
usage.getQuotaUsed().equals(BigDecimal.ZERO)));
+        });
+    }
+
+    private List<QuotaUsageJoinVO> getQuotaUsagesForTest() {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
+        List<QuotaUsageJoinVO> quotaUsages = new ArrayList<>();
+
+        QuotaUsageJoinVO quotaUsage = new QuotaUsageJoinVO();
+        quotaUsage.setAccountId(1l);
+        quotaUsage.setDomainId(2l);
+        quotaUsage.setUsageType(3);
+        quotaUsage.setQuotaUsed(BigDecimal.valueOf(10));
+        try {
+            quotaUsage.setStartDate(sdf.parse("2022-01-01"));
+            quotaUsage.setEndDate(sdf.parse("2022-01-02"));
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        quotaUsages.add(quotaUsage);
+
+        quotaUsage = new QuotaUsageJoinVO();
+        quotaUsage.setAccountId(4l);
+        quotaUsage.setDomainId(5l);
+        quotaUsage.setUsageType(3);
+        quotaUsage.setQuotaUsed(null);
+        try {
+            quotaUsage.setStartDate(sdf.parse("2022-01-03"));
+            quotaUsage.setEndDate(sdf.parse("2022-01-04"));
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        quotaUsages.add(quotaUsage);
+
+        quotaUsage = new QuotaUsageJoinVO();
+        quotaUsage.setAccountId(6l);
+        quotaUsage.setDomainId(7l);
+        quotaUsage.setUsageType(3);
+        quotaUsage.setQuotaUsed(BigDecimal.valueOf(5));
+        try {
+            quotaUsage.setStartDate(sdf.parse("2022-01-05"));
+            quotaUsage.setEndDate(sdf.parse("2022-01-06"));
+        } catch (ParseException e) {
+            e.printStackTrace();

Review Comment:
   Using e.printStackTrace() in test code is not recommended. Consider using a 
proper logging mechanism or re-throwing the exception as a RuntimeException to 
fail the test properly.



##########
plugins/database/quota/src/test/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImplTest.java:
##########
@@ -892,4 +895,97 @@ public void 
injectUsageTypeVariablesTestReturnInjectedVariables() {
         Assert.assertTrue(formattedVariables.containsValue("accountname"));
         Assert.assertTrue(formattedVariables.containsValue("zonename"));
     }
+
+    @Test
+    public void 
createDummyRecordForEachQuotaTypeIfUsageTypeIsNotInformedTestUsageTypeDifferentFromNullDoNothing()
 {
+        List<QuotaUsageJoinVO> listUsage = new ArrayList<>();
+
+        
quotaResponseBuilderSpy.createDummyRecordForEachQuotaTypeIfUsageTypeIsNotInformed(listUsage,
 1);
+
+        Assert.assertTrue(listUsage.isEmpty());
+    }
+
+    @Test
+    public void 
createDummyRecordForEachQuotaTypeIfUsageTypeIsNotInformedTestUsageTypeIsNullAddDummyForAllQuotaTypes()
 {
+        List<QuotaUsageJoinVO> listUsage = new ArrayList<>();
+        listUsage.add(new QuotaUsageJoinVO());
+
+        
quotaResponseBuilderSpy.createDummyRecordForEachQuotaTypeIfUsageTypeIsNotInformed(listUsage,
 null);
+
+        Assert.assertEquals(QuotaTypes.listQuotaTypes().size() + 1, 
listUsage.size());
+
+        QuotaTypes.listQuotaTypes().entrySet().forEach(entry -> {
+            Assert.assertTrue(listUsage.stream().anyMatch(usage -> 
usage.getUsageType() == entry.getKey() && 
usage.getQuotaUsed().equals(BigDecimal.ZERO)));
+        });
+    }
+
+    private List<QuotaUsageJoinVO> getQuotaUsagesForTest() {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
+        List<QuotaUsageJoinVO> quotaUsages = new ArrayList<>();
+
+        QuotaUsageJoinVO quotaUsage = new QuotaUsageJoinVO();
+        quotaUsage.setAccountId(1l);
+        quotaUsage.setDomainId(2l);
+        quotaUsage.setUsageType(3);
+        quotaUsage.setQuotaUsed(BigDecimal.valueOf(10));
+        try {
+            quotaUsage.setStartDate(sdf.parse("2022-01-01"));
+            quotaUsage.setEndDate(sdf.parse("2022-01-02"));
+        } catch (ParseException e) {
+            e.printStackTrace();

Review Comment:
   Using e.printStackTrace() in test code is not recommended. Consider using a 
proper logging mechanism or re-throwing the exception as a RuntimeException to 
fail the test properly.



-- 
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