未验证 提交 d51168f3 编写于 作者: kimmking's avatar kimmking 提交者: GitHub

Merge pull request #5520 from menghaoranss/ut-nacos

Improve unit test coverage of sharding-orchestration#nacos
......@@ -36,6 +36,7 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
......@@ -144,6 +145,48 @@ public final class NacosCenterRepositoryTest {
verify(configService).removeConfig("sharding.test", group);
}
@SneakyThrows
@Test
public void assertDeleteWhenThrowException() {
when(configService.getConfig(eq("sharding.test"), eq(group), anyLong())).thenReturn("value");
doThrow(NacosException.class).when(configService).removeConfig(eq("sharding.test"), eq(group));
REPOSITORY.delete("/sharding/test");
assertNotNull(REPOSITORY.get("/sharding/test"));
}
@SneakyThrows
@Test
public void assertWatchWhenThrowException() {
final ChangedType[] actualType = {null};
doThrow(NacosException.class)
.when(configService)
.addListener(anyString(), anyString(), any(Listener.class));
DataChangedEventListener listener = dataChangedEvent -> actualType[0] = dataChangedEvent.getChangedType();
REPOSITORY.watch("/sharding/test", listener);
assertNull(actualType[0]);
}
@Test
@SneakyThrows
public void assertPersistWhenThrowException() {
String value = "value";
doThrow(NacosException.class).when(configService).publishConfig(eq("sharding.test"), eq(group), eq(value));
REPOSITORY.persist("/sharding/test", value);
assertNull(REPOSITORY.get("/sharding/test"));
}
@Test
public void assertProperties() {
Properties properties = new Properties();
REPOSITORY.setProperties(properties);
assertThat(REPOSITORY.getProperties(), is(properties));
}
@Test
public void assertGetChildrenKeys() {
assertNull(REPOSITORY.getChildrenKeys("/sharding/test"));
}
private VoidAnswer3 getListenerAnswer(final String expectValue) {
return (VoidAnswer3<String, String, Listener>) (dataId, group, listener) -> listener.receiveConfigInfo(expectValue);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册