check for negative length in CigarElement ctor #839

Merged
merged 4 commits into from Apr 16, 2017
@@ -36,6 +36,7 @@
private final CigarOperator operator;
public CigarElement(final int length, final CigarOperator operator) {
+ if (length < 0) throw new IllegalArgumentException(String.format("Cigar element being constructed with negative length: %d and operation: %s" , length, operator.name()));
this.length = length;
this.operator = operator;
}
@@ -0,0 +1,14 @@
+package htsjdk.samtools.util;
+
+
+import htsjdk.samtools.CigarElement;
+import htsjdk.samtools.CigarOperator;
+import org.testng.annotations.Test;
+
+public class CigarElementUnitTest {
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testNegativeLengthCheck(){
+ final CigarElement element = new CigarElement(-1, CigarOperator.M);
+ }
+}