From 13e1ac55133ac2051839deeb19a454d051594c9b Mon Sep 17 00:00:00 2001 From: zhangjiawei <349071347@qq.com> Date: Fri, 22 Dec 2023 00:05:31 +0800 Subject: [PATCH] optimize Exception unit test --- .../AuthenticationFailedExceptionTest.java | 44 ++++++++++++++++ .../exception/JsonParseExceptionTest.java | 41 +++++++++++++++ .../common/exception/RedisExceptionTest.java | 51 +++++++++++++++++++ .../exception/RetryableExceptionTest.java | 44 ++++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 common/src/test/java/io/seata/common/exception/AuthenticationFailedExceptionTest.java create mode 100644 common/src/test/java/io/seata/common/exception/JsonParseExceptionTest.java create mode 100644 common/src/test/java/io/seata/common/exception/RedisExceptionTest.java create mode 100644 common/src/test/java/io/seata/common/exception/RetryableExceptionTest.java diff --git a/common/src/test/java/io/seata/common/exception/AuthenticationFailedExceptionTest.java b/common/src/test/java/io/seata/common/exception/AuthenticationFailedExceptionTest.java new file mode 100644 index 00000000000..078eb33045e --- /dev/null +++ b/common/src/test/java/io/seata/common/exception/AuthenticationFailedExceptionTest.java @@ -0,0 +1,44 @@ +/* + * 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 io.seata.common.exception; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * @description: + * @author: zhangjiawei + * @date: 2023/12/22 + */ +public class AuthenticationFailedExceptionTest { + + @Test + public void testAuthenticationFailedException() { + Assertions.assertThrowsExactly(AuthenticationFailedException.class, () -> { + throw new AuthenticationFailedException(); + }); + Assertions.assertThrowsExactly(AuthenticationFailedException.class, () -> { + throw new AuthenticationFailedException("error"); + }); + Assertions.assertThrowsExactly(AuthenticationFailedException.class, () -> { + throw new AuthenticationFailedException(new Throwable("error")); + }); + Assertions.assertThrowsExactly(AuthenticationFailedException.class, () -> { + throw new AuthenticationFailedException("error", new Throwable("error")); + }); + } +} diff --git a/common/src/test/java/io/seata/common/exception/JsonParseExceptionTest.java b/common/src/test/java/io/seata/common/exception/JsonParseExceptionTest.java new file mode 100644 index 00000000000..e8b4bb0d527 --- /dev/null +++ b/common/src/test/java/io/seata/common/exception/JsonParseExceptionTest.java @@ -0,0 +1,41 @@ +/* + * 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 io.seata.common.exception; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * @description: + * @author: zhangjiawei + * @date: 2023/12/21 + */ +public class JsonParseExceptionTest { + + @Test + public void testJsonParseException() { + Assertions.assertThrowsExactly(JsonParseException.class, () -> { + throw new JsonParseException("error"); + }); + Assertions.assertThrowsExactly(JsonParseException.class, () -> { + throw new JsonParseException("error", new Throwable("error")); + }); + Assertions.assertThrowsExactly(JsonParseException.class, () -> { + throw new JsonParseException(new Throwable("error")); + }); + } +} diff --git a/common/src/test/java/io/seata/common/exception/RedisExceptionTest.java b/common/src/test/java/io/seata/common/exception/RedisExceptionTest.java new file mode 100644 index 00000000000..dbcf70ed216 --- /dev/null +++ b/common/src/test/java/io/seata/common/exception/RedisExceptionTest.java @@ -0,0 +1,51 @@ +/* + * 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 io.seata.common.exception; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * @description: + * @author: zhangjiawei + * @date: 2023/12/21 + */ +public class RedisExceptionTest { + + @Test + public void testRedisException() { + Assertions.assertThrowsExactly(RedisException.class, () -> { + throw new RedisException(FrameworkErrorCode.UnknownAppError); + }); + Assertions.assertThrowsExactly(RedisException.class, () -> { + throw new RedisException("error"); + }); + Assertions.assertThrowsExactly(RedisException.class, () -> { + throw new RedisException("error", FrameworkErrorCode.UnknownAppError); + }); + Assertions.assertThrowsExactly(RedisException.class, () -> { + throw new RedisException(new Throwable("error"), "error", FrameworkErrorCode.UnknownAppError); + }); + Assertions.assertThrowsExactly(RedisException.class, () -> { + throw new RedisException(new Throwable("error")); + }); + Assertions.assertThrowsExactly(RedisException.class, () -> { + throw new RedisException(new Throwable("error"), "error"); + }); + + } +} diff --git a/common/src/test/java/io/seata/common/exception/RetryableExceptionTest.java b/common/src/test/java/io/seata/common/exception/RetryableExceptionTest.java new file mode 100644 index 00000000000..0606a688bc7 --- /dev/null +++ b/common/src/test/java/io/seata/common/exception/RetryableExceptionTest.java @@ -0,0 +1,44 @@ +/* + * 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 io.seata.common.exception; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * @description: + * @author: zhangjiawei + * @date: 2023/12/21 + */ +public class RetryableExceptionTest { + + @Test + public void testRetryableException() { + Assertions.assertThrowsExactly(RetryableException.class, () -> { + throw new RetryableException(); + }); + Assertions.assertThrowsExactly(RetryableException.class, () -> { + throw new RetryableException("error"); + }); + Assertions.assertThrowsExactly(RetryableException.class, () -> { + throw new RetryableException(new Throwable("error")); + }); + Assertions.assertThrowsExactly(RetryableException.class, () -> { + throw new RetryableException("error", new Throwable("error")); + }); + } +}