From 4e991c7dc07090690a29b20c962b24ee4dd1f157 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 27 May 2020 16:28:55 +0200 Subject: [PATCH] Remove use of ExpectedException We have Assert.assertThrows(), hence we can simplify these two tests. Change-Id: I7a30634c4ae8cd89fb317230bd94f12bac6d8953 Signed-off-by: Robert Varga --- .../ModuleShardStrategyTest.java | 18 ++------------- .../ShardStrategyFactoryTest.java | 22 ++++++------------- 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ModuleShardStrategyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ModuleShardStrategyTest.java index 036e881166..fd42b6287c 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ModuleShardStrategyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ModuleShardStrategyTest.java @@ -5,15 +5,12 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.cluster.datastore.shardstrategy; import static org.junit.Assert.assertEquals; import org.junit.BeforeClass; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.opendaylight.controller.cluster.datastore.config.Configuration; import org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl; import org.opendaylight.controller.md.cluster.datastore.model.CarsModel; @@ -21,9 +18,6 @@ import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; public class ModuleShardStrategyTest { - @Rule - public ExpectedException expectedEx = ExpectedException.none(); - private static Configuration configuration; @BeforeClass @@ -31,14 +25,10 @@ public class ModuleShardStrategyTest { configuration = new ConfigurationImpl("module-shards.conf", "modules.conf"); } - @Test public void testFindShard() { - ModuleShardStrategy moduleShardStrategy = - new ModuleShardStrategy("cars", configuration); - + ModuleShardStrategy moduleShardStrategy = new ModuleShardStrategy("cars", configuration); String shard = moduleShardStrategy.findShard(CarsModel.BASE_PATH); - assertEquals("cars-1", shard); } @@ -50,12 +40,8 @@ public class ModuleShardStrategyTest { final YangInstanceIdentifier BASE_PATH = YangInstanceIdentifier.of(baseQName); - ModuleShardStrategy moduleShardStrategy = - new ModuleShardStrategy("missing", configuration); - + ModuleShardStrategy moduleShardStrategy = new ModuleShardStrategy("missing", configuration); String shard = moduleShardStrategy.findShard(BASE_PATH); - assertEquals(DefaultShardStrategy.DEFAULT_SHARD, shard); - } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ShardStrategyFactoryTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ShardStrategyFactoryTest.java index e7b70e8c1e..84b82b293a 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ShardStrategyFactoryTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardstrategy/ShardStrategyFactoryTest.java @@ -5,16 +5,15 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.cluster.datastore.shardstrategy; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl; import org.opendaylight.controller.md.cluster.datastore.model.CarsModel; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; @@ -22,16 +21,12 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; public class ShardStrategyFactoryTest { - - ShardStrategyFactory factory; - - @Rule - public ExpectedException expectedEx = ExpectedException.none(); + private ShardStrategyFactory factory; @Before public void setUp() { - factory = new ShardStrategyFactory( - new ConfigurationImpl("module-shards.conf", "modules.conf"), LogicalDatastoreType.CONFIGURATION); + factory = new ShardStrategyFactory(new ConfigurationImpl("module-shards.conf", "modules.conf"), + LogicalDatastoreType.CONFIGURATION); } @Test @@ -46,12 +41,9 @@ public class ShardStrategyFactoryTest { assertTrue(strategy instanceof ModuleShardStrategy); } - @Test public void testGetStrategyNullPointerExceptionWhenPathIsNull() { - expectedEx.expect(NullPointerException.class); - expectedEx.expectMessage("path should not be null"); - - factory.getStrategy(null); + final NullPointerException ex = assertThrows(NullPointerException.class, () -> factory.getStrategy(null)); + assertEquals("path should not be null", ex.getMessage()); } } -- 2.36.6