You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by nv...@apache.org on 2021/09/22 15:02:31 UTC

[cloudstack] branch main updated: Refactor GroupByExtension to improve test logic (#5480)

This is an automated email from the ASF dual-hosted git repository.

nvazquez pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/main by this push:
     new 7d5393d  Refactor GroupByExtension to improve test logic (#5480)
7d5393d is described below

commit 7d5393d577b19b74f2643389b99713ce6d398916
Author: wx930910 <wx...@gmail.com>
AuthorDate: Wed Sep 22 11:02:10 2021 -0400

    Refactor GroupByExtension to improve test logic (#5480)
---
 .../test/java/com/cloud/utils/db/GroupByTest.java  | 25 +++++++++++-----------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/framework/db/src/test/java/com/cloud/utils/db/GroupByTest.java b/framework/db/src/test/java/com/cloud/utils/db/GroupByTest.java
index f508746..c47d1d2 100644
--- a/framework/db/src/test/java/com/cloud/utils/db/GroupByTest.java
+++ b/framework/db/src/test/java/com/cloud/utils/db/GroupByTest.java
@@ -30,9 +30,20 @@ import com.cloud.utils.Pair;
 import com.cloud.utils.db.SearchCriteria.Func;
 import com.cloud.utils.db.SearchCriteria.Op;
 
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.any;
+
 
 public class GroupByTest {
 
+    public static GroupBy<SearchBaseExtension, String, String> mockGroupBy1(final SearchBaseExtension builder) {
+        GroupBy<SearchBaseExtension, String, String> mockInstance = spy(new GroupBy(builder));
+        mockInstance._builder = builder;
+        doNothing().when(mockInstance).init(any(SearchBaseExtension.class));
+        return mockInstance;
+    }
+
     protected static final String EXPECTED_QUERY = "BASE GROUP BY FIRST(TEST_TABLE.TEST_COLUMN), MAX(TEST_TABLE.TEST_COLUMN) HAVING COUNT(TEST_TABLE2.TEST_COLUMN2) > ? ";
     protected static final DbTestDao dao = new DbTestDao();
     protected static final String EXPECTED_QUERY_2 = "TEST GROUP BY test.fld_int HAVING SUM(test.fld_long) > ? ";
@@ -42,7 +53,8 @@ public class GroupByTest {
     public void testToSql() {
         // Prepare
         final StringBuilder sb = new StringBuilder("BASE");
-        final GroupByExtension groupBy = new GroupByExtension(new SearchBaseExtension(String.class, String.class));
+        // Construct mock object
+        final GroupBy<SearchBaseExtension, String, String> groupBy = GroupByTest.mockGroupBy1(new SearchBaseExtension(String.class, String.class));
 
         final Attribute att = new Attribute("TEST_TABLE", "TEST_COLUMN");
         final Attribute att2 = new Attribute("TEST_TABLE2", "TEST_COLUMN2");
@@ -100,17 +112,6 @@ public class GroupByTest {
 
 }
 
-class GroupByExtension extends GroupBy<SearchBaseExtension, String, String> {
-
-    public GroupByExtension(final SearchBaseExtension builder) {
-        super(builder);
-        _builder = builder;
-    }
-
-    @Override
-    protected void init(final SearchBaseExtension builder) {
-    }
-}
 
 class SearchBaseExtension extends SearchBase<SearchBaseExtension, String, String>{