Use assertThat(isA()) instead of assertTrue(instanceof) 59/82759/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 27 Jun 2019 10:30:44 +0000 (12:30 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 27 Jun 2019 10:31:33 +0000 (12:31 +0200)
This improves errors reported when tests are failing, which is
a good thing.

Change-Id: I9ac82a7915de2faced58401f77fc0707a31b2754
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug4933Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5437Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5884Test.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileAugmentStmtTest.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileListStmtTest.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/stmt/yin/YinFileStmtTest.java
yang/yang-parser-rfc7950/src/test/java/org/opendaylight/yangtools/yang/thirdparty/plugin/ThirdPartyExtensionPluginTest.java

index 8d8482302d2d2b0829f0f36d859397aa56b41b23..0c79a1096993cc4955ce812202451c24bb811f88 100644 (file)
@@ -7,8 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
+import static org.hamcrest.Matchers.isA;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -39,7 +41,7 @@ public class Bug4933Test {
             fail("ReactorException should be thrown.");
         } catch (ReactorException e) {
             final Throwable cause = e.getCause();
-            assertTrue(cause instanceof SourceException);
+            assertThat(cause, isA(SourceException.class));
             assertTrue(cause.getMessage().startsWith("String 'not_supported' is not valid deviate argument"));
         }
     }
index e1e42cc136c77df4afe6104ce33265df3071d2f1..81739a55c20a67ded0b594de9ed9e388c058a1eb 100644 (file)
@@ -7,8 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
+import static org.hamcrest.Matchers.isA;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThat;
 
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -40,20 +41,21 @@ public class Bug5437Test {
         SchemaPath leafRef2Path = SchemaPath.create(true, root, leafRef2);
         SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, leafRefPath);
         SchemaNode findDataSchemaNode2 = SchemaContextUtil.findDataSchemaNode(context, leafRef2Path);
-        assertTrue(findDataSchemaNode instanceof LeafSchemaNode);
-        assertTrue(findDataSchemaNode2 instanceof LeafSchemaNode);
+        assertThat(findDataSchemaNode, isA(LeafSchemaNode.class));
+        assertThat(findDataSchemaNode2, isA(LeafSchemaNode.class));
+
         LeafSchemaNode leafRefNode = (LeafSchemaNode) findDataSchemaNode;
         LeafSchemaNode leafRefNode2 = (LeafSchemaNode) findDataSchemaNode2;
 
-        assertTrue(leafRefNode.getType() instanceof LeafrefTypeDefinition);
-        assertTrue(leafRefNode2.getType() instanceof LeafrefTypeDefinition);
+        assertThat(leafRefNode.getType(), isA(LeafrefTypeDefinition.class));
+        assertThat(leafRefNode2.getType(), isA(LeafrefTypeDefinition.class));
 
         TypeDefinition<?> baseTypeForLeafRef = SchemaContextUtil.getBaseTypeForLeafRef(
                 (LeafrefTypeDefinition) leafRefNode.getType(), context, leafRefNode);
         TypeDefinition<?> baseTypeForLeafRef2 = SchemaContextUtil.getBaseTypeForLeafRef(
                 (LeafrefTypeDefinition) leafRefNode2.getType(), context, leafRefNode2);
 
-        assertTrue(baseTypeForLeafRef instanceof BinaryTypeDefinition);
-        assertTrue(baseTypeForLeafRef2 instanceof Int16TypeDefinition);
+        assertThat(baseTypeForLeafRef, isA(BinaryTypeDefinition.class));
+        assertThat(baseTypeForLeafRef2, isA(Int16TypeDefinition.class));
     }
 }
index 814b4bae239780bfacfc724ca538ecb03ac378cd..f533b61f341d86ac5dbb280f9d06c4d1a2f293df 100644 (file)
@@ -7,8 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.stmt;
 
+import static org.hamcrest.Matchers.isA;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThat;
 
 import java.util.Iterator;
 import java.util.Set;
@@ -53,7 +54,7 @@ public class Bug5884Test {
         while (iterator.hasNext()) {
             AugmentationSchemaNode allAugments = iterator.next();
             final DataSchemaNode currentChoice = allAugments.getChildNodes().iterator().next();
-            assertTrue(currentChoice instanceof CaseSchemaNode);
+            assertThat(currentChoice, isA(CaseSchemaNode.class));
         }
     }
 }
\ No newline at end of file
index ce4ad365600ff33fbfdb619360be01f42ccbf714..c842887960e0b67736cf00c9db33176cb120bb08 100644 (file)
@@ -7,8 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.stmt.yin;
 
+import static org.hamcrest.Matchers.isA;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 import java.util.Iterator;
@@ -42,6 +44,6 @@ public class YinFileAugmentStmtTest extends AbstractYinModulesTest {
         assertEquals(1, augment.getChildNodes().size());
         final DataSchemaNode caseNode = augment.findDataChildByName(
             QName.create(testModule.getQNameModule(), "main-impl")).get();
-        assertTrue(caseNode instanceof CaseSchemaNode);
+        assertThat(caseNode, isA(CaseSchemaNode.class));
     }
 }
index 4fdec23f188beaea01334b979c42c35ae91053e4..45e941fd0fa2533f1b2e1b2800090ac8e299f37e 100644 (file)
@@ -7,8 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.stmt.yin;
 
+import static org.hamcrest.Matchers.isA;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 import java.util.Collection;
@@ -27,7 +29,6 @@ import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
 import org.opendaylight.yangtools.yang.stmt.TestUtils;
 
 public class YinFileListStmtTest extends AbstractYinModulesTest {
-
     @Test
     public void testListAndLeaves() {
         final Module testModule = TestUtils.findModule(context, "config").get();
@@ -53,10 +54,9 @@ public class YinFileListStmtTest extends AbstractYinModulesTest {
         assertEquals("type", leaf.getQName().getLocalName());
 
         final TypeDefinition<?> leafType = leaf.getType();
-        assertTrue(leafType instanceof IdentityrefTypeDefinition);
+        assertThat(leafType, isA(IdentityrefTypeDefinition.class));
         assertEquals("module-type", ((IdentityrefTypeDefinition)leafType).getIdentities().iterator().next().getQName()
             .getLocalName());
         assertTrue(leaf.isMandatory());
     }
-
 }
index 760acc777d682e20d0024e1ee91b5de110735462..731c6a13ef83855cab90348515fc7eb16dee340f 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.stmt.yin;
 
+import static org.hamcrest.Matchers.isA;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -69,7 +71,7 @@ public class YinFileStmtTest {
             fail("Reactor exception should have been thrown");
         } catch (ReactorException e) {
             final Throwable cause = e.getCause();
-            assertTrue(cause instanceof SourceException);
+            assertThat(cause, isA(SourceException.class));
             assertTrue(cause.getMessage().startsWith(
                 "Key argument 'testing-string testing-string' contains duplicates"));
         }
index 9c0ef54c9a183e55749b0d5855cbe4cc5c42faac..bd756fc152d8bdb007e39a5abd9f069aebd76f45 100644 (file)
@@ -7,8 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.thirdparty.plugin;
 
+import static org.hamcrest.Matchers.isA;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThat;
 
 import java.io.IOException;
 import java.net.URISyntaxException;
@@ -36,14 +37,15 @@ public class ThirdPartyExtensionPluginTest {
 
         final SchemaContext schema = reactor.buildEffective();
         final DataSchemaNode dataChildByName = schema.getDataChildByName(QName.create(NS, REV, "root"));
-        assertTrue(dataChildByName instanceof ContainerSchemaNode);
+        assertThat(dataChildByName, isA(ContainerSchemaNode.class));
+
         final ContainerSchemaNode root = (ContainerSchemaNode) dataChildByName;
 
         final List<UnknownSchemaNode> unknownSchemaNodes = root.getUnknownSchemaNodes();
         assertEquals(1, unknownSchemaNodes.size());
 
         final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.get(0);
-        assertTrue(unknownSchemaNode instanceof ThirdPartyExtensionEffectiveStatement);
+        assertThat(unknownSchemaNode, isA(ThirdPartyExtensionEffectiveStatement.class));
         final ThirdPartyExtensionEffectiveStatement thirdPartyExtensionStmt =
                 (ThirdPartyExtensionEffectiveStatement) unknownSchemaNode;
         assertEquals("Third-party namespace test.", thirdPartyExtensionStmt.getValueFromNamespace());