X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Futil%2FDnaUtilsTest.java;h=9815aa033ba87254bea2513dfc0c0ac8f76038c5;hb=df0035d38851d468e8f6991ad6ed1c8f6cce2610;hp=d7a76b9ab2f10dae94af794e1f766a0997ee7c79;hpb=9c39e96af6b84257604da448101505361dced686;p=jalview.git diff --git a/test/jalview/util/DnaUtilsTest.java b/test/jalview/util/DnaUtilsTest.java index d7a76b9..9815aa0 100644 --- a/test/jalview/util/DnaUtilsTest.java +++ b/test/jalview/util/DnaUtilsTest.java @@ -1,22 +1,56 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.util; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertNull; import static org.testng.AssertJUnit.fail; +import jalview.gui.JvOptionPane; + +import java.text.ParseException; import java.util.List; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class DnaUtilsTest { + + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + /** * Tests for parsing an ENA/GenBank location specifier * + * @throws ParseException + * * @see http://www.insdc.org/files/feature_table.html#3.4 */ @Test(groups = { "Functional" }) - public void testParseLocation() + public void testParseLocation() throws ParseException { /* * single locus @@ -91,21 +125,21 @@ public class DnaUtilsTest /* * valid things we don't yet handle */ - assertNull(DnaUtils.parseLocation("<34..126")); - assertNull(DnaUtils.parseLocation("35..>126")); - assertNull(DnaUtils.parseLocation("34.126")); - assertNull(DnaUtils.parseLocation("34^126")); - assertNull(DnaUtils.parseLocation("order(34..126,130..180)")); + checkForParseException("<34..126"); + checkForParseException("35..>126"); + checkForParseException("34.126"); + checkForParseException("34^126"); + checkForParseException("order(34..126,130..180)"); /* * invalid things */ - assertNull(DnaUtils.parseLocation("")); - assertNull(DnaUtils.parseLocation("JOIN(1..2)")); - assertNull(DnaUtils.parseLocation("join(1..2")); - assertNull(DnaUtils.parseLocation("join(1..2(")); - assertNull(DnaUtils.parseLocation("complement(1..2")); - assertNull(DnaUtils.parseLocation("complement(1..2(")); + checkForParseException(""); + checkForParseException("JOIN(1..2)"); + checkForParseException("join(1..2"); + checkForParseException("join(1..2("); + checkForParseException("complement(1..2"); + checkForParseException("complement(1..2("); try { assertNull(DnaUtils.parseLocation(null)); @@ -119,14 +153,29 @@ public class DnaUtilsTest * nested joins are not allowed; just as well since this fails to parse * (splitting tokens by comma fragments the inner join expression) */ - assertNull(DnaUtils - .parseLocation("join(1..2,join(4..5,10..12),18..22)")); + checkForParseException("join(1..2,join(4..5,10..12),18..22)"); /* * complement may not enclose multiple ranges * parsing fails for the same reason */ - assertNull(DnaUtils - .parseLocation("join(complement(36618..36700,4000..4200),86988..87064)")); + checkForParseException("join(complement(36618..36700,4000..4200),86988..87064)"); + } + + /** + * Verifies that a ParseException is thrown when the given location is parsed + * + * @param location + */ + void checkForParseException(String location) + { + try + { + DnaUtils.parseLocation(location); + fail("Expected exception"); + } catch (ParseException e) + { + // expected; + } } }