Skip to content

Commit

Permalink
optimize Exception unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
l81893521 committed Dec 21, 2023
1 parent 1bd7c64 commit 13e1ac5
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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"));
});
}
}
Original file line number Diff line number Diff line change
@@ -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"));
});
}
}
Original file line number Diff line number Diff line change
@@ -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");
});

}
}
Original file line number Diff line number Diff line change
@@ -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"));
});
}
}

0 comments on commit 13e1ac5

Please sign in to comment.