-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: increase common module unit test coverage (#6157)
- Loading branch information
Showing
21 changed files
with
613 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
common/src/test/java/io/seata/common/exception/AuthenticationFailedExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
/** | ||
*/ | ||
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")); | ||
}); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
common/src/test/java/io/seata/common/exception/JsonParseExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 io.seata.common.exception; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
*/ | ||
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")); | ||
}); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
common/src/test/java/io/seata/common/exception/RedisExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
*/ | ||
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"); | ||
}); | ||
|
||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
common/src/test/java/io/seata/common/exception/RetryableExceptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
/** | ||
*/ | ||
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")); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
common/src/test/java/io/seata/common/metadata/ClusterRoleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* 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.metadata; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
*/ | ||
public class ClusterRoleTest { | ||
|
||
@Test | ||
public void testClusterRole() { | ||
Assertions.assertEquals(0, ClusterRole.LEADER.getRoleCode()); | ||
Assertions.assertEquals(1, ClusterRole.FOLLOWER.getRoleCode()); | ||
Assertions.assertEquals(2, ClusterRole.LEARNER.getRoleCode()); | ||
Assertions.assertEquals(3, ClusterRole.MEMBER.getRoleCode()); | ||
Assertions.assertDoesNotThrow(() -> ClusterRole.MEMBER.setRoleCode(4)); | ||
} | ||
} |
Oops, something went wrong.