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

xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 80b796690 [type:refactor] code polish in admin (#3395)
80b796690 is described below

commit 80b79669058684619532ae2bbe3c2e92398799e7
Author: dragon-zhang <[email protected]>
AuthorDate: Thu May 12 13:56:51 2022 +0800

    [type:refactor] code polish in admin (#3395)
    
    * [type:refactor] code polish in admin
    
    * [type:refactor] code polish in admin
    
    * fix testcase
    
    * fix style
---
 .../shenyu/admin/service/impl/RuleServiceImpl.java       |  3 ++-
 .../shenyu/admin/service/impl/SelectorServiceImpl.java   |  1 +
 .../org/apache/shenyu/admin/service/RuleServiceTest.java | 16 +++++++++++-----
 .../apache/shenyu/admin/service/SelectorServiceTest.java |  1 +
 4 files changed, 15 insertions(+), 6 deletions(-)

diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java
index 3681cf32c..7770e367c 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java
@@ -301,6 +301,7 @@ public class RuleServiceImpl implements RuleService {
                         }
                     }
                     return null;
-                }).collect(Collectors.toList());
+                }).filter(Objects::nonNull)
+                .collect(Collectors.toList());
     }
 }
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java
index 2cfe85fa0..c103bfcc6 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java
@@ -440,6 +440,7 @@ public class SelectorServiceImpl implements SelectorService 
{
                     List<ConditionData> conditionDataList = 
ConditionTransfer.INSTANCE.mapToSelectorDOS(selectorConditionMap.get(id));
                     return SelectorDO.transFrom(selectorDO, 
pluginDO.getName(), conditionDataList);
                 })
+                .filter(Objects::nonNull)
                 .collect(Collectors.toList());
     }
     
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java
index f851f9fa8..098923d0b 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/RuleServiceTest.java
@@ -17,6 +17,8 @@
 
 package org.apache.shenyu.admin.service;
 
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shenyu.admin.mapper.DataPermissionMapper;
 import org.apache.shenyu.admin.mapper.PluginMapper;
@@ -58,6 +60,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+import java.util.Optional;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.greaterThan;
@@ -161,13 +164,13 @@ public final class RuleServiceTest {
     @Test
     public void testListAll() {
         publishEvent();
-        checkListAll();
+        checkListAll(null);
     }
 
     @Test
     public void testListAllWithSelectorNull() {
         mockFindSelectorIsNull();
-        checkListAll();
+        checkListAll(0);
     }
 
     private void mockFindSelectorIsNull() {
@@ -178,7 +181,7 @@ public final class RuleServiceTest {
     @Test
     public void testListAllWithPluginNull() {
         mockFindPluginIsNull();
-        checkListAll();
+        checkListAll(0);
     }
 
     private void mockFindPluginIsNull() {
@@ -186,7 +189,7 @@ public final class RuleServiceTest {
         given(this.pluginMapper.selectById("789")).willReturn(null);
     }
 
-    private void checkListAll() {
+    private void checkListAll(final Integer expected) {
         RuleConditionQuery ruleConditionQuery = buildRuleConditionQuery();
         RuleConditionDO ruleCondition = buildRuleConditionDO();
         
given(this.ruleConditionMapper.selectByQuery(ruleConditionQuery)).willReturn(Collections.singletonList(ruleCondition));
@@ -195,7 +198,7 @@ public final class RuleServiceTest {
         given(this.ruleMapper.selectAll()).willReturn(ruleDOList);
         List<RuleData> dataList = this.ruleService.listAll();
         assertNotNull(dataList);
-        assertEquals(ruleDOList.size(), dataList.size());
+        assertEquals(Optional.ofNullable(expected).orElse(ruleDOList.size()), 
dataList.size());
     }
 
     @Test
@@ -231,6 +234,9 @@ public final class RuleServiceTest {
         SelectorDO selectorDO = buildSelectorDO();
         given(this.selectorMapper.selectById("456")).willReturn(selectorDO);
         given(this.pluginMapper.selectById("789")).willReturn(pluginDO);
+        
given(this.selectorMapper.selectByIdSet(Sets.newHashSet("456"))).willReturn(Collections.singletonList(selectorDO));
+        
given(this.pluginMapper.selectByIds(Lists.newArrayList("789"))).willReturn(Collections.singletonList(pluginDO));
+        
given(this.ruleConditionMapper.selectByRuleIdSet(Sets.newHashSet("123"))).willReturn(Collections.singletonList(buildRuleConditionDO()));
     }
 
     private void testRegisterCreate() {
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java
index c229381c9..75e37ee9b 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SelectorServiceTest.java
@@ -205,6 +205,7 @@ public final class SelectorServiceTest {
     public void testListAll() {
         final List<SelectorDO> selectorDOs = buildSelectorDOList();
         given(this.selectorMapper.selectAll()).willReturn(selectorDOs);
+        
given(this.pluginMapper.selectByIds(any())).willReturn(Collections.singletonList(buildPluginDO()));
         List<SelectorData> dataList = this.selectorService.listAll();
         assertNotNull(dataList);
         assertEquals(selectorDOs.size(), dataList.size());

Reply via email to