X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Futil%2Fmatcher%2FMatcherTest.java;h=a47fb60fc99a19c942475bc11b4dd0d8bcac5f80;hb=b320470d1ddb95476d3678477b72f6f791a51404;hp=d988c3a1729511dbc5529a8f35d30bc34bc8b42f;hpb=baa077bd19420018433d78927aad3ad139e47351;p=jalview.git diff --git a/test/jalview/util/matcher/MatcherTest.java b/test/jalview/util/matcher/MatcherTest.java index d988c3a..a47fb60 100644 --- a/test/jalview/util/matcher/MatcherTest.java +++ b/test/jalview/util/matcher/MatcherTest.java @@ -6,16 +6,21 @@ import static org.testng.Assert.assertNotEquals; import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; +import java.util.Locale; + import org.testng.annotations.Test; +import junit.extensions.PA; + public class MatcherTest { - @Test + @Test(groups = "Functional") public void testConstructor() { MatcherI m = new Matcher(Condition.Contains, "foo"); assertEquals(m.getCondition(), Condition.Contains); - assertEquals(m.getPattern(), "FOO"); // all comparisons upper-cased + assertEquals(m.getPattern(), "foo"); + assertEquals(PA.getValue(m, "uppercasePattern"), "FOO"); assertEquals(m.getFloatValue(), 0f); m = new Matcher(Condition.GT, -2.1f); @@ -25,7 +30,7 @@ public class MatcherTest m = new Matcher(Condition.NotContains, "-1.2f"); assertEquals(m.getCondition(), Condition.NotContains); - assertEquals(m.getPattern(), "-1.2F"); + assertEquals(m.getPattern(), "-1.2f"); assertEquals(m.getFloatValue(), 0f); m = new Matcher(Condition.GE, "-1.2f"); @@ -55,7 +60,7 @@ public class MatcherTest /** * Tests for float comparison conditions */ - @Test + @Test(groups = "Functional") public void testMatches_float() { /* @@ -107,7 +112,7 @@ public class MatcherTest assertTrue(m.matches("1.9")); } - @Test + @Test(groups = "Functional") public void testMatches_floatNullOrInvalid() { for (Condition cond : Condition.values()) @@ -125,7 +130,7 @@ public class MatcherTest /** * Tests for string comparison conditions */ - @Test + @Test(groups = "Functional") public void testMatches_pattern() { /* @@ -167,6 +172,22 @@ public class MatcherTest assertTrue(m.matches(null)); /* + * value is present (is not null) + */ + m = new Matcher(Condition.Present, null); + assertTrue(m.matches("benign")); + assertTrue(m.matches("")); + assertFalse(m.matches(null)); + + /* + * value is not present (is null) + */ + m = new Matcher(Condition.NotPresent, null); + assertFalse(m.matches("benign")); + assertFalse(m.matches("")); + assertTrue(m.matches(null)); + + /* * a float with a string match condition will be treated as string */ Matcher m1 = new Matcher(Condition.Contains, "32"); @@ -177,7 +198,7 @@ public class MatcherTest /** * If a float is passed with a string condition it gets converted to a string */ - @Test + @Test(groups = "Functional") public void testMatches_floatWithStringCondition() { MatcherI m = new Matcher(Condition.Contains, 1.2e-6f); @@ -189,20 +210,22 @@ public class MatcherTest assertFalse(m.matches("0.0000001f")); } - @Test + @Test(groups = "Functional") public void testToString() { + Locale.setDefault(Locale.ENGLISH); + MatcherI m = new Matcher(Condition.LT, 1.2e-6f); - assertEquals(m.toString(), "LT 1.2E-6"); + assertEquals(m.toString(), "< 1.2E-6"); m = new Matcher(Condition.NotMatches, "ABC"); - assertEquals(m.toString(), "NotMatches ABC"); + assertEquals(m.toString(), "Does not match 'ABC'"); m = new Matcher(Condition.Contains, -1.2f); - assertEquals(m.toString(), "Contains -1.2"); + assertEquals(m.toString(), "Contains '-1.2'"); } - @Test + @Test(groups = "Functional") public void testEquals() { /* @@ -235,7 +258,7 @@ public class MatcherTest assertFalse(m.equals(new Matcher(Condition.LT, -1.1f))); } - @Test + @Test(groups = "Functional") public void testHashCode() { MatcherI m1 = new Matcher(Condition.NotMatches, "ABC");