1 package jalview.util.matcher;
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertFalse;
5 import static org.testng.Assert.assertTrue;
7 import org.testng.annotations.Test;
9 public class KeyedMatcherTest
12 public void testMatches()
15 * a numeric matcher - MatcherTest covers more conditions
17 KeyedMatcherI km = new KeyedMatcher(Condition.GE, -2F, "AF");
18 assertTrue(km.matches(key -> "-2"));
19 assertTrue(km.matches(key -> "-1"));
20 assertFalse(km.matches(key -> "-3"));
21 assertFalse(km.matches(key -> ""));
22 assertFalse(km.matches(key -> "junk"));
23 assertFalse(km.matches(key -> null));
26 * a string pattern matcher
28 km = new KeyedMatcher(Condition.Contains, "Cat", "AF");
30 km.matches(key -> "AF".equals(key[0]) ? "raining cats and dogs"
35 public void testToString()
38 * toString uses the i18n translation of the enum conditions
40 KeyedMatcherI km = new KeyedMatcher(Condition.LT, 1.2f, "AF");
41 assertEquals(km.toString(), "AF < 1.2");
45 public void testGetKey()
47 KeyedMatcherI km = new KeyedMatcher(Condition.GE, -2F, "AF");
48 assertEquals(km.getKey(), new String[] { "AF" });
51 * compound key (attribute / subattribute)
53 km = new KeyedMatcher(Condition.GE, -2F, "CSQ", "Consequence");
54 assertEquals(km.getKey(), new String[] { "CSQ", "Consequence" });
58 public void testGetMatcher()
60 KeyedMatcherI km = new KeyedMatcher(Condition.GE, -2F, "AF");
61 assertEquals(km.getMatcher().getCondition(), Condition.GE);
62 assertEquals(km.getMatcher().getFloatValue(), -2F);
63 assertEquals(km.getMatcher().getPattern(), "-2.0");