From 55e12c5771f04d6917a2c23f09afca0a916f452a Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 23 Jan 2020 17:50:22 +0100 Subject: [PATCH] Remove usage of ExpectedException 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 --- .../yangtools/util/ListenerRegistryTest.java | 6 ------ .../yangtools/yang/stmt/CaseStmtTest.java | 17 ++++++----------- .../yang/stmt/SubstatementValidatorTest.java | 17 ++++++----------- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/common/util/src/test/java/org/opendaylight/yangtools/util/ListenerRegistryTest.java b/common/util/src/test/java/org/opendaylight/yangtools/util/ListenerRegistryTest.java index a5996bbc6d..d8b3f792de 100644 --- a/common/util/src/test/java/org/opendaylight/yangtools/util/ListenerRegistryTest.java +++ b/common/util/src/test/java/org/opendaylight/yangtools/util/ListenerRegistryTest.java @@ -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 registry; - @Rule - public ExpectedException expException = ExpectedException.none(); - @Before public void init() { testEventListener = new TestEventListener() {}; diff --git a/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/CaseStmtTest.java b/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/CaseStmtTest.java index bea2781f90..b8f8e822ad 100644 --- a/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/CaseStmtTest.java +++ b/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/CaseStmtTest.java @@ -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 diff --git a/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/SubstatementValidatorTest.java b/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/SubstatementValidatorTest.java index 3498fe561e..d2baf198e7 100644 --- a/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/SubstatementValidatorTest.java +++ b/yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/SubstatementValidatorTest.java @@ -9,6 +9,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; @@ -18,9 +19,7 @@ import java.io.UnsupportedEncodingException; import java.util.Collection; 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; @@ -30,9 +29,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")); @@ -71,10 +67,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 @@ -86,7 +81,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 -- 2.36.6