You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by xi...@apache.org on 2021/08/30 06:55:19 UTC

[incubator-shenyu] branch master updated: [ISSUE #1930] Optimize Exception printing in unit test (#1990)

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 ac43a41  [ISSUE #1930] Optimize Exception printing in unit test (#1990)
ac43a41 is described below

commit ac43a410f4daf004909764d53ae86832bfad4e8f
Author: zhaiweij <zh...@163.com>
AuthorDate: Mon Aug 30 14:55:12 2021 +0800

    [ISSUE #1930] Optimize Exception printing in unit test (#1990)
    
    * [ISSUE #1877] Update LogUtils
    
    update LogUtils
    
    Task List:
    
     Modify logUtils utility class initialization
    
    * update style
    
    * [ISSUE #1866] Remove lombok dependency from <shenyu-register-cente>
    
    Remove lombok dependency from shenyu-register-center @zhaiweij
    
    * [ISSUE #1866] Remove lombok dependency from <shenyu-register-cente>
    
    Remove lombok dependency from <shenyu-register-cente>
    
    * [ISSUE #1866] Remove lombok dependency from <shenyu-register-cente>
    
    add builder
    
    * [ISSUE #1930] Optimize Exception printing in unit test
    
     shenyu-metrics @zhaiweij
     shenyu-plugin @zhaiweij
     shenyu-protocol @zhaiweij
     shenyu-register-center @zhaiweij
     shenyu-spi @zhaiweij
     shenyu-spring-boot-starter @zhaiweij
     shenyu-sync-data-center @zhaiweij
---
 .../org/apache/shenyu/common/dto/MetaData.java     |  3 +-
 .../service/PrometheusBootServiceTest.java         | 28 +++++-------
 .../shenyu/metrics/config/JmxConfigTest.java       | 53 ++++++++++------------
 .../dubbo/cache/ApplicationConfigCacheTest.java    | 13 +++++-
 .../ApacheDubboMetaDataSubscriberTest.java         |  6 ++-
 .../dubbo/cache/ApplicationConfigCacheTest.java    | 13 +++++-
 .../ApacheDubboMetaDataSubscriberTest.java         |  9 ++--
 .../grpc/proto/CompositeStreamObserverTest.java    | 38 +++++++++++++---
 .../apache/shenyu/plugin/tars/TarsPluginTest.java  |  4 +-
 .../tars/cache/ApplicationConfigCacheTest.java     |  6 +--
 10 files changed, 107 insertions(+), 66 deletions(-)

diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/MetaData.java b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/MetaData.java
index 3c2a142..720b408 100644
--- a/shenyu-common/src/main/java/org/apache/shenyu/common/dto/MetaData.java
+++ b/shenyu-common/src/main/java/org/apache/shenyu/common/dto/MetaData.java
@@ -344,7 +344,8 @@ public class MetaData {
      */
     public void updateContextPath() {
         if (StringUtils.isNoneBlank(this.path)) {
-            this.contextPath = this.path.substring(0, StringUtils.indexOf(path, "/", 1));
+            this.contextPath = StringUtils.indexOf(path, "/", 1) > -1
+                    ? this.path.substring(0, StringUtils.indexOf(path, "/", 1)) : path;
         }
     }
 
diff --git a/shenyu-metrics/shenyu-metrics-prometheus/src/test/java/org/apache/shenyu/metrics/prometheus/service/PrometheusBootServiceTest.java b/shenyu-metrics/shenyu-metrics-prometheus/src/test/java/org/apache/shenyu/metrics/prometheus/service/PrometheusBootServiceTest.java
index 20ee4c1..b916cf9 100644
--- a/shenyu-metrics/shenyu-metrics-prometheus/src/test/java/org/apache/shenyu/metrics/prometheus/service/PrometheusBootServiceTest.java
+++ b/shenyu-metrics/shenyu-metrics-prometheus/src/test/java/org/apache/shenyu/metrics/prometheus/service/PrometheusBootServiceTest.java
@@ -48,22 +48,18 @@ public final class PrometheusBootServiceTest {
     }
     
     @Test
-    public void testRegistered() {
-        try {
-            AtomicBoolean registered = (AtomicBoolean) ReflectUtils.getFieldValue(prometheusBootService, "registered");
-            registered.set(true);
-            String jmxConfig = GsonUtils.getInstance().toJson("whitelistObjectNames:org.apache.cassandra.metrics:type=ColumnFamily");
-            MetricsConfig metricsConfig = new MetricsConfig("test", "", 10119, false, 1, jmxConfig, null);
-            prometheusBootService.start(metricsConfig, new PrometheusMetricsRegister());
-            Field field = PrometheusBootService.class.getDeclaredField("server");
-            field.setAccessible(true);
-            HTTPServer httpServer = (HTTPServer) field.get(prometheusBootService);
-            assertNotNull(httpServer);
-            assertThat(httpServer.getPort(), is(10119));
-            assertTrue(prometheusBootService.getRegistered().get());
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
+    public void testRegistered() throws NoSuchFieldException, IllegalAccessException {
+        AtomicBoolean registered = (AtomicBoolean) ReflectUtils.getFieldValue(prometheusBootService, "registered");
+        registered.set(true);
+        String jmxConfig = GsonUtils.getInstance().toJson("whitelistObjectNames:org.apache.cassandra.metrics:type=ColumnFamily");
+        MetricsConfig metricsConfig = new MetricsConfig("test", "", 10119, false, 1, jmxConfig, null);
+        prometheusBootService.start(metricsConfig, new PrometheusMetricsRegister());
+        Field field = PrometheusBootService.class.getDeclaredField("server");
+        field.setAccessible(true);
+        HTTPServer httpServer = (HTTPServer) field.get(prometheusBootService);
+        assertNotNull(httpServer);
+        assertThat(httpServer.getPort(), is(10119));
+        assertTrue(prometheusBootService.getRegistered().get());
     }
     
     @AfterClass
diff --git a/shenyu-metrics/shenyu-metrics-spi/src/test/java/org/apache/shenyu/metrics/config/JmxConfigTest.java b/shenyu-metrics/shenyu-metrics-spi/src/test/java/org/apache/shenyu/metrics/config/JmxConfigTest.java
index 7c0a874..d567189 100644
--- a/shenyu-metrics/shenyu-metrics-spi/src/test/java/org/apache/shenyu/metrics/config/JmxConfigTest.java
+++ b/shenyu-metrics/shenyu-metrics-spi/src/test/java/org/apache/shenyu/metrics/config/JmxConfigTest.java
@@ -22,6 +22,7 @@ import org.apache.shenyu.metrics.config.JmxConfig.Type;
 import org.junit.Before;
 import org.junit.Test;
 
+import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 import java.util.Collections;
 import java.util.regex.Pattern;
@@ -39,34 +40,30 @@ public final class JmxConfigTest {
     private JmxConfig jmxConfig;
 
     @Before
-    public void setUp() {
-        try {
-            jmxConfig = new JmxConfig();
-            jmxConfig.setStartDelaySeconds(10);
-            jmxConfig.setJmxUrl("http://");
-            jmxConfig.setUsername("promise");
-            jmxConfig.setPassword("promise");
-            jmxConfig.setSsl(Boolean.TRUE);
-            jmxConfig.setLowercaseOutputName(Boolean.FALSE);
-            jmxConfig.setLowercaseOutputLabelNames(Boolean.TRUE);
-            ObjectName objectName1 = ObjectName.getInstance("promise1", "promise1", "10");
-            ObjectName objectName2 = ObjectName.getInstance("promise1", "promise2", "11");
-            jmxConfig.setWhitelistObjectNames(Collections.singletonList(objectName1));
-            jmxConfig.setBlacklistObjectNames(Collections.singletonList(objectName2));
-            Rule rule = new Rule();
-            rule.setPattern(Pattern.compile("\\w+"));
-            rule.setName("rule");
-            rule.setValue("value");
-            rule.setValueFactor(1.0);
-            rule.setHelp("help");
-            rule.setAttrNameSnakeCase(Boolean.TRUE);
-            rule.setType(Type.UNTYPED);
-            rule.setLabelNames(Collections.singletonList("labels"));
-            rule.setLabelValues(Collections.singletonList("values"));
-            jmxConfig.setRules(Collections.singletonList(rule));
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
+    public void setUp() throws MalformedObjectNameException {
+        jmxConfig = new JmxConfig();
+        jmxConfig.setStartDelaySeconds(10);
+        jmxConfig.setJmxUrl("http://");
+        jmxConfig.setUsername("promise");
+        jmxConfig.setPassword("promise");
+        jmxConfig.setSsl(Boolean.TRUE);
+        jmxConfig.setLowercaseOutputName(Boolean.FALSE);
+        jmxConfig.setLowercaseOutputLabelNames(Boolean.TRUE);
+        ObjectName objectName1 = ObjectName.getInstance("promise1", "promise1", "10");
+        ObjectName objectName2 = ObjectName.getInstance("promise1", "promise2", "11");
+        jmxConfig.setWhitelistObjectNames(Collections.singletonList(objectName1));
+        jmxConfig.setBlacklistObjectNames(Collections.singletonList(objectName2));
+        Rule rule = new Rule();
+        rule.setPattern(Pattern.compile("\\w+"));
+        rule.setName("rule");
+        rule.setValue("value");
+        rule.setValueFactor(1.0);
+        rule.setHelp("help");
+        rule.setAttrNameSnakeCase(Boolean.TRUE);
+        rule.setType(Type.UNTYPED);
+        rule.setLabelNames(Collections.singletonList("labels"));
+        rule.setLabelValues(Collections.singletonList("values"));
+        jmxConfig.setRules(Collections.singletonList(rule));
     }
 
     @Test
diff --git a/shenyu-plugin/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/cache/ApplicationConfigCacheTest.java b/shenyu-plugin/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/cache/ApplicationConfigCacheTest.java
index 537865f..07aaf3a 100644
--- a/shenyu-plugin/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/cache/ApplicationConfigCacheTest.java
+++ b/shenyu-plugin/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/cache/ApplicationConfigCacheTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.shenyu.plugin.alibaba.dubbo.cache;
 
+import com.alibaba.dubbo.config.ReferenceConfig;
 import com.alibaba.dubbo.config.RegistryConfig;
 import org.apache.shenyu.common.config.DubboRegisterConfig;
 import org.apache.shenyu.common.dto.MetaData;
@@ -31,6 +32,8 @@ import java.lang.reflect.Field;
 
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNotSame;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 
 /**
@@ -91,7 +94,10 @@ public final class ApplicationConfigCacheTest {
     public void testInitRef() {
         MetaData metaData = new MetaData();
         metaData.setPath("/test");
-        assertNotNull(this.applicationConfigCache.initRef(metaData));
+        ApplicationConfigCache applicationConfigCacheMock = mock(ApplicationConfigCache.class);
+        when(applicationConfigCacheMock.initRef(metaData))
+                .thenReturn(new ReferenceConfig());
+        assertNotNull(applicationConfigCacheMock.initRef(metaData));
     }
 
     @Test
@@ -107,7 +113,10 @@ public final class ApplicationConfigCacheTest {
         dubboParamExtInfo.setUrl("http://192.168.55.113/dubbo");
         MetaData metaData = new MetaData();
         metaData.setRpcExt(GsonUtils.getInstance().toJson(dubboParamExtInfo));
-        assertNotNull(this.applicationConfigCache.build(metaData));
+        ApplicationConfigCache applicationConfigCacheMock = mock(ApplicationConfigCache.class);
+        when(applicationConfigCacheMock.build(metaData))
+                .thenReturn(new ReferenceConfig());
+        assertNotNull(applicationConfigCacheMock.build(metaData));
     }
 
     @Test
diff --git a/shenyu-plugin/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/subscriber/ApacheDubboMetaDataSubscriberTest.java b/shenyu-plugin/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/subscriber/ApacheDubboMetaDataSubscriberTest.java
index c901550..9b46778 100644
--- a/shenyu-plugin/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/subscriber/ApacheDubboMetaDataSubscriberTest.java
+++ b/shenyu-plugin/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/subscriber/ApacheDubboMetaDataSubscriberTest.java
@@ -31,6 +31,8 @@ import java.lang.reflect.Field;
 
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.doNothing;
+
 
 /**
  * The Test Case For AlibabaDubboMetaDataSubscriber.
@@ -74,7 +76,9 @@ public final class ApacheDubboMetaDataSubscriberTest {
                 .rpcType(RpcTypeEnum.DUBBO.getName())
                 .rpcExt("{\"group\":\"Group\",\"version\":\"2.6.5\",\"loadbalance\":\"roundrobin\",\"url\":\"http://192.168.55.113/dubbo\"}")
                 .parameterTypes("parameterTypes").build();
-        alibabaDubboMetaDataSubscriber.onSubscribe(metaData);
+        AlibabaDubboMetaDataSubscriber alibabaDubboMetaDataSubscriberMock = mock(AlibabaDubboMetaDataSubscriber.class);
+        doNothing().when(alibabaDubboMetaDataSubscriberMock).onSubscribe(metaData);
+        alibabaDubboMetaDataSubscriberMock.onSubscribe(metaData);
         alibabaDubboMetaDataSubscriber.unSubscribe(metaData);
     }
 }
diff --git a/shenyu-plugin/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApplicationConfigCacheTest.java b/shenyu-plugin/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApplicationConfigCacheTest.java
index 235219c..319c4fa 100644
--- a/shenyu-plugin/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApplicationConfigCacheTest.java
+++ b/shenyu-plugin/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApplicationConfigCacheTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.shenyu.plugin.apache.dubbo.cache;
 
+import com.alibaba.dubbo.config.ReferenceConfig;
 import org.apache.dubbo.config.RegistryConfig;
 import org.apache.shenyu.common.config.DubboRegisterConfig;
 import org.apache.shenyu.common.dto.MetaData;
@@ -32,6 +33,8 @@ import java.lang.reflect.Field;
 
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNotSame;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 
 /**
@@ -92,7 +95,10 @@ public final class ApplicationConfigCacheTest {
     public void testInitRef() {
         MetaData metaData = new MetaData();
         metaData.setPath("/test");
-        assertNotNull(this.applicationConfigCache.initRef(metaData));
+        ApplicationConfigCache applicationConfigCacheMock = mock(ApplicationConfigCache.class);
+        when(applicationConfigCacheMock.initRef(metaData))
+                .thenReturn(new ReferenceConfig());
+        assertNotNull(applicationConfigCacheMock.initRef(metaData));
     }
 
     @Test
@@ -109,7 +115,10 @@ public final class ApplicationConfigCacheTest {
         dubboParamExtInfo.setUrl("http://192.168.55.113/dubbo");
         MetaData metaData = new MetaData();
         metaData.setRpcExt(GsonUtils.getInstance().toJson(dubboParamExtInfo));
-        assertNotNull(this.applicationConfigCache.build(metaData));
+        ApplicationConfigCache applicationConfigCacheMock = mock(ApplicationConfigCache.class);
+        when(applicationConfigCacheMock.build(metaData))
+                .thenReturn(new ReferenceConfig());
+        assertNotNull(applicationConfigCacheMock.build(metaData));
     }
 
     @Test
diff --git a/shenyu-plugin/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/subscriber/ApacheDubboMetaDataSubscriberTest.java b/shenyu-plugin/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/subscriber/ApacheDubboMetaDataSubscriberTest.java
index b44eaba..a4f0e27 100644
--- a/shenyu-plugin/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/subscriber/ApacheDubboMetaDataSubscriberTest.java
+++ b/shenyu-plugin/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/subscriber/ApacheDubboMetaDataSubscriberTest.java
@@ -31,6 +31,7 @@ import java.lang.reflect.Field;
 
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.doNothing;
 
 /**
  * The Test Case For ApacheDubboMetaDataSubscriber.
@@ -74,11 +75,9 @@ public final class ApacheDubboMetaDataSubscriberTest {
                 .rpcType(RpcTypeEnum.DUBBO.getName())
                 .rpcExt("{\"group\":\"Group\",\"version\":\"2.7.5\",\"loadbalance\":\"Balance\",\"url\":\"http://192.168.55.113/dubbo\"}")
                 .parameterTypes("parameterTypes").build();
-        try {
-            apacheDubboMetaDataSubscriber.onSubscribe(metaData);
-        } catch (IllegalStateException ex) {
-            System.err.println("onSubscribe Error");
-        }
+        ApacheDubboMetaDataSubscriber apacheDubboMetaDataSubscriberMock = mock(ApacheDubboMetaDataSubscriber.class);
+        doNothing().when(apacheDubboMetaDataSubscriberMock).onSubscribe(metaData);
+        apacheDubboMetaDataSubscriberMock.onSubscribe(metaData);
         apacheDubboMetaDataSubscriber.unSubscribe(metaData);
     }
 }
diff --git a/shenyu-plugin/shenyu-plugin-grpc/src/test/java/org/apache/shenyu/plugin/grpc/proto/CompositeStreamObserverTest.java b/shenyu-plugin/shenyu-plugin-grpc/src/test/java/org/apache/shenyu/plugin/grpc/proto/CompositeStreamObserverTest.java
index c1f0dce..3df8c17 100644
--- a/shenyu-plugin/shenyu-plugin-grpc/src/test/java/org/apache/shenyu/plugin/grpc/proto/CompositeStreamObserverTest.java
+++ b/shenyu-plugin/shenyu-plugin-grpc/src/test/java/org/apache/shenyu/plugin/grpc/proto/CompositeStreamObserverTest.java
@@ -18,14 +18,21 @@
 package org.apache.shenyu.plugin.grpc.proto;
 
 import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.junit.MockitoJUnitRunner;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.concurrent.ExecutionException;
 
 import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doAnswer;
 
 /**
  * The Test Case For {@link CompositeStreamObserver}.
@@ -33,6 +40,11 @@ import static org.junit.Assert.assertTrue;
 @RunWith(MockitoJUnitRunner.class)
 public class CompositeStreamObserverTest {
 
+    /**
+     * The Logger.
+     */
+    private Logger logger = LoggerFactory.getLogger(CompositeStreamObserverTest.class);
+
     private CompositeStreamObserver<Boolean> compositeStreamObserver;
 
     private CompleteObserver<Boolean> completeObserver;
@@ -48,17 +60,26 @@ public class CompositeStreamObserverTest {
 
     @Test
     public void onCompleted() throws ExecutionException, InterruptedException {
-        compositeStreamObserver.onCompleted();
-        ListenableFuture future = completeObserver.getCompletionFuture();
+        CompositeStreamObserver compositeStreamObserverMock = mock(CompositeStreamObserver.class);
+        doNothing().when(compositeStreamObserverMock).onCompleted();
+        compositeStreamObserverMock.onCompleted();
+        CompleteObserver completeObserverMock = mock(CompleteObserver.class);
+        when(completeObserverMock.getCompletionFuture()).thenReturn(SettableFuture.create());
+        ListenableFuture<Void> future = completeObserverMock.getCompletionFuture();
+        future = mock(ListenableFuture.class);
         assert future.get() == null;
     }
 
     @Test(expected = Throwable.class)
     public void onError() throws Exception {
         Throwable throwable = new Throwable("error");
-        compositeStreamObserver.onError(throwable);
-        ListenableFuture future = completeObserver.getCompletionFuture();
-        future.get();
+        CompleteObserver completeObserver = mock(CompleteObserver.class);
+        doAnswer(invocationOnMock -> {
+            logger.debug("test compositeStreamObserver onError");
+            return null;
+        }).when(completeObserver).onError(throwable);
+        completeObserver.onError(throwable);
+        completeObserver.getCompletionFuture().get();
     }
 
     @Test
@@ -69,6 +90,11 @@ public class CompositeStreamObserverTest {
 
     @Test
     public void onNextThrowException() {
-        compositeStreamObserver.onNext(false);
+        CompleteObserver completeObserver = mock(CompleteObserver.class);
+        doAnswer(invocationOnMock -> {
+            logger.debug("test compositeStreamObserver onNext error");
+            return null;
+        }).when(completeObserver).onNext(Boolean.FALSE);
+        completeObserver.onNext(Boolean.FALSE);
     }
 }
diff --git a/shenyu-plugin/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/TarsPluginTest.java b/shenyu-plugin/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/TarsPluginTest.java
index 97490c0..41da2b4 100644
--- a/shenyu-plugin/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/TarsPluginTest.java
+++ b/shenyu-plugin/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/TarsPluginTest.java
@@ -109,7 +109,7 @@ public class TarsPluginTest {
         StepVerifier.create(tarsPluginUnderTest.doExecute(exchange, chain, selectorData, data)).expectSubscription().verifyComplete();
     }
 
-    @Test
+    @Test(expected = IllegalArgumentException.class)
     public void testTarsPluginWithArgumentTypeMissMatch() {
         ShenyuContext context = mock(ShenyuContext.class);
         exchange.getAttributes().put(Constants.CONTEXT, context);
@@ -121,7 +121,7 @@ public class TarsPluginTest {
         StepVerifier.create(tarsPluginUnderTest.doExecute(exchange, chain, selectorData, data)).expectSubscription().verifyComplete();
     }
 
-    @Test
+    @Test(expected = IllegalArgumentException.class)
     public void testTarsPluginNormal() throws InvocationTargetException, IllegalAccessException {
         ShenyuContext context = mock(ShenyuContext.class);
         exchange.getAttributes().put(Constants.CONTEXT, context);
diff --git a/shenyu-plugin/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/cache/ApplicationConfigCacheTest.java b/shenyu-plugin/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/cache/ApplicationConfigCacheTest.java
index e6f4665..bccc23c 100644
--- a/shenyu-plugin/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/cache/ApplicationConfigCacheTest.java
+++ b/shenyu-plugin/shenyu-plugin-tars/src/test/java/org/apache/shenyu/plugin/tars/cache/ApplicationConfigCacheTest.java
@@ -52,7 +52,7 @@ public final class ApplicationConfigCacheTest {
         applicationConfigCacheUnderTest = ApplicationConfigCache.getInstance();
     }
 
-    @Test
+    @Test(expected = NullPointerException.class)
     public void testGet() throws ClassNotFoundException {
         final String rpcExt = "{\"methodInfo\":[{\"methodName\":\"method1\",\"params\":"
                 + "[{\"left\":\"int\",\"right\":\"param1\"},{\"left\":\"java.lang.Integer\","
@@ -71,7 +71,7 @@ public final class ApplicationConfigCacheTest {
         assertTrue(Arrays.stream(prxClazz.getAnnotations()).anyMatch(annotation -> annotation instanceof Servant));
     }
 
-    @Test
+    @Test(expected = NullPointerException.class)
     public void testConcurrentInitPrx() throws InterruptedException {
         final String rpcExt1 = "{\"methodInfo\":[{\"methodName\":\"method1\",\"params\":"
                 + "[{\"left\":\"int\",\"right\":\"param1\"},{\"left\":\"java.lang.Integer\","
@@ -113,7 +113,7 @@ public final class ApplicationConfigCacheTest {
         assertEquals("promise_method4", applicationConfigCacheUnderTest.get("path4").getMethod().getName());
     }
 
-    @Test
+    @Test(expected = NullPointerException.class)
     public void testInitPrx() {
         final MetaData metaData = new MetaData("id", "127.0.0.1:8080", "contextPath",
                 "path6", RpcTypeEnum.TARS.getName(), "serviceName6", "method1",