164b8eb2d7e8fda663e9cc6c8f409b06ed0dcf53
[jalview.git] / test / jalview / util / matcher / KeyedMatcherTest.java
1 package jalview.util.matcher;
2
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertFalse;
5 import static org.testng.Assert.assertTrue;
6
7 import org.testng.annotations.Test;
8
9 public class KeyedMatcherTest
10 {
11   @Test
12   public void testMatches()
13   {
14     /*
15      * a numeric matcher - MatcherTest covers more conditions
16      */
17     KeyedMatcherI km = new KeyedMatcher("AF", Condition.GE, -2F);
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));
24
25     /*
26      * a string pattern matcher
27      */
28     km = new KeyedMatcher("AF", Condition.Contains, "Cat");
29     assertTrue(km.matches(key -> "AF".equals(key) ? "raining cats and dogs"
30             : "showers"));
31   }
32
33   @Test
34   public void testToString()
35   {
36     /*
37      * toString uses the i18n translation of the enum conditions
38      */
39     KeyedMatcherI km = new KeyedMatcher("AF", Condition.LT, 1.2f);
40     assertEquals(km.toString(), "AF < 1.2");
41   }
42
43   @Test
44   public void testGetKey()
45   {
46     KeyedMatcherI km = new KeyedMatcher("AF", Condition.GE, -2F);
47     assertEquals(km.getKey(), "AF");
48   }
49
50   @Test
51   public void testGetMatcher()
52   {
53     KeyedMatcherI km = new KeyedMatcher("AF", Condition.GE, -2F);
54     assertEquals(km.getMatcher().getCondition(), Condition.GE);
55     assertEquals(km.getMatcher().getFloatValue(), -2F);
56     assertEquals(km.getMatcher().getPattern(), "-2.0");
57   }
58 }