3030import com .cloud .utils .db .SearchCriteria .Func ;
3131import com .cloud .utils .db .SearchCriteria .Op ;
3232
33+ import static org .mockito .Mockito .doNothing ;
34+ import static org .mockito .Mockito .spy ;
35+ import static org .mockito .Mockito .any ;
36+
3337
3438public class GroupByTest {
3539
40+ public static GroupBy <SearchBaseExtension , String , String > mockGroupBy1 (final SearchBaseExtension builder ) {
41+ GroupBy <SearchBaseExtension , String , String > mockInstance = spy (new GroupBy (builder ));
42+ mockInstance ._builder = builder ;
43+ doNothing ().when (mockInstance ).init (any (SearchBaseExtension .class ));
44+ return mockInstance ;
45+ }
46+
3647 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) > ? " ;
3748 protected static final DbTestDao dao = new DbTestDao ();
3849 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 {
4253 public void testToSql () {
4354 // Prepare
4455 final StringBuilder sb = new StringBuilder ("BASE" );
45- final GroupByExtension groupBy = new GroupByExtension (new SearchBaseExtension (String .class , String .class ));
56+ // Construct mock object
57+ final GroupBy <SearchBaseExtension , String , String > groupBy = GroupByTest .mockGroupBy1 (new SearchBaseExtension (String .class , String .class ));
4658
4759 final Attribute att = new Attribute ("TEST_TABLE" , "TEST_COLUMN" );
4860 final Attribute att2 = new Attribute ("TEST_TABLE2" , "TEST_COLUMN2" );
@@ -100,17 +112,6 @@ public void testToSqlWithDao() {
100112
101113}
102114
103- class GroupByExtension extends GroupBy <SearchBaseExtension , String , String > {
104-
105- public GroupByExtension (final SearchBaseExtension builder ) {
106- super (builder );
107- _builder = builder ;
108- }
109-
110- @ Override
111- protected void init (final SearchBaseExtension builder ) {
112- }
113- }
114115
115116class SearchBaseExtension extends SearchBase <SearchBaseExtension , String , String >{
116117
0 commit comments