Skip to content

Commit

Permalink
test: enhance test coverage of seata common (#6430)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikhailNavitski authored Mar 20, 2024
1 parent 2682c00 commit 9e78cdd
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#6157](https://github.com/apache/incubator-seata/pull/6157)] increase common module unit test coverage
- [[#6250](https://github.com/apache/incubator-seata/pull/6250)] increase seata-core module unit test coverage
- [[#6325](https://github.com/apache/incubator-seata/pull/6325)] fix mockServerTest fail cause using same port with seata-server
- [[#6430](https://github.com/apache/incubator-seata/pull/6430)] increase common module unit test coverage

### refactor:
- [[#6280](https://github.com/apache/incubator-seata/pull/6280)] refactor Saga designer using diagram-js
Expand Down Expand Up @@ -166,5 +167,6 @@ Thanks to these contributors for their code commits. Please report an unintended
- [gggyd123](https://github.com/gggyd123)
- [jonasHanhan](https://github.com/jonasHanhan)
- [Code-breaker1998](https://github.com/Code-breaker1998)
- [MikhailNavitski](https://github.com/MikhailNavitski)

Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.
2 changes: 2 additions & 0 deletions changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
- [[#6157](https://github.com/apache/incubator-seata/pull/6157)] 增加common模块单测覆盖率
- [[#6250](https://github.com/apache/incubator-seata/pull/6250)] 增加seata-core模块单测覆盖率
- [[#6325](https://github.com/apache/incubator-seata/pull/6325)] 修复mock-server相关测试用例
- [[#6430](https://github.com/apache/incubator-seata/pull/6430)] 增加 common 模块单元测试覆盖率

### refactor:
- [[#6280](https://github.com/apache/incubator-seata/pull/6280)] 使用diagram-js重构Saga设计器
Expand Down Expand Up @@ -168,5 +169,6 @@
- [gggyd123](https://github.com/gggyd123)
- [jonasHanhan](https://github.com/jonasHanhan)
- [Code-breaker1998](https://github.com/Code-breaker1998)
- [MikhailNavitski](https://github.com/MikhailNavitski)

同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。
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 org.apache.seata.common.exception;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;


class RepeatRegistrationExceptionTest {

@Test
void testRepeatRegistrationException() {
assertAll(
() -> assertThrowsExactly(RepeatRegistrationException.class, () -> {
throw new RepeatRegistrationException("error");
}),
() -> assertThrowsExactly(RepeatRegistrationException.class, () -> {
throw new RepeatRegistrationException("error", new Throwable("error"));
}),
() -> assertThrowsExactly(RepeatRegistrationException.class, () -> {
throw new RepeatRegistrationException(new Throwable("error"));
})
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.seata.common.exception;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;

class SkipCallbackWrapperExceptionTest {

@Test
void testSkipCallbackWrapperException() {
assertThrowsExactly(SkipCallbackWrapperException.class, () -> {
throw new SkipCallbackWrapperException(new Throwable("error"));
});

}

@Test
void testFillInStackTrace() {
SkipCallbackWrapperException skipCallbackWrapperException = new SkipCallbackWrapperException(new Throwable("error"));
assertNull(skipCallbackWrapperException.fillInStackTrace());

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.seata.common.util;

import org.junit.jupiter.api.Test;

import java.util.function.Function;
import java.util.function.Predicate;

import static org.junit.jupiter.api.Assertions.assertTrue;

class LambdaUtilsTest {

@Test
void shouldReturnTrueForDistinctKeys() {
Function<Object, Object> keyExtractor = Object::getClass;
Predicate<Object> distinctByKey = LambdaUtils.distinctByKey(keyExtractor);

boolean result = distinctByKey.test(new Object());
assertTrue(result);
}
}

0 comments on commit 9e78cdd

Please sign in to comment.