Skip to content

Commit

Permalink
Added a null check to MolecularFormulaRange
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-pluskal committed Aug 6, 2016
1 parent 5332a43 commit d82fd44
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public MolecularFormulaRange() {
*
*/
public void addIsotope(IIsotope isotope, int countMin, int countMax) {

if (isotope == null)
throw new IllegalArgumentException("Isotope must not be null");

boolean flag = false;
for (Iterator<IIsotope> it = isotopes().iterator(); it.hasNext();) {
IIsotope thisIsotope = it.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,17 @@ public void testClone_Isotopes() throws Exception {
Assert.assertEquals(8, ((MolecularFormulaRange) clone).getIsotopeCountMax(flu));
Assert.assertEquals(10, ((MolecularFormulaRange) clone).getIsotopeCountMax(h1));
}

/**
* Test what happens when null isotope is added to MF range.
*/
@Test(expected=IllegalArgumentException.class)
public void testNull() throws Exception {
MolecularFormulaRange mfRange = new MolecularFormulaRange();
IIsotope carb = builder.newInstance(IIsotope.class, "C");
IIsotope nul = null;
mfRange.addIsotope(carb, 2, 5);
mfRange.addIsotope(nul, 3, 7);
}

}

0 comments on commit d82fd44

Please sign in to comment.