package jalview.util.matcher; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; import org.testng.annotations.Test; public class KeyedMatcherTest { @Test public void testMatches() { /* * a numeric matcher - MatcherTest covers more conditions */ KeyedMatcherI km = new KeyedMatcher(Condition.GE, -2F, "AF"); assertTrue(km.matches(key -> "-2")); assertTrue(km.matches(key -> "-1")); assertFalse(km.matches(key -> "-3")); assertFalse(km.matches(key -> "")); assertFalse(km.matches(key -> "junk")); assertFalse(km.matches(key -> null)); /* * a string pattern matcher */ km = new KeyedMatcher(Condition.Contains, "Cat", "AF"); assertTrue( km.matches(key -> "AF".equals(key[0]) ? "raining cats and dogs" : "showers")); } @Test public void testToString() { /* * 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(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(Condition.GE, -2F, "AF"); assertEquals(km.getMatcher().getCondition(), Condition.GE); assertEquals(km.getMatcher().getFloatValue(), -2F); assertEquals(km.getMatcher().getPattern(), "-2.0"); } }