BUG-4638: Convert to using new types
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / retest / YangParserNegativeTest.java
index bfaea689bc988b3f42f23a90d2fa1c9ab42ad82b..012f154c82afb08bfc1019da0e87f5cc54a85391 100644 (file)
@@ -24,6 +24,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedEx
 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.util.YangParseException;
 import org.opendaylight.yangtools.yang.parser.util.YangValidationException;
+import com.google.common.base.Throwables;
 
 public class YangParserNegativeTest {
 
@@ -36,10 +37,10 @@ public class YangParserNegativeTest {
                 fail("SomeModifiersUnresolvedException should be thrown");
             }
         } catch (SomeModifiersUnresolvedException e) {
-            final Throwable suppressed2levelsDown = e.getSuppressed()[0].getSuppressed()[0];
-            assertTrue(suppressed2levelsDown instanceof InferenceException);
-            assertTrue(suppressed2levelsDown.getMessage().startsWith("Imported module"));
-            assertTrue(suppressed2levelsDown.getMessage().endsWith("was not found."));
+            Throwable rootCause = Throwables.getRootCause(e);
+            assertTrue(rootCause instanceof InferenceException);
+            assertTrue(rootCause.getMessage().startsWith("Imported module"));
+            assertTrue(rootCause.getMessage().endsWith("was not found."));
         }
     }
 
@@ -51,9 +52,11 @@ public class YangParserNegativeTest {
                 TestUtils.loadModule(stream);
                 fail("IllegalArgumentException should be thrown");
             }
-        } catch (IllegalStateException e) {
-            assertTrue(e.getMessage().startsWith(
-                    "Type '(urn:simple.types.data.demo?revision=2013-02-27)int-ext' was not found"));
+        } catch (SomeModifiersUnresolvedException e) {
+            Throwable rootCause = Throwables.getRootCause(e);
+            assertTrue(rootCause instanceof InferenceException);
+            assertTrue(rootCause.getMessage()
+                    .startsWith("Type [(urn:simple.types.data.demo?revision=2013-02-27)int-ext] was not found."));
         }
     }
 
@@ -73,11 +76,11 @@ public class YangParserNegativeTest {
                 }
             }
         } catch (SomeModifiersUnresolvedException e) {
-            final Throwable suppressed2levelsDown = e.getSuppressed()[0].getSuppressed()[0];
-            assertTrue(suppressed2levelsDown instanceof InferenceException);
+            final Throwable rootCause = Throwables.getRootCause(e);
+            assertTrue(rootCause instanceof InferenceException);
             assertEquals(
                     "Augment target not found: Absolute{path=[(urn:simple.container.demo?revision=1970-01-01)unknown]}",
-                    suppressed2levelsDown.getMessage());
+                    rootCause.getMessage());
         }
     }
 
@@ -105,7 +108,7 @@ public class YangParserNegativeTest {
                 TestUtils.loadModule(stream);
                 fail("YangParseException should be thrown");
             }
-        } catch (YangParseException e) {
+        } catch (SourceException e) {
             assertTrue(e.getMessage().contains("Invalid length constraint: <4, 10>"));
         }
     }
@@ -118,7 +121,7 @@ public class YangParserNegativeTest {
                 TestUtils.loadModule(stream);
                 fail("Exception should be thrown");
             }
-        } catch (YangParseException e) {
+        } catch (SourceException e) {
             assertTrue(e.getMessage().contains("Invalid range constraint: <5, 20>"));
         }
     }