Remove usage of ExpectedException 15/87115/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 23 Jan 2020 16:50:22 +0000 (17:50 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 23 Jan 2020 20:46:42 +0000 (21:46 +0100)
New JUnit provides an explicit assertThrows(), which supersedes
the old ExpectedException pattern. Migrate our tests to the new way
of doing things.

Change-Id: Idac4862fc8e20e4a27b2ac766c4d1770208195a8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
common/util/src/test/java/org/opendaylight/yangtools/util/ListenerRegistryTest.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/CaseStmtTest.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/SubstatementValidatorTest.java

index a5996bbc6db705b38730665a2f33f2e2f27f014e..d8b3f792dee1894358f5a8b940cc5a96a40a36e8 100644 (file)
@@ -13,20 +13,14 @@ import static org.junit.Assert.assertNotNull;
 import com.google.common.collect.ImmutableSet;
 import java.util.EventListener;
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 
 public class ListenerRegistryTest {
-
     private TestEventListener testEventListener;
     private ExtendedTestEventListener extendedTestEventListener;
     private ListenerRegistry<TestEventListener> registry;
 
-    @Rule
-    public ExpectedException expException = ExpectedException.none();
-
     @Before
     public void init() {
         testEventListener = new TestEventListener() {};
index bea2781f90ae3f94bb8011651e5af6db5b0e6879..b8f8e822ad167cab9c31883a3b63ef6c223b1a14 100644 (file)
@@ -5,18 +5,16 @@
  * 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.yangtools.yang.stmt;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 import java.net.URI;
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.Revision;
@@ -39,9 +37,6 @@ public class CaseStmtTest {
     private DataSchemaNode tempThirdChild;
     private CaseSchemaNode tempChoice;
 
-    @Rule
-    public ExpectedException expectedEx = ExpectedException.none();
-
     @Before
     public void setup() throws Exception {
         schema = StmtTestUtils.parseYangSources("/case-test");
@@ -531,14 +526,14 @@ public class CaseStmtTest {
     }
 
     @Test
-    public void testInferenceExceptionChoice() throws Exception {
-        expectedEx.expect(ReactorException.class);
-        schema = StmtTestUtils.parseYangSources("/case-test/case-test-exceptions/choice");
+    public void testInferenceExceptionChoice() {
+        assertThrows(ReactorException.class,
+            () -> StmtTestUtils.parseYangSources("/case-test/case-test-exceptions/choice"));
     }
 
     @Test
     public void testInferenceExceptionCase() throws Exception {
-        expectedEx.expect(ReactorException.class);
-        schema = StmtTestUtils.parseYangSources("/case-test/case-test-exceptions/case");
+        assertThrows(ReactorException.class,
+            () -> StmtTestUtils.parseYangSources("/case-test/case-test-exceptions/case"));
     }
 }
\ No newline at end of file
index 21cb097921dcd35440b6bd7198ed43690b55ca96..7024493e34e61a57e18f1104d1f6ed2572079dc3 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.yangtools.yang.stmt;
 
 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 static org.junit.Assert.fail;
 
@@ -19,9 +20,7 @@ import java.io.UnsupportedEncodingException;
 import java.util.Set;
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
@@ -31,9 +30,6 @@ public class SubstatementValidatorTest {
     private final PrintStream stdout = System.out;
     private final ByteArrayOutputStream output = new ByteArrayOutputStream();
 
-    @Rule
-    public ExpectedException expectedEx = ExpectedException.none();
-
     @Before
     public void setUp() throws UnsupportedEncodingException {
         System.setOut(new PrintStream(output, true, "UTF-8"));
@@ -72,10 +68,9 @@ public class SubstatementValidatorTest {
     }
 
     @Test
-    public void missingElementException() throws Exception {
-        expectedEx.expect(SomeModifiersUnresolvedException.class);
-
-        TestUtils.loadModules(getClass().getResource("/substatement-validator/missing-element").toURI());
+    public void missingElementException() {
+        assertThrows(SomeModifiersUnresolvedException.class, () -> TestUtils.loadModules(
+            SubstatementValidatorTest.class.getResource("/substatement-validator/missing-element").toURI()));
     }
 
     @Test
@@ -87,7 +82,7 @@ public class SubstatementValidatorTest {
 
     @Test
     public void bug4310test() throws Exception {
-        expectedEx.expect(SomeModifiersUnresolvedException.class);
-        TestUtils.loadModules(getClass().getResource("/substatement-validator/bug-4310").toURI());
+        assertThrows(SomeModifiersUnresolvedException.class, () -> TestUtils.loadModules(
+            SubstatementValidatorTest.class.getResource("/substatement-validator/bug-4310").toURI()));
     }
 }
\ No newline at end of file