JAL-2808 added conditions Present, NotPresent as options
[jalview.git] / test / jalview / util / matcher / KeyedMatcherTest.java
index ebc09c1..3fd7800 100644 (file)
@@ -14,7 +14,7 @@ public class KeyedMatcherTest
     /*
      * a numeric matcher - MatcherTest covers more conditions
      */
-    KeyedMatcherI km = new KeyedMatcher("AF", Condition.GE, -2F);
+    KeyedMatcherI km = new KeyedMatcher(Condition.GE, -2F, "AF");
     assertTrue(km.matches(key -> "-2"));
     assertTrue(km.matches(key -> "-1"));
     assertFalse(km.matches(key -> "-3"));
@@ -25,29 +25,47 @@ public class KeyedMatcherTest
     /*
      * a string pattern matcher
      */
-    km = new KeyedMatcher("AF", Condition.Contains, "Cat");
-    assertTrue(km.matches(key -> "AF".equals(key) ? "raining cats and dogs"
-            : "showers"));
+    km = new KeyedMatcher(Condition.Contains, "Cat", "AF");
+    assertTrue(
+            km.matches(key -> "AF".equals(key[0]) ? "raining cats and dogs"
+                    : "showers"));
   }
 
   @Test
   public void testToString()
   {
-    KeyedMatcherI km = new KeyedMatcher("AF", Condition.LT, 1.2f);
-    assertEquals(km.toString(), "AF LT 1.2");
+    /*
+     * toString uses the i18n translation of the enum conditions
+     */
+    KeyedMatcherI km = new KeyedMatcher(Condition.LT, 1.2f, "AF");
+    assertEquals(km.toString(), "AF < 1.2");
+
+    /*
+     * Present / NotPresent omit the value pattern
+     */
+    km = new KeyedMatcher(Condition.Present, "", "AF");
+    assertEquals(km.toString(), "AF Is present");
+    km = new KeyedMatcher(Condition.NotPresent, "", "AF");
+    assertEquals(km.toString(), "AF Is not present");
   }
 
   @Test
   public void testGetKey()
   {
-    KeyedMatcherI km = new KeyedMatcher("AF", Condition.GE, -2F);
-    assertEquals(km.getKey(), "AF");
+    KeyedMatcherI km = new KeyedMatcher(Condition.GE, -2F, "AF");
+    assertEquals(km.getKey(), new String[] { "AF" });
+
+    /*
+     * compound key (attribute / subattribute)
+     */
+    km = new KeyedMatcher(Condition.GE, -2F, "CSQ", "Consequence");
+    assertEquals(km.getKey(), new String[] { "CSQ", "Consequence" });
   }
 
   @Test
   public void testGetMatcher()
   {
-    KeyedMatcherI km = new KeyedMatcher("AF", Condition.GE, -2F);
+    KeyedMatcherI km = new KeyedMatcher(Condition.GE, -2F, "AF");
     assertEquals(km.getMatcher().getCondition(), Condition.GE);
     assertEquals(km.getMatcher().getFloatValue(), -2F);
     assertEquals(km.getMatcher().getPattern(), "-2.0");