You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2023/03/05 05:51:02 UTC
[shardingsphere] branch master updated: Refactor @Test(expected) to assert assertThrows on mode modules (#24463)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 762bb064375 Refactor @Test(expected) to assert assertThrows on mode modules (#24463)
762bb064375 is described below
commit 762bb064375c867b5c2196705a867c77cd9d534f
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Mar 5 13:50:54 2023 +0800
Refactor @Test(expected) to assert assertThrows on mode modules (#24463)
---
.../mode/repository/cluster/nacos/NacosRepositoryTest.java | 9 +++++----
.../workerid/generator/StandaloneWorkerIdGeneratorTest.java | 5 +++--
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/mode/type/cluster/repository/provider/nacos/src/test/java/org/apache/shardingsphere/mode/repository/cluster/nacos/NacosRepositoryTest.java b/mode/type/cluster/repository/provider/nacos/src/test/java/org/apache/shardingsphere/mode/repository/cluster/nacos/NacosRepositoryTest.java
index c53d87b20cc..ecf0b1d6cb5 100644
--- a/mode/type/cluster/repository/provider/nacos/src/test/java/org/apache/shardingsphere/mode/repository/cluster/nacos/NacosRepositoryTest.java
+++ b/mode/type/cluster/repository/provider/nacos/src/test/java/org/apache/shardingsphere/mode/repository/cluster/nacos/NacosRepositoryTest.java
@@ -58,6 +58,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
@@ -336,16 +337,16 @@ public final class NacosRepositoryTest {
verify(client).shutDown();
}
- @Test(expected = ClusterPersistRepositoryException.class)
+ @Test
public void assertPersistNotAvailable() {
- REPOSITORY.persist("/test/children/keys/persistent/1", "value4");
+ assertThrows(ClusterPersistRepositoryException.class, () -> REPOSITORY.persist("/test/children/keys/persistent/1", "value4"));
}
- @Test(expected = IllegalStateException.class)
+ @Test
public void assertExceededMaximum() {
ServiceMetaData ephemeralService = serviceController.getEphemeralService();
ephemeralService.setPort(new AtomicInteger(Integer.MAX_VALUE));
- REPOSITORY.persistEphemeral("/key2", "value");
+ assertThrows(IllegalStateException.class, () -> REPOSITORY.persistEphemeral("/key2", "value"));
}
private VoidAnswer2<String, EventListener> getListenerAnswer(final Instance preInstance, final Event event) {
diff --git a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/workerid/generator/StandaloneWorkerIdGeneratorTest.java b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/workerid/generator/StandaloneWorkerIdGeneratorTest.java
index 5769dc6b791..7df8c492d92 100644
--- a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/workerid/generator/StandaloneWorkerIdGeneratorTest.java
+++ b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/workerid/generator/StandaloneWorkerIdGeneratorTest.java
@@ -26,6 +26,7 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertThrows;
public final class StandaloneWorkerIdGeneratorTest {
@@ -44,8 +45,8 @@ public final class StandaloneWorkerIdGeneratorTest {
assertThat(new StandaloneWorkerIdGenerator().generate(PropertiesBuilder.build(new Property(WorkerIdGenerator.WORKER_ID_KEY, "1"))), is(1));
}
- @Test(expected = IllegalStateException.class)
+ @Test
public void assertGenerateWithInvalidProperties() {
- new StandaloneWorkerIdGenerator().generate(PropertiesBuilder.build(new Property(WorkerIdGenerator.WORKER_ID_KEY, "1024")));
+ assertThrows(IllegalStateException.class, () -> new StandaloneWorkerIdGenerator().generate(PropertiesBuilder.build(new Property(WorkerIdGenerator.WORKER_ID_KEY, "1024"))));
}
}