import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Verify.verify;
+import static com.google.common.base.Verify.verifyNotNull;
import static java.util.Objects.requireNonNull;
import com.google.common.collect.Iterables;
final int toWalk = ourDepth - depth;
YangInstanceIdentifier result = this;
for (int i = 0; i < toWalk; ++i) {
- result = result.getParent();
+ result = verifyNotNull(result.getParent());
}
return result;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
final YangInstanceIdentifier yangInstanceIdentifier1 = stackedYangInstanceIdentifier.getAncestor(4);
assertEquals(stackedYangInstanceIdentifier, stackedYangInstanceIdentifierClone);
assertEquals(stackedReversePathArguments, yangInstanceIdentifier1.getReversePathArguments());
+ assertSame(stackedYangInstanceIdentifier.getParent(), stackedYangInstanceIdentifier.getAncestor(3));
- assertThrows(IllegalArgumentException.class, () -> stackedYangInstanceIdentifier.getAncestor(12));
+ final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class,
+ () -> stackedYangInstanceIdentifier.getAncestor(12));
+ assertEquals("Depth 12 exceeds maximum depth 4", thrown.getMessage());
}
}