You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by lw...@apache.org on 2021/08/01 01:36:48 UTC
[incubator-shenyu] branch master updated: #1824 Add test for
org.apache.shenyu.common.exception.* (#1848)
This is an automated email from the ASF dual-hosted git repository.
lw1243925457 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 38b63d2 #1824 Add test for org.apache.shenyu.common.exception.* (#1848)
38b63d2 is described below
commit 38b63d28b245dbd4070f054baff056091020f171
Author: lahmxu <31...@users.noreply.github.com>
AuthorDate: Sun Aug 1 09:36:32 2021 +0800
#1824 Add test for org.apache.shenyu.common.exception.* (#1848)
* feat: add test
* feat: add test
Co-authored-by: lahmxu <la...@gmail.com>
---
.../common/exception/CommonErrorCodeTest.java | 38 +++++++++++++
.../common/exception/SerializerExceptionTest.java | 62 ++++++++++++++++++++++
.../common/exception/ShenyuExceptionTest.java | 62 ++++++++++++++++++++++
3 files changed, 162 insertions(+)
diff --git a/shenyu-common/src/test/java/org/apache/shenyu/common/exception/CommonErrorCodeTest.java b/shenyu-common/src/test/java/org/apache/shenyu/common/exception/CommonErrorCodeTest.java
new file mode 100644
index 0000000..2d8525d
--- /dev/null
+++ b/shenyu-common/src/test/java/org/apache/shenyu/common/exception/CommonErrorCodeTest.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.common.exception;
+
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Test case for {@link CommonErrorCode}.
+ */
+public final class CommonErrorCodeTest {
+
+ @Test
+ public void testCommonErrorCode() {
+ assertThat(CommonErrorCode.SUCCESSFUL, is(200));
+ assertThat(CommonErrorCode.ERROR, is(500));
+ assertThat(CommonErrorCode.TOKEN_ERROR, is(600));
+ assertThat(CommonErrorCode.TOKEN_NO_PERMISSION, is(601));
+ assertThat(CommonErrorCode.NOT_FOUND_EXCEPTION, is(404));
+ }
+}
diff --git a/shenyu-common/src/test/java/org/apache/shenyu/common/exception/SerializerExceptionTest.java b/shenyu-common/src/test/java/org/apache/shenyu/common/exception/SerializerExceptionTest.java
new file mode 100644
index 0000000..9bf4d4b
--- /dev/null
+++ b/shenyu-common/src/test/java/org/apache/shenyu/common/exception/SerializerExceptionTest.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.common.exception;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test case for {@link SerializerException}.
+ */
+public final class SerializerExceptionTest {
+
+ @Test
+ public void testAcquireByThrowable() {
+ String message = "error throwable";
+ Throwable throwable = new Throwable(message);
+ SerializerException serializerException = new SerializerException(throwable);
+
+ assertTrue(serializerException instanceof SerializerException);
+ assertEquals(serializerException.getCause().getMessage(), message);
+ assertEquals(serializerException.getCause(), throwable);
+ }
+
+ @Test
+ public void testAcquireByMessage() {
+ String message = "error";
+ SerializerException serializerException = new SerializerException(message);
+
+ assertTrue(serializerException instanceof SerializerException);
+ assertEquals(serializerException.getMessage(), message);
+ }
+
+ @Test
+ public void testAcquireByMessageAndThrowable() {
+ String message = "error message";
+ String throwableMessage = "error throwable";
+ Throwable throwable = new Throwable(throwableMessage);
+ SerializerException serializerException = new SerializerException(message, throwable);
+
+ assertTrue(serializerException instanceof SerializerException);
+ assertEquals(serializerException.getMessage(), message);
+ assertEquals(serializerException.getCause().getMessage(), throwableMessage);
+ assertEquals(serializerException.getCause(), throwable);
+ }
+}
diff --git a/shenyu-common/src/test/java/org/apache/shenyu/common/exception/ShenyuExceptionTest.java b/shenyu-common/src/test/java/org/apache/shenyu/common/exception/ShenyuExceptionTest.java
new file mode 100644
index 0000000..12e4e87
--- /dev/null
+++ b/shenyu-common/src/test/java/org/apache/shenyu/common/exception/ShenyuExceptionTest.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.common.exception;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test case for {@link ShenyuException}.
+ */
+public final class ShenyuExceptionTest {
+
+ @Test
+ public void testAcquireByThrowable() {
+ String message = "error throwable";
+ Throwable throwable = new Throwable(message);
+ ShenyuException shenyuException = new ShenyuException(throwable);
+
+ assertTrue(shenyuException instanceof ShenyuException);
+ assertEquals(shenyuException.getCause().getMessage(), message);
+ assertEquals(shenyuException.getCause(), throwable);
+ }
+
+ @Test
+ public void testAcquireByMessage() {
+ String message = "error";
+ ShenyuException shenyuException = new ShenyuException(message);
+
+ assertTrue(shenyuException instanceof ShenyuException);
+ assertEquals(shenyuException.getMessage(), message);
+ }
+
+ @Test
+ public void testAcquireByMessageAndThrowable() {
+ String message = "error message";
+ String throwableMessage = "error throwable";
+ Throwable throwable = new Throwable(throwableMessage);
+ ShenyuException shenyuException = new ShenyuException(message, throwable);
+
+ assertTrue(shenyuException instanceof ShenyuException);
+ assertEquals(shenyuException.getMessage(), message);
+ assertEquals(shenyuException.getCause().getMessage(), throwableMessage);
+ assertEquals(shenyuException.getCause(), throwable);
+ }
+}