Remove use of org.junit.rules.ExpectedException 00/87100/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 23 Jan 2020 11:02:46 +0000 (12:02 +0100)
committerRobert Varga <nite@hq.sk>
Thu, 23 Jan 2020 11:19:43 +0000 (11:19 +0000)
We can use assertThrows() instead.

Change-Id: I8d752851d11496c74388f625067e41582447a8c5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/mdsal/binding/model/util/BindingGeneratorUtilTest.java
binding/mdsal-binding-generator-util/src/test/java/org/opendaylight/mdsal/binding/model/util/TypeNameTest.java

index 76240b31266d0f463ed52b20cf1208c2fcd2c0c1..b41b8463e5721bab4fcb9c18773bef435a7cde0d 100644 (file)
@@ -12,6 +12,7 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 
@@ -21,9 +22,7 @@ import com.google.common.collect.Range;
 import java.io.Serializable;
 import java.util.Optional;
 import java.util.Set;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import org.opendaylight.mdsal.binding.model.api.AccessModifier;
 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
 import org.opendaylight.mdsal.binding.model.api.Restrictions;
@@ -53,9 +52,6 @@ import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 public class BindingGeneratorUtilTest {
     private static final SchemaPath ROOT_PATH = SchemaPath.create(true, QName.create("test", "root"));
 
-    @Rule
-    public ExpectedException expectedEx = ExpectedException.none();
-
     /*
      * Tests methods:
      * &lt;ul&gt;
@@ -124,8 +120,7 @@ public class BindingGeneratorUtilTest {
      */
     @Test
     public void testPackageNameForGeneratedTypeNullBasePackageName() {
-        expectedEx.expect(NullPointerException.class);
-        BindingGeneratorUtil.packageNameForGeneratedType(null, null);
+        assertThrows(NullPointerException.class, () ->  BindingGeneratorUtil.packageNameForGeneratedType(null, null));
     }
 
     /*
@@ -137,8 +132,8 @@ public class BindingGeneratorUtilTest {
      */
     @Test
     public void testPackageNameForGeneratedTypeNullSchemaPath() {
-        expectedEx.expect(NullPointerException.class);
-        BindingGeneratorUtil.packageNameForGeneratedType("test.package", null);
+        assertThrows(NullPointerException.class,
+            () -> BindingGeneratorUtil.packageNameForGeneratedType("test.package", null));
     }
 
     /*
index 3b558bb048eb6a2b40c68242460997957191ccd1..63483d08b4662e88c90e89281635023d3e399aa2 100644 (file)
@@ -11,16 +11,10 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertTrue;
 
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
 
 public class TypeNameTest {
-
-    @Rule
-    public ExpectedException expException = ExpectedException.none();
-
     @Test
     public void testHashCode() {
         JavaTypeName baseType1 = JavaTypeName.create("org.opendaylight.yangtools.test", "Test");